• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ section类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: get_entry

	bool get_entry(
		Elf_Xword	index,
		Elf64_Addr	&offset,
		Elf_Word	&symbol,
		Elf_Word	&type,
		Elf_Sxword	&addend
	) const {
		if ( index >= get_entries_num() ) {	// Is index valid
			return false;
		}
		if ( elf_file.get_class() == ELFCLASS32 ) {
			if ( SHT_REL == relocation_section->get_type() ) {
				generic_get_entry_rel< Elf32_Rel >( index, offset, symbol,
													type,  addend );
			}
			else if ( SHT_RELA == relocation_section->get_type() ) {
				generic_get_entry_rela< Elf32_Rela >( index, offset, symbol,
													type,  addend );
			}
		}
		else {
			if ( SHT_REL == relocation_section->get_type() ) {
				generic_get_entry_rel< Elf64_Rel >( index, offset, symbol,
													type,  addend );
			}
			else if ( SHT_RELA == relocation_section->get_type() ) {
				generic_get_entry_rela< Elf64_Rela >( index, offset, symbol,
													type,  addend );
			}
		}
		return true;
	}
开发者ID:kungfooman,项目名称:easyelf,代码行数:32,代码来源:relocation.hpp


示例2: get_entries_num

	Elf_Xword get_entries_num() const {
		Elf_Xword nRet = 0;
		if ( 0 != relocation_section->get_entry_size() ) {
			nRet = relocation_section->get_size() / relocation_section->get_entry_size();
		}
		return nRet;
	}
开发者ID:kungfooman,项目名称:easyelf,代码行数:7,代码来源:relocation.hpp


示例3: rebuild_resources

//Resources rebuilder
//resource_directory - root resource directory
//resources_section - section where resource directory will be placed (must be attached to PE image)
//offset_from_section_start - offset from resources_section raw data start
//resource_directory is non-constant, because it will be sorted
//save_to_pe_headers - if true, new resource directory information will be saved to PE image headers
//auto_strip_last_section - if true and resources are placed in the last section, it will be automatically stripped
//number_of_id_entries and number_of_named_entries for resource directories are recalculated and not used
const image_directory rebuild_resources(pe_base& pe, resource_directory& info, section& resources_section, uint32_t offset_from_section_start, bool save_to_pe_header, bool auto_strip_last_section)
{
    //Check that resources_section is attached to this PE image
    if(!pe.section_attached(resources_section))
        throw pe_exception("Resource section must be attached to PE file", pe_exception::section_is_not_attached);
    
    //Check resource directory correctness
    if(info.get_entry_list().empty())
        throw pe_exception("Empty resource directory", pe_exception::incorrect_resource_directory);
    
    uint32_t aligned_offset_from_section_start = pe_utils::align_up(offset_from_section_start, sizeof(uint32_t));
    uint32_t needed_size_for_structures = aligned_offset_from_section_start - offset_from_section_start; //Calculate needed size for resource tables and data
    uint32_t needed_size_for_strings = 0;
    uint32_t needed_size_for_data = 0;

    calculate_resource_data_space(info, aligned_offset_from_section_start, needed_size_for_structures, needed_size_for_strings);

    {
        uint32_t current_data_pos = aligned_offset_from_section_start + needed_size_for_structures + needed_size_for_strings;
        calculate_resource_data_space(info, needed_size_for_structures, needed_size_for_strings, needed_size_for_data, current_data_pos);
    }

    uint32_t needed_size = needed_size_for_structures + needed_size_for_strings + needed_size_for_data;

    //Check if resources_section is last one. If it's not, check if there's enough place for resource data
    if(&resources_section != &*(pe.get_image_sections().end() - 1) && 
        (resources_section.empty() || pe_utils::align_up(resources_section.get_size_of_raw_data(), pe.get_file_alignment())
        < needed_size + aligned_offset_from_section_start))
        throw pe_exception("Insufficient space for resource directory", pe_exception::insufficient_space);

    std::string& raw_data = resources_section.get_raw_data();

    //This will be done only if resources_section is the last section of image or for section with unaligned raw length of data
    if(raw_data.length() < needed_size + aligned_offset_from_section_start)
        raw_data.resize(needed_size + aligned_offset_from_section_start); //Expand section raw data

    uint32_t current_structures_pos = aligned_offset_from_section_start;
    uint32_t current_strings_pos = current_structures_pos + needed_size_for_structures;
    uint32_t current_data_pos = current_strings_pos + needed_size_for_strings;
    rebuild_resource_directory(pe, resources_section, info, current_structures_pos, current_data_pos, current_strings_pos, aligned_offset_from_section_start);
    
    //Adjust section raw and virtual sizes
    pe.recalculate_section_sizes(resources_section, auto_strip_last_section);

    image_directory ret(pe.rva_from_section_offset(resources_section, aligned_offset_from_section_start), needed_size);

    //If auto-rewrite of PE headers is required
    if(save_to_pe_header)
    {
        pe.set_directory_rva(image_directory_entry_resource, ret.get_rva());
        pe.set_directory_size(image_directory_entry_resource, ret.get_size());
    }

    return ret;
}
开发者ID:apriorit,项目名称:portable-executable-library,代码行数:63,代码来源:pe_resources.cpp


