Created
October 24, 2022 21:18
-
-
Save BJWielink/20cbf97cc35053b5e053ea9b5cd02734 to your computer and use it in GitHub Desktop.
Search for Cheat Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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