General principles of ollydbg full tutorial [General principles]

Source: Internet
Author: User
II. General principle [General principles]

I hope you can understand the internal structure of the 80x86 series processor and write assembler programs. You must be familiar with Microsoft Windows.

Ollydbg is a single-process, multi-thread analysis code-level debugging tool running on Windows 95, Windows 98, Windows ME, Windows NT, and Windows 2000 systems. It can debug pe-format execution files and dynamic link libraries, and patch them. "Code-level" means you can directly deal with bit, byte, or processor commands. Ollydbg only uses open Win32 API functions, so it can be used in all Windows operating systems and later versions. However, since I have not thoroughly tested the XP system, the full use of the ollydbg function cannot be guaranteed. Note: ollydbg does not support debugging. net programs.

Ollydbg is not compiler-oriented. It does not have special rules to specify which compiler must generate code. Therefore, ollydbg can handle the code generated by the compiler very well, or directly write the code using the assembly.

Ollydbg can debug programs in parallel. You can browse code and data, set breakpoints, stop or recover threads, and even directly modify the memory without suspending the execution program. (This can be regarded as a software debugging mode. The opposite hardware mode is that the debugger is blocked when the process is running, and the opposite is true ). If the required operations are complex, the ollydbg will terminate the process for a short period of time, but the suspension is transparent to users.

Sometimes the process is not permitted. You can set ollydbg to the instant [just-in-time] debugger, which will hook up the program with errors and stop it in the place where the program generates exceptions.

With ollydbg, You can debug a separate DLL [standalone DLLs] file. The operating system cannot directly run DLL files. Therefore, ollydbg compresses a DLL-loaded applet into resources. This program allows you to call output functions with a maximum of 10 parameters.

