fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define WINAPI
  5. using LPCSTR = const char*;
  6. using BOOL = int;
  7. using DWORD = unsigned int;
  8. using LPVOID = void*;
  9. constexpr BOOL TRUE = 1;
  10. constexpr BOOL FALSE = 0;
  11.  
  12. BOOL WINAPI GetFileVersionInfo_dummy(LPCSTR, DWORD, DWORD, LPVOID) { return TRUE; }
  13.  
  14. void* WINAPI LoadLibraryA(LPCSTR) { return reinterpret_cast<void*>(1); }
  15. void* WINAPI GetProcAddress(void*, LPCSTR) { return (void*) &GetFileVersionInfo_dummy; }
  16.  
  17. template <typename RetType, typename... ArgTypes>
  18. struct proxyTraits
  19. {
  20. using funcType = RetType (WINAPI *)(ArgTypes...);
  21. using proxyType = RetType (*)(ArgTypes...);
  22. };
  23.  
  24. template <typename RetType, typename... ArgTypes>
  25. auto proxyFunction(
  26. LPCSTR dllPath,
  27. LPCSTR functionName,
  28. RetType (*proxy)(ArgTypes...))
  29. {
  30. using funcType = typename proxyTraits<RetType, ArgTypes...>::funcType;
  31. funcType funcPtr = (funcType) GetProcAddress(LoadLibraryA(dllPath), functionName);
  32.  
  33. if (funcPtr)
  34. std::cout << "Proxy success" << std::endl;
  35. else
  36. std::cout << "Proxy fail" << std::endl;
  37.  
  38. return funcPtr;
  39. }
  40.  
  41. BOOL GetFileVersionInfoProxy(LPCSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData)
  42. {
  43. auto getFileVersion = proxyFunction("C:\\Windows\\System32\\Version.dll", "GetFileVersionInfoA", &GetFileVersionInfoProxy);
  44. if (getFileVersion)
  45. return getFileVersion(lptstrFilename, dwHandle, dwLen, lpData);
  46.  
  47. return FALSE;
  48. }
  49.  
  50. int main()
  51. {
  52. GetFileVersionInfoProxy("filename", 0, 0, nullptr);
  53. return 0;
  54. }
Success #stdin #stdout 0s 4408KB
stdin
Standard input is empty
stdout
Proxy success