Posted: 11th Apr 2003 13:00
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.

+ Code Snippet
' 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
Posted: 17th May 2003 3:07
I had been thinking about using UPX but didn't know it had a pointer issue with DArkBasic. Is the Snippet for Q Basic or DarkBasic. I don't have Q Basic.
Does it work with DarkBasic Pro and DarkBasic exes?
Lastly do I need a certain version of UPX or will any work?

Thanks
Posted: 19th May 2003 15:06
This snippet is written on QBasic.
QBasic is a free DOS BASIC interpreter
(limited free "interpreter only" version of Quick Basic 4.5)
by Microsoft. There are many links in web about QBasic or where
to find, please search in
http://www.google.com
"qbasic" or "qbasic download".
This snippet is intended for packing DarkBasic classic EXE files.
Only EXE code is packed, not attached data,
so this method is not good for packing programs with much data
attached. The main purpose of this snippet is to pack EXE code
created by "MAKE EXE". For data packing I use another method.
This program was tested with UPX 1.24 but older versions must
also work fine
Posted: 19th May 2003 15:23
DBPro + UPX =

I never had any luck compressing DBPro exe's with UPX, they always throw errors.
Posted: 16th Jun 2003 15:19
Now you can download compiled program with source from
http://atd-group.narod.ru/eng/coding.htm
There are some other useful tools here