Execute EXE from memory Lib

Developed or developing a new product in PureBasic? Tell the world about it.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Very nice! Glad it could be recovered!
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Maxus wrote:I now install VMware and I shall check up on Window98.
Sorry for the stupid question, but do you call cmd.exe to execute the program ?
It's command.com on Win9x/Me.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
oryaaaaa
Addict
Addict
Posts: 825
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Post by oryaaaaa »

Cool library :D
Thanks
User avatar
Maxus
User
User
Posts: 71
Joined: Thu Feb 16, 2006 9:35 am
Location: Russia
Contact:

Post by Maxus »

gnozal wrote:
Maxus wrote:I now install VMware and I shall check up on Window98.
Sorry for the stupid question, but do you call cmd.exe to execute the program ?
It's command.com on Win9x/Me.
I understand, for this purpose and I am going to check.
Sorry my English, I'm Russian
AMT Laboratory
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

Maxus - Спасибо ! :)
Check out OOP support for PB here!
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Is this ussefull to prevent cracking of some app?

Which could be the best way to use it? Packing app? Any ideas?
User avatar
Maxus
User
User
Posts: 71
Joined: Thu Feb 16, 2006 9:35 am
Location: Russia
Contact:

Post by Maxus »

It is a lot of ideas, the most important that imaginations have sufficed.
Also it is not necessary to forget: " That one person has ciphered, another all the same will decipher ", only how many on it of time and nerves will leave?

P.S. - I think to continue restoration of an initial code after a trip to Italy, approximately after July, 15th.
Sorry my English, I'm Russian
AMT Laboratory
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Hi,

I wonder, what brilliant things can be done with pure basic (and good programmers ) - thanks for the nice tool!

I just changed some lines, even it does not do any enhancement...

Code: Select all


; did some small changes...
; - allow screen savers to be compressed
; - allow to use the tool more often (signature has been filled with MZMZMZ...)
; - reduced the code a little bit (you could also remove a fileseek line in the stub.pb;)
; - changed the maximum packing rate to 9 (I did not see better results anyway)
; - calculate real size reduction (stub size have to be added)

; - now only a icon for the created exe is missing ;)

;(c)2006 Inf0Byt3

Enumeration
	#Window_0
EndEnumeration

Enumeration
	#Text_0
	#String_0
	#Button_0
	#Frame3D_0
	#CheckBox_0
	#Text_1
	#TrackBar_1
	#ProgressString_0
	#Button_1
	#Button_2
	#Button_3
EndEnumeration

