Created
December 31, 2024 03:25
-
-
Save aemmitt-ns/49b8eb923594baaa16b98ca64864de1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int32_t process_connection(struct AsmpConnection* asmp_conn) | |
{ | |
avoPrintf(0x12000000, "process_connection start\n"); | |
asmp_conn->ssl_conn = 0; | |
int32_t fd = asmp_conn->sockfd; | |
char* buffer = malloc(0x4000); | |
if (buffer == 0) | |
{ | |
free(asmp_conn); | |
close(fd); | |
pthreadExit(0); | |
} | |
void sock_addr; | |
GetPeerName(fd, &sock_addr); | |
number_of_connections += 1; | |
ManagerStatusTable_add(&sock_addr); | |
ManagerThisSessionMarkAlive(&sock_addr, 0x12c); | |
int32_t logged_in = asmp_conn->logged_in; | |
while (true) | |
{ | |
char* buf = buffer; | |
int32_t state = 1; | |
int32_t recv_len = 0; | |
int32_t len = 0xc; | |
int32_t readtime = 0; | |
while (true) | |
{ | |
void var_b0; | |
if ((logged_in & 4) == 0) | |
{ | |
if (GetPeerName(fd, &var_b0) < 0) | |
avoPrintf(0x82000000, "process_connection: ASMP socket …"); | |
else | |
{ | |
int32_t r3_6; | |
int32_t flags; | |
r3_6 = linux_asmp_read_select(asmp_conn, 5); | |
bool lt_1; | |
if (r3_6 != 0) | |
{ | |
recv_len = asmp_recv(asmp_conn, buf, len, flags); | |
lt_1 = recv_len < 0; | |
bool gt; | |
if (gt) | |
{ | |
if (state < 1) | |
goto label_101f3a24; | |
char rtype; | |
int32_t req_size; | |
if (state > 2) | |
{ | |
if (state != 3) | |
goto label_101f3a24; | |
if (recv_len < len) | |
{ | |
logged_in = asmp_conn->logged_in; | |
buf = &buf[recv_len]; | |
len -= recv_len; | |
state = 3; | |
continue; | |
} | |
else if (recv_len == len) | |
{ | |
process_transaction(buffer, (req_size + 0xd), asmp_conn); | |
if (((uint32_t)rtype) != 2) | |
{ | |
logged_in = asmp_conn->logged_in; | |
break; | |
} | |
logged_in = asmp_conn->logged_in; | |
if ((logged_in & 1) != 0) | |
break; | |
} | |
else | |
{ | |
logged_in = asmp_conn->logged_in; | |
state = 3; | |
continue; | |
} | |
} | |
else if (len > recv_len) | |
{ | |
logged_in = asmp_conn->logged_in; | |
buf = &buf[recv_len]; | |
len -= recv_len; | |
state = 2; | |
continue; | |
} | |
else if (len != recv_len) | |
{ | |
logged_in = asmp_conn->logged_in; | |
continue; | |
} | |
else | |
{ | |
uint32_t one = ((uint32_t)*(uint8_t*)buf); | |
uint8_t one_1 = ((int8_t)one); | |
int32_t magic = *(uint32_t*)(buf + 1); | |
int16_t something = *(uint16_t*)(buf + 5); | |
int16_t something_2 = something; | |
int16_t something_1 = something; | |
rtype = buf[7]; | |
int32_t size = *(uint32_t*)(buf + 8); | |
int32_t size_1 = size; | |
req_size = size; | |
if (one == 1) | |
{ | |
int32_t is_asmp = strncmp(&magic, "ASMP", 4); | |
int32_t is_aidp; | |
if (is_asmp != 0) | |
is_aidp = strncmp(&magic, "AIDP", 4); | |
if (((is_asmp == 0 || is_aidp == 0) && size <= 0x4000)) | |
{ | |
bool has_data = len >= 0; | |
recv_len = len; | |
buf = &buf[len]; | |
readtime = 0; | |
len = (size + 1); | |
state = 3; | |
if (has_data) | |
{ | |
logged_in = asmp_conn->logged_in; | |
continue; | |
} | |
} | |
} | |
} | |
} | |
} | |
else | |
{ | |
if (state != 1) | |
{ | |
readtime += 5; | |
if (readtime > 0x1e) | |
{ | |
avoPrintf(0x82000000, "\nASMPConnectionThread read time…", state, len); | |
recv_len = 0xffffffff; | |
} | |
} | |
ManagerKeepAliveThisSession(&sock_addr); | |
if (ManagerTerminateThisSession(&sock_addr) != 0) | |
{ | |
void addr_text; | |
int16_t var_12e; | |
avoPrintf(0x12000000, "\nASMPConnectionThread %s:%d Ter…", sockAddr_2text(&sock_addr, &addr_text, 0x2e), ((uint32_t)var_12e)); | |
int32_t r3_13 = asmp_build_broadcast(buffer, 1, 2); | |
if (r3_13 != 0) | |
asmp_send(asmp_conn, buffer, r3_13); | |
} | |
else | |
{ | |
lt_1 = recv_len < 0; | |
label_101f3a24: | |
if (!(lt_1)) | |
{ | |
logged_in = asmp_conn->logged_in; | |
continue; | |
} | |
} | |
} | |
} | |
} | |
free(buffer); | |
number_of_connections -= 1; | |
int32_t r3_16 = asmp_conn->file_info[0]; | |
if (r3_16 != 0) | |
free(r3_16); | |
int32_t ssl_conn = asmp_conn->ssl_conn; | |
if (ssl_conn == 0) | |
Close(fd); | |
else | |
{ | |
if (asmp_conn->is_ssl != 0) | |
{ | |
X509_Free(); | |
ssl_conn = asmp_conn->ssl_conn; | |
} | |
SSL_Close_Connection(ssl_conn); | |
} | |
void* field_10 = asmp_conn->field_10; | |
if (field_10 != 0) | |
free(field_10); | |
free(asmp_conn); | |
ManagerStatusTable_remove(&sock_addr); | |
avoPrintf(0x12000000, "Close ASMP connection\n"); | |
return pthreadExit(0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment