Hi,
all the APIs i know enable me to execute an executable from my HDD.
But now, i need to be able to execute an executable stored in memory (but not running) for which i have the handle (like we can have DLL handle).
Is it possible to execute it (may be to execute a memory area if i provide the start address ?) or is it impossible ??
Thanks in advance.
regards.
To execute an executable's handle from memory, possible ?
To execute an executable's handle from memory, possible ?
- Registered PB user -
Using PB 4.00
Using PB 4.00
-
Edwin Knoppert
- Addict

- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
A while ago i posted this on the IBasic site.
It's for simplistic dll's only, maybe you can use it on a pb dll.
http://www.pyxia.com/community/viewtopic.php?t=7404
BTW, i heard exe's where possible but did not obtain any code for that.
If you have the time, please convert this to an PureBasic example for sharing.

It's for simplistic dll's only, maybe you can use it on a pb dll.
http://www.pyxia.com/community/viewtopic.php?t=7404
BTW, i heard exe's where possible but did not obtain any code for that.
If you have the time, please convert this to an PureBasic example for sharing.
-
PolyVector
- Enthusiast

- Posts: 499
- Joined: Wed Sep 17, 2003 9:17 pm
- Location: Southern California
- Contact:
Here's my go at a translation (I don't know IBasic so it was fun!)
This DLL is very interesting, anyone know what the licensing is on it? I'd love to use it!
This DLL is very interesting, anyone know what the licensing is on it? I'd love to use it!
Code: Select all
DataSection
StartDLLTEST:
IncludeBinary "DLLTEST.DLL"
EndDLLTEST:
EndDataSection
#DynLoadLib=0
OpenLibrary(#DynLoadLib,"DYNLOAD.DLL")
Global DL_LoadLibrary.l,DL_GetProcAddress.l,DL_CallFunctionByArray.l,DL_GetResourceData.l,DL_FreeBStr.l
DL_LoadLibrary=IsFunction(#DynLoadLib,"DL_LoadLibrary")
DL_GetProcAddress=IsFunction(#DynLoadLib,"DL_GetProcAddress")
DL_CallFunctionByArray=IsFunction(#DynLoadLib,"DL_CallFunctionByArray")
DL_GetResourceData=IsFunction(#DynLoadLib,"DL_GetResourceData")
DL_FreeBStr=IsFunction(#DynLoadLib,"DL_FreeBStr")
If DL_LoadLibrary=0 Or DL_GetProcAddress=0 Or DL_CallFunctionByArray=0 Or DL_GetResourceData=0 Or DL_FreeBStr=0
MessageRequester("Error","Function Not Found")
End
EndIf
; Load the library using the binary buffer.
hLib=CallFunctionFast(DL_LoadLibrary, ?StartDLLTEST, ?EndDLLTEST-?StartDLLTEST)
If hLib = 0
End
EndIf
; All calls must be obtained as address.
pTest0 = CallFunctionFast(DL_GetProcAddress, hLib, "Test0")
If pTest0 = 0
End
EndIf
nResult = CallFunctionFast(DL_CallFunctionByArray, pTest0, 0, 0)
;-Added: It should be faster to call directly like this:
CallFunctionFast(pTest0)
; Call a procedure in this library.
pTest2 = CallFunctionFast(DL_GetProcAddress, hLib, "Test2" )
If pTest2 = 0
End
EndIf
Dim nValues.l(2)
nValues(1) = 1234
nValues(2) = 4567
nResult = CallFunctionFast(DL_CallFunctionByArray, pTest2, 2, @nValues(1))
;-Added: It should be faster to call directly like this:
CallFunctionFast(pTest2,2468,1632)
-
PolyVector
- Enthusiast

- Posts: 499
- Joined: Wed Sep 17, 2003 9:17 pm
- Location: Southern California
- Contact:
It was in the forum Edwin linked to:
http://www.hellobasic.com/download/dynload.zip
I would kill for this in PB LIB form
http://www.hellobasic.com/download/dynload.zip
I would kill for this in PB LIB form
-
Edwin Knoppert
- Addict

- Posts: 1073
- Joined: Fri Apr 25, 2003 11:13 pm
- Location: Netherlands
- Contact:
-
Num3
- PureBasic Expert

- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
Interesting stuff...
I've worked on a self-modifing code a while back, it injected a saved procedure (procedure memory area) into a running app.
Unfortunatly i did not get very far, cos it only worked for very simple things, after a net dig i found out i need to reallocate stuff on memory to set things right... Too much for me so i quited.
During the dig i found you need to build a PE loader to execute programs from memory.
That's what UPX does, it makes a PE and unpacks the original executable into that memory area...
If anyone succeds CALL ME !
I've worked on a self-modifing code a while back, it injected a saved procedure (procedure memory area) into a running app.
Unfortunatly i did not get very far, cos it only worked for very simple things, after a net dig i found out i need to reallocate stuff on memory to set things right... Too much for me so i quited.
During the dig i found you need to build a PE loader to execute programs from memory.
That's what UPX does, it makes a PE and unpacks the original executable into that memory area...
If anyone succeds CALL ME !
