/** * @param section * @param index * @return * @throws IOException */ final String getStringFromSection(final Section section, final int index) throws IOException { if (index > section.getSize()) { return ""; } final StringBuffer str = new StringBuffer(); // Most string symbols will be less than 50 bytes in size final byte[] tmp = new byte[50]; this.efile.seek(section.getFileOffset() + index); while (true) { int len = this.efile.read(tmp); for (int i = 0; i < len; i++) { if (tmp[i] == 0) { len = 0; break; } str.append((char) tmp[i]); } if (len <= 0) { break; } } return str.toString(); }
/** * @param name * @return * @throws IOException */ public Section getSectionByName(final String name) throws IOException { final Section[] secs = getSections(); for (Section section : secs) { if (name.equals(section.getName())) { return section; } } return null; }
/** * @param type * @return * @throws IOException */ public Section[] getSections(final int type) throws IOException { final ArrayList<Section> result = new ArrayList<Section>(); final Section[] secs = getSections(); for (Section section : secs) { if (type == section.getType()) { result.add(section); } } return result.toArray(new Section[result.size()]); }
/** * @return * @throws IOException */ public Section[] getSections() throws IOException { if (this.sections == null) { this.sections = Section.create(this, this.ehdr, this.efile); for (int i = 0; i < this.sections.length; i++) { if (this.sections[i].getType() == Section.SHT_SYMTAB) { this.syms = i; } if ((this.syms == 0) && (this.sections[i].getType() == Section.SHT_DYNSYM)) { this.syms = i; } } } return this.sections; }
/** * @param aSection * @return * @throws IOException */ private Symbol[] loadSymbolsBySection(final Section aSection) throws IOException { if (aSection == null) { return new Symbol[0]; } return aSection.loadSymbols(this.ehdr, this.efile); }