You are not logged in.
I'm trying to get data out of a game file (ITM/Baldurs Gate http://iesdp.gibberlings3.net/ieformats/itm_v1.htm). Some of variables can't be read directly (like dword) (won't show the data it should).
A java based NearInfinity converts binary dword data in this way:
public static int convertInt(byte buffer[], int offset)
{
int value = 0;
for (int i = 3; i >= 0; i--)
value = (value << 8) | (buffer[offset + i] & 0xFF);
return value;
}
Now, how Python code would look like? I've checked binascii module with no luck.
Offline
Use the 'b' flag when opening your file.
myFile = open("something.dat", "rb")
data = myFile.read()
Now you can iterate over each byte and do whatever you want.
Offline
I have
plik = open('bow08.itm', 'rb')
try:
tekst = plik.read()
finally:
plik.close()
# char array - works
print tekst[0x0004:0x0004+4]
# resref - works
print tekst[0x003a:0x003a+8]
#dword
print tekst[0x004c:0x004c+4]
and the dword (and few other variables) won't show anything (will output binary something), the java snippet in my first post from NearInfinity converts that binary code into a normal data
Offline
You need to use the 'int()' function to convert the character string to an integer.
Offline
it isn't a string, it's something binary ValueError: invalid literal for int():
Offline
Sorry for my hasty (and wrong) reply! I think you want to look at the 'unpack' function in the 'struct' module.
Offline