mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 00:40:51 +01:00
packet structure & predictor changes
This commit is contained in:
parent
6b9e3451e0
commit
b13cba0cf4
@ -45,6 +45,9 @@ public class PacketStringUtils {
|
||||
packet = replaceAll(packet, "\\{u:([0-9]+)}",
|
||||
m -> "[" + (Integer.parseInt(m.group(1))/256) + "][" + (Integer.parseInt(m.group(1)) % 256) + "]");
|
||||
|
||||
packet = replaceAll(packet, "\\{h:([0-9]+)}",
|
||||
m -> "[" + (Integer.parseInt(m.group(1))/256) + "][" + (Integer.parseInt(m.group(1)) % 256) + "]");
|
||||
|
||||
packet = replaceAll(packet, "\\{b:([Ff]alse|[Tt]rue)}",
|
||||
m -> m.group(1).toLowerCase().equals("true") ? "[1]" : "[0]");
|
||||
|
||||
@ -174,7 +177,7 @@ public class PacketStringUtils {
|
||||
packet.resetReadIndex();
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("{l}{u:").append(packet.headerId()).append("}");
|
||||
builder.append("{l}{h:").append(packet.headerId()).append("}");
|
||||
|
||||
buildExpressionFromGivenStructure(packet, struct, 0, builder);
|
||||
packet.setReadIndex(oldReadIndex);
|
||||
@ -205,6 +208,7 @@ public class PacketStringUtils {
|
||||
else if (c == 'b') builder.append("{b:").append(p.readByte()).append('}');
|
||||
else if (c == 'B') builder.append("{b:").append(p.readBoolean()).append('}');
|
||||
else if (c == 'l') builder.append("{l:").append(p.readLong()).append('}');
|
||||
else if (c == 'u') builder.append("{u:").append(p.readShort()).append('}');
|
||||
else return;
|
||||
}
|
||||
}
|
||||
@ -233,16 +237,16 @@ public class PacketStringUtils {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InvalidPacketException {
|
||||
HPacket p1 = fromString("{l}{u:1129}{s:\"\\\\\\\\\"}{i:0}{i:0}");
|
||||
HPacket p1 = fromString("{l}{h:1129}{s:\"\\\\\\\\\"}{i:0}{i:0}");
|
||||
System.out.println(p1.toExpression());
|
||||
HPacket p1_2 = fromString(p1.toExpression());
|
||||
System.out.println(p1_2.toExpression());
|
||||
|
||||
HPacket p2 = fromString("{l}{u:4564}{i:3}{i:0}{s:\"hi\"}{i:0}{i:1}{s:\"how\"}{i:3}{b:1}{b:2}{b:3}{i:2}{s:\"r u\"}{i:1}{b:120}{i:2}{b:true}");
|
||||
HPacket p2 = fromString("{l}{h:4564}{i:3}{i:0}{s:\"hi\"}{i:0}{i:1}{s:\"how\"}{i:3}{b:1}{b:2}{b:3}{i:2}{s:\"r u\"}{i:1}{b:120}{i:2}{b:true}");
|
||||
System.out.println(p2);
|
||||
|
||||
System.out.println(structureEquals(
|
||||
new HPacket("{l}{u:5}{s:\"asdas\"}"),
|
||||
new HPacket("{l}{h:5}{s:\"asdas\"}"),
|
||||
"s"
|
||||
));
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ import java.util.List;
|
||||
|
||||
public class StructurePredictor {
|
||||
|
||||
HPacket packet;
|
||||
String structure; // null if not found/ didnt try to find
|
||||
private HPacket packet;
|
||||
private String structure; // null if not found/ didnt try to find
|
||||
|
||||
public StructurePredictor(HPacket packet) {
|
||||
this.packet = packet;
|
||||
|
@ -33,7 +33,7 @@ public class IntegerChecker extends TypeChecker<Integer> {
|
||||
}
|
||||
|
||||
// 4 bytes that read [0][2]xy could be a string
|
||||
if (ushortTest >= 2 && ushortTest <= 6 && StringChecker.canReadString(hPacket, index)) {
|
||||
if (ushortTest == 2 && StringChecker.canReadString(hPacket, index)) {
|
||||
return (1 - StringChecker.scoreString(hPacket.readString(index)));
|
||||
}
|
||||
|
||||
@ -100,4 +100,17 @@ public class IntegerChecker extends TypeChecker<Integer> {
|
||||
int nextIndexSafe(int index) {
|
||||
return index + 4;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
HPacket packet = new HPacket("{l}{h:901}{b:false}{b:9}{i:0}{i:20064977}");
|
||||
// System.out.println(new IntegerChecker(packet).score(30));
|
||||
// System.out.println(new IntegerChecker(packet).score(26));
|
||||
// System.out.println(new StringChecker(packet).score(30));
|
||||
|
||||
TypeCheckerProducer.UNITY_PACKETS = true;
|
||||
|
||||
System.out.println(new LongChecker(packet).score(8));
|
||||
|
||||
System.out.println(packet.toExpression());
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,13 @@ public class LongChecker extends TypeChecker<Long> {
|
||||
int split1 = hPacket.readInteger(index);
|
||||
int split2 = hPacket.readInteger(index + 4);
|
||||
|
||||
if (split2 > 256 * 256 * 3 && split1 == 0) {
|
||||
return integerChecker.score(index);
|
||||
int zeros = 0;
|
||||
for (int i = index + 4; i < index + 8; i++) {
|
||||
zeros += hPacket.readByte(i) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
if (split2 > 256 * 256 * 3 && split1 == 0 && zeros < 2) {
|
||||
return integerChecker.score(index) * integerChecker.score(index + 4) + 0.0000000001;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -0,0 +1,56 @@
|
||||
package gearth.misc.packetrepresentation.prediction.checkers;
|
||||
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
public class ShortChecker extends TypeChecker {
|
||||
|
||||
private BooleanChecker booleanChecker;
|
||||
private ByteChecker byteChecker;
|
||||
|
||||
protected ShortChecker(HPacket hPacket) {
|
||||
super("u", hPacket);
|
||||
booleanChecker = new BooleanChecker(hPacket);
|
||||
byteChecker = new ByteChecker(hPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(int index) {
|
||||
return index >= 6 && !(index + 2 > hPacket.getBytesLength());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double score(int index) {
|
||||
short val = hPacket.readShort(index);
|
||||
|
||||
if (index == 6 && val == 0 && hPacket.length() == nextIndexSafe(index)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (val <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (val < 1000) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
double leftMinScore;
|
||||
double rightMinScore;
|
||||
if (booleanChecker.canRead(index)) leftMinScore = booleanChecker.score(index);
|
||||
else leftMinScore = byteChecker.score(index);
|
||||
if (booleanChecker.canRead(index+1)) rightMinScore = booleanChecker.score(index+1);
|
||||
else rightMinScore = byteChecker.score(index+1);
|
||||
|
||||
return leftMinScore * rightMinScore + 0.00000001;
|
||||
}
|
||||
|
||||
@Override
|
||||
Object get(int index) {
|
||||
return hPacket.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
int nextIndexSafe(int index) {
|
||||
return index + 2;
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
public class TypeCheckerProducer {
|
||||
|
||||
public static volatile boolean USE_LONG_DATATYPE = false;
|
||||
public static volatile boolean UNITY_PACKETS = false;
|
||||
|
||||
public static List<TypeChecker> getValidators(HPacket packet) {
|
||||
List<TypeChecker> typeCheckers = new ArrayList<>(Arrays.asList(
|
||||
@ -17,8 +17,9 @@ public class TypeCheckerProducer {
|
||||
new IntegerChecker(packet),
|
||||
new StringChecker(packet)));
|
||||
|
||||
if (USE_LONG_DATATYPE) {
|
||||
if (UNITY_PACKETS) {
|
||||
typeCheckers.add(new LongChecker(packet));
|
||||
typeCheckers.add(new ShortChecker(packet));
|
||||
}
|
||||
|
||||
return typeCheckers;
|
||||
|
@ -607,7 +607,7 @@ public class HPacket implements StringifyAble {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
HPacket packet = new HPacket("{l}{u:4564}{i:3}{i:0}{s:\"hi\"}{i:0}{i:1}{s:\"how\"}{i:3}{b:1}{b:2}{b:3}{i:2}{s:\"r u\"}{i:1}{b:120}{i:2}{b:true}{d:1.4}");
|
||||
HPacket packet = new HPacket("{l}{h:4564}{i:3}{i:0}{s:\"hi\"}{i:0}{i:1}{s:\"how\"}{i:3}{b:1}{b:2}{b:3}{i:2}{s:\"r u\"}{i:1}{b:120}{i:2}{b:true}{d:1.4}");
|
||||
|
||||
String str = PacketStringUtils.toExpressionFromGivenStructure(packet, "i(isi(b))iBd");
|
||||
|
||||
|
@ -2,7 +2,6 @@ package gearth.ui.extra;
|
||||
|
||||
import gearth.Main;
|
||||
import gearth.misc.Cacher;
|
||||
import gearth.misc.packetrepresentation.prediction.StructurePredictor;
|
||||
import gearth.misc.packetrepresentation.prediction.checkers.TypeCheckerProducer;
|
||||
import gearth.protocol.HConnection;
|
||||
import gearth.protocol.connection.HState;
|
||||
@ -12,8 +11,6 @@ import gearth.services.gpython.GPythonVersionUtils;
|
||||
import gearth.ui.SubForm;
|
||||
import gearth.ui.info.InfoController;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.InvalidationListener;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
@ -64,10 +61,10 @@ public class ExtraController extends SubForm implements SocksConfiguration {
|
||||
public RadioButton rd_flash;
|
||||
|
||||
public void initialize() {
|
||||
TypeCheckerProducer.USE_LONG_DATATYPE = rd_unity.isSelected();
|
||||
TypeCheckerProducer.UNITY_PACKETS = rd_unity.isSelected();
|
||||
tgl_clientMode.selectedToggleProperty().addListener(observable -> {
|
||||
parentController.connectionController.changeClientMode();
|
||||
TypeCheckerProducer.USE_LONG_DATATYPE = rd_unity.isSelected();
|
||||
TypeCheckerProducer.UNITY_PACKETS = rd_unity.isSelected();
|
||||
});
|
||||
|
||||
url_troubleshooting.setTooltip(new Tooltip("https://github.com/sirjonasxx/G-Earth/wiki/Troubleshooting"));
|
||||
|
@ -136,8 +136,8 @@ public class InjectionController extends SubForm {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
HPacket[] packets = parsePackets("{l}{u:3}{i:967585}{i:9589}{s:\"furni_inscriptionfuckfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\"}{s:\"sirjonasxx-II\"}{s:\"\"}{i:188}{i:0}{i:0}{b:false}");
|
||||
System.out.println(new HPacket("{l}{u:2550}{s:\"ClientPerf\"\"ormance\\\"}\"}{s:\"23\"}{s:\"fps\"}{s:\"Avatars: 1, Objects: 0\"}{i:76970180}").toExpression());
|
||||
HPacket[] packets = parsePackets("{l}{h:3}{i:967585}{i:9589}{s:\"furni_inscriptionfuckfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionfurni_inscriptionsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\"}{s:\"sirjonasxx-II\"}{s:\"\"}{i:188}{i:0}{i:0}{b:false}");
|
||||
System.out.println(new HPacket("{l}{h:2550}{s:\"ClientPerf\"\"ormance\\\"}\"}{s:\"23\"}{s:\"fps\"}{s:\"Avatars: 1, Objects: 0\"}{i:76970180}").toExpression());
|
||||
|
||||
System.out.println("hi");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user