jeudi 29 mai 2014

c ++ - D3D->CreateDevice() ne parvient pas à l'intérieur d'une DLL injecté - Stack Overflow


I'm writing a DLL that hooks certain D3D-functions by changing needed pointers in the VMT of the injected process. The algorythm is like:



  1. Obtain a dummy window handle.

  2. Init a dummmy D3D-object, create a D3D-device.

  3. Grab the needed offsets (VMT - D3D base address).

  4. Destroy the D3D object and the window handle.

  5. Get the D3D*.dll base of the injected process.

  6. Construct the actual VMT pointers (offsets + base).

  7. Search for them in the process heap.

  8. If found - change the pointers to my own.


It works totally fine within the application, where I init D3D, start the drawing loop and then fire the hooking procedure, but it doesn't work from a DLL - for some reason it crashes while trying to create a dummy device with last error code = 126 ("The specified module could not be found", though D3D*.dll loads correctly).


I know that at the same moment there can be only one D3DDevice inited, but in my test app I can create more of 1 - only 1 works, but I still can grab the VMT.


So, the question is - what is the difference between running the same code from EXE and from DLL?



I'm writing a DLL that hooks certain D3D-functions by changing needed pointers in the VMT of the injected process. The algorythm is like:



  1. Obtain a dummy window handle.

  2. Init a dummmy D3D-object, create a D3D-device.

  3. Grab the needed offsets (VMT - D3D base address).

  4. Destroy the D3D object and the window handle.

  5. Get the D3D*.dll base of the injected process.

  6. Construct the actual VMT pointers (offsets + base).

  7. Search for them in the process heap.

  8. If found - change the pointers to my own.


It works totally fine within the application, where I init D3D, start the drawing loop and then fire the hooking procedure, but it doesn't work from a DLL - for some reason it crashes while trying to create a dummy device with last error code = 126 ("The specified module could not be found", though D3D*.dll loads correctly).


I know that at the same moment there can be only one D3DDevice inited, but in my test app I can create more of 1 - only 1 works, but I still can grab the VMT.


So, the question is - what is the difference between running the same code from EXE and from DLL?


0 commentaires:

Enregistrer un commentaire