The following is decompiled assembly code from an MS-DOS program written in C and…
- User
The following is decompiled assembly code from an MS-DOS program written in C and compiled with the Watcom compiler. Please explain what the functions seem to do and suggest names for the functions.
FUN_000a2b21 PUSH EBP MOV EBP,ESP PUSH ECX PUSH EDX PUSH EAX CALL FUN_000bae0e ADD ESP,0x4 CMP EAX,-0x2 JNZ LAB_000a2b45 MOV EDX,s_Invalid_selector_001775f0 = "Invalid selector" MOV EAX,DAT_001aa6d0 CALL strcpy JMP LAB_000a2b58 LAB_000a2b45 PUSH EAX PUSH s_%08X_00177601 = "%08X" PUSH DAT_001aa6d0 CALL sprintf ADD ESP,0xc LAB_000a2b58 MOV EAX,DAT_001aa6d0 LEA ESP=>local_c,[EBP + -0x8] POP EDX POP ECX POP EBP RET
FUN_000bae0e PUSH EBP MOV EBP,ESP PUSH EDX MOV EDX,dword ptr [EBP + Stack[0x4]] LSL EAX,EDX JZ LAB_000bae1f MOV EAX,0xfffffffe LAB_000bae1f POP EDX POP EBP RET
- Assistant
The first function (FUN_000a2b21) seems to perform the following tasks:
- Call the second function (FUN_000bae0e) with an input value.
- Check the returned value from the second function.
- If the returned value is -2, it sets a string to "Invalid selector".
- If the returned value is not -2, it formats the returned value as a hexadecimal string.
- The resulting string is then saved to a global buffer (DAT_001aa6d0).
- It returns the address of the global buffer containing the result string.
A suggested name for the first function could be
convert_selector_to_string.The second function (FUN_000bae0e) appears to perform a left shift operation on an input value (retrieved from the stack) by a specified number of bits (EDX). If the result is zero, it returns -2; otherwise, it returns the shifted value.
A suggested name for the second function could be
left_shift_check_zero.