Skip to content

Commit

Permalink
Clean up whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Mar 28, 2020
1 parent 2697329 commit ea81c3e
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 71 deletions.
4 changes: 2 additions & 2 deletions elftools/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# Eli Bendersky ([email protected])
# This code is in the public domain
#-------------------------------------------------------------------------------
class ELFError(Exception):
class ELFError(Exception):
pass

class ELFRelocationError(ELFError):
pass

class ELFParseError(ELFError):
pass

Expand Down
29 changes: 14 additions & 15 deletions elftools/construct/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class Probe(Construct):
A probe: dumps the context, stack frames, and stream content to the screen
to aid the debugging process.
See also Debugger.
Parameters:
* name - the display name
* show_stream - whether or not to show stream contents. default is True.
* show_stream - whether or not to show stream contents. default is True.
the stream must be seekable.
* show_context - whether or not to show the context. default is True.
* show_stack - whether or not to show the upper stack frames. default
* show_stack - whether or not to show the upper stack frames. default
is True.
* stream_lookahead - the number of bytes to dump when show_stack is set.
default is 100.
Example:
Struct("foo",
UBInt8("a"),
Expand All @@ -34,13 +34,13 @@ class Probe(Construct):
)
"""
__slots__ = [
"printname", "show_stream", "show_context", "show_stack",
"printname", "show_stream", "show_context", "show_stack",
"stream_lookahead"
]
counter = 0
def __init__(self, name = None, show_stream = True,
show_context = True, show_stack = True,

def __init__(self, name = None, show_stream = True,
show_context = True, show_stack = True,
stream_lookahead = 100):
Construct.__init__(self, None)
if name is None:
Expand All @@ -59,7 +59,7 @@ def _build(self, obj, stream, context):
self.printout(stream, context)
def _sizeof(self, context):
return 0

def printout(self, stream, context):
obj = Container()
if self.show_stream:
Expand All @@ -71,10 +71,10 @@ def printout(self, stream, context):
stream.seek(-len(follows), 1)
obj.following_stream_data = HexString(follows)
print

if self.show_context:
obj.context = context

if self.show_stack:
obj.stack = ListContainer()
frames = [s[0] for s in inspect.stack()][1:-1]
Expand All @@ -83,7 +83,7 @@ def printout(self, stream, context):
a = Container()
a.__update__(f.f_locals)
obj.stack.append(a)

print("=" * 80)
print("Probe", self.printname)
print(obj)
Expand All @@ -93,10 +93,10 @@ class Debugger(Subconstruct):
"""
A pdb-based debugger. When an exception occurs in the subcon, a debugger
will appear and allow you to debug the error (and even fix on-the-fly).
Parameters:
* subcon - the subcon to debug
Example:
Debugger(
Enum(UBInt8("foo"),
Expand Down Expand Up @@ -131,4 +131,3 @@ def handle_exc(self, msg = None):
print(msg)
pdb.post_mortem(sys.exc_info()[2])
print("=" * 80)

9 changes: 4 additions & 5 deletions elftools/construct/lib/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def int_to_bin(number, width=32):


_bit_values = {
0: 0,
1: 1,
0: 0,
1: 1,
48: 0, # '0'
49: 1, # '1'

Expand Down Expand Up @@ -90,7 +90,7 @@ def swap_bytes(bits, bytesize=8):


def encode_bin(data):
"""
"""
Create a binary representation of the given b'' object. Assume 8-bit
ASCII. Example:
Expand All @@ -101,7 +101,7 @@ def encode_bin(data):


def decode_bin(data):
"""
"""
Locical opposite of decode_bin.
"""
if len(data) & 7:
Expand All @@ -115,4 +115,3 @@ def decode_bin(data):
i += 8
j += 1
return b"".join(chars)

3 changes: 1 addition & 2 deletions elftools/construct/lib/hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ def __init__(self, data, linesize = 16):

def __new__(cls, data, *args, **kwargs):
return bytes.__new__(cls, data)

def __str__(self):
if not self:
return "''"
sep = "\n"
return sep + sep.join(
hexdump(self, self.linesize))

3 changes: 1 addition & 2 deletions elftools/construct/lib/py3compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def decodebytes(b, encoding):
return bytes(b, encoding)

advance_iterator = next

else:
import cStringIO
StringIO = BytesIO = cStringIO.StringIO
Expand All @@ -72,4 +72,3 @@ def decodebytes(b, encoding):

def advance_iterator(it):
return it.next()

26 changes: 13 additions & 13 deletions elftools/dwarf/aranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
from bisect import bisect_right
import math

# An entry in the aranges table;
# An entry in the aranges table;
# begin_addr: The beginning address in the CU
# length: The length of the address range in this entry
# info_offset: The CU's offset into .debug_info
# see 6.1.2 in DWARF4 docs for explanation of the remaining fields
ARangeEntry = namedtuple('ARangeEntry',
ARangeEntry = namedtuple('ARangeEntry',
'begin_addr length info_offset unit_length version address_size segment_size')

class ARanges(object):
""" ARanges table in DWARF
stream, size:
stream, size:
A stream holding the .debug_aranges section, and its size
structs:
structs:
A DWARFStructs instance for parsing the data
"""
def __init__(self, stream, size, structs):
Expand All @@ -50,7 +50,7 @@ def cu_offset_at_addr(self, addr):
"""
tup = self.entries[bisect_right(self.keys, addr) - 1]
return tup.info_offset


#------ PRIVATE ------#
def _get_entries(self):
Expand All @@ -62,14 +62,14 @@ def _get_entries(self):

# one loop == one "set" == one CU
while offset < self.size :
aranges_header = struct_parse(self.structs.Dwarf_aranges_header,
aranges_header = struct_parse(self.structs.Dwarf_aranges_header,
self.stream, offset)
addr_size = self._get_addr_size_struct(aranges_header["address_size"])

# No segmentation
if aranges_header["segment_size"] == 0:
# pad to nearest multiple of tuple size
tuple_size = aranges_header["address_size"] * 2
tuple_size = aranges_header["address_size"] * 2
fp = self.stream.tell()
seek_to = int(math.ceil(fp/float(tuple_size)) * tuple_size)
self.stream.seek(seek_to)
Expand All @@ -80,8 +80,8 @@ def _get_entries(self):
while addr != 0 or length != 0:
# 'begin_addr length info_offset version address_size segment_size'
entries.append(
ARangeEntry(begin_addr=addr,
length=length,
ARangeEntry(begin_addr=addr,
length=length,
info_offset=aranges_header["debug_info_offset"],
unit_length=aranges_header["unit_length"],
version=aranges_header["version"],
Expand All @@ -93,18 +93,18 @@ def _get_entries(self):
elif aranges_header["segment_size"] != 0:
raise NotImplementedError("Segmentation not implemented")

offset = (offset
+ aranges_header.unit_length
offset = (offset
+ aranges_header.unit_length
+ self.structs.initial_length_field_size())

return entries

def _get_addr_size_struct(self, addr_header_value):
""" Given this set's header value (int) for the address size,
""" Given this set's header value (int) for the address size,
get the Construct representation of that size
"""
if addr_header_value == 4:
return self.structs.Dwarf_uint32
else:
else:
assert addr_header_value == 8
return self.structs.Dwarf_uint64
2 changes: 1 addition & 1 deletion elftools/dwarf/callframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def _decode_CFI_table(self):
def _add_to_order(regnum):
# DW_CFA_restore and others remove registers from cur_line,
# but they stay in reg_order. Avoid duplicates.
if regnum not in reg_order:
if regnum not in reg_order:
reg_order.append(regnum)

for instr in self.instructions:
Expand Down
4 changes: 2 additions & 2 deletions elftools/dwarf/dwarf_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def parse_arg_struct(arg_struct):
def parse_arg_struct2(arg1_struct, arg2_struct):
return lambda stream: [struct_parse(arg1_struct, stream),
struct_parse(arg2_struct, stream)]

# ULEB128, then an expression of that length
def parse_nestedexpr():
def parse(stream):
Expand Down Expand Up @@ -241,7 +241,7 @@ def parse_typedblob():
add('DW_OP_call2', parse_arg_struct(structs.Dwarf_uint16('')))
add('DW_OP_call4', parse_arg_struct(structs.Dwarf_uint32('')))
add('DW_OP_call_ref', parse_arg_struct(structs.Dwarf_offset('')))
add('DW_OP_implicit_value', parse_blob())
add('DW_OP_implicit_value', parse_blob())
add('DW_OP_GNU_entry_value', parse_nestedexpr())
add('DW_OP_GNU_const_type', parse_typedblob())
add('DW_OP_GNU_regval_type', parse_arg_struct2(structs.Dwarf_uleb128(''),
Expand Down
11 changes: 5 additions & 6 deletions elftools/dwarf/lineprogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LineProgram(object):
"""
def __init__(self, header, stream, structs,
program_start_offset, program_end_offset):
"""
"""
header:
The header of this line program. Note: LineProgram may modify
its header by appending file entries if DW_LNE_define_file
Expand Down Expand Up @@ -117,7 +117,7 @@ def get_entries(self):
return self._decoded_entries

#------ PRIVATE ------#

def __getitem__(self, name):
""" Implement dict-like access to header entries
"""
Expand All @@ -144,7 +144,7 @@ def add_entry_old_state(cmd, args, is_extended=False):
offset = self.program_start_offset
while offset < self.program_end_offset:
opcode = struct_parse(
self.structs.Dwarf_uint8(''),
self.structs.Dwarf_uint8(''),
self.stream,
offset)

Expand All @@ -159,7 +159,7 @@ def add_entry_old_state(cmd, args, is_extended=False):
adjusted_opcode = opcode - self['opcode_base']
operation_advance = adjusted_opcode // self['line_range']
address_addend = (
self['minimum_instruction_length'] *
self['minimum_instruction_length'] *
((state.op_index + operation_advance) //
maximum_operations_per_instruction))
state.address += address_addend
Expand All @@ -180,7 +180,7 @@ def add_entry_old_state(cmd, args, is_extended=False):
state.end_sequence = True
add_entry_new_state(ex_opcode, [], is_extended=True)
# reset state
state = LineState(self.header['default_is_stmt'])
state = LineState(self.header['default_is_stmt'])
elif ex_opcode == DW_LNE_set_address:
operand = struct_parse(self.structs.Dwarf_target_addr(''),
self.stream)
Expand Down Expand Up @@ -259,4 +259,3 @@ def add_entry_old_state(cmd, args, is_extended=False):
opcode,))
offset = self.stream.tell()
return entries

2 changes: 1 addition & 1 deletion elftools/dwarf/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _create_nameLUT_header(self):
self.Dwarf_nameLUT_header = Struct("Dwarf_nameLUT_header",
self.Dwarf_initial_length('unit_length'),
self.Dwarf_uint16('version'),
self.Dwarf_offset('debug_info_offset'),
self.Dwarf_offset('debug_info_offset'),
self.Dwarf_length('debug_info_length')
)

Expand Down
2 changes: 1 addition & 1 deletion elftools/elf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ class SUNW_SYMINFO_FLAGS(object):
class VER_FLAGS(object):
VER_FLG_BASE=0x1
VER_FLG_WEAK=0x2
VER_FLG_INFO=0x4
VER_FLG_INFO=0x4
2 changes: 1 addition & 1 deletion elftools/elf/descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def describe_attr_tag_arm(tag, val, extra):

elif tag == 'TAG_NODEFAULTS':
return _DESCR_ATTR_TAG_ARM[tag] + 'True'

s = _DESCR_ATTR_TAG_ARM[tag]
s += '"%s"' % val if val else ''
return s
Expand Down
10 changes: 5 additions & 5 deletions elftools/elf/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ class Dynamic(object):
"""
def __init__(self, stream, elffile, stringtable, position, empty):
"""
stream:
stream:
The file-like object from which to load data
elffile:
elffile:
The parent elffile object
stringtable:
stringtable:
A stringtable reference to use for parsing string references in
entries
position:
position:
The file offset of the dynamic segment/section
empty:
empty:
Whether this is a degenerate case with zero entries. Normally, every
dynamic table will have at least one entry, the DT_NULL terminator.
"""
Expand Down
4 changes: 2 additions & 2 deletions elftools/elf/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def tag(self):
return self._tag['tag']

def __repr__(self):
s = '<ARMAttribute (%s): %r>' % (self.tag, self.value)
s = '<ARMAttribute (%s): %r>' % (self.tag, self.value)
s += ' %s' % self.extra if self.extra is not None else ''
return s

Expand Down Expand Up @@ -374,7 +374,7 @@ def _make_attributes(self):
yield ARMAttribute(self.structs, self.stream)

def __repr__(self):
s = "<ARMAttributesSubsubsection (%s): %d bytes>"
s = "<ARMAttributesSubsubsection (%s): %d bytes>"
return s % (self.header.tag[4:], self.header.value)


Expand Down
Loading

0 comments on commit ea81c3e

Please sign in to comment.