■ Créer un dossier. Enregistrer et créer un exécutable de ce bout de code qui sera l'exécutable à lancer en mémoire sans l'installer sur le disque de l'utilisateur. (demo.exe)
Code : Tout sélectionner
Enumeration
#Mainform
EndEnumeration
Define.l Event, GEvent
Global WindowStyle.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered
Procedure Open_MainForm()
OpenWindow(#Mainform, 0, 0, 300, 200, "Demo", WindowStyle)
EndProcedure
Open_MainForm()
Repeat
Event = WaitWindowEvent(10)
GEvent = EventGadget()
Select Event
Case #PB_Event_Gadget
Select GEvent
EndSelect
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
Code : Tout sélectionner
;http://forums.purebasic.com/english/viewtopic.php?p=311116&sid=71318ad4a9f408ffe97d5eb450eef191#p311116
EnableExplicit
Enumeration
#btn1
EndEnumeration
Define.l Event, EventGadget, EventGadget, EventWindow
Procedure RunPE(lBuff, parameters.s)
Protected *idh.IMAGE_DOS_HEADER = lBuff
Protected *ish.IMAGE_SECTION_HEADERS
Protected pi.PROCESS_INFORMATION
Protected *inh.IMAGE_NT_HEADERS
Protected si.STARTUPINFO
Protected lpBaseAddres.l
Protected Ctx.CONTEXT
Protected Addr.l, RET.l, i.l
CreateProcess_(#NUL, ProgramFilename() + " " + parameters, #NUL, #NUL, #False, #CREATE_SUSPENDED, #NUL, #NUL, @si, @pi)
Ctx\ContextFlags = #CONTEXT_INTEGER
If GetThreadContext_(pi\hThread, Ctx) = 0 : Goto EndThread : EndIf
ReadProcessMemory_(pi\hProcess, Ctx\Ebx + 8, @Addr, 4, #NUL)
If ZwUnmapViewOfSection_(Pi\hProcess, Addr) : Goto EndThread : EndIf
If lBuff = 0 : Goto EndThread : EndIf
*inh = lBuff + *idh\e_lfanew
lpBaseAddres = VirtualAllocEx_(pi\hProcess, *inh\OptionalHeader\ImageBase, *inh\OptionalHeader\SizeOfImage, #MEM_COMMIT | #MEM_RESERVE, #PAGE_EXECUTE_READWRITE)
WriteProcessMemory_(pi\hProcess, lpBaseAddres, lBuff, *inh\OptionalHeader\SizeOfHeaders, @ret)
*ish = *inh\OptionalHeader + *inh\FileHeader\SizeOfOptionalHeader
For i = 0 To *inh\FileHeader\NumberOfSections - 1
WriteProcessMemory_(pi\hProcess, lpBaseAddres + *ish\ish[i]\VirtualAddress, lBuff + *ish\ish[i]\PointerToRawData, *ish\ish[i]\SizeOfRawData, @ret)
Next
WriteProcessMemory_(pi\hProcess, Ctx\Ebx + 8, @lpBaseAddres, 4, #NUL)
Ctx\Eax = lpBaseAddres + *inh\OptionalHeader\AddressOfEntryPoint
SetThreadContext_(pi\hThread, Ctx)
ResumeThread_(pi\hThread)
ProcedureReturn
EndThread:
TerminateProcess_(pi\hProcess, #NUL)
CloseHandle_(pi\hThread)
CloseHandle_(pi\hProcess)
EndProcedure
OpenWindow(0, #PB_Ignore, #PB_Ignore, 140, 50, "", #PB_Window_SystemMenu |#PB_Window_ScreenCentered)
ButtonGadget(#btn1, 40,15, 60, 20, "Run PE")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
EventGadget = EventGadget()
If EventGadget = #btn1
RunPE(?file, "")
EndIf
Case #PB_Event_CloseWindow
EventGadget = EventWindow()
If EventWindow = 0
CloseWindow(0)
Break
EndIf
EndSelect
ForEver
DataSection
file:
IncludeBinary "demo.exe"
EndDataSection