When using pointers, i like to see what happen when coding.. I believe a lot of programmer (which working on pointers) also love to work that way. But what really annoying me start at that point. Hexdump.
I don’t have any idea of why the people who make this standard of hex dump, i first saw this at PcTools at DOS at 1992, but one way or another people continue that way of formatting.
00000000 48 54 54 50 2f 31 2e 30 20 32 30 30 20 43 6f 6e HTTP/1.0 200 Con
00000010 6e 65 63 74 69 6f 6e 20 65 73 74 61 62 6c 69 73 nection establis
00000020 68 65 64 0d 0a 0d 0a hed....
annoying part for me is, I really like to see that damned data when debug, yes it also shown at this. but I don’t have any idea of which character is which ASCII. I am NOT smart enough to remember all ASCII character’s hexadecimal values.
and when you start to debug, you are starting to count. (that start at 10, so that hex value must be 14. then looking it’s hexadecimal value). Doing that for almost 100 times at least really annoys me.
Another problem was in DOS times, our codes was work at real memory. not a protected virtual memory. so showing address in hex can be understandable.
But now ? I use decimal values when doing memory walking not hex! We use flat memory model in codes. mostly can be done is writing pointer memory address. and it can be use only for compare values and it can be done in decimal too.
And when my feelings changed to hate from annoy. I changed to hexdump format to this way at my codes.
00000000 48 54 54 50 2f 31 2e 30 20 32 30 30 20 43 6f 6e
H T T P / 1 . 0 2 0 0 C o n
00000016 6e 65 63 74 69 6f 6e 20 65 73 74 61 62 6c 69 73
n e c t i o n e s t a b l i s
00000032 68 65 64 0d 0a 0d 0a
h e d . . . .
Yes, I don’t care about row count because I can use less, more, most, shift PageUp. any pager or console help me at it.
And code example:
function csHexDump(const adata: Pointer; datalen: Cardinal;
showAddress: Boolean = True; startAt: Cardinal = 0;
oldStyle: Boolean = False): AnsiString;
Var
_Address: ShortString;
_Dump: ShortString;
_Ansi: ShortString;
X, I, J: Integer;
Begin
Result := '';
if showAddress then
_Address := Format( '%.10U:', [ Cardinal( AData ) + startAt ] )
else
_Address := Format( '%.6U:', [0] );
_Dump := '';
_Ansi := '';
if not oldStyle then
for j := 0 to Length(_Address) - 1 do
_Ansi := _Ansi + ' ';
For I := 0 To datalen - (startAt) - 1 Do
Begin
_Dump := _Dump + Format( '%3.2x', [Byte((pChar( AData ) + I + StartAt)^ )]);
if oldStyle then
If Byte( ( pChar( AData ) + I + startAt)^ ) >= 31 Then
begin
_Ansi := _Ansi + Char( ( pChar( AData ) + I + startAt)^ );
end else
_Ansi := _Ansi + '.';
if not oldStyle then
If Byte( ( pChar( AData ) + I + startAt)^ ) >= 31 Then
_Ansi := _Ansi + Format( '%3.2S', [Char((pChar( AData )+I+startAt)^)])
else
_Ansi := _Ansi + Format( '%3.2S', ['.'] );
If ( Cardinal( AData ) + I ) Mod 16 = 7 Then _Dump := _Dump + ' |';
if not oldStyle then
If ( Cardinal( AData ) + I ) Mod 16 = 7 Then _Ansi := _Ansi + ' ';
If ( Cardinal( AData ) + I ) Mod 16 = 15 Then
Begin
For X := Length( _Dump ) + 1 To 50 Do _Dump := ' ' + _Dump;
For X := Length( _Ansi ) + 1 To 16 Do _Ansi := ' ' + _Ansi;
if oldStyle then
Result := Result + _Address + _Dump + ' | ' + _Ansi + #13#10
else
Result := Result + _Address + _Dump + #13#10 + _Ansi + #13#10;
if showAddress then
_Address := Format( '%.10U:', [ Cardinal( AData ) + I + startAt + 1 ] )
else
_Address := Format( '%.6U:', [ I + 1 ] );
_Dump := '';
_Ansi := '';
if not oldStyle then
for j := 0 to Length(_Address) - 1 do
_Ansi := _Ansi + ' ';
End;
End;
if Length(_Dump) > 0 then
For X := Length( _Dump ) + 1 To 50 Do _Dump := _Dump + ' ';
if oldStyle then
if (_Dump <> '') then
Result := Result + _Address + _Dump + ' | ' + _Ansi + #13#10;
if not oldStyle then
if (_Dump <> '') then
Result := Result + _Address + _Dump + #13#10 + _Ansi + #13#10;
end;