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_00050069 is a function that exits the game with an error message.
FUN_0008dce3 PUSH EBP MOV EBP,ESP PUSH ECX PUSH ESI PUSH EDI SUB ESP,0x18 MOV dword ptr [EBP + local_28],EAX MOV dword ptr [EBP + local_24],EDX MOV dword ptr [EBP + local_20],EBX MOV EBX,dword ptr [EBP + local_20] MOV EDX,dword ptr [EBP + local_24] MOV EAX,dword ptr [EBP + local_28] MOV EAX,dword ptr [EAX + 0x3f] CALL FUN_0008db21 MOV dword ptr [EBP + local_1c],EAX MOV EAX,dword ptr [EBP + local_28] MOV EDX,dword ptr [EBP + local_1c] MOV dword ptr [EDX + 0x43],EAX MOV EAX,dword ptr [EBP + local_1c] MOV dword ptr [EBP + local_18],EAX LAB_0008dd1b CMP dword ptr [EBP + local_18],0x0 JZ LAB_0008dd35 MOV EAX,dword ptr [EBP + local_18] MOV EDX,dword ptr [EBP + local_28] MOV dword ptr [EDX + 0x3f],EAX MOV EAX,dword ptr [EBP + local_18] MOV EAX,dword ptr [EAX + 0x3b] MOV dword ptr [EBP + local_18],EAX JMP LAB_0008dd1b LAB_0008dd35 MOV EAX,dword ptr [EBP + local_1c] MOV dword ptr [EBP + local_14],EAX MOV EAX,dword ptr [EBP + local_14] LEA ESP=>local_10,[EBP + -0xc] POP EDI POP ESI POP ECX POP EBP RET
FUN_0008db21 PUSH EBP MOV EBP,ESP PUSH ECX PUSH ESI PUSH EDI SUB ESP,0x18 MOV dword ptr [EBP + local_28],EAX MOV dword ptr [EBP + local_24],EDX MOV dword ptr [EBP + local_20],EBX MOV EAX,dword ptr [EBP + local_20] ADD EAX,0x47 MOV dword ptr [EBP + local_1c],EAX MOV EAX,dword ptr [EBP + local_1c] ADD EAX,0x12 SUB dword ptr [DAT_001a9b38],EAX MOV EDX,dword ptr [EBP + local_1c] MOV EAX,DAT_00195e18 CALL FUN_00069f8a MOV dword ptr [EBP + local_18],EAX CMP dword ptr [EBP + local_18],0x0 JNZ LAB_0008db6b MOV EAX,s_Unable_to_allocate_OBJECT_memory_00176e70 = "Unable to allocate OBJECT memory." CALL FUN_00050069 LAB_0008db6b CMP dword ptr [EBP + local_24],0x0 JZ LAB_0008dbd0 PUSH 0x4 PUSH 0xa3 MOV ECX,s_object.c_00176e44 = "object.c" MOV EBX,0x37 MOV EDX,dword ptr [EBP + local_24] MOV EAX,dword ptr [EBP + local_18] CALL FUN_000a1023 PUSH 0x4 PUSH 0xa4 MOV ECX,s_object.c_00176e44 = "object.c" MOV EBX,dword ptr [EBP + local_1c] SUB EBX,0x47 MOV EDX,dword ptr [EBP + local_24] ADD EDX,0x47 MOV EAX,dword ptr [EBP + local_18] ADD EAX,0x47 CALL FUN_000a1023 PUSH 0x4 PUSH 0xa5 MOV ECX,s_object.c_00176e44 = "object.c" MOV EBX,0x10 XOR EDX,EDX MOV EAX,dword ptr [EBP + local_18] ADD EAX,0x37 CALL FUN_000a0040 JMP LAB_0008dbfb LAB_0008dbd0 PUSH 0x4 PUSH 0xa9 MOV ECX,s_object.c_00176e44 = "object.c" MOV EBX,dword ptr [EBP + local_1c] XOR EDX,EDX MOV EAX,dword ptr [EBP + local_18] CALL FUN_000a0040 MOV EAX,0x1 CALL FUN_0008eb88 MOV EDX,EAX MOV EAX,dword ptr [EBP + local_18] MOV dword ptr [EAX + 0x1f],EDX LAB_0008dbfb CMP dword ptr [EBP + local_28],0x0 JZ LAB_0008dc0c MOV EDX,dword ptr [EBP + local_18] MOV EAX,dword ptr [EBP + local_28] CALL FUN_0008e09a LAB_0008dc0c MOV EAX,dword ptr [EBP + local_18] MOV dword ptr [EBP + local_14],EAX MOV EAX,dword ptr [EBP + local_14] LEA ESP=>local_10,[EBP + -0xc] POP EDI POP ESI POP ECX POP EBP RET
- Assistant
- User
- Assistant
- User
It seems that FUN_0008e55f returns either 1 or 0, so I think it returns true or false, rather than an object or object pointer.
Also, I think that search_limit is instead a searched for object ID, and current_search_position is the object with the searched for object ID. I think that OBJECT_removeObjectFromList actually checks whether the passed in object's ID matches the ID searched for, and if so sets the value at current_search_position to that object.
Can you re-examine the object-related functions and consider my suggestions, and if you agree, please revise your answer. If you do not agree, please explain why.
- Assistant
You are right about FUN_0008e55f, and I apologize for the confusion. Given that it returns true or false, the suggested signature should be changed:
Revised FUN_0008e55f:
Suggested name: findObjectByCondition
Suggested signature:
bool findObjectByCondition(Object *list, bool (*condition)(Object *));Where EAX maps to list and EDX maps to the condition function.
As for FUN_0008e8e9, it appears you are correct. The function checks if the passed object's ID matches the searched-for object ID, and if it does, it updates the current_search_position.
Revised FUN_0008e8e9:
Suggested name: checkObjectMatchById
Suggested signature:
void checkObjectMatchById(Object *object);Where EAX maps to the object to be checked.
Global values:
- DAT_00199770: Matching object
- DAT_001a9b14: Current search position
- DAT_001a9b18: Searched-for object ID
Reviewing the object-related functions with the updated information, I still believe the previous suggestions for their names and signatures are accurate.
- User
Please review addChildObject. The child object appears to be inserted to the front of a list of objects linked to the parent (with the previous object at the front, if there was one, now at the front of the child's list). However, I noticed that the child object is given the same value at offset 0x43 that the parent object had. This suggests to me that, rather than a parent-child relationship, they may be "siblings" with the same parent at offset 0x43. In which case, this function would be inserting a new sibling object to the front of the list, not a child. What do you think of my interpretation? If you agree, please revise the explanation and signature. Also, you do not need to adhere to my terminology, as I do not know the correct terminology. For example, I do not know if "sibling" or "list" are the correct terms here, but I think you can understand what I meant. If you do not understand my interpretation of the function, please ask me where I should clarify.
- Assistant
You're correct in your interpretation, and I apologize for the confusion. The function does appear to insert a new object as the first in a list of "sibling" objects, with the entire list having a common parent at offset 0x43. All the objects in the list share the same parent, and the function updates the 0x43 value for the new object to match the parent object. In light of this, we should revise the explanation and signature.
Revised FUN_0008e09a:
Suggested name: addSiblingObjectToFront
Suggested signature:
void addSiblingObjectToFront(Object *newObject, Object *previousFrontObject);Where EAX maps to newObject and EDX maps to previousFrontObject.
This function adds a new "sibling" object (newObject) to the front of the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.