繁体   English   中英

python PeFile 打印节的字节数

[英]python PeFile print bytes of section

我想打印特定标题范围内的字节。 我在 python 中使用 Pefile 来获取位置,据我所知,这样做应该很简单,但我收到的地址是一个虚拟地址,这意味着我已将二进制文件加载到内存中。

import pefile
pe = pefile.PE("/home/luser/mybinary.exe")

for entry in pe.OPTIONAL_HEADER.DATA_DIRECTORY:
    print(entry.name + "\n|\n|---- Size : " + str(entry.Size) + "\n|\n|---- VirutalAddress : " + hex(entry.VirtualAddress) +'\n')

有问题的部分:

IMAGE_DIRECTORY_ENTRY_EXCEPTION
|
|---- Size : 660
|
|---- VirutalAddress : 0x6000

我不确定它是否相关,但此部分填充了 64 位二进制文​​件以保存异常表。

如果相关,这里有一些测试代码

#include <stdexcept> 
#include <iostream>
#include <string>

bool myfunction(const std::string& str) {
    if (str == "true")
        return true;

    else if (str == "false")
        return false;

    else
        throw std::invalid_argument("Expected true or false");
}


int main(int argc, const char** argv) {
    try {
        const bool check = myfunction("not true");
    }

    catch (std::invalid_argument& error) {
        std::cerr << error.what() << '\n';
    }
    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM