Execute EXE from memory Lib

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Maxus
User
User
Posts: 71
Joined: Thu Feb 16, 2006 9:35 am
Location: Russia
Contact:

Execute EXE from memory Lib

Post by Maxus »

This lib: http://www.bigvolga.ru/svalka/ExecuteEXE

install this lib to PBdir\PureLibraries\UserLibraries\

Help:

Code: Select all

 If ReadFile(0,"C:\WINNT\Notepad.exe") 
  Length = Lof(0) 
  *Buffer = AllocateMemory(Length) 
  ReadData(0,*Buffer,Length) 
  CloseFile(0) 
  ExecuteEXE(*Buffer,"","") 
 EndIf
Last edited by Maxus on Wed Jan 30, 2008 2:12 pm, edited 2 times in total.
Sorry my English, I'm Russian
AMT Laboratory
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

Data Execution Prevention prevents your lib to work on my PC. How can I bypass this?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

No crash here, but does nothing ?!

Code: Select all

If ReadFile(0,"C:\Windows\Pbrush.exe")
  Debug "Found"
  length = Lof(0)
  *Buffer = AllocateMemory(length)
  Debug ReadData(0,*Buffer,length)
  CloseFile(0)
  ExecuteEXE(*Buffer)
EndIf
(Windows 98SE / PB4 final + beta libs / jaPBe V3)
Last edited by gnozal on Wed Jun 21, 2006 3:38 pm, edited 1 time in total.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

works here, thanks! ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

At windows XP SP 2 i get the same message as Bonne_den_kule
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

The problem is that we have to allocate memory which code is allowed to run from, I think.
Understanding Data Execution PreventionData Execution Prevention (DEP) helps prevent damage from viruses and other security threats that attack by running (executing) malicious code from memory locations that only Windows and other programs should use. This type of threat causes damage by taking over one or more memory locations in use by a program. Then it spreads and harms other programs, files, and even your e-mail contacts.

Unlike a firewall or antivirus program, DEP does not help prevent harmful programs from being installed on your computer. Instead, it monitors your programs to determine if they use system memory safely. To do this, DEP software works alone or with compatible microprocessors to mark some memory locations as "non-executable". If a program tries to run code—malicious or not—from a protected location, DEP closes the program and notifies you.

DEP can take advantage of software and hardware support. To use DEP, your computer must be running Microsoft Windows XP Service Pack 2 (SP2) or later, or Windows Server 2003 Service Pack 1 or later. DEP software alone helps protect against certain types of malicious code attacks but to take full advantage of the protection that DEP can offer, your processor must support "execution protection". This is a hardware-based technology designed to mark memory locations as non-executable. If your processor does not support hardware-based DEP, it's a good idea to upgrade to a processor that offers execution protection features.
I am using a Amd Athlon 64 X2 3800+, which supports "execution protection".
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

64-bit applications should not execute code from the stack or the default process heap. Applications that want to allocate executable memory should do so using VirtualAlloc() with one of the PAGE_EXECUTE memory attributes.
@Maxus: You must allocate the memory block which is executed with #PAGE_EXECUTE_READWRITE constant in your lib.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Yes, this should fix it.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

Great job, thanks
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Brilliant job. Lots of people have been searching for something like this for a while now. Well done. 8)
I may look like a mule, but I'm not a complete ass.
User avatar
Maxus
User
User
Posts: 71
Joined: Thu Feb 16, 2006 9:35 am
Location: Russia
Contact:

Post by Maxus »

OK. I'm fixed this bug, Download update: http://amt-lab.com/svalka/ExecuteEXE
Sorry my English, I'm Russian
AMT Laboratory
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Great job! It works very nice.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

This is just cool!

And it seems real! Filemon doesn't repport anything suspicious.

Great job :!:
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

thx, works

but what is about parameters oder handle to exe?
there come always 0 from the function
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

The program will appears as cmd.exe in the process explorer.
This is enough info to get the handle and etc. But it would be nice if the function could return the handle + passing program parameters if possible.

And it would be nice with a function to set the default directory.
Post Reply