EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
utils_hex.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void build_hex_line (const uint8 *buffer, size_t length, size_t offset, char *ret, unsigned int padding=4)
 Build a printable line suitable for hex dump. More...
 
void pfxHexDump (const char *pfx, FILE *into, const uint8 *data, size_t length)
 
void pfxHexDump (const char *pfx, LogType type, const uint8 *data, size_t length)
 
void pfxHexDumpPreview (const char *pfx, FILE *into, const uint8 *data, size_t length)
 
void pfxHexDumpPreview (const char *pfx, LogType type, const uint8 *data, size_t length)
 

Variables

const uint32 HEX_DUMP_PREVIEW_LIMIT
 

Function Documentation

void build_hex_line ( const uint8 buffer,
size_t  length,
size_t  offset,
char *  ret,
unsigned int  padding = 4 
)

Build a printable line suitable for hex dump.

Parameters
[in]bufferBuffer which is being dumped.
[in]lengthLength of buffer.
[in]offsetOffset at which the dump should start.
[out]retArray where result is stored.
[in]paddingPadding to be used when printing offset.

Definition at line 33 of file utils_hex.cpp.

References IsPrintable(), and snprintf.

Referenced by log_hex(), log_phex(), pfxHexDump(), and pfxHexDumpPreview().

34 {
35  ret += snprintf( ret, length, "%0*zX:", padding, offset );
36 
37  char printable[17];
38 
39  for( size_t i = 0; i < 16; i++ )
40  {
41  if( i == 8 )
42  {
43  ret += snprintf( ret, length, " -" );
44  }
45 
46  if( ( i + offset ) < length )
47  {
48  uint8 c = *(const uint8*)( buffer + offset + i );
49 
50  ret += snprintf( ret, length, " %02X", c );
51  printable[i] = ( IsPrintable( c ) ? (char)c : '.' );
52  }
53  else
54  {
55  ret += snprintf( ret, length, " " );
56  printable[i] = 0;
57  }
58  }
59 
60  snprintf( ret, length, " | %.16s", printable );
61 }
unsigned __int8 uint8
Definition: eve-compat.h:46
bool IsPrintable(const PyString *str)
Checks whether string is printable.
Definition: EVEUtils.cpp:31
#define snprintf
Definition: eve-compat.h:184

Here is the call graph for this function:

Here is the caller graph for this function:

void pfxHexDump ( const char *  pfx,
FILE *  into,
const uint8 data,
size_t  length 
)

Definition at line 63 of file utils_hex.cpp.

References build_hex_line().

Referenced by PyLogDumpVisitor::_dump(), PyFileDumpVisitor::_dump(), and pfxHexDumpPreview().

64 {
65  char buffer[80];
66 
67  for( uint32 offset = 0; offset < length; offset += 16 )
68  {
69  build_hex_line( data, length, offset, buffer, 4 );
70 
71  fprintf( into, "%s%s\n", pfx, buffer );
72  }
73 }
void build_hex_line(const uint8 *buffer, size_t length, size_t offset, char *ret, unsigned int padding)
Build a printable line suitable for hex dump.
Definition: utils_hex.cpp:33
unsigned __int32 uint32
Definition: eve-compat.h:50

Here is the call graph for this function:

Here is the caller graph for this function:

void pfxHexDump ( const char *  pfx,
LogType  type,
const uint8 data,
size_t  length 
)

Definition at line 75 of file utils_hex.cpp.

References _log, and build_hex_line().

76 {
77  char buffer[80];
78 
79  for( uint32 offset = 0; offset < length; offset += 16 )
80  {
81  build_hex_line( data, length, offset, buffer, 4 );
82 
83  _log( type, "%s%s", pfx, buffer );
84  }
85 }
#define _log(type, fmt,...)
Definition: logsys.h:124
void build_hex_line(const uint8 *buffer, size_t length, size_t offset, char *ret, unsigned int padding)
Build a printable line suitable for hex dump.
Definition: utils_hex.cpp:33
unsigned __int32 uint32
Definition: eve-compat.h:50

Here is the call graph for this function:

void pfxHexDumpPreview ( const char *  pfx,
FILE *  into,
const uint8 data,
size_t  length 
)

Definition at line 87 of file utils_hex.cpp.

References build_hex_line(), HEX_DUMP_PREVIEW_LIMIT, and pfxHexDump().

Referenced by PyLogDumpVisitor::_dump(), and PyFileDumpVisitor::_dump().

88 {
89  char buffer[80];
90 
91  if( length > HEX_DUMP_PREVIEW_LIMIT )
92  {
93  pfxHexDump( pfx, into, data, HEX_DUMP_PREVIEW_LIMIT - 32 );
94  fprintf( into, "%s ... truncated ...\n", pfx );
95 
96  build_hex_line( data, length, length - 16, buffer, 4 );
97  fprintf( into, "%s%s\n", pfx, buffer );
98  }
99  else
100  pfxHexDump( pfx, into, data, length );
101 }
const uint32 HEX_DUMP_PREVIEW_LIMIT
Definition: utils_hex.cpp:31
void build_hex_line(const uint8 *buffer, size_t length, size_t offset, char *ret, unsigned int padding)
Build a printable line suitable for hex dump.
Definition: utils_hex.cpp:33
void pfxHexDump(const char *pfx, FILE *into, const uint8 *data, size_t length)
Definition: utils_hex.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

void pfxHexDumpPreview ( const char *  pfx,
LogType  type,
const uint8 data,
size_t  length 
)

Definition at line 103 of file utils_hex.cpp.

References _log, build_hex_line(), HEX_DUMP_PREVIEW_LIMIT, and pfxHexDump().

104 {
105  char buffer[80];
106 
107  if( length > HEX_DUMP_PREVIEW_LIMIT )
108  {
109  pfxHexDump( pfx, type, data, HEX_DUMP_PREVIEW_LIMIT - 32 );
110  _log( type, "%s ... truncated ...", pfx );
111 
112  build_hex_line( data, length, length - 16, buffer, 4 );
113  _log( type, "%s%s", pfx, buffer );
114  }
115  else
116  pfxHexDump( pfx, type, data, length );
117 }
#define _log(type, fmt,...)
Definition: logsys.h:124
const uint32 HEX_DUMP_PREVIEW_LIMIT
Definition: utils_hex.cpp:31
void build_hex_line(const uint8 *buffer, size_t length, size_t offset, char *ret, unsigned int padding)
Build a printable line suitable for hex dump.
Definition: utils_hex.cpp:33
void pfxHexDump(const char *pfx, FILE *into, const uint8 *data, size_t length)
Definition: utils_hex.cpp:63

Here is the call graph for this function:

Variable Documentation

const uint32 HEX_DUMP_PREVIEW_LIMIT

The maximal number of bytes printed by pfxHexDumpPreview.

Definition at line 31 of file utils_hex.cpp.

Referenced by pfxHexDumpPreview().