bool elf_readert::has_section(const std::string &name) const { for(unsigned i=0; i<number_of_sections; i++) if(section_name(i)==name) return true; return false; }
int FWeaponSlots::RestoreSlots(FConfigFile *config, const char *section) { FString section_name(section); const char *key, *value; int slotsread = 0; section_name += ".Weapons"; if (!config->SetSection(section_name)) { return 0; } while (config->NextInSection (key, value)) { if (strnicmp (key, "Slot[", 5) != 0 || key[5] < '0' || key[5] > '0'+NUM_WEAPON_SLOTS || key[6] != ']' || key[7] != 0) { continue; } Slots[key[5] - '0'].AddWeaponList(value, true); slotsread++; } return slotsread; }
void core_target::get_core_register_section (struct regcache *regcache, const struct regset *regset, const char *name, int section_min_size, int which, const char *human_name, bool required) { struct bfd_section *section; bfd_size_type size; char *contents; bool variable_size_section = (regset != NULL && regset->flags & REGSET_VARIABLE_SIZE); thread_section_name section_name (name, regcache->ptid ()); section = bfd_get_section_by_name (core_bfd, section_name.c_str ()); if (! section) { if (required) warning (_("Couldn't find %s registers in core file."), human_name); return; } size = bfd_section_size (core_bfd, section); if (size < section_min_size) { warning (_("Section `%s' in core file too small."), section_name.c_str ()); return; } if (size != section_min_size && !variable_size_section) { warning (_("Unexpected size of section `%s' in core file."), section_name.c_str ()); } contents = (char *) alloca (size); if (! bfd_get_section_contents (core_bfd, section, contents, (file_ptr) 0, size)) { warning (_("Couldn't read %s registers from `%s' section in core file."), human_name, section_name.c_str ()); return; } if (regset != NULL) { regset->supply_regset (regset, regcache, -1, contents, size); return; } gdb_assert (m_core_vec != nullptr); m_core_vec->core_read_registers (regcache, contents, size, which, ((CORE_ADDR) bfd_section_vma (core_bfd, section))); }
static bool write_config_ini(Properties& config, const char* path) { FILE* config_file = fopen(path, "w"); if (config_file == NULL) return false; Properties::Iterator it(&config); while (const char* name = it.next()) { BaseString section_name(name); fprintf(config_file, "[%s]\n", section_name.substr(0, section_name.lastIndexOf('_')).c_str()); const Properties* p; if (!config.get(name, &p)) return false; Properties::Iterator it2(p); while (const char* name2 = it2.next()) { PropertiesType type; if (!p->getTypeOf(name2, &type)) return false; switch (type) { case PropertiesType_Uint32: { Uint32 value; if (!p->get(name2, &value)) return false; fprintf(config_file, "%s=%u\n", name2, value); break; } case PropertiesType_char: { const char* value; if (!p->get(name2, &value)) return false; fprintf(config_file, "%s=%s\n", name2, value); break; } default: abort(); break; } } fprintf(config_file, "\n"); } fclose(config_file); return true; }
void dump_section_header(struct elf_file *file, Elf32_Shdr *header) { printf("%-20s", section_name(file, header)); printf("%u\t", header->sh_type); printf("0x%8.8X\t", header->sh_addr); printf("%u\t", header->sh_offset); printf("%u\t", header->sh_size); printf("%u\t", header->sh_flags); printf("%u\t", header->sh_link); printf("%u\t", header->sh_info); printf("%u\t", header->sh_addralign); printf("%u\n", header->sh_entsize); }
void RuleEvaluator::extractSection_(INIFile& file, const String& symbol) { // assemble the section name String section_name(prefix_ + ":" + symbol); // abort if the INI file does not contain the requested section if (!file.hasSection(section_name)) { return; } // create a new entry for symbol if (!rule_map_.has(symbol)) { rule_map_.insert(symbol, list<pair<Expression, String> >()); } // iterate over all lines of the respective section INIFile::LineIterator it = file.getSectionFirstLine(section_name); ++it;//skip section line for (; +it ; it.getSectionNextLine()) { String line(*it); // empty lines or comment lines (starting with ';' or '#') are ignored if (line.has('=') && (line[0] != ';') && (line[0] != '#')) { if (line[0] == '=') { Log.error() << "RuleEvaluator:: invalid rule in line: " << line << endl; continue; } String value = line.before("="); String expression_string; if (line.after("=").isValid()) { expression_string = line.after("="); } expression_string.trim(); value.trim(); // push the expression into the list rule_map_[symbol].push_back(pair<Expression, String>(Expression(expression_string), value)); } } }
bool INIFile::appendLine(const String& sectionName, const String& line) { String section_name(sectionName); if (section_name == "") { SectionIterator it(sections_.end()); it--; section_name = it->getName(); } if (!hasSection(section_name) || line[0] == '[') { Log.error() << "In INIFile " << filename_ << " , error while appending line: " << line << " . Illegal section-name: " << sectionName << endl; return false; } Section& section(*getSection(section_name)); // key? if (line.hasSubstring("=", 1)) { String key(line.before("=")); key.trim(); if (section.key_map_.has(key) && check_duplicate_keys_) { Log.error() << "In INIFile " << filename_ << " , error while appending line: " << line << " . Key '" << key << "' already exists in section." << endl; return false; } section.lines_.push_back(line); list<String >::iterator line_it(section.lines_.end()); line_it--; section.key_map_[key] = line_it; return true; } section.lines_.push_back(line); return true; }
void dump_relocations(struct elf_file *file, Elf32_Shdr *header) { char *name = string_entry(file, file->sh_string_table, header->sh_name); if (header->sh_type != SHT_REL) { fprintf(stderr, "%s is not a relocation section\n", name); return; } char *type_name = "unknown"; if (header->sh_type == SHT_REL) type_name = "SHT_REL"; if (header->sh_type == SHT_RELA) type_name = "SHT_RELA"; printf("\nRelocation section: %s [%s]\n", name, type_name); if (header->sh_entsize != sizeof(Elf32_Rel)) { fprintf(stderr, "table entry size (%d) is not sizeof(Elf32_Rel) [%zu]\n", header->sh_entsize, sizeof(Elf32_Rel)); return; } if (header->sh_size % header->sh_entsize) { fprintf(stderr, "section size is not a multiple of entrysize (%d/%d)\n", header->sh_size, header->sh_entsize); return; } size_t entry_count = header->sh_size / header->sh_entsize; Elf32_Sym *symbols = (Elf32_Sym *)(file->file_data + file->symbol_table->sh_offset); Elf32_Rel *relocations = (Elf32_Rel *)(file->file_data + header->sh_offset); size_t idx; printf("Idx Name value size offset section type\n"); for (idx = 0; idx < entry_count; idx++) { Elf32_Rel *entry = relocations + idx; Elf32_Sym *symbol = symbols + ELF32_R_SYM(entry->r_info); printf("%4.4zu: %-24s %8.8X %4.4X %6X %-16s %s\n", idx, symbol_name(file, symbol), symbol->st_value, symbol->st_size, entry->r_offset, section_name(file, section_header(file, symbol->st_shndx)), relocation_type(ELF32_R_TYPE(entry->r_info))); } }
//! The constructor reads parameters from the stream explicit settings(std::basic_istream< char_type >& strm) { typedef typename string_type::iterator str_iterator; std::locale loc = strm.getloc(); typename sections_t::iterator current_section = m_Sections.end(); string_type line; for (unsigned int line_counter = 1; strm.good(); ++line_counter) { line.clear(); std::getline(strm, line); boost::algorithm::trim(line, loc); // Skipping empty lines and comments // NOTE: The comments are only allowed to be the whole line. // Comments beginning in the middle of the line are not supported. if (!line.empty() && line[0] != constants::char_comment) { // Check if the line is a section starter if (line[0] == constants::char_section_bracket_left) { str_iterator it = std::find(line.begin() + 1, line.end(), constants::char_section_bracket_right); string_type section_name(line.begin() + 1, it); boost::algorithm::trim(section_name, loc); if (it != line.end() && !section_name.empty()) { // Creating a new section current_section = m_Sections.insert(std::make_pair(section_name, params_t())).first; } else { // The section starter is broken std::ostringstream descr; descr << "At line " << line_counter << ". The section header is invalid."; boost::log::aux::throw_exception(std::runtime_error(descr.str())); } } else { // Check that we've already started a section if (current_section != m_Sections.end()) { // Find the '=' between the parameter name and value str_iterator it = std::find(line.begin(), line.end(), constants::char_equal); string_type param_name(line.begin(), it); boost::algorithm::trim_right(param_name, loc); if (it != line.end() && !param_name.empty()) { // Put the parameter value into the map string_type param_value(++it, line.end()); boost::algorithm::trim_left(param_value, loc); if (param_value.size() >= 2 && param_value[0] == constants::char_quote && *param_value.rbegin() == constants::char_quote) { param_value = param_value.substr(1, param_value.size() - 2); } current_section->second[param_name] = param_value; } else { // The parameter name is not valid std::ostringstream descr; descr << "At line " << line_counter << ". Parameter description is not valid."; boost::log::aux::throw_exception(std::runtime_error(descr.str())); } } else { // The parameter encountered before any section starter std::ostringstream descr; descr << "At line " << line_counter << ". Parameters are only allowed in sections."; boost::log::aux::throw_exception(std::runtime_error(descr.str())); } } } } }