示例4: appconfig_option

void appconfig_option(std::string const& name, section const& pars, T& data)
{
    try {
        if (pars.has_entry(name))
            data = lexical_cast<T>(pars.get_entry(name));
    } catch (...) {
        std::string msg = boost::str(boost::format(
            "\"%1%\" is not a valid value for %2%")
            % pars.get_entry(name) % name);
        HPX_THROW_IN_CURRENT_FUNC(bad_parameter, msg);
    }
}
开发者ID:STEllAR-GROUP,项目名称:hpx_historic,代码行数:12,代码来源:smp_amr3d_client.cpp


示例5: if

	void section_schema::validate_section(section &sect, schema_mode mode) const
	{
		/*
		 * Here should be done:
		 * - check if section has proper options (compare by names) - depends on mode
		 * - for options with given schema call validate on that option
		 * - for missing options from schema (relaxed mode) add string options with
		 *   default value
		 */

		// firstly go through option schemas
		for (auto &opt : options_) {
			bool contains = sect.contains(opt->get_name());

			if (contains) {
				// even if option is not mandatory, we execute validation of option (both modes)
				opt->validate_option(sect[opt->get_name()]);
			} else if (opt->is_mandatory()) {
				// mandatory option is not present in given section (both modes)
				throw validation_exception(
					"Mandatory option '" + opt->get_name() + "' is missing in section '" + sect.get_name() + "'");
			} else {
				// option is not mandatory and not in given section
				//   => add option with default value
				sect.add_option(opt->get_name(), opt->get_default_value());
				// validate added option, so type of the value could be changed to nonstring type
				opt->validate_option(sect[opt->get_name()]);
			}
		}

		// secondly go through options
		for (auto &opt : sect) {
			bool contains = this->contains(opt.get_name());

			// if section_schema contains option everything is fine, we handled this above
			if (contains) {
				continue;
			}

			// we have strict mode and option which is not in section_schema
			if (mode == schema_mode::strict) {
				throw validation_exception("Option '" + opt.get_name() + "' not specified in schema");
			}
		}
	}
开发者ID:MartinFrancu,项目名称:dppUkol5,代码行数:45,代码来源:section_schema.cpp


示例6: generic_get_entry_rela

	void generic_get_entry_rela(
		Elf_Xword	index,
		Elf64_Addr	&offset,
		Elf_Word	&symbol,
		Elf_Word	&type,
		Elf_Sxword	&addend
	) const {
		const endianess_convertor& convertor = elf_file.get_convertor();
		const T* pEntry = reinterpret_cast<const T*>(
			relocation_section->get_data() +
			index * relocation_section->get_entry_size()
		);
		offset		= convertor( pEntry->r_offset );
		Elf_Xword tmp = convertor( pEntry->r_info );
		symbol		= get_sym_and_type<T>::get_r_sym( tmp );
		type		= get_sym_and_type<T>::get_r_type( tmp );
		addend		= convertor( pEntry->r_addend );
	}
开发者ID:kungfooman,项目名称:easyelf,代码行数:18,代码来源:relocation.hpp


示例7: generic_add_entry

	void generic_add_entry( Elf64_Addr offset, Elf_Xword info ) {
		const endianess_convertor& convertor = elf_file.get_convertor();
		T entry;
		entry.r_offset = offset;
		entry.r_info   = info;
		entry.r_offset = convertor( entry.r_offset );
		entry.r_info   = convertor( entry.r_info );
		relocation_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) );
	}
开发者ID:kungfooman,项目名称:easyelf,代码行数:9,代码来源:relocation.hpp


示例8: rebuild_exports