Ollydbg is fully oriented to the module [module-oriented. The module [module] includes an executable file (the extension is usually. EXE) and a dynamic link library that is loaded at startup or when needed (the extension is usually. dll
). During debugging, you can set breakpoints [breakpoints], define new labels [labels], and comment [comment] Assembly commands. When a module detaches [unload] from the memory, the debugger saves the information in the file. The file name is the name of the module and the extension is. UDD (indicating the User-Defined file [user-defined data]) When ollydbg loads the module next time, it automatically restores all debugging information, no matter which program uses this module. Assume that you are debugging the program myprog1, which uses mydll. You have set some breakpoints in mydll, and then you start to debug myprog2. This program also uses mydll. At this time, you will find that all the breakpoints in mydll still exist, even if mydll is loaded to different locations!

Some debuggers regard the memory of the debugged process as a single (and mostly empty) area with a size of 2 ^ 32 bytes. Ollydbg uses a different technology: here, the memory is composed of many independent blocks, and any operations on the memory content are limited in their respective blocks. In most cases, this method works well and facilitates debugging. However, if the module contains several executable segments [executable sections], you will not be able to see all the code at once. However, this situation is rare.

Ollydbg is a memory-consuming program [memory-hungry application]. It requires 3 MB at startup, and one to two MB of memory is required when you load the program to be debugged for the first time. Each analysis, backup, Trace, or file data display requires a certain amount of memory. Therefore, when you debug a large project and find that the program manager shows that 40 or 60 MB of memory is occupied, do not panic.

To effectively Debug programs without source code, you must first understand how it works. The large number of features of ollydbg can make this understanding very easy.

First, ollydbg contains a built-in Code Analyzer. Analyzer traverses the entire code, separates commands and data, identifies different data types and processes, and analyzes standard API functions (about 1900 most commonly used functions) and try to guess the number of parameters of the unknown function. You can also add your own function description [your own function descriptions]. It marks the entry point and jump destination of the program, recognizes the jump table [Table-driven Switches] And the pointer to the string, adds some comments, and even marks the direction of the jump. Based on the analysis results, the call tree [call tree] shows which functions are called by the specified process (directly or indirectly) and identifies recursive calls, system calls, and leaf processes [Leaf procedures]. If necessary, you can set the decoding prompt [decoding hints] to help the analyzer parse ambiguous code or data.

The ollydbg also contains the object scanner [object scanner]. If you have a library file [libraries] or a target file [object files], the scanner locates these library functions in the program to be debugged. In all function calls, calls to standard functions are a very important part (I estimate 70% ). If you know the function of the function to be called, you do not have to focus on this function. You can simply step through [
Step over] this call. Analyzer knows more than 400 standard C functions, such as fopen and memcpy. However, I must admit that the current version of ollydbg cannot locate very short functions (not much more than a return command) or similar functions (only different in relocation ).

The object scanner [object libraries] can also identify the input Library [import libraries]. If a DLL is output by serial number, you will not see the function name, but will only find a bunch of meaningless mysterious numbers. Developers of such DLL usually provide an input library to implement the correspondence between function Symbol names and serial numbers. Let ollydbg use this input library, and it will restore the original function symbol name.

An object-oriented language (such as C ++) uses a technology called name-modifier [name mangling] to add function types and parameters to the function name. Ollydbg can decode the function name [demangle] to make the program easier to read.

Note: The name modification of c ++ is a process in which the compiler converts the name of a function into a unique string. This string is used for the class, namespace, and parameter table of the function, and others. The name modification of c ++ is applicable to static member functions and non-static member functions. One of the advantages of static function name modification is that two or more static member functions can be declared using the same name in different classes without name conflicts.

Ollydbg fully supports Unicode, and almost all operations on ASCII strings can also be applied to Unicode.

Assembly commands are similar. You may often wonder if you have tracked a piece of code. In ollydbg, you can add your own label [labels] and comment [comments]. These greatly facilitate debugging. Note that once you have commented on a DLL, the annotation and tag are valid each time this DLL is loaded-although you are debugging different programs.

Ollydbg can trace standard stack frames [stack frames] (created by push EBP, mov EBP, and ESP ). Modern compilers have the option to prohibit the generation of a standard stack framework. In this case, allocate the stack [stack walk
] Is impossible. When the program runs on a known function, the Stack window [Stack window] parses its parameters and calls the stack [Call Stack] window to display the sequence of functions called at the current position.

Modern object-oriented applications use a technology called [structured exception handling, she] widely. The she window [seh window] displays the exception handling link.

Multiple different search [Search] options allow you to find binary code or data, command or command sequence, constant or string, symbol name, or a record in the run trace.

For any address or constant, ollydbg can find a list of all commands from [Referencing] to this address or constant. Then you can find the important reference in this list. For example, a function may be called directly, or the address is put into the register for indirect call after the compiler optimization, or the address is pushed into the stack as a parameter-no problem, ollydbg will find all such places. It can even find and list all jumps related to a specified location. (True? Oh, my God !......)

Ollydbg supports all standard types of breakpoints [breakpoints]-non-conditional and conditional breakpoints, memory breakpoints (write or access), hardware breakpoint, or up/down breakpoint on the entire memory block (the last two functions are only valid in window me, NT, 2000, XP ). Conditional expressions can be very complex ("when the 2nd bits of [esp + 8] are set and the word [word] At the 123456 position is less than 10, or eax points to a unicode string starting with "ABC", but skips the first 10 breakpoints and causes 11th interruptions "). You can set one or more commands. When the program is suspended, ollydbg passes the commands to the plug-in [plugins]. In addition to pausing, you can also record the value of an expression (which can be briefly described) or record the parameters of functions known to ollydbg. In the athlon 2600 + and Windows2000 environments, ollydbg can process up to 25000 conditional breakpoints per second.

Another useful feature is tracking. Ollydbg supports two tracking methods: Hit and run. In the first case, it sets a breakpoint for each instruction within the specified range (for example, in all executable code ). When the set-off command is reached, ollydbg clears the breakpoint and marks the command as hit. This method can be used to check whether a code segment is executed. Hit tracking speed is astonishing, and after a very short start, the program almost reached full speed (note: this should be compared with the speed when debugging is not performed ). Because the int3 breakpoint may have a catastrophic impact on the data, we recommend that you do not use the fuzzy recognition process. Hit tracking cannot be used when the code is not analyzed.

Run trace [run trace] is a step-by-step program execution, records the precise running history, the content of all registers, known parameters, and optional commands at the same time (this is helpful when the code is self-modified ). Of course, this requires a lot of memory (each command requires 15 to 50 bytes, depending on the debugging mode), but it can be precisely traced and analyzed. You can perform run tracking only in the selected code segment or even a command, or you can skip irrelevant code. For each address, the ollydbg can calculate the number of times this address appears in the run trace log. Although the execution will be slow, the code execution statistics can be obtained. For example, if a command allows you to perform run tracking at the entrance of each identified process, the [Profile] will count the number of times each process is called. When a command, an address range, or a command counter reaches a certain value, the run trace can automatically suspend [Pause].

In a multi-threaded program, ollydbg can automatically manage threads [threads]. If you debug or track programs in one step, it automatically restores the current thread and suspends other threads. If you run the program, ollydbg restores the previous thread status.

You can create snapshots (called backups) for memory blocks ). Ollydbg highlights all the changes. You can save the backup to a file or read it from the file to find the differences between the two operations. You can view backups, search for the next change, and restore All or selected changes. The Patch Manager [Patch Manager] records all patches from the last application to the program and can be applied again during the next debugging.

You can easily add your patch to the executable file. The ollydbg is automatically corrected.

You cannot use ollydbg in Windows with Win32 16-bit. This 32-bit extended operating system cannot implement some required debugging functions.

You can neither debug the DOS program nor debug 16-bit NE (new executable) files. I do not plan to support these files in future versions. Rest in peace, an old and beautiful command prompt!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.