Ejemplo n.º 1
0
 private static void readDebugRawData(PE pe, DataEntry entry, IDataReader dr) throws IOException {
   // Read any preamble data
   ImageData id = pe.getImageData();
   byte[] pa = readPreambleData(entry.pointer, dr);
   if (pa != null) id.setDebugRawDataPreamble(pa);
   DebugDirectory dd = id.getDebug();
   byte[] b = new byte[dd.getSizeOfData()];
   dr.read(b);
   id.setDebugRawData(b);
 }
Ejemplo n.º 2
0
  public static DataEntry findNextEntry(PE pe, int pos) {
    DataEntry de = new DataEntry();

    // Check sections first
    int ns = pe.getCoffHeader().getNumberOfSections();
    for (int i = 0; i < ns; i++) {
      SectionHeader sh = pe.getSectionTable().getHeader(i);
      if (sh.getSizeOfRawData() > 0
          && sh.getPointerToRawData() >= pos
          && (de.pointer == 0 || sh.getPointerToRawData() < de.pointer)) {
        de.pointer = sh.getPointerToRawData();
        de.index = i;
        de.isSection = true;
      }
    }

    // Now check image data directories
    RVAConverter rvc = pe.getSectionTable().getRVAConverter();
    int dc = pe.getOptionalHeader().getDataDirectoryCount();
    for (int i = 0; i < dc; i++) {
      ImageDataDirectory idd = pe.getOptionalHeader().getDataDirectory(i);
      if (idd.getSize() > 0) {
        int prd = idd.getVirtualAddress();
        // Assume certificate live outside section ?
        if (i != ImageDataDirectoryType.CERTIFICATE_TABLE && isInsideSection(pe, idd)) {
          prd = rvc.convertVirtualAddressToRawDataPointer(idd.getVirtualAddress());
        }
        if (prd >= pos && (de.pointer == 0 || prd < de.pointer)) {
          de.pointer = prd;
          de.index = i;
          de.isSection = false;
        }
      }
    }

    // Check debug
    ImageData id = pe.getImageData();
    DebugDirectory dd = null;
    if (id != null) dd = id.getDebug();
    if (dd != null) {
      int prd = dd.getPointerToRawData();
      if (prd >= pos && (de.pointer == 0 || prd < de.pointer)) {
        de.pointer = prd;
        de.index = -1;
        de.isDebugRawData = true;
        de.isSection = false;
        de.baseAddress = prd;
      }
    }

    if (de.pointer == 0) return null;

    return de;
  }
Ejemplo n.º 3
0
 public static DebugDirectory readDebugDirectory(byte[] b, IDataReader dr) throws IOException {
   DebugDirectory dd = new DebugDirectory();
   dd.set(b);
   dd.setCharacteristics(dr.readDoubleWord());
   dd.setTimeDateStamp(dr.readDoubleWord());
   dd.setMajorVersion(dr.readWord());
   dd.setMajorVersion(dr.readWord());
   dd.setType(dr.readDoubleWord());
   dd.setSizeOfData(dr.readDoubleWord());
   dd.setAddressOfRawData(dr.readDoubleWord());
   dd.setPointerToRawData(dr.readDoubleWord());
   return dd;
 }