Saturday, November 21, 2009

Linux Master Boot Record display

Hai guys , i would like to show you how to display the MBR contents

Step 1 : Copy the MBR from the boot device ,

$ dd if=/dev/sda of=myMBR.bin bs=512 count=1

Here /dev/sda is my sata hard disk drive file and it would be /dev/hda for IDE drives.

Step 2:
Write the following program:


import java.io.*;
public class MBR {
public static void main(String args[])throws Exception{
if(args.length != 1){
System.out.println("Usage : java MBR ") ;
System.exit(0) ;
}

File file = new File(args[0]) ;

System.out.println("Size of "+args[0]+" = "+file.length());
FileInputStream fin = new FileInputStream(file) ;
byte[] mbr = new byte[512] ;

int size = fin.read(mbr) ;

System.out.println("Size readed = "+size) ;

int j = 0 ;

for(int i=0 ; i j++;
StringBuffer s =
new StringBuffer(Integer.toHexString((mbr[i] >= 0) ? mbr[i] : 256 +mbr[i]));

if(s.length() == 1) s.insert(0,'0');

if(j > 10){
j = 0 ;
System.out.println() ;
}

System.out.print(" "+s.toString()) ;

}

fin.close() ;
}
}




Step 3: Compile the above program , and run it , also pass the file myMBR.bin(which was created in first step).

$ java MBR myMBR.bin

The above command produced the following output when i run it :

OUTPUT

Size of sda = 512
Size readed = 512
eb 48 90 d0 bc 00 7c fb 50 07
50 1f fc be 1b 7c bf 1b 06 50 57
b9 e5 01 f3 a4 cb bd be 07 b1 04
38 6e 00 7c 09 75 13 83 c5 10 e2
f4 cd 18 8b f5 83 c6 10 49 74 19
38 2c 74 f6 a0 b5 07 b4 03 02 ff
00 00 20 01 00 00 00 00 02 fa 90
90 f6 c2 80 75 02 b2 80 ea 59 7c
00 00 31 c0 8e d8 8e d0 bc 00 20
fb a0 40 7c 3c ff 74 02 88 c2 52
be 7f 7d e8 34 01 f6 c2 80 74 54
b4 41 bb aa 55 cd 13 5a 52 72 49
81 fb 55 aa 75 43 a0 41 7c 84 c0
75 05 83 e1 01 74 37 66 8b 4c 10
be 05 7c c6 44 ff 01 66 8b 1e 44
7c c7 04 10 00 c7 44 02 01 00 66
89 5c 08 c7 44 06 00 70 66 31 c0
89 44 04 66 89 44 0c b4 42 cd 13
72 05 bb 00 70 eb 7d b4 08 cd 13
73 0a f6 c2 80 0f 84 ea 00 e9 8d
00 be 05 7c c6 44 ff 00 66 31 c0
88 f0 40 66 89 44 04 31 d2 88 ca
c1 e2 02 88 e8 88 f4 40 89 44 08
31 c0 88 d0 c0 e8 02 66 89 04 66
a1 44 7c 66 31 d2 66 f7 34 88 54
0a 66 31 d2 66 f7 74 04 88 54 0b
89 44 0c 3b 44 08 7d 3c 8a 54 0d
c0 e2 06 8a 4c 0a fe c1 08 d1 8a
6c 0c 5a 8a 74 0b bb 00 70 8e c3
31 db b8 01 02 cd 13 72 2a 8c c3
8e 06 48 7c 60 1e b9 00 01 8e db
31 f6 31 ff fc f3 a5 1f 61 ff 26
42 7c be 85 7d e8 40 00 eb 0e be
8a 7d e8 38 00 eb 06 be 94 7d e8
30 00 be 99 7d e8 2a 00 eb fe 47
52 55 42 20 00 47 65 6f 6d 00 48
61 72 64 20 44 69 73 6b 00 52 65
61 64 00 20 45 72 72 6f 72 00 bb
01 00 b4 0e cd 10 ac 3c 00 75 f4
c3 00 00 00 00 00 00 00 00 00 00
00 56 a8 03 00 00 00 80 01 01 00
83 fe ff b4 3f 00 00 00 36 a1 e8
00 00 00 c1 b5 0f fe ff ff 75 a1
e8 00 4c 43 68 08 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 55 aa

No comments:

Post a Comment