-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.cpp
More file actions
66 lines (59 loc) · 1.86 KB
/
Copy pathhelper.cpp
File metadata and controls
66 lines (59 loc) · 1.86 KB
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
#include <iostream>
#include <iomanip>
#include "helper.hpp"
#include "context.hpp"
using namespace std;
bool ldump(const void* data, uint length, uint start) {
if (!Context::debug) return false;
uint end = start + length;
string txt; // for ASCII display
const auto align = 32;
if (length >= align) cerr << endl;
auto offset(0);
const char* chars = static_cast<const char*>(data);
for (uint i = start; i < end; i++) {
uint8_t c = chars[i];
if (!(offset % align)) cerr << setw(4) << dec << offset << 'x' << setw(3) << uppercase << hex << offset << ": ";
cerr << std::hex << std::setw(2) << static_cast<uint16_t>(c) << ' ';
txt.push_back(isprint(c)? c: ' ');
offset++;
if (!(offset % 8) && (offset % align)) {
cerr << '|';
txt.push_back('|');
}
if (!(offset % align)) {
cerr << '\t' << txt;
if (offset < length) cerr << endl;
txt.clear();
}
}
if (length >= align) while (offset % align) {
offset++;
cerr << "_ _";
if (!(offset % 8) && (offset % align))
cerr << '|';
if (!(offset % align))
cerr << '\t' << txt;
}
else cerr << tab << txt;
return true;
}
bool pdump(const void* start, const void* end) {
uint length = reinterpret_cast<const char*>(end) - reinterpret_cast<const char*>(start);
return ldump(start, length);
}
bool dump(const vector<char>& data) {
if (!Context::debug) return false;
return ldump(data.data(), (uint)data.size());
}
string& lower(string& text) {
for (auto& c: text)
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
return text;
}
void confirm(bool cond) {
if (!Context::confirm && !cond) return;
cerr << "\tPress ENTER to continue...\n";
cin.get();
cerr << clean;
}