use of net.runelite.asm.ClassFile in project runelite by runelite.
the class FieldInliner method findFieldIns.
private void findFieldIns() {
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
if (code == null)
continue;
for (Instruction i : code.getInstructions().getInstructions()) {
if (!(i instanceof FieldInstruction))
continue;
FieldInstruction sf = (FieldInstruction) i;
if (sf.getMyField() == null)
continue;
fieldInstructions.put(sf.getMyField(), sf);
}
}
}
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class IllegalStateExceptions method findInteresting.
/* find if, new, ..., athrow, replace with goto */
private void findInteresting(ClassGroup group) {
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code c = m.getCode();
if (c == null)
continue;
Instructions instructions = c.getInstructions();
List<Instruction> ilist = instructions.getInstructions();
for (int i = 0; i < ilist.size(); ++i) {
Instruction ins = ilist.get(i);
if (// the if
!(ins instanceof ComparisonInstruction))
continue;
Instruction ins2 = ilist.get(i + 1);
if (!(ins2 instanceof New))
continue;
New new2 = (New) ins2;
net.runelite.asm.pool.Class clazz = new2.getNewClass();
if (!clazz.getName().contains("java/lang/IllegalStateException"))
continue;
interesting.add(ins);
}
}
}
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class RuntimeExceptions method run.
@Override
public void run(ClassGroup group) {
boolean foundInit = false;
int i = 0;
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code c = m.getCode();
if (c == null)
continue;
// keeps the client error handling related methods
if (cf.getName().equals("client") && m.getName().equals("init")) {
foundInit = true;
continue;
}
for (net.runelite.asm.attributes.code.Exception e : new ArrayList<>(c.getExceptions().getExceptions())) {
if (e.getCatchType() != null && e.getCatchType().getName().equals("java/lang/RuntimeException")) {
c.getExceptions().remove(e);
++i;
}
}
}
}
if (!foundInit) {
throw new IllegalStateException("client.init(...) method seems to be missing!");
}
logger.info("Remove {} exception handlers", i);
}
use of net.runelite.asm.ClassFile 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.ClassFile 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();
}
}
}
Aggregations