use of net.runelite.asm.ClassFile in project runelite by runelite.
the class UnreachedCode method run.
@Override
public void run(ClassGroup group) {
group.buildClassGraph();
execution = new Execution(group);
execution.populateInitialMethods();
execution.run();
int count = 0;
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
if (m.getCode() == null)
continue;
count += removeUnused(m);
}
}
logger.info("Removed {} unused instructions", count);
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class UnusedParameters method removeParameter.
public void removeParameter(ClassGroup group, List<Method> methods, Signature signature, Execution execution, int paramIndex, int lvtIndex) {
int slots = signature.getTypeOfArg(paramIndex).getSize();
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code c = m.getCode();
if (c == null) {
continue;
}
for (Instruction i : new ArrayList<>(c.getInstructions().getInstructions())) {
if (!(i instanceof InvokeInstruction)) {
continue;
}
InvokeInstruction ii = (InvokeInstruction) i;
if (!ii.getMethods().stream().anyMatch(me -> methods.contains(me))) {
continue;
}
// remove parameter from instruction
ii.removeParameter(paramIndex);
Collection<InstructionContext> ics = invokes.get(i);
assert ics != null;
if (ics != null) {
for (InstructionContext ins : ics) {
// index from top of stack of parameter. 0 is the last parameter
int pops = signature.size() - paramIndex - 1;
StackContext sctx = ins.getPops().get(pops);
if (sctx.getPushed().getInstruction().getInstructions() == null) {
continue;
}
// remove parameter from stack
ins.removeStack(pops);
}
}
}
}
}
for (Method method : methods) {
if (method.getCode() != null) // adjust lvt indexes to get rid of idx in the method
{
for (Instruction ins : method.getCode().getInstructions().getInstructions()) {
if (ins instanceof LVTInstruction) {
LVTInstruction lins = (LVTInstruction) ins;
int i = lins.getVariableIndex();
// current unused variable detection just looks for no accesses
assert i != lvtIndex;
// reassign
if (i > lvtIndex) {
assert i > 0;
assert i >= lvtIndex + slots;
Instruction newIns = lins.setVariableIndex(i - slots);
assert ins == newIns;
}
}
}
}
}
for (Method method : methods) {
method.getDescriptor().remove(paramIndex);
}
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class PutField method getMyField.
@Override
public net.runelite.asm.Field getMyField() {
Class clazz = field.getClazz();
ClassGroup group = this.getInstructions().getCode().getMethod().getClassFile().getGroup();
ClassFile cf = group.findClass(clazz.getName());
if (cf == null) {
return null;
}
net.runelite.asm.Field f2 = cf.findFieldDeep(field.getName(), field.getType());
return f2;
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class EnumDeobfuscator method run.
@Override
public void run(ClassGroup group) {
for (ClassFile cf : group.getClasses()) {
if (!isEnum(cf) || cf.isEnum()) {
continue;
}
logger.info("Converting {} to an enum", cf.getName());
makeEnum(cf);
}
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class VirtualMethods method findBaseMethods.
// find the base methods for a method. search goes up from there to see if two
// different methods can be invoked with the same instruction.
private static List<Method> findBaseMethods(List<Method> methods, ClassFile cf, String name, Signature type) {
if (cf == null)
return methods;
Method m = cf.findMethod(name, type);
if (m != null && !m.isStatic())
methods.add(m);
List<Method> parentMethods = findBaseMethods(new ArrayList<>(), cf.getParent(), name, type);
for (ClassFile inter : cf.getInterfaces().getMyInterfaces()) parentMethods.addAll(findBaseMethods(new ArrayList<>(), inter, name, type));
// parentMethods take precedence over our methods
return parentMethods.isEmpty() ? methods : parentMethods;
}
Aggregations