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.
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 seems to read a line from a buffer and copy it into another buffer. It first checks for special characters like '[' and '\r' and skips leading spaces in the line. It also adds a null-terminator at the end of the copied line. The function returns an integer which indicates if the line has been successfully read.
Here's my suggested function signature:
cint read_line(GameState* state, char* output, int max_length);Parameters map to registers as:
GameState* state-> EBP + Stack[0x4]char* output-> EBP + Stack[0x8]int max_length-> EBP + Stack[0xC]
Suggested names for global values and local variables:
dword ptr [EBP + local_1c]=>char* read_ptrdword ptr [EBP + local_10]=>int is_line_readdword ptr [EBP + local_18]=>char* buffer_enddword ptr [EBP + local_14]=>int num_chars_copiedGameState + 0xA8=>