本文整理汇总了Python中file.File.setContent方法的典型用法代码示例。如果您正苦于以下问题:Python File.setContent方法的具体用法?Python File.setContent怎么用?Python File.setContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file.File
的用法示例。
在下文中一共展示了File.setContent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Parser
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import setContent [as 别名]
#.........这里部分代码省略.........
a = Abnormality(title='UNKNOWN CPUTYPE', data=data)
self.addAbnormality(a)
try:
subtype = dictionary.cputypes[cputype][subtype]
except:
data = {
'offset': macho.getOffset() + 8,
'cputype': cputype,
'subtype': subtype
}
a = Abnormality(title='UNKNOWN SUBTYPE', data=data)
self.addAbnormality(a)
try:
filetype = dictionary.filetypes[filetype]
except:
data = {
'offset': macho.getOffset() + 12,
'filetype': filetype
}
a = Abnormality(title='UNKNOWN FILETYPE', data=data)
self.addAbnormality(a)
flags = self.listMachOFlags(flags)
macho.setCPUType(cpu)
macho.setSubType(subtype)
macho.setFileType(filetype)
macho.setNLCs(nlcs)
macho.setSLCs(slcs)
macho.setFlags(flags)
lc = LoadCommander(f=self._f, macho=macho, file_size=self._file.getSize())
lc.parseLCs()
self._abnormalities += lc.getAbnormalities()
# Need to investigate whether the presence of a
# symbol/string table is expected and whether the
# abscence is indicative of shenanigans.
if macho.hasLC('SYMTAB'):
self.parseSyms(macho)
self.parseImportsAndStrings(macho)
if macho.hasLC('CODE_SIGNATURE'):
self.parseSig(macho)
if not macho.isArchive():
self._file.setContent(macho)
def parseUniversal(self):
self._f.seek(0)
# skip magic
self._f.read(4)
nmachos = getInt(self._f)
u = Universal(nmachos=nmachos)
u_size = self.getFile().getSize()
for i in range(u.getNMachOs()):
# skip cputype, subtype
self._f.read(8)
offset = getInt(self._f)
size = getInt(self._f)
# Abnormality OUT_OF_BOUNDS check
if offset + size > u_size:
data = {
'offset': offset,
'size': size,
'file_size': u_size
}
a = Abnormality(title='MACH-O OUT OF BOUNDS', data=data)
self.addAbnormality(a)
continue
# skip align
self._f.read(4)
identity = self.identifyFile(offset)
# Abnormality BAD_MAGIC check
if identity not in dictionary.machos.values():
data = {
'offset': offset,
'magic': identity,
}
a = Abnormality(title='BAD MAGIC - MACH-O')
self.addAbnormality(a)
continue
u.addMachO(MachO(archive=True, offset=offset, arch=identity[0],
endi=identity[1], size=size))
for i in u.genMachOs():
self.parseMachO(i)
self._file.setContent(u)
def parseFile(self):
size = self.getFileSize()
hashes = self.getFileHashes()
self._file.setSize(size)
self._file.setHashes(hashes)
identity = self.identifyFile(0)
if identity == 'universal':
self.parseUniversal()
else:
self.parseMachO(MachO(archive=False, offset=0, arch=identity[0],
endi=identity[1], size=self.getFileSize()))