use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class ConcreteStaticInvocationPass method accept.
@Override
public PassResult accept(PassContext pcxt) {
AnalysisContext cxt = pcxt.getAnalysis();
int fixed = 0;
InvocationResolver resolver = cxt.getInvocationResolver();
for (ClassNode cn : cxt.getApplication().iterate()) {
for (MethodNode mn : cn.getMethods()) {
ControlFlowGraph cfg = cxt.getIRCache().getFor(mn);
for (BasicBlock b : cfg.vertices()) {
for (Stmt stmt : b) {
for (Expr e : stmt.enumerateOnlyChildren()) {
if (e.getOpcode() == Opcode.INVOKE) {
InvocationExpr invoke = (InvocationExpr) e;
if (invoke.getCallType() == InvocationExpr.CallType.STATIC) {
MethodNode invoked = resolver.resolveStaticCall(invoke.getOwner(), invoke.getName(), invoke.getDesc());
if (invoked != null) {
if (!invoked.getOwner().equals(invoke.getOwner())) {
invoke.setOwner(invoked.getOwner());
fixed++;
}
}
}
}
}
}
}
}
}
System.out.printf(" corrected %d dodgy static calls.%n", fixed);
return PassResult.with(pcxt, this).finished().make();
}
use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class DeadCodeEliminationPass method accept.
@Override
public PassResult accept(PassContext pcxt) {
AnalysisContext cxt = pcxt.getAnalysis();
deadBlocks = 0;
immediateJumps = 0;
deadLocals = 0;
for (ClassNode cn : cxt.getApplication().iterate()) {
for (MethodNode m : cn.getMethods()) {
ControlFlowGraph cfg = cxt.getIRCache().getFor(m);
/* dead blocks */
process(cfg);
}
}
System.out.printf(" removed %d dead blocks.%n", deadBlocks);
System.out.printf(" converted %d immediate jumps.%n", immediateJumps);
System.out.printf(" eliminated %d dead locals.%n", deadLocals);
return PassResult.with(pcxt, this).finished(deadBlocks + immediateJumps).make();
}
use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class ExceptionFixerPass method accept.
@Override
public PassResult accept(PassContext cxt) {
final AtomicInteger counter = new AtomicInteger();
for (ControlFlowGraph value : cxt.getAnalysis().getIRCache().values()) {
for (ExceptionRange<BasicBlock> range : value.getRanges()) {
if (range.getTypes().size() <= 1)
continue;
ClassNode superType = null;
for (Type type : range.getTypes()) {
ClassNode classNode = cxt.getAnalysis().getApplication().findClassNode(type.getClassName());
if (classNode == null) {
try {
classNode = ClassHelper.create(type.getClassName());
} catch (IOException e) {
continue;
}
}
if (superType == null) {
superType = classNode;
} else {
superType = cxt.getAnalysis().getApplication().getClassTree().getCommonSuperType(superType.getName(), classNode.getName());
}
}
final Set<Type> types = new HashSet<>(Collections.singleton(superType == null ? TypeUtils.OBJECT_TYPE : Type.getObjectType(superType.getName())));
range.setTypes(types);
counter.incrementAndGet();
}
}
logger.info("[*] Successfully fixed" + counter.get() + " exception ranges!");
return PassResult.with(cxt, this).finished().make();
}
use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class CallgraphPruningPass method accept.
@Override
public PassResult accept(PassContext cxt) {
int delta = 0;
Set<MethodNode> active = cxt.getAnalysis().getIRCache().getActiveMethods();
for (ClassNode cn : cxt.getAnalysis().getApplication().iterate()) {
ListIterator<MethodNode> lit = cn.getMethods().listIterator();
while (lit.hasNext()) {
MethodNode m = lit.next();
if (!active.contains(m)) {
lit.remove();
delta++;
}
}
}
System.out.println("Removed " + delta + " dead methods.");
return PassResult.with(cxt, this).finished().make();
}
use of org.mapleir.asm.ClassNode in project maple-ir by LLVM-but-worse.
the class Boot method rt.
private static LibraryClassSource rt(ApplicationClassSource app, File rtjar) throws IOException {
section("Loading " + rtjar.getName() + " from " + rtjar.getAbsolutePath());
SingleJarDownloader<ClassNode> dl = new SingleJarDownloader<>(new JarInfo(rtjar));
dl.download();
return new LibraryClassSource(app, dl.getJarContents().getClassContents());
}
Aggregations