parallel threaded search for RC4 key speed-up

This commit is contained in:
sirjonasxx 2018-06-13 22:01:28 +02:00
parent dbea4608e1
commit 809b68869a

View File

@ -155,81 +155,100 @@ public class LinuxHabboClient implements HabboClient {
private List<LinuxMemorySnippet> createMemorySnippetListForRC4() { private List<LinuxMemorySnippet> createMemorySnippetListForRC4() {
int offset = 4; Object lock = new Object();
refreshMemoryMaps(); refreshMemoryMaps();
String memoryPath = "/proc/" + PID + "/mem"; String memoryPath = "/proc/" + PID + "/mem";
int[] count = {0};
List<LinuxMemorySnippet> result = new ArrayList<>(); List<LinuxMemorySnippet> result = new ArrayList<>();
for (long[] map : maps) { for (long[] map : maps) {
long start = map[0]; new Thread(() -> {
long end = map[1]; int offset = 4;
long start = map[0];
long end = map[1];
byte[] data = new byte[(int)(end - start)]; byte[] data = new byte[(int)(end - start)];
try { try {
RandomAccessFile raf = new RandomAccessFile(memoryPath, "r"); RandomAccessFile raf = new RandomAccessFile(memoryPath, "r");
raf.seek(start); raf.seek(start);
raf.read(data); raf.read(data);
raf.close(); raf.close();
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}
int maskCount = 0;
int[] nToMap = new int[256];
int[] removeMap = new int[256];
for (int i = 0; i < removeMap.length; i++) {
removeMap[i] = -1;
nToMap[i] = -1;
}
int matchStart = -1;
int matchEnd = -1;
for (int i = 0; i < data.length; i+=offset) {
int b = (((int)data[i]) + 128) % 256;
int indInMap = (i/4) % 256;
int deletedNumber = removeMap[indInMap];
if (deletedNumber != -1) {
nToMap[deletedNumber] = -1;
maskCount --;
removeMap[indInMap] = -1;
} }
if (nToMap[b] == -1) {
maskCount ++; int maskCount = 0;
removeMap[indInMap] = b; int[] nToMap = new int[256];
nToMap[b] = indInMap; int[] removeMap = new int[256];
} for (int i = 0; i < removeMap.length; i++) {
else { removeMap[i] = -1;
removeMap[nToMap[b]] = -1; nToMap[i] = -1;
removeMap[indInMap] = b;
nToMap[b] = indInMap;
} }
if (maskCount == 256) {
if (matchStart == -1) { int matchStart = -1;
matchStart = i - ((256 - 1) * offset); int matchEnd = -1;
for (int i = 0; i < data.length; i+=offset) {
int b = (((int)data[i]) + 128) % 256;
int indInMap = (i/4) % 256;
int deletedNumber = removeMap[indInMap];
if (deletedNumber != -1) {
nToMap[deletedNumber] = -1;
maskCount --;
removeMap[indInMap] = -1;
}
if (nToMap[b] == -1) {
maskCount ++;
removeMap[indInMap] = b;
nToMap[b] = indInMap;
}
else {
removeMap[nToMap[b]] = -1;
removeMap[indInMap] = b;
nToMap[b] = indInMap;
}
if (maskCount == 256) {
if (matchStart == -1) {
matchStart = i - ((256 - 1) * offset);
matchEnd = i;
}
if (matchEnd < i - ((256 - 1) * offset)) {
result.add(new LinuxMemorySnippet(start + matchStart, new byte[matchEnd - matchStart + 4]));
matchStart = i - ((256 - 1) * offset);
}
matchEnd = i; matchEnd = i;
} }
if (matchEnd < i - ((256 - 1) * offset)) {
result.add(new LinuxMemorySnippet(start + matchStart, new byte[matchEnd - matchStart + 4]));
matchStart = i - ((256 - 1) * offset);
}
matchEnd = i;
} }
} if (matchStart != -1) {
result.add(new LinuxMemorySnippet(start + matchStart, new byte[matchEnd - matchStart + 4]));
}
if (matchStart != -1) { synchronized (lock) {
result.add(new LinuxMemorySnippet(start + matchStart, new byte[matchEnd - matchStart + 4])); count[0] ++;
}
}).start();
}
while (count[0] < maps.size()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
} }
} }
return result; return result;
} }
} }