To execute an executable's handle from memory, possible ?

Windows specific forum
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

To execute an executable's handle from memory, possible ?

Post 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.
- Registered PB user -

Using PB 4.00
TIGER
User
User
Posts: 81
Joined: Mon Feb 23, 2004 8:33 pm

Post by TIGER »

If ist a PB dll why don you trabslate it indo a DLL
And any other EXE ? I dont think so.
PIII450 128RAM TNT2
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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.

:)
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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)
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Where i can get a copy of that dll? Sounds nice :P
ARGENTINA WORLD CHAMPION
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post 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 :)
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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 ! :P
Post Reply