forked from Prof-Butts/Hook_XWACockpitLook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hex.h
40 lines (35 loc) · 1010 Bytes
/
Hex.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
#pragma once
#include <cstring>
#include <cstdlib>
void* hexstr_to_char_address(unsigned char* address, const char* hexstr)
{
size_t len = strlen(hexstr);
if (len % 2 != 0)
return NULL;
size_t final_len = len / 2;
unsigned char* chrs = address;
for (size_t i = 0, j = 0; j < final_len; i += 2, j++)
chrs[j] = (hexstr[i] % 32 + 9) % 25 * 16 + (hexstr[i + 1] % 32 + 9) % 25;
return 0;
}
unsigned char* hexstr_to_char(const char* hexstr)
{
size_t len = strlen(hexstr);
if (len % 2 != 0)
return NULL;
size_t final_len = len / 2;
unsigned char* chrs = (unsigned char*)malloc((final_len + 1) * sizeof(*chrs));
for (size_t i = 0, j = 0; j < final_len; i += 2, j++)
chrs[j] = (hexstr[i] % 32 + 9) % 25 * 16 + (hexstr[i + 1] % 32 + 9) % 25;
chrs[final_len] = '\0';
return chrs;
}
void CopyByteString(char *destination, unsigned char *source, int size)
{
int count = 0;
for (int i = 0; count < size; i++)
{
destination[i] = source[i];
count++;
}
}