From: CW2K
Subject: Fas->Lsp Decompiler Project
Date: 
Message-ID: <1116963930.128045.284070@z14g2000cwz.googlegroups.com>
Hi,

I start writting a Fas-Decompiler for AutoCAD Lisp files.

http://lisp-decompiler-project.cjb.net

I think half of the work is already done. It's of some use in its
current form.I'd  worked out the specification of the Fas-file-format /
how to decrypted & interpret the Fas-Bytecode.
So for ex. the output of that line

      (initget 0 "Rechteckige Polare Kreisförmige")

will be:
...                                                 0
02367  32    0       push  00                       1
02369  9     6       push var "Rechteckige Polare K 2
02372  35    2 68 3  INITGET 2 Params are above...  1
02377  A             pop dummy (decrease stack)     0
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
offset command&parambytes description     stackpointer

What's to do now:

Now it's up to reassemble/combine the extracted raw datafragments to a
higher level and more lisp language.

The Data need to be traced correcting (take care of If then else
structures). With help of the stackpoint(which is only right if code is
traced correction) the lines can be seperated (Note: A line is finish
if stackpoint is 0 again)

After that an pattern/ structure scan algo is need to recognise makro
structures
like Cond( or while commands or optimise things like:
    (command "_.UNDO")
    (command "_E")
to
    (command "_.UNDO" "_E")

Currently I don't have time/motivation to develop that any further. So
the project is 'on ice' since about 2 years. The project was just for
fun&learn I don't really need for this to recover lost sources. So far
the primary goal was reached - now fas is no blackbox anymore. Now
-with some effort- you can see how certain parts of the Lisp program
are really implemented and you can fix some small bugs directly inside
the fas-bytecode.

I just ask if someone wants take part/overtake the project. Or if there
is someone
who have experiences in writing pattern/ structure scan algo's a talk
above or some
decompiler compiler or parse.

<CW2K>




P.S.
And yes it's true internally fas is implemented in Forth manner(stack
machine)
And now to the end instead of to talk about/trying to describe how it
is in gerneral this specific code snippet...

      (setq xx (getkword "\nAnordnungst<...>olar] <R>:"))
      (cond
        ((or (eq xx "Rechteckige")
             (eq xx nil))
          (r-array)
        )
        (T
          (p-array)
        )
      (command "_.UNDO" "_E")

... as internal fas-code with comments:
(Note: Stackpointer at the end maybe incorrect in some case -That's
what I ment with Todo:))

      (setq xx (getkword "\nAnordnungstyp eingeben [Rechteckig/Polar]
<R>:"))
02378 9     5             push var "\nAnordnungstyp eingeben
[Rechteckig/Po 11
02381 35    1 5D 3        GETKWORD 1 Params are above...
    11
02386 6     4             setq XX Retval of GETKWORD
    10


(cond
     ((or
    (eq xx "Rechteckige")
02389 3   4        Push value of [XX]                                11
02392 9   3        push var "Rechteckige"                            12
02395 35  2 2 3    EQ 2 Params are above...                          11
02400 68  F        If (Retval of EQ<>0) [Far] Jump to 2420 Else .pop 10

         eq xx nil)
02405 3   4        Push value of [XX]                                11
02408 1            Push <nil>                                        12
02409 35  2 2 3    EQ 2 Params are above...                          11
02414 68  1        If (Retval of EQ<>0) [Far] Jump to 2420 Else .pop 10

02419 1            Push <nil>                                        11
02420 6A  1        If (<nil>==0) [Far]Jump to 2426 Else .pop         10

02425 2            Push [61A4E6AC]                                   11
02426 68  1A       If ( [61A4E6AC]<>0) [Far] Jump to 2457 Else .pop  10

        (T
02431 3   1        Push value of [T]                                 11
02434 68  5        If (T<>0) [Far] Jump to 2444 Else .pop            10
02439 57  8        jump [far] over 8 bytes to 2452                   10
02444 A            pop dummy (decrease stack)
          (p-array)
02445 5F  0 199    defun P-ARRAY                                      9
02451 A            pop dummy (decrease stack)
                                                                      8
02452 57  8        jump [far] over 8 bytes to 2465                    8
02457 A            pop dummy (decrease stack)
                                                                      7
02458 5F  0 392    defun R-ARRAY                                      7
02464 A            pop dummy (decrease stack)                         6


    (command "_.UNDO" "_E")                                           6
02465 9   72       push var "_.UNDO"                                  7
02468 51  1 71 1   ads-cmd 1 Params are above <- Convert to funcptr   7
02474 A            pop dummy (decrease stack)
                                                                      6
02475 9   70       push var "_E"                                      7
02478 51  1 71 1   ads-cmd 1 Params                                   7
02484 A            pop dummy (decrease stack)                         6