Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
some compiler warning fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hotline1337 committed Jun 25, 2023
1 parent 983c172 commit fddb735
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 44 deletions.
2 changes: 2 additions & 0 deletions R3nzSkin/R3nzSkin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
<FloatingPointExceptions>false</FloatingPointExceptions>
<CreateHotpatchableImage>false</CreateHotpatchableImage>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalOptions>/EHsc %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
53 changes: 52 additions & 1 deletion R3nzSkin_Injector/Injector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
#include <string>
#include <thread>
#include <tlhelp32.h>
#include <regex>
#include <msclr/marshal_cppstd.h>

#include "Injector.hpp"
#include "R3nzUI.hpp"
#include "lazy_importer.hpp"

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Threading;
using namespace System::Globalization;
using namespace System::Net;

proclist_t WINAPI Injector::findProcesses(const std::wstring name) noexcept
{
auto process_snap{ LI_FN(CreateToolhelp32Snapshot)(TH32CS_SNAPPROCESS, 0) };
Expand Down Expand Up @@ -84,7 +92,7 @@ bool WINAPI Injector::inject(const std::uint32_t pid) noexcept
const auto dll_path{ std::wstring(current_dir) + L"\\R3nzSkin.dll" };

if (auto f{ std::ifstream(dll_path) }; !f.is_open()) {
LI_FN(MessageBox)(nullptr, L"R3nzSkin.dll file could not be found.\nTry reinstalling the cheat.", L"R3nzSkin", MB_ICONERROR | MB_OK);
LI_FN(MessageBoxW)(nullptr, L"R3nzSkin.dll file could not be found.\nTry reinstalling the cheat.", L"R3nzSkin", MB_ICONERROR | MB_OK);
LI_FN(CloseHandle)(handle);
return false;
}
Expand Down Expand Up @@ -146,6 +154,49 @@ std::string Injector::randomString(std::uint32_t size) noexcept
return tmp_s;
}

void Injector::autoUpdate()
{
WebClient^ client = gcnew WebClient();
client->Headers->Add(L"User-Agent", L"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0");

try
{
std::string json = msclr::interop::marshal_as<std::string>(client->DownloadString(L"https://api.github.com/repos/R3nzTheCodeGOD/R3nzSkin/releases/latest"));
std::regex tagnameRegex("\"tag_name\"\\s*:\\s*\"([^\"]+)");
std::regex urlRegex("\"browser_download_url\"\\s*:\\s*\"([^\"]+)");
std::regex dateRegex("\"created_at\"\\s*:\\s*\"([^\"]+)");

std::smatch tagnameMatch, urlMatch, dateMatch;
if (std::regex_search(json, tagnameMatch, tagnameRegex))
{
auto version = gcnew String(tagnameMatch[1].str().c_str());
if (std::regex_search(json, dateMatch, dateRegex))
{
auto date_of_new_release = DateTime::ParseExact(gcnew String(dateMatch[1].str().c_str()), L"yyyy-MM-ddTHH:mm:ssZ", CultureInfo::InvariantCulture).ToString(L"dd.MM.yyyy");
auto date_of_current_release = System::IO::File::GetLastWriteTime(L"R3nzSkin.dll").ToString(L"dd.MM.yyyy");
if (date_of_current_release != date_of_new_release)
{
auto result = MessageBox::Show(L"New version is available on GitHub\nWould you like to download it now?", L"R3nzSkin", MessageBoxButtons::YesNo, MessageBoxIcon::Information);
if (result == DialogResult::Yes)
{
if (std::regex_search(json, urlMatch, urlRegex))
{
auto url = gcnew String(urlMatch[1].str().c_str());
auto file = String::Format(L"R3nzSkin_{0}.zip", version);
client->DownloadFile(url, file);
Environment::Exit(0);
}
}
}
}
}
}
catch (Exception^ e)
{
MessageBox::Show(e->Message, L"R3nzSkin", MessageBoxButtons::OK, MessageBoxIcon::Error);
}
}

