forked from eliben/pyelftools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added license snippet to all files in the code. Whitespace cleanup.
- Loading branch information
Showing
10 changed files
with
79 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#------------------------------------------------------------------------------- | ||
# elftools | ||
# | ||
# Eli Bendersky ([email protected]) | ||
# This code is in the public domain | ||
#------------------------------------------------------------------------------- | ||
__version__ = '0.21' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#------------------------------------------------------------------------------- | ||
# elftools tests | ||
# | ||
# Eli Bendersky ([email protected]) | ||
# This code is in the public domain | ||
#------------------------------------------------------------------------------- | ||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#------------------------------------------------------------------------------- | ||
# elftools tests | ||
# | ||
# Eli Bendersky ([email protected]) | ||
# This code is in the public domain | ||
#------------------------------------------------------------------------------- | ||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
|
@@ -19,7 +25,7 @@ def assertInstruction(self, instr, name, args): | |
self.assertIsInstance(instr, CallFrameInstruction) | ||
self.assertEqual(instruction_name(instr.opcode), name) | ||
self.assertEqual(instr.args, args) | ||
|
||
def test_spec_sample_d6(self): | ||
# D.6 sample in DWARFv3 | ||
s = BytesIO() | ||
|
@@ -40,7 +46,7 @@ def test_spec_sample_d6(self): | |
b'\x08\x07' + | ||
b'\x09\x08\x01' + | ||
b'\x00' + | ||
|
||
# then comes the FDE | ||
b'\x28\x00\x00\x00' + # length | ||
b'\x00\x00\x00\x00' + # CIE_pointer (to CIE at 0) | ||
|
@@ -125,7 +131,7 @@ def test_spec_sample_d6(self): | |
self.assertEqual(decoded_FDE.table[9]['pc'], 0x11223344 + 76) | ||
|
||
def test_describe_CFI_instructions(self): | ||
# The data here represents a single CIE | ||
# The data here represents a single CIE | ||
data = (b'' + | ||
b'\x16\x00\x00\x00' + # length | ||
b'\xff\xff\xff\xff' + # CIE_id | ||
|
@@ -141,7 +147,7 @@ def test_describe_CFI_instructions(self): | |
|
||
set_global_machine_arch('x86') | ||
self.assertEqual(describe_CFI_instructions(entries[0]), | ||
( ' DW_CFA_def_cfa: r7 (edi) ofs 2\n' + | ||
( ' DW_CFA_def_cfa: r7 (edi) ofs 2\n' + | ||
' DW_CFA_expression: r2 (edx) (DW_OP_addr: 201; DW_OP_deref; DW_OP_deref)\n')) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#------------------------------------------------------------------------------- | ||
# elftools tests | ||
# | ||
# Eli Bendersky ([email protected]) | ||
# This code is in the public domain | ||
#------------------------------------------------------------------------------- | ||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
|
@@ -23,12 +29,12 @@ def test_basic_single(self): | |
self.visitor.process_expr([0x1b]) | ||
self.assertEqual(self.visitor.get_str(), | ||
'DW_OP_div') | ||
|
||
self.setUp() | ||
self.visitor.process_expr([0x74, 0x82, 0x01]) | ||
self.assertEqual(self.visitor.get_str(), | ||
'DW_OP_breg4 (rsi): 130') | ||
|
||
self.setUp() | ||
self.visitor.process_expr([0x91, 0x82, 0x01]) | ||
self.assertEqual(self.visitor.get_str(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#------------------------------------------------------------------------------- | ||
# elftools tests | ||
# | ||
# Eli Bendersky ([email protected]) | ||
# This code is in the public domain | ||
#------------------------------------------------------------------------------- | ||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
|
@@ -24,24 +30,24 @@ def _make_program_in_stream(self, stream): | |
b'\x0A' + # opcode_base | ||
b'\x00\x01\x04\x08\x0C\x01\x01\x01\x00' + # standard_opcode_lengths | ||
# 2 dir names followed by a NULL | ||
b'\x61\x62\x00\x70\x00\x00' + | ||
b'\x61\x62\x00\x70\x00\x00' + | ||
# a file entry | ||
b'\x61\x72\x00\x0C\x0D\x0F' + | ||
b'\x61\x72\x00\x0C\x0D\x0F' + | ||
# and another entry | ||
b'\x45\x50\x51\x00\x86\x12\x07\x08' + | ||
# followed by NULL | ||
b'\x00') | ||
|
||
lp = LineProgram(header, stream, ds, 0, len(stream.getvalue())) | ||
return lp | ||
|
||
def assertLineState(self, state, **kwargs): | ||
""" Assert that the state attributes specified in kwargs have the given | ||
values (the rest are default). | ||
""" | ||
for k, v in iteritems(kwargs): | ||
self.assertEqual(getattr(state, k), v) | ||
|
||
def test_spec_sample_59(self): | ||
# Sample in figure 59 of DWARFv3 | ||
s = BytesIO() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#------------------------------------------------------------------------------- | ||
# elftools tests | ||
# | ||
# Eli Bendersky ([email protected]) | ||
# This code is in the public domain | ||
#------------------------------------------------------------------------------- | ||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
|
@@ -20,9 +26,9 @@ def test_lineprog_header(self): | |
b'\x06' + # opcode_base | ||
b'\x00\x01\x04\x08\x0C' + # standard_opcode_lengths | ||
# 2 dir names followed by a NULL | ||
b'\x61\x62\x00\x70\x00\x00' + | ||
b'\x61\x62\x00\x70\x00\x00' + | ||
# a file entry | ||
b'\x61\x72\x00\x0C\x0D\x0F' + | ||
b'\x61\x72\x00\x0C\x0D\x0F' + | ||
# and another entry | ||
b'\x45\x50\x51\x00\x86\x12\x07\x08' + | ||
# followed by NULL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
#------------------------------------------------------------------------------- | ||
# elftools tests | ||
# | ||
# Eli Bendersky ([email protected]) | ||
# This code is in the public domain | ||
#------------------------------------------------------------------------------- | ||
try: | ||
import unittest2 as unittest | ||
except ImportError: | ||
|
@@ -14,7 +20,7 @@ | |
class Test_parse_cstring_from_stream(unittest.TestCase): | ||
def _make_random_bytes(self, n): | ||
return b''.join(int2byte(randint(32, 127)) for i in range(n)) | ||
|
||
def test_small1(self): | ||
sio = BytesIO(b'abcdefgh\x0012345') | ||
self.assertEqual(parse_cstring_from_stream(sio), b'abcdefgh') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
#------------------------------------------------------------------------------- | ||
# elftools | ||
# | ||
# Eli Bendersky ([email protected]) | ||
# This code is in the public domain | ||
#------------------------------------------------------------------------------- | ||
|
||
# Just a script for playing around with pyelftools during testing | ||
# please ignore it! | ||
# | ||
|