Skip to content

Commit

Permalink
fix TA_UseTrial not returning TA_OK
Browse files Browse the repository at this point in the history
computers with an already expired trial won't return TA_OK here

Closes #1
  • Loading branch information
relative committed Sep 23, 2020
1 parent 98e081d commit 41837ac
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string>
#include <chrono>
#include <vector>
#include <shlobj.h>

#include "TurboActivate.h"
#include "inih.h"
Expand All @@ -18,6 +19,7 @@ namespace config
namespace trial
{
bool enabled;
bool usetrial_ok;
uint32_t days_remaining;
}
namespace license
Expand All @@ -40,17 +42,6 @@ namespace config
bool force_ok;
}
}
void log_write(std::string str)
{
if (!config::log::enabled)
return;
static auto log_filename = []() {
auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
return "./ta-emulator-" + std::to_string(timestamp) + ".log";
}();
std::ofstream file(log_filename , std::ios::app | std::ios::out);
file << str << std::endl;
}

// shamelessly stole these two functions from https://stackoverflow.com/a/3999597
// i hate winapi
Expand All @@ -74,6 +65,22 @@ std::wstring utf8_decode(const std::string& str)
return wstrTo;
}


void log_write(std::string str)
{
if (!config::log::enabled)
return;
static auto log_filename = []() {
auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
/*LPWSTR path;
SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &path);
std::string p = utf8_encode(path);*/
return std::string(".\\ta-emulator-" + std::to_string(timestamp) + ".log").c_str();
}();
std::ofstream file(log_filename , std::ios::app | std::ios::out);
file << str << std::endl;
}

void initialize_ta_emulator()
{
auto* const turboactivate = LoadLibraryA("turboactivate_orig.dll");
Expand All @@ -94,6 +101,7 @@ void initialize_ta_emulator()

config::trial::enabled = reader.GetBoolean("trial", "enabled", true);
config::trial::days_remaining = reader.GetInteger("trial", "days_remaining", 9999);
config::trial::usetrial_ok = reader.GetBoolean("trial", "usetrial_ok", true);

config::license::enabled = reader.GetBoolean("license", "enabled", false);
config::license::is_activated = reader.GetBoolean("license", "is_activated", true);
Expand Down Expand Up @@ -313,6 +321,10 @@ TURBOACTIVATE_API HRESULT TA_CC TA_UseTrial(uint32_t handle, uint32_t flags, STR
flags &= ~TA_DISALLOW_VM;
}

if (config::trial::usetrial_ok) {
return TA_OK;
}

using originalfn = HRESULT(TA_CC*)(uint32_t, uint32_t, STRCTYPE);
auto retval = static_cast<originalfn>(imports.at(17))(handle, flags, extra_data);
if (config::misc::antivm_detect && retval == TA_E_IN_VM) retval = TA_OK;
Expand Down

0 comments on commit 41837ac

Please sign in to comment.