Please examine the following decompiled function. This function is for an MS-DOS program…
Private research annotation
Sign in to add a private research label or note.
- User
Please examine the following decompiled function. This function is for an MS-DOS program written in C using the Watcom compiler. The function call is thought to be to the library function "strlen", which has the following documentation:
size_t strlen( const char *s ); The strlen function computes the length of the string pointed to by "s".
Unknown_Function PUSH EBP MOV EBP,ESP MOV EBX,dword ptr [EBP + Stack[0x4]] MOV EAX,EBX CALL strlen MOVZX EAX,AL LEA EDX,[EAX + EBX*0x1] LAB_000a8e34
TEST EAX,EAX JZ LAB_000a8e40 DEC EDX DEC EAX CMP byte ptr [EDX],0x5c JNZ LAB_000a8e34 INC EAX LAB_000a8e40 ADD EAX,EBX POP EBP RET 0x4Here is the assembly for the function thought to be "strlen".
strlen PUSH ECX PUSH EDI MOV EDI,EAX PUSH ES MOV AX,DS MOV ES,AX SUB ECX,ECX DEC ECX XOR EAX,EAX SCASB.REP ES:EDI NOT ECX DEC ECX POP ES MOV EAX,ECX POP EDI POP ECX RET
Do you agree that the called function appears to be "strlen" and matches the documented function, or not? What do you think the unknown function that calls "strlen" does, and what might be an appropriate function name for it?
- Assistant
Yes, the called function appears to be "strlen" and matches the documented function. The assembly code for "strlen" shows that it computes the length of the input string using SCASB and REP instructions, which are commonly used for string operations.
The unknown function seems to find the position of the last occurrence of the backslash character '\' in the input string. It first calls "strlen" to find the length of the input string and then iterates backward through the string, searching for '\' and returning the index(position) where it was found, relative to the input string pointer. It continues searching until it finds a '\' or reaches the beginning of the string.
An appropriate function name for this unknown function could be "find_last_backslash_index".
- User
Here is another function from the same program. What do you think this one does, and can you suggest a name for it?
Unknown function
PUSH EBP MOV EBP,ESP MOV AL,byte ptr [EBP + Stack[0x4]] CMP AL,0x4 JC LAB_000a90f8 CMP AL,0x5 JBE LAB_000a90f2 CMP AL,0x56 JC LAB_000a90f8 CMP AL,0x59 JA LAB_000a90f8 LAB_000a90f2 XOR EAX,EAX POP EBP RET 0x4 LAB_000a90f8 MOV EAX,0x1 POP EBP RET 0x4 - Assistant
This function appears to check if the input byte (AL) falls within specific ranges. It checks whether AL is between 4 to 5 inclusive, or between 86 to 89 inclusive. If the input byte matches these conditions, the function returns 0 (EAX is XORed with itself, making it 0). Otherwise, the function returns 1.
A possible name for this function could be "check_byte_in_range".
- User
I will give you another unknown function from the same program. It calls each of the previous two functions, to which I have assigned your suggested names. It also calls the function _fmemset. First, here is the documentation for _fmemset:
"void __far *_fmemset( void __far *s, int c, size_t length );
The _fmemset function fills the first "length" characters of the object pointed to by "s" with the value "c".
The _fmemset function is a data model independent form of the memset function. It accepts far pointer arguments and returns a far pointer. It is most useful in mixed memory model applications."
- Assistant
This function appears to perform some initialization or setup steps for a data structure, probably located at a given memory location. It seems to follow these steps:
- Fill a memory area of 0x16 bytes, pointed to by 'ESI', with zeros using '_fmemset'.
- Save some input parameters (from EBP stack frame) to specific offsets within that memory block according to the function's logic.
- Call 'find_last_backslash_index' function with a global data pointer DAT_00188aa4, and save the returned result at an offset within the memory block.
- Save a global data value (DAT_00188aa8) at an offset within the memory block.
- Depending on the value of another global byte (DAT_00188aad), set a specific flag (bit 1) within the memory block.
- Call the 'check_byte_in_range' function with the byte value passed as an input parameter. If the function returns 0, set another flag (bit 3) within the memory block.
Based on the functionality of the unknown function, an appropriate name could be "initialize_data_structure" or "setup_data_structure".