mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-20 04:35:58 +00:00
AS2 deobfuscation fix
This commit is contained in:
@@ -120,7 +120,7 @@ public class ActionDeobfuscatorSimpleFast implements SWFDecompilerListener {
|
||||
if (isGetTime && a2 instanceof ActionIf) {
|
||||
ActionJump jump = new ActionJump(0);
|
||||
ActionItem jumpItem = new ActionItem(jump);
|
||||
jumpItem.jumpTarget = a2Item.jumpTarget;
|
||||
jumpItem.setJumpTarget(a2Item.getJumpTarget());
|
||||
iterator.remove(); // GetTime
|
||||
iterator.next();
|
||||
iterator.remove(); // If
|
||||
@@ -142,7 +142,7 @@ public class ActionDeobfuscatorSimpleFast implements SWFDecompilerListener {
|
||||
if (a instanceof ActionGetTime && a1 instanceof ActionIncrement && a2 instanceof ActionIf) {
|
||||
ActionJump jump = new ActionJump(0);
|
||||
ActionItem jumpItem = new ActionItem(jump);
|
||||
jumpItem.jumpTarget = a2Item.jumpTarget;
|
||||
jumpItem.setJumpTarget(a2Item.getJumpTarget());
|
||||
iterator.remove(); // GetTime
|
||||
iterator.next();
|
||||
iterator.remove(); // Increment
|
||||
@@ -159,14 +159,14 @@ public class ActionDeobfuscatorSimpleFast implements SWFDecompilerListener {
|
||||
return false;
|
||||
}
|
||||
|
||||
// private boolean removeObfuscationIfs(FastActionList actions) throws InterruptedException {
|
||||
// if (actions.isEmpty()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// actions.removeUnreachableActions();
|
||||
// actions.removeZeroJumps();
|
||||
//
|
||||
private boolean removeObfuscationIfs(FastActionList actions) throws InterruptedException {
|
||||
if (actions.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
actions.removeUnreachableActions();
|
||||
actions.removeZeroJumps();
|
||||
|
||||
// FastActionListIterator iterator = actions.iterator();
|
||||
// while (iterator.hasNext()) {
|
||||
// ActionItem actionItem = iterator.next();
|
||||
@@ -217,9 +217,9 @@ public class ActionDeobfuscatorSimpleFast implements SWFDecompilerListener {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean isFakeName(String name) {
|
||||
for (char ch : name.toCharArray()) {
|
||||
if (ch > 31) {
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package com.jpexs.decompiler.flash.action.fastactionlist;
|
||||
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -31,9 +33,13 @@ public class ActionItem {
|
||||
|
||||
public ActionItem next;
|
||||
|
||||
public ActionItem jumpTarget;
|
||||
private ActionItem jumpTarget;
|
||||
|
||||
public List<ActionItem> containerLastActions;
|
||||
public Set<ActionItem> jumpsHere;
|
||||
|
||||
public Set<ActionItem> lastActionOf;
|
||||
|
||||
private List<ActionItem> containerLastActions;
|
||||
|
||||
// 1 means reachable, 2 means reachable and processed
|
||||
int reachable;
|
||||
@@ -41,4 +47,100 @@ public class ActionItem {
|
||||
public ActionItem(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public boolean isJumpTarget() {
|
||||
return jumpsHere != null && !jumpsHere.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isContainerLastAction() {
|
||||
return lastActionOf != null && !lastActionOf.isEmpty();
|
||||
}
|
||||
|
||||
public void removeJumpTarget() {
|
||||
if (jumpTarget == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (jumpTarget.jumpsHere != null) {
|
||||
jumpTarget.jumpsHere.remove(this);
|
||||
}
|
||||
|
||||
jumpTarget = null;
|
||||
}
|
||||
|
||||
public ActionItem getJumpTarget() {
|
||||
return jumpTarget;
|
||||
}
|
||||
|
||||
public Action getJumpTargetAction() {
|
||||
return jumpTarget == null ? null : jumpTarget.action;
|
||||
}
|
||||
|
||||
public void setJumpTarget(ActionItem item) {
|
||||
removeJumpTarget();
|
||||
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.jumpsHere == null) {
|
||||
item.jumpsHere = new HashSet<>();
|
||||
}
|
||||
|
||||
item.jumpsHere.add(this);
|
||||
jumpTarget = item;
|
||||
}
|
||||
|
||||
public List<ActionItem> getContainerLastActions() {
|
||||
return containerLastActions;
|
||||
}
|
||||
|
||||
public void removeContainerLastActions() {
|
||||
if (containerLastActions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ActionItem lastAction : containerLastActions) {
|
||||
if (lastAction.lastActionOf != null) {
|
||||
lastAction.lastActionOf.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
containerLastActions = null;
|
||||
}
|
||||
|
||||
public void replaceContainerLastAction(ActionItem oldItem, ActionItem newItem) {
|
||||
if (containerLastActions == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < containerLastActions.size(); i++) {
|
||||
if (containerLastActions.get(i) == oldItem) {
|
||||
containerLastActions.set(i, newItem);
|
||||
if (oldItem.lastActionOf != null) {
|
||||
oldItem.lastActionOf.remove(this);
|
||||
}
|
||||
|
||||
newItem.ensureLastActionOf().add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setContainerLastActions(List<ActionItem> lastActions) {
|
||||
removeContainerLastActions();
|
||||
|
||||
for (ActionItem lastAction : lastActions) {
|
||||
lastAction.ensureLastActionOf().add(this);
|
||||
}
|
||||
|
||||
containerLastActions = lastActions;
|
||||
}
|
||||
|
||||
private Set<ActionItem> ensureLastActionOf() {
|
||||
if (lastActionOf == null) {
|
||||
lastActionOf = new HashSet<>();
|
||||
}
|
||||
|
||||
return lastActionOf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,20 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
actionItemMap.remove(item.action);
|
||||
actionItemSet.remove(item);
|
||||
|
||||
replaceJumpTargets(item, next);
|
||||
item.removeJumpTarget();
|
||||
item.removeContainerLastActions();
|
||||
|
||||
if (item.jumpsHere != null) {
|
||||
for (ActionItem item1 : item.jumpsHere) {
|
||||
item1.setJumpTarget(item.next);
|
||||
}
|
||||
}
|
||||
|
||||
if (item.lastActionOf != null) {
|
||||
for (ActionItem item1 : item.lastActionOf) {
|
||||
item1.replaceContainerLastAction(item, item.prev);
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
@@ -120,8 +133,8 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
}
|
||||
|
||||
do {
|
||||
if (item.jumpTarget == target) {
|
||||
item.jumpTarget = newTarget;
|
||||
if (item.getJumpTarget() == target) {
|
||||
item.setJumpTarget(newTarget);
|
||||
}
|
||||
|
||||
item = item.next;
|
||||
@@ -137,7 +150,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
do {
|
||||
Action action = item.action;
|
||||
if (action instanceof GraphSourceItemContainer) {
|
||||
item.containerLastActions = getContainerLastActions(actions, action, actionItemMap);
|
||||
item.setContainerLastActions(getContainerLastActions(actions, action, actionItemMap));
|
||||
}
|
||||
|
||||
item = item.next;
|
||||
@@ -213,11 +226,11 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
}
|
||||
}
|
||||
|
||||
item.jumpTarget = actionItemMap.get(targetAction);
|
||||
item.setJumpTarget(actionItemMap.get(targetAction));
|
||||
}
|
||||
if (target >= 0) {
|
||||
Action targetAction = actions.getByAddress(target);
|
||||
item.jumpTarget = actionItemMap.get(targetAction);
|
||||
item.setJumpTarget(actionItemMap.get(targetAction));
|
||||
}
|
||||
|
||||
item = item.next;
|
||||
@@ -251,7 +264,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
Action action = item.action;
|
||||
if (action instanceof ActionIf) {
|
||||
ActionIf aIf = (ActionIf) action;
|
||||
Action target = item.jumpTarget == null ? null : item.jumpTarget.action;
|
||||
Action target = item.getJumpTargetAction();
|
||||
long offset;
|
||||
if (target != null) {
|
||||
offset = target.getAddress() - action.getAddress() - action.getTotalActionLength();
|
||||
@@ -261,7 +274,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
aIf.setJumpOffset((int) offset);
|
||||
} else if (action instanceof ActionJump) {
|
||||
ActionJump aJump = (ActionJump) action;
|
||||
Action target = item.jumpTarget == null ? null : item.jumpTarget.action;
|
||||
Action target = item.getJumpTargetAction();
|
||||
long offset;
|
||||
if (target != null) {
|
||||
offset = target.getAddress() - action.getAddress() - action.getTotalActionLength();
|
||||
@@ -275,7 +288,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
} while (item != firstAction);
|
||||
}
|
||||
|
||||
private void updateActionStores(ActionList actionList) {
|
||||
private void updateActionStores() {
|
||||
ActionItem item = firstAction;
|
||||
if (item == null) {
|
||||
return;
|
||||
@@ -285,17 +298,18 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
Action action = item.action;
|
||||
if (action instanceof ActionStore) {
|
||||
ActionStore aStore = (ActionStore) action;
|
||||
Action nextActionAfterStore = item.jumpTarget == null ? null : item.jumpTarget.action;
|
||||
Action a1 = action;
|
||||
Action nextActionAfterStore = item.getJumpTargetAction();
|
||||
ActionItem item1 = item;
|
||||
List<Action> store = new ArrayList<>();
|
||||
while (true) {
|
||||
long address = a1.getAddress() + a1.getTotalActionLength();
|
||||
a1 = actionList.getByAddress(address);
|
||||
if (a1 == null || a1 == nextActionAfterStore) {
|
||||
item1 = item1.next;
|
||||
if (item1 == firstAction || item1.action == nextActionAfterStore) {
|
||||
break;
|
||||
}
|
||||
store.add(a1);
|
||||
|
||||
store.add(item1.action);
|
||||
}
|
||||
|
||||
aStore.setStore(store);
|
||||
}
|
||||
|
||||
@@ -313,7 +327,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
Action action = item.action;
|
||||
if (action instanceof GraphSourceItemContainer) {
|
||||
GraphSourceItemContainer container = (GraphSourceItemContainer) action;
|
||||
List<ActionItem> lastActions = item.containerLastActions;
|
||||
List<ActionItem> lastActions = item.getContainerLastActions();
|
||||
long startAddress = action.getAddress() + container.getHeaderSize();
|
||||
for (int j = 0; j < lastActions.size(); j++) {
|
||||
Action lastAction = lastActions.get(j).action;
|
||||
@@ -365,7 +379,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
do {
|
||||
Action action = item.action;
|
||||
if (action instanceof ActionJump) {
|
||||
if (item.jumpTarget == item.next && item.jumpTarget != firstAction) {
|
||||
if (item.getJumpTarget() == item.next && item.getJumpTarget() != firstAction) {
|
||||
item = removeItem(item);
|
||||
continue;
|
||||
}
|
||||
@@ -439,7 +453,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
}
|
||||
}
|
||||
|
||||
ActionItem target = item.jumpTarget;
|
||||
ActionItem target = item.getJumpTarget();
|
||||
if (target != null) {
|
||||
if (target.reachable == 0) {
|
||||
target.reachable = 1;
|
||||
@@ -447,7 +461,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
}
|
||||
|
||||
if (action instanceof GraphSourceItemContainer) {
|
||||
for (ActionItem lastActionItem : item.containerLastActions) {
|
||||
for (ActionItem lastActionItem : item.getContainerLastActions()) {
|
||||
if (lastActionItem != null && lastActionItem.next != null && lastActionItem.next.reachable == 0) {
|
||||
lastActionItem.next.reachable = 1;
|
||||
}
|
||||
@@ -473,7 +487,7 @@ public class FastActionList implements Collection<ActionItem> {
|
||||
ActionList result = new ActionList(resultList);
|
||||
updateActionAddressesAndLengths();
|
||||
updateJumps();
|
||||
updateActionStores(result);
|
||||
updateActionStores();
|
||||
updateContainerSizes();
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user