示例#1
0
  /**
   * Reads the program segment from the ELF file and writes it to the given writer.
   *
   * @param aHeader the program segment to read;
   * @param aWriter the writer to write the read data to.
   * @throws IOException in case of I/O problems.
   */
  public void readSegment(ProgramHeader aHeader, OutputStream aWriter) throws IOException {
    this.efile.seek(aHeader.getFileOffset());

    this.efile.setEndiannes(this.ehdr.isLittleEndian());

    long size = aHeader.getFileSize();
    if (this.ehdr.is32bit()) {
      size /= 4;
    } else if (this.ehdr.is64bit()) {
      size /= 8;
    }

    while (size-- >= 0) {
      if (this.ehdr.is32bit()) {
        byte[] buf = new byte[4];
        this.efile.readFullyE(buf);
        aWriter.write(buf, 0, 4);
      } else {
        byte[] buf = new byte[8];
        this.efile.readFullyE(buf);
        aWriter.write(buf, 0, 8);
      }
    }
  }
示例#2
0
 /**
  * @return
  * @throws IOException
  */
 public ProgramHeader[] getProgramHeaders() throws IOException {
   return ProgramHeader.createHeaders(this.ehdr, this.efile);
 }