mirror of
https://github.com/Obfuscator-Collections/VMProtect.git
synced 2025-08-02 05:00:12 +03:00
first commit
Version 3.x.x
This commit is contained in:
169
VMProtectCon/console.cc
Normal file
169
VMProtectCon/console.cc
Normal file
@@ -0,0 +1,169 @@
|
||||
#include "../core/objects.h"
|
||||
#include "../core/osutils.h"
|
||||
#include "../core/files.h"
|
||||
#include "../core/processors.h"
|
||||
#include "../core/lang.h"
|
||||
#include "console.h"
|
||||
|
||||
/**
|
||||
* ConsoleLog
|
||||
*/
|
||||
|
||||
ConsoleLog::ConsoleLog()
|
||||
: pos_(0), max_(0), percent_value_(0), percent_chars_(0), warnings_as_errors_(false)
|
||||
{
|
||||
show_progress_ = (isatty(fileno(stdout)) != 0);
|
||||
}
|
||||
|
||||
static const char *compilation_type[] = {
|
||||
"V",
|
||||
"M",
|
||||
"U"
|
||||
};
|
||||
|
||||
bool IsUserFunction(const IFunction *func)
|
||||
{
|
||||
IArchitecture *file = func->owner()->owner();
|
||||
return (file && file->function_list()->IndexOf(func) != NOT_ID);
|
||||
}
|
||||
|
||||
void ConsoleLog::Notify(MessageType type, IObject *sender, const std::string &message)
|
||||
{
|
||||
static const LangString message_lang_type[] = {
|
||||
lsInformation,
|
||||
lsWarning,
|
||||
lsError,
|
||||
lsLoading,
|
||||
lsChanging,
|
||||
lsDeleting,
|
||||
lsScript,
|
||||
};
|
||||
|
||||
bool need_throw;
|
||||
if (type == mtWarning && warnings_as_errors_) {
|
||||
type = mtError;
|
||||
need_throw = true;
|
||||
} else {
|
||||
need_throw = false;
|
||||
}
|
||||
|
||||
std::string log_message, add;
|
||||
std::string message_type = language[message_lang_type[type]];
|
||||
if (sender) {
|
||||
if (IFunction *func = dynamic_cast<IFunction *>(sender)) {
|
||||
if (IsUserFunction(func) && (type == mtAdded || type == mtChanged || type == mtDeleted)) {
|
||||
std::string compilation_type_str = func->need_compile() ? compilation_type[func->compilation_type()] : "-";
|
||||
std::string address_str = func->type() != otUnknown ? string_format("%.8llX", func->address()) : "????????";
|
||||
log_message = string_format("%s [%s] %s %s", message_type.c_str(), compilation_type_str.c_str(), address_str.c_str(), func->display_name().c_str());
|
||||
}
|
||||
} else if (ICommand *command = dynamic_cast<ICommand *>(sender)) {
|
||||
if (IsUserFunction(command->owner())) {
|
||||
std::string func_name;
|
||||
if (command->owner()) {
|
||||
func_name = command->owner()->display_name();
|
||||
if (!func_name.empty())
|
||||
func_name += ".";
|
||||
}
|
||||
add = string_format("%s%.8llX: ", func_name.c_str(), command->address());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type == mtInformation || type == mtWarning || type == mtError || type == mtScript)
|
||||
log_message = string_format("[%s] %s%s", message_type.c_str(), add.c_str(), message.c_str());
|
||||
|
||||
if (!log_message.empty()) {
|
||||
EndProgress();
|
||||
PrintArch();
|
||||
operator << (log_message) << endl;
|
||||
}
|
||||
|
||||
if (need_throw)
|
||||
throw abort_error("");
|
||||
}
|
||||
|
||||
void ConsoleLog::StartProgress(const std::string &caption, unsigned long long max)
|
||||
{
|
||||
EndProgress();
|
||||
caption_ = caption;
|
||||
pos_ = 0;
|
||||
max_ = max;
|
||||
percent_value_ = 0;
|
||||
}
|
||||
|
||||
void ConsoleLog::PrintArch()
|
||||
{
|
||||
if (!arch_name_.empty())
|
||||
operator << (arch_name_) << "> ";
|
||||
}
|
||||
|
||||
void ConsoleLog::PrintPercent()
|
||||
{
|
||||
std::string percent_str = string_format(" %d%%", percent_value_);
|
||||
operator << (percent_str);
|
||||
percent_chars_ = percent_str.size();
|
||||
}
|
||||
|
||||
void ConsoleLog::StepProgress(unsigned long long value, bool is_project)
|
||||
{
|
||||
if (is_project)
|
||||
return;
|
||||
|
||||
pos_ += value;
|
||||
size_t old_percent_value = percent_value_;
|
||||
percent_value_ = static_cast<size_t>(100.0 * pos_ / max_);
|
||||
|
||||
if (percent_chars_) {
|
||||
if (percent_value_ == old_percent_value)
|
||||
return;
|
||||
|
||||
if (percent_chars_ != NEED_PRINT_PERCENT) {
|
||||
std::string back_str;
|
||||
size_t i;
|
||||
for (i = 0; i < percent_chars_; i++) {
|
||||
back_str += '\b';
|
||||
}
|
||||
for (i = 0; i < percent_chars_; i++) {
|
||||
back_str += ' ';
|
||||
}
|
||||
for (i = 0; i < percent_chars_; i++) {
|
||||
back_str += '\b';
|
||||
}
|
||||
operator << (back_str);
|
||||
}
|
||||
} else {
|
||||
PrintArch();
|
||||
operator << (caption_);
|
||||
}
|
||||
|
||||
if (show_progress_)
|
||||
PrintPercent();
|
||||
else
|
||||
percent_chars_ = NEED_PRINT_PERCENT;
|
||||
}
|
||||
|
||||
void ConsoleLog::EndProgress()
|
||||
{
|
||||
if (!percent_chars_)
|
||||
return;
|
||||
if (percent_chars_ == NEED_PRINT_PERCENT)
|
||||
PrintPercent();
|
||||
operator << (endl);
|
||||
percent_chars_ = 0;
|
||||
}
|
||||
|
||||
ConsoleLog &ConsoleLog::operator<<(ConsoleLog & (* function)(ConsoleLog &))
|
||||
{
|
||||
(*function)(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ConsoleLog &ConsoleLog::operator<<(const std::string &text)
|
||||
{
|
||||
os::Print(text.c_str());
|
||||
return *this;
|
||||
}
|
||||
|
||||
ConsoleLog &endl(ConsoleLog &log)
|
||||
{
|
||||
return log << "\n";
|
||||
}
|
34
VMProtectCon/console.h
Normal file
34
VMProtectCon/console.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef CONSOLE_H
|
||||
#define CONSOLE_H
|
||||
|
||||
class ConsoleLog : public ILog
|
||||
{
|
||||
public:
|
||||
ConsoleLog();
|
||||
virtual void Notify(MessageType type, IObject *sender, const std::string &message = "");
|
||||
virtual void StartProgress(const std::string &caption, unsigned long long max);
|
||||
virtual void StepProgress(unsigned long long value, bool is_project);
|
||||
virtual void EndProgress();
|
||||
virtual void set_warnings_as_errors(bool value) { warnings_as_errors_ = value; }
|
||||
virtual void set_arch_name(const std::string &arch_name) { arch_name_ = arch_name; }
|
||||
ConsoleLog &operator<<(ConsoleLog & (* function)(ConsoleLog &));
|
||||
ConsoleLog &operator<<(const std::string &text);
|
||||
private:
|
||||
enum {
|
||||
NEED_PRINT_PERCENT = (size_t)-1
|
||||
};
|
||||
void PrintArch();
|
||||
void PrintPercent();
|
||||
unsigned long long pos_;
|
||||
unsigned long long max_;
|
||||
size_t percent_value_;
|
||||
size_t percent_chars_;
|
||||
std::string caption_;
|
||||
bool warnings_as_errors_;
|
||||
bool show_progress_;
|
||||
std::string arch_name_;
|
||||
};
|
||||
|
||||
ConsoleLog &endl(ConsoleLog &log);
|
||||
|
||||
#endif
|
18
VMProtectCon/lin_console.mak
Normal file
18
VMProtectCon/lin_console.mak
Normal file
@@ -0,0 +1,18 @@
|
||||
SOURCES := console.cc main.cc
|
||||
|
||||
|
||||
PROJECT := vmprotect_con
|
||||
TARGET := $(PROJECT)
|
||||
BIN_DIR := ../bin/$(ARCH_DIR)/$(CFG_DIR)
|
||||
TMP_ARCH_DIR := ../tmp/lin/console/$(ARCH_DIR)
|
||||
TMP_DIR := $(TMP_ARCH_DIR)/$(CFG_DIR)/$(PROJECT)
|
||||
PCH_DIR := $(TMP_DIR)/$(PROJECT).gch
|
||||
DEFINES := $(CONFIG) -DTIXML_USE_STL
|
||||
LFLAGS := -Wl,-rpath,\$$ORIGIN
|
||||
LIBS := $(SDK_LIBS) -Wl,--no-as-needed -L../bin -lVMProtectSDK$(ARCH_DIR) -ldl -Wl,--as-needed
|
||||
OBJCOMP := ../bin/$(ARCH_DIR)/$(CFG_DIR)/core.a ../bin/$(ARCH_DIR)/invariant_core.a ../third-party/libffi/libffi$(ARCH_DIR).a /usr/lib/$(ARCH)/libcrypto.a
|
||||
DYLIBS :=
|
||||
PCH_DIR := $(TMP_DIR)
|
||||
|
||||
include ../lin_common.mak
|
||||
include ../gnu_simple.mak
|
3
VMProtectCon/lin_console32.mak
Normal file
3
VMProtectCon/lin_console32.mak
Normal file
@@ -0,0 +1,3 @@
|
||||
ARCH := i386-linux-gnu
|
||||
ARCH_DIR := 32
|
||||
include lin_console.mak
|
3
VMProtectCon/lin_console64.mak
Normal file
3
VMProtectCon/lin_console64.mak
Normal file
@@ -0,0 +1,3 @@
|
||||
ARCH := x86_64-linux-gnu
|
||||
ARCH_DIR := 64
|
||||
include lin_console.mak
|
18
VMProtectCon/mac_console.mak
Normal file
18
VMProtectCon/mac_console.mak
Normal file
@@ -0,0 +1,18 @@
|
||||
SOURCES := console.cc main.cc
|
||||
|
||||
|
||||
PROJECT := vmprotect_con
|
||||
TARGET := $(PROJECT)
|
||||
BIN_DIR := ../bin/$(ARCH_DIR)/$(CFG_DIR)
|
||||
TMP_ARCH_DIR := ../tmp/mac/console/$(ARCH_DIR)
|
||||
TMP_DIR := $(TMP_ARCH_DIR)/$(CFG_DIR)/$(PROJECT)
|
||||
PCH_DIR := $(TMP_DIR)/$(PROJECT).gch
|
||||
DEFINES := $(CONFIG) -DTIXML_USE_STL
|
||||
LFLAGS :=
|
||||
LIBS := -framework CoreServices -framework Security
|
||||
OBJCOMP := ../bin/$(ARCH_DIR)/invariant_core.a ../bin/$(ARCH_DIR)/$(CFG_DIR)/core.a /usr/local/opt/libffi/lib/libffi.a
|
||||
DYLIBS := ../bin/libVMProtectSDK.dylib
|
||||
PCH_DIR := $(TMP_DIR)
|
||||
|
||||
include ../mac_common.mak
|
||||
include ../gnu_simple.mak
|
3
VMProtectCon/mac_console32.mak
Normal file
3
VMProtectCon/mac_console32.mak
Normal file
@@ -0,0 +1,3 @@
|
||||
ARCH := i386
|
||||
ARCH_DIR := 32
|
||||
include mac_console.mak
|
3
VMProtectCon/mac_console64.mak
Normal file
3
VMProtectCon/mac_console64.mak
Normal file
@@ -0,0 +1,3 @@
|
||||
ARCH := x86_64
|
||||
ARCH_DIR := 64
|
||||
include mac_console.mak
|
231
VMProtectCon/main.cc
Normal file
231
VMProtectCon/main.cc
Normal file
@@ -0,0 +1,231 @@
|
||||
#include "../core/objects.h"
|
||||
#include "../core/osutils.h"
|
||||
#include "../core/streams.h"
|
||||
#include "../core/files.h"
|
||||
#include "../core/core.h"
|
||||
#include "../core/script.h"
|
||||
#include "../core/lang.h"
|
||||
#include "console.h"
|
||||
#include "main.h"
|
||||
|
||||
#ifdef VMP_GNU
|
||||
int main(int argc, const char *argv[])
|
||||
#else
|
||||
|
||||
int wmain(int argc, wchar_t *argv[])
|
||||
#endif
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
#ifdef VMP_GNU
|
||||
args.push_back(argv[i]);
|
||||
#else
|
||||
args.push_back(os::ToUTF8(argv[i]));
|
||||
#endif
|
||||
}
|
||||
return ConsoleApplication(args).Run();
|
||||
}
|
||||
|
||||
/**
|
||||
* ConsoleApplication
|
||||
*/
|
||||
|
||||
ConsoleApplication::ConsoleApplication(const std::vector<std::string> &args)
|
||||
: args_(args)
|
||||
{
|
||||
log_ << string_format("%s v %s (build %s) %s", Core::edition(), Core::version(), Core::build(), Core::copyright()) << endl;
|
||||
}
|
||||
|
||||
#ifdef ULTIMATE
|
||||
static bool checkdate(int y, int m, int d)
|
||||
{
|
||||
if (m < 1 || m > 12)
|
||||
return false;
|
||||
|
||||
int max_days;
|
||||
if (m == 4 || m == 6 || m == 9 || m == 11)
|
||||
max_days = 30;
|
||||
else if (m == 2)
|
||||
max_days = (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) ? 29 : 28;
|
||||
else
|
||||
max_days = 31;
|
||||
return (d >= 1 && d <= max_days);
|
||||
}
|
||||
#endif
|
||||
|
||||
int ConsoleApplication::Run()
|
||||
{
|
||||
#ifdef DEMO
|
||||
log_ << language[lsDemoVersion] << endl;
|
||||
#else
|
||||
bool is_registered = false;
|
||||
{
|
||||
VMProtectSerialNumberData serial_data;
|
||||
if (VMProtectSetSerialNumber(VMProtectDecryptStringA("SerialNumber")) == SERIAL_STATE_SUCCESS && VMProtectGetSerialNumberData(&serial_data, sizeof(serial_data))) {
|
||||
if (Core::check_license_edition(serial_data)) {
|
||||
log_ << string_format("%s: %s [%s], %s", language[lsRegisteredTo].c_str(),
|
||||
os::ToUTF8(serial_data.wUserName).c_str(), os::ToUTF8(serial_data.wEMail).c_str(), (serial_data.bUserData[0] & 1) ? "Personal License" : "Company License") << endl;
|
||||
is_registered = true;
|
||||
} else {
|
||||
VMProtectSetSerialNumber(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!is_registered) {
|
||||
log_ << language[lsUnregisteredVersion] << endl;
|
||||
}
|
||||
#endif
|
||||
log_ << endl;
|
||||
|
||||
if (args_.size() < 2) {
|
||||
log_ << string_format("%s: %s %s [%s] [-pf %s] [-sf %s]"
|
||||
#ifdef ULTIMATE
|
||||
" [-lf %s]"
|
||||
" [-bd %s]"
|
||||
#endif
|
||||
" [-wm %s] [-we]",
|
||||
language[lsUsage].c_str(),
|
||||
os::ExtractFileName(args_[0].c_str()).c_str(),
|
||||
language[lsFile].c_str(),
|
||||
language[lsOutputFile].c_str(),
|
||||
language[lsProjectFile].c_str(),
|
||||
language[lsScriptFile].c_str(),
|
||||
#ifdef ULTIMATE
|
||||
language[lsLicensingParametersFile].c_str(),
|
||||
language[lsBuildDate].c_str(),
|
||||
#endif
|
||||
language[lsWatermark].c_str()
|
||||
) << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string input_file_name;
|
||||
std::string output_file_name;
|
||||
std::string project_file_name;
|
||||
std::string script_file_name;
|
||||
std::string watermark_name;
|
||||
#ifdef ULTIMATE
|
||||
std::string licensing_params_file_name;
|
||||
uint32_t build_date = 0;
|
||||
#endif
|
||||
//std::string invalid_param;
|
||||
for (size_t i = 1; i < args_.size(); i++) {
|
||||
std::string param = args_[i];
|
||||
bool is_last = (i == args_.size() - 1);
|
||||
|
||||
bool invalid_value = false;
|
||||
if (param == "-pf") {
|
||||
if (is_last)
|
||||
invalid_value = true;
|
||||
else
|
||||
project_file_name = args_[++i];
|
||||
} else if (param == "-sf") {
|
||||
if (is_last)
|
||||
invalid_value = true;
|
||||
else
|
||||
script_file_name = args_[++i];
|
||||
} else if (param == "-wm") {
|
||||
if (is_last)
|
||||
invalid_value = true;
|
||||
else
|
||||
watermark_name = args_[++i];
|
||||
}
|
||||
#ifdef ULTIMATE
|
||||
else if (param == "-lf") {
|
||||
if (is_last)
|
||||
invalid_value = true;
|
||||
else
|
||||
licensing_params_file_name = args_[++i];
|
||||
} else if (param == "-bd") {
|
||||
if (is_last)
|
||||
invalid_value = true;
|
||||
else {
|
||||
int y, m, d;
|
||||
if (sscanf_s(args_[++i].c_str(), "%04d-%02d-%02d", &y, &m, &d) == 3 && checkdate(y, m, d))
|
||||
build_date = (y << 16) + (static_cast<uint8_t>(m) << 8) + static_cast<uint8_t>(d);
|
||||
else
|
||||
invalid_value = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (param == "-we") {
|
||||
log_.set_warnings_as_errors(true);
|
||||
} else {
|
||||
switch (i) {
|
||||
case 1:
|
||||
input_file_name = param;
|
||||
break;
|
||||
case 2:
|
||||
output_file_name = param;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (invalid_value) {
|
||||
log_.Notify(mtError, NULL, string_format(language[lsInvalidParameterValue].c_str(), param.c_str()));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::string current_path = os::GetCurrentPath();
|
||||
if (!input_file_name.empty())
|
||||
input_file_name = os::CombinePaths(current_path.c_str(), input_file_name.c_str());
|
||||
if (!project_file_name.empty()) {
|
||||
project_file_name = os::CombinePaths(current_path.c_str(), project_file_name.c_str());
|
||||
if (!os::FileExists(project_file_name.c_str())) {
|
||||
log_.Notify(mtError, NULL, string_format(language[lsFileNotFound].c_str(), project_file_name.c_str()));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#ifdef ULTIMATE
|
||||
if (!licensing_params_file_name.empty()) {
|
||||
licensing_params_file_name = os::CombinePaths(current_path.c_str(), licensing_params_file_name.c_str());
|
||||
if (!os::FileExists(licensing_params_file_name.c_str())) {
|
||||
log_.Notify(mtError, NULL, string_format(language[lsFileNotFound].c_str(), licensing_params_file_name.c_str()));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Core core(&log_);
|
||||
try {
|
||||
if (!core.Open(input_file_name, project_file_name
|
||||
#ifdef ULTIMATE
|
||||
, licensing_params_file_name
|
||||
#endif
|
||||
))
|
||||
return 1;
|
||||
|
||||
if (!output_file_name.empty())
|
||||
core.set_output_file_name(os::CombinePaths(current_path.c_str(), output_file_name.c_str()));
|
||||
|
||||
if (!script_file_name.empty()) {
|
||||
script_file_name = os::CombinePaths(current_path.c_str(), script_file_name.c_str());
|
||||
if (!core.script()->LoadFromFile(script_file_name)) {
|
||||
log_.Notify(mtError, NULL, string_format(language[os::FileExists(script_file_name.c_str()) ? lsOpenFileError : lsFileNotFound].c_str(), script_file_name.c_str()));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!watermark_name.empty())
|
||||
core.set_watermark_name(watermark_name);
|
||||
|
||||
#ifdef ULTIMATE
|
||||
if (build_date)
|
||||
core.licensing_manager()->set_build_date(build_date);
|
||||
#endif
|
||||
|
||||
if (!core.Compile())
|
||||
return 1;
|
||||
|
||||
} catch (abort_error & /*error*/) {
|
||||
return 1;
|
||||
} catch (std::runtime_error &error) {
|
||||
if (error.what())
|
||||
log_.Notify(mtError, NULL, error.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
log_ << endl << language[lsCompiled] << endl;
|
||||
return 0;
|
||||
}
|
14
VMProtectCon/main.h
Normal file
14
VMProtectCon/main.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
class ConsoleApplication
|
||||
{
|
||||
public:
|
||||
ConsoleApplication(const std::vector<std::string> &args);
|
||||
int Run();
|
||||
private:
|
||||
std::vector<std::string> args_;
|
||||
ConsoleLog log_;
|
||||
};
|
||||
|
||||
#endif
|
1
VMProtectCon/precompiled.cc
Normal file
1
VMProtectCon/precompiled.cc
Normal file
@@ -0,0 +1 @@
|
||||
#include "precompiled.h"
|
7
VMProtectCon/precompiled.h
Normal file
7
VMProtectCon/precompiled.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#ifndef VMPC_PCH
|
||||
#define VMPC_PCH
|
||||
|
||||
#include "../core/precompiled.h"
|
||||
|
||||
#endif //VMPC_PCH
|
Reference in New Issue
Block a user