Some injecting classes now works
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -117,6 +118,17 @@ public class Inject
|
|||||||
java.lang.Class implementingClass = injectInterface(cf, other);
|
java.lang.Class implementingClass = injectInterface(cf, other);
|
||||||
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())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user