diff --git a/classes/MinecraftInterface.class.php b/classes/MinecraftInterface.class.php index 2fcac65c..09509cbd 100644 --- a/classes/MinecraftInterface.class.php +++ b/classes/MinecraftInterface.class.php @@ -52,7 +52,7 @@ class MinecraftInterface{ protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){ if(LOG === true and DEBUG >= 2){ $p = "[".microtime(true)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".$this->name[$pid]." (0x".Utils::strTohex(chr($pid)).") [lenght ".strlen($raw)."]".PHP_EOL; - $p .= hexdump($raw, false, false, true); + $p .= Utils::hexdump($raw); if(is_array($data)){ foreach($data as $i => $d){ $p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special" or is_int($this->pstruct[$pid][$i])) ? Utils::strToHex($d):$d).")":$this->pstruct[$pid][$i]."(***)").PHP_EOL; @@ -80,7 +80,7 @@ class MinecraftInterface{ $struct = $this->getStruct($pid); if($struct === false){ $p = "[".microtime(true)."] [SERVER->CLIENT]: Error, bad packet id 0x".Utils::strToHex(chr($pid)).PHP_EOL; - $p .= hexdump($data[0], false, false, true); + $p .= Utils::hexdump($data[0]); $p .= PHP_EOL; logg($p, "packets", true, 2); diff --git a/classes/Packet.class.php b/classes/Packet.class.php index 6010d41c..f0bdeb55 100644 --- a/classes/Packet.class.php +++ b/classes/Packet.class.php @@ -36,7 +36,7 @@ class Packet{ $this->offset = 1; $this->raw = $data; $this->data = array(); - if($pid !== false){ + if($data === ""){ $this->addRaw(chr($pid)); } $this->struct = $struct; @@ -61,6 +61,7 @@ class Packet{ switch($this->pid){ case 0x05: case 0x84: + case 0x8c: $this->addRaw($this->data[$field]); break; } @@ -140,6 +141,7 @@ class Packet{ switch($this->pid){ case 0x05: case 0x84: + case 0x8c: $this->data[] = $this->get(true); break; } diff --git a/classes/PocketMinecraftClient.class.php b/classes/PocketMinecraftClient.class.php index e8ad4e8e..b5bea7be 100644 --- a/classes/PocketMinecraftClient.class.php +++ b/classes/PocketMinecraftClient.class.php @@ -26,10 +26,11 @@ the Free Software Foundation, either version 3 of the License, or */ class PocketMinecraftClient{ - protected $interface, $protocol, $entities, $player, $cnt, $events, $username, $version, $clientID, $connected, $serverID; + protected $interface, $protocol, $entities, $player, $cnt, $events, $username, $version, $clientID, $connected, $serverID, $start; var $serverList = array(); function __construct($username, $protocol = CURRENT_PROTOCOL, $version = CURRENT_VERSION){ //$this->player = new Player($username); + $this->start = microtime(true); $this->version = (int) $version; $this->username = $username; $this->connected = false; @@ -77,7 +78,7 @@ class PocketMinecraftClient{ } public function getServerList(){ - $this->action(1000000, '$this->send(0x02, array((microtime(true) * 1000)));'); + $this->action(1000000, '$this->send(0x02, array(((microtime(true) - $this->start) * 1000)));'); $this->action(5000000, '$this->actions = array();$this->stop = true;'); $this->process(); $list = array(); @@ -111,7 +112,8 @@ class PocketMinecraftClient{ case 0x08: $serverID = $data[1]; $this->send(0x84, array( - "\x00\x00\x00\x40\x00\x90\x00\x00\x00\x09".$this->serverID.Utils::writeDouble(microtime(true) * 1000).chr(0x00), + 0, + "\x00\x00\x40\x00\x90\x00\x00\x00\x09".$this->serverID.Utils::writeDouble((microtime(true) - $this->start) * 1000).chr(0x00), /*"\x00\x00\x00\x40\x00\x90\x00\x00\x00\x09", $this->serverID, (microtime(true) * 1000), diff --git a/classes/Utils.class.php b/classes/Utils.class.php index 7c042863..73a96b8d 100644 --- a/classes/Utils.class.php +++ b/classes/Utils.class.php @@ -131,6 +131,17 @@ class Utils{ return ($negative === true ? "-":"").str_replace("x", "", $hash); } + + public static function hexdump($bin){ + $output = ""; + $bin = str_split($bin, 16); + foreach($bin as $counter => $line){ + $hex = chunk_split(chunk_split(str_pad(bin2hex($line), 32, " ", STR_PAD_RIGHT), 2, " "), 24, " "); + $ascii = preg_replace('#([^\x20-\x7E])#', '.', $line); + $output .= str_pad(dechex($counter << 4), 4, "0", STR_PAD_LEFT). " " . $hex . " " . $ascii . PHP_EOL; + } + return $output; + } public static function microtime(){ return microtime(true); diff --git a/common/functions.php b/common/functions.php index 314c5bf6..1d08c7b5 100644 --- a/common/functions.php +++ b/common/functions.php @@ -111,70 +111,4 @@ function logg($message, $name, $EOL = true, $level = 2, $close = false){ unset($fpointers[$name]); } } -} - -function hexdump($data, $htmloutput = true, $uppercase = false, $return = false) -{ - // Init - $hexi = ''; - $ascii = ''; - $dump = ($htmloutput === true) ? '
' : '';
- $offset = 0;
- $len = strlen($data);
-
- // Upper or lower case hexadecimal
- $x = ($uppercase === false) ? 'x' : 'X';
-
- // Iterate string
- for ($i = $j = 0; $i < $len; $i++)
- {
- // Convert to hexidecimal
- $hexi .= Utils::strToHex($data[$i]);
-
- // Replace non-viewable bytes with '.'
- if (ord($data[$i]) >= 0x20 and ord($data[$i]) < 0x80) {
- $ascii .= ($htmloutput === true) ?
- htmlentities($data[$i]) :
- $data[$i];
- } else {
- $ascii .= '.';
- }
-
- // Add extra column spacing
- if ($j === 7) {
- $hexi .= ' ';
- $ascii .= ' ';
- }
-
- // Add row
- if (++$j === 16 || $i === $len - 1) {
- // Join the hexi / ascii output
- $dump .= sprintf("%04$x %-49s %s", $offset, $hexi, $ascii);
-
- // Reset vars
- $hexi = $ascii = '';
- $offset += 16;
- $j = 0;
-
- // Add newline
- if ($i !== $len - 1) {
- $dump .= "\n";
- }
- }
- }
-
- // Finish dump
- $dump .= $htmloutput === true ?
- '' :
- '';
- $dump .= "\n";
-
- $dump = preg_replace("/[^[:print:]\\r\\n]/", ".", $dump);
-
- // Output method
- if ($return === false) {
- echo $dump;
- } else {
- return $dump;
- }
}
\ No newline at end of file
diff --git a/pstruct/RakNet.php b/pstruct/RakNet.php
index 11d2cfc2..5b463e91 100644
--- a/pstruct/RakNet.php
+++ b/pstruct/RakNet.php
@@ -81,6 +81,7 @@ $pstruct = array(
),
0x84 => array(
+ "ubyte",
"special1",
/*10,
8,
@@ -88,6 +89,11 @@ $pstruct = array(
"byte", */
),
+ 0x8c => array(
+ "ubyte",
+ "special1",
+ ),
+
0xc0 => array(
6,
),
diff --git a/pstruct/packetName.php b/pstruct/packetName.php
index 33720197..50d0f8ad 100644
--- a/pstruct/packetName.php
+++ b/pstruct/packetName.php
@@ -35,5 +35,6 @@ $packetName = array(
0x1c => "ID_UNCONNECTED_PONG", //RakNet
0x1d => "ID_ADVERTISE_SYSTEM", //RakNet
0x84 => "ID_RESERVED_7", //Minecraft Implementation
+ 0x8c => "Unknown", //Minecraft Implementation
0xc0 => "Unknown", //Minecraft Implementation
);
\ No newline at end of file