use of net.runelite.asm.Method in project runelite by runelite.
the class Renamer method renameClass.
private void renameClass(ClassGroup group, ClassFile cf, String name) {
for (ClassFile c : group.getClasses()) {
// rename on child interfaces and classes
renameClass(c, cf, name);
for (Method method : c.getMethods()) {
// rename on instructions. this includes method calls and field accesses.
if (method.getCode() != null) {
Code code = method.getCode();
// rename on instructions
for (Instruction i : code.getInstructions().getInstructions()) {
i.renameClass(cf.getName(), name);
}
// rename on exception handlers
Exceptions exceptions = code.getExceptions();
exceptions.renameClass(cf, name);
}
// rename on parameters
Signature.Builder builder = new Signature.Builder();
Signature signature = method.getDescriptor();
for (int i = 0; i < signature.size(); ++i) {
Type type = signature.getTypeOfArg(i);
if (type.getInternalName().equals(cf.getName())) {
builder.addArgument(Type.getType("L" + name + ";", type.getDimensions()));
} else {
builder.addArgument(type);
}
}
// rename return type
if (signature.getReturnValue().getInternalName().equals(cf.getName())) {
builder.setReturnType(Type.getType("L" + name + ";", signature.getReturnValue().getDimensions()));
} else {
builder.setReturnType(signature.getReturnValue());
}
Signature newSignature = builder.build();
if (!method.getDescriptor().equals(newSignature)) {
// Signature was updated. Annotate it
if (method.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE) == null) {
// Signature was not previously renamed
method.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_SIGNATURE, "signature", method.getDescriptor().toString());
}
}
method.setDescriptor(newSignature);
// rename on exceptions thrown
if (method.getExceptions() != null) {
method.getExceptions().renameClass(cf, name);
}
}
// rename on fields
for (Field field : c.getFields()) {
if (field.getType().getInternalName().equals(cf.getName())) {
if (field.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE) == null) {
// Signature was updated. Annotate it
field.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_SIGNATURE, "signature", field.getType().toString());
}
field.setType(Type.getType("L" + name + ";", field.getType().getDimensions()));
}
}
}
if (cf.getAnnotations().find(DeobAnnotations.OBFUSCATED_NAME) == null) {
cf.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_NAME, "value", cf.getName());
}
group.renameClass(cf, name);
}
use of net.runelite.asm.Method in project runelite by runelite.
the class Renamer method regeneratePool.
private void regeneratePool(ClassGroup group) {
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code c = m.getCode();
if (c == null) {
continue;
}
c.getInstructions().regeneratePool();
}
}
}
use of net.runelite.asm.Method 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.Method 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.Method in project runelite by runelite.
the class StaticStep method stepInto.
public static Frame stepInto(Frame f, InstructionContext i) {
Execution e = f.getExecution();
assert i.getInstruction() instanceof InvokeStatic;
InvokeStatic is = (InvokeStatic) i.getInstruction();
List<Method> methods = is.getMethods();
assert methods.size() == 1;
Method to = methods.get(0);
if (isLoop(f)) {
return null;
}
if (e.hasInvoked(i, to)) {
return null;
}
if (to.isNative()) {
return null;
}
Frame f2 = new Frame(e, to);
f2.initialize(i);
f2.setOrder(f.getOrder());
if (e.frames.contains(f)) {
int idx = e.frames.indexOf(f);
// old frame goes away
e.frames.remove(f);
e.frames.add(idx, f2);
} else {
e.frames.add(f);
}
// only mapping executor has other
if (f.other != null) {
assert f.other.other == f;
// even though theyre in different methods
f2.other = f.other;
f.other.other = f2;
f.other = null;
}
// where to go when we're done
f2.returnTo = new Frame(f);
// assert f.getInstructions().isEmpty() == false; // this is wrong?
// also wrong?
f2.returnTo.getInstructions().addAll(f.getInstructions());
logger.trace("Stepping into {} from {}", f2, f);
return f2;
}
Aggregations