static void ApplyRelocation_PC32(UINT32 rel_offset, Symbol *symbol, Section *section, Symbol *dynsym_list, Section *sec_list) { int addend, value, rel_address, plt_address; // Get the addend value int *buffer; buffer = (int *)malloc(sizeof(int)); memcpy(buffer, section->sec_data + rel_offset, sizeof(int)); addend = *buffer; free(buffer); // P rel_address = section->sec_address + rel_offset; value = 0; /* Don't handle the outside symbol's address, so caculate the address here */ if (symbol->sym_sd_type & SYM_PLT) { Section *plt; plt = GetSectionByName(sec_list, PLT_SECTION_NAME); plt_address = plt->sec_address; int sym_address; sym_address = Relocation_PC32_PLT(symbol, dynsym_list) + plt_address; /*printf("%x %s\n", sym_address, symbol->sym_name);*/ value = sym_address + addend - rel_address; } else{ value = (int)symbol->sym_content->st_value + addend - rel_address; /*printf("%x %x %s\n", symbol->sym_content->st_value, value, symbol->sym_name);*/ } memcpy(section->sec_data + rel_offset, &value, sizeof(int)); }
Vd_item *GetSymbolVersions(Section *sec_list) { Section *version_def, *dynstr, *dynamic; version_def = GetSectionByName(sec_list, ".gnu.version_d"); dynstr = GetSectionByName(sec_list, ".dynstr"); dynamic = GetSectionByName(sec_list, ".dynamic"); int numberOfVersions; numberOfVersions = GetDynDataByTag(dynamic, DT_VERDEFNUM); Vd_item *vd_list; vd_list = FillVersionData(version_def, numberOfVersions, dynstr); return vd_list; }
bool HIDDEN FindModuleByName(const char *moduleName, Module *module) { if (!moduleName || !*moduleName || !module) return false; Section *section = GetSectionByName(moduleName); if (section == NULL) return false; return FillModule(section, module); }
/* Take the .got.plt table address as an base to find the symbol's address */ static void ApplyRelocation_GOTOFF(UINT32 rel_offset, Symbol *symbol, Section *section, Section *sec_list) { int value, gotplt_address; Section *gotplt; gotplt = GetSectionByName(sec_list, GOT_PLT_SECTION_NAME); gotplt_address = gotplt->sec_address; value = (int)symbol->sym_content->st_value - gotplt_address; memcpy(section->sec_data + rel_offset, &value, sizeof(int)); }
bool ElfReader::LoadSymbols() { bool hasSymbols = false; SectionID sec = GetSectionByName(".symtab"); if (sec != -1) { int stringSection = sections[sec].sh_link; const char* stringBase = (const char*)GetSectionDataPtr(stringSection); // We have a symbol table! Elf32_Sym* symtab = (Elf32_Sym*)(GetSectionDataPtr(sec)); int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym); for (int sym = 0; sym < numSymbols; sym++) { int size = Common::swap32(symtab[sym].st_size); if (size == 0) continue; // int bind = symtab[sym].st_info >> 4; int type = symtab[sym].st_info & 0xF; int sectionIndex = Common::swap16(symtab[sym].st_shndx); int value = Common::swap32(symtab[sym].st_value); const char* name = stringBase + Common::swap32(symtab[sym].st_name); if (bRelocate) value += sectionAddrs[sectionIndex]; int symtype = Symbol::SYMBOL_DATA; switch (type) { case STT_OBJECT: symtype = Symbol::SYMBOL_DATA; break; case STT_FUNC: symtype = Symbol::SYMBOL_FUNCTION; break; default: continue; } g_symbolDB.AddKnownSymbol(value, size, name, symtype); hasSymbols = true; } } g_symbolDB.Index(); return hasSymbols; }
static void DEH_ParseContext(deh_context_t *context) { deh_section_t *current_section = NULL; char section_name[20]; void *tag = NULL; boolean extended; char *line; // Read the header and check it matches the signature if (!CheckSignatures(context)) { DEH_Error(context, "This is not a valid dehacked patch file!"); } // Read the file while (!DEH_HadError(context)) { // Read the next line. We only allow the special extended parsing // for the BEX [STRINGS] section. extended = current_section != NULL && !strcasecmp(current_section->name, "[STRINGS]"); line = DEH_ReadLine(context, extended); // end of file? if (line == NULL) { return; } while (line[0] != '\0' && isspace(line[0])) ++line; if (line[0] == '#') { // comment DEH_ParseComment(line); continue; } if (IsWhitespace(line)) { if (current_section != NULL) { // end of section if (current_section->end != NULL) { current_section->end(context, tag); } //printf("end %s tag\n", current_section->name); current_section = NULL; } } else { if (current_section != NULL) { // parse this line current_section->line_parser(context, line, tag); } else { // possibly the start of a new section sscanf(line, "%19s", section_name); current_section = GetSectionByName(section_name); if (current_section != NULL) { tag = current_section->start(context, line); //printf("started %s tag\n", section_name); } else { //printf("unknown section name %s\n", section_name); } } } } }
static void DEH_ParseContext(deh_context_t *context) { deh_section_t *current_section = NULL; deh_section_t *prev_section = NULL; // [crispy] remember previous line parser char section_name[20]; void *tag = NULL; boolean extended; char *line; // Read the header and check it matches the signature if (!CheckSignatures(context)) { // [crispy] make non-fatal fprintf(stderr, "This is not a valid dehacked patch file!\n"); } // Read the file while (!DEH_HadError(context)) { // Read the next line. We only allow the special extended parsing // for the BEX [STRINGS] section. extended = current_section != NULL && !strcasecmp(current_section->name, "[STRINGS]"); // [crispy] save pointer to start of line, just in case DEH_SaveLineStart(context); line = DEH_ReadLine(context, extended); // end of file? if (line == NULL) { return; } while (line[0] != '\0' && isspace(line[0])) ++line; if (line[0] == '#') { // comment DEH_ParseComment(line); continue; } if (IsWhitespace(line)) { if (current_section != NULL) { // end of section if (current_section->end != NULL) { current_section->end(context, tag); } // [crispy] if this was a BEX line parser, remember it in case // the next section does not start with a section marker if (current_section->name[0] == '[') { prev_section = current_section; } else { prev_section = NULL; } //printf("end %s tag\n", current_section->name); current_section = NULL; } } else { if (current_section != NULL) { // parse this line current_section->line_parser(context, line, tag); } else { // possibly the start of a new section sscanf(line, "%19s", section_name); current_section = GetSectionByName(section_name); if (current_section != NULL) { tag = current_section->start(context, line); //printf("started %s tag\n", section_name); } else if (prev_section != NULL) { // [crispy] try this line again with the previous line parser DEH_RestoreLineStart(context); current_section = prev_section; prev_section = NULL; } else { //printf("unknown section name %s\n", section_name); } } } } }