@@ -46,11 +46,17 @@ public void execute(List<ClassNode> classNodeList)
4646 String className = viewer .getName ();
4747 ClassNode classnode = BytecodeViewer .getCurrentlyOpenedClassNode ();
4848
49+ if (classnode == null )
50+ {
51+ BytecodeViewer .showMessage ("Open A Classfile First" );
52+ return ;
53+ }
54+
4955 //Call XposedGenerator class
50- ParseChosenFileContent (className , classnode );
56+ parseChosenFileContent (className , classnode );
5157 }
5258
53- public static void ParseChosenFileContent (String classname , ClassNode classNode )
59+ public static void parseChosenFileContent (String classname , ClassNode classNode )
5460 {
5561 try
5662 {
@@ -64,7 +70,9 @@ public static void ParseChosenFileContent(String classname, ClassNode classNode)
6470 //Decompile using Fern
6571 String decomp = decompilefern .decompileClassNode (classNode , cont );
6672 String [] xposedTemplateTypes = {"Empty" , "Parameters" , "Helper" };
67- @ SuppressWarnings ({"unchecked" , "rawtypes" }) JComboBox xposedTemplateList = new JComboBox (xposedTemplateTypes );
73+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
74+ JComboBox xposedTemplateList = new JComboBox (xposedTemplateTypes );
75+
6876 //Set results of parsed methods into a list
6977 List <String > methodsExtracted = ProcessContentExtractedClass (decomp );
7078 String packgExtracted = ProcessContentExtractedPackage (decomp );
@@ -86,6 +94,7 @@ public static void ParseChosenFileContent(String classname, ClassNode classNode)
8694
8795 //output methods to pane box
8896 int result = JOptionPane .showConfirmDialog (null , myPanel , "Choose Template and Method for Xposed Module" , JOptionPane .OK_CANCEL_OPTION );
97+ myPanel .remove ();
8998
9099 if (result == JOptionPane .OK_OPTION )
91100 {
@@ -129,13 +138,6 @@ public static void WriteXposedModule(String functionToHook, String packageName,
129138 {
130139 try
131140 {
132- //TODO: Prompt save dialog
133- File file = new File ("./XposedClassTest.java" );
134-
135- // if file doesn't exist, then create it
136- if (!file .exists ())
137- file .createNewFile ();
138-
139141 //Extract the package name only
140142 String packageNameOnly = packageName .substring (8 , packageName .length () - 2 ).trim ();
141143 String classToHookNameOnly = classToHook ;
@@ -151,18 +153,35 @@ public static void WriteXposedModule(String functionToHook, String packageName,
151153 String onlyFunction = CleanUpFunction (functionSplitValues );
152154
153155 //Write Xposed Class
154- String XposedClassText = "package androidpentesting.com.xposedmodule;" + "\r \n " + "import de.robv.android.xposed.IXposedHookLoadPackage;" + "\r \n " + "\r \n " + "import de.robv.android.xposed.XC_MethodHook;" + "\r \n " + "import de.robv.android.xposed.XposedBridge;" + "\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 " + "public class XposedClassTest implements IXposedHookLoadPackage {" + "\r \n " + "\r \n " + " public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {" + "\r \n " + "\r \n " + " String classToHook = " + "\" " + packageNameOnly + "." + onlyClass + "\" ;" + "\r \n " + " String functionToHook = " + "\" " + onlyFunction + "\" ;" + "\r \n " + " if (lpparam.packageName.equals(" + "\" " + packageNameOnly + "\" " + ")){" + "\r " + "\n " + " XposedBridge.log(" + "\" Loaded app: \" " + " + lpparam.packageName);" + "\r \n " + "\r \n " + " findAndHookMethod(" + "\" " + onlyClass + "\" " + ", lpparam.classLoader, " + " \" " + onlyFunction + "\" " + ", int.class," + "\r \n " + " new XC_MethodHook() {" + "\r \n " + " @Override" + "\r \n " + " protected void beforeHookedMethod(MethodHookParam param) throws " + "Throwable {" + "\r \n " + " //TO BE FILLED BY ANALYST" + "\r \n " + " }" + "\r \n " + " });" + "\r \n " + " }" + "\r \n " + " }" + "\r \n " + "}" + "\r \n " ;
155- FileWriter fw = new FileWriter (file .getAbsoluteFile ());
156- BufferedWriter bw = new BufferedWriter (fw );
157- bw .write (XposedClassText );
158- bw .write ("\r \n " );
159- bw .close ();
160-
161- JOptionPane .showMessageDialog (null , "Xposed Module Generated" );
156+ String XposedClassText = "package androidpentesting.com.xposedmodule;" + "\r \n "
157+ + "import de.robv.android.xposed.IXposedHookLoadPackage;" + "\r \n " + "\r \n "
158+ + "import de.robv.android.xposed.XC_MethodHook;" + "\r \n "
159+ + "import de.robv.android.xposed.XposedBridge;" + "\r \n "
160+ + "import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;" + "\r \n "
161+ + "import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;" + "\r \n " + "\r \n "
162+ + "public class XposedClassTest implements IXposedHookLoadPackage {" + "\r \n " + "\r \n "
163+ + " public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {" + "\r \n " + "\r \n "
164+ + " String classToHook = " + "\" " + packageNameOnly + "." + onlyClass + "\" ;" + "\r \n "
165+ + " String functionToHook = " + "\" " + onlyFunction + "\" ;" + "\r \n " + "\r \n "
166+ + " if (lpparam.packageName.equals(" + "\" " + packageNameOnly + "\" " + ")){" + "\r \n "
167+ + " XposedBridge.log(" + "\" Loaded app: \" " + " + lpparam.packageName);" + "\r \n " + "\r \n "
168+ + " findAndHookMethod(" + "\" " + onlyClass + "\" " + ", lpparam.classLoader, " + " \" " + onlyFunction + "\" " + ", int.class," + "\r \n "
169+ + " new XC_MethodHook() {" + "\r \n "
170+ + " @Override" + "\r \n "
171+ + " protected void beforeHookedMethod(MethodHookParam param) throws Throwable {" + "\r \n "
172+ + " //TO BE FILLED BY ANALYST" + "\r \n "
173+ + " }" + "\r \n "
174+ + " });" + "\r \n "
175+ + " }" + "\r \n "
176+ + " }" + "\r \n "
177+ + "}" + "\r \n " ;
178+
179+ PluginConsole gui = new PluginConsole ("Xposed Code Generation" );
180+ gui .appendText (XposedClassText );
181+ gui .setVisible (true );
162182 }
163- catch (IOException e )
183+ catch (Exception e )
164184 {
165- JOptionPane .showMessageDialog (null , "Error" + e );
166185 e .printStackTrace ();
167186 }
168187 }
0 commit comments