Skip to content

Commit

Permalink
Merge pull request #83 from EpicPlayerA10/chore/stop-execution-on-exc…
Browse files Browse the repository at this point in the history
…eptions

Stop execution on some exceptions
  • Loading branch information
narumii authored Aug 29, 2024
2 parents e8951c3 + 5fcfae0 commit a14e171
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ private Builder() {
public DeobfuscatorOptions.Builder inputJar(@Nullable Path inputJar) {
this.inputJar = inputJar;
if (this.inputJar != null) {
String fullName = inputJar.getFileName().toString();
int dot = fullName.lastIndexOf('.');
this.libraries.add(inputJar);

// Auto fill output jar
this.outputJar = inputJar.getParent()
.resolve(dot == -1 ? fullName + "-out" : fullName.substring(0, dot) + "-out" + fullName.substring(dot));
this.libraries.add(inputJar);
if (this.outputJar == null) {
String fullName = inputJar.getFileName().toString();
int dot = fullName.lastIndexOf('.');

this.outputJar = inputJar.getParent()
.resolve(dot == -1 ? fullName + "-out" : fullName.substring(0, dot) + "-out" + fullName.substring(dot));
}
}
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uwu.narumi.deobfuscator.api.helper;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
Expand All @@ -26,16 +25,15 @@ public static void loadFilesFromZip(Path path, BiConsumer<String, byte[]> consum
.forEachRemaining(
zipEntry -> {
try {
consumer.accept(
zipEntry.getName(), zipFile.getInputStream(zipEntry).readAllBytes());
consumer.accept(zipEntry.getName(), zipFile.getInputStream(zipEntry).readAllBytes());
} catch (Exception e) {
LOGGER.error("Could not load ZipEntry: {}", zipEntry.getName());
LOGGER.debug("Error", e);
}
});
} catch (Exception e) {
LOGGER.error("Could not load file: {}", path);
LOGGER.debug("Error", e);
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,9 @@ private Deobfuscator(DeobfuscatorOptions options) {
}

public void start() {
try {
loadInput();
transform(this.options.transformers());
saveOutput();
} catch (Exception e) {
LOGGER.error("Error occurred while obfuscation");
LOGGER.debug("Error", e);

if (this.options.consoleDebug()) e.printStackTrace();
}
loadInput();
transform(this.options.transformers());
saveOutput();
}

public Context getContext() {
Expand Down Expand Up @@ -175,6 +168,15 @@ private void saveClassesToDir() {
private void saveToJar() {
LOGGER.info("Saving output file: {}", this.options.outputJar());

// Create directories if not exists
if (this.options.outputJar().getParent() != null) {
try {
Files.createDirectories(this.options.outputJar().getParent());
} catch (IOException e) {
throw new RuntimeException(e);
}
}

try (ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(this.options.outputJar()))) {
zipOutputStream.setLevel(9);

Expand Down Expand Up @@ -231,10 +233,9 @@ private void saveToJar() {

context.getFiles().remove(name);
});
} catch (Exception e) {
} catch (IOException e) {
LOGGER.error("Could not save output file: {}", this.options.outputJar());
LOGGER.debug("Error", e);
if (this.options.consoleDebug()) e.printStackTrace();
throw new RuntimeException(e);
}

LOGGER.info("Saved output file: {}\n", this.options.outputJar());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ private void runTest() {
for (String sourceName : sources) {
Path compiledClassPath = COMPILED_CLASSES_PATH.resolve(this.inputType.directory()).resolve(sourceName + ".class");
if (Files.notExists(compiledClassPath)) {
throw new IllegalArgumentException("File not found: " + compiledClassPath.toAbsolutePath().normalize());
throw new IllegalArgumentException(
"Compiled class not found: '" + compiledClassPath.toAbsolutePath().normalize() + "'. You might forgot to compile the class. Use 'mvn test' to compile test classes."
);
}

// Add class
Expand Down

0 comments on commit a14e171

Please sign in to comment.