bool resource_directory::entry_finder::operator()(const resource_directory_entry& entry) const
{
    if(named_)
        return entry.is_named() && entry.get_name() == name_;
    else
        return !entry.is_named() && entry.get_id() == id_;
}
//Helper function to rebuild resource directory
bool entry_sorter::operator()(const resource_directory_entry& entry1, const resource_directory_entry& entry2) const
{
    if(entry1.is_named() && entry2.is_named())
        return entry1.get_name() < entry2.get_name();
    else if(!entry1.is_named() && !entry2.is_named())
        return entry1.get_id() < entry2.get_id();
    else
        return entry1.is_named();
}
//Adds resource_directory_entry
void resource_directory::add_resource_directory_entry(const resource_directory_entry& entry)
{
    entries_.push_back(entry);
    if(entry.is_named())
        ++number_of_named_entries_;
    else
        ++number_of_id_entries_;
}
Beispiel #4
0
//Helper to add/replace resource
void pe_resource_manager::add_resource(const std::string& data, resource_directory_entry& new_root_entry, const resource_directory::entry_finder& root_finder, resource_directory_entry& new_entry, const resource_directory::entry_finder& finder, uint32_t language, uint32_t codepage, uint32_t timestamp)
{
	//Search for resource type
	resource_directory::entry_list* entries = &root_dir_edit_.get_entry_list();
	resource_directory::entry_list::iterator it = std::find_if(entries->begin(), entries->end(), root_finder);
	if(it == entries->end())
	{
		//Add resource type directory, if it was not found
		resource_directory dir;
		dir.set_timestamp(timestamp);
		new_root_entry.add_resource_directory(dir);
		entries->push_back(new_root_entry);
		it = entries->end() - 1;
	}

	//Search for resource name/ID directory with "finder"
	entries = &(*it).get_resource_directory().get_entry_list();
	it = std::find_if(entries->begin(), entries->end(), finder);
	if(it == entries->end())
	{
		//Add resource name/ID directory, if it was not found
		resource_directory dir;
		dir.set_timestamp(timestamp);
		new_entry.add_resource_directory(dir);
		entries->push_back(new_entry);
		it = entries->end() - 1;
	}

	//Search for data resource entry by language
	entries = &(*it).get_resource_directory().get_entry_list();
	it = std::find_if(entries->begin(), entries->end(), resource_directory::id_entry_finder(language));
	if(it != entries->end())
		entries->erase(it); //Erase it, if found

	//Add new data entry
	resource_directory_entry new_dir_data_entry;
	resource_data_entry data_dir(data, codepage);
	new_dir_data_entry.add_data_entry(data_dir);
	new_dir_data_entry.set_id(language);
	entries->push_back(new_dir_data_entry);
}
//Copy constructor
resource_directory_entry::resource_directory_entry(const resource_directory_entry& other)
    :id_(other.id_), name_(other.name_), includes_data_(other.includes_data_), named_(other.named_)
{
    //If union'ed pointer is not zero
    if(other.ptr_.data_)
    {
        if(other.includes_data())
            ptr_.data_ = new resource_data_entry(*other.ptr_.data_);
        else
            ptr_.dir_ = new resource_directory(*other.ptr_.dir_);
    }
}
Beispiel #6
0
bool pe_resource_viewer::has_id::operator()(const resource_directory_entry& entry) const
{
	return !entry.is_named();
}
bool resource_directory::name_entry_finder::operator()(const resource_directory_entry& entry) const
{
    return entry.is_named() && entry.get_name() == name_;
}
bool resource_directory::id_entry_finder::operator()(const resource_directory_entry& entry) const
{
    return !entry.is_named() && entry.get_id() == id_;
}