(self, endian: QL_ENDIAN, bit: int)
| 20 | # Don't assume self is Qiling. |
| 21 | class QlCoreStructs: |
| 22 | def __init__(self, endian: QL_ENDIAN, bit: int): |
| 23 | modifier = { |
| 24 | QL_ENDIAN.EL: '<', |
| 25 | QL_ENDIAN.EB: '>' |
| 26 | }[endian] |
| 27 | |
| 28 | self._fmt8 = struct.Struct(f'{modifier}B') |
| 29 | self._fmt8s = struct.Struct(f'{modifier}b') |
| 30 | self._fmt16 = struct.Struct(f'{modifier}H') |
| 31 | self._fmt16s = struct.Struct(f'{modifier}h') |
| 32 | self._fmt32 = struct.Struct(f'{modifier}I') |
| 33 | self._fmt32s = struct.Struct(f'{modifier}i') |
| 34 | self._fmt64 = struct.Struct(f'{modifier}Q') |
| 35 | self._fmt64s = struct.Struct(f'{modifier}q') |
| 36 | |
| 37 | handlers = { |
| 38 | 64 : (self.pack64, self.pack64s, self.unpack64, self.unpack64s), |
| 39 | 32 : (self.pack32, self.pack32s, self.unpack32, self.unpack32s), |
| 40 | 16 : (self.pack16, self.pack16s, self.unpack16, self.unpack16s), |
| 41 | } |
| 42 | |
| 43 | if bit not in handlers: |
| 44 | raise QlErrorStructConversion("Unsupported Qiling struct conversion") |
| 45 | |
| 46 | p, ps, up, ups = handlers[bit] |
| 47 | |
| 48 | self.pack = p |
| 49 | self.packs = ps |
| 50 | self.unpack = up |
| 51 | self.unpacks = ups |
| 52 | |
| 53 | def pack64(self, x: int, /) -> bytes: |
| 54 | return self._fmt64.pack(x) |
nothing calls this directly
no test coverage detected