예제 #1
0
 public static DOSStub readStub(DOSHeader header, IDataReader dr) throws IOException {
   DOSStub ds = new DOSStub();
   int pos = dr.getPosition();
   int add = header.getAddressOfNewExeHeader();
   byte[] stub = new byte[add - pos];
   dr.read(stub);
   ds.setStub(stub);
   return ds;
 }
예제 #2
0
  public static DOSHeader readDos(IDataReader dr) throws IOException {
    DOSHeader dh = new DOSHeader();
    dh.setMagic(dr.readWord());
    dh.setUsedBytesInLastPage(dr.readWord());
    dh.setFileSizeInPages(dr.readWord());
    dh.setNumRelocationItems(dr.readWord());
    dh.setHeaderSizeInParagraphs(dr.readWord());
    dh.setMinExtraParagraphs(dr.readWord());
    dh.setMaxExtraParagraphs(dr.readWord());
    dh.setInitialSS(dr.readWord());
    dh.setInitialSP(dr.readWord());
    dh.setChecksum(dr.readWord());
    dh.setInitialIP(dr.readWord());
    dh.setInitialRelativeCS(dr.readWord());
    dh.setAddressOfRelocationTable(dr.readWord());
    dh.setOverlayNumber(dr.readWord());
    int[] reserved = new int[4];
    for (int i = 0; i < reserved.length; i++) {
      reserved[i] = dr.readWord();
    }
    dh.setReserved(reserved);
    dh.setOemId(dr.readWord());
    dh.setOemInfo(dr.readWord());
    int[] reserved2 = new int[10];
    for (int i = 0; i < reserved2.length; i++) {
      reserved2[i] = dr.readWord();
    }
    dh.setReserved2(reserved2);
    dh.setAddressOfNewExeHeader(dr.readDoubleWord());

    // calc stub size
    int stubSize = dh.getFileSizeInPages() * 512 - (512 - dh.getUsedBytesInLastPage());
    if (stubSize > dh.getAddressOfNewExeHeader()) stubSize = dh.getAddressOfNewExeHeader();
    stubSize -= dh.getHeaderSizeInParagraphs() * 16;
    dh.setStubSize(stubSize);

    return dh;
  }