Posted: Sun Sep 04, 2005 7:19 am
One tip: Size Of the structure IMAGE_OPTIONAL_HEADER32 is your answer.
*Dont ask me how to do it
I dont know
*Dont ask me how to do it

http://www.purebasic.com
https://www.purebasic.fr/english/
I hope this works for youokasvi wrote: dwSize = ((PIMAGE_NT_HEADERS)(pbModule+((PIMAGE_DOS_HEADER)pbModule)->e_lfanew))->OptionalHeader.SizeOfImage;[/code] to get dwSize I am using just "32768" which works with this example. anyway depending (this is how I see it ) on filesize of created executable you need to change that.
eg. I stopped using Droopylib and got filesize from around 22,5kb to 7,5kb so injection didnt work any more but it can be fixed with replacing "32768" with "32768/2"...
2. doesnt work with debugger for some reason i dont know
Thanks, it worksFreeThought wrote:I hope this works for youokasvi wrote: dwSize = ((PIMAGE_NT_HEADERS)(pbModule+((PIMAGE_DOS_HEADER)pbModule)->e_lfanew))->OptionalHeader.SizeOfImage;[/code] to get dwSize I am using just "32768" which works with this example. anyway depending (this is how I see it ) on filesize of created executable you need to change that.
eg. I stopped using Droopylib and got filesize from around 22,5kb to 7,5kb so injection didnt work any more but it can be fixed with replacing "32768" with "32768/2"...
2. doesnt work with debugger for some reason i dont know
DwSize.l=PeekL(pbmodule+PeekW(pbmodule+$3c)+$50)
regards.
Code: Select all
Procedure RemoteThread()
;MessageRequester("Success","Injection worked.")
;Delay(1500)
Repeat
Beep(1999,1) ;Just to know its running
Delay(320)
cont+1
If cont = 20
a$ = "hello world"
MessageRequester("",a$)
cont = 0
EndIf
ForEver
EndProcedure
im not sureFreeThought wrote:please forgive me, but I still don't understand the code, GetModuleHandle_(0) should
return the handle to the calling process.why virtualalloc a region that is already allocated. it is nice of you ,if you can clarify .thanks
regards
Code: Select all
;RemoteProcedureInjection :D
;credits goes for D-oNe for original code in C++, for Pupil for pointing out that i should use long with pbModule, for FreeThought way to get dwSize dynamically... thanks :D
;okasvi
Procedure RemoteThread()
MessageRequester("Success","Injection worked.")
EndProcedure
Procedure InjectCode(Process.s, *lpCodeToInject)
RunProgram(Process)
dwPID = GetPidProcess(GetFilePart(Process))
Debug Hex(dwPID)
hProcess = OpenProcess_(#PROCESS_ALL_ACCESS, #False, dwPID)
Debug hProcess
dwWritten.l = #Null :
pbModule.l = GetModuleHandle_(#Null)
Debug pbModule.l
DwSize.l =PeekL(pbmodule+PeekW(pbmodule+$3c)+$50)
Debug DwSize.l
;******************************
TestRelease.l= VirtualFreeEx_(hProcess, pbModule, 0, #MEM_RELEASE) ;<<-- *** TestRelease.l = 0
Debug TestRelease.l ;<- *** Fails here ** TestRelease.l is 0 ***
lpBuffer.l = VirtualAllocEx_(hProcess, pbModule, dwSize, #MEM_COMMIT | #MEM_RESERVE, #PAGE_EXECUTE_READWRITE) ;<<-- *** lpBuffer.l = 0
Debug lpBuffer.l ; <- *** And obviously here too NULL ***
;******************************
If lpBuffer = #Null : ProcedureReturn #False : EndIf
If WriteProcessMemory_(hProcess, lpBuffer, pbModule, dwSize, dwWritten) = 0
ProcedureReturn #False
EndIf
hThread.l = CreateRemoteThread_(hProcess, #Null, 0, *lpCodeToInject, pbModule, #Null, #Null)
If hThread=#Null : ProcedureReturn #False : EndIf
CloseHandle_(hThread) : CloseHandle_(hProcess) : ProcedureReturn #True
EndProcedure
If InjectCode("notepad.exe", @RemoteThread()) = #False
MessageRequester("Error!", "Injection failed!")
EndIf
End