You may want to read up on assembly before attempting to reverse engineer.
esi
andedi
are pushed on the stack because the compiler thought this routine modifies them. (It is wrong because onlyedi
is used. Still, better safe than sorry.)mov eax,0cccccccch
moves the value 0CCCCCCCCh into register eax. Which is actually kind of self-explanatory. That instruction in itself does nothing particularly useful, and you should be careful to ask such questions. It is clear from the next lines that the value gets stored into the Local Variable area, to fill it with a 'known' value, rather than having random values.The value 0CCCCCCCCh is used as a sentinel valuesentinel value and so if the context is "it gets stored somewhere", then its purpose is to catch uninitialized pointers.
Again, time for an assembly refresher. The first highlighted line
add esp, 4
is not part of the following instructions, it's Stack Cleanup for the previous instruction: the
call
.The lines
mov [ebp+var_E0], eax
andcmp [ebp+var_E0], 0
have nothing to do at all with any kind of "allocation" or "memory"! All it does is saveeax
– the return value of the previouscall
– into a local variable, and then test if the value is 0. That is boilerplate generated code forvar_E0 = new (uint); if (var_E0 == 0) ...
which is the only 'check' there is, and only after attempting to allocate, not before.
'Blue node': the code in assembler does what the C++ code is supposed to do. It allocated space for a single integer before (the
push 4
in the call tonew
) and in the blue node, it stores the value 255 into the newly allocated memory. If you expected it to allocate 255 bytes: well no. It does what the C++ code is supposed to do, which is explained in What does "new int(100)" do?What does "new int(100)" do? and the question of which it is marked a duplicate.