From 6680c105dea050af7dc4da6e07153999344399e9 Mon Sep 17 00:00:00 2001 From: Eduardo Alonso Date: Thu, 11 Oct 2018 22:41:20 +0400 Subject: [PATCH] Complete Windows support * The memory controller is now 64 bit * The flash process is calculated correctly --- G-WinMem/G-WinMem/G-WinMem.cpp | Bin 8878 -> 15794 bytes G-WinMem/G-WinMem/G-WinMem.vcxproj | 1 + .../windows/WindowsHabboClient.java | 318 +----------------- 3 files changed, 8 insertions(+), 311 deletions(-) diff --git a/G-WinMem/G-WinMem/G-WinMem.cpp b/G-WinMem/G-WinMem/G-WinMem.cpp index a7ea95311ece540c171c70dbb2d115eed1dc90a0..826e0b0f72ff32f991064a3eaa16c184019d34b5 100644 GIT binary patch literal 15794 zcmd6uX-^#46^83;N6LR_6UAzK0=5|vjb&L~0+)m3*n%X`*a{O8|yiaSNScv{RCFN>4ntax7Zi_>DE*e?e9X&2w? z^GNp&!_$6osqa_CvF^0>In(t;@ln@<;yjGF()FRPFOqTl`hKRF=f#^aZ!fITa6o2>h7u{dGXm*N_HtV#!OCX9U_v}fF%O&kqIPJ@;YC#?HU6zorw7I+11 zmqI6+fNGPiA!`t1ex$p5LaOb4s!<@iqnYUUFM2YktE$}X>0EKE#MAU^y%a5rMYojn z_19S!m1qDRr}fRHbd{$Xaiu$b?Y1oX540j0 zx|GD9>CU?LTGN_%lV{rREb!Pb&*b4k(Z%P9gG`G|)>+IY0)^_X!}d_f1- zm->su&b4=^ynib^ITK}Qb|6|V#Jf>#T0ve{dVV3AkrJydloB-x`W4B#Mwrj1rycRb zZP9rtSs6->E8KLnE|$O^C(?o;J!;_kI%pSv*Qz;>u9r>e^kLW&gxJVW`nz8IBwVcN z%8}KQhIe$Qt0&uI2Gq50Jq#QvsTsvNx#FI~-hEUq2}tUS@xT95#ka$UJRPlTJ$$pULeQA33T^kE@R6?qhH?qq8cN9|?HIZt3F2+c6SNXMtc0D>RO++qsB@{b6kV>T zYpg3qj$GsE6ZhFw+&cxvSsuZ9iUec{my#0l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&kP-qdfDeYL@gdZ%n;xJ*IKe+|@4V#^pnToSqDs(NZd04E+FL}x^S-vJ3; zpMp!q)v*BAgQ0Jyvo$9SV7ou-YMh-k_voy0b}wMNz7Dx+{$7m9D%S@V+5Dd+@rm`1 z-&C^KRJQRtUZpjsdve#7j~aDaRevYLX4*VB;A64TazC!)=@Pl;k@_ph(mR=WlH2l= zJb71E&#rAphR;K{X!qM7MIV*EDPgBD{vS+s7Ls=*S0z`vQ??)8`Snn@^m}-FB7MGC zKF_<0aDZ>2%V;ui{WT%e-#X+!h@C>bWaJ=vo>h6m(f^C)r%ct^t@7Q&Nf`;}xFFG~ zHc#PtcOT-sxcr^wg%Ei;;~}c#9oC4;dQWv-QjMJ3e?=2p4vPF;0HdR=vHXy?#CL7I I%NeouUkz2mjQ{`u delta 189 zcmdl~z0P&R8b-lHh8%`;hJ1!1hD?SMh75+>$rBkpCvRaAn*4=n#^g)P6Ie4D@)$}c zU$mBG*JR*j;9{uW%q(2a#H`C;IJuuobn+t61C#kALL`kD44_bfp#}&+N;yGrvaEzF zzcGUagCS7fkO6GStrue _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 Console diff --git a/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java b/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java index 9a23016..969bf2b 100644 --- a/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java +++ b/src/main/protocol/memory/habboclient/windows/WindowsHabboClient.java @@ -1,208 +1,27 @@ 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 com.sun.jna.Memory; -import com.sun.jna.Native; -import com.sun.jna.Pointer; -import com.sun.jna.platform.win32.*; -import com.sun.jna.ptr.IntByReference; -import com.sun.jna.win32.StdCallLibrary; import main.protocol.HConnection; import main.protocol.memory.habboclient.HabboClient; import javax.xml.bind.DatatypeConverter; -import java.io.*; -import java.lang.reflect.Array; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - +import java.util.*; /** * Created by Jeunez on 27/06/2018. */ - -/* - * not functional class - */ - public class WindowsHabboClient extends HabboClient { public WindowsHabboClient(HConnection connection) { super(connection); } - private static final boolean DEBUG = false; - 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; - - 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){ - 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); - } - } - } - } - private ArrayList readPossibleBytes() throws IOException, URISyntaxException { - ProcessBuilder pb = new ProcessBuilder(new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getParent() + "\\G-WinMem.exe"); + ProcessBuilder pb = new ProcessBuilder(new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getParent() + "\\G-WinMem.exe", hConnection.getClientHostAndPort().substring(0, hConnection.getClientHostAndPort().indexOf(':')) , Integer.toString(hConnection.getPort())); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); @@ -221,7 +40,6 @@ public class WindowsHabboClient extends HabboClient { @Override public List getRC4possibilities() { - System.out.println("Getting Win Possibilities"); List result = new ArrayList<>(); try { Thread.sleep(3000); @@ -234,127 +52,5 @@ public class WindowsHabboClient extends HabboClient { e.printStackTrace(); } return result; - - /* - - enableDebugPrivilege(); - obtain_PIDs(); - - 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<>(); - - WinNT.HANDLE process = kernel32.OpenProcess(PROCESS_VM_READ|PROCESS_VM_OPERATION, true, processID); - - Memory out = new Memory(processMemorySize); - IntByReference t = new IntByReference(); - kernel32.ReadProcessMemory(process, process.getPointer(), out, processMemorySize, t); - - - System.out.println("read " + t.getValue()); - - - 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); - - - - - - - System.out.println(process.getPointer()); - - return result; - } - - private static void enableDebugPrivilege() { - WinNT.HANDLEByReference hToken = new WinNT.HANDLEByReference(); - boolean success = Advapi32.INSTANCE.OpenProcessToken(Kernel32.INSTANCE.GetCurrentProcess(), - WinNT.TOKEN_QUERY | WinNT.TOKEN_ADJUST_PRIVILEGES, hToken); - if (!success) { - System.out.println("OpenProcessToken failed. Error: {}" + Native.getLastError()); - return; - } - WinNT.LUID luid = new WinNT.LUID(); - success = Advapi32.INSTANCE.LookupPrivilegeValue(null, WinNT.SE_DEBUG_NAME, luid); - if (!success) { - System.out.println("LookupprivilegeValue failed. Error: {}" + Native.getLastError()); - return; - } - WinNT.TOKEN_PRIVILEGES tkp = new WinNT.TOKEN_PRIVILEGES(1); - tkp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(luid, new WinDef.DWORD(WinNT.SE_PRIVILEGE_ENABLED)); - success = Advapi32.INSTANCE.AdjustTokenPrivileges(hToken.getValue(), false, tkp, 0, null, null); - if (!success) { - System.out.println("AdjustTokenPrivileges failed. Error: {}" + Native.getLastError()); - } - Kernel32.INSTANCE.CloseHandle(hToken.getValue()); - } - - public static void main(String[] args) { - String command2 = "cmd /C tasklist"; - List tasks = execute_command(command2); - List taskList = parseTaskList(tasks); - - System.out.println("t"); - } - -} +} \ No newline at end of file