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


C++ pe_base::has_reloc方法代码示例

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


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

示例1: get_relocations

//Get relocation list of pe file, supports one-word sized relocations only
//If list_absolute_entries = true, IMAGE_REL_BASED_ABSOLUTE will be listed
const relocation_table_list get_relocations(const pe_base& pe, bool list_absolute_entries)
{
    relocation_table_list ret;

    //If image does not have relocations
    if(!pe.has_reloc())
        return ret;

    //Check the length in bytes of the section containing relocation directory
    if(pe.section_data_length_from_rva(pe.get_directory_rva(image_directory_entry_basereloc),
                                       pe.get_directory_rva(image_directory_entry_basereloc), section_data_virtual, true)
            < sizeof(image_base_relocation))
        throw pe_exception("Incorrect relocation directory", pe_exception::incorrect_relocation_directory);

    unsigned long current_pos = pe.get_directory_rva(image_directory_entry_basereloc);
    //First IMAGE_BASE_RELOCATION table
    image_base_relocation reloc_table = pe.section_data_from_rva<image_base_relocation>(current_pos, section_data_virtual, true);

    if(reloc_table.SizeOfBlock % 2)
        throw pe_exception("Incorrect relocation directory", pe_exception::incorrect_relocation_directory);

    unsigned long reloc_size = pe.get_directory_size(image_directory_entry_basereloc);
    unsigned long read_size = 0;

    //reloc_table.VirtualAddress is not checked (not so important)
    while(reloc_table.SizeOfBlock && read_size < reloc_size)
    {
        //Create relocation table
        relocation_table table;
        //Save RVA
        table.set_rva(reloc_table.VirtualAddress);

        if(!pe_utils::is_sum_safe(current_pos, reloc_table.SizeOfBlock))
            throw pe_exception("Incorrect relocation directory", pe_exception::incorrect_relocation_directory);

        //List all relocations
        for(unsigned long i = sizeof(image_base_relocation); i < reloc_table.SizeOfBlock; i += sizeof(uint16_t))
        {
            relocation_entry entry(pe.section_data_from_rva<uint16_t>(current_pos + i, section_data_virtual, true));
            if(list_absolute_entries || entry.get_type() != image_rel_based_absolute)
                table.add_relocation(entry);
        }

        //Save table
        ret.push_back(table);

        //Go to next relocation block
        if(!pe_utils::is_sum_safe(current_pos, reloc_table.SizeOfBlock))
            throw pe_exception("Incorrect relocation directory", pe_exception::incorrect_relocation_directory);

        current_pos += reloc_table.SizeOfBlock;
        read_size += reloc_table.SizeOfBlock;
        if (read_size >= reloc_size)
            break;

        reloc_table = pe.section_data_from_rva<image_base_relocation>(current_pos, section_data_virtual, true);
    }

    return ret;
}
开发者ID:xingkongtianyu,项目名称:crypter_stuff,代码行数:62,代码来源:pe_relocations.cpp


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