From ac66eb740ba51a9cd79dbbb1d7265aeef8c16a24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Mon, 4 Jan 2021 10:10:23 +0100 Subject: [PATCH] Fixed: Correct AS/P-code matching in editor for AS3 after using deobfuscation --- CHANGELOG.md | 1 + .../decompiler/flash/abc/avm2/AVM2Code.java | 6 ++++++ .../abc/avm2/instructions/AVM2Instruction.java | 11 +++++++++++ .../decompiler/flash/abc/types/MethodBody.java | 4 +++- .../jpexs/decompiler/flash/action/Action.java | 12 ++++++++++++ .../flash/helpers/HighlightedTextWriter.java | 10 ++++++++-- .../jpexs/decompiler/graph/GraphSourceItem.java | 16 ++++++++++++++++ 7 files changed, 57 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b5eb6c96..4950c6c16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file. ### Fixed - Scaling - Distorted images/canvas on Hi-dpi monitors for Java 9 and later - Radial gradients focal point reading/writing +- Correct AS/P-code matching in editor for AS3 after using deobfuscation ## [11.3.0] - 2020-04-25 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 2600d6842..1d048900c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -2937,4 +2937,10 @@ public class AVM2Code implements Cloneable { throw new RuntimeException(); } } + + public void markVirtualAddresses() { + for (AVM2Instruction ins : code) { + ins.setVirtualAddress(ins.getAddress()); + } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java index f1420e948..3945488fc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java @@ -63,6 +63,8 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { private String file; + private long virtualAddress = -1; + @Override public long getFileOffset() { return -1; @@ -530,4 +532,13 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { body.setModified(); } + @Override + public long getVirtualAddress() { + return virtualAddress; + } + + @Override + public void setVirtualAddress(long virtualAddress) { + this.virtualAddress = virtualAddress; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index ef49c63a0..69bb4298b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.types; import com.jpexs.decompiler.flash.SWFInputStream; @@ -384,6 +385,7 @@ public final class MethodBody implements Cloneable { public MethodBody convertMethodBody(ConvertData convertData, String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait, ScopeStack scopeStack, boolean isStaticInitializer, List fullyQualifiedNames, List initTraits) throws InterruptedException { MethodBody body = clone(); AVM2Code code = body.getCode(); + code.markVirtualAddresses(); code.fixJumps(path, body); if (convertData.deobfuscationMode != 0) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index c69e7894c..3adb18044 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -127,6 +127,8 @@ public abstract class Action implements GraphSourceItem { private long address; + private long virtualAddress = -1; + @Override public long getLineOffset() { return fileOffset; @@ -1232,4 +1234,14 @@ public abstract class Action implements GraphSourceItem { public String getFile() { return null; } + + @Override + public long getVirtualAddress() { + return virtualAddress; + } + + @Override + public void setVirtualAddress(long virtualAddress) { + this.virtualAddress = virtualAddress; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java index 14608dd59..41b6417f4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/HighlightedTextWriter.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.helpers; import com.jpexs.decompiler.flash.configuration.Configuration; @@ -201,7 +202,12 @@ public class HighlightedTextWriter extends GraphTextWriter { HighlightData ndata = new HighlightData(); ndata.merge(itemPos.data); ndata.merge(data); - ndata.offset = src.getAddress() + pos; + long virtualAddress = src.getVirtualAddress(); + if (virtualAddress != -1) { + ndata.offset = virtualAddress + pos; + } else { + ndata.offset = src.getAddress() + pos; + } ndata.fileOffset = src.getFileOffset(); if (itemPos.startLineItem != null) { ndata.firstLineOffset = itemPos.startLineItem.getLineOffset(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphSourceItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphSourceItem.java index 66bf74294..1feb9f7b9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphSourceItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphSourceItem.java @@ -59,4 +59,20 @@ public interface GraphSourceItem extends Serializable, Cloneable { public String getFile(); public abstract int getBytesLength(); + + /** + * Gets virtual address. A virtual adress can be used for storing original + * address before applying deobfuscation + * + * @return + */ + public long getVirtualAddress(); + + /** + * Sets virtual address. A virtual adress can be used for storing original + * address before applying deobfuscation + * + * @param virtualAddress + */ + public void setVirtualAddress(long virtualAddress); }