From a18256640ec16802bd0811617d2e38117a5ce00d Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Wed, 4 Apr 2018 17:04:43 +0200 Subject: [PATCH] cleaning up shitty code --- src/main/protocol/memory/FlashClient.java | 60 +++++++++++------------ src/main/protocol/memory/MemoryUtils.java | 34 ------------- 2 files changed, 29 insertions(+), 65 deletions(-) delete mode 100644 src/main/protocol/memory/MemoryUtils.java diff --git a/src/main/protocol/memory/FlashClient.java b/src/main/protocol/memory/FlashClient.java index 335a9f7..9d7bf61 100644 --- a/src/main/protocol/memory/FlashClient.java +++ b/src/main/protocol/memory/FlashClient.java @@ -1,13 +1,14 @@ package main.protocol.memory; -import main.irrelevant.Timer; - import java.io.*; -import java.lang.reflect.Array; +import java.nio.file.Files; import java.util.*; public class FlashClient { + + private static final String[] potentialProcessNames = {"--ppapi-flash-args", "plugin-container"}; + private int PID; private List maps; @@ -20,10 +21,16 @@ public class FlashClient { do { File[] fileList = folder.listFiles(); for (File file : fileList) { - if (file.isDirectory() && MemoryUtils.stringIsNumeric(file.getName())) { + if (file.isDirectory() && stringIsNumeric(file.getName())) { String path = "/proc/" + file.getName() + "/cmdline"; - if (MemoryUtils.fileContainsString(path, "--ppapi-flash-args") || - MemoryUtils.fileContainsString(path, "plugin-container")) { + boolean isHabboProcess = false; + for (String s : potentialProcessNames) { + if (fileContainsString(path, s)) { + isHabboProcess = true; + break; + } + } + if (isHabboProcess) { client = new FlashClient(); client.PID = Integer.parseInt(file.getName()); client.maps = new ArrayList<>(); @@ -151,33 +158,24 @@ public class FlashClient { return result; } - public static void main(String[] args) throws InterruptedException { - FlashClient client = FlashClient.create(); - client.refreshMemoryMaps(); -// List gameHostOccurences = client.searchOffsetForString("game-nl.habbo.com"); -// List rsaOccurences = client.searchOffsetForString("xIBlMDUyODA4YzFhYmVmNjlhMWE2MmMzOTYzOTZiODU5NTVlMmZmNTIy"); -// List occ = client.searchOffsetForString("sirjonasxx"); - -// List l = client.createMemorySnippetList(); -// client.fetchMemory(l); -// Thread.sleep(1000); -// //what didnt change in the last 1000ms? -// List l2 = client.differentiate(l, false, 0); -// Thread.sleep(1000); -// //what changed in the last 1000ms? -// List l3 = client.differentiate(l2, true, 0); -// Thread.sleep(1000); -// //what didnt change in the last 1000ms? -// List l4 = client.differentiate(l3, false, 0); -// Thread.sleep(1000); -// //what changed in the last 1000ms? -// List l5 = client.differentiate(l4, true, 0); - -// client.updateMapLocationsSnippetList(l); + static boolean stringIsNumeric(String str) { + for (char c : str.toCharArray()) { + if (c < '0' || c > '9') return false; + } + return true; + } + static boolean fileContainsString(String path, String contains) { + try { + List lines = Files.readAllLines(new File(path).toPath()); + for (String line : lines) { + if (line.contains(contains)) return true; + } + } catch (Exception e) { + // process of specified path not running anymore + } + return false; } - - } diff --git a/src/main/protocol/memory/MemoryUtils.java b/src/main/protocol/memory/MemoryUtils.java deleted file mode 100644 index 0a5d0a3..0000000 --- a/src/main/protocol/memory/MemoryUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -package main.protocol.memory; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; - -class MemoryUtils { - - static boolean stringIsNumeric(String str) { - for (char c : str.toCharArray()) { - if (c < '0' || c > '9') return false; - } - return true; - } - - static boolean fileContainsString(String path, String contains) { - - try { - List lines = Files.readAllLines(new File(path).toPath()); - for (String line : lines) { - if (line.contains(contains)) return true; - } - } catch (Exception e) { - // process of specified path not running anymore - } - return false; - - } - -}