Page 1 of 1
To execute an executable's handle from memory, possible ?
Posted: Sun Feb 29, 2004 6:13 pm
by newbie
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.
Posted: Mon Mar 01, 2004 9:38 pm
by TIGER
If ist a PB dll why don you trabslate it indo a DLL
And any other EXE ? I dont think so.
Posted: Mon Mar 01, 2004 10:56 pm
by Edwin Knoppert
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.

Posted: Mon Mar 01, 2004 11:12 pm
by PolyVector
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!
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)
Posted: Tue Mar 02, 2004 2:08 am
by ricardo
Where i can get a copy of that dll? Sounds nice

Posted: Tue Mar 02, 2004 3:55 am
by PolyVector
It was in the forum Edwin linked to:
http://www.hellobasic.com/download/dynload.zip
I would kill for this in PB LIB form

Posted: Tue Mar 02, 2004 10:13 am
by Edwin Knoppert
It's written with PowerBASIC.
PEBundle is simply much better.
But for simple stuff it works fine.
The dll should not rely on resources he has.
Posted: Tue Mar 02, 2004 7:55 pm
by Num3
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 !
