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:
notcpuid
2025-07-02 08:50:40 +03:00
parent 6dfed55ebc
commit 6aabd8950a
4 changed files with 54 additions and 22 deletions

View File

@@ -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);
if (!pe_file) {
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));
if (m_peImage->get_pe_type() != pe_bliss::pe_type_32) {
print_error("Binary is not x86 architecture\n");
return;
}
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) {
print_error("Failed initialization\n");
return;
}
print_custom("asmjit", "Successfully asmjit initialization\n");
@@ -370,6 +367,8 @@ void c_core::process()
patch_file.close();
print_info("File successfully packed and saved in %s", m_output.c_str());
return;
}
void c_core::simple_jump_obfuscation()

View File

@@ -1,4 +1,5 @@
#pragma once
#include <iostream>
#define COLOR_RESET "\033[0m"
#define COLOR_RED "\033[31m"
@@ -7,10 +8,39 @@
#define COLOR_BLUE "\033[34m"
#define COLOR_CYAN "\033[36m"
#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_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__);
//#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_custom(fmt, mdl, ...) printf("[ " COLOR_GREEN "%s" COLOR_RESET " ] " mdl, 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) \
try { \

View File

@@ -1,22 +1,12 @@
#include "core/core.hpp"
#include "utils/utils.hpp"
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[])
{
if (argc < 4) {
print_error("invalid arguments");
return EXIT_FAILURE;
print_error("Invalid arguments");
}
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);
print_info("mutations count: %i\n", mut_count);
print_info("Mutations count: %i\n", mut_count);
packer->process();
}
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;
}

View File

@@ -7,4 +7,15 @@ inline int random_value(int from, int to) {
std::uniform_int_distribution<std::mt19937::result_type> dist6(from, to);
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);
}