/
test_arm_firmware.py
43 lines (33 loc) · 1.28 KB
/
test_arm_firmware.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import cle
import pyvex
import struct
from nose.tools import assert_equal
test_location = str(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'binaries', 'tests'))
def test_empty_segements():
"""
Test for bizarre ELves #1: Energy Micro's compiler makes empty segments
:return:
"""
path = os.path.join(test_location, "armel", "efm32gg.elf")
cle.Loader(path, rebase_granularity=0x1000)
# If we survive this, we're doing OK!
def test_thumb_object():
"""
Test for an object file I ripped out of an ARM firmware HAL.
Uses some nasty relocs
:return:
"""
path = os.path.join(test_location, "armel", "i2c_api.o")
l = cle.Loader(path, rebase_granularity=0x1000)
for r in l.main_object.relocs:
if r.__class__ == cle.backends.elf.relocation.arm.R_ARM_THM_JUMP24:
if r.symbol.name == 'HAL_I2C_ER_IRQHandler':
irsb = pyvex.lift(struct.pack('<I', r.value), r.rebased_addr + 1, l.main_object.arch, bytes_offset=1)
assert_equal(irsb.default_exit_target, r.resolvedby.rebased_addr)
break
else:
assert False, "Could not find JUMP24 relocation for HAL_I2C_ER_IRQHandler"
if __name__ == "__main__":
test_thumb_object()
test_empty_segements()