Datei an exe anhängen und lesen
Verfasst: 12.03.2012 21:13
einer exe sollen dateien (zumindest eine text datei) angehängt werden die diese dann aus sich selbst liest.
hier habe ich was in der Richtung gefunden, wenn es mit PB 4.60 noch brauchbar wäre.
und dieser wird es angehangen
hier habe ich was in der Richtung gefunden, wenn es mit PB 4.60 noch brauchbar wäre.
Code: Alles auswählen
; ... EXE Data Stub Appender 0.1d by Griz October 2004 ...
; Appends a data stub to EXE : exe+data+packedsize(long)+unpackedsize(long)
Global datafile.s : datafile=""
Global exein.s : exein=""
Global exeout.s : exeout=""
Global messageout.s : messageout=""
Global password.s : password=""
Global originalsize
; Procedure Mod(a,b)
; ProcedureReturn a-(a/b)*b
; EndProcedure
; RC4 from Pille / Rings
Procedure.l RC4Mem(Mem.l, memLen.l, Key.s)
Dim s.w(255)
Dim k.w(255)
i.l=0: j.l=0: t.l=0: x.l=0
temp.w=0: y.w=0
Outp.s=""
For i = 0 To 255
s(i) = i
Next
j = 1
For i = 0 To 255
If j > Len(Key)
j = 1
EndIf
k(i) = Asc(Mid(Key, j, 1))
j = j + 1
Next i
j = 0
For i = 0 To 255
j = Mod(j + s(i) + k(i), 256)
temp = s(i)
s(i) = s(j)
s(j) = temp
Next i
i = 0
j = 0
For x = 0 To memLen-1
i = Mod(i + 1, 256)
j = Mod(j + s(i),256)
temp = s(i)
s(i) = s(j)
s(j) = temp
t = Mod(s(i) + Mod(s(j), 256) , 256)
y = s(t)
PokeB(Mem+x, PeekB(Mem+x)!y)
Next
ProcedureReturn Mem
EndProcedure
MessageRequester("Appender","version 0.1d by Griz",#PB_MessageRequester_Ok)
exein=OpenFileRequester("Choose Source EXE", "", "Executable (*.exe)|*.exe|All files (*.*)|*.*" , 0)
If exein
datafile=OpenFileRequester("Choose Source Data File", "", "Text (*.txt)|*.txt;*.bat|All files (*.*)|*.*" , 0)
If datafile
exeout=SaveFileRequester("Filename for output EXE", "", "Executable (*.exe)|*.exe;*.bat|All files (*.*)|*.*" , 0)
If exeout
password.s=InputRequester("RC4 Encryption","Please enter a password :","test123")
If ReadFile(0, datafile)
FileLength = Lof(0)
source=AllocateMemory(FileLength)
If FileLength And source
; read data stub into memory
ReadData(0,source,FileLength)
; pack the data
originalsize=FileLength
sourcetemp=AllocateMemory(FileLength+8)
If sourcetemp
f=PackMemory(source,sourcetemp,FileLength)
FreeMemory(source)
source=AllocateMemory(f)
CopyMemory(sourcetemp,source,f)
FreeMemory(sourcetemp)
FileLength=f
; read the exe into memory
If ReadFile(1,exein)
exefilelength=Lof(1)
destination=AllocateMemory(FileLength+exefilelength+4+4)
If destination
ReadData(1,destination,exefilelength)
CopyMemory(source,destination+exefilelength,FileLength)
; size of data (packed)
PokeL(destination+exefilelength+FileLength,FileLength)
; size of data (unpacked)
PokeL(destination+exefilelength+FileLength+4,originalsize)
; encrypt the data stub
RC4Mem(destination+exefilelength,FileLength,password)
; write the destination exe
If OpenFile(2,exeout)
WriteData(2, destination,exefilelength+FileLength+4+4)
MessageRequester("Success!", "EXE Generated")
CloseFile(2)
EndIf
FreeMemory(destination)
EndIf
EndIf
EndIf
FreeMemory(source)
EndIf
CloseFile(2)
EndIf
EndIf
EndIf
EndIf
End Code: Alles auswählen
; .. EXE Data Stub Decoder 0.1d by Griz October 2004 ..
; Read the last 4 bytes (long) as Data size then
; Read the data stub appended to end of the EXE
Global password.s : password="test123" ; rc4 password
Global originalsize
; API Call to get EXE Name
Procedure.s GetExeName()
sApp.s=Space(256)
GetModuleFileName_(GetModuleHandle_(0), @sApp, 256)
ProcedureReturn sApp
EndProcedure
; Procedure Mod(a,b)
; ProcedureReturn a-(a/b)*b
; EndProcedure
; RC4 from Pille / Rings
Procedure.l RC4Mem(Mem.l, memLen.l, Key.s)
Dim s.w(255)
Dim k.w(255)
i.l=0: j.l=0: t.l=0: x.l=0
temp.w=0: y.w=0
Outp.s=""
For i = 0 To 255
S(i) = i
Next
j = 1
For i = 0 To 255
If j > Len(Key)
j = 1
EndIf
k(i) = Asc(Mid(Key, j, 1))
j = j + 1
Next i
j = 0
For i = 0 To 255
j = Mod(j + S(i) + k(i), 256)
temp = S(i)
S(i) = S(j)
S(j) = temp
Next i
i = 0
j = 0
For x = 0 To memLen-1
i = Mod(i + 1, 256)
j = Mod(j + S(i),256)
temp = S(i)
S(i) = S(j)
S(j) = temp
t = Mod(S(i) + Mod(S(j), 256) , 256)
y = S(t)
PokeB(Mem+x, PeekB(Mem+x)!y)
Next
ProcedureReturn Mem
EndProcedure
Procedure GetExeData()
pfile.s=GetExeName()
psize=FileSize(pfile)
infile=ReadFile(#PB_Any, pfile)
If infile
; read packed size of data stub
FileSeek(infile,psize-8)
msize=ReadLong(infile)
; read unpacked size of data stub
FileSeek(infile,psize-4)
originalsize=ReadLong(infile)
FileSeek(infile,psize-8-msize)
source=AllocateMemory(msize)
If source
; read data stub into memory buffer
ReadData(infile, source,msize)
; decrypt the data stub
RC4Mem(source,msize,password)
; unpack the data stub
sourcetemp=AllocateMemory(originalsize)
If sourcetemp
UnpackMemory(source,sourcetemp)
FreeMemory(source)
source=AllocateMemory(originalsize)
CopyMemory(sourcetemp,source,originalsize)
FreeMemory(sourcetemp)
; ----------------------------------------
; data is now contained in 'source' memory bank
; below we simply capture it all as a string (for example)
d$=PeekS(source,originalsize)
If Len(d$)>512 ; only show the first 100 characters in messagebox
d$=Left(d$,512)+" <more...>"
EndIf
MessageRequester("Success!", "data size ="+Str(msize)+"/"+Str(originalsize)+Chr(13)+Chr(10)+Chr(13)+Chr(10)+d$)
FreeMemory(source)
; ----------------------------------------
EndIf
EndIf
CloseFile(infile)
EndIf
EndProcedure
GetExeData()