Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.nio.ByteBuffer;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.io.RandomAccessFile;
- import java.io.Reader;
- public class NDSRomInfo {
- static File file;
- public static byte[] getBytes(int start, int end, boolean reverse) {
- RandomAccessFile raf = null;
- byte[] header = new byte[end + 1 - start];
- try {
- raf = new RandomAccessFile(file, "r");
- raf.seek(start);
- for (int i = 0; i < header.length; ++i) {
- if(reverse == true){
- header[(header.length-1) - i] = raf.readByte();
- } else {
- header[i] = raf.readByte();
- }
- }
- return header;
- }
- catch (IOException ex) {
- return null;
- }
- }
- public static void main(String[] args) {
- if(args.length == 0){
- System.out.printf("Please specify an input file.");
- return;
- }
- file = new File(args[0]);
- if(file.exists() && !file.isDirectory()) {
- ByteBuffer bannerLocation = ByteBuffer.wrap(getBytes(0x68, 0x6B, true));
- ByteBuffer bannerSize = ByteBuffer.wrap(getBytes(0x208, 0x20B, true));
- String ndsData = "";
- try {
- FileInputStream fis = new FileInputStream(file);
- byte[] data = new byte[(int) file.length()];
- fis.read(data);
- fis.close();
- ndsData = new String(data);
- data = null;
- } catch (IOException ex) {
- return;
- }
- int gamePathStartOffset = ndsData.indexOf("<<<Start NDS Path");
- int gamePathEndOffset = ndsData.indexOf("End NDS Path>>>");
- if(gamePathEndOffset > -1){
- gamePathEndOffset += 15;
- }
- if(gamePathStartOffset > -1){
- System.out.printf(" GamePath Start: 0x%X\n", gamePathStartOffset);
- } else {
- System.out.printf(" GamePath Start: NOT FOUND\n");
- }
- if(gamePathEndOffset > -1){
- System.out.printf("GamePath Length: %d\n", (gamePathEndOffset - gamePathStartOffset));
- } else {
- System.out.printf("GamePath Length: 0\n");
- }
- System.out.printf("Banner Location: 0x%X\n", bannerLocation.getInt());
- System.out.printf(" Banner Size: 0x%X\n", bannerSize.getInt());
- } else {
- System.out.printf("File not found.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement