示例#1
0
 public static void close(Object o) {
   try {
     if (o == null) return;
     if (o instanceof InputStream) {
       ((InputStream) o).close();
     } else if (o instanceof OutputStream) {
       ((OutputStream) o).flush();
       ((OutputStream) o).close();
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#2
0
 public static void copyStream(InputStream in, OutputStream out) throws IOException {
   byte[] data = new byte[BUFFER];
   int currentByte;
   while ((currentByte = in.read(data, 0, BUFFER)) != -1) {
     out.write(data, 0, currentByte);
   }
 }
示例#3
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);
      }
    }
  }