Some injecting classes now works

This commit is contained in:
Adam
2016-03-11 17:34:09 -05:00
parent 2cbdec1798
commit 6e79aece20
4 changed files with 55 additions and 36 deletions

View File

@@ -295,4 +295,9 @@ public class ClassFile
{ {
return (this.access_flags & ACC_FINAL) != 0; return (this.access_flags & ACC_FINAL) != 0;
} }
public void clearFinal()
{
this.access_flags &= ~ACC_FINAL;
}
} }

View File

@@ -1,5 +1,6 @@
package net.runelite.deob.injection; package net.runelite.deob.injection;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@@ -118,6 +119,17 @@ public class Inject
if (implementingClass == null) if (implementingClass == null)
continue; continue;
InjectReplace ij = new InjectReplace(cf, other);
try
{
ij.run();
}
catch (ClassNotFoundException | IOException ex)
{
ex.printStackTrace();
assert false;
}
for (Field f : cf.getFields().getFields()) for (Field f : cf.getFields().getFields())
{ {
an = f.getAttributes().getAnnotations(); an = f.getAttributes().getAnnotations();

View File

@@ -74,12 +74,13 @@ public class InjectReplace
// set parent // set parent
classToInject.setParentClass(vanilla.getPoolClass()); classToInject.setParentClass(vanilla.getPoolClass());
assert !vanilla.isFinal(); vanilla.clearFinal(); // can't be final anymore now that we inherit from it
injectConstructors(classToInject); injectConstructors(classToInject);
overideMethods(classToInject); overideMethods(classToInject);
// find all classes which inherit from 'vanilla'. replace with classToInject
replaceSuperclass(classToInject); replaceSuperclass(classToInject);
replaceNew(classToInject); replaceNew(classToInject);
@@ -228,11 +229,12 @@ public class InjectReplace
private void replaceSuperclass(ClassFile classToInject) private void replaceSuperclass(ClassFile classToInject)
{ {
// find all classes which inherit from 'vanilla'. replace with classToInject
for (ClassFile cf : vanilla.getGroup().getClasses()) for (ClassFile cf : vanilla.getGroup().getClasses())
if (cf.getParentClass().equals(vanilla.getPoolClass())) if (cf.getParentClass().equals(vanilla.getPoolClass()))
{ {
if (cf == classToInject) // of course this inherits from it.
continue;
cf.setParentClass(classToInject.getPoolClass()); cf.setParentClass(classToInject.getPoolClass());
// adjust constructors // adjust constructors
@@ -275,46 +277,47 @@ public class InjectReplace
// new vanilla -> new classToInject // new vanilla -> new classToInject
for (ClassFile cf : vanilla.getGroup().getClasses()) for (ClassFile cf : vanilla.getGroup().getClasses())
if (cf.getParentClass().equals(vanilla.getPoolClass())) for (Method m : cf.getMethods().getMethods())
{ {
for (Method m : cf.getMethods().getMethods()) Code code = m.getCode();
if (code == null)
continue;
Instructions ins = code.getInstructions();
boolean seen = false, isConstructor = m.getName().equals("<init>");
for (Instruction i : ins.getInstructions())
{ {
Code code = m.getCode(); if (i instanceof New)
Instructions ins = code.getInstructions();
boolean seen = false, isConstructor = m.getName().equals("<init>");
for (Instruction i : ins.getInstructions())
{ {
if (i instanceof New) New n = (New) i;
{ if (!n.getNewClass().equals(vanilla.getPoolClass()))
New n = (New) i; continue;
if (!n.getNewClass().equals(vanilla.getPoolClass()))
continue;
n.setNewClass(classToInject.getPoolClass()); n.setNewClass(classToInject.getPoolClass());
} }
else if (i instanceof InvokeSpecial) else if (i instanceof InvokeSpecial)
{
if (isConstructor)
{ {
if (isConstructor) if (!seen)
{ {
if (!seen) seen = true;
{ continue; // superclass invoke in constructor of class which inherits classToInject
seen = true;
continue; // superclass invoke in constructor of class which inherits classToInject
}
} }
InvokeSpecial is = (InvokeSpecial) i;
net.runelite.deob.pool.Method method = (net.runelite.deob.pool.Method) is.getMethod();
is.setMethod(
new net.runelite.deob.pool.Method(
classToInject.getPoolClass(),
method.getNameAndType()
)
);
} }
InvokeSpecial is = (InvokeSpecial) i;
net.runelite.deob.pool.Method method = (net.runelite.deob.pool.Method) is.getMethod();
is.setMethod(
new net.runelite.deob.pool.Method(
classToInject.getPoolClass(),
method.getNameAndType()
)
);
} }
} }
} }

View File

@@ -3,7 +3,6 @@ package net.runelite.deob.injection;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import net.runelite.deob.ClassGroup; import net.runelite.deob.ClassGroup;
import net.runelite.deob.runeloader.MappingImporter;
import net.runelite.deob.util.JarUtil; import net.runelite.deob.util.JarUtil;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;