-
-
Save morelli690/4a57376d02c676d4b261185c23b1dead to your computer and use it in GitHub Desktop.
Converts any file's byte's into a Resource Header file. File -> Resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <Windows.h> | |
#include <TlHelp32.h> | |
#include <iostream> | |
#include <fstream> | |
std::string file_path = ""; | |
std::string file_endpath = ""; | |
std::string namespace_name = "example_namespace"; | |
std::string namespace_resource_name = "resources"; | |
int linebreak_number = 40; | |
bool ReadFileToMemory(const std::string& file_path, std::vector<uint8_t>* out_buffer) | |
{ | |
std::ifstream file_ifstream(file_path, std::ios::binary); | |
if (!file_ifstream) | |
return false; | |
out_buffer->assign((std::istreambuf_iterator<char>(file_ifstream)), std::istreambuf_iterator<char>()); | |
file_ifstream.close(); | |
return true; | |
} | |
int main(int argc, char* argv[]) | |
{ | |
std::vector<uint8_t> dll_contents; | |
ReadFileToMemory(file_path, &dll_contents); | |
FILE* file = fopen(file_endpath.c_str(), "w"); | |
fprintf(file, "#pragma once\n#include <stdint.h>\n\nnamespace %s {\n\tuint8_t %s[] = {\n\t\t", namespace_name, namespace_resource_name); | |
for (size_t i = 0; i < dll_contents.size(); i++) { | |
uint8_t byte = dll_contents.at(i); | |
if (i == dll_contents.size() - 1) { | |
fprintf(file, "0x%02X", byte); | |
} | |
else { | |
fprintf(file, "0x%02X, ", byte); | |
if (((i + 1) % linebreak_number) == 0) | |
fprintf(file, "\n\t\t"); | |
} | |
} | |
fprintf(file, "\n\t};\n};"); | |
fclose(file); | |
system("pause"); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment