Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Please Help with ApiHook

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
cleiton
Newbie cheater
Reputation: 0

Joined: 05 Mar 2014
Posts: 21

PostPosted: Wed Mar 05, 2014 1:25 pm    Post subject: Please Help with ApiHook Reply with quote

I'm coding an Anti Hack for a game, the hackers usually use DLL Injection to hack my game, so I decided to code an Anti DLL Injection that hooks LoadLibrary API, I'm having a problem, when I hook LoadLibrary API my game does not load itself, because the game needs LoadLibrary API.

Look what I'm doing:
Code:

var
TLoadLibrary: function (lpLibFileName: PChar): HMODULE; stdcall;

function OLoadLibrary(lpLibFileName: PChar): HMODULE; stdcall;
begin
result:=0;
end;

procedure DllMain(reason: integer);
begin
case reason of
DLL_PROCESS_DETACH:;
end;
DLL_PROCESS_ATTACH:
ApiHook('KERNEL32.DLL', 'LoadLibrary', @OLoadLibrary, @TLoadLibrary);
end;
end;



How to add an exception that only allow my game to use LoadLibrary? And does not allow external process to use that against my game?

Thank u all
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25823
Location: The netherlands

PostPosted: Wed Mar 05, 2014 11:44 pm    Post subject: Reply with quote

Try using a flag that allows modules to be loaded, until the game has been fully loaded.

it won't block dll injections that start before your game is loaded, but nothing can stop that. (if they wish you could even make the system dll's auto load that)

_________________
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
View user's profile Send private message MSN Messenger
cleiton
Newbie cheater
Reputation: 0

Joined: 05 Mar 2014
Posts: 21

PostPosted: Fri Mar 07, 2014 9:06 am    Post subject: Reply with quote

Code:
function OLdrLoadDll(szcwPath: PWideChar; pdwLdrErr: dword; pUniModuleName: PUnicodeString; pResultInstance: PDWORD): Cardinal;stdcall;
const
  ALLOWED_MODULES : array [0..9] of string = ('ADVAPI32.dll', 'GDI32.dll', 'IMM32.dll',
                                              'KERNEL32.dll', 'OLEAUT32.dll', 'SHELL32.dll',
                                              'USER32.dll', 'WINMM.dll', 'ws2_32.dll', 'ole32.dll');
var
  s : string;
  found : boolean;
  i : integer;
begin
  s := LowerCase(ExtractFileName(String(szcwPath)));
  found := false;
  for i := 0 to length(ALLOWED_MODULES) do
  begin
    if s = ALLOWED_MODULES[i] then
    begin
      found := true;
      break;
    end;
  end;
  if not found then
  begin
    pResultInstance:=0;
  end;
end;


tried that but doesn't work still blocking game dll's
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25823
Location: The netherlands

PostPosted: Fri Mar 07, 2014 9:23 am    Post subject: Reply with quote

That's not allowing all modules till the game has been loaded, that's just an exclusion list. (and I think you're missing a few, like nvidia's dll's...)

You should use a global flag used by the game to indicate it's loaded

Also, your code won't work because you're never calling the original loader (and on failure you're setting pResultInstance to 0 which is a local parameter, you need to set pResultInstance^ to 0)


OutputDebugString is useful here

_________________
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
View user's profile Send private message MSN Messenger
cleiton
Newbie cheater
Reputation: 0

Joined: 05 Mar 2014
Posts: 21

PostPosted: Fri Mar 07, 2014 9:35 am    Post subject: Reply with quote

Surprised

don't know how to do that

can u give me some tips?
Back to top
View user's profile Send private message
cleiton
Newbie cheater
Reputation: 0

Joined: 05 Mar 2014
Posts: 21

PostPosted: Sat Mar 08, 2014 6:05 pm    Post subject: Reply with quote

Can anyone help me?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites