deobfuscation mode switch logic implemented

This commit is contained in:
honfika
2014-08-23 20:53:30 +02:00
parent c8208c0360
commit e4d30b03de
10 changed files with 236 additions and 234 deletions

View File

@@ -195,7 +195,7 @@ public class MethodBody implements Cloneable, Serializable {
MethodBody b = Helper.deepCopy(this);
AVM2Code deobfuscated = b.code;
deobfuscated.markMappedOffsets();
if (Configuration.deobfuscationMode.get() != 0) {
if (Configuration.autoDeobfuscate.get()) {
try {
deobfuscated.removeTraps(constants, trait, method_info.get(this.method_info), b, abc, scriptIndex, classIndex, isStatic, path);
} catch (StackOverflowError ex) {

View File

@@ -93,11 +93,12 @@ public class ActionListReader {
*/
public static ActionList readActionListTimeout(final List<DisassemblyListener> listeners, final SWFInputStream sis, final int version, final int ip, final int endIp, final String path) throws IOException, InterruptedException, TimeoutException {
try {
final int deobfuscationMode = Configuration.autoDeobfuscate.get() ? Configuration.deobfuscationMode.get() : -1;
ActionList actions = CancellableWorker.call(new Callable<ActionList>() {
@Override
public ActionList call() throws IOException, InterruptedException {
return readActionList(listeners, sis, version, ip, endIp, path, Configuration.deobfuscationMode.get());
return readActionList(listeners, sis, version, ip, endIp, path, deobfuscationMode);
}
}, Configuration.decompilationTimeoutSingleMethod.get(), TimeUnit.SECONDS);
@@ -125,7 +126,7 @@ public class ActionListReader {
* @param ip
* @param endIp
* @param path
* @param deobfuscate
* @param deobfuscationMode
* @return List of actions
* @throws IOException
* @throws java.lang.InterruptedException
@@ -178,7 +179,7 @@ public class ActionListReader {
}
}
if (deobfuscationMode == 1) {
if (deobfuscationMode == 0) {
try {
actions = deobfuscateActionList(listeners, actions, version, 0, path);
updateActionLengths(actions, version);
@@ -186,7 +187,7 @@ public class ActionListReader {
// keep orignal (not deobfuscated) actions
Logger.getLogger(ActionListReader.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
} else if (deobfuscationMode == 1) {
try {
new ActionDeobfuscatorSimple().actionListParsed(actions, sis.getSwf());
new ActionDeobfuscator().actionListParsed(actions, sis.getSwf());

View File

@@ -109,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, "", 0);
ActionList newActions = ActionListReader.readActionList(new ArrayList<DisassemblyListener>(), rri, SWF.DEFAULT_VERSION, 0, actionBytes.length, "", -1);
actions.setActions(newActions);
} catch (IOException | InterruptedException ex) {
Logger.getLogger(ActionDeobfuscator.class.getName()).log(Level.SEVERE, null, ex);

View File

@@ -80,6 +80,10 @@ public class Configuration {
@ConfigurationCategory("decompilation")
public static final ConfigurationItem<Integer> parallelThreadCount = null;
@ConfigurationDefaultBoolean(false)
@ConfigurationCategory("script")
public static final ConfigurationItem<Boolean> autoDeobfuscate = null;
@ConfigurationDefaultInt(0)
@ConfigurationCategory("script")
public static final ConfigurationItem<Integer> deobfuscationMode = null;

View File

@@ -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,11 @@ 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);
miRenameOneIdentifier.addActionListener(this);
@@ -270,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);
@@ -441,14 +442,14 @@ public class MainFrameClassicMenu implements MainFrameMenu, ActionListener {
case ACTION_SEARCH_AS:
mainFrame.panel.searchAs();
break;
/*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;*/
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;
case ACTION_EXIT:
mainFrame.panel.setVisible(false);
if (Main.proxyFrame != null) {

View File

@@ -123,13 +123,12 @@ 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;
@@ -147,7 +146,6 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
private JCommandButton importTextCommandButton;
private JCommandToggleButton viewModeResourcesToggleButton;
private JCommandToggleButton viewModeHexToggleButton;
private JCommandToggleButton deobfuscationModeDisabledToggleButton;
private JCommandToggleButton deobfuscationModeOldToggleButton;
private JCommandToggleButton deobfuscationModeNewToggleButton;
@@ -283,7 +281,7 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
resizePolicies.add(new CoreRibbonResizePolicies.Mirror(ribbonBand.getControlPanel()));
return resizePolicies;
}
private List<RibbonBandResizePolicy> getResizePolicies(JRibbonBand ribbonBand) {
List<RibbonBandResizePolicy> resizePolicies = new ArrayList<>();
resizePolicies.add(new CoreRibbonResizePolicies.Mirror(ribbonBand.getControlPanel()));
@@ -432,10 +430,11 @@ 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);
if (externalFlashPlayerUnavailable) {
@@ -478,7 +477,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));
@@ -507,38 +506,30 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
assignListener(clearRecentFilesCommandButton, ACTION_CLEAR_RECENT_FILES);
advancedSettingsBand.addCommandButton(clearRecentFilesCommandButton, RibbonElementPriority.MEDIUM);
JRibbonBand deobfuscationBand = new JRibbonBand(translate("menu.deobfuscation"), null);
JRibbonBand deobfuscationBand = new JRibbonBand(translate("menu.deobfuscation"), null);
deobfuscationBand.setResizePolicies(getEmptyResizePolicies(deobfuscationBand)); //TODO: add icons and change this to getResizePolicies
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:
case 1:
grpDeobfuscation.setSelected(deobfuscationModeNewToggleButton, true);
break;
}
deobfuscationBand.addCommandButton(deobfuscationModeDisabledToggleButton, RibbonElementPriority.MEDIUM);
deobfuscationBand.addCommandButton(deobfuscationModeOldToggleButton, RibbonElementPriority.MEDIUM);
deobfuscationBand.addCommandButton(deobfuscationModeNewToggleButton, RibbonElementPriority.MEDIUM);
@@ -712,6 +703,14 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
Configuration.dumpView.set(true);
mainFrame.panel.showDumpView(true);
break;
case ACTION_DEOBFUSCATION_MODE_OLD:
Configuration.deobfuscationMode.set(0);
mainFrame.panel.autoDeobfuscateChanged();
break;
case ACTION_DEOBFUSCATION_MODE_NEW:
Configuration.deobfuscationMode.set(1);
mainFrame.panel.autoDeobfuscateChanged();
break;
case ACTION_DUMP_VIEW_SWITCH:
Configuration.dumpView.set(miDumpView.isSelected());
mainFrame.panel.showDumpView(miDumpView.isSelected());
@@ -722,14 +721,14 @@ public class MainFrameRibbonMenu implements MainFrameMenu, ActionListener {
case ACTION_TIMELINE:
mainFrame.panel.timeline();
break;
/*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;*/
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;
case ACTION_CLEAR_RECENT_FILES:
Configuration.recentFiles.set(null);
break;

View File

@@ -515,6 +515,5 @@ contextmenu.parseABC = Parse ABC
contextmenu.parseInstructions = Parse AVM2 Instrctions
menu.deobfuscation = Deobfuscation
menu.file.deobfuscation.disabled = Disabled
menu.file.deobfuscation.old = Old
menu.file.deobfuscation.new = New

View File

@@ -515,6 +515,5 @@ 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

View File

@@ -43,7 +43,7 @@ import org.testng.annotations.Test;
* @author JPEXS
*/
public class ActionScript2ModificationTest extends ActionStript2TestBase {
@BeforeClass
public void init() throws IOException, InterruptedException {
Main.initLogging(false);
@@ -60,14 +60,13 @@ public class ActionScript2ModificationTest extends ActionStript2TestBase {
if (matcher.find()) {
String str = matcher.group(1);
actions = actions.replaceAll(str, "label_" + labelCnt++);
}
else {
} else {
break;
}
}
return actions;
}
public void testRemoveAction(String actionsString, String expectedResult, int[] actionsToRemove) {
try {
ActionList actions = ASMParser.parse(0, true, actionsString, swf.version, false);
@@ -75,7 +74,7 @@ public class ActionScript2ModificationTest extends ActionStript2TestBase {
for (int i : actionsToRemove) {
actions.removeAction(i);
}
DoActionTag doa = getFirstActionTag();
doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version));
HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false);
@@ -84,19 +83,19 @@ public class ActionScript2ModificationTest extends ActionStript2TestBase {
actualResult = cleanPCode(actualResult);
expectedResult = cleanPCode(expectedResult);
Assert.assertEquals(actualResult, expectedResult);
} catch (IOException | ParseException | InterruptedException ex) {
fail();
}
}
public void testAddAction(String actionsString, String expectedResult, Action action, int index) {
try {
ActionList actions = ASMParser.parse(0, true, actionsString, swf.version, false);
actions.addAction(index, action);
DoActionTag doa = getFirstActionTag();
doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version));
HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false);
@@ -105,226 +104,226 @@ public class ActionScript2ModificationTest extends ActionStript2TestBase {
actualResult = cleanPCode(actualResult);
expectedResult = cleanPCode(expectedResult);
Assert.assertEquals(actualResult, expectedResult);
} catch (IOException | ParseException | InterruptedException ex) {
fail();
}
}
@Test
public void testRemoveJumpAction() {
String actionsString =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"Return\n" +
"}\n" +
"Push 2\n" +
"Jump label_1\n" + // remove this action
String actionsString
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "Return\n"
+ "}\n"
+ "Push 2\n"
+ "Jump label_1\n" + // remove this action
"label_1:Push 3";
String expectedResult =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"Return\n" +
"}\n" +
"Push 2 3";
testRemoveAction(actionsString, expectedResult, new int[] {5});
String expectedResult
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "Return\n"
+ "}\n"
+ "Push 2 3";
testRemoveAction(actionsString, expectedResult, new int[]{5});
}
@Test
public void testRemoveActionFromContainer() {
String actionsString =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" + // remove this action
"Return\n" +
"}\n" +
"Push 2\n" +
"Jump label_1\n" +
"label_1:Push 3";
String expectedResult =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Return\n" +
"}\n" +
"Push 2\n" +
"Jump label_1\n" +
"label_1:Push 3";
testRemoveAction(actionsString, expectedResult, new int[] {2});
String actionsString
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n" + // remove this action
"Return\n"
+ "}\n"
+ "Push 2\n"
+ "Jump label_1\n"
+ "label_1:Push 3";
String expectedResult
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Return\n"
+ "}\n"
+ "Push 2\n"
+ "Jump label_1\n"
+ "label_1:Push 3";
testRemoveAction(actionsString, expectedResult, new int[]{2});
}
@Test
public void testRemoveLastActionFromContainer() {
String actionsString =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" + // remove this action
"}\n" +
"Push 2\n" +
"Jump label_1\n" +
"label_1:Push 3";
String expectedResult =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"}\n" +
"Push 2\n" +
"Jump label_1\n" +
"label_1:Push 3";
testRemoveAction(actionsString, expectedResult, new int[] {3});
String actionsString
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n" + // remove this action
"}\n"
+ "Push 2\n"
+ "Jump label_1\n"
+ "label_1:Push 3";
String expectedResult
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "}\n"
+ "Push 2\n"
+ "Jump label_1\n"
+ "label_1:Push 3";
testRemoveAction(actionsString, expectedResult, new int[]{3});
}
@Test
public void testRemoveIfTargetAction() {
String actionsString =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:Push 4\n" + // remove this action
String actionsString
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:Push 4\n" + // remove this action
"Push 5"; // after removing the previous action the if action should jump here
String expectedResult =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:Push 5";
testRemoveAction(actionsString, expectedResult, new int[] {7});
String expectedResult
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:Push 5";
testRemoveAction(actionsString, expectedResult, new int[]{7});
}
@Test
public void testRemoveIfTargetLastAction() {
String actionsString =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:Push 4"; // remove this action
String expectedResult =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:";
testRemoveAction(actionsString, expectedResult, new int[] {7});
String actionsString
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:Push 4"; // remove this action
String expectedResult
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:";
testRemoveAction(actionsString, expectedResult, new int[]{7});
}
@Test
public void testAddAtion1() {
String actionsString =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:Push 4";
String expectedResult =
"ConstantPool\n" +
"GetMember\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:Push 4";
String actionsString
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:Push 4";
String expectedResult
= "ConstantPool\n"
+ "GetMember\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:Push 4";
testAddAction(actionsString, expectedResult, new ActionGetMember(), 1);
}
@Test
public void testAddAtionToContainer() {
String actionsString =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:Push 4";
String expectedResult =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"GetMember\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:Push 4";
String actionsString
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:Push 4";
String expectedResult
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "GetMember\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:Push 4";
testAddAction(actionsString, expectedResult, new ActionGetMember(), 2);
}
@Test
public void testAddActionIf() {
String actionsString =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"label_1:Push 4";
String expectedResult =
"ConstantPool\n" +
"DefineFunction \"test\" 1 \"p1\" {\n" +
"Push 1\n" +
"GetVariable\n" +
"}\n" +
"Push 2\n" +
"If label_1\n" +
"Push 3\n" +
"GetMember\n" +
"label_1:Push 4";
String actionsString
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "label_1:Push 4";
String expectedResult
= "ConstantPool\n"
+ "DefineFunction \"test\" 1 \"p1\" {\n"
+ "Push 1\n"
+ "GetVariable\n"
+ "}\n"
+ "Push 2\n"
+ "If label_1\n"
+ "Push 3\n"
+ "GetMember\n"
+ "label_1:Push 4";
testAddAction(actionsString, expectedResult, new ActionGetMember(), 7);
}
@Test
public void testAddToJumpTarget() {
String actionsString =
"ConstantPool\n" +
"If label_1\n" +
"GetMember\n" +
"label_1:Jump label_2\n" + // address 9
"label_2:Jump label_3\n" +
"label_3:Jump labelend\n" +
"labelend:End"; // address 24
String expectedResult =
"ConstantPool\n" +
"If label_1\n" +
"GetMember\n" +
"Jump label_4\n" +
"label_1:Jump label_2\n" +
"label_2:Jump label_3\n" +
"label_3:Jump label_4\n" +
"label_4:";
String actionsString
= "ConstantPool\n"
+ "If label_1\n"
+ "GetMember\n"
+ "label_1:Jump label_2\n" + // address 9
"label_2:Jump label_3\n"
+ "label_3:Jump labelend\n"
+ "labelend:End"; // address 24
String expectedResult
= "ConstantPool\n"
+ "If label_1\n"
+ "GetMember\n"
+ "Jump label_4\n"
+ "label_1:Jump label_2\n"
+ "label_2:Jump label_3\n"
+ "label_3:Jump label_4\n"
+ "label_4:";
ActionJump jump = new ActionJump(0);
jump.setAddress(9);
jump.setJumpOffset(24 - 9 - 5);

View File

@@ -21,7 +21,7 @@ package com.jpexs.decompiler.flash;
* @author JPEXS
*/
public class ActionScriptTestBase {
protected String cleanPCode(String pCode) {
pCode = pCode.replaceAll(" *[\r\n]+ *", "\n").trim();
pCode = pCode.replaceAll(" +", " ").trim();