Unverified Commit 47c8c06c by Buddy Committed by GitHub

Merge pull request #378 from ReFirmLabs/351-endianess-to-endianness

Changed endianess to endianness.
parents c55cb3f9 11a9bcd4
...@@ -131,13 +131,13 @@ class SignatureLine(object): ...@@ -131,13 +131,13 @@ class SignatureLine(object):
# little endian. # little endian.
if self.type.startswith('be'): if self.type.startswith('be'):
self.type = self.type[2:] self.type = self.type[2:]
self.endianess = '>' self.endianness = '>'
elif self.type.startswith('le'): elif self.type.startswith('le'):
self.endianess = '<' self.endianness = '<'
self.type = self.type[2:] self.type = self.type[2:]
# Assume big endian if no endianess was explicitly specified # Assume big endian if no endianness was explicitly specified
else: else:
self.endianess = '>' self.endianness = '>'
# Check the comparison value for the type of comparison to be performed (e.g., # Check the comparison value for the type of comparison to be performed (e.g.,
# '=0x1234', '>0x1234', etc). If no operator is specified, '=' is implied. # '=0x1234', '>0x1234', etc). If no operator is specified, '=' is implied.
...@@ -237,9 +237,9 @@ class SignatureLine(object): ...@@ -237,9 +237,9 @@ class SignatureLine(object):
self.fmt = self.fmt.upper() self.fmt = self.fmt.upper()
# If a struct format was identified, create a format string to be passed to struct.unpack # If a struct format was identified, create a format string to be passed to struct.unpack
# which specifies the endianess and data type format. # which specifies the endianness and data type format.
if self.fmt: if self.fmt:
self.pkfmt = '%c%c' % (self.endianess, self.fmt) self.pkfmt = '%c%c' % (self.endianness, self.fmt)
else: else:
self.pkfmt = None self.pkfmt = None
...@@ -312,7 +312,7 @@ class Signature(object): ...@@ -312,7 +312,7 @@ class Signature(object):
# Strings and single byte signatures are taken at face value; # Strings and single byte signatures are taken at face value;
# multi-byte integer values are turned into regex strings based # multi-byte integer values are turned into regex strings based
# on their data type size and endianess. # on their data type size and endianness.
if line.type == 'regex': if line.type == 'regex':
# Regex types are already compiled expressions. # Regex types are already compiled expressions.
# Note that since re.finditer is used, unless the specified # Note that since re.finditer is used, unless the specified
...@@ -323,23 +323,23 @@ class Signature(object): ...@@ -323,23 +323,23 @@ class Signature(object):
elif line.size == 1: elif line.size == 1:
restr = chr(line.value) restr = chr(line.value)
elif line.size == 2: elif line.size == 2:
if line.endianess == '<': if line.endianness == '<':
restr = chr(line.value & 0xFF) + chr(line.value >> 8) restr = chr(line.value & 0xFF) + chr(line.value >> 8)
elif line.endianess == '>': elif line.endianness == '>':
restr = chr(line.value >> 8) + chr(line.value & 0xFF) restr = chr(line.value >> 8) + chr(line.value & 0xFF)
elif line.size == 4: elif line.size == 4:
if line.endianess == '<': if line.endianness == '<':
restr = (chr(line.value & 0xFF) + restr = (chr(line.value & 0xFF) +
chr((line.value >> 8) & 0xFF) + chr((line.value >> 8) & 0xFF) +
chr((line.value >> 16) & 0xFF) + chr((line.value >> 16) & 0xFF) +
chr(line.value >> 24)) chr(line.value >> 24))
elif line.endianess == '>': elif line.endianness == '>':
restr = (chr(line.value >> 24) + restr = (chr(line.value >> 24) +
chr((line.value >> 16) & 0xFF) + chr((line.value >> 16) & 0xFF) +
chr((line.value >> 8) & 0xFF) + chr((line.value >> 8) & 0xFF) +
chr(line.value & 0xFF)) chr(line.value & 0xFF))
elif line.size == 8: elif line.size == 8:
if line.endianess == '<': if line.endianness == '<':
restr = (chr(line.value & 0xFF) + restr = (chr(line.value & 0xFF) +
chr((line.value >> 8) & 0xFF) + chr((line.value >> 8) & 0xFF) +
chr((line.value >> 16) & 0xFF) + chr((line.value >> 16) & 0xFF) +
...@@ -348,7 +348,7 @@ class Signature(object): ...@@ -348,7 +348,7 @@ class Signature(object):
chr((line.value >> 40) & 0xFF) + chr((line.value >> 40) & 0xFF) +
chr((line.value >> 48) & 0xFF) + chr((line.value >> 48) & 0xFF) +
chr(line.value >> 56)) chr(line.value >> 56))
elif line.endianess == '>': elif line.endianness == '>':
restr = (chr(line.value >> 56) + restr = (chr(line.value >> 56) +
chr((line.value >> 48) & 0xFF) + chr((line.value >> 48) & 0xFF) +
chr((line.value >> 40) & 0xFF) + chr((line.value >> 40) & 0xFF) +
......
...@@ -558,7 +558,7 @@ ...@@ -558,7 +558,7 @@
0x10 string ROMFS\x20v D-Link ROMFS filesystem, 0x10 string ROMFS\x20v D-Link ROMFS filesystem,
>0x17 string x version %s, >0x17 string x version %s,
>0 string !\x2EmoR >0 string !\x2EmoR
>>0 string !Rom\x2E {invalid} unknown endianess >>0 string !Rom\x2E {invalid} unknown endianness
>0 string \x2EmoR little endian, >0 string \x2EmoR little endian,
>>8 lelong x size: <= %d >>8 lelong x size: <= %d
>>8 lelong-0x20 x {jump:%d} >>8 lelong-0x20 x {jump:%d}
......
...@@ -51,42 +51,42 @@ class Disasm(Module): ...@@ -51,42 +51,42 @@ class Disasm(Module):
ARCHITECTURES = [ ARCHITECTURES = [
Architecture(type=capstone.CS_ARCH_ARM, Architecture(type=capstone.CS_ARCH_ARM,
mode=capstone.CS_MODE_ARM, mode=capstone.CS_MODE_ARM,
endianess=capstone.CS_MODE_BIG_ENDIAN, endianness=capstone.CS_MODE_BIG_ENDIAN,
description="ARM executable code, 32-bit, big endian"), description="ARM executable code, 32-bit, big endian"),
Architecture(type=capstone.CS_ARCH_ARM, Architecture(type=capstone.CS_ARCH_ARM,
mode=capstone.CS_MODE_ARM, mode=capstone.CS_MODE_ARM,
endianess=capstone.CS_MODE_LITTLE_ENDIAN, endianness=capstone.CS_MODE_LITTLE_ENDIAN,
description="ARM executable code, 32-bit, little endian"), description="ARM executable code, 32-bit, little endian"),
Architecture(type=capstone.CS_ARCH_ARM64, Architecture(type=capstone.CS_ARCH_ARM64,
mode=capstone.CS_MODE_ARM, mode=capstone.CS_MODE_ARM,
endianess=capstone.CS_MODE_BIG_ENDIAN, endianness=capstone.CS_MODE_BIG_ENDIAN,
description="ARM executable code, 64-bit, big endian"), description="ARM executable code, 64-bit, big endian"),
Architecture(type=capstone.CS_ARCH_ARM64, Architecture(type=capstone.CS_ARCH_ARM64,
mode=capstone.CS_MODE_ARM, mode=capstone.CS_MODE_ARM,
endianess=capstone.CS_MODE_LITTLE_ENDIAN, endianness=capstone.CS_MODE_LITTLE_ENDIAN,
description="ARM executable code, 64-bit, little endian"), description="ARM executable code, 64-bit, little endian"),
Architecture(type=capstone.CS_ARCH_PPC, Architecture(type=capstone.CS_ARCH_PPC,
mode=capstone.CS_MODE_BIG_ENDIAN, mode=capstone.CS_MODE_BIG_ENDIAN,
endianess=capstone.CS_MODE_BIG_ENDIAN, endianness=capstone.CS_MODE_BIG_ENDIAN,
description="PPC executable code, 32/64-bit, big endian"), description="PPC executable code, 32/64-bit, big endian"),
Architecture(type=capstone.CS_ARCH_MIPS, Architecture(type=capstone.CS_ARCH_MIPS,
mode=capstone.CS_MODE_64, mode=capstone.CS_MODE_64,
endianess=capstone.CS_MODE_BIG_ENDIAN, endianness=capstone.CS_MODE_BIG_ENDIAN,
description="MIPS executable code, 32/64-bit, big endian"), description="MIPS executable code, 32/64-bit, big endian"),
Architecture(type=capstone.CS_ARCH_MIPS, Architecture(type=capstone.CS_ARCH_MIPS,
mode=capstone.CS_MODE_64, mode=capstone.CS_MODE_64,
endianess=capstone.CS_MODE_LITTLE_ENDIAN, endianness=capstone.CS_MODE_LITTLE_ENDIAN,
description="MIPS executable code, 32/64-bit, little endian"), description="MIPS executable code, 32/64-bit, little endian"),
Architecture(type=capstone.CS_ARCH_ARM, Architecture(type=capstone.CS_ARCH_ARM,
mode=capstone.CS_MODE_THUMB, mode=capstone.CS_MODE_THUMB,
endianess=capstone.CS_MODE_LITTLE_ENDIAN, endianness=capstone.CS_MODE_LITTLE_ENDIAN,
description="ARM executable code, 16-bit (Thumb), little endian"), description="ARM executable code, 16-bit (Thumb), little endian"),
Architecture(type=capstone.CS_ARCH_ARM, Architecture(type=capstone.CS_ARCH_ARM,
mode=capstone.CS_MODE_THUMB, mode=capstone.CS_MODE_THUMB,
endianess=capstone.CS_MODE_BIG_ENDIAN, endianness=capstone.CS_MODE_BIG_ENDIAN,
description="ARM executable code, 16-bit (Thumb), big endian"), description="ARM executable code, 16-bit (Thumb), big endian"),
] ]
...@@ -99,7 +99,7 @@ class Disasm(Module): ...@@ -99,7 +99,7 @@ class Disasm(Module):
self.disasm_data_size = self.min_insn_count * 10 self.disasm_data_size = self.min_insn_count * 10
for arch in self.ARCHITECTURES: for arch in self.ARCHITECTURES:
self.disassemblers.append((capstone.Cs(arch.type, (arch.mode + arch.endianess)), arch.description)) self.disassemblers.append((capstone.Cs(arch.type, (arch.mode + arch.endianness)), arch.description))
def scan_file(self, fp): def scan_file(self, fp):
total_read = 0 total_read = 0
......
...@@ -11,7 +11,7 @@ except ImportError as e: ...@@ -11,7 +11,7 @@ except ImportError as e:
class RomFSCommon(object): class RomFSCommon(object):
def _read_next_word(self): def _read_next_word(self):
value = struct.unpack("%sL" % self.endianess, self.data[self.index:self.index + 4])[0] value = struct.unpack("%sL" % self.endianness, self.data[self.index:self.index + 4])[0]
self.index += 4 self.index += 4
return value return value
...@@ -49,9 +49,9 @@ class RomFSEntry(RomFSCommon): ...@@ -49,9 +49,9 @@ class RomFSEntry(RomFSCommon):
DATA_MASK = 0x00000008 DATA_MASK = 0x00000008
COMPRESSED_MASK = 0x005B0000 COMPRESSED_MASK = 0x005B0000
def __init__(self, data, endianess="<"): def __init__(self, data, endianness="<"):
self.data = data self.data = data
self.endianess = endianess self.endianness = endianness
self.index = 0 self.index = 0
self.type = self._read_next_word() self.type = self._read_next_word()
...@@ -68,10 +68,10 @@ class RomFSDirStruct(RomFSCommon): ...@@ -68,10 +68,10 @@ class RomFSDirStruct(RomFSCommon):
SIZE = 0x20 SIZE = 0x20
def __init__(self, data, endianess="<"): def __init__(self, data, endianness="<"):
self.index = 0 self.index = 0
self.data = data self.data = data
self.endianess = endianess self.endianness = endianness
self.directory = False self.directory = False
self.uid = None self.uid = None
self.ls = [] self.ls = []
...@@ -116,8 +116,8 @@ class RomFS(object): ...@@ -116,8 +116,8 @@ class RomFS(object):
SUPERBLOCK_SIZE = 0x20 SUPERBLOCK_SIZE = 0x20
FILE_ENTRY_SIZE = 0x20 FILE_ENTRY_SIZE = 0x20
def __init__(self, fname, endianess="<"): def __init__(self, fname, endianness="<"):
self.endianess = endianess self.endianness = endianness
self.data = open(fname, "rb").read() self.data = open(fname, "rb").read()
self.entries = self._process_all_entries() self.entries = self._process_all_entries()
...@@ -151,7 +151,7 @@ class RomFS(object): ...@@ -151,7 +151,7 @@ class RomFS(object):
while True: while True:
try: try:
entry = RomFSEntry(self.data[offset:offset + self.FILE_ENTRY_SIZE], endianess=self.endianess) entry = RomFSEntry(self.data[offset:offset + self.FILE_ENTRY_SIZE], endianness=self.endianness)
except ValueError as e: except ValueError as e:
break break
...@@ -166,7 +166,7 @@ class RomFS(object): ...@@ -166,7 +166,7 @@ class RomFS(object):
if entry.type & entry.DIR_STRUCT_MASK: if entry.type & entry.DIR_STRUCT_MASK:
entries[entry.uid].type = "directory" entries[entry.uid].type = "directory"
ds = RomFSDirStruct(self.data[entry.offset:entry.offset + entry.size], endianess=self.endianess) ds = RomFSDirStruct(self.data[entry.offset:entry.offset + entry.size], endianness=self.endianness)
for (uid, name) in ds.ls: for (uid, name) in ds.ls:
if not uid in entries: if not uid in entries:
entries[uid] = FileContainer() entries[uid] = FileContainer()
......
...@@ -7,27 +7,27 @@ import binwalk.core.plugin ...@@ -7,27 +7,27 @@ import binwalk.core.plugin
class PFSCommon(object): class PFSCommon(object):
def _make_short(self, data, endianess): def _make_short(self, data, endianness):
"""Returns a 2 byte integer.""" """Returns a 2 byte integer."""
data = binwalk.core.compat.str2bytes(data) data = binwalk.core.compat.str2bytes(data)
return struct.unpack('%sH' % endianess, data)[0] return struct.unpack('%sH' % endianness, data)[0]
def _make_int(self, data, endianess): def _make_int(self, data, endianness):
"""Returns a 4 byte integer.""" """Returns a 4 byte integer."""
data = binwalk.core.compat.str2bytes(data) data = binwalk.core.compat.str2bytes(data)
return struct.unpack('%sI' % endianess, data)[0] return struct.unpack('%sI' % endianness, data)[0]
class PFS(PFSCommon): class PFS(PFSCommon):
"""Class for accessing PFS meta-data.""" """Class for accessing PFS meta-data."""
HEADER_SIZE = 16 HEADER_SIZE = 16
def __init__(self, fname, endianess='<'): def __init__(self, fname, endianness='<'):
self.endianess = endianess self.endianness = endianness
self.meta = binwalk.core.common.BlockFile(fname, 'rb') self.meta = binwalk.core.common.BlockFile(fname, 'rb')
header = self.meta.read(self.HEADER_SIZE) header = self.meta.read(self.HEADER_SIZE)
self.file_list_start = self.meta.tell() self.file_list_start = self.meta.tell()
self.num_files = self._make_short(header[-2:], endianess) self.num_files = self._make_short(header[-2:], endianness)
self.node_size = self._get_fname_len() + 12 self.node_size = self._get_fname_len() + 12
def _get_fname_len(self, bufflen=128): def _get_fname_len(self, bufflen=128):
...@@ -42,7 +42,7 @@ class PFS(PFSCommon): ...@@ -42,7 +42,7 @@ class PFS(PFSCommon):
def _get_node(self): def _get_node(self):
"""Reads a chunk of meta data from file and returns a PFSNode.""" """Reads a chunk of meta data from file and returns a PFSNode."""
data = self.meta.read(self.node_size) data = self.meta.read(self.node_size)
return PFSNode(data, self.endianess) return PFSNode(data, self.endianness)
def get_end_of_meta_data(self): def get_end_of_meta_data(self):
"""Returns integer indicating the end of the file system meta data.""" """Returns integer indicating the end of the file system meta data."""
...@@ -63,12 +63,12 @@ class PFS(PFSCommon): ...@@ -63,12 +63,12 @@ class PFS(PFSCommon):
class PFSNode(PFSCommon): class PFSNode(PFSCommon):
"""A node in the PFS Filesystem containing meta-data about a single file.""" """A node in the PFS Filesystem containing meta-data about a single file."""
def __init__(self, data, endianess): def __init__(self, data, endianness):
self.fname, data = data[:-12], data[-12:] self.fname, data = data[:-12], data[-12:]
self._decode_fname() self._decode_fname()
self.inode_no = self._make_int(data[:4], endianess) self.inode_no = self._make_int(data[:4], endianness)
self.foffset = self._make_int(data[4:8], endianess) self.foffset = self._make_int(data[4:8], endianness)
self.fsize = self._make_int(data[8:], endianess) self.fsize = self._make_int(data[8:], endianness)
def _decode_fname(self): def _decode_fname(self):
"""Extracts the actual string from the available bytes.""" """Extracts the actual string from the available bytes."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment