Recent

Author Topic: DLL hook/performance questions  (Read 6308 times)

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: DLL hook/performance questions
« Reply #15 on: April 10, 2019, 04:51:50 pm »
Inside your dll you also need {$calling stdcall}
You do not need to import functions from Kernel32/User32. They are already imported for you inside unit Windows. Just use the proper way to refer to them, like: Windows.FindFirstFile.

Mike_HDF

  • New Member
  • *
  • Posts: 15
Re: DLL hook/performance questions
« Reply #16 on: April 10, 2019, 05:14:17 pm »
Inside your dll you also need {$calling stdcall}

I did, thanks!

You do not need to import functions from Kernel32/User32. They are already imported for you inside unit Windows. Just use the proper way to refer to them, like: Windows.FindFirstFile.

I need the kernel32 functions to export them, that's the trick so the game works as espected (need to test with the modified Find* functions, can wait!).

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: DLL hook/performance questions
« Reply #17 on: April 10, 2019, 06:00:06 pm »
I need the kernel32 functions to export them, that's the trick so the game works as espected (need to test with the modified Find* functions, can wait!).
Not only you shouldn't need to do that but, that won't cause the exe program to call the functions in your dll.

In the exe file, there is an import descriptor (one or more per import library) and, the descriptor tells the loader the name of the library where to find the functions.  In the case of kernel32, the descriptor says "kernel32.dll", the loader will completely ignore your dll.   The only time your technique works is when your dll is a replacement for the original dll. 

Somewhere you have to patch the exe's Import Address Table (IAT) so that the IAT has the address of YOUR functions in your dll instead of the address of those functions in kernel32.

I don't see anywhere in your code that you are patching the exe's IAT. 

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Mike_HDF

  • New Member
  • *
  • Posts: 15
Re: DLL hook/performance questions
« Reply #18 on: April 10, 2019, 07:50:38 pm »
In the exe file, there is an import descriptor (one or more per import library) and, the descriptor tells the loader the name of the library where to find the functions.  In the case of kernel32, the descriptor says "kernel32.dll", the loader will completely ignore your dll.

Yes, I modified the exe so kernel32.dll is now sortfile.dll. For what you told me I know is not the best practice, but that's the way the community has been upgrading the game.

The game is running with the new DLL and I verified that it loads the files in alphabetical order. The hack is working well!

Thanks for your help.

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: DLL hook/performance questions
« Reply #19 on: April 10, 2019, 08:53:04 pm »
Yes, I modified the exe so kernel32.dll is now sortfile.dll. For what you told me I know is not the best practice, but that's the way the community has been upgrading the game.
I wholeheartedly agree that isn't the "best practice" but, I like it.  My concern with that method is that Windows is very protective of its system dlls and when you modify them, it restores the original from copies it keeps at hand (I know because I've used that method too... <chuckle>)

edit: never mind, you modified the exe not kernel32.

The game is running with the new DLL and I verified that it loads the files in alphabetical order. The hack is working well!

Thanks for your help.
You're welcome.  I'm pleased you got it working. 

« Last Edit: April 10, 2019, 09:14:01 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018