Updated XposedGenerator

This fixes the API breaks introduced in the recent patches, it should now function as originally intended
This commit is contained in:
Konloch 2021-07-13 05:33:34 -07:00
parent 1eda5e7f78
commit 420cd9d060

View file

@ -16,8 +16,9 @@ import javax.swing.JPanel;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.*; import the.bytecode.club.bytecodeviewer.*;
import the.bytecode.club.bytecodeviewer.util.*; import the.bytecode.club.bytecodeviewer.util.*;
import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.api.*;
import the.bytecode.club.bytecodeviewer.decompilers.FernFlowerDecompiler; import the.bytecode.club.bytecodeviewer.decompilers.impl.FernFlowerDecompiler;
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
/** /**
* @author jowasp * @author jowasp
@ -35,27 +36,29 @@ public class XposedGenerator extends Plugin
public void execute(ArrayList<ClassNode> classNodeList) public void execute(ArrayList<ClassNode> classNodeList)
{ {
//Get actual file class content //Get actual file class content
final Component tabComp = BytecodeViewer.viewer.workPane.tabs.getSelectedComponent(); ResourceViewer viewer = BytecodeViewer.getActiveResource();
if(tabComp == null) if(viewer == null)
{ {
JOptionPane.showMessageDialog(null, "Open A Class First"); BytecodeViewer.showMessage("Open A Class First");
return; return;
} }
String className = tabComp.getName(); String className = viewer.getName();
String containerName = ((FileContainer)BytecodeViewer.files.get(0)).name; String containerName = viewer.name;
ClassNode classnode = BytecodeViewer.getCurrentlyOpenedClassNode(); ClassNode classnode = BytecodeViewer.getCurrentlyOpenedClassNode();
//Call XposedGenerator class //Call XposedGenerator class
ParseChosenFileContent(className,containerName,classnode); ParseChosenFileContent(className,containerName,classnode);
} }
public static void ParseChosenFileContent(String classname, String containerName, ClassNode classNode){ public static void ParseChosenFileContent(String classname, String containerName, ClassNode classNode)
{
try{ try
{
//Parse content - Extract methods after APK /JAR has been extracted //Parse content - Extract methods after APK /JAR has been extracted
byte[] cont = BytecodeViewer.getFileContents(classname.toString()); byte[] cont = ASMUtil.nodeToBytes(classNode);
//Use one of the decompilers //Use one of the decompilers
//TODO:Allow users to select other decompilers? //TODO:Allow users to select other decompilers?
FernFlowerDecompiler decompilefern = new FernFlowerDecompiler(); FernFlowerDecompiler decompilefern = new FernFlowerDecompiler();
@ -132,15 +135,18 @@ public class XposedGenerator extends Plugin
file.createNewFile(); file.createNewFile();
} }
//Extract the package name only //Extract the package name only
String packageNameOnly = packageName.substring(8,packageName.length() - 2 ); String packageNameOnly = packageName.substring(8,packageName.length() - 2 ).trim();
String classToHookNameOnly = classToHook.substring(0, packageName.length() - 9); String classToHookNameOnly = classToHook;
if(classToHookNameOnly.endsWith(".class"))
classToHookNameOnly = classToHook.substring(0, classToHookNameOnly.length() - 6);
String[] classClean = classToHookNameOnly.split("\\/"); String[] classClean = classToHookNameOnly.split("\\/");
String[] functionSplitValues = functionToHook.split("\\s+"); String[] functionSplitValues = functionToHook.split("\\s+");
//select //select
String onlyClass = classClean[classClean.length-1]; String onlyClass = classClean[classClean.length-1];
//String onlyFunctionParateses = functionSplitValues[functionSplitValues.length-2]; //String onlyFunctionParateses = functionSplitValues[functionSplitValues.length-2];
String onlyFunction = CleanUpFuunction(functionSplitValues); String onlyFunction = CleanUpFunction(functionSplitValues);
//String functionToHookOnly = "dummy function"; //String functionToHookOnly = "dummy function";
System.out.println(onlyClass); System.out.println(onlyClass);
System.out.println(packageNameOnly); System.out.println(packageNameOnly);
@ -155,20 +161,20 @@ public class XposedGenerator extends Plugin
"import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;"+"\r\n" + "import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;"+"\r\n" +
"import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;"+"\r\n" +"\r\n" + "import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;"+"\r\n" +"\r\n" +
"public class XposedClassTest implements IXposedHookLoadPackage {"+"\r\n" +"\r\n" + "public class XposedClassTest implements IXposedHookLoadPackage {"+"\r\n" +"\r\n" +
" public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {" + "\r\n" +"\r\n" + " public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {" + "\r\n" +"\r\n" +
" String classToHook = " + "\"" + packageNameOnly + "." + onlyClass + "\" ;" + "\r\n" + " String classToHook = " + "\"" + packageNameOnly + "." + onlyClass + "\";" + "\r\n" +
" String functionToHook = "+"\""+ onlyFunction+"\";"+"\r\n" + " String functionToHook = "+"\""+ onlyFunction+"\";"+"\r\n" +
" if (lpparam.packageName.equals("+"\""+packageNameOnly+ "\""+")){"+ "\r\n" + " if (lpparam.packageName.equals("+"\""+packageNameOnly+ "\""+")){"+ "\r\n" +
" XposedBridge.log(" + "\" Loaded app: \" " + " + lpparam.packageName);"+ "\r\n" +"\r\n" + " XposedBridge.log(" + "\" Loaded app: \" " + " + lpparam.packageName);"+ "\r\n" +"\r\n" +
" findAndHookMethod("+"\""+onlyClass+"\"" + ", lpparam.classLoader, "+" \"" +onlyFunction + "\""+", int.class,"+ "\r\n" + " findAndHookMethod("+"\""+onlyClass+"\"" + ", lpparam.classLoader, "+" \"" +onlyFunction + "\""+", int.class,"+ "\r\n" +
" new XC_MethodHook() {"+ "\r\n" + " new XC_MethodHook() {"+ "\r\n" +
" @Override"+ "\r\n" + " @Override"+ "\r\n" +
" protected void beforeHookedMethod(MethodHookParam param) throws Throwable {"+ "\r\n" + " protected void beforeHookedMethod(MethodHookParam param) throws Throwable {"+ "\r\n" +
" //TO BE FILLED BY ANALYST {"+ "\r\n" + " //TO BE FILLED BY ANALYST"+ "\r\n" +
" }"+ "\r\n" + " }"+ "\r\n" +
" });"+"\r\n" + " });"+"\r\n" +
" }"+ "\r\n" + " }"+ "\r\n" +
"}"+ "\r\n" + " }"+ "\r\n" +
"}"+ "\r\n" "}"+ "\r\n"
; ;
FileWriter fw = new FileWriter(file.getAbsoluteFile()); FileWriter fw = new FileWriter(file.getAbsoluteFile());
@ -210,7 +216,8 @@ public class XposedGenerator extends Plugin
if (matcher.group() != null) if (matcher.group() != null)
{ {
System.out.println("find() found the pattern \"" + quote(line.trim())) ; System.out.println("find() found the pattern \"" + quote(line.trim()));
System.out.println("Function: " + CleanUpFunction(line.trim().split("\\s+")));
methodsNames.add(quote(line.trim())); methodsNames.add(quote(line.trim()));
} }
else else
@ -259,16 +266,15 @@ public class XposedGenerator extends Plugin
} }
private static String CleanUpFuunction(String[] rawFunction) private static String CleanUpFunction(String[] rawFunction)
{ {
String onlyFunc = "functiondummy"; String onlyFunc = "functiondummy";
for (String m:rawFunction) for (String m:rawFunction)
{ {
if(m.contains("(")) if(m.contains("("))
{ {
String[] functions = m.split("[ ,()]+"); String[] split = m.split("\\(")[0].split(" ");
onlyFunc = functions[functions.length -1]; return split[split.length-1];
return onlyFunc;
} }
else else
{ {