The source code contained in this area is provied without any restrictions and without
any warranty. I hope that it will be useful to others that stumble onto this web site.
Please feel free to send any feedback or questions you may have to me at [hh@hackhawk.net].
[ c/c++ functions |
php functions |
dos functions ]
Binary Print Function
This function takes an unsigned character array of binary data, and dumps/prints it in
a human readable format.
Here's an example of a typical HTTP binary return string that printbin will display.
0000 4854 5450 2F31 2E31 2032 3030 204F 4B0D HTTP/1.1 200 OK.
0010 0A53 6572 7665 723A 204D 6963 726F 736F .Server: Microso
0020 6674 2D49 4953 2F34 2E30 0D0A 4461 7465 ft-IIS/4.0..Date
0030 3A20 5361 742C 2032 3420 4A61 6E20 3230 : Sat, 24 Jan 20
0040 3034 2032 333A 3535 3A35 3520 474D 540D 04 23:55:55 GMT.
// tch is the unsigned character/binary array.
// tlen is the number of bytes you wish printbin to display.
int printbin ( unsigned char *tch, int tlen ) {
int i=0,j;
char tval[64]={0};
char cval[32]={0};
char zval[5]={0};
while (i<tlen) {
memset(tval,'\0',64);
memset(cval,'\0',32);
for (j=i;(j<i+16);j++) {
if (((j/2)*2)==j) strncat(tval," ",1);
if (j<tlen) {
sprintf(zval,"%02X",tch[j]);
strncat(tval,zval,2);
if ((tch[j]>31)&&(tch[j]<127)) strncat(cval,&tch[j],1);
else strncat(cval,".",1);
} else {
strncat(tval," ",2);
strncat(cval," ",1);
}
}
printf("%04X %s %s\n",i,tval,cval);
i = i+16;
}
return 0;
}

|