Skip to content

Commit 9f64166

Browse files
Col-EItzSomebody
authored andcommitted
Make ASM patching optional flag, fix ASM crash not being caught in 'loadInput' logging
1 parent 8188dba commit 9f64166

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

src/main/java/com/javadeobfuscator/deobfuscator/Deobfuscator.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,19 @@ public void loadInput(String name, byte[] data) {
280280
}
281281

282282
try {
283-
// Pass the bytecode through cafedude to filter out any ASM crashing data.
284-
// We always do this step since there are ASM crashes targeting both reading and writing steps
285-
ClassFileReader cfr = new ClassFileReader();
286-
cfr.setDropForwardVersioned(true);
287-
cfr.setDropEofAttributes(true);
288-
ClassFile cf = cfr.read(data);
289-
new IllegalStrippingTransformer(cf).transform();
290-
ClassFileWriter cfw = new ClassFileWriter();
291-
byte[] fixedData = cfw.write(cf);
283+
// Patching optional, disabling useful for ensuring that output problems related to patch process.
284+
if (configuration.isPatchAsm()) {
285+
ClassFileReader cfr = new ClassFileReader();
286+
cfr.setDropForwardVersioned(true);
287+
cfr.setDropEofAttributes(true);
288+
ClassFile cf = cfr.read(data);
289+
new IllegalStrippingTransformer(cf).transform();
290+
ClassFileWriter cfw = new ClassFileWriter();
291+
data = cfw.write(cf);
292+
}
292293
// Should be compliant now unless a new crash is discovered.
293294
// Check for updates or open an issue on the CAFED00D project if this occurs
294-
ClassReader reader = new ClassReader(fixedData);
295+
ClassReader reader = new ClassReader(data);
295296
ClassNode node = new ClassNode();
296297
reader.accept(node, ClassReader.SKIP_FRAMES);
297298
readers.put(node, reader);
@@ -319,11 +320,13 @@ public void loadInput(String name, byte[] data) {
319320
} else {
320321
classpath.put(node.name, node);
321322
}
322-
} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException | InvalidClassException x) {
323-
if (this.configuration.isParamorphismV2()) {
323+
} catch (IllegalArgumentException | IndexOutOfBoundsException | InvalidClassException x) {
324+
if (configuration.isParamorphismV2()) {
324325
invalidClasses.put(name, data);
326+
} else if (!configuration.isPatchAsm()) {
327+
logger.error("Could not parse {} (Try adding \"patchAsm: true\" to the config?)", name, x);
325328
} else {
326-
logger.error("Could not parse {} (is it a class file?)", name, x);
329+
logger.error("Could not parse {} (Is it a class file?)", name, x);
327330
}
328331
}
329332
}
@@ -382,13 +385,13 @@ public void start() throws Throwable {
382385
if (message == null) {
383386
continue;
384387
}
385-
388+
386389
logger.info("");
387390
logger.info("{}: {}", rule.getClass().getSimpleName(), rule.getDescription());
388391
logger.info("\t{}", message);
389392
logger.info("Recommend transformers:");
390393
logger.info("(Choose one transformer. If there are multiple, it's recommended to try the transformer listed first)");
391-
394+
392395
Collection<Class<? extends Transformer<?>>> recommended = rule.getRecommendTransformers();
393396
if (recommended == null) {
394397
logger.info("\tNone");
@@ -410,14 +413,14 @@ public void start() throws Throwable {
410413

411414
logger.info("Computing callers");
412415
computeCallers();
413-
416+
414417
if (configuration.isDeleteUselessClasses()) {
415418
logger.warn("Warning: You have enabled the option \"delete useless classes\".");
416419
logger.warn("This option will delete any classes whose superclasses or interfaces cannot be resolved for certain transformers.");
417420
logger.warn("This feature is only to be used when your file contains trash classes that prevent transformers from working.");
418421
logger.warn("All libraries must be added for this to work properly.");
419422
}
420-
423+
421424
if (configuration.isSmartRedo()) {
422425
logger.warn("You have enabled \"smart redo\". For some transformers, this may result in an infinite loop.");
423426
}

src/main/java/com/javadeobfuscator/deobfuscator/config/Configuration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public class Configuration {
5050
@JsonProperty
5151
private boolean detect;
5252

53+
/**
54+
* Allows patching of ASM-crashing exploits.
55+
*/
56+
@JsonProperty
57+
private boolean patchAsm;
58+
5359
/**
5460
* Must enable for paramorphism obfuscated files.
5561
*/
@@ -136,6 +142,14 @@ public void setDetect(boolean detect) {
136142
this.detect = detect;
137143
}
138144

145+
public boolean isPatchAsm() {
146+
return patchAsm;
147+
}
148+
149+
public void setPatchAsm(boolean patchAsm) {
150+
this.patchAsm = patchAsm;
151+
}
152+
139153
public boolean isSmartRedo() {
140154
return smartRedo;
141155
}

0 commit comments

Comments
 (0)