Skip to content

Commit

Permalink
extended versioninfo, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Oct 27, 2023
1 parent d124a34 commit a9415e5
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github: ThirteenAG
ko_fi: thirteenag
patreon: ThirteenAG
custom: [https://paypal.me/SergeyP13, https://boosty.to/thirteenag/donate]
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 6.{build}
version: 6.{build}.0
skip_tags: true
image: Visual Studio 2022
configuration: Release
Expand Down
56 changes: 45 additions & 11 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@ workspace "Ultimate-ASI-Loader-Win32"

defines { "rsc_CompanyName=\"ThirteenAG\"" }
defines { "rsc_LegalCopyright=\"MIT License\""}
if(_OPTIONS["with-version"]) then
defines { "rsc_FileVersion=\"" .. _OPTIONS["with-version"] .. "\"", "rsc_ProductVersion=\"" .. _OPTIONS["with-version"] .. "\"" }
else
defines { "rsc_FileVersion=\"1.0.0.0\"", "rsc_ProductVersion=\"1.0.0.0\"" }
end
defines { "rsc_InternalName=\"%{prj.name}\"", "rsc_ProductName=\"%{prj.name}\"", "rsc_OriginalFilename=\"%{prj.name}.dll\"" }
defines { "rsc_FileDescription=\"Ultimate ASI Loader\"" }
defines { "rsc_UpdateUrl=\"https://github.com/ThirteenAG/Ultimate-ASI-Loader\"" }

local major = 1
local minor = 0
local build = 0
local revision = 0
if(_OPTIONS["with-version"]) then
local t = {}
for i in _OPTIONS["with-version"]:gmatch("([^.]+)") do
t[#t + 1], _ = i:gsub("%D+", "")
end
while #t < 4 do t[#t + 1] = 0 end
major = math.min(tonumber(t[1]), 255)
minor = math.min(tonumber(t[2]), 255)
build = math.min(tonumber(t[3]), 65535)
revision = math.min(tonumber(t[4]), 65535)
end
defines { "rsc_FileVersion_MAJOR=" .. major }
defines { "rsc_FileVersion_MINOR=" .. minor }
defines { "rsc_FileVersion_BUILD=" .. build }
defines { "rsc_FileVersion_REVISION=" .. revision }
defines { "rsc_FileVersion=\"" .. major .. "." .. minor .. "." .. build .. "\"" }
defines { "rsc_ProductVersion=\"" .. major .. "." .. minor .. "." .. build .. "\"" }

project "Ultimate-ASI-Loader-Win32"
kind "SharedLib"
Expand Down Expand Up @@ -159,15 +176,32 @@ workspace "Ultimate-ASI-Loader-x64"

defines { "rsc_CompanyName=\"ThirteenAG\"" }
defines { "rsc_LegalCopyright=\"MIT License\""}
if(_OPTIONS["with-version"]) then
defines { "rsc_FileVersion=\"" .. _OPTIONS["with-version"] .. "\"", "rsc_ProductVersion=\"" .. _OPTIONS["with-version"] .. "\"" }
else
defines { "rsc_FileVersion=\"1.0.0.0\"", "rsc_ProductVersion=\"1.0.0.0\"" }
end
defines { "rsc_InternalName=\"%{prj.name}\"", "rsc_ProductName=\"%{prj.name}\"", "rsc_OriginalFilename=\"%{prj.name}.dll\"" }
defines { "rsc_FileDescription=\"Ultimate ASI Loader\"" }
defines { "rsc_UpdateUrl=\"https://github.com/ThirteenAG/Ultimate-ASI-Loader\"" }


local major = 1
local minor = 0
local build = 0
local revision = 0
if(_OPTIONS["with-version"]) then
local t = {}
for i in _OPTIONS["with-version"]:gmatch("([^.]+)") do
t[#t + 1], _ = i:gsub("%D+", "")
end
while #t < 4 do t[#t + 1] = 0 end
major = math.min(tonumber(t[1]), 255)
minor = math.min(tonumber(t[2]), 255)
build = math.min(tonumber(t[3]), 65535)
revision = math.min(tonumber(t[4]), 65535)
end
defines { "rsc_FileVersion_MAJOR=" .. major }
defines { "rsc_FileVersion_MINOR=" .. minor }
defines { "rsc_FileVersion_BUILD=" .. build }
defines { "rsc_FileVersion_REVISION=" .. revision }
defines { "rsc_FileVersion=\"" .. major .. "." .. minor .. "." .. build .. "\"" }
defines { "rsc_ProductVersion=\"" .. major .. "." .. minor .. "." .. build .. "\"" }

defines { "X64" }

project "Ultimate-ASI-Loader-x64"
Expand Down
84 changes: 81 additions & 3 deletions source/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ enum Kernel32ExportsData
Kernel32ExportsDataCount
};

enum OLE32ExportsNames
{
eCoCreateInstance,

OLE32ExportsNamesCount
};

size_t Kernel32Data[Kernel32ExportsNamesCount][Kernel32ExportsDataCount];
size_t OLE32Data[OLE32ExportsNamesCount][Kernel32ExportsDataCount];

#if !X64
#define IDR_VORBISF 101
Expand Down Expand Up @@ -749,12 +757,61 @@ std::filesystem::path GetFileName(auto lpFilename)
return str1.starts_with(str2);
};

static auto lexicallyRelativeCaseIns = [](const std::filesystem::path& path, const std::filesystem::path& base) -> std::filesystem::path
{
class input_iterator_range
{
public:
input_iterator_range(const std::filesystem::path::const_iterator& first, const std::filesystem::path::const_iterator& last)
: _first(first)
, _last(last)
{}
std::filesystem::path::const_iterator begin() const { return _first; }
std::filesystem::path::const_iterator end() const { return _last; }
private:
std::filesystem::path::const_iterator _first;
std::filesystem::path::const_iterator _last;
};

if (!iequals(path.root_name().wstring(), base.root_name().wstring()) || path.is_absolute() != base.is_absolute() || (!path.has_root_directory() && base.has_root_directory())) {
return std::filesystem::path();
}
std::filesystem::path::const_iterator a = path.begin(), b = base.begin();
while (a != path.end() && b != base.end() && iequals(a->wstring(), b->wstring())) {
++a;
++b;
}
if (a == path.end() && b == base.end()) {
return std::filesystem::path(".");
}
int count = 0;
for (const auto& element : input_iterator_range(b, base.end())) {
if (element != "." && element != "" && element != "..") {
++count;
}
else if (element == "..") {
--count;
}
}
if (count < 0) {
return std::filesystem::path();
}
std::filesystem::path result;
for (int i = 0; i < count; ++i) {
result /= "..";
}
for (const auto& element : input_iterator_range(a, path.end())) {
result /= element;
}
return result;
};

if (gamePath.empty())
gamePath = std::filesystem::path(GetExeModulePath());

auto filePath = std::filesystem::path(lpFilename);
auto absolutePath = std::filesystem::absolute(filePath, ec);
auto relativePath = std::filesystem::canonical(absolutePath, ec).lexically_relative(gamePath);
auto relativePath = lexicallyRelativeCaseIns(absolutePath, gamePath);
auto commonPath = gamePath;

if (starts_with(relativePath, ".."))
Expand Down Expand Up @@ -899,7 +956,7 @@ HRESULT WINAPI CustomCoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWOR
else if (rclsid == CLSID_WinInet)
hDll = ::LoadLibrary(L"wininet.dll");

if (hDll == NULL)
if (hDll == NULL || GetProcAddress(hDll, "IsUltimateASILoader") != NULL)
return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv);

