[HELP] DLL Injection

Technical Discussions not Related Directly to MHS. For Example, Coding, Hex Editing, General Hacking, Etc.

Moderators: g3nuin3, SpeedWing, WhiteHat

[HELP] DLL Injection

Postby denispn » Mon Apr 05, 2010 9:36 am

Hi folks!

I have a basic question about DLL injection.

Let's suppose that i have created a DLL in assembly language, and i want this DLL to run in a loop, so that it constantly reads values in some addresses of any game and executes functions in this DLL when some criteria is met.

Example of function: Loop through all my units' life value addresses and maximize them if the are bellow it's maximum.

Assuming that i want to use MHS to inject my DLL, how should i write this DLL?

Thanks in advance,
ctl3d32

Edit: I think i have posted in the wrong section. If it is the case, sorry for that.
denispn
Hacker Smacker
 
Posts: 43
Joined: Wed Dec 26, 2007 9:45 am

Re: [HELP] DLL Injection

Postby L. Spiro » Mon Apr 05, 2010 12:48 pm

Create a thread inside DllMain() which runs until DllMain() is called again to shut down.
The thread runs your loop.

There is no special coding to allow a DLL to work with MHS; MHS can inject any DLL and call any function inside any DLL with any number of parameters.


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Re: [HELP] DLL Injection

Postby denispn » Tue Apr 06, 2010 5:03 am

Thanks L.Spiro!

I will take a look at the Windows API and learn how to create a thread.
denispn
Hacker Smacker
 
Posts: 43
Joined: Wed Dec 26, 2007 9:45 am

Re: [HELP] DLL Injection

Postby denispn » Sun Apr 25, 2010 11:21 pm

Hi!

I'm posting here an example of DLL that can be injected into a process.
This example uses the CreateThread Windows API to show a simple MessageBox in a new thread.

Cheers,
ctl3d32

Code: Select all
; DLL creation example

format PE GUI 4.0 DLL
entry DllEntryPoint

include 'win32a.inc'

section '.text' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
        mov    eax,[fdwReason]
        cmp    eax,DLL_PROCESS_ATTACH
        jne    .finish
        invoke CreateThread,NULL,NULL,ShowMessage,NULL,NULL,ThreadID
        mov    [hThread],eax
        .finish:
        mov     eax,TRUE
        ret
endp

proc ShowMessage
     invoke MessageBox,NULL,_title,_text,MB_OK
     ret
endp

section '.data' data readable writeable

  _title db 'Window Title',0
  _text db 'Window Message.',0

section '.bss' readable writeable

  ThreadID dd ?
  hThread dd ?

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'

  import kernel,\
         CreateThread,'CreateThread'

  import user,\
         MessageBox,'MessageBoxA'

section '.edata' export data readable

  export 'DLLTest.DLL',\
         ShowMessage,'ShowMessage'

section '.reloc' fixups data discardable
Attachments
DLLTest.zip
Includes SOURCE and the DLL.
(1.16 KiB) Downloaded 1012 times
denispn
Hacker Smacker
 
Posts: 43
Joined: Wed Dec 26, 2007 9:45 am


Return to Technical Unrelated

Who is online

Users browsing this forum: No registered users and 0 guests

cron