mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
Init Commit
This commit is contained in:
commit
d492ba7224
39 files changed
+27426
No files matched your search
@@ -0,0 +1,15 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id "com.gradleup.shadow" version "8.3.9"
|
||||
}
|
||||
|
||||
group = 'cn.xiaozhou233.orangex.injector'
|
||||
version = 'unspecified'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package cn.xiaozhou233.juiceagent.injector;
|
||||
|
||||
public class InjectorNative {
|
||||
/*
|
||||
* @param pid target process id
|
||||
*/
|
||||
public native boolean inject(int pid, String path);
|
||||
|
||||
/*
|
||||
* @param pid target process id
|
||||
* @param path injection dll path
|
||||
* @param configPath config file path
|
||||
*/
|
||||
public native boolean inject(int pid, String path, String configPath);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static native WindowInfo[] findWindowsByTitle(String keyword);
|
||||
|
||||
|
||||
public static class WindowInfo {
|
||||
public String title;
|
||||
public int pid;
|
||||
|
||||
public WindowInfo(String title, int pid) {
|
||||
this.title = title;
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("标题: %-30s | PID: %d", title, pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.xiaozhou233.orangex.injector;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static void unzip(InputStream zipInputStream, File destDir) throws IOException {
|
||||
if (!destDir.exists()) {
|
||||
destDir.mkdirs(); // 创建目标目录
|
||||
}
|
||||
|
||||
try (ZipInputStream zipIn = new ZipInputStream(zipInputStream)) {
|
||||
ZipEntry entry;
|
||||
while ((entry = zipIn.getNextEntry()) != null) {
|
||||
File outFile = new File(destDir, entry.getName());
|
||||
if (entry.isDirectory()) {
|
||||
outFile.mkdirs(); // 创建目录
|
||||
} else {
|
||||
File parent = outFile.getParentFile();
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs(); // 创建父目录
|
||||
}
|
||||
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile))) {
|
||||
byte[] buffer = new byte[4096];
|
||||
int read;
|
||||
while ((read = zipIn.read(buffer)) != -1) {
|
||||
bos.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
}
|
||||
zipIn.closeEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package cn.xiaozhou233.orangex.injector;
|
||||
|
||||
import cn.xiaozhou233.juiceagent.injector.InjectorNative;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Injector {
|
||||
public static String orangexPath = System.getProperty("user.home") + "/.orangex";
|
||||
public static void main(String[] args) {
|
||||
System.out.println("OrangeX Injector");
|
||||
|
||||
int pid = -1;
|
||||
|
||||
// Unzip injection.zip to ~/.orangex
|
||||
System.out.println("Unzip injection.zip to " + orangexPath);
|
||||
try (InputStream zipStream = ClassLoader.getSystemResourceAsStream("injection.zip")) {
|
||||
if (zipStream == null) {
|
||||
System.err.println("ZIP resource not found!");
|
||||
return;
|
||||
}
|
||||
FileUtils.unzip(zipStream, new File(orangexPath));
|
||||
System.out.println("Done!");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Load Native Library
|
||||
System.load(orangexPath + "/libinject.dll");
|
||||
InjectorNative injectorNative = new InjectorNative();
|
||||
|
||||
// Find Minecraft
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
try {
|
||||
String[] titles = {"Minecraft", "minecraft", "1.8.9", "Badlion", "Lunar"};
|
||||
String[] ignoreTitles = {"Badlion Client", "Badlion Chat", "Home - Lunar Client"};
|
||||
ArrayList<Integer> pids = new ArrayList<>();
|
||||
for (String title : titles) {
|
||||
InjectorNative.WindowInfo[] list = InjectorNative.findWindowsByTitle(title);
|
||||
if (list == null || list.length == 0) {
|
||||
} else {
|
||||
for (InjectorNative.WindowInfo w : list) {
|
||||
if (pids.contains(w.pid))
|
||||
continue;
|
||||
if (Arrays.stream(ignoreTitles).anyMatch(w.title::contains))
|
||||
continue;
|
||||
pids.add(w.pid);
|
||||
stringBuilder.append(String.format("[ %s ] %s%n", w.pid, w.title));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
throw new RuntimeException("Native method findWindowsByTitle not available", ule);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("[ERROR] Error while calling native findWindowsByTitle: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
// Print the result
|
||||
System.out.println("=======================");
|
||||
System.out.println(stringBuilder);
|
||||
System.out.println("=======================");
|
||||
|
||||
// Input the process ID
|
||||
try (Scanner scanner = new Scanner(System.in)) {
|
||||
System.out.print("[INPUT] PID: ");
|
||||
pid = scanner.nextInt();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid PID input", e);
|
||||
}
|
||||
|
||||
// Inject!
|
||||
String agentPath = orangexPath + "/libagent.dll";
|
||||
String configDir = orangexPath;
|
||||
injectorNative.inject(pid, agentPath, configDir);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user