📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  Target Specific - General  >>  Confusing Calls to _exit

Topic created on: February 24, 2007 11:27 CST by SpacedOut .

On the reversing project I'm working (trying to get a file format) on i keep seeing calls to _exit, for example:

push 204h ; NumberOfBytesToRead
call _exit
add esp, 4
mov [esp+10], eax

I'm not sure why IDA identified 204h as number of bytes to read or why the return value from a void function is being used.  IDA seems to confirm that this is the C library exit() function too, not another one with the same name.

Any help would be appreciated.

  nezumi     February 24, 2007 11:56.38 CST
seems it's just a bug in IDA or conflict between FLIRT bases, it occurs quite often, however, in my version (4.7 console), everything is ok:


.text:004010B4                 call    _main
.text:004010B9                 add     esp, 0Ch
.text:004010BC                 mov     [ebp+var_1C], eax
.text:004010BF                 push    eax             ; int
.text:004010C0                 call    _exit


also, try to use functions long GetSpd(long ea) and long GetSpDiff(long ea) to determine if IDA determines ESP value correctly or not, and if it's wrong use success SetSpDiff(long ea,long delta) to correct ESP (maybe, IDA thinks that PUSH-argument belongs to another function).

p.s. I wrote a book about IDA-script language, but it's not translated into eng yet and available in rus only.

  igorsk     February 24, 2007 13:25.01 CST
Looks like a FLIRT miss to me, i.e. that _exit is not _exit at all, but some kind of fread() function. Comment "NumberOfBytesToRead" was probably added by propagating up parameters of the ReadFile function called somewhere in that "_exit" function.

  nezumi     February 24, 2007 14:35.04 CST
no, it can't be fread(), due to add esp,4 command means so-called _exit() takes only _one_ parameter, since fread() takes four!
meantime, it can't be _exit(), since real _exit() returns void, not _int_ (see command mov[esp+10],eax)

SpacedOut
I can't help you having only piece of code.
if it's possible, please send your project
(not IDA database!) to [email protected]

  igorsk     February 24, 2007 17:22.40 CST
I didn't say it's fread, I said "some kind of fread()". Of course I noticed it takes only one argument :)

  AbelianGrape     February 24, 2007 20:30.51 CST
"some kind of fread()" would surely take at least two arguments, including a file handle / some structure containing a file handle, so that's unlikely to be true (unless this is a fastcall function and we aren't seeing all of the arguments).  

Solution:  disassemble the so-called _exit and/or observe the return value at runtime.

  SpacedOut     February 25, 2007 11:05.35 CST
Thanks a lot for the help everyone, I admit I'm a newb so I really appreciate it.  AbelianGrape, I took your advice and disassembled the so-called exit and I think I figured it out.

I was looking through a tree of what functions were called from this so-called exit and I noticed MessageBox() was one, I went to that section of code and found it displayed "SmartHeap Library."  A google search brought me to this page: http://www.microquill.com/index.html.  Apparently they sell a library that makes managing memory allocation with threads easier.  I believe this is a memory allocation function.

SmartHeap by default overrides malloc(), and now that I think about it I haven't seen a single call to malloc() but I've seen several to this function.  Further, on the three calls I was observing there was a call to the 'eh vector iterator constructor'().  The best part is the sizes match up:

push 204h
call _exit
...
push offset null_sub
push offset sub_6A0760
push 20h
push 10h ; 20h * 10h + 4 = 204h
push esi
call ??_L@YGXPAXIHP6EX0@Z1@Z

...

push 1F2h
call _exit
...
push offset null_sub
push offset sub_6A0780
push 0Dh
push 26h ; 0Dh * 26h + 4 = 1F2h
push esi
call ??_L@YGXPAXIHP6EX0@Z1@Z

What should I do now?  Is there a way to correct the disassembly, is it worth it in your opinion?  How should I handle these kinds of situations?

  nezumi     February 25, 2007 12:07.02 CST
first of all:
check the list of signatures (view -> open subview -> signatures) and tell us what you see.
if you have two or more modules, delete C-runtime module (if IDA says it can't do that, well, damage start-up code in hex-redactor and re-create project. be ready to load signatures manually: view -> open subview -> signatures -> insert key).

however, if IDA leaves "NumberOfBytesToRead" comment it means that IDA doesn't know about Smart Heap Lib, otherwise it should say "NumberOfBytesToAllocate" or something like that.

it's very possible you have deal with "malloc()" or something like that, but you never can be absolute sure until you have investigated the "_exit()" code.

to answer your question: "What should I do now?"
1) just nothing;
2) rename _exit to _smart_malloc;
3) create your own FLIRT signature and share it with the world :-)

  SpacedOut     February 25, 2007 12:49.30 CST
Signatures:
vc32rtf Applied 1008 Microsoft VisualC 2-8/net runtime
vc32mfc Applied 1664 MFC 3.1/4.0/4.2/8.0 32bit        

just looking at the xrefs from, this _smart_malloc is pretty large function, most of it probably has to deal with multi-processors, threads, and stuff since that's what the makers of Smart Heap Lib say it will do.  It does make calls to Win32 memory allocation functions, exception functions, other error handling functions, and the actual _exit(). Since I don't know how to make a FLIRT signature, I'm inclined to just do nothing and move on, unless you really think that's a bad idea.

  nezumi     February 25, 2007 15:31.55 CST
just rename _exit to _smart_heap_malloc and forgot about it, just in case set break point on _exit and check if it returns pointer to valid memory area.

  SpacedOut     February 25, 2007 19:34.37 CST
I've already done that, it does return a valid memory pointer.  Thanks for your help.

  PSUJobu     February 26, 2007 06:26.29 CST
...and if you still have the NumberOfBytesRead argument propagated in all the calls to _smart_heap_malloc(), use "y" to fix the function signature.

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit