-
-
8016-Roba--任务完成-待整理
-
发表于: 2004-8-16 08:59 5198
-
一般原理[General principles]
我希望您能对80x86系列处理器的内部结构有所了解,同时具有一定的编写汇编程序的能力。对于Microsoft Windows方面的知识,您也要熟悉。
OllyDbg是运行在Windows 95、Windows 98、Windows ME、Windows NT和Windows 2000系统下的一个单进程、多线程的分析代码级调试工具。它可以调试PE格式的执行文件及动态链接库,并可以对其打补丁。“代码级”意味着您可以直接与比特、字节或处理器指令打交道。OllyDbg仅使用已公开的Win32 API函数,因此它可以在所有Winodows操作系统及后继版本中使用。但是由于我没有对XP系统进行彻底测试,因此不能保证OllyDbg功能的充分发挥。注意:OllyDbg不支持对.NET程序的调试。
OllyDbg不是面向编译器的。它没有特别的规则规定必须是哪一个编译器产生的代码。因此,OllyDbg可以非常好的处理通过编译器生成的代码,或是直接用汇编写入的代码。
OllyDbg可以并行调试程序。您无须暂停执行程序,就可以浏览代码和数据,设置断点、停止或恢复线程,甚至直接修改内存。(这可以视为一种软件调试的模式,与之相对的硬件模式则是当进程在运行时调试器被阻滞,反之亦然)。假使所需的操作比较复杂,OllyDbg会让进程终止一小段时间,但是这种暂停对于用户来说是透明的。
有时进程会发生非法操作。您可以把OD设置成即时[just-in-time]调试器,它会挂接出错程序,并停在程序产生异常的地方。
通过OllyDbg,您可以调试With OllyDbg, you can debug standalone DLLs. OS can’t start DLL directly, so OllyDbg keeps, as a packed resource, small application that loads your library and allows you to call exported functions with up to 10 arguments.
OllyDbg is strongly module-oriented. Module is the main executable file (usually with extension .EXE) or dynamic-link library (usually .DLL) loaded either on startup or dynamically on request. During debugging session you set breakpoints, define new labels and comment assembler commands. When some module unloads from the memory, Debugger saves this information to file with the same name as the debugged module and extension .UDD (stays for User-Defined Data). Next time when OllyDbg loads this module, it automatically restores all debugging information, no matter which program uses this module. Suppose you are debugging Myprog1 that uses Mydll and set some breakpoints in Mydll. Then you start debugging Myprog2 that also makes use of Mydll - and all breakpoints in Mydll are still here, even if Mydll loads on different location!
Some debuggers treat memory of debugged process as a single (and mostly empty) arena 2**32 bytes in size. OllyDbg takes another approach. Here, memory consists of several independent blocks. Any operation on the memory contents is limited to the block. In most cases, this works fine and facilitates debugging. But if, for example, module contains several executable sections, you will be unable to see the whole code at once. Such cases, however, are seldom.
OllyDbg is a memory-hungry application. It allocates up to 3 MB of memory directly on startup and another megabyte or two when you first load debugged program. Each analysis, backup, trace or file dump take their own pieces, so please don't panic when you are debugging larger project and Program Manages shows 40 or 60 allocated megabytes.
To effectively debug some program without source code, you must first understand how it works. OllyDbg contains plenty of features that facilitate this understanding.
First of all, it contains built-in code analyzer. Analyzer walks through the code, separates commands from data, recognizes different data types, procedures, decodes arguments of standard API functions (about 1900 most frequently used) and attempts to guess number of arguments of unknown functions. You can add your own function descriptions, too. It marks entry points and jump destinations, recognizes table-driven switches and pointers to strings, adds some comments and even shows the direction of jumps. Basing on the results of analysis, call tree shows which functions given procedure calls (directly or indirectly) and recognizes recursive, system and leaf procedures. If necessary, you may set decoding hints that help analyzer to decode ambiguous pieces of code or data.
OllyDbg also includes Object Scanner. If you possess libraries or object files, Scanner will locate library functions in the debugged application. Calls to standard functions take significant part of all function calls (up to 70%, according to my estimations). If you know which function is being called, it will not distract your attention and you can simply step over the call. Analyzer knows by name more than 400 standard C functions, like fopen or memcpy. I must admit however that OllyDbg in actual version is unable to locate short (consisting of hardly more than return) or similar functions (which differ only in relocations).
Object scanner also understands import libraries. If some DLL exports functions by ordinals, you will see meaningless cryptical numbers instead of function names. Developers of such DLLs usually supply import libraries that set correspondence between symbols and ordinals. Tell OllyDbg to use import library, and it will restore original names.
Object-oriented languages, like C++, use technique called name mangling that adds information on types and arguments to symbol. OllyDbg can demangle such names, making program more readable.
OllyDbg fully supports UNICODE. Almost everything you can do with ASCII string is possible with UNICODE, too.
Assembler commands are all very similar. It often happens that you don't know whether you've already traced this branch of code or not. In OllyDbg you can add own labels and write comments. This greatly facilitates debugging. Notice that once you commented some DLL, comments and labels will be available each time DLL is loaded - even if you debug different application.
OllyDbg traces standard stack frames (those created by PUSH EBP; MOV EBP,ESP). Modern compilers have option that disables generation of stack frames, in this case stack walk is not possible. When execution reaches call of known funbction, stack window decodes its arguments. Call stack window displays sequence of calls leading to the actual point of execution.
Modern OO applications extensively use structured exception handling (SEH). SEH window displays chain of exception handlers.
Many different search options allow you to find binary code or data, command or a sequence of commands, constant or string, symbolic name or a record in a run trace.
For any address or constant, OllyDbg can prepare the complete list of commands referencing this address or constant. You then walk this list and decide whether given reference is of any importance for you. For example, some function may be called explicitly, or optimizing compiler can load its address in register and then call function indirectly, or push address into the stack as a parameter - not a problem, OllyDbg will find all such places. It will even find and list all relative jumps and switches to the specified location (Really? Oh dear!..)
OllyDbg supports all standard kinds of breakpoints - unconditional and conditional, memory (on write or access), hardware or on access to the whole memory block (the last two work only under Windows ME, NT, 2000 or XP). Conditional expressions can be very complex (?break when bit 2 in [ESP+8] is set and word at location 123456 is less than 10 or EAX points to UNICODE string that begins with 'ABC', but skip first 10 breaks"). You may specify one or several commands that OllyDbg passes to plugins when application pauses. Instead of pausing, you can request logging the value of another expression (with brief explanation) or logging the arguments of function known to OllyDbg. On Athlon 2600+ running under Windows 2000, OllyDbg can process up to 25000 conditional breaks per second.
Another useful feature is tracing. OllyDbg supports two kinds of tracing: hit and run. In the first case, it sets breakpoint on every command in specified range (for example, in the whole executable code). After command is reached, it removes breakpoint and marks command as hit. This allows to check at a glance whether some branch of code was executed or not. Hit tracing is astoundingly fast, after short startup application reaches almost full speed. As INT3 breakpoint may have disastrous effect when set on data, I recommend that you don't use fuzzy recognition of procedures. Hit tracing is not available at all when code is not analyzed.
Run trace executes program step by step and records exact execution history together with contents of all registers, known arguments and optionally commands (this helps when code is self-modified). Of course, this requires plenty of memory (depending on the mode, from 15 to 50 bytes per command) but allows for precise backtracing and analysis. You can run trace only selected pieces of code, or even single commands, or you can skip quasi-linear pieces that are of no special interest. For each address, OllyDbg calculates number of times this address appears in run trace log, implementing slow but comprehensive profiling. For example, special command lets you set run trace breakpoint on every entry to recognized procedure, then profile gives you notion how frequently each routine is called. Run trace may automatically pause on command, address range or counter.
OllyDbg automatically manages threads in multithread applications. If you step or trace your program, it automatically resumes current thread and suspends all others. If you run it, OllyDbg restores previous thread state.
You can make momentary snapshot (called backup) of the memory block. OllyDbg then highlights all changes. You can save backup to file and read back, thus locating the differences between two runs. You can view backup, search for next modified piece, or undo all or selected changes. Patch manager remembers all patches applied to debugged application in previous sessions and can apply them again.
You can easily transfer your patches back to the executable file. OllyDbg will automatically correct fixups.
You can’t use OllyDbg on 16-bit Windows with Win32s. This 32-bit extender does not implement all necessary debugging functions.
You can debug neither DOS nor 16-bit NE (New Executable) files, and I have no plans to support this in the future. R.I.P., old good command prompt!
我希望您能对80x86系列处理器的内部结构有所了解,同时具有一定的编写汇编程序的能力。对于Microsoft Windows方面的知识,您也要熟悉。
OllyDbg是运行在Windows 95、Windows 98、Windows ME、Windows NT和Windows 2000系统下的一个单进程、多线程的分析代码级调试工具。它可以调试PE格式的执行文件及动态链接库,并可以对其打补丁。“代码级”意味着您可以直接与比特、字节或处理器指令打交道。OllyDbg仅使用已公开的Win32 API函数,因此它可以在所有Winodows操作系统及后继版本中使用。但是由于我没有对XP系统进行彻底测试,因此不能保证OllyDbg功能的充分发挥。注意:OllyDbg不支持对.NET程序的调试。
OllyDbg不是面向编译器的。它没有特别的规则规定必须是哪一个编译器产生的代码。因此,OllyDbg可以非常好的处理通过编译器生成的代码,或是直接用汇编写入的代码。
OllyDbg可以并行调试程序。您无须暂停执行程序,就可以浏览代码和数据,设置断点、停止或恢复线程,甚至直接修改内存。(这可以视为一种软件调试的模式,与之相对的硬件模式则是当进程在运行时调试器被阻滞,反之亦然)。假使所需的操作比较复杂,OllyDbg会让进程终止一小段时间,但是这种暂停对于用户来说是透明的。
有时进程会发生非法操作。您可以把OD设置成即时[just-in-time]调试器,它会挂接出错程序,并停在程序产生异常的地方。
通过OllyDbg,您可以调试With OllyDbg, you can debug standalone DLLs. OS can’t start DLL directly, so OllyDbg keeps, as a packed resource, small application that loads your library and allows you to call exported functions with up to 10 arguments.
OllyDbg is strongly module-oriented. Module is the main executable file (usually with extension .EXE) or dynamic-link library (usually .DLL) loaded either on startup or dynamically on request. During debugging session you set breakpoints, define new labels and comment assembler commands. When some module unloads from the memory, Debugger saves this information to file with the same name as the debugged module and extension .UDD (stays for User-Defined Data). Next time when OllyDbg loads this module, it automatically restores all debugging information, no matter which program uses this module. Suppose you are debugging Myprog1 that uses Mydll and set some breakpoints in Mydll. Then you start debugging Myprog2 that also makes use of Mydll - and all breakpoints in Mydll are still here, even if Mydll loads on different location!
Some debuggers treat memory of debugged process as a single (and mostly empty) arena 2**32 bytes in size. OllyDbg takes another approach. Here, memory consists of several independent blocks. Any operation on the memory contents is limited to the block. In most cases, this works fine and facilitates debugging. But if, for example, module contains several executable sections, you will be unable to see the whole code at once. Such cases, however, are seldom.
OllyDbg is a memory-hungry application. It allocates up to 3 MB of memory directly on startup and another megabyte or two when you first load debugged program. Each analysis, backup, trace or file dump take their own pieces, so please don't panic when you are debugging larger project and Program Manages shows 40 or 60 allocated megabytes.
To effectively debug some program without source code, you must first understand how it works. OllyDbg contains plenty of features that facilitate this understanding.
First of all, it contains built-in code analyzer. Analyzer walks through the code, separates commands from data, recognizes different data types, procedures, decodes arguments of standard API functions (about 1900 most frequently used) and attempts to guess number of arguments of unknown functions. You can add your own function descriptions, too. It marks entry points and jump destinations, recognizes table-driven switches and pointers to strings, adds some comments and even shows the direction of jumps. Basing on the results of analysis, call tree shows which functions given procedure calls (directly or indirectly) and recognizes recursive, system and leaf procedures. If necessary, you may set decoding hints that help analyzer to decode ambiguous pieces of code or data.
OllyDbg also includes Object Scanner. If you possess libraries or object files, Scanner will locate library functions in the debugged application. Calls to standard functions take significant part of all function calls (up to 70%, according to my estimations). If you know which function is being called, it will not distract your attention and you can simply step over the call. Analyzer knows by name more than 400 standard C functions, like fopen or memcpy. I must admit however that OllyDbg in actual version is unable to locate short (consisting of hardly more than return) or similar functions (which differ only in relocations).
Object scanner also understands import libraries. If some DLL exports functions by ordinals, you will see meaningless cryptical numbers instead of function names. Developers of such DLLs usually supply import libraries that set correspondence between symbols and ordinals. Tell OllyDbg to use import library, and it will restore original names.
Object-oriented languages, like C++, use technique called name mangling that adds information on types and arguments to symbol. OllyDbg can demangle such names, making program more readable.
OllyDbg fully supports UNICODE. Almost everything you can do with ASCII string is possible with UNICODE, too.
Assembler commands are all very similar. It often happens that you don't know whether you've already traced this branch of code or not. In OllyDbg you can add own labels and write comments. This greatly facilitates debugging. Notice that once you commented some DLL, comments and labels will be available each time DLL is loaded - even if you debug different application.
OllyDbg traces standard stack frames (those created by PUSH EBP; MOV EBP,ESP). Modern compilers have option that disables generation of stack frames, in this case stack walk is not possible. When execution reaches call of known funbction, stack window decodes its arguments. Call stack window displays sequence of calls leading to the actual point of execution.
Modern OO applications extensively use structured exception handling (SEH). SEH window displays chain of exception handlers.
Many different search options allow you to find binary code or data, command or a sequence of commands, constant or string, symbolic name or a record in a run trace.
For any address or constant, OllyDbg can prepare the complete list of commands referencing this address or constant. You then walk this list and decide whether given reference is of any importance for you. For example, some function may be called explicitly, or optimizing compiler can load its address in register and then call function indirectly, or push address into the stack as a parameter - not a problem, OllyDbg will find all such places. It will even find and list all relative jumps and switches to the specified location (Really? Oh dear!..)
OllyDbg supports all standard kinds of breakpoints - unconditional and conditional, memory (on write or access), hardware or on access to the whole memory block (the last two work only under Windows ME, NT, 2000 or XP). Conditional expressions can be very complex (?break when bit 2 in [ESP+8] is set and word at location 123456 is less than 10 or EAX points to UNICODE string that begins with 'ABC', but skip first 10 breaks"). You may specify one or several commands that OllyDbg passes to plugins when application pauses. Instead of pausing, you can request logging the value of another expression (with brief explanation) or logging the arguments of function known to OllyDbg. On Athlon 2600+ running under Windows 2000, OllyDbg can process up to 25000 conditional breaks per second.
Another useful feature is tracing. OllyDbg supports two kinds of tracing: hit and run. In the first case, it sets breakpoint on every command in specified range (for example, in the whole executable code). After command is reached, it removes breakpoint and marks command as hit. This allows to check at a glance whether some branch of code was executed or not. Hit tracing is astoundingly fast, after short startup application reaches almost full speed. As INT3 breakpoint may have disastrous effect when set on data, I recommend that you don't use fuzzy recognition of procedures. Hit tracing is not available at all when code is not analyzed.
Run trace executes program step by step and records exact execution history together with contents of all registers, known arguments and optionally commands (this helps when code is self-modified). Of course, this requires plenty of memory (depending on the mode, from 15 to 50 bytes per command) but allows for precise backtracing and analysis. You can run trace only selected pieces of code, or even single commands, or you can skip quasi-linear pieces that are of no special interest. For each address, OllyDbg calculates number of times this address appears in run trace log, implementing slow but comprehensive profiling. For example, special command lets you set run trace breakpoint on every entry to recognized procedure, then profile gives you notion how frequently each routine is called. Run trace may automatically pause on command, address range or counter.
OllyDbg automatically manages threads in multithread applications. If you step or trace your program, it automatically resumes current thread and suspends all others. If you run it, OllyDbg restores previous thread state.
You can make momentary snapshot (called backup) of the memory block. OllyDbg then highlights all changes. You can save backup to file and read back, thus locating the differences between two runs. You can view backup, search for next modified piece, or undo all or selected changes. Patch manager remembers all patches applied to debugged application in previous sessions and can apply them again.
You can easily transfer your patches back to the executable file. OllyDbg will automatically correct fixups.
You can’t use OllyDbg on 16-bit Windows with Win32s. This 32-bit extender does not implement all necessary debugging functions.
You can debug neither DOS nor 16-bit NE (New Executable) files, and I have no plans to support this in the future. R.I.P., old good command prompt!
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
赞赏
他的文章
- [分享]咕咚智能健康称的开源硬件下载地址 9484
- [推荐]打造无人机编队 15371
- [调查]那些年,一起玩过的智能外设 11423
- [原创]看雪主办:走进企业看安全--第4站:安全管家(12月21日)--免费报名 29722
- 看雪主办:走进企业看安全--第3站:360公司(11月30日) 21762
赞赏
雪币:
留言: