From 689ec294485245f507e0ad4af89277ffe533e302 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Tue, 2 Dec 2014 22:38:46 +0100 Subject: [PATCH] faster editor.setText (but still so slow with huge texts) faster AS2 deobfuscation (when multiple jumps should be replaced with a single jump) --- .../ActionDeobfuscatorSimple.java | 40 +++-- .../flash/gui/abc/UndoFixedEditorPane.java | 165 ++++++++++-------- 2 files changed, 112 insertions(+), 93 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscatorSimple.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscatorSimple.java index 8adfcf1d1..0a0da09fe 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscatorSimple.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscatorSimple.java @@ -147,22 +147,27 @@ public class ActionDeobfuscatorSimple implements SWFDecompilerListener { Action target = actions.get(result.idx); Action prevAction = actions.get(i); - if (!result.stack.isEmpty()) { - ActionPush push = new ActionPush(0); - push.values.clear(); - for (GraphTargetItem graphTargetItem : result.stack) { - DirectValueActionItem dv = (DirectValueActionItem) graphTargetItem; - push.values.add(dv.value); + if (result.stack.isEmpty() && prevAction instanceof ActionJump) { + ActionJump jump = (ActionJump) prevAction; + jump.setJumpOffset((int) (target.getAddress() - jump.getAddress() - jump.getTotalActionLength())); + } else { + if (!result.stack.isEmpty()) { + ActionPush push = new ActionPush(0); + push.values.clear(); + for (GraphTargetItem graphTargetItem : result.stack) { + DirectValueActionItem dv = (DirectValueActionItem) graphTargetItem; + push.values.add(dv.value); + } + push.setAddress(prevAction.getAddress()); + actions.addAction(i++, push); + prevAction = push; } - push.setAddress(prevAction.getAddress()); - actions.addAction(i++, push); - prevAction = push; - } - ActionJump jump = new ActionJump(0); - jump.setAddress(prevAction.getAddress()); - jump.setJumpOffset((int) (target.getAddress() - jump.getAddress() - jump.getTotalActionLength())); - actions.addAction(i++, jump); + ActionJump jump = new ActionJump(0); + jump.setAddress(prevAction.getAddress()); + jump.setJumpOffset((int) (target.getAddress() - jump.getAddress() - jump.getTotalActionLength())); + actions.addAction(i++, jump); + } Action nextAction = actions.size() > i ? actions.get(i) : null; @@ -277,13 +282,12 @@ public class ActionDeobfuscatorSimple implements SWFDecompilerListener { break; } - Action action = actions.get(idx); - instructionsProcessed++; - if (instructionsProcessed > executionLimit) { break; } + Action action = actions.get(idx); + /*System.out.print(action.getASMSource(actions, new ArrayList(), ScriptExportMode.PCODE)); for (int j = 0; j < stack.size(); j++) { System.out.print(" '" + stack.get(j).getResult() + "'"); @@ -348,6 +352,8 @@ public class ActionDeobfuscatorSimple implements SWFDecompilerListener { } } + instructionsProcessed++; + if (stack.allItemsFixed()) { result.idx = idx == actions.size() ? idx - 1 : idx; result.instructionsProcessed = instructionsProcessed; diff --git a/src/com/jpexs/decompiler/flash/gui/abc/UndoFixedEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/UndoFixedEditorPane.java index 13a518cef..3a2e2b82d 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/UndoFixedEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/UndoFixedEditorPane.java @@ -1,76 +1,89 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui.abc; - -import com.jpexs.decompiler.flash.configuration.Configuration; -import java.awt.event.KeyEvent; -import javax.swing.JEditorPane; -import javax.swing.text.Document; -import jsyntaxpane.SyntaxDocument; - -/** - * - * @author JPEXS - */ -public class UndoFixedEditorPane extends JEditorPane { - - @Override - public void setText(String t) { - if (getText() != t) { - super.setText(t); - clearUndos(); - } - } - - public void setText(String t, String contentType) { - if (getText() != t) { - // OK to check reference equals, because the string object should be the same - super.setText(null); - if (t.length() > Configuration.syntaxHighlightLimit.get()) { - setContentType("text/plain"); - } else { - if (!getContentType().equals(contentType)) { - setContentType(contentType); - } - } - super.setText(t); - clearUndos(); - } - } - - @Override - protected void processKeyEvent(KeyEvent ke) { - if (!isEditable()) { - // disable Ctrl-E: delete line - // and Ctrl-H: Search and replace - if ((ke.getKeyCode() == KeyEvent.VK_E && ke.isControlDown()) - || (ke.getKeyCode() == KeyEvent.VK_H && ke.isControlDown())) { - return; - } - } - - super.processKeyEvent(ke); - } - - public void clearUndos() { - Document doc = getDocument(); - if (doc instanceof SyntaxDocument) { - SyntaxDocument sdoc = (SyntaxDocument) doc; - sdoc.clearUndos(); - } - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui.abc; + +import com.jpexs.decompiler.flash.configuration.Configuration; +import java.awt.event.KeyEvent; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JEditorPane; +import static javax.swing.JEditorPane.createEditorKitForContentType; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import jsyntaxpane.SyntaxDocument; + +/** + * + * @author JPEXS + */ +public class UndoFixedEditorPane extends JEditorPane { + + @Override + public void setText(String t) { + setText(t, getContentType()); + } + + public void setText(String t, String contentType) { + if (!t.equals(getText())) { + boolean plain = t.length() > Configuration.syntaxHighlightLimit.get(); + if (plain) { + contentType = "text/plain"; + } + + try { + setContentType(contentType); + Document doc = getDocument(); + setDocument(new SyntaxDocument(null)); + doc.remove(0, doc.getLength()); + Reader r = new StringReader(t); + EditorKit kit = createEditorKitForContentType(contentType); + kit.read(r, doc, 0); + setDocument(doc); + } catch (BadLocationException | IOException ex) { + Logger.getLogger(UndoFixedEditorPane.class.getName()).log(Level.SEVERE, null, ex); + } + + clearUndos(); + } + } + + @Override + protected void processKeyEvent(KeyEvent ke) { + if (!isEditable()) { + // disable Ctrl-E: delete line + // and Ctrl-H: Search and replace + if ((ke.getKeyCode() == KeyEvent.VK_E && ke.isControlDown()) + || (ke.getKeyCode() == KeyEvent.VK_H && ke.isControlDown())) { + return; + } + } + + super.processKeyEvent(ke); + } + + public void clearUndos() { + Document doc = getDocument(); + if (doc instanceof SyntaxDocument) { + SyntaxDocument sdoc = (SyntaxDocument) doc; + sdoc.clearUndos(); + } + } +}