promote hex_dump() to fko_util
This commit is contained in:
@@ -53,8 +53,6 @@
|
||||
|
||||
/* Prototypes
|
||||
*/
|
||||
void hex_dump(const unsigned char *data, const int size);
|
||||
int set_file_perms(const char *file);
|
||||
int verify_file_perms_ownership(const char *file);
|
||||
int resolve_dst_addr(const char *dns_str, struct addrinfo *hints,
|
||||
char *ip_str, size_t ip_bufsize, fko_cli_options_t *opts);
|
||||
|
||||
@@ -738,6 +738,47 @@ free_argv(char **argv_new, int *argc_new)
|
||||
return;
|
||||
}
|
||||
|
||||
#define ASCII_LEN 16
|
||||
|
||||
/* Generic hex dump function.
|
||||
*/
|
||||
void
|
||||
hex_dump(const unsigned char *data, const int size)
|
||||
{
|
||||
int ln=0, i=0, j=0;
|
||||
char ascii_str[ASCII_LEN+1] = {0};
|
||||
|
||||
for(i=0; i<size; i++)
|
||||
{
|
||||
if((i % ASCII_LEN) == 0)
|
||||
{
|
||||
printf(" %s\n 0x%.4x: ", ascii_str, i);
|
||||
memset(ascii_str, 0x0, ASCII_LEN-1);
|
||||
j = 0;
|
||||
}
|
||||
|
||||
printf("%.2x ", data[i]);
|
||||
|
||||
ascii_str[j++] = (data[i] < 0x20 || data[i] > 0x7e) ? '.' : data[i];
|
||||
|
||||
if(j == 8)
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
/* Remainder...
|
||||
*/
|
||||
ln = strlen(ascii_str);
|
||||
if(ln > 0)
|
||||
{
|
||||
for(i=0; i < ASCII_LEN-ln; i++)
|
||||
printf(" ");
|
||||
if(ln < 8)
|
||||
printf(" ");
|
||||
|
||||
printf(" %s\n\n", ascii_str);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dump a FKO context to a buffer
|
||||
|
||||
@@ -42,6 +42,7 @@ int is_valid_encoded_msg_len(const int len);
|
||||
int is_valid_pt_msg_len(const int len);
|
||||
int is_valid_ipv4_addr(const char * const ip_str);
|
||||
int is_base64(const unsigned char * const buf, const unsigned short int len);
|
||||
void hex_dump(const unsigned char *data, const int size);
|
||||
int enc_mode_strtoint(const char *enc_mode_str);
|
||||
short enc_mode_inttostr(int enc_mode, char* enc_mode_str, size_t enc_mode_size);
|
||||
int strtol_wrapper(const char * const str, const int min,
|
||||
|
||||
@@ -33,50 +33,6 @@
|
||||
#include "fw_util.h"
|
||||
#include "cmd_cycle.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define ASCII_LEN 16
|
||||
|
||||
/* Generic hex dump function.
|
||||
*/
|
||||
void
|
||||
hex_dump(const unsigned char *data, const int size)
|
||||
{
|
||||
int ln=0, i=0, j=0;
|
||||
char ascii_str[ASCII_LEN+1] = {0};
|
||||
|
||||
for(i=0; i<size; i++)
|
||||
{
|
||||
if((i % ASCII_LEN) == 0)
|
||||
{
|
||||
printf(" %s\n 0x%.4x: ", ascii_str, i);
|
||||
memset(ascii_str, 0x0, ASCII_LEN-1);
|
||||
j = 0;
|
||||
}
|
||||
|
||||
printf("%.2x ", data[i]);
|
||||
|
||||
ascii_str[j++] = (data[i] < 0x20 || data[i] > 0x7e) ? '.' : data[i];
|
||||
|
||||
if(j == 8)
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
/* Remainder...
|
||||
*/
|
||||
ln = strlen(ascii_str);
|
||||
if(ln > 0)
|
||||
{
|
||||
for(i=0; i < ASCII_LEN-ln; i++)
|
||||
printf(" ");
|
||||
if(ln < 8)
|
||||
printf(" ");
|
||||
|
||||
printf(" %s\n\n", ascii_str);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Basic directory/binary checks (stat() and whether the path is actually
|
||||
* a directory or an executable).
|
||||
*/
|
||||
|
||||
@@ -60,7 +60,6 @@
|
||||
|
||||
/* Prototypes
|
||||
*/
|
||||
void hex_dump(const unsigned char *data, const int size);
|
||||
char* dump_ctx(fko_ctx_t ctx);
|
||||
int is_valid_dir(const char *path);
|
||||
int is_valid_exe(const char *path);
|
||||
|
||||
Reference in New Issue
Block a user