Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts
Thursday, September 21, 2017
Tips for writing Ollydbg plugins
Tips for writing Ollydbg plugins
As a part of my masters thesis project I developed an ollydbg plugin which serves as a front-end to my system. While developing it Ive had some problems figuring out how to use certain things since documentation is somewhat lacking. In this post Ill write some tips which can be helpful to people who are developing their first ollydbg plugin (or people who would like to develop ollydbg plugins).
First step
As a first step you should visit this site and download plugin development kit (PDK). You can see some information on the site, such as what youll find in PDK and some rules about writing plugin.Working environment setting
Ive developed plugin using visual studio 2012, so Ill write how to set visual studio to be able to write plugins. Ollydbg is implemented as a dll so to create ollydbg plugin you have to create win32 dll in visual studio. To do that follow these actions: FILE -> New -> Project -> Visual C++ -> Win32 -> Win32 Console Application. In the application wizard choose next and then under application type choose DLL.One of the rules ollydbg sets up is that default character type has to be set to unsigned character. That is achieved by adding /J option to the command like arguments. To do that right click on project and choose Properties -> Configuration Properties -> C/C++ -> Command Line. Under Additional Options add /J.
Plugin functions
There is a .hlp file that comes with PDK, inside is a description of functions and structures available to use within ollydbg plugins. I will describe some functions which I used to create my plugin.Callback functions
Functions which name starts with ODBG_ prefix are callback functions. They are used to:- perform data initialization at the plugin start,
- free resources when ollydbg is closed,
- define plugin menu and its interaction,
- perform some functionality when debugged application is paused.
- ODBG_Plugindata - every plugin must have this function, its functionality is to provide plugins name and return plugin version,
- ODBG_Plugininit - another function which every plugin must have, its called during startup and it should be used to perform all one-time initialization
- ODBG_Plugindestroy - called at the exit, all resources allocated should be freed here
- ODBG_Pluginreset - called when user opens new or restarts current application, structures and variable should be reset to initial state here
- ODBG_Paused - ollydbg calls this function every time when debugged application is paused, it is a good place to perform some modification or check whether certain condition is met.
Disassembly functions
I will describe functions which I used for disassembly. Basic function for disassembly isDisasm(char *src, ulong srcsize, ulong srcip, char *srcdec, t_disasm *disasm, int disasmmode, ulong threadid).Its parameters are:
- src - buffer which contains raw data which needs to be dissasembled,
- srcip - size of src buffer,
- srcsize - address of instruction to disassemble, if you call Disasm from ODBG_Paused fucntion you can get this value from t_reg structure,
- srcdec - instruction description, its best to provide DEC_UNKNOWN or NULL value here (you can see all values in a header file, they are prefixed by DEC_),
- disasm - structure which saves the results of disassembly,
- disasmmode - what should be disassembled, values can be seen in header file with DISASM_ prefix,
- threadid - thread id in which disassembling is occurring, NULL can be provided for current thread.
Readcommand(ulong ip, char *cmd)
Its parameters are:
- ip - size of src buffer,
- cmd - buffer which contains raw data which needs to be dissasembled.
I suggest studying t_disasm structure in a header file since all disassembly results are saved in this structure and t_reg structure which holds information about current state of debugged application.
download file now
Subscribe to:
Posts (Atom)