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 if you have enough context to do so.
FUN_0008ca9a PUSH EBP MOV EBP,ESP PUSH ESI PUSH EDI SUB ESP,0x10 MOV dword ptr [EBP + local_1c],EAX MOV dword ptr [EBP + local_18],EDX MOV dword ptr [EBP + local_10],EBX MOV dword ptr [EBP + local_14],ECX MOV AL,byte ptr [EBP + Stack[0x48]] MOV EDX,dword ptr [EBP + local_1c] MOV byte ptr [EDX],AL MOV AL,byte ptr [EBP + Stack[0x38]] MOV EDX,dword ptr [EBP + local_1c] MOV byte ptr [EDX + 0x1],AL MOV AL,byte ptr [EBP + Stack[0x3c]] MOV EDX,dword ptr [EBP + local_1c] MOV byte ptr [EDX + 0x2],AL MOV AL,byte ptr [EBP + Stack[0x40]] MOV EDX,dword ptr [EBP + local_1c] MOV byte ptr [EDX + 0x3],AL MOV AL,byte ptr [EBP + Stack[0x44]] MOV EDX,dword ptr [EBP + local_1c] MOV byte ptr [EDX + 0x4],AL MOV EAX,dword ptr [EBP + local_18] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x5],AX MOV EAX,dword ptr [EBP + local_10] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x7],AX MOV EAX,dword ptr [EBP + local_14] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x9],AX MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0xb],AX MOV EAX,dword ptr [EBP + Stack[0x8]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0xd],AX MOV EAX,dword ptr [EBP + Stack[0xc]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0xf],AX MOV EAX,dword ptr [EBP + Stack[0x10]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x11],AX MOV EAX,dword ptr [EBP + Stack[0x14]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x13],AX MOV EAX,dword ptr [EBP + Stack[0x18]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x15],AX MOV EAX,dword ptr [EBP + Stack[0x1c]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x17],AX MOV EAX,dword ptr [EBP + Stack[0x20]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x19],AX MOV EAX,dword ptr [EBP + Stack[0x24]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x1b],AX MOV EAX,dword ptr [EBP + Stack[0x28]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x1d],AX MOV EAX,dword ptr [EBP + Stack[0x2c]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x1f],AX MOV EAX,dword ptr [EBP + Stack[0x30]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x21],AX MOV EAX,dword ptr [EBP + Stack[0x34]] MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x23],AX MOV EAX,dword ptr [EBP + local_1c] MOV word ptr [EAX + 0x25],0x0 MOV EAX,dword ptr [EBP + local_1c] MOV word ptr [EAX + 0x27],0x0 MOV EAX,dword ptr [EBP + local_1c] MOV word ptr [EAX + 0x29],0x0 MOV EAX,dword ptr [EBP + local_1c] MOV AX,word ptr [EAX + 0x23] DEC EAX MOV EDX,dword ptr [EBP + local_1c] MOV word ptr [EDX + 0x2d],AX MOV EAX,dword ptr [EBP + local_1c] MOV word ptr [EAX + 0x2b],0x0 MOV EBX,0x28 MOV EDX,s_picklist.c_00176e38 = "picklist.c" MOV EAX,0x8980 CALL FUN_000a00af MOV EDX,dword ptr [EBP + local_1c] MOV dword ptr [EDX + 0x2f],EAX MOV EAX,dword ptr [EBP + local_1c] CMP byte ptr [EAX],0x0 JZ LAB_0008cc2a MOV EBX,0x2c MOV EDX,s_picklist.c_00176e38 = "picklist.c" MOV EAX,dword ptr [EBP + local_1c] MOVSX ECX,word ptr [EAX + 0x9] MOV EAX,dword ptr [EBP + local_1c] MOVSX EAX,word ptr [EAX + 0xb] IMUL EAX,ECX CALL FUN_000a00af MOV EDX,EAX MOV EAX,dword ptr [EBP + local_1c] MOV dword ptr [EAX + 0x33],EDX MOV EBX,0x2d MOV EDX,s_picklist.c_00176e38 = "picklist.c" MOV EAX,dword ptr [EBP + local_1c] MOVSX ECX,word ptr [EAX + 0x21] MOV EAX,dword ptr [EBP + local_1c] MOVSX EAX,word ptr [EAX + 0x23] IMUL EAX,ECX CALL FUN_000a00af MOV EDX,EAX MOV EAX,dword ptr [EBP + local_1c] MOV dword ptr [EAX + 0x37],EDX MOV EAX,dword ptr [EBP + local_1c] CALL FUN_0008ca25 LAB_0008cc2a LEA ESP=>local_c,[EBP + -0x8] POP EDI POP ESI POP EBP RET 0x48
FUN_000a00af PUSH EBP MOV EBP,ESP PUSH ECX PUSH ESI MOV ESI,EAX PUSH EDX PUSH EBX CALL FUN_000a0ed9 MOV EAX,ESI CALL FUN_000a10a8 LEA ESP=>local_c,[EBP + -0x8] POP ESI POP ECX POP EBP RET
FUN_0008ca25 PUSH EBP MOV EBP,ESP PUSH EBX PUSH ECX PUSH EDX PUSH ESI PUSH EDI SUB ESP,0x4 MOV dword ptr [EBP + local_1c],EAX MOV EAX,dword ptr [EBP + local_1c] CMP byte ptr [EAX],0x0 JZ LAB_0008ca90 PUSH 0x0 MOV EAX,dword ptr [EBP + local_1c] PUSH dword ptr [EAX + 0x33] MOV EAX,dword ptr [EBP + local_1c] MOVSX ECX,word ptr [EAX + 0xb] MOV EAX,dword ptr [EBP + local_1c] MOVSX EBX,word ptr [EAX + 0x9] MOV EAX,dword ptr [EBP + local_1c] MOVSX EDX,word ptr [EAX + 0x7] MOV EAX,dword ptr [EBP + local_1c] MOVSX EAX,word ptr [EAX + 0x5] CALL FUN_00144e84 PUSH 0x0 MOV EAX,dword ptr [EBP + local_1c] PUSH dword ptr [EAX + 0x37] MOV EAX,dword ptr [EBP + local_1c] MOVSX ECX,word ptr [EAX + 0x23] MOV EAX,dword ptr [EBP + local_1c] MOVSX EBX,word ptr [EAX + 0x21] MOV EAX,dword ptr [EBP + local_1c] MOVSX EDX,word ptr [EAX + 0x1f] MOV EAX,dword ptr [EBP + local_1c] MOVSX EAX,word ptr [EAX + 0x1d] CALL FUN_00144e84 LAB_0008ca90 LEA ESP=>local_18,[EBP + -0x14] POP EDI POP ESI POP EDX POP ECX POP EBX POP EBP RET
FUN_00144e00 TEST EBX,EBX JLE LAB_00144e81 NOP NOP NOP NOP TEST ECX,ECX JLE LAB_00144e81 NOP NOP NOP NOP CMP EAX,dword ptr [DAT_00142948] JGE LAB_00144e81 NOP NOP NOP NOP CMP EDX,dword ptr [DAT_0014294c] JGE LAB_00144e81 CMP EDX,dword ptr [DAT_00142944] JGE LAB_00144e44 SUB EDX,dword ptr [DAT_00142944] ADD ECX,EDX JLE LAB_00144e81 LEA EDI,[EBX + EBP*0x1] IMUL EDX,EDI SUB ESI,EDX MOV EDX,dword ptr [DAT_00142944] LAB_00144e44 CMP EAX,dword ptr JGE LAB_00144e5f SUB EAX,dword ptr [DAT_00142940] ADD EBX,EAX JLE LAB_00144e81 SUB EBP,EAX SUB ESI,EAX MOV EAX,[DAT_00142940] LAB_00144e5f MOV EDI,EDX ADD EDI,ECX SUB EDI,dword ptr [DAT_0014294c] JLE LAB_00144e6f SUB ECX,EDI JLE LAB_00144e81 LAB_00144e6f MOV EDI,EAX ADD EDI,EBX SUB EDI,dword ptr [DAT_00142948] JLE LAB_00144e7f SUB EBX,EDI ADD EBP,EDI LAB_00144e7f CLC RET LAB_00144e81 STC RET
FUN_00144e84 PUSH EBP MOV EBP,ESP PUSH EDI PUSH ESI MOV EDI,dword ptr [EBP + Stack[0x4]] MOV EBP,dword ptr [EBP + Stack[0x8]] CALL FUN_00144e9c POP ESI POP EDI POP EBP RET 0x8
FUN_00144e9c PUSH ESI MOV ESI,EDI CALL FUN_00144e00 JC LAB_00144ed5 MOV EDI,ESI MOV ESI,dword ptr [EDX*0x4 + DAT_00142950] ADD ESI,dword ptr [PTR_DAT_00143550] ADD ESI,EAX MOV EDX,ECX MOV EAX,[DAT_00142930] SUB EAX,EBX LAB_00144ec0 MOV ECX,EBX AND ECX,0x3 MOVSB.REP ES:EDI,ESI MOV ECX,EBX SHR ECX,0x2 MOVSD.REP ES:EDI,ESI ADD ESI,EAX ADD EDI,EBP DEC EDX JNZ LAB_00144ec0 LAB_00144ed5 POP ESI RET
- Assistant
- FUN_0008ca9a function:
This function initializes a structure with the given input parameters. It takes 13 parameters passed through registers and stack values.
Suggested C signature of the function:
void InitStructure(T* structure, uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint16_t f, uint16_t g, uint16_t h, uint16_t i, uint16_t j, uint16_t k, uint16_t l, uint16_t m, uint16_t n, uint16_t o, uint16_t p, uint16_t q, uint16_t r);Mapping of input parameters to registers and stack values:
- EAX -> structure
- EDX -> a
- EBX -> b
- ECX -> c
- Stack[0x48] -> d
- Stack[0x38] -> e
- Stack[0x3c] -> f
- Stack[0x40] -> g
- Stack[0x44] -> h
- Stack[0x4] -> i
- Stack[0x8] -> j
- Stack[0xc] -> k
- Stack[0x10] -> l
- Stack[0x14] -> m
- Stack[0x18] -> n
- Stack[0x1c] -> o
- Stack[0x20] -> p
- Stack[0x24] -> q
- Stack[0x28] -> r
- FUN_000a00af function:
This function appears to allocate memory and assign the allocated memory to an input parameter.
Suggested C signature of the function:
void* AllocateMemory(uint32_t size, const char* file, uint32_t line);Mapping of input parameters to registers and stack values:
- EAX -> size
- EDX -> file (s_picklist.c_00176e38)
- ECX -> line (0x8980)
- FUN_0008ca25 function:
This function appears to call the FUN_00144e84 function twice, each time passing different input parameters.
Suggested C signature of the function:
void CallFunctions(T* structure);Mapping of input parameters to registers and stack values:
- EAX -> structure
- FUN_00144e00 function:
This function checks if the input parameters are within certain bounds.
Suggested C signature of the function:
bool CheckBounds(int32_t ebx, int32_t ecx, int32_t eax, int32_t edx);Mapping of input parameters to registers and stack values:
- EBX -> ebx
- ECX -> ecx
- EAX -> eax
- EDX -> edx
- FUN_00144e84 function:
This function calls the FUN_00144e9c function.
Suggested C signature of the function:
void CallFunction(int32_t edi, int32_t ebp, int32_t esi);Mapping of input parameters to registers and stack values:
- EDI -> edi
- EBP -> ebp
- Stack[0x4] -> esi
- FUN_00144e9c function:
This function calls the FUN_00144e00 function and performs some memory copying operation based on the input parameters.
Suggested C signature of the function:
void CopyMem(int32_t esi, int32_t edi, int32_t ecx, int32_t edx, int32_t eax, int32_t ebx);Mapping of input parameters to registers and stack values:
- ESI -> esi
- EDI -> edi
- ECX -> ecx
- EDX -> edx
- EAX -> eax
- EBX -> ebx
- User
Here is additional context. Please use it to re-examine the functions and update your previous answer if needed:
This is a sample call to FUN_0008ca9a: XOR EAX,EAX PUSH EAX MOV EAX,0x72 PUSH EAX MOV EAX,0xf4 PUSH EAX MOV EAX,0x92 PUSH EAX MOV EAX,0x92 PUSH EAX MOV EAX,0x1 PUSH EAX MOV EAX,0x1 PUSH EAX XOR EAX,EAX PUSH EAX XOR EAX,EAX PUSH EAX MOV EAX,0x3b PUSH EAX MOV EAX,0x8 PUSH EAX MOV EAX,0xb3 PUSH EAX MOV EAX,0x58 PUSH EAX MOV EAX,0xf PUSH EAX MOV EAX,0x8 PUSH EAX MOV EAX,0x9f PUSH EAX MOV EAX,0x58 PUSH EAX MOV EAX,0x22 PUSH EAX MOV ECX,0xa6 MOV EBX,0x9f MOV EDX,0x64 MOV EAX=>DAT_001a9ab8,DAT_001a9ab8 CALL FUN_0008ca9a
Here are names that were suggested for some global values in previous analysis. They are not necessarily accurate:
- DAT_00142940: int screenOffsetX
- DAT_00142944: int screenOffsetY
- DAT_00142948: int screenWidth
- DAT_0014294C: int screenHeight
- DAT_00142950: uint32_t screenBuffer
- DAT_00142930: int screenBufferOffset
- Assistant
Considering the additional context and the sample call to FUN_0008ca9a, the functions can be updated as follows:
- FUN_0008ca9a function:
This function initializes a structure representing a graphical element with the given input parameters.
Suggested name:
InitGraphicalElementSuggested C signature:
void InitGraphicalElement(GraphicalElement* element, uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint16_t f, uint16_t g, uint16_t h, uint16_t i, uint16_t j, uint16_t k, uint16_t l, uint16_t m, uint16_t n, uint16_t o, uint16_t p, uint16_t q, uint16_t r);- FUN_000a00af function:
This function allocates memory for storing an object in the game and assigns the allocated memory to an input parameter.
Suggested name:
AllocateObjectMemorySuggested C signature:
void* AllocateObjectMemory(uint32_t size, const char* file, uint32_t line);- FUN_0008ca25 function:
This function appears to draw the graphical element by calling the FUN_00144e84 function twice, each time passing different input parameters.
Suggested name:
DrawGraphicalElementSuggested C signature:
void DrawGraphicalElement(GraphicalElement* element);- FUN_00144e00 function:
This function checks if the input parameters (coordinates) are within the bounds of the screen.
Suggested name:
IsWithinScreenBoundsSuggested C signature:
bool IsWithinScreenBounds(int32_t x, int32_t y, int32_t width, int32_t height);- FUN_00144e84 function:
This function draws part of the graphical element on the screen by calling the FUN_00144e9c function.
Suggested name:
DrawPartialGraphicalElementSuggested C signature:
void DrawPartialGraphicalElement(int32_t xOffset, int32_t yOffset, int32_t areaSize);- FUN_00144e9c function:
This function calls the IsWithinScreenBounds function and performs memory copying operation to draw a graphical element on the screen based on the input parameters.
Suggested name:
DrawGraphicalElementOnScreenSuggested C signature:
void DrawGraphicalElementOnScreen(int32_t screenX, int32_t screenY, int32_t objWidth, int32_t objHeight, int32_t screenWidth, int32_t screenHeight);
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.