MCPcopy
hub / github.com/kovidgoyal/kitty / get_binary_arch

Function get_binary_arch

setup.py:415–430  ·  view source on GitHub ↗
(path: str)

Source from the content-addressed store, hash-verified

413
414
415def get_binary_arch(path: str) -> BinaryArch:
416 with open(path, 'rb') as f:
417 sig = f.read(64)
418 if sig.startswith(b'\x7fELF'): # ELF
419 bits = {1: 32, 2: 64}[sig[4]]
420 endian = {1: '<', 2: '>'}[sig[5]]
421 machine, = struct.unpack_from(endian + 'H', sig, 0x12)
422 isa = {i.value:i for i in ISA}.get(machine, ISA.Other)
423 elif sig[:4] in (b'\xcf\xfa\xed\xfe', b'\xce\xfa\xed\xfe'): # Mach-O
424 s, cpu_type, = struct.unpack_from('<II', sig, 0)
425 bits = {0xfeedface: 32, 0xfeedfacf: 64}[s]
426 cpu_type &= 0xff
427 isa = {0x7: ISA.AMD64, 0xc: ISA.ARM64}[cpu_type]
428 else:
429 raise SystemExit(f'Unknown binary format with signature: {sig[:4]!r}')
430 return BinaryArch(bits=bits, isa=isa)
431
432
433def test_compile(

Callers 1

test_compileFunction · 0.85

Calls 3

BinaryArchClass · 0.90
readMethod · 0.45
getMethod · 0.45

Tested by 1

test_compileFunction · 0.68