During the winter vacation, it may take about half a month to write this script intermittently, but it may be a few days late in the next year.
In the past two days, some bugs have been cleared, the Code has been sorted out, and we plan to release the code.
Observer is written based on Microsoft's detour3.0.
Applicable objects: exe files written in c/c ++ (map files need to be generated)
Download Observer address: http://pan.baidu.com/share/link? Consumer id = 281171 & uk = 2133448544
Download Source Code address (vs2008 project): https://github.com/youzhonghui/Observer
BUG can be sent to http://1.obser.sinaapp.com/
To compile the source code, copy the include and lib. X86 files of detour3.0 to the include and lib folders under Microsoft Visual Studio 9.0 \ VC installation directories of vs2008.
The following is a user guide.
Principles:
In the link stage, you can choose to let the connector generate a map file. The map file contains information such as the function name and the expected loading address of the function. When the program is loaded, it will not be relocated (the exe part). Therefore, based on this information, you can use detour to inject dll to change the function process.
If you want to view the code, pay attention to the following points for easy understanding:
1. Only the function you have compiled is the Observer test object, timing rules, etc. You can refer to the following "Observer User Guide".
2. The number of test objects is uncertain. Therefore, you need to dynamically generate the Execution Code at runtime to correspond to each function. (I used to think about using a function to enclose some functions, but this would be complicated and inefficient)
3. The method for generating and executing code is to first write a function as "template", then copy the code of this template each time, and then modify the code in the place that needs to be modified (mark the template)
4. The "template" is the myFunc function. QueryPerformanceCounter is called as the timer. Call a function using ret instead of call (--| call is used to calculate the relative distance. ret can use an absolute address)
5. be careful to maintain the stack balance, and save the changes to the register first, because I do not know the parameters of the tested function, fastcall or stdcall, and whether the returned values use the stack, all I have to do is carefully save the original status and then change it back.
Observer User Guide:
Author: nanshu
Blog: http://www.cnblogs.com/nanshu/
Observer Forum: http://1.obser.sinaapp.com/
This software is green and does not require installation.
Required during running
Observer_shell_v2.0.exe
Observer-kernel_v1.0.dll
withdll.exe
The three files are in the same directory.
Usage:
Run observer_shell_v2.0.exe
You can see that you are waiting for the input.
Drag the target exe file to be tested into a black box and press Enter.
Ensure that the map file and the target exe file are in the same directory
The name_result.txt file will be generated in the directory of the target file after running, that is, the test result.
There is a test in the sample folder. Run observer_shell_v2.0.exe and then drop test into the black box and press Enter. After the operation, a corresponding result file is generated.
How to generate a map file:
Map is generated in the link phase. If IDE is used, it can be found on the link page of project properties.
For example, vc6 is a project-> set-> connection-> Generate a map file.
Vs2008 is properties-> linker-> Debugging-> Generate Map File
Other ides or makefiles can be used for online check.
Note:
Do not contain spaces in the path
The first line of name_result.txt contains Minimum interval.
Example: Minimum interval: 0.000411 MS
Indicates that if a function is used for less than 0.000411 MS during one execution, all time will not be recorded and the call time for the function in the result is 0
Frequency indicates the number of times the function is called.
Time indicates the Time when the function runs. Note: Please carefully read the following timing rules
If your platform does not support high-precision timing (do not support timer In the first line of name_result.txt), you cannot use this program.
If the function you write is short, it may be optimized by the compiler as an inline function and won't appear in the map file. You can remove this option from the compiler optimization options.
Vc can use # pragma optimize ("", off) to cancel optimization.
Timing rules:
The test object is a self-written function. The called API or function in the c standard library is not used as the test object.
If function A and function B are all test objects and function A calls function B, the last time of function A is the start time and end time of function A-the start time and end time of function B. Recursion is also used for statistics and will not overlap.