//Export directory rebuilder
//info - export information
//exported_functions_list - list of exported functions
//exports_section - section where export directory will be placed (must be attached to PE image)
//offset_from_section_start - offset from exports_section raw data start
//save_to_pe_headers - if true, new export directory information will be saved to PE image headers
//auto_strip_last_section - if true and exports are placed in the last section, it will be automatically stripped
//number_of_functions and number_of_names parameters don't matter in "info" when rebuilding, they're calculated independently
//characteristics, major_version, minor_version, timestamp and name are the only used members of "info" structure
//Returns new export directory information
//exported_functions_list is copied intentionally to be sorted by ordinal values later
//Name ordinals in exported function don't matter, they will be recalculated
const image_directory rebuild_exports(pe_base& pe, const export_info& info, exported_functions_list exports, section& exports_section, uint32_t offset_from_section_start, bool save_to_pe_header, bool auto_strip_last_section)
{
	//Check that exports_section is attached to this PE image
	if(!pe.section_attached(exports_section))
		throw pe_exception("Exports section must be attached to PE file", pe_exception::section_is_not_attached);

	//Needed space for strings
	uint32_t needed_size_for_strings = static_cast<uint32_t>(info.get_name().length() + 1);
	uint32_t number_of_names = 0; //Number of named functions
	uint32_t max_ordinal = 0; //Maximum ordinal number
	uint32_t ordinal_base = static_cast<uint32_t>(-1); //Minimum ordinal value
	
	if(exports.empty())
		ordinal_base = info.get_ordinal_base();

	uint32_t needed_size_for_function_names = 0; //Needed space for function name strings
	uint32_t needed_size_for_function_forwards = 0; //Needed space for function forwards names
	
	//List all exported functions
	//Calculate needed size for function list
	{
		//Also check that there're no duplicate names and ordinals
		std::set<std::string> used_function_names;
		std::set<uint16_t> used_function_ordinals;

		for(exported_functions_list::const_iterator it = exports.begin(); it != exports.end(); ++it)
		{
			const exported_function& func = (*it);
			//Calculate maximum and minimum ordinal numbers
			max_ordinal = std::max<uint32_t>(max_ordinal, func.get_ordinal());
			ordinal_base = std::min<uint32_t>(ordinal_base, func.get_ordinal());

			//Check if ordinal is unique
			if(!used_function_ordinals.insert(func.get_ordinal()).second)
				throw pe_exception("Duplicate exported function ordinal", pe_exception::duplicate_exported_function_ordinal);
			
			if(func.has_name())
			{
				//If function is named
				++number_of_names;
				needed_size_for_function_names += static_cast<uint32_t>(func.get_name().length() + 1);
				
				//Check if it's name and name ordinal are unique
				if(!used_function_names.insert(func.get_name()).second)
					throw pe_exception("Duplicate exported function name", pe_exception::duplicate_exported_function_name);
			}

			//If function is forwarded to another DLL
			if(func.is_forwarded())
				needed_size_for_function_forwards += static_cast<uint32_t>(func.get_forwarded_name().length() + 1);
		}
	}
	
	//Sort functions by ordinal value
	std::sort(exports.begin(), exports.end(), ordinal_sorter());

	//Calculate needed space for different things...
	needed_size_for_strings += needed_size_for_function_names;
	needed_size_for_strings += needed_size_for_function_forwards;
	uint32_t needed_size_for_function_name_ordinals = number_of_names * sizeof(uint16_t);
	uint32_t needed_size_for_function_name_rvas = number_of_names * sizeof(uint32_t);
	uint32_t needed_size_for_function_addresses = (max_ordinal - ordinal_base + 1) * sizeof(uint32_t);
	
	//Export directory header will be placed first
	uint32_t directory_pos = pe_utils::align_up(offset_from_section_start, sizeof(uint32_t));

	uint32_t needed_size = sizeof(image_export_directory); //Calculate needed size for export tables and strings
	//sizeof(IMAGE_EXPORT_DIRECTORY) = export directory header

	//Total needed space...
	needed_size += needed_size_for_function_name_ordinals; //For list of names ordinals
	needed_size += needed_size_for_function_addresses; //For function RVAs
	needed_size += needed_size_for_strings; //For all strings
	needed_size += needed_size_for_function_name_rvas; //For function name strings RVAs

	//Check if exports_section is last one. If it's not, check if there's enough place for exports data
	if(&exports_section != &*(pe.get_image_sections().end() - 1) && 
		(exports_section.empty() || pe_utils::align_up(exports_section.get_size_of_raw_data(), pe.get_file_alignment()) < needed_size + directory_pos))
		throw pe_exception("Insufficient space for export directory", pe_exception::insufficient_space);

	std::string& raw_data = exports_section.get_raw_data();

	//This will be done only if exports_section is the last section of image or for section with unaligned raw length of data
	if(raw_data.length() < needed_size + directory_pos)
		raw_data.resize(needed_size + directory_pos); //Expand section raw data

	//Library name will be placed after it
	uint32_t current_pos_of_function_names = static_cast<uint32_t>(info.get_name().length() + 1 + directory_pos + sizeof(image_export_directory));
//.........这里部分代码省略.........
开发者ID:Scrik,项目名称:godot,代码行数:101,代码来源:pe_exports.cpp


示例9: operator

bool section_by_raw_offset::operator()(const section& s) const
{
	return (s.get_pointer_to_raw_data() <= offset_)
		&& (s.get_pointer_to_raw_data() + s.get_size_of_raw_data() > offset_);
}
开发者ID:asinbow,项目名称:libpebliss,代码行数:5,代码来源:pe_section.cpp


示例10: rebuild_bound_imports

//imports - bound imported modules list
//imports_section - section where export directory will be placed (must be attached to PE image)
//offset_from_section_start - offset from imports_section raw data start
//save_to_pe_headers - if true, new bound import directory information will be saved to PE image headers
//auto_strip_last_section - if true and bound imports are placed in the last section, it will be automatically stripped
const image_directory rebuild_bound_imports(pe_base& pe, const bound_import_module_list& imports, section& imports_section, uint32_t offset_from_section_start, bool save_to_pe_header, bool auto_strip_last_section)
{
    //Check that exports_section is attached to this PE image
    if(!pe.section_attached(imports_section))
        throw pe_exception("Bound import section must be attached to PE file", pe_exception::section_is_not_attached);

    uint32_t directory_pos = pe_utils::align_up(offset_from_section_start, sizeof(uint32_t));
    uint32_t needed_size = sizeof(image_bound_import_descriptor) /* Ending null descriptor */;
    uint32_t needed_size_for_strings = 0;

    //Calculate needed size for bound import data
    for(bound_import_module_list::const_iterator it = imports.begin(); it != imports.end(); ++it)
    {
        const bound_import& import = *it;
        needed_size += sizeof(image_bound_import_descriptor);
        needed_size_for_strings += static_cast<uint32_t>((*it).get_module_name().length()) + 1 /* nullbyte */;

        const bound_import::ref_list& refs = import.get_module_ref_list();
        for(bound_import::ref_list::const_iterator ref_it = refs.begin(); ref_it != refs.end(); ++ref_it)
        {
            needed_size_for_strings += static_cast<uint32_t>((*ref_it).get_module_name().length()) + 1 /* nullbyte */;
            needed_size += sizeof(image_bound_forwarder_ref);
        }
    }

    needed_size += needed_size_for_strings;

    //Check if imports_section is last one. If it's not, check if there's enough place for bound import data
    if(&imports_section != &*(pe.get_image_sections().end() - 1) &&
            (imports_section.empty() || pe_utils::align_up(imports_section.get_size_of_raw_data(), pe.get_file_alignment()) < needed_size + directory_pos))
        throw pe_exception("Insufficient space for bound import directory", pe_exception::insufficient_space);

    std::string& raw_data = imports_section.get_raw_data();

    //This will be done only if imports_section is the last section of image or for section with unaligned raw length of data
    if(raw_data.length() < needed_size + directory_pos)
        raw_data.resize(needed_size + directory_pos); //Expand section raw data

    uint32_t current_pos_for_structures = directory_pos;
    uint32_t current_pos_for_strings = current_pos_for_structures + needed_size - needed_size_for_strings;

    for(bound_import_module_list::const_iterator it = imports.begin(); it != imports.end(); ++it)
    {
        const bound_import& import = *it;
        image_bound_import_descriptor descriptor;
        descriptor.NumberOfModuleForwarderRefs = static_cast<uint16_t>(import.get_module_ref_list().size());
        descriptor.OffsetModuleName = static_cast<uint16_t>(current_pos_for_strings - directory_pos);
        descriptor.TimeDateStamp = import.get_timestamp();

        memcpy(&raw_data[current_pos_for_structures], &descriptor, sizeof(descriptor));
        current_pos_for_structures += sizeof(descriptor);

        size_t length = import.get_module_name().length() + 1 /* nullbyte */;
        memcpy(&raw_data[current_pos_for_strings], import.get_module_name().c_str(), length);
        current_pos_for_strings += static_cast<uint32_t>(length);

        const bound_import::ref_list& refs = import.get_module_ref_list();
        for(bound_import::ref_list::const_iterator ref_it = refs.begin(); ref_it != refs.end(); ++ref_it)
        {
            const bound_import_ref& ref = *ref_it;
            image_bound_forwarder_ref ref_descriptor = {0};
            ref_descriptor.OffsetModuleName = static_cast<uint16_t>(current_pos_for_strings - directory_pos);
            ref_descriptor.TimeDateStamp = ref.get_timestamp();

            memcpy(&raw_data[current_pos_for_structures], &ref_descriptor, sizeof(ref_descriptor));
            current_pos_for_structures += sizeof(ref_descriptor);

            length = ref.get_module_name().length() + 1 /* nullbyte */;
            memcpy(&raw_data[current_pos_for_strings], ref.get_module_name().c_str(), length);
            current_pos_for_strings += static_cast<uint32_t>(length);
        }
    }

    //Adjust section raw and virtual sizes
    pe.recalculate_section_sizes(imports_section, auto_strip_last_section);

    image_directory ret(pe.rva_from_section_offset(imports_section, directory_pos), needed_size);

    //If auto-rewrite of PE headers is required
    if(save_to_pe_header)
    {
        pe.set_directory_rva(image_directory_entry_bound_import, ret.get_rva());
        pe.set_directory_size(image_directory_entry_bound_import, ret.get_size());
    }

    return ret;
}
开发者ID:Scrik,项目名称:godot,代码行数:92,代码来源:pe_bound_import.cpp


示例11: operator

		bool operator()(const section& in_section) {return in_section.contains(x);};
开发者ID:imzhukov,项目名称:video_3.0.0,代码行数:1,代码来源:piecewise.cpp


示例12: parse_config_internal

void parse_config_internal(const config *help_cfg, const config *section_cfg,
						   section &sec, int level)
{
	if (level > max_section_level) {
		std::cerr << "Maximum section depth has been reached. Maybe circular dependency?"
				  << std::endl;
	}
	else if (section_cfg != NULL) {
		const std::vector<std::string> sections = utils::quoted_split((*section_cfg)["sections"]);
		sec.level = level;
		std::string id = level == 0 ? "toplevel" : (*section_cfg)["id"].str();
		if (level != 0) {
			if (!is_valid_id(id)) {
				std::stringstream ss;
				ss << "Invalid ID, used for internal purpose: '" << id << "'";
				throw help::parse_error(ss.str());
			}
		}
		t_string title = level == 0 ? "" : (*section_cfg)["title"].t_str();
		sec.id = id;
		sec.title = title;
		std::vector<std::string>::const_iterator it;
		// Find all child sections.
		for (it = sections.begin(); it != sections.end(); ++it) {
			if (const config &child_cfg = help_cfg->find_child("section", "id", *it))
			{
				section child_section;
				parse_config_internal(help_cfg, &child_cfg, child_section, level + 1);
				sec.add_section(child_section);
			}
			else {
				std::stringstream ss;
				ss << "Help-section '" << *it << "' referenced from '"
				   << id << "' but could not be found.";
				throw help::parse_error(ss.str());
			}
		}

		generate_sections(help_cfg, (*section_cfg)["sections_generator"], sec, level);
		//TODO: harmonize topics/sections sorting
		if ((*section_cfg)["sort_sections"] == "yes") {
			std::sort(sec.sections.begin(),sec.sections.end(), section_less());
		}

		bool sort_topics = false;
		bool sort_generated = true;

		if ((*section_cfg)["sort_topics"] == "yes") {
		  sort_topics = true;
		  sort_generated = false;
		} else if ((*section_cfg)["sort_topics"] == "no") {
		  sort_topics = false;
    	  sort_generated = false;
		} else if ((*section_cfg)["sort_topics"] == "generated") {
		  sort_topics = false;
		  sort_generated = true;
		} else if ((*section_cfg)["sort_topics"] != "") {
		  std::stringstream ss;
		  ss << "Invalid sort option: '" << (*section_cfg)["sort_topics"] << "'";
		  throw help::parse_error(ss.str());
		}

		std::vector<topic> generated_topics =
		generate_topics(sort_generated,(*section_cfg)["generator"]);

		const std::vector<std::string> topics_id = utils::quoted_split((*section_cfg)["topics"]);
		std::vector<topic> topics;

		// Find all topics in this section.
		for (it = topics_id.begin(); it != topics_id.end(); ++it) {
			if (const config &topic_cfg = help_cfg->find_child("topic", "id", *it))
			{
				t_string text = topic_cfg["text"].t_str();
				text += generate_topic_text(topic_cfg["generator"], help_cfg, sec, generated_topics);
				topic child_topic(topic_cfg["title"], topic_cfg["id"], text);
				if (!is_valid_id(child_topic.id)) {
					std::stringstream ss;
					ss << "Invalid ID, used for internal purpose: '" << id << "'";
					throw help::parse_error(ss.str());
				}
				topics.push_back(child_topic);
			}
			else {
				std::stringstream ss;
				ss << "Help-topic '" << *it << "' referenced from '" << id
				   << "' but could not be found." << std::endl;
				throw help::parse_error(ss.str());
			}
		}

		if (sort_topics) {
			std::sort(topics.begin(),topics.end(), title_less());
			std::sort(generated_topics.begin(),
			  generated_topics.end(), title_less());
			std::merge(generated_topics.begin(),
			  generated_topics.end(),topics.begin(),topics.end()
			  ,std::back_inserter(sec.topics),title_less());
		}
		else {
			std::copy(topics.begin(), topics.end(),
//.........这里部分代码省略.........
开发者ID:hyrio,项目名称:War-Of-Kingdom,代码行数:101,代码来源:help.cpp


示例13: clear_book

void clear_book()
{
	game_cfg = NULL;
	map = NULL;
	hidden_sections.clear();
}
开发者ID:hyrio,项目名称:War-Of-Kingdom,代码行数:6,代码来源:help.cpp


示例14: generate_contents

void generate_contents(const std::string& tag, section& toplevel)
{
	toplevel.clear();
	hidden_sections.clear();

	const config *help_config = &game_cfg->find_child("book", "id", tag);
	if (!*help_config) {
		help_config = &dummy_cfg;
	}
	try {
		toplevel = parse_config(help_config);
		// Create a config object that contains everything that is
		// not referenced from the toplevel element. Read this
		// config and save these sections and topics so that they
		// can be referenced later on when showing help about
		// specified things, but that should not be shown when
		// opening the help browser in the default manner.
		config hidden_toplevel;
		std::stringstream ss;
		BOOST_FOREACH (const config &section, help_config->child_range("section"))
		{
			const std::string id = section["id"];
			if (find_section(toplevel, id) == NULL) {
				// This section does not exist referenced from the
				// toplevel. Hence, add it to the hidden ones if it
				// is not referenced from another section.
				if (!section_is_referenced(id, *help_config)) {
					if (ss.str() != "") {
						ss << ",";
					}
					ss << id;
				}
			}
		}
		hidden_toplevel["sections"] = ss.str();
		ss.str("");
		BOOST_FOREACH (const config &topic, help_config->child_range("topic"))
		{
			const std::string id = topic["id"];
			if (find_topic(toplevel, id) == NULL) {
				if (!topic_is_referenced(id, *help_config)) {
					if (ss.str() != "") {
						ss << ",";
					}
					ss << id;
				}
			}
		}
		hidden_toplevel["topics"] = ss.str();
		config hidden_cfg = *help_config;
		// Change the toplevel to our new, custom built one.
		hidden_cfg.clear_children("toplevel");
		hidden_cfg.add_child("toplevel", hidden_toplevel);
		hidden_sections = parse_config(&hidden_cfg);
	}
	catch (help::parse_error e) {
		std::stringstream msg;
		msg << "Parse error when parsing help text: '" << e.message << "'";
		VALIDATE(false, msg.str());
	}
}
开发者ID:hyrio,项目名称:War-Of-Kingdom,代码行数:61,代码来源:help.cpp


示例15: rebuild_image_config_base

const image_directory rebuild_image_config_base(pe_base& pe, const image_config_info& info, section& image_config_section, uint32_t offset_from_section_start, bool write_se_handlers, bool write_lock_prefixes, bool save_to_pe_header, bool auto_strip_last_section)
{
	//Check that image_config_section is attached to this PE image
	if(!pe.section_attached(image_config_section))
		throw pe_exception("Image Config section must be attached to PE file", pe_exception::section_is_not_attached);
	
	uint32_t alignment = pe_utils::align_up(offset_from_section_start, sizeof(typename PEClassType::BaseSize)) - offset_from_section_start;

	uint32_t needed_size = sizeof(typename PEClassType::ConfigStruct); //Calculate needed size for Image Config table
	
	uint32_t image_config_data_pos = offset_from_section_start + alignment;

	uint32_t current_pos_of_se_handlers = 0;
	uint32_t current_pos_of_lock_prefixes = 0;
	
	if(write_se_handlers)
	{
		current_pos_of_se_handlers = needed_size + image_config_data_pos;
		needed_size += static_cast<uint32_t>(info.get_se_handler_rvas().size()) * sizeof(uint32_t); //RVAs of SE Handlers
	}
	
	if(write_lock_prefixes)
	{
		current_pos_of_lock_prefixes = needed_size + image_config_data_pos;
		needed_size += static_cast<uint32_t>((info.get_lock_prefix_rvas().size() + 1) * sizeof(typename PEClassType::BaseSize)); //VAs of Lock Prefixes (and ending null element)
	}

	//Check if image_config_section is last one. If it's not, check if there's enough place for Image Config data
	if(&image_config_section != &*(pe.get_image_sections().end() - 1) && 
		(image_config_section.empty() || pe_utils::align_up(image_config_section.get_size_of_raw_data(), pe.get_file_alignment()) < needed_size + image_config_data_pos))
		throw pe_exception("Insufficient space for TLS directory", pe_exception::insufficient_space);

	std::string& raw_data = image_config_section.get_raw_data();

	//This will be done only if image_config_section is the last section of image or for section with unaligned raw length of data
	if(raw_data.length() < needed_size + image_config_data_pos)
		raw_data.resize(needed_size + image_config_data_pos); //Expand section raw data

	//Create and fill Image Config structure
	typename PEClassType::ConfigStruct image_config_section_struct = {0};
	image_config_section_struct.Size = sizeof(image_config_section_struct);
	image_config_section_struct.TimeDateStamp = info.get_time_stamp();
	image_config_section_struct.MajorVersion = info.get_major_version();
	image_config_section_struct.MinorVersion = info.get_minor_version();
	image_config_section_struct.GlobalFlagsClear = info.get_global_flags_clear();
	image_config_section_struct.GlobalFlagsSet = info.get_global_flags_set();
	image_config_section_struct.CriticalSectionDefaultTimeout = info.get_critical_section_default_timeout();
	image_config_section_struct.DeCommitFreeBlockThreshold = static_cast<typename PEClassType::BaseSize>(info.get_decommit_free_block_threshold());
	image_config_section_struct.DeCommitTotalFreeThreshold = static_cast<typename PEClassType::BaseSize>(info.get_decommit_total_free_threshold());
	image_config_section_struct.MaximumAllocationSize = static_cast<typename PEClassType::BaseSize>(info.get_max_allocation_size());
	image_config_section_struct.VirtualMemoryThreshold = static_cast<typename PEClassType::BaseSize>(info.get_virtual_memory_threshold());
	image_config_section_struct.ProcessHeapFlags = info.get_process_heap_flags();
	image_config_section_struct.ProcessAffinityMask = static_cast<typename PEClassType::BaseSize>(info.get_process_affinity_mask());
	image_config_section_struct.CSDVersion = info.get_service_pack_version();
	image_config_section_struct.EditList = static_cast<typename PEClassType::BaseSize>(info.get_edit_list_va());
	image_config_section_struct.SecurityCookie = static_cast<typename PEClassType::BaseSize>(info.get_security_cookie_va());
	image_config_section_struct.SEHandlerCount = static_cast<typename PEClassType::BaseSize>(info.get_se_handler_rvas().size());
	

	if(write_se_handlers)
	{
		if(info.get_se_handler_rvas().empty())
		{
			write_se_handlers = false;
			image_config_section_struct.SEHandlerTable = 0;
		}
		else
		{
			typename PEClassType::BaseSize va;
			pe.rva_to_va(pe.rva_from_section_offset(image_config_section, current_pos_of_se_handlers), va);
			image_config_section_struct.SEHandlerTable = va;
		}
	}
	else
	{
		image_config_section_struct.SEHandlerTable = static_cast<typename PEClassType::BaseSize>(info.get_se_handler_table_va());
	}

	if(write_lock_prefixes)
	{
		if(info.get_lock_prefix_rvas().empty())
		{
			write_lock_prefixes = false;
			image_config_section_struct.LockPrefixTable = 0;
		}
		else
		{
			typename PEClassType::BaseSize va;
			pe.rva_to_va(pe.rva_from_section_offset(image_config_section, current_pos_of_lock_prefixes), va);
			image_config_section_struct.LockPrefixTable = va;
		}
	}
	else
	{
		image_config_section_struct.LockPrefixTable = static_cast<typename PEClassType::BaseSize>(info.get_lock_prefix_table_va());
	}

	//Write image config section
	memcpy(&raw_data[image_config_data_pos], &image_config_section_struct, sizeof(image_config_section_struct));

//.........这里部分代码省略.........
开发者ID:Scrik,项目名称:godot,代码行数:101,代码来源:pe_load_config.cpp


示例16: rebuild_resource_directory

//Helper function to rebuild resource directory
void rebuild_resource_directory(pe_base& pe, section& resource_section, resource_directory& root, uint32_t& current_structures_pos, uint32_t& current_data_pos, uint32_t& current_strings_pos, uint32_t offset_from_section_start)
{
    //Create resource directory
    image_resource_directory dir = {0};
    dir.Characteristics = root.get_characteristics();
    dir.MajorVersion = root.get_major_version();
    dir.MinorVersion = root.get_minor_version();
    dir.TimeDateStamp = root.get_timestamp();
    
    {
        resource_directory::entry_list& entries = root.get_entry_list();
        std::sort(entries.begin(), entries.end(), entry_sorter());
    }

    //Calculate number of named and ID entries
    for(resource_directory::entry_list::const_iterator it = root.get_entry_list().begin(); it != root.get_entry_list().end(); ++it)
    {
        if((*it).is_named())
            ++dir.NumberOfNamedEntries;
        else
            ++dir.NumberOfIdEntries;
    }
    
    std::string& raw_data = resource_section.get_raw_data();

    //Save resource directory
    memcpy(&raw_data[current_structures_pos], &dir, sizeof(dir));
    current_structures_pos += sizeof(dir);

    uint32_t this_current_structures_pos = current_structures_pos;

    current_structures_pos += sizeof(image_resource_directory_entry) * (dir.NumberOfNamedEntries + dir.NumberOfIdEntries);

    //Create all resource directory entries
    for(resource_directory::entry_list::iterator it = root.get_entry_list().begin(); it != root.get_entry_list().end(); ++it)
    {
        image_resource_directory_entry entry;
        if((*it).is_named())
        {
            entry.NameItem.Name = 0x80000000 | (current_strings_pos - offset_from_section_start);
            uint16_t unicode_length = static_cast<uint16_t>((*it).get_name().length());
            memcpy(&raw_data[current_strings_pos], &unicode_length, sizeof(unicode_length));
            current_strings_pos += sizeof(unicode_length);

#ifdef PE_BLISS_WINDOWS
            memcpy(&raw_data[current_strings_pos], (*it).get_name().c_str(), (*it).get_name().length() * sizeof(uint16_t) + sizeof(uint16_t) /* unicode */);
#else
            {
                u16string str(pe_utils::to_ucs2((*it).get_name()));
                memcpy(&raw_data[current_strings_pos], str.c_str(), (*it).get_name().length() * sizeof(uint16_t) + sizeof(uint16_t) /* unicode */);
            }
#endif

            current_strings_pos += static_cast<uint32_t>((*it).get_name().length() * sizeof(uint16_t) + sizeof(uint16_t) /* unicode */);
        }
        else
        {
            entry.NameItem.Name = (*it).get_id();
        }

        if((*it).includes_data())
        {
            current_data_pos = pe_utils::align_up(current_data_pos, sizeof(uint32_t));
            image_resource_data_entry data_entry = {0};
            data_entry.CodePage = (*it).get_data_entry().get_codepage();
            data_entry.Size = static_cast<uint32_t>((*it).get_data_entry().get_data().length());
            data_entry.OffsetToData = pe.rva_from_section_offset(resource_section, current_data_pos + sizeof(data_entry));
            
            entry.DirItem.OffsetToData = current_data_pos - offset_from_section_start;

            memcpy(&raw_data[current_data_pos], &data_entry, sizeof(data_entry));
            current_data_pos += sizeof(data_entry);
            
            memcpy(&raw_data[current_data_pos], (*it).get_data_entry().get_data().data(), data_entry.Size);
            current_data_pos += data_entry.Size;

            memcpy(&raw_data[this_current_structures_pos], &entry, sizeof(entry));
            this_current_structures_pos += sizeof(entry);
        }
        else
        {
            entry.DirItem.OffsetToData = 0x80000000 | (current_structures_pos - offset_from_section_start);

            memcpy(&raw_data[this_current_structures_pos], &entry, sizeof(entry));
            this_current_structures_pos += sizeof(entry);

            rebuild_resource_directory(pe, resource_section, (*it).get_resource_directory(), current_structures_pos, current_data_pos, current_strings_pos, offset_from_section_start);
        }
    }
}
开发者ID:apriorit,项目名称:portable-executable-library,代码行数:91,代码来源:pe_resources.cpp


示例17: rebuild_relocations

//Simple relocations rebuilder
//To keep PE file working, don't remove any of existing relocations in
//relocation_table_list returned by a call to get_relocations() function
//auto_strip_last_section - if true and relocations are placed in the last section, it will be automatically stripped
//offset_from_section_start - offset from the beginning of reloc_section, where relocations data will be situated
//If save_to_pe_header is true, PE header will be modified automatically
const image_directory rebuild_relocations(pe_base& pe, const relocation_table_list& relocs, section& reloc_section, uint32_t offset_from_section_start, bool save_to_pe_header, bool auto_strip_last_section)
{
    //Check that reloc_section is attached to this PE image
    if(!pe.section_attached(reloc_section))
        throw pe_exception("Relocations section must be attached to PE file", pe_exception::section_is_not_attached);

    uint32_t current_reloc_data_pos = pe_utils::align_up(offset_from_section_start, sizeof(uint32_t));

    uint32_t needed_size = current_reloc_data_pos - offset_from_section_start; //Calculate needed size for relocation tables
    uint32_t size_delta = needed_size;

    uint32_t start_reloc_pos = current_reloc_data_pos;

    //Enumerate relocation tables
    for(relocation_table_list::const_iterator it = relocs.begin(); it != relocs.end(); ++it)
    {
        needed_size += static_cast<uint32_t>((*it).get_relocations().size() * sizeof(uint16_t) /* relocations */ + sizeof(image_base_relocation) /* table header */);
        //End of each table will be DWORD-aligned
        if((start_reloc_pos + needed_size - size_delta) % sizeof(uint32_t))
            needed_size += sizeof(uint16_t); //Align it with IMAGE_REL_BASED_ABSOLUTE relocation
    }

    //Check if reloc_section is last one. If it's not, check if there's enough place for relocations data
    if(&reloc_section != &*(pe.get_image_sections().end() - 1) &&
            (reloc_section.empty() || pe_utils::align_up(reloc_section.get_size_of_raw_data(), pe.get_file_alignment()) < needed_size + current_reloc_data_pos))
        throw pe_exception("Insufficient space for relocations directory", pe_exception::insufficient_space);

    std::string& raw_data = reloc_section.get_raw_data();

    //This will be done only if reloc_section is the last section of image or for section with unaligned raw length of data
    if(raw_data.length() < needed_size + current_reloc_data_pos)
        raw_data.resize(pe_utils::align_up(needed_size + current_reloc_data_pos, pe.get_file_alignment())); //Expand section raw data

    //Enumerate relocation tables
    for(relocation_table_list::const_iterator it = relocs.begin(); it != relocs.end(); ++it)
    {
        //Create relocation table header
        image_base_relocation reloc;
        reloc.VirtualAddress = (*it).get_rva();
        const relocation_table::relocation_list& reloc_list = (*it).get_relocations();
        reloc.SizeOfBlock = static_cast<uint32_t>(sizeof(image_base_relocation) + sizeof(uint16_t) * reloc_list.size());
        if((reloc_list.size() * sizeof(uint16_t)) % sizeof(uint32_t)) //If we must align end of relocation table
            reloc.SizeOfBlock += sizeof(uint16_t);

        memcpy(&raw_data[current_reloc_data_pos], &reloc, sizeof(reloc));
        current_reloc_data_pos += sizeof(reloc);

        //Enumerate relocations in table
        for(relocation_table::relocation_list::const_iterator r = reloc_list.begin(); r != reloc_list.end(); ++r)
        {
            //Save relocations
            uint16_t reloc_value = (*r).get_item();
            memcpy(&raw_data[current_reloc_data_pos], &reloc_value, sizeof(reloc_value));
            current_reloc_data_pos += sizeof(reloc_value);
        }

        if(current_reloc_data_pos % sizeof(uint32_t)) //If end of table is not DWORD-aligned
        {
            memset(&raw_data[current_reloc_data_pos], 0, sizeof(uint16_t)); //Align it with IMAGE_REL_BASED_ABSOLUTE relocation
            current_reloc_data_pos += sizeof(uint16_t);
        }
    }

    image_directory ret(pe.rva_from_section_offset(reloc_section, start_reloc_pos), needed_size - size_delta);

    //Adjust section raw and virtual sizes
    pe.recalculate_section_sizes(reloc_section, auto_strip_last_section);

    //If auto-rewrite of PE headers is required
    if(save_to_pe_header)
    {
        pe.set_directory_rva(image_directory_entry_basereloc, ret.get_rva());
        pe.set_directory_size(image_directory_entry_basereloc, ret.get_size());

        pe.clear_characteristics_flags(image_file_relocs_stripped);
        pe.set_dll_characteristics(pe.get_dll_characteristics() | image_dllcharacteristics_dynamic_base);
    }

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


示例18: get_symbol_table_index


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ secure_vector类代码示例发布时间:2022-05-31
下一篇:
C++ search_path类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap