3

I've got a process that writes to a file (database). In process monitor I see WriteFile. After this I see the file is about to be either written or updated (offset:length).

How can I reveal the content that is about to be written or updated in this file using Ollydbg? Is there a tutorial or something similar? And how to specify the function on Ollydbg?

In process monitor, I see WriteFile, but in Ollydbg, what is the function?

1 Answer 1

4

You can have a look at Woodmann or tuts4you if you need tutorials. And if you want to see what is writes you will have to have where the pointers are stored for the function in question.

This has a lot to do with calling conventions, cdecl and stdcall and knowing about them is important for this..

I am going to try to explain using the writeFile function.

How does WriteFile Work

First we look at the WriteFile declaration (taken from MSDN)

BOOL WINAPI WriteFile(
  _In_         HANDLE hFile,
  _In_         LPCVOID lpBuffer,
  _In_         DWORD nNumberOfBytesToWrite,
  _Out_opt_    LPDWORD lpNumberOfBytesWritten,
  _Inout_opt_  LPOVERLAPPED lpOverlapped
);

Now when we assume that Windows has stdcall (win32api has). We can figure out where we can find the variables. (for more about the stdcall see Wikipedia).

Due to our wikipedia article we a few things:

  • The parameters are pushed onto the stack in right-to-left order
  • Registers EAX, ECX, and EDX are designated for use within the function.
  • Return values are stored in the EAX register.
  • stdcall is the standard calling convention for the Microsoft Win32 API.

This is great

Now we have everything we need to figure out where we can find the location of the information you need. When a breakpoint is placed on the function call you'll know that all the variables are stored on the stsck. LPCVOID is a Pointer, all that is left is to follow it and read the data.

4
  • really thanks for your efforts just two thinks to know 1- what u means the returned values are stored in EAx do u mean that this values will be used by writefile ? 2-what is LPCVOID? Commented Sep 6, 2013 at 22:26
  • @studentofmp From one of the supplied links: If the function succeeds, the return value is nonzero (TRUE). So when the write is successful the eax register is non-zero.
    – Stolas
    Commented Sep 6, 2013 at 22:30
  • i have set a breakpoint on the exact address just before the writefile function whene i hold "F8" to setp into ... in the process monitor "the writefile appears" but EAX = 0 where can i see the EAX value? thanks Commented Sep 6, 2013 at 22:56
  • thanks i have seen the full assci but now how can i edit this content before it will be written ? shoul be the last question Commented Sep 6, 2013 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.