Light Cleanup
This commit is contained in:
parent
f85ee82202
commit
edd27ea458
1 changed files with 13 additions and 29 deletions
|
@ -21,7 +21,7 @@ import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer
|
||||||
* @author jowasp
|
* @author jowasp
|
||||||
*/
|
*/
|
||||||
public class XposedGenerator extends Plugin {
|
public class XposedGenerator extends Plugin {
|
||||||
//PRIVATE
|
|
||||||
private static final List<String> methodsNames = new ArrayList<>();
|
private static final List<String> methodsNames = new ArrayList<>();
|
||||||
private static final List<String> cleanMethodsNames = new ArrayList<>();
|
private static final List<String> cleanMethodsNames = new ArrayList<>();
|
||||||
private static String foundPckg;
|
private static String foundPckg;
|
||||||
|
@ -40,7 +40,6 @@ public class XposedGenerator extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
String className = viewer.getName();
|
String className = viewer.getName();
|
||||||
//String containerName = viewer.getName();
|
|
||||||
ClassNode classnode = BytecodeViewer.getCurrentlyOpenedClassNode();
|
ClassNode classnode = BytecodeViewer.getCurrentlyOpenedClassNode();
|
||||||
|
|
||||||
//Call XposedGenerator class
|
//Call XposedGenerator class
|
||||||
|
@ -64,7 +63,6 @@ public class XposedGenerator extends Plugin {
|
||||||
//Set results of parsed methods into a list
|
//Set results of parsed methods into a list
|
||||||
List<String> methodsExtracted = ProcessContentExtractedClass(decomp);
|
List<String> methodsExtracted = ProcessContentExtractedClass(decomp);
|
||||||
String packgExtracted = ProcessContentExtractedPackage(decomp);
|
String packgExtracted = ProcessContentExtractedPackage(decomp);
|
||||||
System.out.println("PACKAGE NAME: " + packgExtracted);
|
|
||||||
|
|
||||||
//Get a clean list
|
//Get a clean list
|
||||||
List<String> cleanMethods;
|
List<String> cleanMethods;
|
||||||
|
@ -114,16 +112,16 @@ public class XposedGenerator extends Plugin {
|
||||||
|
|
||||||
public static void WriteXposedModule(String functionToHook, String packageName, String classToHook,
|
public static void WriteXposedModule(String functionToHook, String packageName, String classToHook,
|
||||||
String template) {
|
String template) {
|
||||||
System.out.println("TEMPLATE: " + template);
|
|
||||||
if (template != null && !template.equals("Empty")) {
|
if (template != null && !template.equals("Empty")) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//TODO: Prompt save dialog
|
//TODO: Prompt save dialog
|
||||||
File file = new File("./XposedClassTest.java");
|
File file = new File("./XposedClassTest.java");
|
||||||
|
|
||||||
// if file doesn't exist, then create it
|
// if file doesn't exist, then create it
|
||||||
if (!file.exists()) {
|
if (!file.exists())
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
}
|
|
||||||
//Extract the package name only
|
//Extract the package name only
|
||||||
String packageNameOnly = packageName.substring(8, packageName.length() - 2).trim();
|
String packageNameOnly = packageName.substring(8, packageName.length() - 2).trim();
|
||||||
String classToHookNameOnly = classToHook;
|
String classToHookNameOnly = classToHook;
|
||||||
|
@ -132,18 +130,14 @@ public class XposedGenerator extends Plugin {
|
||||||
|
|
||||||
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 onlyFunction = CleanUpFunction(functionSplitValues);
|
String onlyFunction = CleanUpFunction(functionSplitValues);
|
||||||
//String functionToHookOnly = "dummy function";
|
|
||||||
System.out.println(onlyClass);
|
|
||||||
System.out.println(packageNameOnly);
|
|
||||||
|
|
||||||
//Write Xposed Class
|
//Write Xposed Class
|
||||||
String XposedClassText =
|
String XposedClassText = "package androidpentesting.com.xposedmodule;" + "\r\n" +
|
||||||
"package androidpentesting.com.xposedmodule;" + "\r\n" +
|
|
||||||
"import de.robv.android.xposed.IXposedHookLoadPackage;" + "\r\n" +
|
"import de.robv.android.xposed.IXposedHookLoadPackage;" + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"import de.robv.android.xposed.XC_MethodHook;" + "\r\n" +
|
"import de.robv.android.xposed.XC_MethodHook;" + "\r\n" +
|
||||||
|
@ -177,7 +171,6 @@ public class XposedGenerator extends Plugin {
|
||||||
bw.write("\r\n");
|
bw.write("\r\n");
|
||||||
bw.close();
|
bw.close();
|
||||||
|
|
||||||
System.out.println("Done");
|
|
||||||
JOptionPane.showMessageDialog(null, "Xposed Module Generated");
|
JOptionPane.showMessageDialog(null, "Xposed Module Generated");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
JOptionPane.showMessageDialog(null, "Error" + e);
|
JOptionPane.showMessageDialog(null, "Error" + e);
|
||||||
|
@ -193,19 +186,16 @@ public class XposedGenerator extends Plugin {
|
||||||
try {
|
try {
|
||||||
scanner = new Scanner(contentFile);
|
scanner = new Scanner(contentFile);
|
||||||
//@TODO : Improve patterns to match other excepts 'public'
|
//@TODO : Improve patterns to match other excepts 'public'
|
||||||
String regexclass = "public";
|
|
||||||
//String regexPkg = "package";
|
|
||||||
Pattern pattern = Pattern.compile(regexclass, Pattern.CASE_INSENSITIVE);
|
|
||||||
//Pattern patternVoid = Pattern.compile(regexVoid , Pattern.CASE_INSENSITIVE);
|
|
||||||
// Pattern patternPkg = Pattern.compile(regexPkg , Pattern.CASE_INSENSITIVE);
|
|
||||||
//scanner.useDelimiter(";");
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
|
|
||||||
|
String regexclass = "public";
|
||||||
|
Pattern pattern = Pattern.compile(regexclass, Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
|
|
||||||
// process the line
|
// process the line
|
||||||
Matcher matcher = pattern.matcher(line);
|
Matcher matcher = pattern.matcher(line);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
|
|
||||||
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+")));
|
System.out.println("Function: " + CleanUpFunction(line.trim().split("\\s+")));
|
||||||
|
@ -213,9 +203,7 @@ public class XposedGenerator extends Plugin {
|
||||||
} else {
|
} else {
|
||||||
methodsNames.add("No methods found");
|
methodsNames.add("No methods found");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (methodsNames.isEmpty()) {
|
if (methodsNames.isEmpty()) {
|
||||||
|
@ -237,11 +225,9 @@ public class XposedGenerator extends Plugin {
|
||||||
if (!m.contains("extends") && (!m.contains("implements") && (m.contains("(")))) {
|
if (!m.contains("extends") && (!m.contains("implements") && (m.contains("(")))) {
|
||||||
cleanMethodsNames.add(m);
|
cleanMethodsNames.add(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cleanMethodsNames;
|
return cleanMethodsNames;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String CleanUpFunction(String[] rawFunction) {
|
private static String CleanUpFunction(String[] rawFunction) {
|
||||||
|
@ -254,7 +240,6 @@ public class XposedGenerator extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
return onlyFunc;
|
return onlyFunc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String ProcessContentExtractedPackage(String contentFile) {
|
private static String ProcessContentExtractedPackage(String contentFile) {
|
||||||
|
@ -264,20 +249,19 @@ public class XposedGenerator extends Plugin {
|
||||||
String regexPkg = "package";
|
String regexPkg = "package";
|
||||||
Pattern patternPkg = Pattern.compile(regexPkg, Pattern.CASE_INSENSITIVE);
|
Pattern patternPkg = Pattern.compile(regexPkg, Pattern.CASE_INSENSITIVE);
|
||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
|
|
||||||
// process the line
|
// process the line
|
||||||
Matcher matcher = patternPkg.matcher(line);
|
Matcher matcher = patternPkg.matcher(line);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
|
|
||||||
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()));
|
||||||
foundPckg = quote(line.trim());
|
foundPckg = quote(line.trim());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
foundPckg = "";
|
foundPckg = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
//
|
|
||||||
{
|
{
|
||||||
if (foundPckg == null || foundPckg.isEmpty())
|
if (foundPckg == null || foundPckg.isEmpty())
|
||||||
foundPckg = "No Package Found";
|
foundPckg = "No Package Found";
|
||||||
|
@ -296,8 +280,8 @@ public class XposedGenerator extends Plugin {
|
||||||
if (scanner != null)
|
if (scanner != null)
|
||||||
scanner.close();
|
scanner.close();
|
||||||
}
|
}
|
||||||
return foundPckg;
|
|
||||||
|
|
||||||
|
return foundPckg;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String quote(String aText) {
|
private static String quote(String aText) {
|
||||||
|
|
Loading…
Reference in a new issue