Page 1 of 1

Code Injection or Inject DLL?!

Posted: Sun May 29, 2005 8:38 pm
by Kendrel
I wanna call asm functions from an foreign process (a game actually), and from what i know there are only one solutionsfor that when iam right (please correct me if iam wrong)... DLL Injection?!

I guess there isnt any other way, and iam not sure how to do it at all on my own... but i would have a small programm to inject dll's, but havent tested it yet.

iam doing this all for fun only, and to increase my asm knowledge... this is nothing illegal at all from what i know... why do i tell you this?! I dont want you to get mad :)

cheers, Ken

erm

Posted: Sun May 29, 2005 8:53 pm
by Kendrel
thx @thefool!

Posted: Sun May 29, 2005 8:55 pm
by thefool
i removed code but ill send you a pm. the code didnt get in here correctly!

thx

Posted: Sun May 29, 2005 9:07 pm
by Kendrel
thx... had one constant missing at all, but i know that values from some of my own functions...

Posted: Sun May 29, 2005 10:42 pm
by Henrik
Hi Damn :evil:
I would like to see the code
TtttheFooolll Plz. repost it..
thefool wrote:i removed code but ill send you a pm. the code didnt get in here correctly!


Best
Henrik.

Posted: Sun May 29, 2005 10:45 pm
by thefool

Code: Select all

Procedure InjectDLL(DllFileName$,ProcessID.l)
  Protected Result.l,DllFileName$,Size.l,Process.l,RemoteMem.l,BytesWritten.l,LoadLibrary_Address.l,hThread.l
  Result=#False
  Size=Len(DllFileName$)+1
  Process=OpenProcess_(#PROCESS_ALL_ACCESS,0,ProcessID)
  If Process
    RemoteMem=VirtualAllocEx_(Process,#Null,Size,#MEM_COMMIT,#PAGE_READWRITE)
    If RemoteMem
      WriteProcessMemory_(Process,RemoteMem,DllFileName$,Size,@BytesWritten);BytesWritten can be #Null....
      If BytesWritten=>Size
        If OpenLibrary(0,"Kernel32.dll")
          LoadLibrary_Address=IsFunction(0,"LoadLibraryA")
          CloseLibrary(0)
          If LoadLibrary_Address
            hThread=CreateRemoteThread_(Process,#Null,#Null,LoadLibrary_Address,RemoteMem,#Null,#Null)
            If hThread
              WaitForSingleObject_(hThread, #INFINITE)
              GetExitCodeThread_(hThread,@Result)
            EndIf
          EndIf
        EndIf
      EndIf
      VirtualFreeEx_(Process,RemoteMem,Size,#MEM_DECOMMIT)
    EndIf
    CloseHandle_(Process)
  EndIf
  ProcedureReturn Result
EndProcedure
[/size]

it does not get posted correctly. Code is by Polyvector. Notice to have an attachprocess() procedure! read about that in the pb help file.!

edit: when i copy & paste the code to jaPBe the code is correct again. it just doesnt show correctly here.

Posted: Sun May 29, 2005 10:58 pm
by Henrik
@Thefool
Is it the second line that is broken, then it's okay when paste to the default editor
The rest looks okay to me..

Thanks TF :D

Best
Henrik..

Posted: Sun May 29, 2005 11:01 pm
by thefool
Np. i didnt even write the code but i just had it around so why not share it.

well its just a line thats broken, its wordwrap of something like that. If you have a bigger resolution of smaller text, it doesnt do it.

Posted: Sun May 29, 2005 11:04 pm
by Henrik
K.. Cool TF 8)
Best
Henrik..