1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-14 19:59:02 +00:00

Replaced nmap's hex dump functions with new hexdump() included in nbase. Before

Nmap used two functions: one of them, hdump(), just printed raw hex bytes 
(no ASCII equivalents) and the other one, lamont_hdump() had a bug when 
printing buffers where bufflen%16==3. A new function has been implemented 
from scratch, that basically produces the same output as Wireshark. 
Output looks like this:

0000   e8 60 65 86 d7 86 6d 30  35 97 54 87 ff 67 05 9e  .`e...m05.T..g..
0010   07 5a 98 c0 ea ad 50 d2  62 4f 7b ff e1 34 f8 fc  .Z....P.bO{..4..
0020   c4 84 0a 6a 39 ad 3c 10  63 b2 22 c4 24 40 f4 b1  ...j9.<.c.".$@..

Changes:

- The new hexdump() function has been added to nbase.
- Old hdump() and lamont_dump() have been removed from nmap's code.
- A wrapper to the new hexdump(), called nmap_hexdump(), has been added
  to nmap's utils.cc. The wrapper basically prints the buffer returned 
  by hexdump() using nmap's log_write() function.
This commit is contained in:
luis
2009-08-25 18:09:19 +00:00
parent d63fba1dd6
commit a5ca31db9e
5 changed files with 14 additions and 86 deletions

View File

@@ -137,89 +137,18 @@ int wildtest(char *wild, char *test) {
}
/* Wrapper for nbase function hexdump() */
void nmap_hexdump(unsigned char *cp, unsigned int length){
/* Hex dump */
void hdump(unsigned char *packet, unsigned int len) {
unsigned int i=0, j=0;
log_write(LOG_PLAIN, "Here it is:\n");
for(i=0; i < len; i++){
j = (unsigned) (packet[i]);
log_write(LOG_PLAIN, "%-2X ", j);
if (!((i+1)%16))
log_write(LOG_PLAIN, "\n");
else if (!((i+1)%4))
log_write(LOG_PLAIN, " ");
}
log_write(LOG_PLAIN, "\n");
char *string=NULL;
string = hexdump((u8*)cp, length);
if(string){
log_write(LOG_PLAIN, "%s", string);
free(string);
}
return;
}
/* A better version of hdump, from Lamont Granquist. Modified slightly
by Fyodor (fyodor@insecure.org) */
void lamont_hdump(char *cp, unsigned int length) {
/* stolen from tcpdump, then kludged extensively */
static const char asciify[] = "................................ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~.................................................................................................................................";
const u_short *sp;
const u_char *ap;
unsigned char *bp = (unsigned char *) cp;
u_int i, j;
int nshorts, nshorts2;
int padding;
log_write(LOG_PLAIN, "\n\t");
padding = 0;
sp = (u_short *)bp;
ap = (u_char *)bp;
nshorts = (u_int) length / sizeof(u_short);
nshorts2 = (u_int) length / sizeof(u_short);
i = 0;
j = 0;
while(1) {
while (--nshorts >= 0) {
log_write(LOG_PLAIN, " %04x", ntohs(*sp));
sp++;
if ((++i % 8) == 0)
break;
}
if (nshorts < 0) {
if ((length & 1) && (((i-1) % 8) != 0)) {
log_write(LOG_PLAIN, " %02x ", *(u_char *)sp);
padding++;
}
nshorts = (8 - (nshorts2 - nshorts));
while(--nshorts >= 0) {
log_write(LOG_PLAIN, " ");
}
if (!padding) log_write(LOG_PLAIN, " ");
}
log_write(LOG_PLAIN, " ");
while (--nshorts2 >= 0) {
log_write(LOG_PLAIN, "%c%c", asciify[*ap], asciify[*(ap+1)]);
ap += 2;
if ((++j % 8) == 0) {
log_write(LOG_PLAIN, "\n\t");
break;
}
}
if (nshorts2 < 0) {
if ((length & 1) && (((j-1) % 8) != 0)) {
log_write(LOG_PLAIN, "%c", asciify[*ap]);
}
break;
}
}
if ((length & 1) && (((i-1) % 8) == 0)) {
log_write(LOG_PLAIN, " %02x", *(u_char *)sp);
log_write(LOG_PLAIN, " %c", asciify[*ap]);
}
log_write(LOG_PLAIN, "\n");
}
#ifndef HAVE_STRERROR
char *strerror(int errnum) {