DllPreloadingAttack.zip/PrintVersion_sono2/main.cpp
#include <cstdio>
#include <vector>
#include <Windows.h>
typedef DWORD (WINAPI *GetFileVersionInfoSizeW_T)(
_In_ LPCWSTR lptstrFilename,
_Out_opt_ LPDWORD lpdwHandle
);
typedef BOOL (WINAPI *GetFileVersionInfoW_T)(
_In_ LPCWSTR lptstrFilename,
_Reserved_ DWORD dwHandle,
_In_ DWORD dwLen,
_Out_writes_bytes_(dwLen) LPVOID lpData
);
typedef BOOL (WINAPI *VerQueryValueW_T)(
_In_ LPCVOID pBlock,
_In_ LPCWSTR lpSubBlock,
_Outptr_result_buffer_(_Inexpressible_("buffer can be PWSTR or DWORD*")) LPVOID * lplpBuffer,
_Out_ PUINT puLen
);
int main() {
wchar_t versionPath[MAX_PATH] = { 0 };
::GetSystemDirectoryW(versionPath, _countof(versionPath));
::wcscat_s(versionPath, L"\\version.dll");
const HMODULE module = ::LoadLibraryW(versionPath);
const GetFileVersionInfoSizeW_T GetFileVersionInfoSizeW = reinterpret_cast<GetFileVersionInfoSizeW_T>(::GetProcAddress(module, "GetFileVersionInfoSizeW"));
const GetFileVersionInfoW_T GetFileVersionInfoW = reinterpret_cast<GetFileVersionInfoW_T>(::GetProcAddress(module, "GetFileVersionInfoW"));
const VerQueryValueW_T VerQueryValueW = reinterpret_cast<VerQueryValueW_T>(::GetProcAddress(module, "VerQueryValueW"));
wchar_t path[MAX_PATH] = { 0 };
::GetModuleFileNameW(nullptr, path, _countof(path));
std::vector<unsigned char> buf;
buf.resize(GetFileVersionInfoSizeW(path, 0));
if (!GetFileVersionInfoW(path, 0, buf.size(), &buf.front())) {
return 1;
}
VS_FIXEDFILEINFO *info;
unsigned int temp;
if (!VerQueryValueW(&buf.front(), L"\\", reinterpret_cast<void **>(&info), &temp)) {
return 1;
}
::printf("%d.%d.%d.%d", HIWORD(info->dwFileVersionMS), LOWORD(info->dwFileVersionMS), HIWORD(info->dwFileVersionLS), LOWORD(info->dwFileVersionLS));
std::getchar();
return 0;
}