11package jadx .plugins .stringdecoder ;
22
3- import jadx .api .JadxArgs ;
4- import jadx .api .JadxDecompiler ;
5- import jadx .api .JavaClass ;
63import org .junit .jupiter .api .Test ;
74
8- import java .io .File ;
9- import java .net .URISyntaxException ;
10- import java .net .URL ;
115import java .util .Map ;
126
137import static org .assertj .core .api .Assertions .assertThat ;
148
15- class JadxStringDecoderPluginTest {
9+ class B64DeobfuscatePassTest extends PluginTestBase {
1610
1711 @ Test
1812 public void integrationTest () throws Exception {
@@ -202,49 +196,6 @@ public void minDecodedLengthAllowsLongDecodeTest() throws Exception {
202196 assertThat (code ).contains ("b64: Hello, World!" );
203197 }
204198
205- @ Test
206- public void byteArrayStringTest () throws Exception {
207- // byte[] field whose bytes are ASCII "Hello, World!" — plugin should add a bytes: comment
208- String code = decompileSmali ("bytes/byte_array_string.smali" );
209- System .out .println (code );
210- assertThat (code ).contains ("bytes: \" Hello, World!\" " );
211- }
212-
213- @ Test
214- public void intArrayUtf8Test () throws Exception {
215- // int[] storing "café" as unsigned UTF-8 bytes {99, 97, 102, 195, 169}.
216- // Values 195 and 169 exceed signed byte range; byte[] would need negative literals, int[] avoids that.
217- String code = decompileSmali ("bytes/int_array_utf8.smali" );
218- System .out .println (code );
219- assertThat (code ).contains ("bytes: \" café\" " );
220- }
221-
222- @ Test
223- public void twoByteArraysInClinitTest () throws Exception {
224- // Two byte[] fields initialised sequentially in <clinit> via new-array + fill-array-data.
225- // Mirrors the real-world Base64$Encoder pattern — both fields should get bytes: comments.
226- String code = decompileSmali ("bytes/two_byte_arrays.smali" );
227- System .out .println (code );
228- assertThat (code ).contains ("bytes: \" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\" " );
229- assertThat (code ).contains ("bytes: \" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\" " );
230- }
231-
232- @ Test
233- public void byteArrayB64AlphabetTest () throws Exception {
234- // byte[] alphabet field — standard Base64 (+/)
235- String code = decompileSmali ("bytes/b64_alphabet_byte_array.smali" );
236- System .out .println (code );
237- assertThat (code ).contains ("bytes: \" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\" " );
238- }
239-
240- @ Test
241- public void intArrayB64AlphabetTest () throws Exception {
242- // int[] alphabet field — URL-safe Base64 (-_); verifies int[] is treated identically to byte[]
243- String code = decompileSmali ("bytes/b64_alphabet_byte_array.smali" );
244- System .out .println (code );
245- assertThat (code ).contains ("bytes: \" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\" " );
246- }
247-
248199 @ Test
249200 public void multilineFieldB64Test () throws Exception {
250201 // PEM-style line-wrapped Base64 string passed to Base64.decode — MIME decoder required
@@ -430,16 +381,6 @@ public void multiB64InvokeChainTest() throws Exception {
430381 assertThat (code ).contains ("b64[1]: getPackageManager" );
431382 }
432383
433- @ Test
434- public void base64EncoderInnerClassTest () throws Exception {
435- // Synthetic inner class with two byte[] fields (standard and URL-safe Base64 alphabets)
436- // initialised sequentially in <clinit>. Verifies ByteArrayStringPass recurses into inner classes.
437- String code = decompileSmali ("bytes/base64_encoder_inner_class.smali" );
438- System .out .println (code );
439- assertThat (code ).contains ("bytes: \" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\" " );
440- assertThat (code ).contains ("bytes: \" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\" " );
441- }
442-
443384 @ Test
444385 public void b64ReflectTryCatchTest () throws Exception {
445386 // Multiple Base64.decode strings inside try-catch blocks with conditional branching.
@@ -455,7 +396,6 @@ public void b64ReflectTryCatchTest() throws Exception {
455396 assertThat (code ).contains ("b64: getPackageInfo" );
456397 }
457398
458-
459399 @ Test
460400 public void b64CachedReflectionTest () throws Exception {
461401 // Three Base64.decode strings in a cached-reflection pattern with try-catch + conditionals.
@@ -479,38 +419,4 @@ public void b64InTryCatchTest() throws Exception {
479419 assertThat (code ).contains ("b64: getPackageInfo" );
480420 }
481421
482- @ Test
483- public void byteArrayStringPassDisabledTest () throws Exception {
484- // with enableByteArrayStringPass=false the bytes: comment must not appear
485- String code = decompileSmali ("bytes/byte_array_string.smali" ,
486- Map .of (opt ("enableByteArrayStringPass" ), "false" ));
487- System .out .println (code );
488- assertThat (code ).doesNotContain ("bytes:" );
489- }
490-
491- private String decompileSmali (String fileName ) throws Exception {
492- return decompileSmali (fileName , Map .of ());
493- }
494-
495- private static String opt (String key ) {
496- return JadxStringDecoderPlugin .PLUGIN_ID + "." + key ;
497- }
498-
499- private String decompileSmali (String fileName , Map <String , String > pluginOptions ) throws Exception {
500- JadxArgs args = new JadxArgs ();
501- args .isShowInconsistentCode ();
502- args .getInputFiles ().add (getSampleFile (fileName ));
503- args .setPluginOptions (pluginOptions );
504- try (JadxDecompiler jadx = new JadxDecompiler (args )) {
505- jadx .load ();
506- JavaClass cls = jadx .getClasses ().get (0 );
507- return cls .getCode ();
508- }
509- }
510-
511- private File getSampleFile (String fileName ) throws URISyntaxException {
512- URL file = getClass ().getClassLoader ().getResource ("samples/" + fileName );
513- assertThat (file ).isNotNull ();
514- return new File (file .toURI ());
515- }
516422}
0 commit comments