Nvperfhud4 is an application of NVIDIA's geforce6 series graphics card to DX9.ProgramA powerful tool for performance analysis. It analyzes the performance of graphics applications from both the macro and micro perspectives. On the macro level, we can see how much time is consumed by the CPU and GPU, how much time is consumed by PS and VS, CPU wait time, and GPU wait time respectively. Micro view shows the process of each DP call, showing the time occupied by PS, VS, and raster in each DP call process, and the Vs and PS used by each DP call.CodeThe textures used and all the painting states. To get such a powerful function to modify the application code, you only need to create a 3D device using the following method:
G_pd3d-> createdevice (g_pd3d-> getadaptercount ()-1, d3ddevtype_ref, hwnd, d3dcreate_hardware_vertexprocessing, & d3dpp, & g_pd3ddevice );
The most critical parameter is the first two. That is to say, as long as applications that create 3D devices follow the above method, they can be analyzed through nvperfhud. To analyze farcry with nvperfhud, locate the call location of the createdevice () function in the binary code of farcry, and modify the call parameters as required. The following describes the process.
Use IDA to open the d3d9 rendering module xrenderd3d9 of farcry. DLL, the string we are interested in is found in the strings window "creating d3d device (adapter format: % s, backbuffer format: % s, depth format: % s )", right-click the menu and jump to the address that references this string. The following code is found:
01 push offset acreatingd3ddev; "creating d3d device (adapter format: % s "...
02. Text: Pushed 54cf3 push ECx
03. Text: 201754cf4 call dword ptr [EDI + 8]
04. Text: 10954cf7 mov eax, dword_389e67d8
05. Text: 201754cfc add ESP, 14 h
06. Text: 10954cff test eax, eax
07. Text: 201754d01 jnz short loc_38054d51
08. Text: 10954d03 mov Al, [ESI + 1d1_h]
09. Text: Certificate 54d09 test Al, Al
10. Text: 201754d0b JZ short loc_38054d15
11. Text: 10954d0d mov eax, [ESI + 1d65ch]
12. Text: 201754d13 JMP short loc_38054d1b
13. Text: 255.54d15
14. Text: 201754d15 loc_38054d15:; Code xref: sub_38054b00 + 20bj
15. Text: 10954d15 mov eax, [ESI + 1d694h]
16. Text: 255.54d1b
17. Text: 201754d1b loc_38054d1b:; Code xref: sub_38054b00 + 2017j
18. Text: 10954d1b mov EBP, [esp + 21ch + var_20c]
19. Text: 10954d1f mov ECx, [eax]
20. Text: 10954d21 mov eax, [ESI + 1d620h]
21. Text: 10954d27 mov edX, [eax]
22. Text: Listen 54d29 Lea EDI, [ESI + 1e698h]
23. Text: Pushed 54d2f push EDI
24. Text: Listen 54d30 Lea EBX, [ESI + 1d6c0h]
25. Text: Pushed 54d36 push EBX
26. Text: Pushed 54d37 push EBP
27. Text: 10954d38 mov EBP, [ESI + 1f494h]
28. Text: 10954d3e mov EBP, [EBP + 0]
29. Text: Pushed 54d41 push EBP
30. Text: 10954d42 mov EBP, [esp + 22ch + var_208]
31. Text: 10954d46 mov EBP, [EBP + 4]
32. Text: Pushed 54d49 push EBP
33. Text: Pushed 54d4a push ECx
34. Text: Pushed 54d4b push eax
35. Text: 10954d4c call dword ptr [edX + 40 h]
36. Text: 201754d4f JMP short loc_38054d8a
37. Text: 255.54d51
38. Text: 201754d51 loc_38054d51:; Code xref: sub_38054b00 + 201j
39. Text: 10954d51 mov ECx, [esp + 21ch + var_20c]
40. Text: 10954d55 mov edX, [ESI + 1f494h]
41. Text: 10954d5b mov eax, [ESI + 1d620h]
42. Text: 10954d61 mov EBP, [eax]
43. Text: 12754d63 Lea EDI, [ESI + 1e698h]
44. Text: Pushed 54d69 push EDI
45. Text: 38054d6a Lea EBX, [ESI + 1d6c0h]
46. Text: Pushed 54d70 push EBX
47. Text: 10954d71 and ECx, 0 ffffefh
48. Text: Pushed 54d74 push ECx
49. Text: 10954d75 mov ECx, [edX]
50. Text: Pushed 54d77 push ECx
51. Text: Pushed 54d78 push 2
52. Text: Pushed 54d7a push eax
53. Text: 201754d7b call dword ptr [EBP + 10 h]
54. Text: 10954d7e mov edX, [ESI + 1d620h]
55. Text: Pushed 54d84 dec eax
56. Text: Pushed 54d85 push eax
57. Text: Pushed 54d86 push edX
58. Text: 201754d87 call dword ptr [EBP + 40 h]
Line 1st will push the string address we are interested in into the stack. Line 3rd should be a call such as an output log. The following should not be far from the call to create a device (createdevice. Let's take a look at the definition of the idirect3d9 interface:
Declare_interface _ (idirect3d9, iunknown)
{
/*** Iunknown Methods ***/
Stdmethod (QueryInterface) (This _ refiid riid, void ** ppvobj) pure;
Stdmethod _ (ulong, addref) (this) pure;
Stdmethod _ (ulong, release) (this) pure;
/*** Idirect3d9 Methods ***/
Stdmethod (registersoftwaredevice) (This _ void * pinitializefunction) pure;
Stdmethod _ (uint, getadaptercount) (this) pure;
Stdmethod (getadapteridentifier) (This _ uint adapter, DWORD flags, d3dadapter_identifier9 * pidentifier) pure;
Stdmethod _ (uint, getadaptermodecount) (This _ uint adapter, d3dformat format) pure;
Stdmethod (enumadaptermodes) (This _ uint adapter, d3dformat format, uint mode, d3ddisplaymode * pmode) pure;
Stdmethod (getadapterdisplaymode) (This _ uint adapter, d3ddisplaymode * pmode) pure;
Stdmethod (checkdevicetype) (This _ uint adapter, d3ddevtype devtype, d3dformat adapterformat, d3dformat backbufferformat, bool bwindowed) pure;
Stdmethod (checkdeviceformat) (This _ uint adapter, d3ddevtype devicetype, d3dformat adapterformat, DWORD usage, d3dresourcetype Rtype, d3dformat checkformat) pure;
Stdmethod (checkdevicemultisampletype) (This _ uint adapter, d3ddevtype devicetype, d3dformat surfaceformat, bool initialize wed, d3dmultisample_type multisampletype, DWORD * pqualitylevels) pure;
Stdmethod (checkdepthstencilmatch) (This _ uint adapter, d3ddevtype devicetype, d3dformat adapterformat, d3dformat rendertargetformat, d3dformat depthstencilformat) pure;
Stdmethod (checkdeviceformatconversion) (This _ uint adapter, d3ddevtype devicetype, d3dformat sourceformat, d3dformat targetformat) pure;
Stdmethod (getdevicecaps) (This _ uint adapter, d3ddevtype devicetype, d3dcaps9 * pcaps) pure;
Stdmethod _ (hmonitor, getadaptermonitor) (This _ uint adapter) pure;
Stdmethod (createdevice) (This _ uint adapter, d3ddevtype devicetype, hwnd hfocuswindow, DWORD behaviorflags, d3dpresent_parameters * ppresentationparameters, idirect3ddevice9 ** parameters) pure;
# Ifdef d3d_debug_info
Lpcwstr version;
# Endif
};
After counting the number, we can see that createdevice () is the 17th function of the interface, that is, its offset in the virtual function table should be 0x40. Looking back at the assembly code above, we can find that there are two function calls like "Call dword ptr [EBP + 40 h]", which should be for createdevice () the function is called twice. Let's look at the second row and call "Call dword ptr [EBP + 10 h]". We know this is the getadaptercount () function against the definition of the idirect3d9 interface, and the second row calls the getadaptercount () function () is this the first parameter of the createdevice () function we need? Let's see if the second parameter is also the required d3ddevtype_ref. The command "Push 2" in line 51st is pushed to the second parameter of the createdevice () function. Looking for the relevant header file, we find that the value of d3ddevtype_ref is exactly 2, which makes us believe that the createdevice () In line 58th is () the call is provided for nvperfhud. We don't even need to modify the call parameters. We just need to import the execution path of the program here.
Switch Ida's code window to the graphic view to make it easier to see the code jump path.
The code is divided into two forks at the top, and the green arrow on the right points to the createdevice () call we need, we only need to modify the "jnz short loc_38054d51" command in the top box to "JZ short loc_38054d51", that is, obtain the inverse condition judgment, this allows the code to go through the execution path we need. In the hexadecimal editing window, find the relevant code, change 75 to 74 (jnz to JZ), and then save the disk to complete the modification of xrenderd3d9. dll.