1717public class Core {
1818
1919 static BufferedWriter writer = null ;
20+ static String key = null ;
2021 static String module = null ;
2122 static String variant = null ;
23+ static boolean variantLocated = false ;
2224
23- final String TAG = "obfuscator-script" ;
25+ final static String TAG = "obfuscator-script" ;
26+ final static String SEPARATOR = "-----------------------------------------------------------------------------" ;
27+ final static String VERSION = "0.4" ;
28+ final static int maxToShow = 15 ;
29+ final static String FOLDER = "string_obfuscation" ;
2430
2531 public static void main (String [] args ) {
26-
27- String xml = "" ;
28- System .out .println (":obfuscator-script: -----------------------------------------------------------------------------" );
29- System .out .println (":obfuscator-script: v0.4 --- bugs or improvements to https://github.com/efraespada/AndroidStringObfuscator/issues" );
30- System .out .println (":obfuscator-script: -----------------------------------------------------------------------------" );
3132
3233 if (args .length != 3 ) {
33- System . out . println ( ":obfuscator-script: -> params [xml_file_name] [variant] [module]" );
34+ print ( " -> params [xml_file_name] [variant] [module]" );
3435 System .exit (0 );
3536 return ;
3637 }
@@ -46,12 +47,15 @@ else if (i == 2)
4647 module = args [i ];
4748 }
4849
49- String key = getKey (variant , module );
50+ String xml = "" ;
51+ print (SEPARATOR );
52+
53+ getKey ();
5054
5155 File jarFile = new File ("." );
5256
5357 String inputFilePath = jarFile .getAbsolutePath ().replace ("." , "" ) + file ;
54- System . out . println ( ":obfuscator-script: -> looking for string file on -> " + inputFilePath );
58+ print ( " looking for string file on -> " + inputFilePath );
5559 String message = "" ;
5660 try {
5761 FileInputStream stream = new FileInputStream (new File (inputFilePath ));
@@ -65,10 +69,8 @@ else if (i == 2)
6569 }
6670
6771 xml = find (message , key );
68-
69- String folderName = key .replaceAll (":" , "" );
7072
71- File fingerFolder = new File (folderName );
73+ File fingerFolder = new File (FOLDER );
7274 if (!fingerFolder .exists ()) {
7375 try {
7476 Files .createDirectory (fingerFolder .toPath ());
@@ -79,7 +81,10 @@ else if (i == 2)
7981
8082 File xmlFile = new File (fingerFolder , "strings.xml" );
8183 writeFile (xmlFile , xml );
82- System .out .println (":obfuscator-script: -----------------------------------------------------------------------------" );
84+
85+ print (SEPARATOR );
86+ print ("v" + VERSION + " --- bugs or improvements to https://github.com/efraespada/AndroidStringObfuscator/issues" );
87+ print (SEPARATOR );
8388 }
8489
8590 public static String getString (BufferedReader br ) {
@@ -148,11 +153,11 @@ public static String find(String xmlO, String key) {
148153 }
149154
150155
151- toShow = toShow .length () > 8 ? toShow .substring (0 , 8 ) + ".." : toShow ;
152- encrypted = encrypted .length () > 8 ? encrypted .substring (0 , 8 ) + ".." : encrypted ;
153- System . out . println ( ":obfuscator-script: -> [" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : "" ));
156+ toShow = toShow .length () > maxToShow ? toShow .substring (0 , maxToShow ) + ".." : toShow ;
157+ encrypted = encrypted .length () > maxToShow ? encrypted .substring (0 , maxToShow ) + ".." : encrypted ;
158+ print ( " [" + toShow + "] - [" + encrypted + "]" + (hasExtra ? extra : "" ));
154159 } catch (Exception e ) {
155- System . out . println ("error on " + result );
160+ print ("error on " + result );
156161 e .printStackTrace ();
157162 }
158163
@@ -171,9 +176,7 @@ public static String extrac(String val) {
171176 return val ;
172177 }
173178
174- public static String getKey (String variant , String module ) {
175- String key = null ;
176-
179+ public static void getKey () {
177180 try {
178181
179182 String cmd = "" ;
@@ -189,43 +192,66 @@ public static String getKey(String variant, String module) {
189192 BufferedReader buff = new BufferedReader (isr );
190193
191194 String line ;
192- String trace = "" ;
193- ArrayList <String > traces = new ArrayList <>()
194- while ((line = buff .readLine ()) != null ) {
195- boolean result = parseTrace (module , variant , line );
195+ while ((line = buff .readLine ()) != null ) {
196+ parseTrace (line );
196197
197- traces .add (e )
198- trace += line + "\n " ;
199- System .out .println (line );
198+ if (key != null ) {
199+ print ("SHA1 fingerprint: " + key );
200+ break ;
201+ }
202+
200203 }
201204
202- System .out .println (trace );
203- } catch (IOException e2 ) {
204- e2 .printStackTrace ();
205- return null ;
205+ } catch (IOException e ) {
206+ e .printStackTrace ();
206207 }
207-
208- return key ;
209208 }
210209
211210 /**
212- * returns true if
211+ * returns true if key has been located
213212 * @param moduleName
214- * @param traces
215213 * @param variant
214+ * @param line
216215 * @return boolean
217216 */
218- public static boolean parseTrace (String moduleName , String variant , String line ) {
217+ public static void parseTrace (String line ) {
218+
219+ boolean mustPrint = false ;
219220
220- return false ;
221+ if (line .toLowerCase ().contains ("downloading" )) {
222+ mustPrint = true ;
223+ } else if (line .toLowerCase ().contains ("unzipping" )) {
224+ mustPrint = true ;
225+ } else if (line .toLowerCase ().contains ("permissions" )) {
226+ mustPrint = true ;
227+ } else if (line .toLowerCase ().contains ("sha" )) {
228+ if (variantLocated )
229+ key = line .split (" " )[1 ];
230+
231+ } else if (line .toLowerCase ().contains ("variant" )) {
232+ String locV = line .split (" " )[1 ];
233+ if (locV .equals (variant )) {
234+ print (locV + " variant" );
235+ variantLocated = true ;
236+ }
237+ }
238+
239+ if (mustPrint )
240+ print (line );
221241 }
222242
223- private static void print () {
224- String var = ":undefined" ;
243+ /**
244+ * prints messages (for gradle console)
245+ * @param message
246+ */
247+ private static void print (String message ) {
248+ String var = ":undefined:" ;
225249
226250 if (variant != null )
227- var = variant ;
251+ var = ":" + module + ":" ;
252+
253+ var += TAG ;
228254
229- var += ""
255+ System . out . println ( var + " - " + message );
230256 }
231257}
0 commit comments