This code sucks, much more elegant if the code is geared towards a purpose, ie parsing incoming data;
import struct
def unpack_dword(data):
return struct.unpack('I', data)[0]
def unpack_word(data):
return struct.unpack('H', data)[0]
def unpack_byte(data):
return struct.unpack('<B', data)[0]
class recv_buffer:
def __init__(self, raw_buffer):
self.raw_buffer = raw_buffer
self.position = 0
def jump(self, bytes):
self.position += bytes
def back(self, bytes):
self.position -= bytes
def set_position(self, position):
self.position = position
def next_string(self):
pos = self.raw_buffer.find(chr(0), self.position)
string = self.raw_buffer[self.position:pos]
self.set_position(pos + 1)
return string
def next_byte(self):
param = self.raw_buffer[self.position:self.position + 1]
byte = unpack_byte(param)
self.jump(1)
return byte
def next_dword(self):
param = self.raw_buffer[self.position:self.position + 4]
dword = unpack_dword(param)
self.jump(4)
return dword
def next_word(self):
param = self.raw_buffer[self.position:self.position + 2]
word = unpack_word(param)
self.jump(2)
return word
def next_dword_list(self, size):
dword_list = []
for i in xrange(size):
dword_list.append(self.next_dword())
return dword_list
def next_data(self, bytes):
return self.raw_buffer[self.position: self.position + bytes]
def dump_data(self):
self.raw_buffer = ""
Much shorter, too, unlike the code from a good year ago
I'd be interested in seeing a bot written in Python. I've never used the language - does it have a nice API including networking stuff as well, or is it more like Brainfuck where you have nothing at all?
Python is very easy to learn (I've seen users dub it "visual basic 2", or some other clever nick). The stdlib is huge, much like Java's. There is a significant amount of networking modules built-in.
The bot has been available for some
time. I ran into some phantom bugs while I was working on it, but it has enough done that it should be easily completed. In fact, some leech even thought it complete enough to use and plaster his name on it without giving
credit.