diff --git a/G-Earth.iml b/G-Earth.iml
index c90834f..5377335 100644
--- a/G-Earth.iml
+++ b/G-Earth.iml
@@ -7,5 +7,7 @@
+
+
\ No newline at end of file
diff --git a/desktop.ini b/desktop.ini
new file mode 100644
index 0000000..808f178
--- /dev/null
+++ b/desktop.ini
@@ -0,0 +1,3 @@
+[LocalizedFileNames]
+jna-4.5.1.jar=@jna-4.5.1.jar,0
+jna-platform-4.5.1.jar=@jna-platform-4.5.1.jar,0
diff --git a/jna-4.5.1.jar b/jna-4.5.1.jar
new file mode 100644
index 0000000..68216af
Binary files /dev/null and b/jna-4.5.1.jar differ
diff --git a/jna-platform-4.5.1.jar b/jna-platform-4.5.1.jar
new file mode 100644
index 0000000..5aeb3e4
Binary files /dev/null and b/jna-platform-4.5.1.jar differ
diff --git a/src/main/protocol/memory/habboclient/linux/LinuxHabboClient.java b/src/main/protocol/memory/habboclient/linux/LinuxHabboClient.java
index aaf1c28..6e8198f 100644
--- a/src/main/protocol/memory/habboclient/linux/LinuxHabboClient.java
+++ b/src/main/protocol/memory/habboclient/linux/LinuxHabboClient.java
@@ -233,11 +233,10 @@ public class LinuxHabboClient extends HabboClient {
}
- if (matchStart != -1) {
- result.add(new LinuxMemorySnippet(start + matchStart, new byte[matchEnd - matchStart + 4]));
- }
-
synchronized (lock) {
+ if (matchStart != -1) {
+ result.add(new LinuxMemorySnippet(start + matchStart, new byte[matchEnd - matchStart + 4]));
+ }
count[0] ++;
}
diff --git a/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java b/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java
index 9ebb517..b7f59a2 100644
--- a/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java
+++ b/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java
@@ -1,59 +1,303 @@
package main.protocol.memory.habboclient.windows;
+import com.sun.jna.Memory;
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
+import com.sun.jna.platform.win32.Kernel32;
+import com.sun.jna.platform.win32.User32;
+import com.sun.jna.platform.win32.WinBase;
+import com.sun.jna.platform.win32.WinNT;
+import com.sun.jna.ptr.IntByReference;
import main.protocol.HConnection;
import main.protocol.memory.habboclient.HabboClient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
+import java.lang.reflect.Array;
+import java.util.*;
/**
* Created by Jeunez on 27/06/2018.
*/
+
+
+/*
+ * all code in this file is here for no actual purpose atm
+ */
+
public class WindowsHabboClient extends HabboClient {
private static final boolean DEBUG = true;
- private int[] PID; // list of potential PIDs
+ private List possibleFlashTasks;
+
+ static Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32",Kernel32.class);
+ static User32 user32 = (User32) Native.loadLibrary("user32", User32.class);
+
+ public static int PROCESS_VM_READ= 0x0010;
+ public static int PROCESS_VM_WRITE = 0x0020;
+ public static int PROCESS_VM_OPERATION = 0x0008;
+
public WindowsHabboClient(HConnection connection) {
super(connection);
-
-
}
- private void obtain_PID () {
- String command="cmd /C netstat -a -o -n | findstr "+hConnection.getClientHostAndPort()+" | findstr ESTABLISHED";
+ static class WindowsTask {
+ public String name;
+ public int PID;
+ public String session_name;
+ public int sessionNumber;
+ public int mem_usage;
+
+ public WindowsTask(String name, int PID, String sessions_name, int sessionNumber, int mem_usage) {
+ this.name = name;
+ this.PID = PID;
+ this.session_name = sessions_name;
+ this.sessionNumber = sessionNumber;
+ this.mem_usage = mem_usage;
+ }
+
+ @Override
+ public String toString() {
+ return "name: " + name + ", PID: " + PID + ", memory: " + mem_usage;
+ }
+ }
+
+ private static List execute_command(String command) {
+ List result = new ArrayList<>();
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader=new BufferedReader( new InputStreamReader(process.getInputStream()));
String s;
while ((s = reader.readLine()) != null){
- String[] split = s.split(" ");
-
- List realSplit = new ArrayList<>();
- for (String spli : split) {
- if (!spli.equals("") && !spli.equals(" ")) {
- realSplit.add(spli);
- }
- }
-
- if (realSplit.get(1).equals(hConnection.getClientHostAndPort())) {
-// PID = Integer.parseInt(realSplit.get(4));
- }
+ result.add(s);
}
} catch (IOException e) {
e.printStackTrace();
}
+ return result;
+ }
+ private static List splitStringExtra(String s, String regex ) {
+ String[] split = s.split(regex);
+
+ List realSplit = new ArrayList<>();
+ for (String spli : split) {
+ if (!spli.equals("") && !spli.equals(" ")) {
+ realSplit.add(spli);
+ }
+ }
+
+ return realSplit;
+ }
+ private static List parseTaskList(List lines) {
+ List windowsTasks = new ArrayList<>();
+
+ final int ARG_COUNT = 5;
+ boolean listHasStarted = false;
+ int[] paramLengths = new int[ARG_COUNT];
+ for (String line : lines) {
+
+ if (!listHasStarted && line.startsWith("=")) {
+ List splitted = splitStringExtra(line, " ");
+ if (splitted.size() == ARG_COUNT) {
+ listHasStarted = true;
+ for (int i = 0; i < ARG_COUNT; i++) {
+ paramLengths[i] = splitted.get(i).length();
+ }
+ }
+ }
+ else if (listHasStarted && splitStringExtra(line, " ").size() >= 5) {
+ int v = 0;
+ String[] args = new String[ARG_COUNT];
+ for (int i = 0; i < ARG_COUNT; i++) {
+ int endindex = v + paramLengths[i];
+ args[i] = trim(line.substring(v, endindex));
+ v = endindex + 1;
+ }
+
+ WindowsTask task = new WindowsTask(
+ args[0],
+ Integer.parseInt(args[1]),
+ args[2],
+ Integer.parseInt(args[3]),
+ obtainMemorySizeFromCMDString(args[4])
+ );
+
+ windowsTasks.add(task);
+ }
+
+ }
+
+ return windowsTasks;
+ }
+ private static String trim(String s) {
+ int start = 0;
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == ' ') start++;
+ else break;
+ }
+
+ int end = s.length();
+ for (int i = s.length() - 1; i >= 0; i--) {
+ if (s.charAt(i) == ' ') end--;
+ else break;
+ }
+
+ return s.substring(start, end);
+ }
+ private static int obtainMemorySizeFromCMDString(String s) {
+ s = s.replaceAll("[^0-9A-Z]","")
+ .replace("K","000")
+ .replace("M", "000000")
+ .replace("G", "000000000");
+ return Integer.parseInt(s);
+ }
+
+ private void obtain_PIDs() {
+ int headPID = -1;
+
+
+ String command1 = "cmd /C netstat -a -o -n | findstr "+hConnection.getClientHostAndPort()+" | findstr ESTABLISHED";
+ List connections = execute_command(command1);
+ for (String s : connections) {
+ List realSplit = splitStringExtra(s, " ");
+
+ if (realSplit.size() > 1 && realSplit.get(1).equals(hConnection.getClientHostAndPort())) {
+ headPID = Integer.parseInt(realSplit.get(4));
+ }
+ }
+
+
+
+ String command2 = "cmd /C tasklist";
+ List tasks = execute_command(command2);
+ List taskList = parseTaskList(tasks);
+
+ WindowsTask matchWithPID = null;
+ int i = 0;
+ while (matchWithPID == null && i < taskList.size()) {
+ WindowsTask task = taskList.get(i);
+ if (task.PID == headPID) {
+ matchWithPID = task;
+ }
+ i++;
+ }
+
+ possibleFlashTasks = new ArrayList<>();
+ if (matchWithPID != null) {
+ for (WindowsTask task : taskList) {
+ if (task.name.equals(matchWithPID.name)) {
+ possibleFlashTasks.add(task);
+ }
+ }
+ }
+
+
+
}
@Override
public List getRC4possibilities() {
- obtain_PID();
- if (DEBUG) System.out.println("FLASH PROCESS ID: " + PID);
+ obtain_PIDs();
- while (true) {}
-// return null;
+ List possibilities = new ArrayList<>();
+
+ int[] count = {0};
+ for (int i = 0; i < possibleFlashTasks.size(); i++) {
+ WindowsTask task = possibleFlashTasks.get(i);
+ if (DEBUG) System.out.println("Potential task " + task);
+
+ new Thread(() -> {
+ List sublist = getRC4possibilities(task.PID, task.mem_usage);
+
+ synchronized (count) {
+ possibilities.addAll(sublist);
+ count[0] ++;
+ }
+
+ }).start();
+ }
+
+ while (count[0] != possibleFlashTasks.size() + 1) { // the +1 is temporary, to keep this function blocking untill it's functional
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return possibilities;
}
+
+ public List getRC4possibilities(int processID, int processMemorySize) {
+ List result = new ArrayList<>();
+
+// user32.GetWindowThreadProcessId()
+ WinNT.HANDLE process = kernel32.OpenProcess(PROCESS_VM_READ|PROCESS_VM_OPERATION, true, processID);
+
+ IntByReference test = new IntByReference(0);
+ Memory output = new Memory(100000);
+ System.out.println(kernel32.ReadProcessMemory(process, new Pointer(0), output, 100000, test));
+ System.out.println(test.getValue());
+
+ int[] counter = new int[256];
+ int p = 0;
+ while (p < output.size()) {
+ counter[(output.getByte(p) + 256) % 256] ++;
+ p += 4;
+ }
+
+// for (int i = 0; i < counter.length; i++) {
+// System.out.println("counter " + i + " = " + counter[i]);
+// }
+
+// WinNT.HANDLE process = kernel32.OpenProcess(PROCESS_VM_READ|PROCESS_VM_OPERATION, true, processID);
+// Memory out = new Memory(processMemorySize);
+// kernel32.ReadProcessMemory(process, new Pointer(0), out, processMemorySize, new IntByReference());
+//
+// int[] counter = new int[256];
+// int p = 0;
+// while (p < out.size()) {
+// counter[((out.getByte(p)) + 256) % 256] ++;
+// p += 4;
+// }
+//
+// HashMap> mapper = new HashMap<>();
+// HashSet allvalues = new HashSet<>();
+// for (int i = 0; i < counter.length; i++) {
+// if (!mapper.containsKey(counter[i])) {
+// mapper.put(counter[i], new ArrayList<>());
+// }
+// mapper.get(counter[i]).add(i);
+// allvalues.add(counter[i]);
+// }
+//// System.out.println(allvalues.size());
+// ArrayList allvalues2 = new ArrayList<>(allvalues);
+// allvalues2.sort(Integer::compareTo);
+//
+// StringBuilder sttt = new StringBuilder();
+// sttt.append("process ").append(processID).append(", ");
+// for (int i = 1; i < Math.min(4, allvalues2.size()+1); i++) {
+// int occ = allvalues2.get(allvalues2.size() - i);
+// sttt .append(i)
+// .append(": ")
+// .append(mapper.get(occ).get(0))
+// .append(" with ")
+// .append(occ)
+// .append(" occurences, ");
+// }
+// System.out.println(sttt);
+
+ return result;
+ }
+
+ public static void main(String[] args) {
+ String command2 = "cmd /C tasklist";
+ List tasks = execute_command(command2);
+ List taskList = parseTaskList(tasks);
+
+ System.out.println("t");
+ }
+
}
diff --git a/src/main/ui/extensions/extensionfilemanager/ExtensionFilesManager.java b/src/main/ui/extensions/extensionfilemanager/ExtensionFilesManager.java
deleted file mode 100644
index b9473e4..0000000
--- a/src/main/ui/extensions/extensionfilemanager/ExtensionFilesManager.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package main.ui.extensions.extensionfilemanager;
-
-import main.ui.extensions.extensionfilemanager.extensionfile.ExtensionFile;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * Created by Jonas on 21/06/18.
- */
-public interface ExtensionFilesManager {
-
- List getAllExtensions();
-
- ExtensionFile addExtension(File file); //returns g-earth extension file, returns null if failure
-
- boolean removeExtension(ExtensionFile file); //returns false if not done
-
-}
diff --git a/src/main/ui/extensions/extensionfilemanager/ExtensionFilesManagerFactory.java b/src/main/ui/extensions/extensionfilemanager/ExtensionFilesManagerFactory.java
deleted file mode 100644
index c9e0483..0000000
--- a/src/main/ui/extensions/extensionfilemanager/ExtensionFilesManagerFactory.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package main.ui.extensions.extensionfilemanager;
-
-/**
- * Created by Jonas on 21/06/18.
- */
-public class ExtensionFilesManagerFactory {
-}
diff --git a/src/main/ui/extensions/extensionfilemanager/LinuxExtensionFilesManager.java b/src/main/ui/extensions/extensionfilemanager/LinuxExtensionFilesManager.java
deleted file mode 100644
index 2ee1a5c..0000000
--- a/src/main/ui/extensions/extensionfilemanager/LinuxExtensionFilesManager.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package main.ui.extensions.extensionfilemanager;
-
-import main.ui.extensions.extensionfilemanager.extensionfile.ExtensionFile;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * Created by Jonas on 21/06/18.
- */
-public class LinuxExtensionFilesManager implements ExtensionFilesManager {
-
- @Override
- public List getAllExtensions() {
- return null;
- }
-
- @Override
- public ExtensionFile addExtension(File file) {
- return null;
- }
-
- @Override
- public boolean removeExtension(ExtensionFile file) {
- return false;
- }
-}
diff --git a/src/main/ui/extensions/extensionfilemanager/extensionfile/ExtensionFile.java b/src/main/ui/extensions/extensionfilemanager/extensionfile/ExtensionFile.java
deleted file mode 100644
index 4e3524c..0000000
--- a/src/main/ui/extensions/extensionfilemanager/extensionfile/ExtensionFile.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package main.ui.extensions.extensionfilemanager.extensionfile;
-
-/**
- * Created by Jonas on 21/06/18.
- */
-public class ExtensionFile {
-
-
-
-}