From 2609cfa9e3aae6686934a0ea0f96d937f1940e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 28 Sep 2013 08:42:42 +0200 Subject: [PATCH] Issue #382 AS3 Fixed adding new method --- trunk/src/com/jpexs/decompiler/flash/abc/ABC.java | 11 +++++++++-- .../com/jpexs/decompiler/flash/gui/abc/ABCPanel.java | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index ea53d4dd1..aae0f5cbb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -67,8 +67,15 @@ public class ABC { public int addMethodBody(MethodBody body) { bodies = Arrays.copyOf(bodies, bodies.length + 1); bodies[bodies.length - 1] = body; - bodyIdxFromMethodIdx = Arrays.copyOf(bodyIdxFromMethodIdx, bodyIdxFromMethodIdx.length + 1); - bodyIdxFromMethodIdx[bodyIdxFromMethodIdx.length - 1] = body.method_info; + if (body.method_info >= bodyIdxFromMethodIdx.length) { + int newlen = body.method_info + 1; + int oldlen = bodyIdxFromMethodIdx.length; + bodyIdxFromMethodIdx = Arrays.copyOf(bodyIdxFromMethodIdx, newlen); + for (int i = oldlen; i < newlen; i++) { + bodyIdxFromMethodIdx[i] = -1; + } + bodyIdxFromMethodIdx[body.method_info] = bodies.length - 1; + } return bodies.length - 1; } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 8e4b28435..bb459d567 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -22,6 +22,11 @@ import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; +import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.instructions.localregs.GetLocal0Ins; +import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ReturnVoidIns; +import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushScopeIns; +import com.jpexs.decompiler.flash.abc.avm2.parser.ASM3Parser; import com.jpexs.decompiler.flash.abc.types.ABCException; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -638,11 +643,15 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr body.max_stack = 1; body.exceptions = new ABCException[0]; AVM2Code code = new AVM2Code(); + code.code.add(new AVM2Instruction(0, new GetLocal0Ins(), new int[0], new byte[0])); + code.code.add(new AVM2Instruction(0, new PushScopeIns(), new int[0], new byte[0])); + code.code.add(new AVM2Instruction(0, new ReturnVoidIns(), new int[0], new byte[0])); body.code = code; Traits traits = new Traits(); traits.traits = new Trait[0]; body.traits = traits; abc.addMethodBody(body); + mi.setBody(body); t = tm; break; case Trait.TRAIT_SLOT: