From fc63676bde3c3a6482f698f3ce1bdba92409a024 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Thu, 6 Dec 2012 01:21:39 +0100 Subject: [PATCH] Fixes, structure --- classes/CustomPacketHandler.class.php | 65 ++++++++++++------------- classes/PocketMinecraftClient.class.php | 2 +- classes/Session.class.php | 4 +- classes/Utils.class.php | 2 +- pstruct/dataName.php | 1 + 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/classes/CustomPacketHandler.class.php b/classes/CustomPacketHandler.class.php index c557b6f0e..5bf8e7bd0 100644 --- a/classes/CustomPacketHandler.class.php +++ b/classes/CustomPacketHandler.class.php @@ -49,36 +49,40 @@ class CustomPacketHandler{ $this->offset = 0; $this->c = (bool) $create; switch($pid){ + case 0x00: + if($this->c === false){ + $this->data["payload"] = Utils::readLong($this->get(8)); + }else{ + $this->raw .= Utils::writeLong($this->data["payload"]); + } + break; case 0x09: if($this->c === false){ $this->data["clientID"] = $this->get(8); - $this->data["unknown1"] = $this->get(4); - $this->data["session"] = $this->get(2); - $this->data["unknown2"] = $this->get(2); + $this->data["session"] = Utils::readLong($this->get(8)); + $this->data["unknown2"] = $this->get(1); }else{ $this->raw .= $this->data["clientID"]; - $this->raw .= "\x00\x00\x00\x00\x00"; - $this->raw .= $this->data["session"]; - $this->raw .= "\x19\x00"; + $this->raw .= Utils::writeLong($this->data["session"]); + $this->raw .= "\x00"; } break; case 0x10: if($this->c === false){ - $this->data["cookie"] = $this->get(4); // 043f57ff - $this->data["unknown1"] = $this->get(1); + $this->data["cookie"] = $this->get(4); // 043f57fe + $this->data["security"] = $this->get(1); $this->data["port"] = Utils::readShort($this->get(2), false); $this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 10, $offset); $this->get($offset); - $this->data["unknown2"] = $this->get(8); - $this->data["unknown3"] = $this->get(2); - $this->data["unknown4"] = $this->get(5); - $this->data["session"] = $this->get(2); + $this->data["unknown1"] = $this->get(2); + $this->data["session"] = Utils::readLong($this->get(8)); + $this->data["session2"] = Utils::readLong($this->get(8)); }else{ - $this->raw .= "\x04\x3f\x57\xff"; - $this->raw .= "\x3f"; + $this->raw .= "\x04\x3f\x57\xfe"; + $this->raw .= "\xcd"; $this->raw .= Utils::writeShort($this->data["port"]); $this->raw .= Utils::writeDataArray(array( - "\x80\xff\xff\xfe", + "\xff\xff\xff\xff", "\xff\xff\xff\xff", "\xff\xff\xff\xff", "\xff\xff\xff\xff", @@ -89,30 +93,32 @@ class CustomPacketHandler{ "\xff\xff\xff\xff", "\xff\xff\xff\xff", )); - $this->raw .= "\x00\x00\x00\x00\x00\x00\x00\x00"; - $this->raw .= "\x0c\x98"; - $this->raw .= "\x00\x00\x00\x00\x00\x00\x00\x00"; - $this->raw .= $this->data["session"]; + $this->raw .= "\x00\x00"; + $this->raw .= Utils::writeLong($this->data["session"]); + $this->raw .= Utils::writeLong($this->data["session2"]); } break; case 0x13: if($this->c === false){ - $this->data["cookie"] = $this->get(4); // 043f57ff - $this->data["unknown1"] = $this->get(1); + $this->data["cookie"] = $this->get(4); // 043f57fe + $this->data["security"] = $this->get(1); $this->data["port"] = Utils::readShort($this->get(2), false); $this->data["dataArray0"] = $this->get(ord($this->get(1))); $this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 9, $offset); $this->get($offset); - $this->data["unknown2"] = $this->get(13); + $this->data["unknown1"] = $this->get(2); + $this->data["session2"] = Utils::readLong($this->get(8)); + $this->data["session"] = Utils::readLong($this->get(8)); }else{ - $this->raw .= "\x04\x3f\x57\xff"; - $this->raw .= "\x3e"; + $this->raw .= "\x04\x3f\x57\xfe"; + $this->raw .= "\xed"; $this->raw .= Utils::writeShort($this->data["port"]); $w = array_shift($this->data["dataArray"]); $this->raw .= chr(strlen($w)).$w; $this->raw .= Utils::writeDataArray($this->data["dataArray"]); - $this->raw .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; - $this->raw .= $this->data["session"]."\x5e"; + $this->raw .= "\x00\x00"; + $this->raw .= Utils::writeLong($this->data["session2"]); + $this->raw .= Utils::writeLong($this->data["session"]); } break; case 0x15: @@ -175,13 +181,6 @@ class CustomPacketHandler{ $this->raw .= Utils::writeShort(strlen($this->data["message"])).$this->data["message"]; } break; - case 0x00: - if($this->c === false){ - $this->data["payload"] = $this->get(8); - }else{ - $this->raw .= $this->data["payload"]; - } - break; } } diff --git a/classes/PocketMinecraftClient.class.php b/classes/PocketMinecraftClient.class.php index 817b3bb76..c79778619 100644 --- a/classes/PocketMinecraftClient.class.php +++ b/classes/PocketMinecraftClient.class.php @@ -118,7 +118,7 @@ class PocketMinecraftClient{ array( "id" => 0x09, "clientID" => $this->clientID, - "session" => Utils::getRandomBytes(2), + "session" => "\x00\x00\x00\x00\x03\x1c\xaf\x05", ), )); ++$this->counter[0]; diff --git a/classes/Session.class.php b/classes/Session.class.php index 57391c986..dbb61e129 100644 --- a/classes/Session.class.php +++ b/classes/Session.class.php @@ -91,9 +91,9 @@ class Session{ 0x00, array( "id" => 0x10, - "count" => 0, "port" => $this->port, - "session" => $data[2]["session"], + "session" => $data["session"], + "session2" => Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9"), ), )); ++$this->counter[0]; diff --git a/classes/Utils.class.php b/classes/Utils.class.php index 0ee76a074..8628b6c97 100644 --- a/classes/Utils.class.php +++ b/classes/Utils.class.php @@ -337,7 +337,7 @@ class Utils{ public static function writeLong($value){ $long = new Math_BigInteger($value, -10); - return $long->toBytes(true); + return str_pad($long->toBytes(true), 8, "\x00", STR_PAD_LEFT); } } \ No newline at end of file diff --git a/pstruct/dataName.php b/pstruct/dataName.php index d268b8254..4de02adb1 100644 --- a/pstruct/dataName.php +++ b/pstruct/dataName.php @@ -30,6 +30,7 @@ $dataName = array( 0x09 => "ClientHandshake", 0x10 => "ServerHandshake", 0x13 => "ClientConnect", + 0x15 => "ClientDisconnect", 0x82 => "Login", 0x83 => "LoginStatus",