From 71ca5f2952b2d0e4bb3de8f28f36365511da48cf Mon Sep 17 00:00:00 2001 From: Ammar Askar Date: Thu, 6 Sep 2012 15:08:03 +0500 Subject: [PATCH] Fix hexdigest --- Utils.py | 23 ++++++++++++++++------- networking/NetworkManager.py | 5 ++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Utils.py b/Utils.py index 62a60bd..fd33608 100644 --- a/Utils.py +++ b/Utils.py @@ -3,14 +3,15 @@ import array def stringToByteArray(string): return array.array('B', string.decode("hex")) -def TwosCompliment(hash): - hash = array.array('B', hash.decode("hex")) +def TwosCompliment(digest): carry = True - for i in range((hash.__len__() - 1), 0, -1): + for i in range((digest.__len__() - 1), -1, -1): + value = 255 - digest[i] + digest[i] = value if(carry): - carry = hash[i] == 0xFF - hash[i] += 1 - return hash + carry = digest[i] == 0xFF + digest[i] = digest[i] + 1 + return digest def trimStart(string, character): for c in string: @@ -19,4 +20,12 @@ def trimStart(string, character): else: break return string - \ No newline at end of file + +def getHexString(byteArray): + result = "" + for i in range(byteArray.__len__()): + if (byteArray[i] < 0x10): + result += '0' + result += hex(byteArray[i])[2:] + return result + \ No newline at end of file diff --git a/networking/NetworkManager.py b/networking/NetworkManager.py index 44696dd..ee0c650 100644 --- a/networking/NetworkManager.py +++ b/networking/NetworkManager.py @@ -94,7 +94,6 @@ class ServerConnection(threading.Thread): try: #Open up the url with the appropriate get parameters url = "http://session.minecraft.net/game/joinserver.jsp?user=" + self.username + "&sessionId=" + self.sessionID + "&serverId=" + serverid - print url response = urllib2.urlopen(url).read() if(response != "OK"): @@ -306,7 +305,7 @@ class PacketListener(threading.Thread): elif(response == "\x67"): PacketListenerManager.handle67(self.FileObject) elif(response == "\x68"): - print PacketListenerManager.handle68(self.FileObject) + PacketListenerManager.handle68(self.FileObject) elif(response == "\x69"): PacketListenerManager.handle69(self.FileObject) elif(response == "\x6A"): @@ -322,7 +321,7 @@ class PacketListener(threading.Thread): elif(response == "\xC8"): PacketListenerManager.handleC8(self.FileObject) elif(response == "\xC9"): - print PacketListenerManager.handleC9(self.FileObject) + PacketListenerManager.handleC9(self.FileObject) elif(response == "\xCA"): PacketListenerManager.handleCA(self.FileObject) elif(response == "\xCB"):