typedef HRESULT(__stdcall *pDllGetClassObject)(IN REFCLSID rclsid, IN REFIID riid, OUT LPVOID FAR* ppv);
Expand Down Expand Up @@ -1157,6 +1214,9 @@ bool HookKernel32IAT(HMODULE mod, bool exe)

auto PatchCoCreateInstance = [&](size_t start, size_t end, size_t exe_end)
{
if (iequals(GetSelfName(), L"dinput8.dll") || iequals(GetSelfName(), L"dinput.dll") || iequals(GetSelfName(), L"wininet.dll"))
return;

for (size_t i = 0; i < nNumImports; i++)
{
if (hExecutableInstance + (pImports + i)->FirstThunk > start && !(end && hExecutableInstance + (pImports + i)->FirstThunk > end))
Expand All @@ -1170,6 +1230,9 @@ bool HookKernel32IAT(HMODULE mod, bool exe)
end = exe_end;
}

if (exe)
OLE32Data[eCoCreateInstance][ProcAddress] = (size_t)GetProcAddress(GetModuleHandle(TEXT("OLE32.DLL")), "CoCreateInstance");

for (auto i = start; i < end; i += sizeof(size_t))
{
DWORD dwProtect[2];
Expand All @@ -1179,8 +1242,9 @@ bool HookKernel32IAT(HMODULE mod, bool exe)
if (!ptr)
continue;

if (ptr == (size_t)GetProcAddress(GetModuleHandle(TEXT("OLE32.DLL")), "CoCreateInstance"))
if (ptr == OLE32Data[eCoCreateInstance][ProcAddress])
{
if (exe) OLE32Data[eCoCreateInstance][IATPtr] = i;
*(size_t*)i = (size_t)CustomCoCreateInstance;
VirtualProtect((size_t*)i, sizeof(size_t), dwProtect[0], &dwProtect[1]);
break;
Expand Down Expand Up @@ -1866,5 +1930,19 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID /*lpReserved*/)
hm = hModule;
Init();
}
else if (reason == DLL_PROCESS_DETACH)
{
for (size_t i = 0; i < OLE32ExportsNamesCount; i++)
{
if (OLE32Data[i][IATPtr] && OLE32Data[i][ProcAddress])
{
auto ptr = (size_t*)OLE32Data[i][IATPtr];
DWORD dwProtect[2];
VirtualProtect(ptr, sizeof(size_t), PAGE_EXECUTE_READWRITE, &dwProtect[0]);
*ptr = OLE32Data[i][ProcAddress];
VirtualProtect(ptr, sizeof(size_t), dwProtect[0], &dwProtect[1]);
}
}
}
return TRUE;
}
Binary file modified source/resources/Versioninfo.rc
Binary file not shown.

0 comments on commit a9415e5

Please sign in to comment.