Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
75 lines (69 loc) · 1.89 KB

File metadata and controls

75 lines (69 loc) · 1.89 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <math.h>
static std::vector<char> read_file_buf(const std::string& file_path) {
std::ifstream file(file_path, std::ios::binary | std::ios::ate);
if (file) {
auto size = file.tellg();
std::vector<char> buffer(size);
file.seekg(0, std::ios::beg);
file.read(buffer.data(), size);
file.close();
return buffer;
}
return {};
}
static void get_rand_str(char* dest, int n) {
int i, randno;
char stardstring[63] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
srand((unsigned)time(NULL));
for (i = 0; i < n; i++) {
randno = rand() % 62;
*dest = stardstring[randno];
dest++;
}
}
static std::string generate_random_root_key() {
const int key_len = 48;
char root_key_data[key_len] = { 0 };
get_rand_str(root_key_data, sizeof(root_key_data));
std::string str_root_key(root_key_data, sizeof(root_key_data));
return str_root_key;
}
static auto hex2byte(uint8_t* hex, uint8_t* str) -> void {
char high, low;
for (size_t i = 0, length = strlen((char*)hex); i < length; i += 2) {
high = toupper(hex[i]) - '0';
low = toupper(hex[i + 1]) - '0';
str[i / 2] = ((high > 9 ? high - 7 : high) << 4) + (low > 9 ? low - 7 : low);
}
}
static bool write_file_bytes(const char* file_path, size_t offset, const char* bytes, size_t len) {
std::fstream file_stream(file_path, std::ios::in | std::ios::out | std::ios::binary);
if (!file_stream) {
return false;
}
file_stream.seekp(offset);
if (!file_stream.good()) {
file_stream.close();
return false;
}
file_stream.write(bytes, len);
if (!file_stream.good()) {
file_stream.close();
return false;
}
file_stream.close();
return true;
}
static size_t align8(size_t addr) {
if (addr % 8 != 0) {
addr = (addr + 7) & ~static_cast<size_t>(7); // Align to next 8-byte boundary
}
return addr;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.