• Welcome to Valhalla Legends Archive.
 

[Python] MakeDWORD

Started by Yegg, December 05, 2004, 05:52 PM

Previous topic - Next topic

Yegg

Ok, I am currently trying to make a bot in Python and I've actually gotten quite a lot added to it. My main problem is that when I come to adding the parts that a normal battle.net packetbuffer would have, I can't add MakeDWORD. As far as I know the way Visual Basic 6 does MakeDWORD cannot be converted into Python. I tried getting help on this topic at forums.devshed.com, only no one there is good with battle.net and the only help someone could give me was to come here (which I've been here many times before). Does anyone know how to make a working MakeDWORD code in Python?

BaDDBLooD

#1
Try asking how to convert a 32 bit integer into a string.
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Banana fanna fo fanna

Actually, you almost have a complete packet buffer included with Python: the struct module. Please see here:

http://docs.python.org/lib/module-struct.html

That should do most of the work for you for a packet buffer, but I'll also provide your makedword function in case that would be easier/better for you:


import struct

def make_dword(n):
    "convert a number to an unsigned double word"
    return struct.pack("< I", n)

def get_dword(buf):
    "get the first dword in the buffer"
    return struct.unpack("< I", buf[:4])[0]


EDIT: spaced out the code to make it more readable

Yegg

Lol. After Baddblood posted and i went back down to the other forums, the admin there also told me about struct, he obviously gave a different example but they are both the same things. Since you seem to know about it, will the following code work:
    def MakeDWORD(value):
        MakeDWORD = MakeDWORD()
        return struct.pack(result, value, 4)


Result being the string and value being long, as it is said in Visual Basic. As for the 4, I'm not sure if the 4 is needed, because in VB6 MakeDWORD has an interger of 4, and MakeWORD has an integer of 2, because of this I'm assuming those intergers will be needed?  I just have no clue how to place the interger if it is needed. Post back whenever you can.

Banana fanna fo fanna

Ew, that code is horrible....it absolutely will not work at all.

What's wrong with the code I posted? It outta work. What are you trying to do?

Banana fanna fo fanna

Quote from: Yegg
I just had a quick question about this. Where you have the code,
def make_dword(n):
    "convert a number to an unsigned double word"
    return struct.pack("< I", n)


I'm a little confused on what the <, the I and the n do. Can you just clarify what each of these are, because in VB6 there is an interger, string, and long. I wan't to understand your code so I can use it later on without having to ask questions. Thanks.

The "n" is the argument you passed to the function.

Read the module docs! They'll tell you that:
- < means little-endian byte order
- I means an unsigned, double word (dword)

Yegg

#6
Sorry to bring this topic back up, but, if MakeDWORD uses I for long, then would this mean that MakeWORD uses H? Or do I only need MakeDWORD and not MakeWORD? Also, for GetDWORD, is the argument for that buf,

Banana fanna fo fanna

MakeWORD would use H, yes.