def __init__(self, raw_buff): self.reset() self.buff = bytecode.BuffHandle(raw_buff) self.buff.read(4) self.buff.read(4) self.sb = StringBlock(self.buff) self.m_resourceIDs = [] self.m_prefixuri = {} self.m_uriprefix = {} self.m_prefixuriL = []
def testArscHeader(self): """Test if wrong arsc headers are rejected""" with self.assertRaises(AssertionError) as cnx: axml.ARSCHeader(bytecode.BuffHandle(b"\x02\x01")) self.assertTrue( "Can not read over the buffer size" in str(cnx.exception)) with self.assertRaises(AssertionError) as cnx: axml.ARSCHeader( bytecode.BuffHandle(b"\x02\x01\xFF\xFF\x08\x00\x00\x00")) self.assertTrue("smaller than header size" in str(cnx.exception)) with self.assertRaises(AssertionError) as cnx: axml.ARSCHeader( bytecode.BuffHandle(b"\x02\x01\x01\x00\x08\x00\x00\x00")) self.assertTrue("declared header size is smaller than required size" in str(cnx.exception)) with self.assertRaises(AssertionError) as cnx: axml.ARSCHeader( bytecode.BuffHandle(b"\x02\x01\x08\x00\x04\x00\x00\x00")) self.assertTrue("declared chunk size is smaller than required size" in str(cnx.exception)) a = axml.ARSCHeader( bytecode.BuffHandle(b"\xCA\xFE\x08\x00\x10\x00\x00\x00" b"\xDE\xEA\xBE\xEF\x42\x42\x42\x42")) self.assertEqual(a.type, 0xFECA) self.assertEqual(a.header_size, 8) self.assertEqual(a.size, 16) self.assertEqual(a.start, 0) self.assertEqual(a.end, 16) self.assertEqual( repr(a), "<ARSCHeader idx='0x00000000' type='65226' header_size='8' size='16'>" )