...............
Publié : mar. 02/juin/2009 19:25
...............................
Code : Tout sélectionner
; EXE2compressedDATA
; zaphod - 2009
name_file$=OpenFileRequester("ouvrir","","*.exe",0)
If name_file$<>""
If ReadFile(0, name_file$)
length = Lof(0)
*MemoryID = AllocateMemory(length)
If *MemoryID
bytes = ReadData(0, *MemoryID, length)
EndIf
CloseFile(0)
EndIf
*pack=AllocateMemory(length+8)
sz=PackMemory(*memoryid,*pack,length,9)
FreeMemory(*memoryid)
;
OpenFile(1,name_file$+".pb")
titre$=name_file$
WriteStringN(1,"DataSection")
WriteStringN(1,"datas:")
i=0 ;nombre de datas / ligne
WriteString(1,"data.l ")
For j=0 To sz-1 Step 4
WriteString(1,"$"+Hex(PeekL(*pack+j),#PB_Long))
i+1
If j<sz-4
If i<10 ;10 datas / ligne
WriteString(1,",")
Else
WriteString(1,Chr(13))
WriteString(1,"data.l ")
i=0
EndIf
EndIf
Next
;
FreeMemory(*pack)
WriteString(1,Chr(13))
WriteStringN(1,"EndDataSection")
WriteStringN(1,"titre$="+Chr(34)+titre$+Chr(34))
WriteStringN(1,"*pak=allocatememory("+Str(sz)+")")
WriteStringN(1,"for i=0 to "+Str(sz-1)+" step 4")
WriteStringN(1,"Read.l d")
WriteStringN(1,"PokeI(*pak+i,d)")
WriteStringN(1,"next")
WriteStringN(1,"*unpak=allocatememory("+Str(length)+")")
WriteStringN(1,"unpackmemory(*pak,*unpak)")
WriteStringN(1,"CreateFile(1,titre$)")
WriteStringN(1,"WriteData(1,*unpak,"+Str(length)+")")
WriteStringN(1,"CloseFile(1)")
WriteStringN(1,"freememory(*pak)")
WriteStringN(1,"freememory(*unpak)")
CloseFile(1)
EndIf