If you are looking for the decompiler itself, visit https://github.com/jindrapetrik/jpexs-decompiler
NEW : You can now close your own issues and reopen them later if needed. You can also comment closed issues.
List of issues#2667 Questions about mapping p-code lines to ActionScript lines
Author:
tjahier
tjahierDate created:
Type: question
Visibility: Everybody
Assigned to:
State: opened 

Hello! I am working on a toolkit for GFx modders, and I am heavily relying on FFDEC
(thaank you!).
My program is working on p-code text but I would like it to be able to show users what
lines are affected in the decompiled ActionScript code.
For that, I figured out I could generate .swd files using:
[code]
ffdec-cli -enabledebugging -generateswd my_gfx_file.gfx debug.gfx
ffdec-cli -enabledebugging -generateswd -pcode my_gfx_file.gfx debug_pcode.gfx
[/code]
Using your work in the flashdebugger lib, I can read those SWD files and use them to make
that link between p-code and ActionScript.
My questions are:
1. Can I ignore the generated debug GFx files if I only need the SWD? Do the generated SWD
files correctly apply to the original GFX files, or do they only apply to the generated
GFX debug files?
2. Am I going the right direction for my goal? Or is it overengineered, or is there a much
better solution?
3. I noticed the CLI documentation says that you can export scripts in multiple formats at
once, by separating formats with commas. However, it does not work for me: [code]
ffdec-cli -format script:as,script:pcodehex,script:pcode -export script[/code]
Have a good day!
As far as I remember, for AS1/2 files, the SWD file line numbers directly match the
decompiled source you see in the decompiler.
For AS3 files, there is no SWD generation (or at least the debugger does not use it),
but if it was, then there might be a little difference because of added jpexs debugger
package,
but I am not sure about this.
I think your direction is the easiest way to get offset-line matching for AS1/2 files.
Ad "exporting multiple formats"
I guess it mainly targets graphic types.
It probably does not work because it uses the same file extension (.as) and next export
overwrites the previous.
State: new→opened
Oh, and Hello btw!
Have a nice day too.
Thank you for your response. The GFx files I am working with are AVM1 (and ActionScript
2).
So, if I understood correctly, the gfx output of `ffdec-cli -enabledebugging -generateswd`
is not needed and can just be dropped/ignored?
About multiple formats exports:
>>> It probably does not work because it uses the same file extension (.as) and next
export
overwrites the previous.
In the case of `-format script:as,script:pcode`, when exporting separately it uses
different file extensions: .as and .pcode.
I have an extra question if you do not mind: when resolving an AS line from a p-code line,
it looks shifted by one line. For example:
```
Line P-code
AS line ActionScript
──────────────────────────────
──────────────────────────────
──────────────────────────────
──────────────────────────────
──────────────────────────────
───────────────────────────
50097 DefineFunction2 "CountingDialogExchangeSubmit", 0, 2, false, false, true, false,
true, false, true, false, false { ~
50098 Push "m_CountingDialog"
12576 }
50099 GetVariable
12564 m_CountingDialog.onEnterFrame = function()
50100 Push "onEnterFrame"
12564 m_CountingDialog.onEnterFrame = function()
50101 DefineFunction2 "", 0, 2, false, false, true, false, true, false, true, false,
false { 12564 m_CountingDialog.onEnterFrame =
function()
```
IMO, `DefineFunction2 "CountingDialogExchangeSubmit"` actually maps to the closing brace
of the function in ActionScript.
Is that because the bytecode offset <-> p-code line mapping refers to the last
instruction?
Yes, I think that in SWD, actionscript lines map to p-code lines the way AS line maps to
last P-code instruction line it uses.
Concerning the line +1 shifting: no worries, that was just a bug on my side. Lines in the
SWD are 1-based, and I forgot to adapt to that in my Python lists on one side of the
pivot.
I successfully mapped p-code lines to ActionScript lines, however, it is very sparse.
I would like to know if there is more to do about it, like you probably do in ffdec.
I was also wondering if it would be right to simply "extend forward" an inferred
ActionScript line from p-code to all subsequent p-code lines which do not have any match?
