Skip to content

Commit

Permalink
black'ed source tree
Browse files Browse the repository at this point in the history
  • Loading branch information
cnvogelg committed Mar 10, 2020
1 parent 5447925 commit 21d2e19
Show file tree
Hide file tree
Showing 390 changed files with 43,937 additions and 41,693 deletions.
92 changes: 46 additions & 46 deletions amitools/binfmt/BinFmt.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@


from .elf.BinFmtELF import BinFmtELF
from .hunk.BinFmtHunk import BinFmtHunk


class BinFmt:
def __init__(self):
self.formats = [BinFmtHunk(), BinFmtELF()]

def get_format(self, path):
"""get instance of BinFmt loader or None"""
with open(path, "rb") as f:
return self.get_format_fobj(f)

def get_format_fobj(self, fobj):
"""get instance of BinFmt loader or None"""
for f in self.formats:
if f.is_image_fobj(fobj):
return f
return None

def is_image(self, path):
"""check if a given file is a supported binary file"""
with open(path, "rb") as f:
return self.is_image_fobj(f)

def is_image_fobj(self, fobj):
"""check if a given file is a supported binary file"""
f = self.get_format_fobj(fobj)
return f is not None

def load_image(self, path):
"""load a binary file and return a BinImage. unknown format returns None"""
with open(path, "rb") as f:
return self.load_image_fobj(f)

def load_image_fobj(self, fobj):
"""load a binary file and return a BinImage. unknown format returns None"""
f = self.get_format_fobj(fobj)
if f is not None:
return f.load_image_fobj(fobj)
else:
return None
def __init__(self):
self.formats = [BinFmtHunk(), BinFmtELF()]

def get_format(self, path):
"""get instance of BinFmt loader or None"""
with open(path, "rb") as f:
return self.get_format_fobj(f)

def get_format_fobj(self, fobj):
"""get instance of BinFmt loader or None"""
for f in self.formats:
if f.is_image_fobj(fobj):
return f
return None

def is_image(self, path):
"""check if a given file is a supported binary file"""
with open(path, "rb") as f:
return self.is_image_fobj(f)

def is_image_fobj(self, fobj):
"""check if a given file is a supported binary file"""
f = self.get_format_fobj(fobj)
return f is not None

def load_image(self, path):
"""load a binary file and return a BinImage. unknown format returns None"""
with open(path, "rb") as f:
return self.load_image_fobj(f)

def load_image_fobj(self, fobj):
"""load a binary file and return a BinImage. unknown format returns None"""
f = self.get_format_fobj(fobj)
if f is not None:
return f.load_image_fobj(fobj)
else:
return None


# mini test
if __name__ == '__main__':
import sys
bf = BinFmt()
for a in sys.argv[1:]:
ok = bf.is_image(a)
bi = bf.load_image(a)
print(a, ok, str(bi))
if __name__ == "__main__":
import sys

bf = BinFmt()
for a in sys.argv[1:]:
ok = bf.is_image(a)
bi = bf.load_image(a)
print(a, ok, str(bi))
Loading

0 comments on commit 21d2e19

Please sign in to comment.