EZ Injection Cleanup

This commit is contained in:
Konloch 2021-07-06 13:23:50 -07:00
parent 0998c54e54
commit be2896ee3e
1 changed files with 97 additions and 89 deletions

View File

@ -69,21 +69,22 @@ public class EZInjection extends Plugin {
String invokeMethodInformation, boolean sandboxRuntime, String invokeMethodInformation, boolean sandboxRuntime,
boolean sandboxSystem, String debugClasses, String proxy, boolean sandboxSystem, String debugClasses, String proxy,
boolean useProxy, boolean launchKit, boolean console, boolean useProxy, boolean launchKit, boolean console,
boolean printCmdL) { boolean printCmdL)
the.bytecode.club.bytecodeviewer.api.BytecodeViewer {
.createNewClassNodeLoaderInstance(); the.bytecode.club.bytecodeviewer.api.BytecodeViewer.createNewClassNodeLoaderInstance();
this.accessModifiers = accessModifiers; this.accessModifiers = accessModifiers;
this.injectHooks = injectHooks; this.injectHooks = injectHooks;
EZInjection.debugHooks = debugHooks; EZInjection.debugHooks = debugHooks;
this.invokeMethod = invokeMethod; this.invokeMethod = invokeMethod;
this.invokeMethodInformation = invokeMethodInformation this.invokeMethodInformation = invokeMethodInformation + "([Ljava/lang/String;)V";
+ "([Ljava/lang/String;)V";
EZInjection.sandboxRuntime = sandboxRuntime; EZInjection.sandboxRuntime = sandboxRuntime;
EZInjection.sandboxSystem = sandboxSystem; EZInjection.sandboxSystem = sandboxSystem;
if (debugClasses.equals("*")) if (debugClasses.equals("*"))
EZInjection.all = true; EZInjection.all = true;
else else
EZInjection.debugClasses = debugClasses.split(","); EZInjection.debugClasses = debugClasses.split(",");
this.proxy = proxy; this.proxy = proxy;
this.useProxy = useProxy; this.useProxy = useProxy;
this.launchKit = launchKit; this.launchKit = launchKit;
@ -91,7 +92,8 @@ public class EZInjection extends Plugin {
EZInjection.printCmdL = printCmdL; EZInjection.printCmdL = printCmdL;
} }
public static void setProxy(String host, String port) { public static void setProxy(String host, String port)
{
System.setProperty("java.net.useSystemProxies", "true"); System.setProperty("java.net.useSystemProxies", "true");
System.setProperty("socksProxyHost", host); System.setProperty("socksProxyHost", host);
System.setProperty("socksProxyPort", port); System.setProperty("socksProxyPort", port);
@ -99,21 +101,25 @@ public class EZInjection extends Plugin {
private static String lastMessage = ""; private static String lastMessage = "";
public static void hook(String info) { public static void hook(String info)
{
for (BytecodeHook hook : hookArray) for (BytecodeHook hook : hookArray)
hook.callHook(info); hook.callHook(info);
if (debugHooks) { if (debugHooks)
{
if (lastMessage.equals(info)) // just a small anti spam measurement if (lastMessage.equals(info)) // just a small anti spam measurement
return; return;
lastMessage = info; lastMessage = info;
boolean print = all; boolean print = all;
if (!all && debugClasses.length >= 1) { if (!all && debugClasses.length >= 1)
for (String s : debugClasses) { {
if (info.split("\\.")[0].equals(s.replaceAll("\\.", "/"))) { for (String s : debugClasses)
{
if (info.split("\\.")[0].equals(s.replaceAll("\\.", "/")))
{
print = true; print = true;
break; break;
} }
@ -125,7 +131,8 @@ public class EZInjection extends Plugin {
} }
} }
public static void print(String message) { public static void print(String message)
{
if (printCmdL) if (printCmdL)
System.out.println(message); System.out.println(message);
@ -134,7 +141,8 @@ public class EZInjection extends Plugin {
} }
@Override @Override
public void execute(ArrayList<ClassNode> classNodeList) { public void execute(ArrayList<ClassNode> classNodeList)
{
BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.viewer.updateBusyStatus(true);
gui.setText(""); gui.setText("");
@ -143,111 +151,103 @@ public class EZInjection extends Plugin {
if (accessModifiers) if (accessModifiers)
print("Setting all of the access modifiers to public/public static."); print("Setting all of the access modifiers to public/public static.");
if (injectHooks) if (injectHooks)
print("Injecting hook..."); print("Injecting hook...");
if (debugHooks) if (debugHooks)
print("Hooks are debugging."); print("Hooks are debugging.");
else if (injectHooks) else if (injectHooks)
print("Hooks are not debugging."); print("Hooks are not debugging.");
else else
print("Hooks are disabled completely."); print("Hooks are disabled completely.");
if (useProxy) if (useProxy)
print("Forcing proxy as '" + proxy + "'."); print("Forcing proxy as '" + proxy + "'.");
if (launchKit) if (launchKit)
print("Launching the Graphicial Reflection Kit upon a succcessful invoke of the main method."); print("Launching the Graphicial Reflection Kit upon a succcessful invoke of the main method.");
for (ClassNode classNode : classNodeList) { //force everything to be public
for (Object o : classNode.fields.toArray()) { for (ClassNode classNode : classNodeList)
{
for (Object o : classNode.fields.toArray())
{
FieldNode f = (FieldNode) o; FieldNode f = (FieldNode) o;
if (accessModifiers) { if (accessModifiers)
{
if (f.access == Opcodes.ACC_PRIVATE if (f.access == Opcodes.ACC_PRIVATE
|| f.access == Opcodes.ACC_PROTECTED) || f.access == Opcodes.ACC_PROTECTED)
f.access = Opcodes.ACC_PUBLIC; f.access = Opcodes.ACC_PUBLIC;
if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC
|| f.access == Opcodes.ACC_PROTECTED || f.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC)
+ Opcodes.ACC_STATIC)
f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC; f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC;
if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL
|| f.access == Opcodes.ACC_PROTECTED || f.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL)
+ Opcodes.ACC_FINAL)
f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL; f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL;
if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL if (f.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC
+ Opcodes.ACC_STATIC || f.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC)
|| f.access == Opcodes.ACC_PROTECTED f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC;
+ Opcodes.ACC_FINAL + Opcodes.ACC_STATIC)
f.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL
+ Opcodes.ACC_STATIC;
} }
} }
for (Object o : classNode.methods.toArray()) {
for (Object o : classNode.methods.toArray())
{
MethodNode m = (MethodNode) o; MethodNode m = (MethodNode) o;
if (accessModifiers)
if (accessModifiers) { {
if (m.access == Opcodes.ACC_PRIVATE if (m.access == Opcodes.ACC_PRIVATE
|| m.access == Opcodes.ACC_PROTECTED) || m.access == Opcodes.ACC_PROTECTED)
m.access = Opcodes.ACC_PUBLIC; m.access = Opcodes.ACC_PUBLIC;
if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC
|| m.access == Opcodes.ACC_PROTECTED || m.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC)
+ Opcodes.ACC_STATIC)
m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC; m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC;
if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL
|| m.access == Opcodes.ACC_PROTECTED || m.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL)
+ Opcodes.ACC_FINAL)
m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL; m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL;
if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL if (m.access == Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC
+ Opcodes.ACC_STATIC || m.access == Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC)
|| m.access == Opcodes.ACC_PROTECTED m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC;
+ Opcodes.ACC_FINAL + Opcodes.ACC_STATIC)
m.access = Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL
+ Opcodes.ACC_STATIC;
} }
if (injectHooks if (injectHooks
&& m.access != Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT
+ Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PRIVATE + Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_PROTECTED + Opcodes.ACC_ABSTRACT
+ Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_PROTECTED
+ Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL && m.access != Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT
+ Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL && m.access != Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT
+ Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC + Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_PROTECTED && m.access != Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC + Opcodes.ACC_ABSTRACT
+ Opcodes.ACC_FINAL + Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_PROTECTED + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC + Opcodes.ACC_ABSTRACT)
&& m.access != Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL {
+ Opcodes.ACC_STATIC + Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL
+ Opcodes.ACC_STATIC + Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_PROTECTED
+ Opcodes.ACC_FINAL + Opcodes.ACC_STATIC
+ Opcodes.ACC_ABSTRACT) {
boolean inject = true; boolean inject = true;
if (m.instructions.size() >= 2 if (m.instructions.size() >= 2
&& m.instructions.get(1) instanceof MethodInsnNode) { && m.instructions.get(1) instanceof MethodInsnNode)
MethodInsnNode mn = (MethodInsnNode) m.instructions {
.get(1); MethodInsnNode mn = (MethodInsnNode) m.instructions.get(1);
if (mn.owner
.equals(EZInjection.class.getName().replace(".", "/")))//"the/bytecode/club // already been injected
// /bytecodeviewer/plugins/EZInjection")) // already been injected if (mn.owner.equals(EZInjection.class.getName().replace(".", "/")))
inject = false; inject = false;
} }
if (inject) {
if (inject)
{
// make this function grab parameters eventually // make this function grab parameters eventually
m.instructions m.instructions
.insert(new MethodInsnNode( .insert(new MethodInsnNode(
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
EZInjection.class.getName().replace(".", "/"),//"the/bytecode/club EZInjection.class.getName().replace(".", "/"),
// /bytecodeviewer/plugins/EZInjection",
"hook", "(Ljava/lang/String;)V")); "hook", "(Ljava/lang/String;)V"));
m.instructions.insert(new LdcInsnNode(classNode.name m.instructions.insert(new LdcInsnNode(classNode.name
+ "." + m.name + m.desc)); + "." + m.name + m.desc));
@ -256,8 +256,10 @@ public class EZInjection extends Plugin {
} }
} }
if (useProxy) { if (useProxy)
try { {
try
{
String[] split = proxy.split(":"); String[] split = proxy.split(":");
setProxy(split[0], split[1]); setProxy(split[0], split[1]);
} catch (Exception e) { } catch (Exception e) {
@ -269,32 +271,38 @@ public class EZInjection extends Plugin {
setFinished(); setFinished();
if (invokeMethod) { if (invokeMethod)
{
// load all the classnodes into the classloader
for (ClassNode cn : BytecodeViewer.getLoadedClasses()) for (ClassNode cn : BytecodeViewer.getLoadedClasses())
// load all the classnodes into the classloader the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().addClass(cn);
the.bytecode.club.bytecodeviewer.api.BytecodeViewer
.getClassNodeLoader().addClass(cn);
print("Invoking " + invokeMethodInformation + ":" + nl + nl); print("Invoking " + invokeMethodInformation + ":" + nl + nl);
for (ClassNode classNode : classNodeList) { for (ClassNode classNode : classNodeList)
for (Object o : classNode.methods.toArray()) { {
for (Object o : classNode.methods.toArray())
{
MethodNode m = (MethodNode) o; MethodNode m = (MethodNode) o;
String methodInformation = classNode.name + "." + m.name String methodInformation = classNode.name + "." + m.name + m.desc;
+ m.desc;
if (invokeMethodInformation.equals(methodInformation)) { if (invokeMethodInformation.equals(methodInformation))
{
for (Method m2 : the.bytecode.club.bytecodeviewer.api.BytecodeViewer for (Method m2 : the.bytecode.club.bytecodeviewer.api.BytecodeViewer
.getClassNodeLoader().nodeToClass(classNode) .getClassNodeLoader().nodeToClass(classNode)
.getMethods()) { .getMethods())
if (m2.getName().equals(m.name)) { {
try { if (m2.getName().equals(m.name))
m2.invoke(classNode.getClass() {
.newInstance(), try
(Object[]) new String[1]); {
m2.invoke(classNode.getClass().newInstance(), (Object[]) new String[1]);
if (launchKit) if (launchKit)
new GraphicalReflectionKit() new GraphicalReflectionKit().setVisible(true);
.setVisible(true); }
} catch (Exception e) { catch (Exception e)
{
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw)); e.printStackTrace(new PrintWriter(sw));
e.printStackTrace(); e.printStackTrace();