Skip to content

Commit a864301

Browse files
committed
putting b64 decoding test resources under a b64 directory
1 parent e8fe68c commit a864301

9 files changed

Lines changed: 132 additions & 4 deletions

File tree

src/test/java/jadx/plugins/stringdecoder/JadxStringDecoderPluginTest.java

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,74 @@ class JadxStringDecoderPluginTest {
1515

1616
@Test
1717
public void integrationTest() throws Exception {
18+
String code = decompileSmali("b64/hello.smali");
19+
System.out.println(code);
20+
assertThat(code).contains("b64: Hello, World!");
21+
}
22+
23+
@Test
24+
public void notB64Test() throws Exception {
25+
// "Hello, World!" contains non-Base64 chars — no comment expected
26+
String code = decompileSmali("b64/not_b64.smali");
27+
System.out.println(code);
28+
assertThat(code).doesNotContain("b64:");
29+
}
30+
31+
@Test
32+
public void looksLikeB64Test() throws Exception {
33+
// "AQIDBAUG" matches the Base64 charset but decodes to binary [1,2,3,4,5,6] — not printable UTF-8, no comment expected
34+
String code = decompileSmali("b64/looks_like_b64.smali");
35+
System.out.println(code);
36+
assertThat(code).doesNotContain("b64:");
37+
}
38+
39+
@Test
40+
public void b64DecodableNotEncodedTest() throws Exception {
41+
// "aGVsbG8=" is not intentionally Base64-encoded but decodes to "hello" — plugin adds a comment (known false positive)
42+
String code = decompileSmali("b64/b64_decodable.smali");
43+
System.out.println(code);
44+
assertThat(code).contains("b64: hello");
45+
}
46+
47+
@Test
48+
public void fieldB64Test() throws Exception {
49+
// Base64 string assigned to a static field in <clinit>
50+
String code = decompileSmali("b64/field_b64.smali");
51+
System.out.println(code);
52+
assertThat(code).contains("b64: Hello, World!");
53+
}
54+
55+
@Test
56+
public void varAssignB64Test() throws Exception {
57+
// Base64 string used twice — may be kept as an explicit local variable in decompiled output
58+
String code = decompileSmali("b64/var_assign_b64.smali");
59+
System.out.println(code);
60+
assertThat(code).contains("b64: Hello, World!");
61+
}
62+
63+
@Test
64+
public void longDecodedStringTest() throws Exception {
65+
// Decoded string is 650 'A' chars — truncated to 100 chars + "..." in the comment
66+
String code = decompileSmali("b64/long_b64.smali");
67+
System.out.println(code);
68+
assertThat(code).contains("b64: " + "A".repeat(100) + "...");
69+
}
70+
71+
@Test
72+
public void multilineDecodedStringTest() throws Exception {
73+
// Decoded string contains newlines — they should be escaped as \n in the comment
74+
String code = decompileSmali("b64/multiline_b64.smali");
75+
System.out.println(code);
76+
assertThat(code).contains("b64: Line 1\\nLine 2\\nLine 3");
77+
}
78+
79+
private String decompileSmali(String fileName) throws Exception {
1880
JadxArgs args = new JadxArgs();
19-
args.getInputFiles().add(getSampleFile("hello.smali"));
81+
args.getInputFiles().add(getSampleFile(fileName));
2082
try (JadxDecompiler jadx = new JadxDecompiler(args)) {
2183
jadx.load();
2284
JavaClass cls = jadx.getClasses().get(0);
23-
String clsCode = cls.getCode();
24-
System.out.println(clsCode);
25-
assertThat(clsCode).contains("b64: Hello, World!");
85+
return cls.getCode();
2686
}
2787
}
2888

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.class LB64Decodable;
2+
.super Ljava/lang/Object;
3+
4+
# "aGVsbG8=" is not intentionally Base64-encoded but decodes to "hello"
5+
.method public static test()Ljava/lang/String;
6+
.registers 1
7+
const-string v0, "aGVsbG8="
8+
return-object v0
9+
.end method
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.class LFieldB64;
2+
.super Ljava/lang/Object;
3+
4+
.field public secret:Ljava/lang/String;
5+
6+
# Assigned in a regular method so the instruction stays in the method body (not extracted as a field initializer)
7+
.method public setSecret()V
8+
.registers 2
9+
const-string v0, "SGVsbG8sIFdvcmxkIQ=="
10+
iput-object v0, p0, LFieldB64;->secret:Ljava/lang/String;
11+
return-void
12+
.end method
File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.class LLongB64;
2+
.super Ljava/lang/Object;
3+
4+
# "A" * 650 base64-encoded — decoded output is 650 chars and should be truncated to 100 + "..." in the comment
5+
.method public static test()Ljava/lang/String;
6+
.registers 1
7+
const-string v0, "QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUE="
8+
return-object v0
9+
.end method
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.class LLooksLikeB64;
2+
.super Ljava/lang/Object;
3+
4+
# "AQIDBAUG" matches the Base64 charset but decodes to binary [1,2,3,4,5,6] — not printable UTF-8
5+
.method public static test()Ljava/lang/String;
6+
.registers 1
7+
const-string v0, "AQIDBAUG"
8+
return-object v0
9+
.end method
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.class LMultilineB64;
2+
.super Ljava/lang/Object;
3+
4+
# "TGluZSAxCkxpbmUgMgpMaW5lIDM=" decodes to "Line 1\nLine 2\nLine 3"
5+
.method public static test()Ljava/lang/String;
6+
.registers 1
7+
const-string v0, "TGluZSAxCkxpbmUgMgpMaW5lIDM="
8+
return-object v0
9+
.end method
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.class LNotB64;
2+
.super Ljava/lang/Object;
3+
4+
.method public static test()Ljava/lang/String;
5+
.registers 1
6+
const-string v0, "Hello, World!"
7+
return-object v0
8+
.end method
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.class LVarAssignB64;
2+
.super Ljava/lang/Object;
3+
4+
# v0 is used twice so it may be kept as an explicit variable in the decompiled output
5+
.method public static main([Ljava/lang/String;)V
6+
.registers 2
7+
const-string v0, "SGVsbG8sIFdvcmxkIQ=="
8+
sget-object p0, Ljava/lang/System;->out:Ljava/io/PrintStream;
9+
invoke-virtual {p0, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
10+
invoke-virtual {p0, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
11+
return-void
12+
.end method

0 commit comments

Comments
 (0)