| 1 | /* |
| 2 | * Copyright (C) 1998 Mark Baysinger ([email protected]) |
| 3 | * Copyright (C) 1998,1999 Ross Combs ([email protected]) |
| 4 | * Copyright (C) 2004 Donny Redmond ([email protected]) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 21 | #include "common/hexdump.h"cxx . . $ `<file>/src/common/hexdump.h`/ |
| 22 | |
| 23 | #include "common/packet.h"cxx . . $ `<file>/src/common/packet.h`/ |
| 24 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 25 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 26 | |
| 27 | namespace pvpgncxx . . $ pvpgn/ |
| 28 | { |
| 29 | |
| 30 | extern void hexdumpcxx . . $ pvpgn/hexdump(23ce3b3157473ba).(stdcxx . . $ std/::FILEcxx . . $ std/FILE# * stream, void const * data, unsigned int len) |
| 31 | { |
| 32 | unsigned int i; |
| 33 | char dst[100]; |
| 34 | unsigned char * datac; |
| 35 | |
| 36 | if (!data) { |
| 37 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL data"); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if (!stream) { |
| 42 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got NULL stream"); |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | for (i = 0, datac = (unsigned char*)data; i < len; i += 16, datac += 16) |
| 47 | { |
| 48 | hexdump_stringcxx . . $ pvpgn/hexdump_string(c601f8efb03f3efb).(datac, (len - i < 16) ? (len - i) : 16, dst, i); |
| 49 | stdcxx . . $ std/::fprintfcxx . . $ std/fprintf(bc216f8e5b1ebeac).(stream, "%s\n", dst); |
| 50 | stdcxx . . $ std/::fflushcxx . . $ std/fflush(89bc1efcdac0ca22).(stream); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | extern void hexdump_stringcxx . . $ pvpgn/hexdump_string(c601f8efb03f3efb).(unsigned char * data, unsigned int datalen, char * dst, unsigned int counter) |
| 55 | { |
| 56 | unsigned int c; |
| 57 | int tlen = 0; |
| 58 | unsigned char *datatmp; |
| 59 | |
| 60 | datatmp = data; |
| 61 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), "%04X: ", counter); |
| 62 | |
| 63 | for (c = 0; c < 8; c++) /* left half of hex dump */ |
| 64 | if (c < datalen) |
| 65 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), "%02X ", *(datatmp++)); |
| 66 | else |
| 67 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), " "); /* pad if short line */ |
| 68 | |
| 69 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), " "); |
| 70 | |
| 71 | for (c = 8; c < 16; c++) /* right half of hex dump */ |
| 72 | if (c < datalen) |
| 73 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), "%02X ", *(datatmp++)); |
| 74 | else |
| 75 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), " "); /* pad if short line */ |
| 76 | |
| 77 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), " "); |
| 78 | |
| 79 | for (c = 0, datatmp = data; c < 16; c++, datatmp++) /* ASCII dump */ |
| 80 | if (c < datalen) { |
| 81 | if (*datatmp >= 32 && *datatmp < 127) |
| 82 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), "%c", *datatmp); |
| 83 | else |
| 84 | tlen += stdcxx . . $ std/::sprintfcxx . . $ std/sprintf(bb743b22d71e45d5).((dst + tlen), "."); /* put this for non-printables */ |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | |
| 89 | } |