more cleanup

This commit is contained in:
Anonymous275
2020-12-20 14:11:17 +02:00
parent 49dd577c36
commit 4b9742553a
33 changed files with 316 additions and 904 deletions

View File

@@ -1,7 +1,11 @@
// Copyright (c) 2020 Anonymous275.
// BeamMP Launcher code is not in the public domain and is not free software.
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
///
/// Created by Anonymous275 on 7/18/2020
///
#include "Security/Enc.h"
#include <filesystem>
#include <Windows.h>
#include "Logger.h"
@@ -19,7 +23,7 @@ std::string GameDir;
void lowExit(int code){
TraceBack = 0;
std::string msg =
Sec("Failed to find the game please launch it. Report this if the issue persists code ");
"Failed to find the game please launch it. Report this if the issue persists code ";
error(msg+std::to_string(code));
std::this_thread::sleep_for(std::chrono::seconds(10));
exit(2);
@@ -27,7 +31,7 @@ void lowExit(int code){
void Exit(int code){
TraceBack = 0;
std::string msg =
Sec("Sorry. We do not support cracked copies report this if you believe this is a mistake code ");
"Sorry. We do not support cracked copies report this if you believe this is a mistake code ";
error(msg+std::to_string(code));
std::this_thread::sleep_for(std::chrono::seconds(10));
exit(3);
@@ -35,7 +39,7 @@ void Exit(int code){
void SteamExit(int code){
TraceBack = 0;
std::string msg =
Sec("Illegal steam modifications detected report this if you believe this is a mistake code ");
"Illegal steam modifications detected report this if you believe this is a mistake code ";
error(msg+std::to_string(code));
std::this_thread::sleep_for(std::chrono::seconds(10));
exit(4);
@@ -87,7 +91,7 @@ std::string QueryKey(HKEY hKey,int ID){
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,achKey,&cbName,nullptr,nullptr,nullptr,&ftLastWriteTime);
if (retCode == ERROR_SUCCESS){
if(strcmp(achKey,Sec("Steam App 284160")) == 0){
if(strcmp(achKey,"Steam App 284160") == 0){
return achKey;
}
}
@@ -105,13 +109,13 @@ std::string QueryKey(HKEY hKey,int ID){
std::string data = reinterpret_cast<const char *const>(buffer);
std::string key = achValue;
switch (ID){
case 1: if(key == Sec("SteamExe")){
case 1: if(key == "SteamExe"){
auto p = data.find_last_of('/');
if(p != std::string::npos)return data.substr(0,p);
}break;
case 2: if(key == Sec("Name") && data == Sec("BeamNG.drive"))return data;break;
case 3: if(key == Sec("rootpath"))return data;break;
case 4: if(key == Sec("userpath_override"))return data;
case 2: if(key == "Name" && data == "BeamNG.drive")return data;break;
case 3: if(key == "rootpath")return data;break;
case 4: if(key == "userpath_override")return data;
default: break;
}
}
@@ -131,7 +135,7 @@ void FileList(std::vector<std::string>&a,const std::string& Path){
}
bool Find(const std::string& FName,const std::string& Path){
std::vector<std::string> FS;
FileList(FS,Path+Sec("/userdata"));
FileList(FS,Path+"/userdata");
for(std::string&a : FS){
if(a.find(FName) != std::string::npos){
FS.clear();
@@ -146,8 +150,8 @@ bool FindHack(const std::string& Path){
for (const auto &entry : fs::directory_iterator(Path)) {
std::string Name = entry.path().filename().string();
for(char&c : Name)c = char(tolower(c));
if(Name == Sec("steam.exe"))s = false;
if(Name.find(Sec("greenluma")) != -1)return true;
if(Name == "steam.exe")s = false;
if(Name.find("greenluma") != -1)return true;
Name.clear();
}
return s;
@@ -209,7 +213,7 @@ std::string GetManifest(const std::string& Man){
f.seekg(0, std::ios_base::beg);
f.read(&vec[0], fileSize);
f.close();
std::string ToFind = Sec("\"LastOwner\"\t\t\"");
std::string ToFind = "\"LastOwner\"\t\t\"";
int pos = int(vec.find(ToFind));
if(pos != -1){
pos += int(ToFind.length());
@@ -219,10 +223,10 @@ std::string GetManifest(const std::string& Man){
}
bool IDCheck(std::string Man, std::string steam){
bool a = false,b = true;
int pos = int(Man.rfind(Sec("steamapps")));
int pos = int(Man.rfind("steamapps"));
if(pos == -1)Exit(5);
Man = Man.substr(0,pos+9) + Sec("/appmanifest_284160.acf");
steam += Sec("/config/loginusers.vdf");
Man = Man.substr(0,pos+9) + "/appmanifest_284160.acf";
steam += "/config/loginusers.vdf";
if(fs::exists(Man) && fs::exists(steam)){
for(const std::string&ID : GetID(steam)){
if(ID == GetManifest(Man))b = false;
@@ -233,16 +237,16 @@ bool IDCheck(std::string Man, std::string steam){
}
void LegitimacyCheck(){
std::string Result,T;
std::string K1 = Sec("Software\\Valve\\Steam");
std::string K2 = Sec("Software\\Valve\\Steam\\Apps\\284160");
std::string K3 = Sec("Software\\BeamNG\\BeamNG.drive");
std::string K1 = R"(Software\Valve\Steam)";
std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
HKEY hKey;
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 1);
if(Result.empty())Exit(1);
if(fs::exists(Result)){
if(!Find(Sec("284160.json"),Result))Exit(2);
if(!Find("284160.json",Result))Exit(2);
if(FindHack(Result))SteamExit(1);
}else Exit(3);
T = Result;
@@ -273,15 +277,14 @@ void LegitimacyCheck(){
if(TraceBack < 3)exit(-1);
}
std::string CheckVer(const std::string &dir){
std::string vec,temp,Path = dir + Sec("\\integrity.json");
std::string temp,Path = dir + "\\integrity.json";
std::ifstream f(Path.c_str(), std::ios::binary);
f.seekg(0, std::ios_base::end);
std::streampos fileSize = f.tellg();
vec.resize(size_t(fileSize) + 1);
f.seekg(0, std::ios_base::beg);
f.read(&vec[0], fileSize);
int Size = int(std::filesystem::file_size(Path));
std::string vec(Size,0);
f.read(&vec[0], Size);
f.close();
vec = vec.substr(vec.find_last_of(Sec("version")),vec.find_last_of('"'));
vec = vec.substr(vec.find_last_of("version"),vec.find_last_of('"'));
for(const char &a : vec){
if(isdigit(a) || a == '.')temp+=a;
}

View File

@@ -1,117 +0,0 @@
#include "Security/Enc.h"
#include <iostream>
#include <sstream>
#include <random>
int LocalKeys[] = {7406809,6967,4810803}; //n e d
int log_power(int n,unsigned int p, int mod){
int result = 1;
for (; p; p >>= 1u){
if (p & 1u)result = int((1LL * result * n) % mod);
n = int((1LL * n * n) % mod);
}
return result;
}
int Rand(){
std::random_device r;
std::default_random_engine e1(r());
std::uniform_int_distribution<int> uniform_dist(1, 5000);
return uniform_dist(e1);
}
bool rabin_miller(int n){
bool ok = true;
for (int i = 1; i <= 5 && ok; i++) {
int a = Rand() + 1;
int result = log_power(a, n - 1, n);
ok &= (result == 1);
}
return ok;
}
int generate_prime(){
int generated = Rand();
while (!rabin_miller(generated))generated = Rand();
return generated;
}
int gcd(int a, int b){
while (b){
int r = a % b;
a = b;
b = r;
}
return a;
}
int generate_coprime(int n){
int generated = Rand();
while (gcd(n, generated) != 1)generated = Rand();
return generated;
}
std::pair<int, int> euclid_extended(int a, int b) {
if(!b)return {1, 0};
auto result = euclid_extended(b, a % b);
return {result.second, result.first - (a / b) * result.second};
}
int modular_inverse(int n, int mod){
int inverse = euclid_extended(n, mod).first;
while(inverse < 0)inverse += mod;
return inverse;
}
RSA* GenKey(){
int p, q;
p = generate_prime();
q = generate_prime();
int n = p * q;
int phi = (p -1) * (q - 1);
int e = generate_coprime(phi);
int d = modular_inverse(e, phi);
return new RSA{n,e,d};
}
int Enc(int value,int e,int n){
return log_power(value, e, n);
}
int Dec(int value,int d,int n){
return log_power(value, d, n);
}
std::string LocalEnc(const std::string& Data){
std::stringstream stream;
for(const char&c : Data){
stream << std::hex << Enc(uint8_t(c),LocalKeys[1],LocalKeys[0]) << "g";
}
return stream.str();
}
std::string LocalDec(const std::string& Data){
std::stringstream ss(Data);
std::string token,ret;
while (std::getline(ss, token, 'g')) {
if(token.find_first_not_of(Sec("0123456789abcdef")) != std::string::npos)return "";
int c = std::stoi(token, nullptr, 16);
ret += char(Dec(c,LocalKeys[2],LocalKeys[0]));
}
return ret;
}
std::string RSA_E(const std::string& Data,int e, int n){
std::stringstream stream;
for(const char&c : Data){
stream << std::hex << Enc(uint8_t(c),e,n) << "g";
}
return stream.str();
}
std::string RSA_D(const std::string& Data, int d, int n){
std::stringstream ss(Data);
std::string token,ret;
while (std::getline(ss, token, 'g')) {
if(token.find_first_not_of(Sec("0123456789abcdef")) != std::string::npos)return "";
int c = std::stoi(token, nullptr, 16);
ret += char(Dec(c,d,n));
}
return ret;
}

View File

@@ -1,71 +0,0 @@
///
/// Created by Anonymous275 on 7/19/2020
///
#include "Security/Enc.h"
#include <windows.h>
#include "Security/Game.h"
#include <filesystem>
#include <RestartManager.h>
#include "Logger.h"
#include <thread>
namespace fs = std::experimental::filesystem;
void CheckDirs(){
for (auto& p : fs::directory_iterator(Sec("BeamNG\\mods"))) {
if(fs::is_directory(p.path()))exit(0);
}
}
bool BeamLoad(PCWSTR pszFile){
bool Ret = false;
DWORD dwSession;
WCHAR szSessionKey[CCH_RM_SESSION_KEY+1] = {0};
DWORD dwError = RmStartSession(&dwSession, 0, szSessionKey);
if (dwError == ERROR_SUCCESS) {
dwError = RmRegisterResources(dwSession, 1, &pszFile,
0, nullptr, 0, nullptr);
if (dwError == ERROR_SUCCESS) {
DWORD dwReason;
UINT nProcInfoNeeded;
UINT nProcInfo = 10;
RM_PROCESS_INFO rgpi[10];
dwError = RmGetList(dwSession, &nProcInfoNeeded,&nProcInfo, rgpi, &dwReason);
if (dwError == ERROR_SUCCESS) {
if(nProcInfo == 1){
std::string AppName(50,0);
size_t N;
wcstombs_s(&N,&AppName[0],50, rgpi[0].strAppName, 50);
if(!AppName.find(Sec("BeamNG.drive")) && GamePID == rgpi[0].Process.dwProcessId){
Ret = true;
}
}
}
}
RmEndSession(dwSession);
}
return Ret;
}
void ContinuousCheck(fs::file_time_type last){
std::string path = Sec(R"(BeamNG\mods\BeamMP.zip)");
int i = 0;
while(fs::exists(path) && last == fs::last_write_time(path)){
if(!BeamLoad(SecW(L"BeamNG\\mods\\BeamMP.zip"))) {
if (i < 120)i++;
else {
error(Sec("Mod did not load! launcher closing soon"));
std::this_thread::sleep_for(std::chrono::seconds(5));
exit(0);
}
}else i = 0;
CheckDirs();
std::this_thread::sleep_for(std::chrono::milliseconds(800));
}
exit(0);
}
void SecureMods(){
fs::file_time_type last = fs::last_write_time(Sec(R"(BeamNG\mods\BeamMP.zip)"));
auto* HandleCheck = new std::thread(ContinuousCheck,last);
HandleCheck->detach();
delete HandleCheck;
}

View File

@@ -1,3 +1,7 @@
// Copyright (c) 2020 Anonymous275.
// BeamMP Launcher code is not in the public domain and is not free software.
// One must be granted explicit permission by the copyright holder in order to modify or distribute any part of the source or binaries.
// Anything else is prohibited. Modified works may not be published and have be upstreamed to the official repository.
///
/// Created by Anonymous275 on 11/26/2020
///