Last Edited: 01 May 2008 by superuser
Importered from old WiKi -- 30/04-08 17:04.
Contents
   hexdump BASIC
          hexdump
          hexdumpa
          hexdump-MBR

hexdump BASIC

I wrote these three simple BASIC programs to make up for the missing hexdump/od functions in Puppy 1.0.6, for people who need to look at the first sector of the hard drive (the MBR) to work on boot problems, and as a first excercise in PuppyBasic programming. (For more information about the MBR, see the Wiki entry Sector0.)

The programs can be entered/edited with a simple text editor such as leafpad. Once you have the file hexdump in the current directory, you can run the program with the simple command
# puppybasic hexdump

The first program, hexdump, just shows the hex contents of the first sector of the file you name. To look at the first sector of the whole hard drive directly, just use the file name /dev/hda.

The second program, hexdumpa, is just a little fancier, adding the ASCII characters besides the hex bytes.

The third program, hexdump-MBR, adds detailed analysis of the MBR, pinpointing the type of boot program loaded and giving all the Partition Table details.

The command
# hdparm -I /dev/hda
is a good way to get basic parameters of the hard drive.

hexdump

' wxbasicscript
' kd 1dec05 for PuppyLinux 1.0.6
' show one sector of 512 bytes
PRINT "hexdump"
INPUT "FILENAME"; NAME
OPEN NAME FOR INPUT AS #1
FOR K = 0 TO 31
PRINT RIGHT(HEX((256*256)+16*K),4); " ";
FOR J = 0 TO 15
RB = READBYTE(1)
IF RB < 0 THEN END
PRINT RIGHT(HEX(256+RB),2); " ";
IF J = 7 THEN PRINT " ";
NEXT J
PRINT
NEXT K
PRINT
CLOSE #1
END

hexdumpa

' wxbasicscript
' kd 1dec05 for PuppyLinux 1.0.6
PRINT "hexdumpa"
INPUT "FILENAME"; NAME
OPEN NAME FOR INPUT AS #1
FOR K = 0 TO 31
PRINT RIGHT(HEX((256*256)+16*K),4); " ";
OUT$ = " "
FOR J = 0 TO 15
RB = READBYTE(1)
' RB = K*16 + J
IF RB < 0 THEN END
PRINT RIGHT(HEX(256+RB),2); " ";
RB = RB MOD 128
IF RB < 32 THEN RB = 46
IF RB = 127 THEN RB = 46
OUT$ = OUT$ & CHR(RB)
IF J = 7 THEN PRINT " ";
NEXT J
PRINT " "; OUT$
NEXT K
PRINT
CLOSE #1
END

hexdump-MBR

' wxbasicscript
' kd for PuppyLinux 1.0.6
PRINT "hexdump-MBR (1dec05)"

DIM PT[66]
PP = 0
PRINT "First Sector"
OPEN "/dev/hda" FOR INPUT AS #1
IN$ = ""
FOR K = 0 TO 31
PRINT RIGHT(HEX((256*256)+16*K),4); " ";
OUT$ = " "
FOR J = 0 TO 15
RB = READBYTE(1)
C = K*16 + J
' RB = C MOD 256
IF C>445 THEN PP = PP+1
PT[PP] = RB
R = RB
IF R = 0 THEN R=255
IN$ = IN$ & CHR(R)
IF LEN(CHR(R))=0 THEN PRINT "NULL: "; RB
PRINT RIGHT(HEX(256+RB),2); " ";
RB = RB MOD 128
IF RB < 32 THEN RB = 46
IF RB = 127 THEN RB = 46
OUT$ = OUT$ & CHR(RB)
IF J = 7 THEN PRINT " ";
NEXT J
PRINT " "; OUT$
NEXT K
CLOSE #1
PRINT

PRINT "Partion Table"
PRINT " ID START END FIRST NUMBER OF"
PRINT "*=ACTIVE C H S C H S SECTOR SECTORS"

FOR I = 1 TO 4
J = I*16 - 15
PRINT I;

K=PT[J]
IF HEX(K)="80" THEN
PRINT " *";
ELSEIF K=0 THEN
PRINT " ";
ELSE
PRINT "bad";
END IF
PRINT RIGHT(HEX(256+PT[J+4]),2); " ";

J2 = PT[J+2] MOD 64
PRINT RIGHT(" "&STR(((PT[J+2]-J2)/64)*256 + PT[J+3]),5);
PRINT RIGHT(" "&STR(PT[J+1]),5);
PRINT RIGHT(" "&STR(J2),5);
PRINT " ";
J6 = PT[J+6] MOD 64
PRINT RIGHT(" "&STR(((PT[J+6]-J6)/64)*256 + PT[J+7]),5);
PRINT RIGHT(" "&STR(PT[J+5]),5);
PRINT RIGHT(" "&STR(J6),5);

PRINT " "; RIGHT(HEX(256+PT[J+11]),2);
PRINT RIGHT(HEX(256+PT[J+10]),2);
PRINT RIGHT(HEX(256+PT[J+9]),2);
PRINT RIGHT(HEX(256+PT[J+8]),2);
PRINT " "; RIGHT(HEX(256+PT[J+15]),2);
PRINT RIGHT(HEX(256+PT[J+14]),2);
PRINT RIGHT(HEX(256+PT[J+13]),2);
PRINT RIGHT(HEX(256+PT[J+12]),2);
PRINT " ="; RIGHT(" "&STR(((PT[J+15]*256 + PT[J+14])*256 + PT[J+13])*256 + PT[J+12]),9)
NEXT I
PRINT

I = INSTR(IN$, "GRUB")
IF I > 0 THEN PRINT "GRUB found at "; HEX(I-1)
J = INSTR(IN$, "LILO")
IF J > 0 THEN PRINT "LILO found at "; HEX(J-1)
K = INSTR(IN$, "Invalid")
IF K > 0 THEN PRINT "DOS/Windows ERR MSG 'Invalid' found at "; HEX(K-1)
IF (I+J+K) = 0 THEN PRINT "No recognized IPL found"

IF (HEX(PT[65])="55") AND (HEX(PT[66])="aa") THEN

PRINT "Signature ID at end OK"

ELSE

PRINT "Signature ID at end BAD"

END IF
PRINT
END



CategoryUserContributions