#include <iostream>
using namespace std;
#define WINAPI
using LPCSTR = const char*;
using BOOL = int;
using DWORD = unsigned int;
using LPVOID = void*;
constexpr BOOL TRUE = 1;
constexpr BOOL FALSE = 0;
BOOL WINAPI GetFileVersionInfo_dummy(LPCSTR, DWORD, DWORD, LPVOID) { return TRUE; }
void* WINAPI LoadLibraryA(LPCSTR) { return reinterpret_cast<void*>(1); }
void* WINAPI GetProcAddress(void*, LPCSTR) { return (void*) &GetFileVersionInfo_dummy; }
template <typename RetType, typename... ArgTypes>
struct proxyTraits
{
using funcType = RetType (WINAPI *)(ArgTypes...);
using proxyType = RetType (*)(ArgTypes...);
};
template <typename RetType, typename... ArgTypes>
auto proxyFunction(
LPCSTR dllPath,
LPCSTR functionName,
RetType (*proxy)(ArgTypes...))
{
using funcType = typename proxyTraits<RetType, ArgTypes...>::funcType;
funcType funcPtr = (funcType) GetProcAddress(LoadLibraryA(dllPath), functionName);
if (funcPtr)
std::cout << "Proxy success" << std::endl;
else
std::cout << "Proxy fail" << std::endl;
return funcPtr;
}
BOOL GetFileVersionInfoProxy(LPCSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData)
{
auto getFileVersion = proxyFunction("C:\\Windows\\System32\\Version.dll", "GetFileVersionInfoA", &GetFileVersionInfoProxy);
if (getFileVersion)
return getFileVersion(lptstrFilename, dwHandle, dwLen, lpData);
return FALSE;
}
int main()
{
GetFileVersionInfoProxy("filename", 0, 0, nullptr);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBXSU5BUEkKdXNpbmcgTFBDU1RSID0gY29uc3QgY2hhcio7CnVzaW5nIEJPT0wgPSBpbnQ7CnVzaW5nIERXT1JEID0gdW5zaWduZWQgaW50Owp1c2luZyBMUFZPSUQgPSB2b2lkKjsKY29uc3RleHByIEJPT0wgVFJVRSA9IDE7CmNvbnN0ZXhwciBCT09MIEZBTFNFID0gMDsKCkJPT0wgV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