1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
RandomAccessFile bFile = null;
FileOutputStream pFile = null;
System.out.print("Enter your binary file : ");
try {
bFile = new RandomAccessFile(new File(scan.nextLine()), "r");
} catch (FileNotFoundException e) {
System.err.println("File not found !");
e.printStackTrace();
}
System.out.print("Enter your output file (with extention) : ");
try {
pFile = new FileOutputStream(scan.nextLine());
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.print("Enter start address : ");
long startAddress = Long.parseLong(scan.nextLine(),16);
System.out.println(startAddress);
System.out.print("Enter stop address :");
long stopAddress = Long.parseLong(scan.nextLine(),16);
bFile.seek(startAddress);
int taille = (int) (stopAddress - startAddress);
byte[] buf = new byte[taille];
int oLu = 0;
do{
oLu = bFile.read(buf);
System.out.println("taille : "+taille);
System.out.println("oLu : "+oLu);
}while(oLu != taille);
pFile.write(buf);
try {
bFile.close();
pFile.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
Partager