Skip to content

Commit 45d4da3

Browse files
committed
simplify pass
1 parent 2fd1cfb commit 45d4da3

2 files changed

Lines changed: 25 additions & 27 deletions

File tree

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,30 @@ public void visit(MethodNode mth) {
9393
FilledNewArrayNode arrayParent = findFilledNewArrayParent(csn);
9494
if (arrayParent != null) {
9595
int idx = argIndexOf(arrayParent, csn.getResult().getSVar());
96-
if (idx >= 0) {
97-
// Determine the best available decoded value for this slot
98-
String candidate = decoded != null ? decoded
99-
: B64Detector.decodeIfValid(str, options.getMaxCommentLength());
100-
if (candidate != null) {
101-
if (fieldConstants == null) {
102-
fieldConstants = collectConstantValueFieldStrings(mth.getParentClass());
96+
if (idx < 0) {
97+
continue;
98+
}
99+
// Determine the best available decoded value for this slot
100+
String candidate = decoded != null ? decoded
101+
: B64Detector.decodeIfValid(str, options.getMaxCommentLength());
102+
if (candidate != null) {
103+
if (fieldConstants == null) {
104+
fieldConstants = collectConstantValueFieldStrings(mth.getParentClass());
105+
}
106+
if (!fieldConstants.contains(str)) {
107+
if (arrayCandidates == null) {
108+
arrayCandidates = new LinkedHashMap<>();
103109
}
104-
if (!fieldConstants.contains(str)) {
105-
if (arrayCandidates == null) {
106-
arrayCandidates = new LinkedHashMap<>();
107-
}
108-
arrayCandidates.computeIfAbsent(arrayParent, k -> new TreeMap<>()).put(idx, candidate);
109-
if (decoded != null) {
110-
if (arrayAnchors == null) {
111-
arrayAnchors = new LinkedHashSet<>();
112-
}
113-
arrayAnchors.add(arrayParent);
110+
arrayCandidates.computeIfAbsent(arrayParent, k -> new TreeMap<>()).put(idx, candidate);
111+
if (decoded != null) {
112+
if (arrayAnchors == null) {
113+
arrayAnchors = new LinkedHashSet<>();
114114
}
115+
arrayAnchors.add(arrayParent);
115116
}
116117
}
117-
continue;
118118
}
119+
continue;
119120
}
120121

121122
if (decoded == null) {
@@ -172,12 +173,6 @@ private static int argIndexOf(InsnNode insn, SSAVar ssaVar) {
172173
return -1;
173174
}
174175

175-
/**
176-
* Builds a multi-line comment text for all decoded strings in a FilledNewArrayNode.
177-
* Each entry is formatted as "b64[N]: decoded" on its own line, sorted by index.
178-
* The renderer (appendMultiLineString) splits on \n and starts each continuation
179-
* line with "// ", producing one "// b64[N]: ..." line per decoded string.
180-
*/
181176
private static String buildArrayComment(TreeMap<Integer, String> decodings) {
182177
StringBuilder sb = new StringBuilder();
183178
for (Map.Entry<Integer, String> e : decodings.entrySet()) {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ public final class B64Detector {
1313
// Allow embedded \n/\r (PEM/MIME line-wrapped Base64); = padding and trailing newline are optional
1414
private static final Pattern BASE64_STANDARD = Pattern.compile("^[A-Za-z0-9+/\\n\\r]*=*[\\n\\r]*$");
1515
private static final Pattern BASE64_URL_SAFE = Pattern.compile("^[A-Za-z0-9_\\-\\n\\r]*=*[\\n\\r]*$");
16-
private B64Detector() {
16+
private static final Base64.Decoder[] STANDARD_AND_URL = { Base64.getDecoder(), Base64.getUrlDecoder() };
17+
private static final Base64.Decoder[] ALL_DECODERS = { Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder() };
18+
19+
private B64Detector() {
1720
}
1821

1922
/**
@@ -117,7 +120,7 @@ public static String decodeIfValid(String str, int maxCommentLength) {
117120
if (!BASE64_STANDARD.matcher(str).matches() && !BASE64_URL_SAFE.matcher(str).matches()) {
118121
return null;
119122
}
120-
for (Base64.Decoder decoder : new Base64.Decoder[] { Base64.getDecoder(), Base64.getUrlDecoder() }) {
123+
for (Base64.Decoder decoder : STANDARD_AND_URL) {
121124
try {
122125
byte[] bytes = decoder.decode(str);
123126
CharsetDecoder utf8 = StandardCharsets.UTF_8.newDecoder()
@@ -138,7 +141,7 @@ public static String decodeIfValid(String str, int maxCommentLength) {
138141
* Invalid UTF-8 bytes are replaced rather than causing a rejection.
139142
*/
140143
public static String decodeForced(String str, int maxCommentLength) {
141-
for (Base64.Decoder decoder : new Base64.Decoder[]{Base64.getDecoder(), Base64.getUrlDecoder(), Base64.getMimeDecoder()}) {
144+
for (Base64.Decoder decoder : ALL_DECODERS) {
142145
try {
143146
byte[] bytes = decoder.decode(str);
144147
CharsetDecoder utf8 = StandardCharsets.UTF_8.newDecoder()

0 commit comments

Comments
 (0)