merged honfika changes

This commit is contained in:
Jindra Petk
2013-08-31 09:36:32 +02:00
3 changed files with 6 additions and 157 deletions

View File

@@ -546,155 +546,6 @@ public class SWFInputStream extends InputStream {
return readActionList(listeners, containerSWFOffset, rri, version, rri.getPos(), rri.getPos() + maxlen, path);
}
// @SuppressWarnings("unchecked")
// private static void getConstantPool(List<DisassemblyListener> listeners, ConstantPool cpool, List<Object> localData, Stack<GraphTargetItem> stack, List<GraphTargetItem> output, ActionGraphSource code, int ip, List<ConstantPool> constantPools, List<Integer> visited, int version, int endIp, String path) {
// boolean debugMode = false;
// boolean deobfuscate = Configuration.getConfig("autoDeobfuscate", true);
// while (((endIp == -1) || (endIp > ip)) && (ip > -1) && ip < code.size()) {
// if (visited.contains(ip)) {
// break;
// }
// for (int i = 0; i < listeners.size(); i++) {
// listeners.get(i).progress("constantpool", ip + 1, code.size());
// }
// GraphSourceItem ins = code.get(ip);
// if (ins.isIgnored()) {
// if (ins.isExit()) {
// break;
// }
// ip++;
// continue;
// }
//
// if (ins instanceof GraphSourceItemContainer) {
// GraphSourceItemContainer cnt = (GraphSourceItemContainer) ins;
// String cntName = cnt.getName();
// if (ins instanceof Action) {
// List<List<GraphTargetItem>> output2s = new ArrayList<>();
// long endAddr = ((Action) ins).getAddress() + cnt.getHeaderSize();
// for (long size : cnt.getContainerSizes()) {
// if (size == 0) {
// output2s.add(new ArrayList<GraphTargetItem>());
// continue;
// }
// List<Object> localData2 = Helper.toList(new HashMap<Integer, String>(), new HashMap<String, GraphTargetItem>(), new HashMap<String, GraphTargetItem>());
// List<GraphTargetItem> output2 = new ArrayList<>();
// output2s.add(output2);
// getConstantPool(listeners, cpool, localData2, new Stack<GraphTargetItem>(), output2, code, code.adr2pos(endAddr), constantPools, visited, version, code.adr2pos(endAddr + size), path + (cntName == null ? "" : "/" + cntName));
// endAddr += size;
// }
// if (deobfuscate) {
// cnt.translateContainer(output2s, stack, output, (HashMap<Integer, String>) localData.get(0), (HashMap<String, GraphTargetItem>) localData.get(1), (HashMap<String, GraphTargetItem>) localData.get(2));
// }
// ip = code.adr2pos(endAddr);
// continue;
// }
// }
// if (ins instanceof ActionPush) {
// if (cpool != null) {
// ((ActionPush) ins).constantPool = cpool.constants;
// cpool.count++;
// }
// }
// if (ins instanceof ActionDefineFunction) {
// if (cpool != null) {
// //((ActionDefineFunction) ins).setConstantPool(cpool.constants,code.getActions());
// cpool.count++;
// }
// }
// if (ins instanceof ActionDefineFunction2) {
// if (cpool != null) {
// //((ActionDefineFunction2) ins).setConstantPool(cpool.constants,code.getActions());
// cpool.count++;
// }
// }
// if (debugMode) {
// String add = "";
// if (ins instanceof ActionIf) {
// add += " change:" + ((ActionIf) ins).getJumpOffset();
// }
// if (ins instanceof ActionJump) {
// add += " change:" + (((ActionJump) ins).getJumpOffset());
// }
// System.err.println("getConstantPool ip " + ip + ", addr " + Helper.formatAddress(((Action) ins).getAddress()) + ": " + ((Action) ins).getASMSource(new ArrayList<GraphSourceItem>(), new ArrayList<Long>(), cpool == null ? null : cpool.constants, version, false) + add + " stack:" + Helper.stackToString(stack, Helper.toList(cpool)));
// }
// if (ins instanceof ActionConstantPool) {
// constantPools.add(new ConstantPool(((ActionConstantPool) ins).constantPool));
// if (cpool == null) {
// cpool = new ConstantPool();
// }
// cpool.setNew(((ActionConstantPool) ins).constantPool);
// }
//
// //for..in return
// if (deobfuscate) {
// if (((ins instanceof ActionEquals) || (ins instanceof ActionEquals2)) && (stack.size() == 1) && (stack.peek() instanceof DirectValueActionItem)) {
// stack.push(new DirectValueActionItem(null, 0, new Null(), new ArrayList<String>()));
// }
// try {
// ins.translate(localData, stack, output, Graph.SOP_USE_STATIC/*Graph.SOP_SKIP_STATIC*/, null);
// } catch (Exception ex) {
// Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, "Error during getting constantpool", ex);
// }
// }
// if (ins.isExit()) {
// break;
// }
//
// if (ins.isBranch() || ins.isJump()) {
//
// if (deobfuscate && (ins instanceof ActionIf) && !stack.isEmpty() && (stack.peek().isCompileTime() && (!stack.peek().hasSideEffect()))) {
// boolean condition = EcmaScript.toBoolean(stack.peek().getResult());
// if (debugMode) {
// if (condition) {
// System.err.println("JUMP");
// } else {
// System.err.println("SKIP");
// }
// }
// stack.pop();
// getConstantPool(listeners, cpool, localData, stack, output, code, condition ? (code.adr2pos(((ActionIf) ins).getAddress() + ((ActionIf) ins).getBytes(code.version).length + ((ActionIf) ins).getJumpOffset())) : ip + 1, constantPools, visited, version, endIp, path);
// } else {
// if (deobfuscate && ins instanceof ActionIf) {
// stack.pop();
// }
// visited.add(ip);
// List<Integer> branches = ins.getBranches(code);
// for (int b : branches) {
// @SuppressWarnings("unchecked")
// Stack<GraphTargetItem> brStack = (Stack<GraphTargetItem>) stack.clone();
// if (b >= 0) {
// getConstantPool(listeners, cpool, prepareLocalBranch(localData), brStack, output, code, b, constantPools, visited, version, endIp, path);
// } else {
// if (debugMode) {
// System.out.println("Negative branch:" + b);
// }
// }
// }
// }
// break;
// }
// ip++;
// };
// if (ip < 0) {
// System.out.println("Visited Negative: " + ip);
// }
// for (DisassemblyListener listener : listeners) {
// listener.progress("constantpool", ip + 1, code.size());
// }
// }
//
// public static List<ConstantPool> getConstantPool(List<DisassemblyListener> listeners, ActionGraphSource code, int addr, int version, String path) {
// List<ConstantPool> ret = new ArrayList<>();
// List<Object> localData = Helper.toList(new HashMap<Integer, String>(), new HashMap<String, GraphTargetItem>(), new HashMap<String, GraphTargetItem>());
// try {
// getConstantPool(listeners, null, localData, new Stack<GraphTargetItem>(), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), ret, new ArrayList<Integer>(), version, -1, path);
// } catch (Exception ex) {
// log.log(Level.SEVERE, "Error during getting constantpool", ex);
// }
// return ret;
// }
private static List<Object> prepareLocalBranch(List<Object> localData) {
@SuppressWarnings("unchecked")
HashMap<Integer, String> regNames = (HashMap<Integer, String>) localData.get(0);