I will provide you disassembly from a computer game that runs in MS-DOS. The game was…
- User
I will provide you disassembly from a computer game that runs in MS-DOS. The game was written in C with a Watcom compiler. Some library function calls are already identified. Explain the functions I give to you and suggest names and C-language function signatures for them. Also suggest names for global values when you have enough context to do so. As I provide more information, please revise your explanations and suggestions as necessary.
FUN_00011a6b PUSH EBP MOV EBP,ESP PUSH ESI PUSH EDI SUB ESP,0x8 PUSH 0x4d MOV ECX,s_profile.c_00170129 = "profile.c" MOV EBX,0x4 MOV EDX,dword ptr [EBP + Stack[0x8]] MOV EAX,dword ptr [EBP + Stack[0x4]] ADD EAX,0x4 CALL FUN_000a0ad9 PUSH 0x200 MOV EAX,dword ptr [EBP + Stack[0x8]] PUSH EAX CALL open ADD ESP,0x8 MOV dword ptr [EBP + local_14],EAX CMP dword ptr [EBP + local_14],-0x1 JNZ LAB_00011ab6 MOV dword ptr [EBP + local_10],0x0 JMP LAB_00011c1a LAB_00011ab6 MOV EBX,0x2 XOR EDX,EDX MOV EAX,dword ptr [EBP + local_14] CALL lseek MOV EDX,EAX MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0x88],EDX MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0x88] ADD EAX,0x400 MOV EDX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EDX + 0x8c],EAX XOR EBX,EBX XOR EDX,EDX MOV EAX,dword ptr [EBP + local_14] CALL lseek MOV EBX,0x5e MOV EDX,s_profile.c_00170129 = "profile.c" MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0x8c] CALL FUN_000a00af MOV EDX,EAX MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0x84],EDX MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0x84] TEST EAX,EAX JNZ LAB_00011b37 MOV EAX,dword ptr [EBP + local_14] CALL __close MOV dword ptr [EBP + local_10],0x0 JMP LAB_00011c1a LAB_00011b37 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EBX,dword ptr [EAX + 0x88] MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EDX,dword ptr [EAX + 0x84] MOV EAX,dword ptr [EBP + local_14] CALL read MOV EDX,EAX MOV EAX,dword ptr [EBP + Stack[0x4]] CMP EDX,dword ptr [EAX + 0x88] JZ LAB_00011bb1 MOV EAX,dword ptr [EBP + local_14] CALL __close MOV EAX,dword ptr [EBP + Stack[0x4]] CMP dword ptr [EAX + 0x84],0x0 JZ LAB_00011b81 MOV EAX,dword ptr [EBP + Stack[0x4]] CMP dword ptr [EAX + 0x84],0x97979797 JNZ LAB_00011b83 LAB_00011b81 JMP LAB_00011ba8 LAB_00011b83 MOV EBX,0x6e MOV EDX,s_profile.c_00170129 = "profile.c" MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0x84] CALL FUN_000a0024 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0x84],0x97979797 LAB_00011ba8 MOV dword ptr [EBP + local_10],0x0 JMP LAB_00011c1a LAB_00011bb1 MOV EAX,dword ptr [EBP + local_14] CALL __close MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EDX,dword ptr [EAX + 0x84] MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0x90],EDX MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0x94],0x0 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0xa0],0x0 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0xa4],0x0 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0x9c],0x0 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0xa8],0x0 MOV EAX,dword ptr [EBP + Stack[0x4]] AND byte ptr [EAX + 0x1],0x7f MOV dword ptr [EBP + local_10],0x1 LAB_00011c1a MOV EAX,dword ptr [EBP + local_10] LEA ESP=>local_c,[EBP + -0x8] POP EDI POP ESI POP EBP RET
- Assistant
This function appears to be reading the header information of a file into a structure. The name of the source file is "profile.c". It is using standard file I/O functions such as open, lseek, read and __close.
Here's a possible C-Language function signature for FUN_00011a6b:
int read_header_info(void* structure, const char* file_path);Explanation of the function:
- It first calls
openwith the given file_path (possibly in "read" mode) and stores the file descriptor as local_14. If the open fails, the function returns 0. - Then, it sequentially calls
lseekwith the file descriptor to set the read position to different byte offsets (2 and 5e). After that, it callsreadto read bytes into the structure from the new read position. - It then checks if the read bytes match the expected header size, if not, it sets the structure values to default 0x97979797 value.
- If the header size matches, the function sets the other structure elements as required.
- Finally, the file is closed, and the local_10 variable is assigned 1 (possibly indicating success).
- It first calls
- User
FUN_00011c24 PUSH EBP MOV EBP,ESP PUSH ESI PUSH EDI SUB ESP,0x8 MOV EAX,dword ptr [EBP + Stack[0x4]] TEST byte ptr [EAX + 0x1],0x80 JZ LAB_00011cc8 PUSH 0x0 PUSH 0x262 MOV EAX,dword ptr [EBP + Stack[0x4]] ADD EAX,0x4 PUSH EAX CALL open ADD ESP,0xc MOV dword ptr [EBP + local_14],EAX CMP dword ptr [EBP + local_14],-0x1 JNZ LAB_00011ca6 MOV EAX,dword ptr [EBP + Stack[0x4]] CMP dword ptr [EAX + 0x84],0x0 JZ LAB_00011c76 MOV EAX,dword ptr [EBP + Stack[0x4]] CMP dword ptr [EAX + 0x84],0x97979797 JNZ LAB_00011c78 LAB_00011c76 JMP LAB_00011c9d LAB_00011c78 MOV EBX,0xab MOV EDX,s_profile.c_00170129 = "profile.c" MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0x84] CALL FUN_000a0024 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0x84],0x97979797 LAB_00011c9d MOV dword ptr [EBP + local_10],0x0 JMP LAB_00011d11 LAB_00011ca6 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EBX,dword ptr [EAX + 0x88] MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EDX,dword ptr [EAX + 0x84] MOV EAX,dword ptr [EBP + local_14] CALL write MOV EAX,dword ptr [EBP + local_14] CALL __close LAB_00011cc8 MOV EAX,dword ptr [EBP + Stack[0x4]] CMP dword ptr [EAX + 0x84],0x0 JZ LAB_00011ce3 MOV EAX,dword ptr [EBP + Stack[0x4]] CMP dword ptr [EAX + 0x84],0x97979797 JNZ LAB_00011ce5 LAB_00011ce3 JMP LAB_00011d0a LAB_00011ce5 MOV EBX,0xb9 MOV EDX,s_profile.c_00170129 = "profile.c" MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0x84] CALL FUN_000a0024 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0x84],0x97979797 LAB_00011d0a MOV dword ptr [EBP + local_10],0x1 LAB_00011d11 MOV EAX,dword ptr [EBP + local_10] LEA ESP=>local_c,[EBP + -0x8] POP EDI POP ESI POP EBP RET
- Assistant
This function appears to be writing the header information of a structure into a file. It uses standard file I/O functions such as open, write and __close.
Here's a possible C-Language function signature for FUN_00011c24:
int write_header_info(void* structure);Explanation of the function:
- It first checks if the 0x80 bit of the byte at offset 1 of the structure is set. If it is not set, the function skips to LAB_00011cc8.
- If the bit is set, it calls
openwith mode 0x262 (possibly "write" mode) and offset 4 in the structure as the file_path. It stores the file descriptor as local_14. If the open fails, the function checks the value at offset 0x84 of the structure, and then calls FUN_000a0024 with a fixed value 0xAB, "profile.c" string and the value at offset 0x84 of the structure. - If the open is successful, the function calls
writeto write the header information into the file, and then calls to close the file.
- User
FUN_00011d1b PUSH EBP MOV EBP,ESP PUSH ESI PUSH EDI SUB ESP,0x18 MOV dword ptr [EBP + local_14],0x0 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0x84] MOV dword ptr [EBP + local_24],EAX MOV dword ptr [EBP + local_18],0x0 LAB_00011d40 MOV EAX,dword ptr [EBP + local_24] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x5b JNZ LAB_00011e02 MOV EAX,dword ptr [EBP + local_24] MOV dword ptr [EBP + local_20],EAX MOV EAX,dword ptr [EBP + local_24] INC dword ptr [EBP + local_24] MOV EAX,dword ptr [EBP + Stack[0x8]] MOV dword ptr [EBP + local_1c],EAX LAB_00011d65 MOV EAX,dword ptr [EBP + local_24] MOV DL,byte ptr [EAX] MOV EAX,dword ptr [EBP + local_1c] CMP DL,byte ptr [EAX] JNZ LAB_00011d7f MOV EAX,dword ptr [EBP + local_18] MOV EDX,dword ptr [EBP + Stack[0x4]] CMP EAX,dword ptr [EDX + 0x88] JC LAB_00011d81 LAB_00011d7f JMP LAB_00011d95 LAB_00011d81 MOV EAX,dword ptr [EBP + local_1c] INC dword ptr [EBP + local_1c] MOV EAX,dword ptr [EBP + local_24] INC dword ptr [EBP + local_24] MOV EAX,dword ptr [EBP + local_18] INC dword ptr [EBP + local_18] JMP LAB_00011d65 LAB_00011d95 MOV EAX,dword ptr [EBP + local_24] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x5d JNZ LAB_00011dac MOV EAX,dword ptr [EBP + local_1c] CMP byte ptr [EAX],0x0 JZ LAB_00011dae LAB_00011dac JMP LAB_00011e02 LAB_00011dae MOV dword ptr [EBP + local_14],0x1 LAB_00011db5 MOV EAX,dword ptr [EBP + local_24] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0xa JZ LAB_00011dcc MOV EAX,dword ptr [EBP + local_24] INC dword ptr [EBP + local_24] JMP LAB_00011db5 LAB_00011dcc MOV EAX,dword ptr [EBP + local_24] INC dword ptr [EBP + local_24] MOV EAX,dword ptr [EBP + local_24] MOV EDX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EDX + 0xa8],EAX MOV EAX,dword ptr [EBP + local_24] MOV EDX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EDX + 0x90],EAX MOV EAX,dword ptr [EBP + local_18] MOV EDX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EDX + 0x94],EAX MOV EAX,dword ptr [EBP + local_20] MOV EDX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EDX + 0x98],EAX LAB_00011e02 MOV EAX,dword ptr [EBP + local_24] INC dword ptr [EBP + local_24] MOV EAX,dword ptr [EBP + local_18] INC dword ptr [EBP + local_18] CMP dword ptr [EBP + local_14],0x0 JNZ LAB_00011e26 MOV EAX,dword ptr [EBP + local_18] MOV EDX,dword ptr [EBP + Stack[0x4]] CMP EAX,dword ptr [EDX + 0x88] JC LAB_00011d40 LAB_00011e26 MOV EAX,dword ptr [EBP + local_14] MOV dword ptr [EBP + local_10],EAX MOV EAX,dword ptr [EBP + local_10] LEA ESP=>local_c,[EBP + -0x8] POP EDI POP ESI POP EBP RET
- Assistant
This function appears to be searching for a specific pattern within a structure and updating some fields of the structure based on the found pattern.
Here's a possible C-Language function signature for FUN_00011d1b:
int search_and_update_structure(void* structure, const char* search_str);Explanation of the function:
- It initializes local variables and assigns the value at offset 0x84 of the input structure as local_24.
- The function starts looping through the bytes of the structure, and it searches for the byte pattern 0x5B (which corresponds to the opening square bracket '[' in ASCII).
- Upon finding the pattern, the function compares the subsequent bytes in the structure to the bytes in the search_str input.
- If a match is found for the entire search string, the function continues searching for the pattern 0x5D (which corresponds to the closing square bracket ']' in ASCII) and sets local_14 as 1.
- When it has identified the patterns and found the match, the function updates several fields of the input structure with the located indices and pointers within the structure.