mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
简化了注入流程
This commit is contained in:
1 parent
88006b8fcd
commit
dca4e7596b
1 file changed
+25
-12
@@ -8,7 +8,7 @@ import java.io.InputStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
public class Injector {
|
public class Injector {
|
||||||
public static String orangexPath = System.getProperty("user.home") + "/.orangex";
|
public static String orangexPath = System.getProperty("user.home") + "/.orangex";
|
||||||
@@ -35,11 +35,11 @@ public class Injector {
|
|||||||
InjectorNative injectorNative = new InjectorNative();
|
InjectorNative injectorNative = new InjectorNative();
|
||||||
|
|
||||||
// Find Minecraft
|
// Find Minecraft
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
ArrayList<Integer> pids = new ArrayList<>();
|
||||||
|
ArrayList<String> windowTitles = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
String[] titles = {"Minecraft", "minecraft", "1.8.9", "Badlion", "Lunar"};
|
String[] titles = {"Minecraft", "minecraft", "1.8.9", "Badlion", "Lunar"};
|
||||||
String[] ignoreTitles = {"Badlion Client", "Badlion Chat", "Home - Lunar Client"};
|
String[] ignoreTitles = {"Badlion Client", "Badlion Chat", "Home - Lunar Client"};
|
||||||
ArrayList<Integer> pids = new ArrayList<>();
|
|
||||||
for (String title : titles) {
|
for (String title : titles) {
|
||||||
InjectorNative.WindowInfo[] list = InjectorNative.findWindowsByTitle(title);
|
InjectorNative.WindowInfo[] list = InjectorNative.findWindowsByTitle(title);
|
||||||
if (list == null || list.length == 0) {
|
if (list == null || list.length == 0) {
|
||||||
@@ -50,7 +50,7 @@ public class Injector {
|
|||||||
if (Arrays.stream(ignoreTitles).anyMatch(w.title::contains))
|
if (Arrays.stream(ignoreTitles).anyMatch(w.title::contains))
|
||||||
continue;
|
continue;
|
||||||
pids.add(w.pid);
|
pids.add(w.pid);
|
||||||
stringBuilder.append(String.format("[ %s ] %s%n", w.pid, w.title));
|
windowTitles.add(w.title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,18 +63,31 @@ public class Injector {
|
|||||||
|
|
||||||
// Print the result
|
// Print the result
|
||||||
System.out.println("=======================");
|
System.out.println("=======================");
|
||||||
System.out.println(stringBuilder);
|
for (int i = 0; i < pids.size(); i++) {
|
||||||
|
System.out.printf("[ %d ] %s (PID: %d)%n", i + 1, windowTitles.get(i), pids.get(i));
|
||||||
|
}
|
||||||
System.out.println("=======================");
|
System.out.println("=======================");
|
||||||
|
|
||||||
// Input the process ID
|
if (pids.isEmpty()) {
|
||||||
try (Scanner scanner = new Scanner(System.in)) {
|
System.out.println("[ERROR] No Minecraft process found!");
|
||||||
System.out.print("[INPUT] PID: ");
|
return;
|
||||||
pid = scanner.nextInt();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Invalid PID input", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject!
|
// Input the sequence number
|
||||||
|
try (Scanner scanner = new Scanner(System.in)) {
|
||||||
|
System.out.printf("[INPUT] Select (1-%d): ", pids.size());
|
||||||
|
int index = scanner.nextInt();
|
||||||
|
if (index < 1 || index > pids.size()) {
|
||||||
|
throw new RuntimeException("Invalid selection: " + index);
|
||||||
|
}
|
||||||
|
pid = pids.get(index - 1);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Invalid input", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inject
|
||||||
String agentPath = orangexPath + "/libagent.dll";
|
String agentPath = orangexPath + "/libagent.dll";
|
||||||
String configDir = orangexPath;
|
String configDir = orangexPath;
|
||||||
injectorNative.inject(pid, agentPath, configDir);
|
injectorNative.inject(pid, agentPath, configDir);
|
||||||
|
|||||||
Reference in new issue
Block a user