added new handler which using std::runtime_error, enable virtual term processing moved on utils.hpp, removed defines for output errors and info
This commit is contained in:
@@ -15,14 +15,12 @@ c_core::c_core(std::string input_file, std::string output_file, std::uint32_t mu
|
|||||||
std::ifstream pe_file(m_input, std::ios::in | std::ios::binary);
|
std::ifstream pe_file(m_input, std::ios::in | std::ios::binary);
|
||||||
if (!pe_file) {
|
if (!pe_file) {
|
||||||
print_error("Binary is not PE file\n");
|
print_error("Binary is not PE file\n");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
m_peImage = std::make_unique<pe_bliss::pe_base>(pe_bliss::pe_factory::create_pe(pe_file));
|
m_peImage = std::make_unique<pe_bliss::pe_base>(pe_bliss::pe_factory::create_pe(pe_file));
|
||||||
if (m_peImage->get_pe_type() != pe_bliss::pe_type_32) {
|
if (m_peImage->get_pe_type() != pe_bliss::pe_type_32) {
|
||||||
print_error("Binary is not x86 architecture\n");
|
print_error("Binary is not x86 architecture\n");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JitRuntime jitRt;
|
JitRuntime jitRt;
|
||||||
@@ -31,7 +29,6 @@ c_core::c_core(std::string input_file, std::string output_file, std::uint32_t mu
|
|||||||
|
|
||||||
if (init_asmjit != kErrorOk) {
|
if (init_asmjit != kErrorOk) {
|
||||||
print_error("Failed initialization\n");
|
print_error("Failed initialization\n");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_custom("asmjit", "Successfully asmjit initialization\n");
|
print_custom("asmjit", "Successfully asmjit initialization\n");
|
||||||
@@ -370,6 +367,8 @@ void c_core::process()
|
|||||||
patch_file.close();
|
patch_file.close();
|
||||||
|
|
||||||
print_info("File successfully packed and saved in %s", m_output.c_str());
|
print_info("File successfully packed and saved in %s", m_output.c_str());
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void c_core::simple_jump_obfuscation()
|
void c_core::simple_jump_obfuscation()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#define COLOR_RESET "\033[0m"
|
#define COLOR_RESET "\033[0m"
|
||||||
#define COLOR_RED "\033[31m"
|
#define COLOR_RED "\033[31m"
|
||||||
@@ -7,10 +8,39 @@
|
|||||||
#define COLOR_BLUE "\033[34m"
|
#define COLOR_BLUE "\033[34m"
|
||||||
#define COLOR_CYAN "\033[36m"
|
#define COLOR_CYAN "\033[36m"
|
||||||
|
|
||||||
#define print_warning(fmt, ...) printf("[ " COLOR_YELLOW "warning" COLOR_RESET " ] " fmt, ##__VA_ARGS__)
|
//#define print_warning(fmt, ...) printf("[ " COLOR_YELLOW "warning" COLOR_RESET " ] " fmt, ##__VA_ARGS__)
|
||||||
#define print_info(fmt, ...) printf("[ " COLOR_CYAN "info" COLOR_RESET " ] " fmt, ##__VA_ARGS__)
|
//#define print_info(fmt, ...) printf("[ " COLOR_CYAN "info" COLOR_RESET " ] " fmt, ##__VA_ARGS__)
|
||||||
#define print_custom(fmt, mdl, ...) printf("[ " COLOR_GREEN "%s" COLOR_RESET " ] " mdl, fmt, ##__VA_ARGS__)
|
//#define print_custom(fmt, mdl, ...) printf("[ " COLOR_GREEN "%s" COLOR_RESET " ] " mdl, fmt, ##__VA_ARGS__)
|
||||||
#define print_error(fmt, ...) printf("[ " COLOR_RED "error" COLOR_RESET " ] " fmt, ##__VA_ARGS__);
|
|
||||||
|
inline void print_custom(const char* mdl, const char* fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
printf("[ " COLOR_GREEN "%s" COLOR_RESET " ] ", mdl);
|
||||||
|
vprintf(fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void print_warning(const char* fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
printf("[ " COLOR_YELLOW "info" COLOR_RESET " ] ");
|
||||||
|
vprintf(fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void print_info(const char* fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
printf("[ " COLOR_CYAN "info" COLOR_RESET " ] ");
|
||||||
|
vprintf(fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[noreturn]] inline void print_error(const std::string& msg) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << msg;
|
||||||
|
throw std::runtime_error(ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
#define error_handling(condition, from, text) \
|
#define error_handling(condition, from, text) \
|
||||||
try { \
|
try { \
|
||||||
|
|||||||
@@ -1,22 +1,12 @@
|
|||||||
#include "core/core.hpp"
|
#include "core/core.hpp"
|
||||||
|
#include "utils/utils.hpp"
|
||||||
|
|
||||||
c_core* packer = nullptr;
|
c_core* packer = nullptr;
|
||||||
|
|
||||||
void enable_virtual_terminal_processing() {
|
|
||||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
||||||
if (hOut == INVALID_HANDLE_VALUE) return;
|
|
||||||
|
|
||||||
DWORD dwMode = 0;
|
|
||||||
if (!GetConsoleMode(hOut, &dwMode)) return;
|
|
||||||
|
|
||||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
|
||||||
SetConsoleMode(hOut, dwMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
print_error("invalid arguments");
|
print_error("Invalid arguments");
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arguments::init(argc, argv);
|
arguments::init(argc, argv);
|
||||||
@@ -33,12 +23,14 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
auto packer = std::make_unique<c_core>(argv[1], argv[2], mut_count);
|
auto packer = std::make_unique<c_core>(argv[1], argv[2], mut_count);
|
||||||
|
|
||||||
print_info("mutations count: %i\n", mut_count);
|
print_info("Mutations count: %i\n", mut_count);
|
||||||
packer->process();
|
packer->process();
|
||||||
}
|
}
|
||||||
catch(const std::exception& ex)
|
catch(const std::exception& ex)
|
||||||
{
|
{
|
||||||
print_error("Exception: %s\n", ex.what());
|
std::stringstream ss;
|
||||||
|
ss << "[ " << COLOR_RED << "error" << COLOR_RESET << " ] " << ex.what();
|
||||||
|
std::cerr << ss.str();
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,3 +8,14 @@ inline int random_value(int from, int to) {
|
|||||||
|
|
||||||
return dist6(rng);
|
return dist6(rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void enable_virtual_terminal_processing() {
|
||||||
|
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
if (hOut == INVALID_HANDLE_VALUE) return;
|
||||||
|
|
||||||
|
DWORD dwMode = 0;
|
||||||
|
if (!GetConsoleMode(hOut, &dwMode)) return;
|
||||||
|
|
||||||
|
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||||
|
SetConsoleMode(hOut, dwMode);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user