-
Notifications
You must be signed in to change notification settings - Fork 1
/
dumps.h
126 lines (113 loc) · 3.85 KB
/
dumps.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**************************************************
* Hexdump for Windows
*-------------------------------------------------
*
* Command line tool inspired by Linux tool
* hexdump - stripped to bare hexadecimal dump
* of given file with option to limit dump length
*
* File: dumps.h
*
*-------------------------------------------------
* Made by Marek Poláèek (Polda18)
**************************************************/
#pragma once
#include <stdio.h> // Measure for file descriptor
#ifndef __DUMPS_H__
#define __DUMPS_H__
// Define basic types
typedef unsigned short uword_t;
typedef unsigned char ubyte_t;
// Define constants
#define MIN_OFFSET_DIGITS 7
#define OVERFLOW_VALUE 0x10000000
#define BYTE_SIZE sizeof(ubyte_t)
#define WORD_SIZE sizeof(uword_t)
#define BYTE_ARRAY_NUM 16 / BYTE_SIZE
#define WORD_ARRAY_NUM 16 / WORD_SIZE
// Number format constants
#define HEX_PLAIN_FORMAT " %04x"
#define OCTAL_BYTE_FORMAT " %03o"
#define OCTAL_WORD_FORMAT " %06o"
#define DECIMAL_WORD_FORMAT " %05u"
#define HEX_WORD_FORMAT " %04x"
// Canonical format constants
#define CAN_HEX_SEPARATOR ' '
#define CAN_ASCII_SEPARATOR " "
#define CAN_HEX_FORMAT " %02x"
#define CAN_ASCII_FORMAT_NONASCII '.'
#define CAN_ASCII_FORMAT_BORDER '|'
// ASCII printable values boundaries
#define ASCII_LOWEST 0x20
#define ASCII_HIGHEST 0x7e
// National DOS codepage low boundary
#define ASCII_DOS_CP_BEGIN 0x80
// Printable character display
#define CHAR_BYTE_FORMAT_PRINTABLE " %c"
// Escape sequences
#define CHAR_BYTE_FORMAT_ESCAPE_NULL " \\0"
#define CHAR_BYTE_FORMAT_ESCAPE_BELL " \\a"
#define CHAR_BYTE_FORMAT_ESCAPE_BS " \\b"
#define CHAR_BYTE_FORMAT_ESCAPE_TAB " \\t"
#define CHAR_BYTE_FORMAT_ESCAPE_LF " \\n"
#define CHAR_BYTE_FORMAT_ESCAPE_VT " \\v"
#define CHAR_BYTE_FORMAT_ESCAPE_FF " \\f"
#define CHAR_BYTE_FORMAT_ESCAPE_CR " \\r"
// Values for escape sequences
#define CHAR_BYTE_VALUE_NULL 0x00 // null byte
#define CHAR_BYTE_VALUE_BELL 0x07 // beep
#define CHAR_BYTE_VALUE_BS 0x08 // backspace
#define CHAR_BYTE_VALUE_TAB 0x09 // tabulator
#define CHAR_BYTE_VALUE_LF 0x0a // line feed
#define CHAR_BYTE_VALUE_VT 0x0b // vertical tab
#define CHAR_BYTE_VALUE_FF 0x0c // form feed
#define CHAR_BYTE_VALUE_CR 0x0d // carriage return
// Declare functions
int dump_plain_hex(
FILE* file,
bool verbose,
size_t offset,
size_t* position,
size_t endoffset
); // Dump plain hex
int dump_byte_octal(
FILE* file,
bool verbose,
size_t* position,
size_t endoffset
); // Dump byte octal
int dump_byte_char(
FILE* file,
bool verbose,
size_t offset,
size_t* position,
size_t endoffset
); // Dump byte character
int dump_canonical(
FILE* file,
bool verbose,
size_t offset,
size_t* position,
size_t endoffset
); // Dump hex-ascii canonical
int dump_word_decimal(
FILE* file,
bool verbose,
size_t* position,
size_t endoffset
); // Dump word decimal
int dump_word_octal(
FILE* file,
bool verbose,
size_t offset,
size_t* position,
size_t endoffset
); // Dump word octal
int dump_word_hex(
FILE* file,
bool verbose,
size_t offset,
size_t* position,
size_t endoffset
); // Dump word hex
#endif