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, including which parameters map to which registers or stack values. 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_00012203 PUSH EBP MOV EBP,ESP PUSH ESI PUSH EDI SUB ESP,0x10 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0xa8] MOV dword ptr [EBP + local_1c],EAX CMP dword ptr [EBP + local_1c],0x0 JZ LAB_0001222f MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x5b JNZ LAB_00012231 LAB_0001222f JMP LAB_00012240 LAB_00012231 MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0xd JNZ LAB_0001224c LAB_00012240 MOV dword ptr [EBP + local_10],0x0 JMP LAB_000122e7 LAB_0001224c MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EDX,dword ptr [EAX + 0x84] MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0x88] ADD EAX,EDX MOV dword ptr [EBP + local_18],EAX MOV dword ptr [EBP + local_14],0x0 LAB_0001226a MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x20 JNZ LAB_00012281 MOV EAX,dword ptr [EBP + local_1c] INC dword ptr [EBP + local_1c] JMP LAB_0001226a LAB_00012281 MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0xd LAB_00012299 MOV EAX,dword ptr [EBP + Stack[0xc]] DEC EAX CMP EAX,dword ptr [EBP + local_14] JA LAB_0001229b LAB_00012299 JMP LAB_000122b0 LAB_0001229b MOV EAX,dword ptr [EBP + local_1c] INC dword ptr [EBP + local_1c] MOV EDX,dword ptr [EBP + local_14] INC dword ptr [EBP + local_14] ADD EDX,dword ptr [EBP + Stack[0x8]] MOV AL,byte ptr [EAX] MOV byte ptr [EDX],AL JMP LAB_00012281 LAB_000122b0 MOV EAX,dword ptr [EBP + Stack[0x8]] ADD EAX,dword ptr [EBP + local_14] MOV byte ptr [EAX],0x0 ADD dword ptr [EBP + local_1c],0x2 MOV EAX,dword ptr [EBP + local_1c] CMP EAX,dword ptr [EBP + local_18] JC LAB_000122d4 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EAX + 0xa8],0x0 JMP LAB_000122e0 LAB_000122d4 MOV EAX,dword ptr [EBP + local_1c] MOV EDX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EDX + 0xa8],EAX LAB_000122e0 MOV dword ptr [EBP + local_10],0x1 LAB_000122e7 MOV EAX,dword ptr [EBP + local_10] LEA ESP=>local_c,[EBP + -0x8] POP EDI POP ESI POP EBP RET
- Assistant
The function appears to be parsing a text buffer for a command, and copying the parsed command to another buffer up to a maximum length parameter. It ignores whitespace characters and stops if it encounters a newline or an open square bracket.
Suggested C-language function signature:
int parse_command(void *game_struct, char *output_buffer, int max_length)Explanation:
game_struct: a pointer to a structure that holds some game-related data.output_buffer: the buffer where the parsed command will be copied to.max_length: the maximum number of characters to copy (decremented, since actual index start at 1).
Registers and Stack values:
- EAX: holds the current character being read from the text buffer.
- EBP + local_1c: holds the current position in the text buffer.
- EBP + Stack[0x4]: a pointer to the game structure, which contains the text buffer.
- EBP + Stack[0x8]: a pointer to the output buffer.