The Owl
November 14th, 2000, 14:21
Quote:
I would like to add to my current iat rebuilder some tracing features,
|
did you consider other options as well? eg, initially you may get away with decoding instruction lengths only, recognizing specific instructions, all without actually executing anything. of course i don't know your goals and why you chose the tracer idea, but you may want to give this a try as well. z0mbie.cjb.net has a nice package called LDE for this purpose (e.g. one of the example Hydra plugins in icedump uses it, enough for peshield and some asprotect API obfuscation).
Quote:
but I can't force the process itself to be traced, my program must trace the code by itself... Do I have to code a device driver on ring 0 ? Is there already made sources available ?
|
by 'process'/'program' i assume you referred to 'thread' which is the executable 'entity' in win32. now, further interpreting the above (feel free to clarify it yourself btw), what you meant probably is that you don't want to start up the target app but instead want to execute its code somehow in your own process, eg. by loading it somewhere in your process' address space and starting a new thread (under the tracer's control). this is indeed possible and would actually result in what i could best describe as the user mode equivalent of icedump's tracer engine.
what you will have to do is roughly this:
1. implement a state machine like icedump's tracer and have it gain control on each single step exception that will occur in the traced thread. you can achieve this by ensuring that the engine's main entry point is always the first Structured Exception Handler in the traced thread. this means of course additional emulation for code that installs its own SEHs (something i didn't have to bother with in icedump).
2. to use the tracer, you'd create a new thread in suspended state, change its context so that single step exceptions would be enabled in it and by grabbing its FS, you have to install your engine's main entry point as the thread's first SEH (the emulation i mentioned will later ensure that it always remains the first handler thereafter). then you resume the thread and let the tracer carry out its job.
3. terminating the tracer will be easy once you got all the above to work, eg, you can do a simple range check for EIP in your engine's main function (which gets called on each single step exception), much like icedump's tracer does it.
now, having said all this, let me address a few points. first of all, this is a very interesting project with lots of potential, i beleive you didn't fully realize it when you asked your question ;-). one advantage of it would be that it would work under both win9x and NT as it would be pure user mode code. the drawback of it will be of course its speed, you can expect it to be between 10-100 times slower than icedump's tracer. this is not a tragedy per se, as long as you don't want to trace hundred million instructions ;-). so, my suggestion is that you study and understand how icedump's tracer works (at least the state machine part, how it interfaces to the win9x kernel or softice is less important for now), then implement it in c++. i will be available for help but don't expect me to do it for you, simply no time for this undertaking (you can expect to spend a 'man-week' or two to get all this to work).