Integration of unsafe packets in injection & bugfixes

This commit is contained in:
sirjonasxx 2022-12-27 23:18:03 +01:00
parent 7912fa35a6
commit cd9f849d21
13 changed files with 71 additions and 27 deletions

View File

@ -85,6 +85,11 @@ public class Cacher {
object.put(key, val);
updateCache(object, cache_filename);
}
public static void remove(String key, String cache_filename) {
JSONObject object = getCacheContents(cache_filename);
if (object.has(key)) object.remove(key);
updateCache(object, cache_filename);
}
public static Object get(String key, String cache_filename) {
JSONObject object = getCacheContents(cache_filename);
if (object.has(key)) return object.get(key);
@ -113,6 +118,9 @@ public class Cacher {
public static void put(String key, Object val) {
put(key, val, DEFAULT_CACHE_FILENAME);
}
public static void remove(String key) {
remove(key, DEFAULT_CACHE_FILENAME);
}
public static Object get(String key) {
return get(key, DEFAULT_CACHE_FILENAME);
}

View File

@ -162,14 +162,15 @@ public class HConnection {
return proxy.sendToServer(packet);
}
private boolean canSendPacket(HMessage.Direction direction, HPacket packet) {
public boolean canSendPacket(HMessage.Direction direction, HPacket packet) {
return isPacketSendingAllowed(direction, packet) && (developerMode || isPacketSendingSafe(direction, packet));
}
public boolean isPacketSendingAllowed(HMessage.Direction direction, HPacket packet) {
if (state != HState.CONNECTED) return false;
HProxy proxy = this.proxy;
if (proxy == null) return false;
if (packet.isCorrupted()) return false;
if (!packet.isPacketComplete()) {
@ -185,8 +186,9 @@ public class HConnection {
}
public boolean isPacketSendingSafe(HMessage.Direction direction, HPacket packet) {
if (proxy == null) return true; // do not mark unsafe, but won't pass "isPacketSendingAllowed()" check
String hotelVersion = proxy.getHotelVersion();
if (hotelVersion == null) return false;
if (hotelVersion == null) return true;
SafePacketsContainer packetsContainer = PacketSafetyManager.PACKET_SAFETY_MANAGER.getPacketContainer(hotelVersion);
return packetsContainer.isPacketSafe(packet.headerId(), direction);

View File

@ -132,11 +132,15 @@ public class ExtraController extends SubForm implements SocksConfiguration {
}
private void saveSocksConfig() {
JSONObject jsonObject = new JSONObject();
jsonObject.put(SOCKS_IP, getSocksHost());
jsonObject.put(SOCKS_PORT, getSocksPort());
// jsonObject.put(IGNORE_ONCE, cbx_socksUseIfNeeded.isSelected());
Cacher.put(SOCKS_CACHE_KEY, jsonObject);
if (txt_socksIp.getText().contains(":")) {
JSONObject jsonObject = new JSONObject();
jsonObject.put(SOCKS_IP, getSocksHost());
jsonObject.put(SOCKS_PORT, getSocksPort());
Cacher.put(SOCKS_CACHE_KEY, jsonObject);
}
else {
Cacher.remove(SOCKS_CACHE_KEY);
}
}
private void updateAdvancedUI() {
@ -160,7 +164,11 @@ public class ExtraController extends SubForm implements SocksConfiguration {
@Override
public int getSocksPort() {
return Integer.parseInt(txt_socksIp.getText().split(":")[1]);
String socksString = txt_socksIp.getText();
if (socksString.contains(":")) {
return Integer.parseInt(socksString.split(":")[1]);
}
return 1337;
}
@Override

View File

@ -1,10 +1,10 @@
package gearth.ui.subforms.injection;
import gearth.GEarth;
import gearth.misc.Cacher;
import gearth.services.packet_info.PacketInfoManager;
import gearth.protocol.HConnection;
import gearth.protocol.HMessage;
import gearth.protocol.connection.HState;
import gearth.protocol.HPacket;
import gearth.ui.SubForm;
import gearth.ui.translations.LanguageBundle;
import gearth.ui.translations.TranslatableString;
import javafx.application.Platform;
@ -14,8 +14,6 @@ import javafx.scene.input.MouseButton;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text;
import gearth.protocol.HPacket;
import gearth.ui.SubForm;
import java.util.ArrayList;
import java.util.Arrays;
@ -109,6 +107,7 @@ public class InjectionController extends SubForm {
private void updateUI() {
boolean dirty = false;
corruption.setFormat("%s: %s");
corruption.setKey(1, "tab.injection.corrupted.false");
lbl_corruption.getStyleClass().clear();
lbl_corruption.getStyleClass().add("not-corrupted-label");
@ -140,27 +139,45 @@ public class InjectionController extends SubForm {
}
if (!dirty) {
PacketInfoManager packetInfoManager = getHConnection().getPacketInfoManager();
for (HPacket packet : packets) {
packet.completePacket(packetInfoManager);
}
HConnection connection = getHConnection();
boolean canSendToClient = Arrays.stream(packets).allMatch(packet ->
packet.isPacketComplete() && packet.canSendToClient());
connection.canSendPacket(HMessage.Direction.TOCLIENT, packet));
boolean canSendToServer = Arrays.stream(packets).allMatch(packet ->
packet.isPacketComplete() && packet.canSendToServer());
connection.canSendPacket(HMessage.Direction.TOSERVER, packet));
btn_sendToClient.setDisable(!canSendToClient);
btn_sendToServer.setDisable(!canSendToServer);
// mark packet sending unsafe if there is any packet that is unsafe for both TOSERVER and TOCLIENT
boolean isUnsafe = Arrays.stream(packets).anyMatch(packet ->
!connection.isPacketSendingSafe(HMessage.Direction.TOCLIENT, packet) &&
!connection.isPacketSendingSafe(HMessage.Direction.TOSERVER, packet));
btn_sendToClient.setDisable(!canSendToClient || getHConnection().getState() != HState.CONNECTED);
btn_sendToServer.setDisable(!canSendToServer || getHConnection().getState() != HState.CONNECTED);
if (packets.length == 1) {
pcktInfo.setFormatAndKeys("%s (%s: " + packets[0].headerId() + ", %s: " + packets[0].length() + ")",
"tab.injection.description.header",
"tab.injection.description.id",
"tab.injection.description.length");
HPacket packet = packets[0];
if (isUnsafe) {
pcktInfo.setFormatAndKeys("%s (%s: " + packet.headerId() + ", %s: " + packet.length() + "), %s",
"tab.injection.description.header",
"tab.injection.description.id",
"tab.injection.description.length",
"tab.injection.description.unsafe");
}
else {
pcktInfo.setFormatAndKeys("%s (%s: " + packet.headerId() + ", %s: " + packet.length() + ")",
"tab.injection.description.header",
"tab.injection.description.id",
"tab.injection.description.length");
}
}
else {
lbl_pcktInfo.setText("");
if (isUnsafe) {
pcktInfo.setFormatAndKeys("%s", "tab.injection.description.unsafe");
}
else {
pcktInfo.setFormatAndKeys("");
}
}
} else {
if (packets.length == 1) {

View File

@ -30,6 +30,7 @@ tab.injection.description.header=Header
tab.injection.description.packets=Pakete
tab.injection.description.id=ID
tab.injection.description.length=Länge
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Zum Server senden
tab.injection.send.toclient=Zum Client senden
tab.injection.history=Verlauf:

View File

@ -28,6 +28,7 @@ tab.injection.description.header=header
tab.injection.description.packets=packets
tab.injection.description.id=id
tab.injection.description.length=length
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Send to server
tab.injection.send.toclient=Send to client
tab.injection.history=History:

View File

@ -28,6 +28,7 @@ tab.injection.description.header=header
tab.injection.description.packets=packets
tab.injection.description.id=id
tab.injection.description.length=longitud
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Enviar al servidor
tab.injection.send.toclient=Enviar a cliente
tab.injection.history=Historial

View File

@ -28,6 +28,7 @@ tab.injection.description.header=otsake
tab.injection.description.packets=paketit
tab.injection.description.id=id
tab.injection.description.length=pituus
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Lähetä palvelimelle
tab.injection.send.toclient=Lähetä asiakkaalle
tab.injection.history=Historia:

View File

@ -31,6 +31,7 @@ tab.injection.description.header=header
tab.injection.description.packets=packets
tab.injection.description.id=id
tab.injection.description.length=taille
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Envoyer au serveur
tab.injection.send.toclient=Envoyer au client
tab.injection.history=Historique:

View File

@ -28,6 +28,7 @@ tab.injection.description.header=header
tab.injection.description.packets=packets
tab.injection.description.id=id
tab.injection.description.length=lunghezza
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Manda al server
tab.injection.send.toclient=Manda al client
tab.injection.history=Cronologia:

View File

@ -28,6 +28,7 @@ tab.injection.description.header=header
tab.injection.description.packets=packets
tab.injection.description.id=id
tab.injection.description.length=lengte
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Stuur naar server
tab.injection.send.toclient=Stuur naar client
tab.injection.history=Geschiedenis:

View File

@ -28,6 +28,7 @@ tab.injection.description.header=cabeçalho
tab.injection.description.packets=pacotes
tab.injection.description.id=id
tab.injection.description.length=comprimento
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Enviar para o servidor
tab.injection.send.toclient=Enviar para o cliente
tab.injection.history=Histórico:

View File

@ -28,6 +28,7 @@ tab.injection.description.header=header
tab.injection.description.packets=paketler
tab.injection.description.id=id
tab.injection.description.length=uzunluk
tab.injection.description.unsafe=UNSAFE
tab.injection.send.toserver=Server a yolla
tab.injection.send.toclient=Client a yolla
tab.injection.history=Geçmiş: