QLiberator decompiler

Anything QL Software or Programming Related.
Post Reply
Martin_Head
Aurora
Posts: 852
Joined: Tue Dec 17, 2013 1:17 pm

Re: QLiberator decompiler

Post by Martin_Head »

There are at least 8 simple compile variations, of AUTOF, WINDS, and REMark $$i that I can see, That may change the size of the resulting program. There may be many more if REMark $$i and REMark $$f 's are scattered about in the original sources.

I need to do some organised testing. That's why I am trying to put together a program to do byte by byte testing.

Looking at some of my notes, I did try compiling the program with itself , and the original QLIB_OBJ. And I got the same program size, and dataspace size at the end of the compile. But I don't know if they are byte for byte the same.

Apart from trying to compile the test programs supplied with QLiberator, I have not done any more testing. I don't usually use compilers. So I don't have a ready made backlog of BASIC programs that I know compile without problems. I am quite happy to supply one of my test compiles, If anyone is willing to throw some programs at it to see how well it works.

Yesterday I started putting together the program to compare _OBJ files. It look like compiling with QDOS makes no difference to compiling with SMSQ/E

Something I have noticed, Is that the Name list, in the recompiled compiler does not exactly match the order of the names in the original compiler. They are mostly the same, but one or two of the normal SuperBASIC commands will move position in the list. The order of the names in the list does not seem to be determined exactly by the program you are compiling.
I don't know how the compiler chooses the names, and the order, to add them to the name list. I don't see a big list of names like PRINT,WINDOW,OPEN in the source code. So I guess it's in one of the loaded SuperBASIC extensions. This raises the question, Was the original object file compiled with the same SuperBASIC extensions in memory, compared to those that got included in the compiled object file? I can see big problems trying to compare the compiled SuperBASIC code sections, if all the offsets in the name list are different.
So I may not be able to get an exact duplicate of the original.


User avatar
RalfR
Aurora
Posts: 872
Joined: Fri Jun 15, 2018 8:58 pm

Re: QLiberator decompiler

Post by RalfR »

Martin_Head wrote:I don't see a big list of names like PRINT,WINDOW,OPEN in the source code. So I guess it's in one of the loaded SuperBASIC extensions.
I think, this list (you mean the list at the bottom of the compiled program?) shows every name/keyword, which is used in the program.


4E75 7000
EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: QLiberator decompiler

Post by EmmBee »

Ralf R. wrote:
Martin_Head wrote:I don't see a big list of names like PRINT,WINDOW,OPEN in the source code. So I guess it's in one of the loaded SuperBASIC extensions.
I think, this list (you mean the list at the bottom of the compiled program?) shows every name/keyword, which is used in the program.
With the original QLIB_obj version 3.36 ..
open_in #9, ram2_QLIB_obj : set_position #9,44746 : x$ = input$(#9,673) : cls : print x$ : hot_stuff x$
The above gives out a list of names, each preceded by its length. Using copy and paste ..
PRINTSTOPINPUTWINDOWBORDERINKPAPERCSIZECURSORATOPENCLOSEDELETECLEAROPEN_INOPEN_NEWCLSPAUSEPOKE_LBEEPREADMODEINTABSPEEK_WPEEK_LEOFINKEY$CHR$CODELENDATEDATE$FILL$RECHPCURSENCURDISALCHPRMODEQ_ERR_ONQ_ERRQLIB_USE
QLIB_LIST$SETPOSSETUPWINPUTFCOPYWWRITELWRITERNAMEWNAMETSORTPACK_NUNPACK_NPOS
FINDSYMBOL GENSYMBOLFINDNEXTFREERA6UNdefINITgenGENopGENBGENWGENLGENintGENfloat GENsfloat GENstringGENtextGENntdSMEMRP_ADDRODDSHORTFLINT
NEXT_TOKENLSET_POS READ_nameNEXTLINELPOSb1WM_RptrWM_OutlnWM_SptrWM_wrspinput_edit$DnrFwindTqueue_TICOL_BPCOL_SICOL_DICOL_CUCOL_NRCHAN_HEAP_STACK_BUFFER_HELPF
Since the SuperBASIC code is now available, it might be possible to try and guess how this list is collected.
I believe that all these names are treated as being EXTRAS.
None of the actual SuperBASIC keywords would be included. PRINT WINDOW OPEN are not keywords, they are implemented as being EXTRAS.


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: QLiberator decompiler

Post by EmmBee »

