Search in sources :

Example 6 with ApplicationClassSource

use of org.mapleir.app.service.ApplicationClassSource in project maple-ir by LLVM-but-worse.

the class FieldRenamerPass method accept.

@Override
public int accept(AnalysisContext cxt, IPass prev, List<IPass> completed) {
    Map<FieldNode, String> remapped = new HashMap<>();
    // int totalFields = 0;
    // int i = RenamingUtil.computeMinimum(totalFields);
    ApplicationClassSource source = cxt.getApplication();
    int i = RenamingUtil.numeric("aaaaa");
    for (ClassNode cn : source.iterate()) {
        // totalFields += cn.fields.size();
        for (FieldNode fn : cn.fields) {
            remapped.put(fn, RenamingUtil.createName(i++));
        }
    }
    InvocationResolver resolver = cxt.getInvocationResolver();
    for (ClassNode cn : source.iterate()) {
        for (MethodNode m : cn.methods) {
            ControlFlowGraph cfg = cxt.getIRCache().getFor(m);
            for (BasicBlock b : cfg.vertices()) {
                for (Stmt stmt : b) {
                    if (stmt.getOpcode() == Opcode.FIELD_STORE) {
                        FieldStoreStmt fs = (FieldStoreStmt) stmt;
                        FieldNode f = resolver.findField(fs.getOwner(), fs.getName(), fs.getDesc(), fs.getInstanceExpression() == null);
                        if (f != null) {
                            if (remapped.containsKey(f)) {
                                fs.setName(remapped.get(f));
                            } else if (mustMark(source, f.owner.name)) {
                                System.err.println("  no remap for " + f + ", owner: " + f.owner.name);
                            }
                        } else {
                            if (mustMark(source, fs.getOwner())) {
                                System.err.println("  can't resolve field(set): " + fs.getOwner() + "." + fs.getName() + " " + fs.getDesc() + ", " + (fs.getInstanceExpression() == null));
                            }
                        }
                    }
                    for (Expr e : stmt.enumerateOnlyChildren()) {
                        if (e.getOpcode() == Opcode.FIELD_LOAD) {
                            FieldLoadExpr fl = (FieldLoadExpr) e;
                            FieldNode f = resolver.findField(fl.getOwner(), fl.getName(), fl.getDesc(), fl.getInstanceExpression() == null);
                            if (f != null) {
                                if (remapped.containsKey(f)) {
                                    fl.setName(remapped.get(f));
                                } else if (mustMark(source, f.owner.name)) {
                                    System.err.println("  no remap for " + f + ", owner: " + f.owner.name);
                                }
                            } else {
                                if (mustMark(source, fl.getOwner())) {
                                    System.err.println("  can't resolve field(get): " + fl.getOwner() + "." + fl.getName() + " " + fl.getDesc() + ", " + (fl.getInstanceExpression() == null));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    for (Entry<FieldNode, String> e : remapped.entrySet()) {
        e.getKey().name = e.getValue();
    }
    System.out.printf("  Renamed %d fields.%n", remapped.size());
    return remapped.size();
}
Also used : FieldStoreStmt(org.mapleir.ir.code.stmt.FieldStoreStmt) ClassNode(org.objectweb.asm.tree.ClassNode) FieldLoadExpr(org.mapleir.ir.code.expr.FieldLoadExpr) FieldNode(org.objectweb.asm.tree.FieldNode) HashMap(java.util.HashMap) BasicBlock(org.mapleir.ir.cfg.BasicBlock) FieldStoreStmt(org.mapleir.ir.code.stmt.FieldStoreStmt) Stmt(org.mapleir.ir.code.Stmt) ApplicationClassSource(org.mapleir.app.service.ApplicationClassSource) MethodNode(org.objectweb.asm.tree.MethodNode) Expr(org.mapleir.ir.code.Expr) FieldLoadExpr(org.mapleir.ir.code.expr.FieldLoadExpr) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) InvocationResolver(org.mapleir.app.service.InvocationResolver)

Aggregations

ApplicationClassSource (org.mapleir.app.service.ApplicationClassSource)6 ClassNode (org.objectweb.asm.tree.ClassNode)6 MethodNode (org.objectweb.asm.tree.MethodNode)6 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)5 InvocationResolver (org.mapleir.app.service.InvocationResolver)3 BasicBlock (org.mapleir.ir.cfg.BasicBlock)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 SimpleApplicationContext (org.mapleir.app.client.SimpleApplicationContext)2 InstalledRuntimeClassSource (org.mapleir.app.service.InstalledRuntimeClassSource)2 AnalysisContext (org.mapleir.context.AnalysisContext)2 BasicAnalysisContext (org.mapleir.context.BasicAnalysisContext)2 IRCache (org.mapleir.context.IRCache)2 IPass (org.mapleir.deob.IPass)2 PassGroup (org.mapleir.deob.PassGroup)2 IRCallTracer (org.mapleir.deob.interproc.IRCallTracer)2 ControlFlowGraphDumper (org.mapleir.ir.algorithms.ControlFlowGraphDumper)2 Expr (org.mapleir.ir.code.Expr)2 Stmt (org.mapleir.ir.code.Stmt)2 FieldStoreStmt (org.mapleir.ir.code.stmt.FieldStoreStmt)2