void Injector::renameExe() noexcept
{
char szExeFileName[MAX_PATH];
Expand Down
7 changes: 7 additions & 0 deletions R3nzSkin_Injector/Injector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
using namespace std::chrono_literals;
using proclist_t = std::vector<std::uint32_t>;

// comment out when building on your own
//#define PERSONAL_BUILD
#ifndef PERSONAL_BUILD
#define GITHUB_BUILD
#endif

NTSTATUS NTAPI NtCreateThreadEx(PHANDLE, ACCESS_MASK, LPVOID, HANDLE, LPTHREAD_START_ROUTINE, LPVOID, BOOL, SIZE_T, SIZE_T, SIZE_T, LPVOID);

class Injector {
Expand All @@ -18,6 +24,7 @@ class Injector {
static bool WINAPI inject(const std::uint32_t pid) noexcept;
static void WINAPI enableDebugPrivilege() noexcept;
static std::string randomString(std::uint32_t size) noexcept;
static void autoUpdate();
static void renameExe() noexcept;
static void run() noexcept;
};
2 changes: 2 additions & 0 deletions R3nzSkin_Injector/R3nzSkin_Injector.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<StringPooling>true</StringPooling>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -217,6 +218,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
46 changes: 3 additions & 43 deletions R3nzSkin_Injector/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,12 @@ using namespace System::Threading;
using namespace System::Globalization;
using namespace System::Net;

void auto_update()
{
WebClient^ client = gcnew WebClient();
client->Headers->Add(L"User-Agent", L"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0");

try
{
std::string json = msclr::interop::marshal_as<std::string>(client->DownloadString(L"https://api.github.com/repos/R3nzTheCodeGOD/R3nzSkin/releases/latest"));
std::regex tagnameRegex("\"tag_name\"\\s*:\\s*\"([^\"]+)");
std::regex urlRegex("\"browser_download_url\"\\s*:\\s*\"([^\"]+)");
std::regex dateRegex("\"created_at\"\\s*:\\s*\"([^\"]+)");

std::smatch tagnameMatch, urlMatch, dateMatch;
if (std::regex_search(json, tagnameMatch, tagnameRegex))
{
auto version = gcnew String(tagnameMatch[1].str().c_str());
if (std::regex_search(json, dateMatch, dateRegex))
{
auto date_of_new_release = DateTime::ParseExact(gcnew String(dateMatch[1].str().c_str()), L"yyyy-MM-ddTHH:mm:ssZ", CultureInfo::InvariantCulture).ToString(L"dd.MM.yyyy");
auto date_of_current_release = System::IO::File::GetLastWriteTime(L"R3nzSkin.dll").ToString(L"dd.MM.yyyy");
if (date_of_current_release != date_of_new_release)
{
auto result = LI_FN(MessageBoxW)(nullptr, L"New version is available on GitHub\nWould you like to download it now?", L"R3nzSkin", MB_YESNO | MB_ICONINFORMATION);
if (result == IDYES)
{
if (std::regex_search(json, urlMatch, urlRegex))
{
auto url = gcnew String(urlMatch[1].str().c_str());
client->DownloadFile(url, String::Format(L"R3nzSkin_{0}.zip", version));
Environment::Exit(0);
}
}
}
}
}
}
catch (Exception^ e)
{
MessageBox::Show(e->Message, L"R3nzSkin", MessageBoxButtons::OK, MessageBoxIcon::Error);
}
}

int main([[maybe_unused]] array<String^>^ args)
{
auto_update();
std::srand(static_cast<unsigned int>(std::time(nullptr)));
#ifdef GITHUB_BUILD
Injector::autoUpdate();
#endif
Injector::renameExe();

Application::EnableVisualStyles();
Expand Down

0 comments on commit fddb735

Please sign in to comment.