I'm using IDA to disassemble a file, and one of the sections contained this. What is this doing? What would it look like in C?
I believe it pushes edx onto the stack, and converts it to an integer using _atoi, but what is left in eax after that, and why is it comparing it to 5?
mov ecx, [ebp+argv]
mov edx, [ecx+4]
push edx ; char *
call _atoi
add esp, 4
mov [ebp+var_60], eax
cmp [ebp+var_60], 5
jle short loc_401167
The C code would look like this
int var_60;
if ( (var_60 = atoi( argv[1] )) > 5 )
{
// execute the instructions after the 'jle' instruction, e.g.
printf( "Invalid argument\n" );
exit( 1 );
}
In other words, the code checks that the first argument to the program is a number that's less than or equal to 5. It also saves the converted value for later use.