deobfuscation mode switch

This commit is contained in:
honfika
2014-08-23 20:12:59 +02:00
parent 0c19a54c02
commit c21a1b2f61
13 changed files with 100 additions and 39 deletions
@@ -195,7 +195,7 @@ public class MethodBody implements Cloneable, Serializable {
MethodBody b = Helper.deepCopy(this);
AVM2Code deobfuscated = b.code;
deobfuscated.markMappedOffsets();
if (Configuration.autoDeobfuscate.get()) {
if (Configuration.deobfuscationMode.get() != 0) {
try {
deobfuscated.removeTraps(constants, trait, method_info.get(this.method_info), b, abc, scriptIndex, classIndex, isStatic, path);
} catch (StackOverflowError ex) {
@@ -97,7 +97,7 @@ public class ActionListReader {
@Override
public ActionList call() throws IOException, InterruptedException {
return readActionList(listeners, sis, version, ip, endIp, path, Configuration.autoDeobfuscate.get());
return readActionList(listeners, sis, version, ip, endIp, path, Configuration.deobfuscationMode.get());
}
}, Configuration.decompilationTimeoutSingleMethod.get(), TimeUnit.SECONDS);
@@ -130,7 +130,7 @@ public class ActionListReader {
* @throws IOException
* @throws java.lang.InterruptedException
*/
public static ActionList readActionList(List<DisassemblyListener> listeners, SWFInputStream sis, int version, int ip, int endIp, String path, boolean deobfuscate) throws IOException, InterruptedException {
public static ActionList readActionList(List<DisassemblyListener> listeners, SWFInputStream sis, int version, int ip, int endIp, String path, int deobfuscationMode) throws IOException, InterruptedException {
ConstantPool cpool = new ConstantPool();
// Map of the actions. Use TreeMap to sort the keys in ascending order
@@ -178,13 +178,18 @@ public class ActionListReader {
}
}
if (deobfuscate) {
if (deobfuscationMode == 1) {
try {
actions = deobfuscateActionList(listeners, actions, version, 0, path);
updateActionLengths(actions, version);
} catch (OutOfMemoryError | StackOverflowError | TranslateException ex) {
// keep orignal (not deobfuscated) actions
Logger.getLogger(ActionListReader.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
try {
new ActionDeobfuscatorSimple().actionListParsed(actions, sis.getSwf());
new ActionDeobfuscator().actionListParsed(actions, sis.getSwf());
/*actions = deobfuscateActionList(listeners, actions, version, 0, path);
updateActionLengths(actions, version);
removeZeroJumps(actions, version);*/
} catch (OutOfMemoryError | StackOverflowError | TranslateException ex) {
// keep orignal (not deobfuscated) actions
Logger.getLogger(ActionListReader.class.getName()).log(Level.SEVERE, null, ex);
@@ -38,6 +38,7 @@ import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ActionSetVariable;
import com.jpexs.decompiler.flash.action.swf4.ActionSubtract;
import com.jpexs.decompiler.flash.action.swf4.ConstantIndex;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionAdd2;
import com.jpexs.decompiler.flash.action.swf5.ActionBitAnd;
import com.jpexs.decompiler.flash.action.swf5.ActionBitLShift;
@@ -108,7 +109,7 @@ public class ActionDeobfuscator implements SWFDecompilerListener {
byte[] actionBytes = Action.actionsToBytes(actions, true, SWF.DEFAULT_VERSION);
try {
SWFInputStream rri = new SWFInputStream(swf, actionBytes);
ActionList newActions = ActionListReader.readActionList(new ArrayList<DisassemblyListener>(), rri, SWF.DEFAULT_VERSION, 0, actionBytes.length, "", false);
ActionList newActions = ActionListReader.readActionList(new ArrayList<DisassemblyListener>(), rri, SWF.DEFAULT_VERSION, 0, actionBytes.length, "", 0);
actions.setActions(newActions);
} catch (IOException | InterruptedException ex) {
Logger.getLogger(ActionDeobfuscator.class.getName()).log(Level.SEVERE, null, ex);
@@ -364,7 +365,7 @@ public class ActionDeobfuscator implements SWFDecompilerListener {
ActionPush push = (ActionPush) action;
boolean ok = true;
for (Object value : push.values) {
if (value instanceof ConstantIndex) {
if (value instanceof ConstantIndex || value instanceof RegisterNumber) {
ok = false;
break;
}
@@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.ActionSubtract;
import com.jpexs.decompiler.flash.action.swf4.ConstantIndex;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionAdd2;
import com.jpexs.decompiler.flash.action.swf5.ActionBitAnd;
import com.jpexs.decompiler.flash.action.swf5.ActionBitLShift;
@@ -152,7 +153,7 @@ public class ActionDeobfuscatorSimple implements SWFDecompilerListener {
ActionPush push = (ActionPush) action;
boolean ok = true;
for (Object value : push.values) {
if (value instanceof ConstantIndex) {
if (value instanceof ConstantIndex || value instanceof RegisterNumber) {
ok = false;
break;
}
@@ -114,7 +114,7 @@ public class ActionPush extends Action {
values.add(sis.readDOUBLE("double"));
break;
case 7:
long el = sis.readSI32("el");
long el = sis.readSI32("integer");
values.add((Long) el);
break;
case 8:
@@ -80,9 +80,9 @@ public class Configuration {
@ConfigurationCategory("decompilation")
public static final ConfigurationItem<Integer> parallelThreadCount = null;
@ConfigurationDefaultBoolean(false)
@ConfigurationDefaultInt(0)
@ConfigurationCategory("script")
public static final ConfigurationItem<Boolean> autoDeobfuscate = null;
public static final ConfigurationItem<Integer> deobfuscationMode = null;
@ConfigurationDefaultBoolean(true)
@ConfigurationCategory("decompilation")
@@ -105,7 +105,7 @@ public class CommandLineArgumentParser {
Configuration.decompile,
Configuration.parallelSpeedUp,
Configuration.internalFlashViewer,
Configuration.autoDeobfuscate,
//Configuration.autoDeobfuscate,
Configuration.cacheOnDisk
};
@@ -87,7 +87,7 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener {
private final MainFrameClassic mainFrame;
private JCheckBoxMenuItem miAutoDeobfuscation;
//private JCheckBoxMenuItem miAutoDeobfuscation;
private JCheckBoxMenuItem miInternalViewer;
private JCheckBoxMenuItem miParallelSpeedUp;
private JCheckBoxMenuItem miAssociate;
@@ -199,10 +199,10 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener {
miDeobfuscation.setActionCommand(ACTION_DEOBFUSCATE);
miDeobfuscation.addActionListener(this);
miAutoDeobfuscation = new JCheckBoxMenuItem(translate("menu.settings.autodeobfuscation"));
miAutoDeobfuscation.setSelected(Configuration.autoDeobfuscate.get());
miAutoDeobfuscation.addActionListener(this);
miAutoDeobfuscation.setActionCommand(ACTION_AUTO_DEOBFUSCATE);
//miAutoDeobfuscation = new JCheckBoxMenuItem(translate("menu.settings.autodeobfuscation"));
//miAutoDeobfuscation.setSelected(Configuration.autoDeobfuscate.get());
//miAutoDeobfuscation.addActionListener(this);
//miAutoDeobfuscation.setActionCommand(ACTION_AUTO_DEOBFUSCATE);
JMenuItem miRenameOneIdentifier = new JMenuItem(translate("menu.tools.deobfuscation.globalrename"));
miRenameOneIdentifier.setActionCommand(ACTION_RENAME_ONE_IDENTIFIER);
@@ -271,7 +271,7 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener {
miAutoRenameIdentifiers.addActionListener(this);
JMenu menuSettings = new JMenu(translate("menu.settings"));
menuSettings.add(miAutoDeobfuscation);
//menuSettings.add(miAutoDeobfuscation);
menuSettings.add(miInternalViewer);
menuSettings.add(miParallelSpeedUp);
menuSettings.add(miDecompile);
@@ -442,14 +442,14 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener {
case ACTION_SEARCH_AS:
mainFrame.panel.searchAs();
break;
case ACTION_AUTO_DEOBFUSCATE:
/*case ACTION_AUTO_DEOBFUSCATE:
if (View.showConfirmDialog(mainFrame.panel, translate("message.confirm.autodeobfuscate") + "\r\n" + (miAutoDeobfuscation.isSelected() ? translate("message.confirm.on") : translate("message.confirm.off")), translate("message.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Configuration.autoDeobfuscate.set(miAutoDeobfuscation.isSelected());
mainFrame.panel.autoDeobfuscateChanged();
} else {
miAutoDeobfuscation.setSelected(!miAutoDeobfuscation.isSelected());
}
break;
break;*/
case ACTION_EXIT:
mainFrame.panel.setVisible(false);
if (Main.proxyFrame != null) {
@@ -123,10 +123,13 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
static final String ACTION_CHECK_RESOURCES = "CHECKRESOURCES";
static final String ACTION_VIEWMODE_RESOURCES = "VIEWMODERESOURCES";
static final String ACTION_VIEWMODE_HEX = "VIEWMODEHEX";
static final String ACTION_DEOBFUSCATION_MODE_DISABLED = "DEOBFUSCATIONMODEDISABLED";
static final String ACTION_DEOBFUSCATION_MODE_OLD = "DEOBFUSCATIONMODEOLD";
static final String ACTION_DEOBFUSCATION_MODE_NEW = "DEOBFUSCATIONMODENEW";
private final MainFrameRibbon mainFrame;
private JCheckBox miAutoDeobfuscation;
//private JCheckBox miAutoDeobfuscation;
private JCheckBox miInternalViewer;
private JCheckBox miDumpView;
private JCheckBox miParallelSpeedUp;
@@ -144,6 +147,9 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
private JCommandButton importTextCommandButton;
private JCommandToggleButton viewModeResourcesToggleButton;
private JCommandToggleButton viewModeHexToggleButton;
private JCommandToggleButton deobfuscationModeDisabledToggleButton;
private JCommandToggleButton deobfuscationModeOldToggleButton;
private JCommandToggleButton deobfuscationModeNewToggleButton;
private JCommandButton reloadCommandButton;
private JCommandButton renameinvalidCommandButton;
@@ -339,7 +345,7 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
JRibbonBand viewBand = new JRibbonBand(translate("menu.view"), null);
viewBand.setResizePolicies(getResizePolicies(viewBand));
CommandToggleButtonGroup grp = new CommandToggleButtonGroup();
CommandToggleButtonGroup grpViewMode = new CommandToggleButtonGroup();
viewModeResourcesToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.view.resources")), View.getResizableIcon("viewresources16"));
assignListener(viewModeResourcesToggleButton, ACTION_VIEWMODE_RESOURCES);
@@ -347,13 +353,13 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
viewModeHexToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.view.hex")), View.getResizableIcon("viewhex16"));
assignListener(viewModeHexToggleButton, ACTION_VIEWMODE_HEX);
grp.add(viewModeResourcesToggleButton);
grp.add(viewModeHexToggleButton);
grpViewMode.add(viewModeResourcesToggleButton);
grpViewMode.add(viewModeHexToggleButton);
if (Configuration.dumpView.get()) {
grp.setSelected(viewModeHexToggleButton, true);
grpViewMode.setSelected(viewModeHexToggleButton, true);
} else {
grp.setSelected(viewModeResourcesToggleButton, true);
grpViewMode.setSelected(viewModeResourcesToggleButton, true);
}
viewBand.addCommandButton(viewModeResourcesToggleButton, RibbonElementPriority.MEDIUM);
@@ -420,10 +426,10 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
JRibbonBand settingsBand = new JRibbonBand(translate("menu.settings"), null);
settingsBand.setResizePolicies(getResizePolicies(settingsBand));
miAutoDeobfuscation = new JCheckBox(translate("menu.settings.autodeobfuscation"));
miAutoDeobfuscation.setSelected(Configuration.autoDeobfuscate.get());
miAutoDeobfuscation.addActionListener(this);
miAutoDeobfuscation.setActionCommand(ACTION_AUTO_DEOBFUSCATE);
//miAutoDeobfuscation = new JCheckBox(translate("menu.settings.autodeobfuscation"));
//miAutoDeobfuscation.setSelected(Configuration.autoDeobfuscate.get());
//miAutoDeobfuscation.addActionListener(this);
//miAutoDeobfuscation.setActionCommand(ACTION_AUTO_DEOBFUSCATE);
miInternalViewer = new JCheckBox(translate("menu.settings.internalflashviewer"));
miInternalViewer.setSelected(Configuration.internalFlashViewer.get() || externalFlashPlayerUnavailable);
@@ -467,7 +473,7 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
miDumpView.setSelected(Configuration.dumpView.get());
miDumpView.setActionCommand(ACTION_DUMP_VIEW_SWITCH);
miDumpView.addActionListener(this);*/
settingsBand.addRibbonComponent(new JRibbonComponent(miAutoDeobfuscation));
//settingsBand.addRibbonComponent(new JRibbonComponent(miAutoDeobfuscation));
settingsBand.addRibbonComponent(new JRibbonComponent(miInternalViewer));
settingsBand.addRibbonComponent(new JRibbonComponent(miParallelSpeedUp));
settingsBand.addRibbonComponent(new JRibbonComponent(miDecompile));
@@ -496,7 +502,42 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
assignListener(clearRecentFilesCommandButton, ACTION_CLEAR_RECENT_FILES);
advancedSettingsBand.addCommandButton(clearRecentFilesCommandButton, RibbonElementPriority.MEDIUM);
return new RibbonTask(translate("menu.settings"), settingsBand, languageBand, advancedSettingsBand);
JRibbonBand deobfuscationBand = new JRibbonBand(translate("menu.deobfuscation"), null);
deobfuscationBand.setResizePolicies(getResizePolicies(deobfuscationBand));
CommandToggleButtonGroup grpDeobfuscation = new CommandToggleButtonGroup();
deobfuscationModeDisabledToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.deobfuscation.disabled")), null);
assignListener(deobfuscationModeDisabledToggleButton, ACTION_DEOBFUSCATION_MODE_DISABLED);
deobfuscationModeOldToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.deobfuscation.old")), null);
assignListener(deobfuscationModeOldToggleButton, ACTION_DEOBFUSCATION_MODE_OLD);
deobfuscationModeNewToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.deobfuscation.new")), null);
assignListener(deobfuscationModeNewToggleButton, ACTION_DEOBFUSCATION_MODE_NEW);
grpDeobfuscation.add(deobfuscationModeDisabledToggleButton);
grpDeobfuscation.add(deobfuscationModeOldToggleButton);
grpDeobfuscation.add(deobfuscationModeNewToggleButton);
int deobfuscationMode = Configuration.deobfuscationMode.get();
switch (deobfuscationMode) {
case 0:
grpDeobfuscation.setSelected(deobfuscationModeDisabledToggleButton, true);
break;
case 1:
grpDeobfuscation.setSelected(deobfuscationModeOldToggleButton, true);
break;
case 2:
grpDeobfuscation.setSelected(deobfuscationModeNewToggleButton, true);
break;
}
deobfuscationBand.addCommandButton(deobfuscationModeDisabledToggleButton, RibbonElementPriority.MEDIUM);
deobfuscationBand.addCommandButton(deobfuscationModeOldToggleButton, RibbonElementPriority.MEDIUM);
deobfuscationBand.addCommandButton(deobfuscationModeNewToggleButton, RibbonElementPriority.MEDIUM);
return new RibbonTask(translate("menu.settings"), settingsBand, languageBand, advancedSettingsBand, deobfuscationBand);
}
private RibbonTask createHelpRibbonTask() {
@@ -676,14 +717,14 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
case ACTION_TIMELINE:
mainFrame.panel.timeline();
break;
case ACTION_AUTO_DEOBFUSCATE:
/*case ACTION_AUTO_DEOBFUSCATE:
if (View.showConfirmDialog(mainFrame.panel, translate("message.confirm.autodeobfuscate") + "\r\n" + (miAutoDeobfuscation.isSelected() ? translate("message.confirm.on") : translate("message.confirm.off")), translate("message.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
Configuration.autoDeobfuscate.set(miAutoDeobfuscation.isSelected());
mainFrame.panel.autoDeobfuscateChanged();
} else {
miAutoDeobfuscation.setSelected(!miAutoDeobfuscation.isSelected());
}
break;
break;*/
case ACTION_CLEAR_RECENT_FILES:
Configuration.recentFiles.set(null);
break;
@@ -68,9 +68,6 @@ config.description.parallelSpeedUp = Parallelism can speed up decompilation
config.name.parallelThreadCount = Number of threads
config.description.parallelThreadCount = Number of threads for parallel speedup
config.name.autoDeobfuscate = Automatic deobfuscation
config.description.autoDeobfuscate = Run deobfuscation on every file before ActionScript decompilation
config.name.cacheOnDisk = Use caching on disk
config.description.cacheOnDisk = Cache already decompiled parts on hard drive instead of memory
@@ -263,3 +260,6 @@ config.description.lzmaFastBytes = Fast bytes parameter of the LZMA encoder
#temporary setting, do not translate it
config.name.pluginPath = Plugin Path
config.description.pluginPath = -
config.name.deobfuscationMode = Deobfuscation mode
config.description.deobfuscationMode = Run deobfuscation on every file before ActionScript decompilation
@@ -260,3 +260,6 @@ config.description.textExportExportFontFace = Bet\u0171t\u00edpus f\u00e1jlok be
config.name.lzmaFastBytes = LZMA fast bytes (\u00e9rv\u00e9nyes \u00e9rt\u00e9kek: 5-255)
config.description.textExportExportFontFace = Az LZMA t\u00f6m\u00f6r\u00edt\u0151 "Fast bytes" param\u00e9tere
config.name.autoDeobfuscate = Deobfuszk\u00e1l\u00e1si m\u00f3d
config.description.autoDeobfuscate = Futtassa a deobfuszk\u00e1l\u00e1st minden f\u00e1jlon az ActionScript visszaford\u00edt\u00e1sa el\u0151tt
@@ -513,3 +513,8 @@ contextmenu.saveToFile = Save to File
contextmenu.parseActions = Parse actions
contextmenu.parseABC = Parse ABC
contextmenu.parseInstructions = Parse AVM2 Instrctions
menu.deobfuscation = Debofuscation
menu.file.deobfuscation.disabled = Disabled
menu.file.deobfuscation.old = Olddddddddddd
menu.file.deobfuscation.new = New
@@ -513,3 +513,8 @@ contextmenu.saveToFile = Ment\u00e9s f\u00e1jlba
contextmenu.parseActions = Action-\u00f6k elemz\u00e9se
contextmenu.parseABC = ABC elemz\u00e9se
contextmenu.parseInstructions = AVM2 utas\u00edt\u00e1sok elemz\u00e9se
menu.deobfuscation = Deobfuszk\u00e1l\u00e1s
menu.file.deobfuscation.disabled = Letiltva
menu.file.deobfuscation.old = R\u00e9gi
menu.file.deobfuscation.new = \u00daj