forked from the4chancup/4ccEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypt.cpp
More file actions
40 lines (32 loc) · 782 Bytes
/
crypt.cpp
File metadata and controls
40 lines (32 loc) · 782 Bytes
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
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include "crypt.h"
//encrypter & decrypter helpers ...
uint8_t *readFile(const TCHAR *path, uint32_t *sizePtr)
{
struct _stat file;
uint8_t *input;
int size;
FILE *inStream = _tfopen(path, _T("rb"));
if (!inStream)
return NULL;
if (_tstat(path, &file))
return NULL;
size = file.st_size;
input = (uint8_t *)malloc(size);
fread(input, 1, size, inStream);
fclose(inStream);
if (sizePtr)
*sizePtr = size;
return input;
}
void writeFile(const TCHAR *path, const uint8_t *data, int size)
{
FILE *outStream = _tfopen(path, _T("wb"));
if (!outStream)
return;
fwrite(data, 1, size, outStream);
fclose(outStream);
}