Code Injection or Inject DLL?!

Everything else that doesn't fall into one of the other PB categories.
Kendrel
User
User
Posts: 58
Joined: Fri Apr 25, 2003 7:00 pm

Code Injection or Inject DLL?!

Post 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
Kendrel
User
User
Posts: 58
Joined: Fri Apr 25, 2003 7:00 pm

erm

Post by Kendrel »

thx @thefool!
Last edited by Kendrel on Sun May 29, 2005 8:57 pm, edited 2 times in total.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

i removed code but ill send you a pm. the code didnt get in here correctly!
Kendrel
User
User
Posts: 58
Joined: Fri Apr 25, 2003 7:00 pm

thx

Post by Kendrel »

thx... had one constant missing at all, but i know that values from some of my own functions...
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post 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.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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.
Last edited by thefool on Tue Nov 15, 2005 9:09 pm, edited 1 time in total.
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post 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..
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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.
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

K.. Cool TF 8)
Best
Henrik..
Post Reply