本文整理汇总了Python中file.File.getSize方法的典型用法代码示例。如果您正苦于以下问题:Python File.getSize方法的具体用法?Python File.getSize怎么用?Python File.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file.File
的用法示例。
在下文中一共展示了File.getSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import getSize [as 别名]
class Parser(object):
# Constructor
def __init__(self, path=None):
# Fields
self._abnormalities = []
self._path = path
self._file = File(name=getFileName(self._path))
self._f = open(path, 'rb')
# Getters
def getAbnormalities(self): return self._abnormalities
def getPath(self): return self._path
def getFile(self): return self._file
def getF(self): return self._f
# Setters
def setPath(self, path): self._path = path
def setFile(self, file): self._file = file
def setF(self, f): self._f = f
# Functions
def addAbnormality(self, abnormality):
self._abnormalities.append(abnormality)
def identifyFile(self, offset):
prev = self._f.tell()
self._f.seek(offset)
magic = getInt(self._f)
self._f.seek(prev)
if magic not in dictionary.machos:
return magic
return dictionary.machos[magic]
def getFileSize(self):
prev = self._f.tell()
self._f.seek(0)
size = len(self._f.read())
self._f.seek(prev)
return size
def getFileHashes(self):
self._f.seek(0)
b = self._f.read()
md5 = hashlib.md5(b).hexdigest()
sha1 = hashlib.sha1(b).hexdigest()
sha256 = hashlib.sha256(b).hexdigest()
return {'md5': md5, 'sha1': sha1, 'sha256': sha256}
def getCertNameData(self, name, o):
try:
return name[o]
except KeyError:
return 'n/a'
def listMachOFlags(self, flags):
l = []
j = 0
while j < 28:
if (0x1 & (flags >> j)) == 0x1:
l.append(dictionary.flags[2 ** j])
j = j + 1
return l
def parseSyms(self, macho):
prev = self._f.tell()
true_offset = macho.getOffset() + macho.getSymTab().getOffset()
if macho.is64Bit():
symbol_size = 60
else:
symbol_size = 56
# print 'to:', true_offset
# print macho.getOffset(), macho.getSize()
if (true_offset < macho.getOffset() + macho.getSize() and
true_offset < self._file.getSize()):
self._f.seek(true_offset)
for i in range(macho.getSymTab().getNSyms()):
# print self._f.tell()
if ((self._f.tell() + symbol_size > macho.getOffset() +
macho.getSize()) or (self._f.tell() + symbol_size >
self._file.getSize())):
data = {
'offset': self._f.tell(),
'mach-o_size': macho.getSize(),
'mach-o_offset': macho.getOffset(),
'file_size': self._file.getSize()
}
a = Abnormality(title='REMAINING SYMBOLS OUT OF BOUNDS',
data=data)
self.addAbnormality(a)
self._f.seek(prev)
return
else:
index = getInt(self._f)
#.........这里部分代码省略.........