写点什么

Threadtear:一款多功能 Java 代码反混淆工具套件,小米 java 社招面试

作者:Java高工P7
  • 2021 年 11 月 10 日
  • 本文字数:1720 字

    阅读完需:约 6 分钟

public class MyExecution extends Execution {


public MyExecution() {


super(ExecutionCategory.CLEANING /* category /, "My execution" / name */,


"Executes something" /* description, can use html */);


}


/**


  • This method is invoked when the user clicks on the Run button

  • @return true if success, false if failure


*/


@Override


public boolean execute(Map<String, Clazz> classes, boolean verbose) {


classes.values().stream().map(c -> c.node).forEach(c -> {


//transform the classes here using the tree-API of ASM


});


return false;


}


}


在运行时加载 ClassNodes 类,可以直接使用?


me.nov.threadtear.asm.vm.VM 类并实现?


me.nov.threadtear.asm.vm.IVMReferenceHandler 方法:


public class MyExecution extends Execution implements IVMReferenceHandler {


public MyExecution() {


super(ExecutionCategory.GENERIC, "My execution", "Loads ClassNodes at runtime");


}


@Override


public boolean execute(Map<String, Clazz> classes, boolean verbose) {


classes.values().stream().map(c -> c.node).forEach(c -> {


VM vm = VM.constructVM(this);


//transform bytecode to java.lang.Class


Class<?> loadedClass = vm.loadClass(c.name.replace('/', '.'), true);


//do stuff with your class here


loadedClass.getMethods[0].invoke(...);


return true;


});


}


/**


  • Will get invoked by VM, when VM.loadClass is called


*/


@Override


public ClassNode tryClassLoad(String name) {


//try to find the class to be loaded in open jar archive


return classes.containsKey(name) ? classes.get(name).node : null;


}


}


通过使用?


me.nov.threadtear.analysis.stack.ConstantTracker 方法,你可以分析目标代码中的方法并追踪非变量栈值:


public class MyExecution extends Execution implements IConstantReferenceHandler {


public MyExecution() {


super(ExecutionCategory.GENERIC, "My execution", "Performs stack analysis and replaces code.");


}


@Override


public boolean execute(Map<String, Clazz> classes, boolean verbose) {


classes.values().stream().map(c -> c.node).forEach(this::analyzeAndRewrite);


return true;


}


public void analyzeAndRewrite(ClassNode cn) {


cn.methods.forEach(m -> {


// this analyzer keeps known stack values, e.g. can be useful for jump prediction


Analyzer<ConstantValue> a = new Analyzer<ConstantValue>(new ConstantTracker(this, Access.isStatic(m.access), m.maxLocals, m.desc, new Object[0]));


try {


a.analyze(cn.name, m);


} catch (AnalyzerException e) {


logger.severe("Failed stack analysis in " + cn.name + "." + m.name + ":" + e.getMessage());


return;


}


Frame<ConstantValue>[] frames = a.getFrames();


InsnList rewrittenCode = new InsnList();


Map<LabelNode, LabelNode> labels = Instructions.cloneLabels(m.instructions);


// rewrite method instructions


for (int i = 0; i < m.instructions.size(); i++) {


AbstractInsnNode ain = m.instructions.get(i);


Frame<ConstantValue> frame = frames[i];


// replace / modify instructions, etc...


if (frame.getStackSize() > 0) {


ConstantValue top = frame.getStack(frame.getStackSize() - 1);


if (top.isKnown() && top.isInteger()) {


int knownTopStackValue = top.getInteger();


// use the known stack to remove jumps, simplify code, etc...


// if(...) { rewrittenCode.add(...); }


continue;


}


}


rewrittenCode.add(ain.clone(labels));


}


// update instructions and fix try catch blocks, local variables, etc...


Instructions.updateInstructions(m, labels, rewrittenCode);


});


}


/**


  • Use this method to predict stack values if fields are loaded


*/


@Override


public Object getFieldValueOrNull(BasicValue v, String owner, String name, String desc)


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


{


return null;


}


/**

用户头像

Java高工P7

关注

还未添加个人签名 2021.11.08 加入

还未添加个人简介

评论

发布
暂无评论
Threadtear:一款多功能Java代码反混淆工具套件,小米java社招面试