If OpenWindow(#Window_0, 411, 290, 299, 208, "FShrink v1.0a",  #PB_Window_SizeGadget | #PB_Window_TitleBar)
	If CreateGadgetList(WindowID(#Window_0))
		TextGadget(#Text_0, 5, 10, 290, 15, "Choose an executable file:")
		StringGadget(#String_0, 5, 30, 225, 20, "")
		ButtonGadget(#Button_0, 235, 30, 60, 20, "Browse")
		Frame3DGadget(#Frame3D_0, 5, 60, 290, 115, "Options")
		CheckBoxGadget(#CheckBox_0, 10, 80, 278, 15, "Backup the input executable file")
		TextGadget(#Text_1, 10, 105, 280, 15, "Compression level:")
		TrackBarGadget(#TrackBar_1, 10, 120, 280, 20, 0, 9)
		TextGadget(#ProgressString_0, 10, 150, 280, 15, "Action: Waiting for a PE file to be loaded.")
		ButtonGadget(#Button_1, 5, 180, 90, 25, "About")
		ButtonGadget(#Button_2, 205, 180, 90, 25, "CompressPE")
		ButtonGadget(#Button_3, 110, 180, 90, 25, "Exit")
		SetGadgetState(#CheckBox_0,1)
		SetGadgetState(#TrackBar_1,9)
	EndIf
EndIf

Repeat
	event = WaitWindowEvent()
	If event= #PB_Event_Gadget
		Select EventGadget()
		Case #Button_0
			PE.s = OpenFileRequester("Choose a program file:","","PE Executable (*.exe, *.scr)|*.exe;*.scr",0)
			If PE <SetGadgetText> 0 And FileSize(File) < 32<<20

				If ReadFile(0,File)
					If ReadWord(0)<>'ZM'
						MessageRequester("FShrink","The file you have chosen is not a valid PE file.")
						End
					Else
						FileSeek(0,0)
						Filesize = Lof(0)

						*Buffer = AllocateMemory(Filesize)
						ReadData(0,*Buffer,Filesize)
						CloseFile(0)
						*BufferCompressed = AllocateMemory(Filesize+8)
						If *Buffer And *BufferCompressed
							SetGadgetText(#ProgressString_0,"Action: Compressing file. Please wait.")
							LengthCompressed = PackMemory(*Buffer,*BufferCompressed,Filesize,GetGadgetState(#TrackBar_1))
							
							If GetGadgetState(#CheckBox_0) = 0
								DeleteFile(File)
							Else
								File=GetPathPart(File)+GetFilePart(File)+"_compressed.exe"
							EndIf
							CreateFile(0,File)
							WriteData(0,?StubStart,?StubEnd-?StubStart)
							WriteData(0,*BufferCompressed,LengthCompressed)
							WriteLong(0,Filesize)
							WriteLong(0,LengthCompressed)
							CloseFile(0)
							MessageRequester("Ready","The file was compressed successfully. Now it is: "+Str((Filesize-LengthCompressed+?StubStart-?StubEnd)>>10)+" kB smaller.")

							SetGadgetText(#ProgressString_0,"Action: Waiting for a PE file to be loaded.")
							SetGadgetText(#String_0,"")
				
						If *BufferCompressed
							FreeMemory(*BufferCompressed)
						EndIf
					EndIf
				EndIf
			Else
				MessageRequester("FShrink","Could not read the file.")
				End
			EndIf
		Else
			MessageRequester("FShrink","The filesize must be bigger than 0 and smaller than 32MB.")
		EndIf
	EndSelect
EndIf
ForEver

DataSection
StubStart:
IncludeBinary "Stub.exe"
StubEnd:
EndDataSection

Michael.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

I have been rewriting the whole stub to add security functionality (polymorphic encryption, polymorphic code (the code is based on random numbers, changes everytime you run it), debugger checks and so on. I still need a lot; but i can't do anything till we can get the launched process id out of the lib!)
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

Michael Vogel wrote:

Code: Select all

If PE <SetGadgetText> 0 And FileSize(File) < 32<<20
interesting Code ;-)

Greetings ... Kiffi
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

thefool wrote:I have been rewriting the whole stub to add security functionality
Sounds great - a perfect application for this lib. Looking forward to seeing more.

@Maxus, thanks alot for this!
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Great job Michael and Thefool. I just found some nice encryption (self-encrypting) but I've got to polish it a bit and I'll post it here :D.

[Edit]
[quote]I have been rewriting the whole stub to add security functionality (polymorphic encryption, polymorphic code (the code is based on random numbers, changes everytime you run it), debugger checks and so on. I still need a lot; but i can't do anything till we can get the launched process id out of the lib!)[quote]

Sorry haven't read this carefully. So the encryption is ready :D. Thanks.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Post by sverson »

Great work - thanks!

;-) sverson
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Inf0Byt3 wrote: Sorry haven't read this carefully. So the encryption is ready :D. Thanks.
hey its more the other stuff. The encryption isnt really that good; so if you got a nice algo please come with it :)
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

I´m very very sorry, but I lost my hard-disk! It failed today in the morning... I´ll kill myself. I´m lucky I didn lost PureAV. For now, I have a 5 GB hard-drive and I use Linux. I don know how much will I be in this situation, I´ll buy another HDD soon. I really really am sorry I dissapointed you and very sad this happened. Don´t know why it failed, just didn´t start anymore :(.

About the encryption, my model was a modification of the self-encryption algo. Here it is the original code (i think Dare2 made it...)

Code: Select all

Procedure.s selfE(src.s,en.l)
  k1=Len(src)
  If k1>0
    *p=@src
    k2=PeekB(*p) & $FF
    r=k1 ! k2
    If r<>0 : PokeB(*p,r) : EndIf
    For i=2 To Len(src)
      *p+1
      If en : k1=PeekB(*p-1) & $FF : Else : k1=k2 : EndIf
      k2=PeekB(*p)
      r=k1 ! k2
      If r<>0 : PokeB(*p,r) : EndIf
    Next
  EndIf
  ProcedureReturn src
EndProcedure

w.s="Wooo! Hooo! This is self encrypting"
x.s=selfE(w,#True)
y.s=selfE(x,#False)
Debug w
Debug x
Debug y
Sorry again and I hope this is good enough...

Cheers,
Alex.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Post Reply