Advertisement
Leo40Bin

.rsrc Reader

Mar 9th, 2018
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. // setup I/O stuff
  2. FileInputStream inStream;
  3. FileChannel inChan;
  4. inStream = new FileInputStream(base);
  5. inChan = inStream.getChannel();
  6. ByteBuffer uBuf = ByteBuffer.allocate(2);
  7. uBuf.order(ByteOrder.LITTLE_ENDIAN);
  8. inChan.position(rsrcPtr + 12);
  9. inChan.read(uBuf);
  10. uBuf.flip();
  11. short nameNum = uBuf.getShort();
  12. uBuf.clear();
  13. inChan.read(uBuf);
  14. uBuf.flip();
  15. short idNum = uBuf.getShort();
  16. ByteBuffer uBuf4 = ByteBuffer.allocate(4);
  17. uBuf4.order(ByteOrder.LITTLE_ENDIAN);
  18. // read name entries
  19. for (int i = 0; i < nameNum; i++) {
  20.     System.out.println(
  21.             "Reading name entry " + i + " (at 0x" + Long.toHexString(inChan.position()).toUpperCase() + "):");
  22.     inChan.read(uBuf4);
  23.     uBuf4.flip();
  24.     int nameOffset = uBuf4.getInt();
  25.     System.out.println("nameOffset=0x" + Integer.toHexString(nameOffset).toUpperCase());
  26.     uBuf4.clear();
  27.     inChan.read(uBuf4);
  28.     uBuf4.flip();
  29.     int otherThing = uBuf4.getInt();
  30.     if ((otherThing & (1 << 31)) == 0)
  31.         // "other thing" is data entry offset
  32.         System.out.println("dataEntryOffset=0x" + Integer.toHexString(otherThing).toUpperCase());
  33.     else {
  34.         // "other thing" is subdirectory offset
  35.         otherThing ^= 1 << 31; // unset high bit
  36.         System.out.println("subdirectoryOffset=0x" + Integer.toHexString(otherThing).toUpperCase());
  37.     }
  38. }
  39. // read ID entries
  40. for (int i = 0; i < idNum; i++) {
  41.     System.out.println(
  42.             "Reading ID entry " + i + " (at 0x" + Long.toHexString(inChan.position()).toUpperCase() + "):");
  43.     inChan.read(uBuf4);
  44.     uBuf4.flip();
  45.     int id = uBuf4.getInt();
  46.     System.out.println("id=0x" + Integer.toHexString(id).toUpperCase());
  47.     uBuf4.clear();
  48.     inChan.read(uBuf4);
  49.     uBuf4.flip();
  50.     int otherThing = uBuf4.getInt();
  51.     if ((otherThing & (1 << 31)) == 0)
  52.         // "other thing" is data entry offset
  53.         System.out.println("dataEntryOffset=0x" + Integer.toHexString(otherThing).toUpperCase());
  54.     else {
  55.         // "other thing" is subdirectory offset
  56.         otherThing ^= 1 << 31; // unset high bit
  57.         System.out.println("subdirectoryOffset=0x" + Integer.toHexString(otherThing).toUpperCase());
  58.     }
  59. }
  60. inStream.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement