Please examine the following assembly for an MS-DOS program and try to explain what the…
- User
Please examine the following assembly for an MS-DOS program and try to explain what the functions are doing and suggest names for the functions. For context, FUN_000a0024 is called throughout the program, with a value in EAX that is likely an object pointer, a value in EDX that is a pointer to a string identifying the .C source file from which the call was made, and a value in EBX that is likely a source line number.
FUN_000a0024 PUSH EBP MOV EBP,ESP PUSH ECX PUSH ESI MOV ESI,EAX PUSH EDX PUSH EBX CALL FUN_000a0ed9 MOV EAX,ESI CALL FUN_000a117e LEA ESP=>local_c,[EBP + -0x8] POP ESI POP ECX POP EBP RET
FUN_000a0ed9 PUSH EBP MOV EBP,ESP CMP dword ptr [DAT_0018d754],0x0 JZ LAB_000a0efd CMP dword ptr [DAT_0018d758],0x0 SETZ AL MOVZX EAX,AL TEST EAX,EAX JZ LAB_000a0efd PUSH 0x0 CALL FUN_000a8db9 LAB_000a0efd MOV EAX,dword ptr [EBP + Stack[0x8]] MOV [DAT_00188a9b],EAX MOV EAX,dword ptr [EBP + Stack[0x4]] MOV [DAT_00188a9f],EAX CMP byte ptr [DAT_00188acb],0x0 JZ LAB_000a0f35 CMP byte ptr [DAT_00188acc],0x0 JNZ LAB_000a0f35 MOV EAX,dword ptr [EBP + Stack[0x8]] MOV [DAT_00188aa4],EAX MOV EAX,dword ptr [EBP + Stack[0x4]] MOV [DAT_00188aa8],EAX INC byte ptr [DAT_00188aad] LAB_000a0f35 POP EBP RET 0x8
FUN_000a117e PUSH EBP MOV EBP,ESP PUSH EBX PUSH ECX PUSH EDX PUSH ESI PUSH EDI SUB ESP,0x20 MOV ESI,EAX MOV EDI,0x1 TEST byte ptr [DAT_00188ac3],0x40 JZ LAB_000a119d MOV AL,0x1c JMP LAB_000a119f LAB_000a119d MOV AL,0xf LAB_000a119f MOV byte ptr [EBP + local_1c],AL MOVZX EAX,AL MOV dword ptr [EBP + local_20],EAX PUSH EAX CALL FUN_000a34b8 CALL FUN_000a33c9 TEST AL,AL JZ LAB_000a121f TEST ESI,ESI JNZ LAB_000a11c3 XOR EDI,EDI JMP LAB_000a11d2 LAB_000a11c3 PUSH ESI PUSH dword ptr [EBP + local_20] LEA EAX=>local_38,[EBP + -0x34] PUSH EAX CALL FUN_000a93ea MOV EDI,EAX LAB_000a11d2 CMP EDI,0x1 JNZ LAB_000a1215 CMP byte ptr [EBP + local_1c],0xf JNZ LAB_000a1201 CMP byte ptr [EBP + local_34],0x24 JNZ LAB_000a1201 PUSH 0x10 CALL FUN_000a926c PUSH dword ptr [EBP + local_38] CALL FUN_000a915f PUSH EAX PUSH dword ptr [PTR_s_%s:_free_of_ptr_0x%p_allocated_w_0018d713] = "%s: free of ptr 0x%p allocated with new" CALL FUN_000a375b ADD ESP,0xc LAB_000a1201 LEA EAX=>local_38,[EBP + -0x34] PUSH EAX CALL FUN_000a8f9c MOVZX EAX,byte ptr [DAT_00188a4c] SUB ESI,EAX JMP LAB_000a121f LAB_000a1215 CMP EDI,0x2 JNZ LAB_000a121f MOV EDI,0x1 LAB_000a121f CMP EDI,0x1 JNZ LAB_000a122b MOV EAX,ESI CALL _nfree LAB_000a122b XREF[1]: 000a1222(j) CALL FUN_000a351e JMP LAB_000a1174
- Assistant
Function names: FUN_000a0024 - log_source_location FUN_000a0ed9 - store_location_data FUN_000a117e - validate_and_free_memory
Explanation:
FUN_000a0024 - log_source_location This function is called throughout the program, likely for debugging/tracing purposes. It takes an object pointer, source file pointer, and source line number, then calls store_location_data and validate_and_free_memory functions. Possible name for this function - log_source_location
FUN_000a0ed9 - store_location_data This function saves information about the source file and source line number being called. It also takes care of setting certain flags and increments a counter based on specific conditions. Possible name for this function - store_location_data
FUN_000a117e - validate_and_free_memory This function validates if a given pointer holds a valid memory address, and if it does, it frees the associated memory block. It also takes care of handling output messages for debugging purposes, based on different flags being set. Possible name for this function - validate_and_free_memory
- User
Additional information:
FUN_000a8db9 PUSH EBP MOV EBP,ESP SUB ESP,0xc CMP dword ptr [DAT_0018d754],0x0 JZ LAB_000a8e0c MOV EAX,dword ptr [EBP + Stack[0x4]] MOV dword ptr [EBP + local_10],EAX MOV dword ptr [EBP + local_c],DAT_0018d758 MOV dword ptr [EBP + local_8],0x0 TEST EAX,EAX JNZ LAB_000a8dff CMP dword ptr [DAT_0018d758],0x0 JZ LAB_000a8dff PUSH s_MemCheck_sez:_entered_critical_s_00177b44 = "MemCheck sez: entered critical section hook twice!!!" CALL FUN_000a3722 MOV dword ptr [DAT_0018d754],0x0 JMP LAB_000a8e0c LAB_000a8dff LEA EAX=>local_10,[EBP + -0xc] PUSH EAX CALL dword ptr [DAT_0018d754] ADD ESP,0x4 LAB_000a8e0c MOV ESP,EBP POP EBP RET 0x4
FUN_000a34b8 PUSH EBP MOV EBP,ESP CMP dword ptr [DAT_0018d754],0x0 JZ LAB_000a34dc CMP dword ptr [DAT_0018d758],0x0 SETZ AL MOVZX EAX,AL TEST EAX,EAX JZ LAB_000a34dc PUSH 0x0 CALL FUN_000a8db9 LAB_000a34dc MOV AL,byte ptr [EBP + Stack[0x4]] MOV [DAT_00188aa3],AL INC byte ptr [DAT_00188acc] CMP byte ptr [DAT_00188acb],0x0 JZ LAB_000a351a CMP byte ptr [DAT_00188acc],0x1 JNZ LAB_000a351a MOV [DAT_00188aac],AL MOV dword ptr [DAT_00188abe],0x0 MOV dword ptr [DAT_00188ac7],0x0 CALL FUN_000a3350 LAB_000a351a POP EBP RET 0x4
FUN_000a33c9 CMP byte ptr [DAT_00188acb],0x0 JZ LAB_000a33fd CMP byte ptr [DAT_00188acc],0x1 JNZ LAB_000a33fd TEST byte ptr [DAT_00188a43],0x4 JZ LAB_000a33ed CMP byte ptr [DAT_00188aad],0x0 JZ LAB_000a33f4 LAB_000a33ed MOV EAX,0x1 JMP LAB_000a33f6 LAB_000a33f4 XOR EAX,EAX LAB_000a33f6 TEST EAX,EAX JZ LAB_000a33fd MOV AL,0x1 RET LAB_000a33fd XOR AL,AL RET
FUN_000a93ea PUSH EBP MOV EBP,ESP PUSH ESI PUSH EDI SUB ESP,0x20 MOV EDI,dword ptr [EBP + Stack[0xc]] XOR ESI,ESI MOVZX EAX,byte ptr [EBP + Stack[0x8]] MOV dword ptr [EBP + local_10],EAX PUSH EAX PUSH EDI PUSH dword ptr [PTR_s_argument_0018d683] = "argument" CALL FUN_000b2ba3 TEST EAX,EAX JNZ LAB_000a9522 PUSH dword ptr [EBP + local_10] CALL FUN_000a90dc TEST EAX,EAX JZ LAB_000a942f MOVZX EAX,byte ptr [DAT_00188a4c] MOV EBX,EDI SUB EBX,EAX MOV dword ptr [EBP + local_14],EBX JMP LAB_000a9432 LAB_000a942f MOV dword ptr [EBP + local_14],EDI LAB_000a9432 LEA EAX=>local_2c,[EBP + -0x28] MOV [DAT_00188abe],EAX PUSH dword ptr [EBP + local_14] PUSH EAX CALL FUN_000b2e2d TEST EAX,EAX JZ LAB_000a94ef CMP byte ptr [DAT_0018d85c],0x0 JZ LAB_000a947f TEST byte ptr [DAT_00188a43],0x80 JZ LAB_000a94e8 CMP byte ptr [DAT_0018d85c],0x0 = 01h JZ LAB_000a94e8 MOV EDX,0x1 MOV EAX,EDI CALL FUN_000b2efd CMP EAX,0x1 JZ LAB_000a94e8 LAB_000a947f PUSH 0xb CALL FUN_000a926c PUSH EDI CALL FUN_000a915f PUSH EAX PUSH dword ptr [PTR_s_%s:_invalid_pointer_0x%p_0018 = "%s: invalid pointer 0x%p" CALL FUN_000a375b ADD ESP,0xc CMP dword ptr [DAT_0018d860],0x0 JZ LAB_000a9522 PUSH EDI INC byte ptr [DAT_00188ac2] CALL dword ptr [DAT_0018d860] ADD ESP,0x4 TEST EAX,EAX JZ LAB_000a94c6 PUSH s_User_ptr_found_by_VerifyF!_00177bdb = "User ptr found by VerifyF!" CALL FUN_000a145c LAB_000a94c6 PUSH dword ptr [EBP + local_14] CALL dword ptr [DAT_0018d860] ADD ESP,0x4 TEST EAX,EAX JZ LAB_000a94e0 PUSH s_Real_ptr_found_by_VerifyF_00177bf6 = "Real ptr found by VerifyF" CALL FUN_000a145c LAB_000a94e0 DEC byte ptr [DAT_00188ac2] JMP LAB_000a9522 LAB_000a94e8 MOV ESI,0x2 JMP LAB_000a9522 LAB_000a94ef PUSH 0x16 LEA EBX=>local_2c,[EBP + -0x28] MOV CX,DS MOV DX,DS MOV EAX,dword ptr [EBP + Stack[0x4]] CALL _fmemcpy MOVZX ESI,byte ptr [EBP + Stack[0x8]] PUSH ESI CALL FUN_000a90dc TEST EAX,EAX JZ LAB_000a951d PUSH dword ptr [EBP + Stack[0x4]] PUSH dword ptr [PTR_s_destination_0018d68b] = "destination" PUSH ESI CALL FUN_000a9329 undefined FUN_000a9329(void) LAB_000a951d MOV ESI,0x1 LAB_000a9522 MOV EAX,ESI JMP LAB_000a93e1 LAB_000a9529 PUSH EBX PUSH ECX d3 MOV BL,DL 10 MOV EDX,dword ptr [EAX] LEA ECX,[EDX + 0x1] MOV dword ptr [EAX],ECX MOV byte ptr [EDX],BL INC dword ptr [EAX + 0x10] POP ECX POP EBX RET
- Assistant
Function names: FUN_000a8db9 - enter_critical_section FUN_000a34b8 - set_debug_level_and_flags FUN_000a33c9 - check_debug_condition FUN_000a93ea - verify_and_classify_ptr
Explanation:
FUN_000a8db9 - enter_critical_section This function appears to be corresponding to entering a critical section (due to the mentions of "entered critical section hook twice") and performing some validation checks. It then calls a function at the address in DAT_0018d754 provided that the comparison checks pass. Possible name for this function - enter_critical_section
FUN_000a34b8 - set_debug_level_and_flags This function sets the debug level and flags for the program by checking the values from the stack and handling some global variables. It also calls enter_critical_section. Possible name for this function - set_debug_level_and_flags
FUN_000a33c9 - check_debug_condition This function checks certain debug conditions like byte flags and appears to return a boolean value based on whether conditions are met. It is used as a sub-routine for other functions to determine whether certain debugging operations are allowed to be executed or not. Possible name for this function - check_debug_condition
FUN_000a93ea - verify_and_classify_ptr This function verifies and classifies a given pointer. It checks if the argument is valid, if the pointer is valid and calls several other functions for further analysis. The result of the function is one of the following values: 0 - not valid, 1 - user pointer, 2 - real pointer; which is returned in the EAX register. Possible name for this function - verify_and_classify_ptr