Skip to content

Instantly share code, notes, and snippets.

@BJWielink
Created October 24, 2022 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BJWielink/20cbf97cc35053b5e053ea9b5cd02734 to your computer and use it in GitHub Desktop.
Save BJWielink/20cbf97cc35053b5e053ea9b5cd02734 to your computer and use it in GitHub Desktop.
Search for Cheat Engine
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class App {
public static void main(String[] args) {
var active = cheatEngineActiveWindows();
System.out.println(active);
}
private static boolean isCheatEngineLine(final String line) {
return (line.startsWith("cheatengine"));
}
private static boolean cheatEngineActiveWindows() {
final Process process;
try {
process = Runtime.getRuntime().exec(System.getenv("windir") +"\\system32\\"+"tasklist.exe");
} catch (IOException e) {
return false;
}
final var processes = loadProcesses(process);
if (processes == null) {
return false;
}
for (var line : processes) {
if (isCheatEngineLine(line)) {
return true;
}
}
return false;
}
private static List<String> loadProcesses(final Process process) {
final var list = new ArrayList<String>();
try (var input = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = input.readLine()) != null) {
list.add(line);
}
} catch (IOException e) {
return null;
}
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment