From 5c62c1d18830e59715e88000f0a5700f8fc94513 Mon Sep 17 00:00:00 2001 From: sirjonasxx <36828922+sirjonasxx@users.noreply.github.com> Date: Fri, 6 Apr 2018 03:45:21 +0200 Subject: [PATCH] add retro support (long connection time) --- src/main/protocol/memory/Rc4Obtainer.java | 68 ++++++++++++++++------- src/main/ui/connection/Connection.java | 47 ++++++++-------- 2 files changed, 70 insertions(+), 45 deletions(-) diff --git a/src/main/protocol/memory/Rc4Obtainer.java b/src/main/protocol/memory/Rc4Obtainer.java index b63b73f..f5d7a8c 100644 --- a/src/main/protocol/memory/Rc4Obtainer.java +++ b/src/main/protocol/memory/Rc4Obtainer.java @@ -64,8 +64,13 @@ public class Rc4Obtainer { if (DEBUG) System.out.println("[+] send encrypted"); sleep(20); - while (pingHeader == -1) { + int count = 0; + while (pingHeader == -1 && count < 500) { sleep(50); + count++; + } + if (count == 500) { + System.out.println("are you connected to a retro? trying other things (might take a while).."); } incomingHandler.block(); @@ -88,21 +93,26 @@ public class Rc4Obtainer { if (DEBUG) System.out.println("size: " + getTotalBytesLengthOfDiff(diff)); int i = 0; while (getTotalBytesLengthOfDiff(diff) > 2000) { - int am = 0; - if (i == 0 || i > 1) { - am = rand.nextInt(25) + 5; - for (int j = 0; j < am; j++) { - incomingHandler.sendToStream(new HPacket(pingHeader).toBytes()); - outgoingHandler.fakePongAlert(); - sleep(20); + if (pingHeader != -1) { + int am = 0; + if (i == 0 || i > 1) { + am = rand.nextInt(25) + 5; + for (int j = 0; j < am; j++) { + incomingHandler.sendToStream(new HPacket(pingHeader).toBytes()); + outgoingHandler.fakePongAlert(); + sleep(20); + } } + sleep(50); } - sleep(50); - int rem = addedBytes; - if (i == 0) client.pauseProcess(); + else { + while (addedBytes == 0) { + sleep(50); + } + System.out.println("making progress.."); + } + diff = searchForPossibleRC4Tables(diff); - if (i == 0) client.resumeProcess(); - if (DEBUG) System.out.println("size: " + getTotalBytesLengthOfDiff(diff) + " with changed bytes: " + rem + " should be: " + am * 6); i++; } @@ -146,15 +156,33 @@ public class Rc4Obtainer { MemorySnippet snippet1 = new MemorySnippet(snippet.getOffset(), new byte[snippet.getData().length]); client.fetchMemory(snippet1); - incomingHandler.sendToStream(new HPacket(pingHeader).toBytes()); - outgoingHandler.fakePongAlert(); + if (pingHeader != -1) { + incomingHandler.sendToStream(new HPacket(pingHeader).toBytes()); + outgoingHandler.fakePongAlert(); + } + sleep(70); - byte[] lastPongPacket = new byte[6]; - List encodedbytelistraw = outgoingHandler.getEncryptedBuffer(); - for (int i = 0; i < 6; i++) { - lastPongPacket[i] = encodedbytelistraw.get(encodedbytelistraw.size() - 6 + i); + byte[] lastOutgoingPacket; + if (pingHeader != -1) { + lastOutgoingPacket = new byte[6]; } + else { + int size = outgoingHandler.getEncryptedBuffer().size(); + int copy = size; + while (copy == size) { + sleep(1); + copy = outgoingHandler.getEncryptedBuffer().size(); + } + lastOutgoingPacket = new byte[copy - size]; + System.out.println("size: " + lastOutgoingPacket.length); + } + + for (int i = 0; i < lastOutgoingPacket.length; i++) { + List encodedbytelistraw = outgoingHandler.getEncryptedBuffer(); + lastOutgoingPacket[i] = encodedbytelistraw.get(encodedbytelistraw.size() - lastOutgoingPacket.length + i); + } + int counter = 0; RC4 result = null; @@ -174,7 +202,7 @@ public class Rc4Obtainer { } RC4 rc4Tryout = new RC4(copy, x, y); - HPacket tryout = new HPacket(rc4Tryout.rc4(lastPongPacket)); + HPacket tryout = new HPacket(rc4Tryout.rc4(lastOutgoingPacket)); if (!tryout.isCorrupted()) { result = rc4Tryout; break outerloop; diff --git a/src/main/ui/connection/Connection.java b/src/main/ui/connection/Connection.java index fa5da10..b79b9bf 100644 --- a/src/main/ui/connection/Connection.java +++ b/src/main/ui/connection/Connection.java @@ -29,29 +29,10 @@ public class Connection extends SubForm { public void initialize() { inpPort.getEditor().textProperty().addListener(observable -> { - try { - int i = Integer.parseInt(inpPort.getEditor().getText()); - btnConnect.setDisable(i < 0 || i >= 256 * 256); - } - catch (Exception e) { - btnConnect.setDisable(true); - } + updateInputUI(); }); cbx_autodetect.selectedProperty().addListener(observable -> { - inpPort.setDisable(cbx_autodetect.isSelected()); - inpHost.setDisable(cbx_autodetect.isSelected()); - if (cbx_autodetect.isSelected()) { - btnConnect.setDisable(false); - } - else { - try { - int i = Integer.parseInt(inpPort.getEditor().getText()); - btnConnect.setDisable(i < 0 || i >= 256 * 256); - } - catch (Exception e) { - btnConnect.setDisable(true); - } - } + updateInputUI(); }); inpPort.getItems().addAll("30000", "38101"); @@ -61,19 +42,35 @@ public class Connection extends SubForm { inpHost.getSelectionModel().selectFirst(); } + private void updateInputUI() { + if (cbx_autodetect.isSelected()) { + btnConnect.setDisable(false); + } + else { + try { + int i = Integer.parseInt(inpPort.getEditor().getText()); + btnConnect.setDisable(i < 0 || i >= 256 * 256); + } + catch (Exception e) { + btnConnect.setDisable(true); + } + } + + inpHost.setDisable(getHConnection().getState() != HConnection.State.NOT_CONNECTED || cbx_autodetect.isSelected()); + inpPort.setDisable(getHConnection().getState() != HConnection.State.NOT_CONNECTED || cbx_autodetect.isSelected()); + } + public void onParentSet(){ getHConnection().addStateChangeListener((oldState, newState) -> Platform.runLater(() -> { if (newState == HConnection.State.NOT_CONNECTED) { - inpHost.setDisable(false); - inpPort.setDisable(false); + updateInputUI(); lblState.setText("Not connected"); btnConnect.setText("Connect"); outHost.setText(""); outPort.setText(""); } else if (oldState == HConnection.State.NOT_CONNECTED) { - inpHost.setDisable(true); - inpPort.setDisable(true); + updateInputUI(); btnConnect.setText("Abort"); }