mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-07-01 18:28:25 +00:00
Adding loader support
This commit is contained in:
@@ -31,8 +31,11 @@ import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.LongStream;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
public class MiscUtils {
|
||||
|
||||
@@ -423,6 +426,64 @@ public class MiscUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Map<String, byte[]> loadJar(File jarFile) {
|
||||
try {
|
||||
Map<String, byte[]> classes = new HashMap<>();
|
||||
JarFile jar = new JarFile(jarFile);
|
||||
Enumeration<JarEntry> enumeration = jar.entries();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
JarEntry entry = enumeration.nextElement();
|
||||
readJar(jar, entry, classes, null);
|
||||
}
|
||||
jar.close();
|
||||
return classes;
|
||||
} catch (ZipException e) {
|
||||
return null;
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Map<String, byte[]> readJar(JarFile jar, JarEntry en, Map<String, byte[]> classes, List<String> ignored) {
|
||||
String name = en.getName();
|
||||
try (InputStream jis = jar.getInputStream(en)) {
|
||||
if (name.endsWith(".class")) {
|
||||
if (ignored != null) {
|
||||
for (String s : ignored) {
|
||||
if (name.startsWith(s)) {
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
}
|
||||
byte[] bytes = getBytes(jis);
|
||||
try {
|
||||
classes.put(name, bytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static byte[] getBytes(InputStream inputStream) {
|
||||
try {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
int nRead;
|
||||
byte[] data = new byte[16384];
|
||||
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
}
|
||||
return buffer.toByteArray();
|
||||
} catch (IOException e) {
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T parseObjectFromString(String s, Class<T> clazz) throws Exception {
|
||||
return clazz.getConstructor(new Class[] {String.class}).newInstance(s);
|
||||
}
|
||||
@@ -483,7 +544,7 @@ public class MiscUtils {
|
||||
for (final File f : pluginDir.listFiles()) {
|
||||
try {
|
||||
if (f.getName().endsWith(".jar")) {
|
||||
final PluginDescriptionFile pdf = Anticheat.INSTANCE.getPluginLoader().getPluginDescription(f);
|
||||
final PluginDescriptionFile pdf = Anticheat.INSTANCE.getPluginInstance().getPluginLoader().getPluginDescription(f);
|
||||
if (pdf.getDepend().contains("Atlas")) {
|
||||
plugins.add(f);
|
||||
}
|
||||
@@ -509,7 +570,7 @@ public class MiscUtils {
|
||||
for (final File f : pluginDir.listFiles()) {
|
||||
try {
|
||||
if (f.getName().endsWith(".jar")) {
|
||||
final PluginDescriptionFile pdf = Anticheat.INSTANCE.getPluginLoader().getPluginDescription(f);
|
||||
final PluginDescriptionFile pdf = Anticheat.INSTANCE.getPluginInstance().getPluginLoader().getPluginDescription(f);
|
||||
if (pdf.getName().equalsIgnoreCase(pl)) {
|
||||
pluginFile = f;
|
||||
msg = "(via search) ";
|
||||
|
||||
Reference in New Issue
Block a user