Taking out the lengths info, for readability ..
PRINT STOP INPUT WINDOW BORDER INK PAPER CSIZE CURSOR AT OPEN CLOSE DELETE CLEAR OPEN_IN OPEN_NEW CLS PAUSE POKE_L BEEP READ MODE INT ABS PEEK_W PEEK_L EOF INKEY CHR CODE LEN DATE DATE FILL RECHP CURSEN CURDIS ALCHP RMODE Q_ERR_ON Q_ERR QLIB_USE QLIB_LIST SETPOS SETUP WINPUT FCOPY WWRITE LWRITE RNAME WNAME TSORT PACK_N UNPACK_N POS FINDSYMBOL GENSYMBOL FINDNEXT FREE RA UNdef INITgen GENop GENB GENW GENL GENint GENfloat GENsfloat GENstring GENtext GENntd SMEM RP_ADDR ODD SHORTF LINT NEXT_TOKEN LSET_POS READ_name NEXTLINE LPOS b WM_Rptr WM_Outln WM_Sptr WM_wrsp input_edit Dnr Fwind Tqueue _TICOL _BPCOL _SICOL _DICOL _CUCOL _NRCHAN _HEAP _STACK _BUFFER _HELPF
I wonder what the differences are between this and the recompiled version


User avatar
RalfR
Aurora
Posts: 872
Joined: Fri Jun 15, 2018 8:58 pm

Re: QLiberator decompiler

Post by RalfR »

EmmBee wrote:PRINT STOP INPUT WINDOW BORDER INK PAPER CSIZE CURSOR AT OPEN CLOSE DELETE CLEAR OPEN_IN OPEN_NEW CLS PAUSE POKE_L BEEP READ MODE INT ABS PEEK_W PEEK_L EOF INKEY CHR CODE LEN DATE DATE FILL RECHP CURSEN CURDIS ALCHP RMODE Q_ERR_ON Q_ERR QLIB_USE QLIB_LIST SETPOS SETUP WINPUT FCOPY WWRITE LWRITE RNAME WNAME TSORT PACK_N UNPACK_N POS FINDSYMBOL GENSYMBOL FINDNEXT FREE RA UNdef INITgen GENop GENB GENW GENL GENint GENfloat GENsfloat GENstring GENtext GENntd SMEM RP_ADDR ODD SHORTF LINT NEXT_TOKEN LSET_POS READ_name NEXTLINE LPOS b WM_Rptr WM_Outln WM_Sptr WM_wrsp input_edit Dnr Fwind Tqueue _TICOL _BPCOL _SICOL _DICOL _CUCOL _NRCHAN _HEAP _STACK _BUFFER _HELPF
Yes, but these are all commands/keywords, which are used in the program. Try and compile an SB program, where just "PRINT" is used. Then there is only "PRINT" in the compiled program's nametable.

There are two bugs in your enumeration. At line 3, "RA" should be "RA6", presumably to read A6. And "b" at line 4 should be "b1". Two of Liberations own extensions.
Last edited by RalfR on Wed Jan 08, 2020 6:06 pm, edited 2 times in total.


4E75 7000
EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: QLiberator decompiler

Post by EmmBee »

Ralf R. wrote:
EmmBee wrote:PRINT STOP INPUT WINDOW BORDER INK PAPER CSIZE CURSOR AT OPEN CLOSE DELETE CLEAR OPEN_IN OPEN_NEW CLS PAUSE POKE_L BEEP READ MODE INT ABS PEEK_W PEEK_L EOF INKEY CHR CODE LEN DATE DATE FILL RECHP CURSEN CURDIS ALCHP RMODE Q_ERR_ON Q_ERR QLIB_USE QLIB_LIST SETPOS SETUP WINPUT FCOPY WWRITE LWRITE RNAME WNAME TSORT PACK_N UNPACK_N POS FINDSYMBOL GENSYMBOL FINDNEXT FREE RA UNdef INITgen GENop GENB GENW GENL GENint GENfloat GENsfloat GENstring GENtext GENntd SMEM RP_ADDR ODD SHORTF LINT NEXT_TOKEN LSET_POS READ_name NEXTLINE LPOS b WM_Rptr WM_Outln WM_Sptr WM_wrsp input_edit Dnr Fwind Tqueue _TICOL _BPCOL _SICOL _DICOL _CUCOL _NRCHAN _HEAP _STACK _BUFFER _HELPF
Yes, but these are all commands/keywords, which are used in the program. Try and compile an SB program, where just "PRINT" is used. Then there is only "PRINT" in the compiled program's nametable.

