Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. import java.nio.ByteBuffer;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileInputStream;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.InputStreamReader;
  10. import java.io.PrintStream;
  11. import java.io.RandomAccessFile;
  12. import java.io.Reader;
  13.  
  14. public class NDSRomInfo {
  15. static File file;
  16.  
  17. public static byte[] getBytes(int start, int end, boolean reverse) {
  18. RandomAccessFile raf = null;
  19. byte[] header = new byte[end + 1 - start];
  20. try {
  21. raf = new RandomAccessFile(file, "r");
  22. raf.seek(start);
  23. for (int i = 0; i < header.length; ++i) {
  24. if(reverse == true){
  25. header[(header.length-1) - i] = raf.readByte();
  26. } else {
  27. header[i] = raf.readByte();
  28. }
  29. }
  30. return header;
  31. }
  32. catch (IOException ex) {
  33. return null;
  34. }
  35. }
  36.  
  37. public static void main(String[] args) {
  38. if(args.length == 0){
  39. System.out.printf("Please specify an input file.");
  40. return;
  41. }
  42. file = new File(args[0]);
  43.  
  44. if(file.exists() && !file.isDirectory()) {
  45. ByteBuffer bannerLocation = ByteBuffer.wrap(getBytes(0x68, 0x6B, true));
  46. ByteBuffer bannerSize = ByteBuffer.wrap(getBytes(0x208, 0x20B, true));
  47. String ndsData = "";
  48.  
  49. try {
  50. FileInputStream fis = new FileInputStream(file);
  51. byte[] data = new byte[(int) file.length()];
  52. fis.read(data);
  53. fis.close();
  54. ndsData = new String(data);
  55. data = null;
  56. } catch (IOException ex) {
  57. return;
  58. }
  59.  
  60.  
  61. int gamePathStartOffset = ndsData.indexOf("<<<Start NDS Path");
  62. int gamePathEndOffset = ndsData.indexOf("End NDS Path>>>");
  63.  
  64. if(gamePathEndOffset > -1){
  65. gamePathEndOffset += 15;
  66. }
  67.  
  68. if(gamePathStartOffset > -1){
  69. System.out.printf(" GamePath Start: 0x%X\n", gamePathStartOffset);
  70. } else {
  71. System.out.printf(" GamePath Start: NOT FOUND\n");
  72. }
  73.  
  74. if(gamePathEndOffset > -1){
  75. System.out.printf("GamePath Length: %d\n", (gamePathEndOffset - gamePathStartOffset));
  76. } else {
  77. System.out.printf("GamePath Length: 0\n");
  78. }
  79.  
  80. System.out.printf("Banner Location: 0x%X\n", bannerLocation.getInt());
  81. System.out.printf(" Banner Size: 0x%X\n", bannerSize.getInt());
  82.  
  83. } else {
  84. System.out.printf("File not found.");
  85. }
  86.  
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement