Part.met file

From AMule Project FAQ
Jump to: navigation, search

Detailed format

Simple and uncomplete parsing script:

#!/usr/bin/python
import sys;
import struct;

def printTag(fichero):
	(type,)=struct.unpack('B',fichero.read(1));
	(lenname,)=struct.unpack('H',fichero.read(2));
	name="";
	if (lenname == 1):
		name = "0x%02X" % (struct.unpack('B',fichero.read(1)));
	elif (lenname == 2):
		name = "0x%02X%02X" % (struct.unpack('2B',fichero.read(2)));
	else:
	 	name = fichero.read(lenname+0);
	print "%u\"%s\";" % (lenname,name),
	if (type == 0x00):
		print "0x00 ????: ",name,
	elif (type == 0x01):
		print "0x01 HASH"
	elif (type == 0x02):
		print "0x02 String:",
		(strlen,) = struct.unpack('H',fichero.read(2));
		str = fichero.read(strlen);
		print "%u\"%s\"" % (strlen,str);
	elif (type == 0x03):
		print "0x03 DWORD: %u" % struct.unpack('I',fichero.read(4))[0]
	elif (type == 0x04):
		print "0x04 FLOAT"
	elif (type == 0x05):
		print "0x05 BOOL"
	elif (type == 0x06):
		print "0x06 BOOLARRAY"
	elif (type == 0x07):
		print "0x07 BLOOB"
	else:
		print "0x%02X !!!!" % type

fichero = open(sys.argv[1],"r");

(leido,) = struct.unpack('B',fichero.read(1));
print "Header: %02X" % (leido)
(leido,) = struct.unpack('I',fichero.read(4));
print "Fecha: %d" % leido
leido = fichero.read(16)
print "Hash: ",
#for i in range(16):
sys.stdout.write("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n" % (struct.unpack('16B',leido)));
(leido,) = struct.unpack('H',fichero.read(2));
print "Hash parciales: %u" % leido
for i in range(leido):
	print "\t[%u]:" % i,
	print "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X" % (struct.unpack('16B',fichero.read(16)));
(leido,) = struct.unpack('I',fichero.read(4));
print "Etiquetas: %u" % leido
for i in range(leido):
	print "\t[%u]:" % i,
	printTag(fichero)