Skip to content

Commit

Permalink
Fixed log4j pull
Browse files Browse the repository at this point in the history
Because he loading EConsole in the game classes, needed log4j library in files of game. Added method extractLib. (Only for log4j, later make more).
  • Loading branch information
Mega4oSS committed Nov 4, 2024
1 parent bf60e9d commit cb61081
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/main/java/ru/artem/alaverdyan/PlusicInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public static void main(String[] args) {
EConsole.write(EConsole.RED, "Version: 1.0.0");
EConsole.write(EConsole.RED, "By Artem Alaverdyan aka Mega4oSS");
EConsole.write("");

File dir = new File(outputDir);
if (dir.exists()) {
deleteDir(dir);
}
EConsole.write(EConsole.WHITE_BG, EConsole.BLACK, "[PlusicInjector] Extracting: " + jarPath);
extractJar(jarPath, outputDir);
EConsole.write(EConsole.WHITE_BG, EConsole.BLACK, "[PlusicInjector] Extracted to: " + outputDir);
Expand All @@ -81,7 +84,8 @@ public static void main(String[] args) {
newClazzez.addAll(PlusicAPI.clazzez);
newClazzez.add(new RegClazz(ClickAnimationPAPIT.class, null));
newClazzez.add(new RegClazz(PlusicAPIText.class, null));

EConsole.write(EConsole.WHITE_BG, EConsole.BLACK, "[PlusicInjector] Registration log4j library...");
extractLib(outputDir);
EConsole.write(EConsole.WHITE_BG, EConsole.BLACK, "[PlusicInjector] Registration classes...");
saveClassesToFiles(newClazzez, outputDir);
EConsole.write(EConsole.WHITE_BG, EConsole.BLACK, "[PlusicInjector] Classes registered");
Expand All @@ -101,6 +105,25 @@ public static void main(String[] args) {
}
}

private static void extractLib(String outputDir) throws IOException {
// Создание директории для извлечения классов
boolean created = new File(outputDir).mkdirs();
ProcessBuilder pb = new ProcessBuilder("jar", "xf", PlusicInjector.class.getProtectionDomain().getCodeSource().getLocation().getPath().replaceAll("%20", " "), "ch", "logback.xml", "org");
pb.directory(new File(outputDir));
pb.inheritIO();
if (created || new File(outputDir).exists()) {
Process process = pb.start();
try {
process.waitFor(); // Подождите завершения процесса
} catch (InterruptedException e) {
EConsole.write(EConsole.RED, e.getLocalizedMessage());
throw new RuntimeException(e);
}
} else {
EConsole.write(EConsole.RED, "[ERROR] Output directory not created, check permissions or idk.");
}
}

// Метод для сохранения скомпилированных классов в файлы
private static void saveClassesToFiles(ArrayList<RegClazz> classList, String outputFolder) {
createFolder(outputFolder);
Expand Down Expand Up @@ -134,10 +157,6 @@ private static void createFolder(String folderName) {
}

private static void extractJar(String jarPath, String outputDir) throws IOException {
File dir = new File(outputDir);
if (dir.exists()) {
deleteDir(dir);
}
// Создание директории для извлечения классов
boolean created = new File(outputDir).mkdirs();
ProcessBuilder pb = new ProcessBuilder("jar", "xf", jarPath);
Expand Down

0 comments on commit cb61081

Please sign in to comment.