Skip to content

Commit 25ae4eb

Browse files
committed
fix: empty string passed to Base64.decode produces blank b64: comment
1 parent 57b9155 commit 25ae4eb

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/main/java/jadx/plugins/stringdecoder/B64Detector.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ public static B64Result decodeForced(String str, int maxCommentLength) {
166166
for (int i = 0; i < ALL_DECODERS.length; i++) {
167167
try {
168168
byte[] bytes = ALL_DECODERS[i].decode(str);
169+
if (bytes.length == 0) {
170+
return null;
171+
}
169172
CharsetDecoder utf8 = StandardCharsets.UTF_8.newDecoder()
170173
.onMalformedInput(CodingErrorAction.REPLACE)
171174
.onUnmappableCharacter(CodingErrorAction.REPLACE);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ public void notB64Test() throws Exception {
2929
assertThat(code).doesNotContain("b64:");
3030
}
3131

32+
@Test
33+
public void emptyStringB64ArgTest() throws Exception {
34+
// Empty string passed to Base64.decode — decodes to zero bytes, no comment should appear.
35+
// Regression: decodeForced("") previously produced "// b64: " (empty decoded value).
36+
String code = decompileSmali("b64/empty_string_b64_arg.smali");
37+
System.out.println(code);
38+
assertThat(code).doesNotContain("b64:");
39+
}
40+
3241
@Test
3342
public void looksLikeB64Test() throws Exception {
3443
// "AQIDBAUG" matches the Base64 charset but decodes to binary [1,2,3,4,5,6] — not printable UTF-8, no comment expected
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.class public Lb64/EmptyStringB64Arg;
2+
.super Ljava/lang/Object;
3+
4+
# Empty string passed to Base64.decode — real-world pattern where "" is loaded early
5+
# and later used as the input to a decode call (e.g. as a default/fallback value).
6+
.method public static process()V
7+
.registers 3
8+
9+
const-string v0, ""
10+
const/4 v1, 0x0
11+
invoke-static {v0, v1}, Landroid/util/Base64;->decode(Ljava/lang/String;I)[B
12+
move-result-object v0
13+
return-void
14+
.end method

0 commit comments

Comments
 (0)