Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

I will provide you disassembly from a computer game that runs in MS-DOS. The game was…

  1. 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_00011f93 PUSH EBP MOV EBP,ESP PUSH ESI PUSH EDI SUB ESP,0x30 MOV EAX,dword ptr [EBP + Stack[0x4]] CMP dword ptr [EAX + 0xa4],0x0 JZ LAB_00011fb8 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0xa4] MOV dword ptr [EBP + local_1c],EAX JMP LAB_00011fc4 LAB_00011fb8 MOV EAX,dword ptr [EBP + Stack[0x4]] MOV EAX,dword ptr [EAX + 0xa0] MOV dword ptr [EBP + local_1c],EAX LAB_00011fc4 CMP dword ptr [EBP + local_1c],0x0 JNZ LAB_00011fd6 MOV dword ptr [EBP + local_10],0x0 JMP LAB_000120e1 LAB_00011fd6 MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x20 JNZ LAB_00011fed MOV EAX,dword ptr [EBP + local_1c] INC dword ptr [EBP + local_1c] JMP LAB_00011fd6 LAB_00011fed MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0xd JNZ LAB_00012008 MOV dword ptr [EBP + local_10],0x0 JMP LAB_000120e1 LAB_00012008 MOV dword ptr [EBP + local_14],0x0 LAB_0001200f MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0xd JZ LAB_0001202d MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x2c JNZ LAB_0001202f LAB_0001202d JMP LAB_0001203e LAB_0001202f MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x20 JNZ LAB_00012040 LAB_0001203e JMP LAB_00012054 LAB_00012040 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] MOV AL,byte ptr [EAX] MOV byte ptr [EDX + EBP0x1 + -0x38],AL JMP LAB_0001200f LAB_00012054 MOV EAX,dword ptr [EBP + local_14] MOV byte ptr [EAX + EBP0x1 + -0x38],0x0 CMP dword ptr [EBP + local_14],0x0 JNZ LAB_0001206e MOV dword ptr [EBP + local_10],0x0 JMP LAB_000120e1 LAB_0001206e MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x20 JNZ LAB_00012085 MOV EAX,dword ptr [EBP + local_1c] INC dword ptr [EBP + local_1c] JMP LAB_0001206e LAB_00012085 MOV EAX,dword ptr [EBP + local_1c] MOV AL,byte ptr [EAX] AND EAX,0xff CMP EAX,0x2c JNZ LAB_000120a5 INC dword ptr [EBP + local_1c] MOV EAX,dword ptr [EBP + local_1c] MOV EDX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EDX + 0xa4],EAX JMP LAB_000120b1 LAB_000120a5 MOV EAX,dword ptr [EBP + local_1c] MOV EDX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EDX + 0xa4],EAX LAB_000120b1 MOVSX EAX,byte ptr [EBP + local_3b] CMP EAX,0x78 JNZ LAB_000120c7 LEA EAX=>local_3a,[EBP + -0x36] CALL FUN_00012d3b MOV dword ptr [EBP + local_18],EAX JMP LAB_000120d2 LAB_000120c7 LEA EAX=>local_3c,[EBP + -0x38] CALL atoi MOV dword ptr [EBP + local_18],EAX LAB_000120d2 MOV EAX,dword ptr [EBP + local_18] MOV EDX,dword ptr [EBP + Stack[0x8]] MOV dword ptr [EDX],EAX MOV dword ptr [EBP + local_10],0x1 LAB_000120e1 MOV EAX,dword ptr [EBP + local_10] LEA ESP=>local_c,[EBP + -0x8] POP EDI POP ESI POP EBP RET

    FUN_00012d3b PUSH EBP MOV EBP,ESP PUSH EBX PUSH ECX PUSH EDX PUSH ESI PUSH EDI SUB ESP,0x18 MOV dword ptr [EBP + local_30],EAX MOV dword ptr [EBP + local_2c],0x0 MOV EAX,dword ptr [EBP + local_30] CALL strlen MOV dword ptr [EBP + local_28],EAX MOV dword ptr [EBP + local_20],0x0 LAB_00012d65 MOV EDX,dword ptr [EBP + local_28] SHL EDX,0x2 MOV EAX,dword ptr [EBP + local_20] INC dword ptr [EBP + local_20] ADD EAX,dword ptr [EBP + local_30] MOVSX EAX,byte ptr [EAX] CALL FUN_00012da5 IMUL EAX,dword ptr [EDX + PTR_s_0123456789ABCDEF_00178848] = address to string "0123456789ABCDEF" ADD dword ptr [EBP + local_2c],EAX MOV EAX,dword ptr [EBP + local_28] DEC dword ptr [EBP + local_28] CMP dword ptr [EBP + local_28],0x0 JA LAB_00012d65 MOV EAX,dword ptr [EBP + local_2c] MOV dword ptr [EBP + local_1c],EAX MOV EAX,dword ptr [EBP + local_1c] LEA ESP=>local_18,[EBP + -0x14] POP EDI POP ESI POP EDX POP ECX POP EBX POP EBP RET

    FUN_00012da5 PUSH EBP MOV EBP,ESP PUSH EBX PUSH ECX PUSH EDX PUSH ESI PUSH EDI SUB ESP,0xc MOV byte ptr [EBP + local_1c],AL MOV dword ptr [EBP + local_24],0x0 LAB_00012dbd CMP dword ptr [EBP + local_24],0x10 JC LAB_00012dcd JMP LAB_00012df0 LAB_00012dc5 MOV EAX,dword ptr [EBP + local_24] INC dword ptr [EBP + local_24] JMP LAB_00012dbd LAB_00012dcd MOV EAX,[PTR_s_0123456789ABCDEF_00178848] = address to string "0123456789ABCDEF" ADD EAX,dword ptr [EBP + local_24] XOR EDX,EDX MOV DL,byte ptr [EAX]=>s_0123456789ABCDEF_00170118 = "0123456789ABCDEF" MOVSX EAX,byte ptr [EBP + local_1c] CALL toupper CMP EDX,EAX JNZ LAB_00012dee MOV EAX,dword ptr [EBP + local_24] MOV dword ptr [EBP + local_20],EAX JMP LAB_00012df7 LAB_00012dee JMP LAB_00012dc5 LAB_00012df0 MOV dword ptr [EBP + local_20],0xffffffff LAB_00012df7 MOV EAX,dword ptr [EBP + local_20] LEA ESP=>local_18,[EBP + -0x14] POP EDI POP ESI POP EDX POP ECX POP EBX POP EBP RET

  2. Assistant

    Initial Explanation:

    • FUN_00011f93: This function appears to parse a string and extract an integer value from the input provided. A "local_1c" variable is used to store the pointer to the start of the input string. It processes characters in the input string individually, skipping whitespace characters, newline characters, and comma. It stores the integer value obtained from the string in "local_18" and then returns "local_10" as a boolean flag to indicate if the operation was successful or not.
    • FUN_00012d3b: This function takes a pointer to a string as input that represents a hexadecimal string and converts it to an integer. It iterates through characters in the input string in reverse and calls FUN_00012da5 to get the hexadecimal value of each character. It then adds this value to the final output after appropriate mathematical operations. It eventually returns the converted integer.
    • FUN_00012da5: This function maps a hexadecimal character from a string to its corresponding integer value by checking if it's present in the hard-coded "0123456789ABCDEF" string. It returns the index of the hexadecimal character within this hard-coded string, which serves as an integer value.

    Revised Function Names and Signatures:

    • FUN_00011f93: Name: parse_string_and_extract_integer Signature: int parse_string_and_extract_integer(char* input_string, int* output_value)

      • Input: EAX + Stack[0x4] -> input_string (pointer to the input string)
      • Output: EAX + Stack[0x8] -> output_value (pointer to store the output integer value)
    • FUN_00012d3b: Name: hex_string_to_integer Signature: int hex_string_to_integer(const char* hex_string)

      • Input: EAX -> hex_string (pointer to the hexadecimal string)
      • Output: EAX -> integer value corresponding to the input hex string
    • FUN_00012da5: Name: hex_char_to_int Signature: int hex_char_to_int(char hex_char)

      • Input: AL -> hex_char (input hexadecimal character)
      • Output: EAX -> integer value corresponding to the input hex character