@@ -37,31 +37,40 @@ public class APKTool
3737
3838 public static synchronized void decodeResources (File input , ResourceContainer container )
3939 {
40- try
41- {
42- File dir = new File (TEMP_DIRECTORY + FS + MiscUtils .randomString (32 ) + FS + DECODED_RESOURCES );
43- dir .mkdirs ();
40+ File dir = new File (TEMP_DIRECTORY + FS + MiscUtils .randomString (32 ) + FS + DECODED_RESOURCES );
41+ File tempAPKPath = new File (TEMP_DIRECTORY + FS + MiscUtils .randomString (12 ));
4442
45- File tempAPKPath = new File (TEMP_DIRECTORY + FS + MiscUtils .randomString (12 ));
46- tempAPKPath .mkdirs ();
43+ // Create temp directories as needed
44+ dir .mkdirs ();
45+ tempAPKPath .mkdirs ();
4746
48- brut .apktool .Main .main (new String [] {
49- "r" ,
47+ try
48+ {
49+ brut .apktool .Main .main (new String []
50+ {
51+ "decode" , // MODE
52+ input .getAbsolutePath (), // INPUT
53+ // OPTIONS
5054 "--frame-path" , tempAPKPath .getAbsolutePath (),
51- "d" , input .getAbsolutePath (),
5255 "-o" , dir .getAbsolutePath (),
53- "-f" ,
54- "-jobs" ,
55- String .valueOf (Runtime .getRuntime ().availableProcessors ())
56+ "-f" , // Force Delete
57+ "-jobs" , String .valueOf (Runtime .getRuntime ().availableProcessors ()) // Use Maximum Threads
5658 });
57-
58- container .APKToolContents = dir ;
59- tempAPKPath .delete ();
59+ }
60+ catch (SecurityException e )
61+ {
62+ // Generally we can safely ignore this, as it's expected behavior due to the sandboxing (Assuming it's enabled)
63+ e .printStackTrace ();
6064 }
6165 catch (Exception e )
6266 {
6367 BytecodeViewer .handleException (e );
6468 }
69+ finally
70+ {
71+ container .APKToolContents = dir ;
72+ tempAPKPath .delete ();
73+ }
6574 }
6675
6776 public static synchronized void buildAPK (File input , File output , ResourceContainer container )
@@ -80,7 +89,11 @@ public static synchronized void buildAPK(File input, File output, ResourceContai
8089
8190 //save entire jar as smali files
8291 System .out .println ("Building!" );
83- brut .apktool .Main .main (new String []{"b" , container .APKToolContents .getAbsolutePath (),
92+ brut .apktool .Main .main (new String []{
93+ "build" , // MODE
94+ container .APKToolContents .getAbsolutePath (), // INPUT
95+
96+ // OPTIONS
8497 "--frame-path" , tempAPKPath .getAbsolutePath (),
8598 "-o" , output .getAbsolutePath ()});
8699
0 commit comments