There are two bugs in your enumeration. At line 3, "RA" should be "RA6", presumably to read A6. And "b" at line 4 should be "b1". Two of Liberations own extensions.
Yes, agreed. I also seem to have lost some $ characters. Here is a, hopefully, more correct version ..
PRINT STOP INPUT WINDOW BORDER INK PAPER CSIZE CURSOR AT OPEN CLOSE DELETE CLEAR OPEN_IN OPEN_NEW CLS PAUSE POKE_L BEEP READ MODE INT ABS PEEK_W PEEK_L EOF INKEY$ CHR$ CODE LEN DATE DATE$ FILL$ RECHP CURSEN CURDIS ALCHP RMODE Q_ERR_ON Q_ERR QLIB_USE QLIB_LIST$ SETPOS SETUP WINPUT FCOPY WWRITE LWRITE RNAME WNAME TSORT PACK_N UNPACK_N POS FINDSYMBOL GENSYMBOL FINDNEXT FREE RA6 UNdef INITgen GENop GENB GENW GENL GENint GENfloat GENsfloat GENstring GENtext GENntd SMEM RP_ADDR ODD SHORTF LINT NEXT_TOKEN LSET_POS READ_name NEXTLINE LPOS b1 WM_Rptr WM_Outln WM_Sptr WM_wrsp input_edit$ Dnr Fwind Tqueue _TICOL _BPCOL _SICOL _DICOL _CUCOL _NRCHAN _HEAP _STACK _BUFFER _HELPF
If the order of the words in the recompiled version is different, then perhaps the order of the $$assembler statements at the start of the program could be shuffled around to get the required order.


User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: QLiberator decompiler

Post by tofro »

Note even the order that extensions have been loaded to the machine that did the compile originally might count (that also affects the order of the EXTRAS output). So, a 100% exact replica of the original compile might be hard to achieve...

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
RalfR
Aurora
Posts: 872
Joined: Fri Jun 15, 2018 8:58 pm

Re: QLiberator decompiler

Post by RalfR »

tofro wrote:Note even the order that extensions have been loaded to the machine that did the compile originally might count (that also affects the order of the EXTRAS output). So, a 100% exact replica of the original compile might be hard to achieve...

Tobias
Yes, but it is quite easy if one examined the original 3.36 nametable. The nametable just shows, how the the "$asmb" was put into order of the compiled program, perhaps, they have made it different (as you have said). The last ones (coming with "_") were from my S_EDITs extension for the config block.


4E75 7000
User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: QLiberator decompiler

Post by mk79 »

Martin_Head wrote:The order of the names in the list does not seem to be determined exactly by the program you are compiling.
As far as I can see LIBERATE generates the order. It's the order the name list had at the time, so the order in which extensions were loaded matters.
This raises the question, Was the original object file compiled with the same SuperBASIC extensions in memory, compared to those that got included in the compiled object file?
No idea, but I can tell that he Q_ERR extension linked into QLIB_obj is actually older than the one shipped for users (at least on 3.35, which I happened to analyze, didn't check on 3.36 yet).

Marcel


Martin_Head
Aurora
Posts: 852
Joined: Tue Dec 17, 2013 1:17 pm

Re: QLiberator decompiler

Post by Martin_Head »

EmmBee wrote: PRINT STOP INPUT WINDOW BORDER INK PAPER CSIZE CURSOR AT OPEN CLOSE DELETE CLEAR OPEN_IN OPEN_NEW CLS PAUSE POKE_L BEEP READ MODE INT ABS PEEK_W PEEK_L EOF INKEY$ CHR$ CODE LEN DATE DATE$ FILL$ RECHP CURSEN CURDIS ALCHP RMODE Q_ERR_ON Q_ERR QLIB_USE QLIB_LIST$ SETPOS SETUP WINPUT FCOPY WWRITE LWRITE RNAME WNAME TSORT PACK_N UNPACK_N POS FINDSYMBOL GENSYMBOL FINDNEXT FREE RA6 UNdef INITgen GENop GENB GENW GENL GENint GENfloat GENsfloat GENstring GENtext GENntd SMEM RP_ADDR ODD SHORTF LINT NEXT_TOKEN LSET_POS READ_name NEXTLINE LPOS b1 WM_Rptr WM_Outln WM_Sptr WM_wrsp input_edit$ Dnr Fwind Tqueue _TICOL _BPCOL _SICOL _DICOL _CUCOL _NRCHAN _HEAP _STACK _BUFFER _HELPF
That's the list. If I remember correctly, Comparing my recompile, with the original. CLEAR (plus one or two others, which I can't remember off hand) move down the list a bit. So the list goes CLOSE DELETE OPEN_IN OPEN_NEW. And CLEAR reappears a bit further down.

The order of the commands doe's not fit the SuperBASIC program. There is a STOP before there are any PRINTs. And I'm pretty sure without looking that there is a Q_ERR_ON very near the start.

It makes me think this list come from the SuperBASIC name list on the machine you compile on. (or at least the one that the _wrk file is created on) So to have any chance of getting an exact copy, I would need to know what operating system and version was used originally. But I'm a bit surprised that compiling under QDOS (JS ROM) and SMSQ/E gives the same name list order.

I think I may be getting a bit over obsessive about trying to get an exact copy. :)


Post Reply