From d9c39ca81618ee9117ca6a91a8407eb81dda298a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Tue, 18 Dec 2012 18:55:33 +0100 Subject: [PATCH] Added integrity test --- classes/API/ServerAPI.php | 39 +++++++++++++++++++++++++++++++++++++-- classes/Utils.class.php | 9 --------- common/config.php | 3 ++- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/classes/API/ServerAPI.php b/classes/API/ServerAPI.php index f6520ae49..bc2354877 100644 --- a/classes/API/ServerAPI.php +++ b/classes/API/ServerAPI.php @@ -30,8 +30,43 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run private $config, $apiList = array(); function __construct(){ console("[INFO] Starting ServerAPI server handler..."); - file_put_contents("packets.log", ""); - file_put_contents("console.in", ""); + file_put_contents(FILE_PATH."packets.log", ""); + file_put_contents(FILE_PATH."console.in", ""); + if(!file_exists(FILE_PATH."test.bin.log") or md5_file(FILE_PATH."test.bin.log") !== TEST_MD5){ + console("[NOTICE] Executing integrity tests..."); + console("[INFO] OS: ".PHP_OS.", ".Utils::getOS()); + console("[INFO] uname -a: ".php_uname("a")); + console("[INFO] PHP Version: ".phpversion()); + console("[INFO] Endianness: ".ENDIANNESS); + $test = b""; + $test .= Utils::writeLong("5567381823242127440"); + $test .= Utils::writeLong("2338608908624488819"); + $test .= Utils::writeLong("2333181766244987936"); + $test .= Utils::writeLong("2334669371112169504"); + $test .= Utils::writeShort(Utils::readShort("\xff\xff\xff\xff")); + $test .= Utils::writeShort(Utils::readShort("\xef\xff\xff\xff")); + $test .= Utils::writeInt(Utils::readInt("\xff\xff\xff\xff")); + $test .= Utils::writeInt(1); + $test .= Utils::writeInt(-1); + $test .= Utils::writeFloat(Utils::readfloat("\xff\xff\xff\xff")); + $test .= Utils::writeFloat(-1.584563155838E+29); + $test .= Utils::writeFloat(1); + $test .= Utils::writeLDouble(Utils::readLDouble("\xff\xff\xff\xff\xff\xff\xff\xff")); + $test .= Utils::writeLong("-1152921504606846977"); + $test .= Utils::writeLong("-1152921504606846976"); + $test .= Utils::writeTriad(16777215); + $test .= Utils::writeTriad(16777216); + $str = new Java_String("THIS_IS_ a TEsT_SEED1_123456789^.,.,\xff\x00\x15"); + $test .= Utils::writeLong($str->hashCode()); + $test .= Utils::writeDataArray(array("a", "b", "c", "\xff\xff\xff\xff")); + $test .= Utils::hexToStr("012334567890"); + file_put_contents(FILE_PATH."test.bin.log", $test); + if(md5($test) !== TEST_MD5){ + console("[ERROR] Test error, please send your console.log + test.bin.log to the Github repo"); + die(); + } + } + if(!file_exists(FILE_PATH."white-list.txt")){ console("[NOTICE] No white-list.txt found, creating blank file"); file_put_contents(FILE_PATH."white-list.txt", ""); diff --git a/classes/Utils.class.php b/classes/Utils.class.php index eafe8b4c2..acd2b91d7 100644 --- a/classes/Utils.class.php +++ b/classes/Utils.class.php @@ -37,15 +37,6 @@ define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE class Utils{ - /*public static function hashCode($str){ - $h = 0; - $len = strlen($str); - for($i = 0; $i < $len; ++$i) { - $h = 31 * $h + $str[$i]; - } - return $h; - }*/ - public static function getOS(){ $uname = strtoupper(php_uname("s")); if(strpos($uname, "WIN") !== false){ diff --git a/common/config.php b/common/config.php index 054e1db3d..07d64ce66 100644 --- a/common/config.php +++ b/common/config.php @@ -37,4 +37,5 @@ ini_set("memory_limit", "1024M"); define("CURRENT_PROTOCOL", 5); define("CURRENT_VERSION", 1); define("LOG", true); -define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"); \ No newline at end of file +define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"); +define("TEST_MD5", "5ca8eced50a5801619f7ae86d631a4e7"); \ No newline at end of file