It is possible to pack compiled EXE files by code compressor
such as UPX
http://upx.sourceforge.net
Code, compiled by DarkBasic has a structure:
{normal PE executable}
{attached data}
{pointer to attached data start address (4byte dword)}
After compression by UPX the code structure is the same,
but {attached data} now starts from new address,
so pointer value is wrong and program crashes.
All we have to do is to write new pointer value after packing.
And now the compressed EXE program works.
The example make this fix for DarkBasic EXEs.
' QB / QBasic
DEFINT A-Z
DIM p AS LONG, l AS LONG, s AS STRING * 16, a AS STRING * 8192
' Copy original file to PACKED.EXE
fi$ = "dbbrowse.exe"
fo$ = "packed.exe"
e$ = CHR$(34)
backslash$ = CHR$(92)
SHELL "copy " + e$ + fi$ + e$ + SPACE$(1) + fo$
' read data pointer
OPEN "b", 1, fo$
GET 1, LOF(1) - 3, p
IF p < 0 AND p >= LOF(1) THEN GOTO wrongformat
GET 1, 1& + p, s: l = CVI(MID$(s, 1, 4)): q$ = MID$(s, 6, 2)
' read first 16 bytes of data
' Is's like this
' dd 1Bh
' db "C:/WIN98/Temp/_exefile.dat",0
' but only with backslashes, not "/"
IF l < 0 OR l > 64 OR q$ <> ":"+backslash$ THEN GOTO wrongformat
CLOSE 1
' Compress PACKED.EXE We must have UPX.EXE somewhere on PATH
SHELL "upx " + fo$
' Open packed file, find new position of attached data
OPEN "b", 1, fo$
p = 0: DO: GET 1, , a: q = INSTR(a, s): p = p + 8192: LOOP WHILE q = 0
p = p - 8192 + q - 1
PRINT HEX$(p)
' Write new pointer value
PUT 1, LOF(1) - 3, p
END
wrongformat:
PRINT fi$; " - possibly not DarkBasic executable"
END