-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalUtil.cpp
executable file
·69 lines (64 loc) · 1.73 KB
/
localUtil.cpp
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
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "localUtil.h"
template<typename unitLen>
void dumpMemT(unsigned char* base, size_t len, const char* format)
{
size_t i = 0;
printf("%04hx: ", (unsigned short)i);
for (i = 0; i < len; i += (sizeof(unitLen)))
{
if (((i % 0x10) == 0) && (i != 0))
{
printf("\n");
printf("UD:%04hx: ", (unsigned short)i);
}
printf(format, *((unitLen*)&base[i]));
}
}
void dumpMem(uint8_t* base, size_t len, char* format_a)
{
char format = format_a[0];
const char formatdump[10] = {0};
char* formatdumpcur = (char*)formatdump;
printf("UD:");
if (format_a[1] == 'x')
{
snprintf(formatdumpcur, sizeof(formatdump), "0x");
formatdumpcur = (char*)&formatdump[2];
}
if (format == 's')
{
printf(" %s", (char*)base);
}
else
{
if ((format == 'c') || (format == 'b'))
{
snprintf(formatdumpcur, sizeof(formatdump), "%%02hhx ");
dumpMemT<uint8_t>(base, len, formatdump);
}
else if (format == 'h')
{
snprintf(formatdumpcur, sizeof(formatdump), "%%04hx ");
dumpMemT<uint16_t>(base, len, formatdump);
}
else if (format == 'w' || ((format == 0) && (sizeof(void*) == 4)))
{
snprintf(formatdumpcur, sizeof(formatdump), "%%08x ");
dumpMemT<uint32_t>(base, len, formatdump);
}
else if (format == 'q' || ((format == 0) && (sizeof(void*) == 8)))
{
#ifdef _WIN32
snprintf(formatdumpcur, sizeof(formatdump), "%%016llx ");
#else
snprintf(formatdumpcur, sizeof(formatdump), "%%016lx ");
#endif
dumpMemT<uint64_t>(base, len, formatdump);
}
}
printf("\n");
}