| View previous topic :: View next topic |
| Author |
Message |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Thu Jun 02, 2016 2:44 am Post subject: Trying to make a proxy dll in Delphi 7 |
|
|
OK so, the game only uses 2 functions from ddraw.dll:
function DirectDrawCreate(a, b, c: pointer): integer; stdcall; external 'ddraw.dll';
function DirectDrawEnumerateA(a, b: pointer): integer; stdcall; external 'ddraw.dll';
exports
DirectDrawEnumerateA, DirectDrawCreate;
And that's what I set at the top of my dll... and of course, my dll is named ddraw.dll. I place that in the same place as the executable. It doesn't work. While the export is right - I am told that what I really need to be doing is forwarding from my dll to the real dll. A few examples (rather rubbish ones) show getprocaddress being used with loadlibrary. But whatever I try - the game does not load correctly.
I have no clue what to do. I just need to know how to create a proxy dll. Anyone? I really have no clue where and how to do that.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Thu Jun 02, 2016 1:15 pm Post subject: |
|
|
None of those are working Delphi examples - especially of the 2 functions I listed above. I'd already seen those examples too - but I have no idea how to relate it to the 2 functions above in Delphi (Pascal) code. It looks easy to do - but any mistake in syntax or approach will mean I am trial and erroring for the next week.
I don't need a complete solution - I just need those 2 functions reconciling with the real ddraw.dll.
I rename MY dll ddraw.dll - the game loads it - it forwards (or whatever the terminology is) the functions to the correct ddraw.dll and leaves me able to edit the game. The second part is done, the first part isn't. The game tries to use the functions I listed and obviously can't - so crashes.
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25818 Location: The netherlands
|
Posted: Thu Jun 02, 2016 1:53 pm Post subject: |
|
|
get rid of external 'ddraw.dll'; and use loadlibrary with getprocaddress. (make sure loadlibrary has the full path to it, else it'll load your dll)
Or, rename the original ddraw.dll to bla.dll and change external 'ddraw.dll'; to external 'bla.dll';
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Thu Jun 02, 2016 4:29 pm Post subject: |
|
|
Edit. Think I may have solved it. Seems ddraw calls on a ton of things that all need setting up in the exports (like ReleaseDDThreadLock). Not just those 2 functions - it branches out.
Edit 2
Yeah - it's fixed. Thanks again!
===============
Thanks Well, I had a go - but clearly I don't know what I am doing. I understand I need to be passing the address of the real function - but I have no clue how the full code works. I am sitting here literally seeing it either not compile or just not doing anything when it does.
I deleted the external bit but now it jumps to the bottom of my dll and expects more (even when I added my rendition of getprocaddress, which is probably bogus). Keeps asking for ";" and not "end.", when I have those 2 functions at the top without external.
I am at a loss. I understand what it's meant to do but I don't know how to actually make the code work.
Any full example? Because I don't think I am going to manage it otherwise.
Also, I think it has to be explicit and not implicit. https://msdn.microsoft.com/en-us/library/windows/desktop/gg426116(v=vs.85).aspx
| Quote: | | You must use LoadLibrary to explicitly link to Ddraw.dll and then use GetProcAddress to access the DirectDrawCreate function. |
If I use implicit, it comes up with other error message
Procedure Entry Point ReleaseDDThreadLock could not be located in dynamic link library DDRAW.DLL
(although that might be because I didn't specify the correct in / out parameters?)
|
|
| Back to top |
|
 |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Fri Jun 03, 2016 1:01 am Post subject: |
|
|
OK this is just to verify that I am actually doing this the right way and not some really crap way. If this isn't how it's meant to be done - or if it can be improved upon - let me know I'll stick to the 2 functions I mentioned.
| Code: | Type
TDirectDrawCreate = Function (a: Pointer; out b: Pointer; c: Pointer): HResult; stdcall;
TDirectDrawEnumerateA = Function (a: Pointer; b: Pointer): HResult; stdcall;
Var
CreateFunc : TDirectDrawCreate;
EnumerateFunc : TDirectDrawEnumerateA;
DLLHandle: THandle;
function DirectDrawCreate (a: Pointer; out b: Pointer; c: Pointer): HResult; stdcall;
begin
CreateFunc(a,b,c); // Is this how you make this dll call the correct dll?
end;
function DirectDrawEnumerateA (a: Pointer; b: Pointer): HResult; stdcall;
begin
EnumerateFunc(a,b);
end;
exports
DirectDrawEnumerateA, DirectDrawCreate;
Begin
DLLHandle:= LoadLibrary('c:\windows\syswow64\ddraw.dll'); // I will make sure it knows which to load based on operating system later. [Loadlibrary automatically finds correct one if you use path to system folder).
if DLLHandle <> 0 then
begin
@CreateFunc := GetProcAddress(DLLHandle, 'DirectDrawCreate');
@EnumerateFunc := GetProcAddress(DLLHandle, 'DirectDrawEnumerateA');
end;
end. |
Another question is - should I use "pointer" in place of the microsoft types like "pguid" - Will that even matter?
Like I say, this code does appear to be working.
Last edited by dlpb on Thu Jun 09, 2016 4:27 am; edited 3 times in total |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25818 Location: The netherlands
|
Posted: Fri Jun 03, 2016 2:54 am Post subject: |
|
|
you are not returning the result of the funtions
result:=createFunc...
result:=enumeratefunc...
you can use pointer just fine, but it's easier to make mistakes that way
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Fri Jun 03, 2016 3:08 am Post subject: |
|
|
| Ah! Of course. But that's how it's done, I take it? As I have done it?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25818 Location: The netherlands
|
Posted: Fri Jun 03, 2016 3:27 am Post subject: |
|
|
Yeah, that should work
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Fri Jun 03, 2016 3:50 am Post subject: |
|
|
| So basically no other way than using types?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25818 Location: The netherlands
|
Posted: Fri Jun 03, 2016 3:55 am Post subject: |
|
|
well, you could use var
| Code: |
Var
CreateFunc : Function (a: Pointer; out b: Pointer; c: Pointer): HResult; stdcall;
EnumerateFunc : Function (a: Pointer; b: Pointer): HResult; stdcall;
|
but besides that no.
Or try my other suggestion(untested) and rename(copy) the original ddraw.dll to something else and static link to the functions you don't want to hook
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Fri Jun 03, 2016 4:04 am Post subject: |
|
|
I tried var before - but this time it appears to have worked. What's the difference? I guess none since it's just passing a pointer to the function?
(I already tried renaming - ddraw does not like it).
|
|
| Back to top |
|
 |
|