当前位置: 首页>>代码示例>>Python>>正文


Python PE.peFromBytes方法代码示例

本文整理汇总了Python中PE.peFromBytes方法的典型用法代码示例。如果您正苦于以下问题:Python PE.peFromBytes方法的具体用法?Python PE.peFromBytes怎么用?Python PE.peFromBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PE的用法示例。


在下文中一共展示了PE.peFromBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: is_legit_pe

# 需要导入模块: import PE [as 别名]
# 或者: from PE import peFromBytes [as 别名]
def is_legit_pe(bytes):
    """
    Load the memory region into a vivisect memory object and try loading the memory region as a PE "from memory".
    If it succeeds and contains valid sections, it's considered a valid PE.

    Parameters:
      bytes : byte string to test

    Returns: bool - True if legit pe, False if not
    """
    try:
        new_pe = PE.peFromBytes(bytes)

        # ImageBase will not be zero and will be page aligned
        if (
            new_pe.IMAGE_NT_HEADERS.OptionalHeader.ImageBase == 0
            or new_pe.IMAGE_NT_HEADERS.OptionalHeader.ImageBase & 0xFFF != 0
        ):
            return False

        if new_pe.IMAGE_NT_HEADERS.OptionalHeader.AddressOfEntryPoint > len(bytes):
            return False

        if new_pe.IMAGE_NT_HEADERS.OptionalHeader.SizeOfHeaders < 0x80:
            return False

        if new_pe.IMAGE_NT_HEADERS.OptionalHeader.SizeOfHeaders > len(bytes):
            return False

        # Section check
        # Start at 0x80, never seen a PE that has a VirtualAddress for the
        # first section below 0x80, usually > 0x400
        prva = 0x80
        for sect in new_pe.getSections():
            if prva > sect.VirtualAddress:
                return False
            elif sect.VirtualAddress & 0xFF != 0:
                return False
            prva = sect.VirtualAddress

        # Assuming that more than 20 sections in a PE is likely bogus
        if 0 >= new_pe.IMAGE_NT_HEADERS.FileHeader.NumberOfSections > 20:
            return False

            # Could do more checks, but leaving at these, hopefully it'll be enough to rule
            # out garbage, but still catch missing MZ or DOS text stubs

    except:
        return False

    return True
开发者ID:SEC-squad,项目名称:flare-dbg,代码行数:53,代码来源:utils.py


注:本文中的PE.peFromBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。