Page 1 of 1

[HELP] DLL Injection

PostPosted: Mon Apr 05, 2010 9:36 am
by denispn
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.

Re: [HELP] DLL Injection

PostPosted: Mon Apr 05, 2010 12:48 pm
by L. Spiro
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

Re: [HELP] DLL Injection

PostPosted: Tue Apr 06, 2010 5:03 am
by denispn
Thanks L.Spiro!

I will take a look at the Windows API and learn how to create a thread.

Re: [HELP] DLL Injection

PostPosted: Sun Apr 25, 2010 11:21 pm
by denispn
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