consolidate
This commit is contained in:
parent
78781791c3
commit
a6131ef9ce
|
@ -43,7 +43,7 @@
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_DEBUG;VERSIONSHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;VERSIONSHIM_EXPORTS;_WINDOWS;_USRDLL;PROJECT_NAME="$(ProjectName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>NDEBUG;VERSIONSHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;VERSIONSHIM_EXPORTS;_WINDOWS;_USRDLL;PROJECT_NAME="$(ProjectName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
|
|
@ -32,35 +32,26 @@ BOOL APIENTRY DllMain(const HMODULE hModule, const DWORD fdwReason, LPCVOID lpRe
|
||||||
if (fdwReason != DLL_PROCESS_ATTACH)
|
if (fdwReason != DLL_PROCESS_ATTACH)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
HANDLE hFile = NULL;
|
LPCH fileStr = NULL;
|
||||||
if (!OpenRead("Libraries.txt", &hFile))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
LPCH fileBuf = NULL;
|
|
||||||
DWORD fileLen = 0;
|
DWORD fileLen = 0;
|
||||||
BOOL success = ReadUtf8File(hFile, &fileBuf, &fileLen);
|
|
||||||
CloseHandle(hFile);
|
|
||||||
if (!success)
|
|
||||||
return Error(L"Failed to read Libraries.txt");
|
|
||||||
if (fileLen > INT_MAX)
|
|
||||||
return Error(L"Libraries.txt was too large to read");
|
|
||||||
|
|
||||||
LPWSTR fileStr = NULL;
|
if (!OpenReadFileUtf8("Libraries.txt", &fileStr, &fileLen))
|
||||||
success = Utf8ToUtf16(fileBuf, &fileStr, (int)fileLen);
|
|
||||||
free(fileBuf);
|
|
||||||
if (!success)
|
|
||||||
return Error(L"Failed to read Libraries.txt as UTF-16");
|
|
||||||
|
|
||||||
LPWSTR end = fileStr + fileLen;
|
|
||||||
for (LPWSTR dllPath = fileStr; dllPath < end;)
|
|
||||||
{
|
{
|
||||||
int numCharInVal = NextLine(dllPath);
|
MessageBoxA(NULL, "Failed to read Libraries.txt", PROJECT_NAME, ErrBoxType);
|
||||||
|
return TRUE;
|
||||||
LoadLibrary(dllPath);
|
}
|
||||||
|
|
||||||
dllPath += numCharInVal + 2;
|
int charsInLine;
|
||||||
}
|
for (LPCH line = fileStr, fileEnd = fileStr + fileLen; line < fileEnd; line += charsInLine + 2)
|
||||||
|
{
|
||||||
free(fileStr);
|
charsInLine = TerminateLineCrlf(line);
|
||||||
|
|
||||||
|
if (!LoadLibraryA(line))
|
||||||
|
{
|
||||||
|
MessageBoxA(NULL, line, PROJECT_NAME" - Failed to load library", ErrBoxType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, fileStr);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
|
@ -4,11 +4,7 @@
|
||||||
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
|
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
|
||||||
// Do not add files here that you will be updating frequently as this negates the performance advantage.
|
// Do not add files here that you will be updating frequently as this negates the performance advantage.
|
||||||
|
|
||||||
#ifndef PCH_H
|
#pragma once
|
||||||
#define PCH_H
|
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#endif //PCH_H
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright © 2023 Xpl0itR
|
// Copyright © 2023 Xpl0itR
|
||||||
//
|
//
|
||||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
@ -6,71 +6,60 @@
|
||||||
|
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
|
||||||
BOOL Error(const LPWSTR message)
|
BOOL OpenFileRead(const LPCSTR lpFileName, HANDLE* fileHandle)
|
||||||
{
|
|
||||||
MessageBox(NULL, message, L"VersionShim", MB_ICONHAND | MB_OK);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL OpenRead(LPCSTR lpFileName, HANDLE* fileHandle)
|
|
||||||
{
|
{
|
||||||
OFSTRUCT ofStruct = { 0 };
|
OFSTRUCT ofStruct = { 0 };
|
||||||
HFILE hFile = OpenFile(lpFileName, &ofStruct, OF_READ | OF_PROMPT);
|
HFILE hFile = OpenFile(lpFileName, &ofStruct, OF_READ | OF_PROMPT);
|
||||||
|
|
||||||
*fileHandle = (HANDLE)hFile;
|
*fileHandle = (HANDLE)(INT_PTR)hFile;
|
||||||
return hFile != HFILE_ERROR;
|
return hFile != HFILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ReadUtf8File(const HANDLE fileHandle, LPCH* fileBuffer, DWORD* fileLength)
|
BOOL ReadFileUtf8(const HANDLE fileHandle, LPCH* fileString, DWORD* fileLength)
|
||||||
{
|
{
|
||||||
const DWORD fileLen = GetFileSize(fileHandle, NULL);
|
DWORD fileLen = GetFileSize(fileHandle, NULL);
|
||||||
*fileLength = fileLen;
|
*fileLength = fileLen;
|
||||||
|
|
||||||
LPCH buffer = malloc(fileLen + 1);
|
HANDLE heap = GetProcessHeap();
|
||||||
|
LPCH buffer = HeapAlloc(heap, 0, fileLen + 1);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!ReadFile(fileHandle, buffer, fileLen, NULL, NULL))
|
if (!ReadFile(fileHandle, buffer, fileLen, NULL, NULL))
|
||||||
{
|
{
|
||||||
free(buffer);
|
HeapFree(heap, 0, buffer);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[fileLen] = '\0';
|
buffer[fileLen] = '\0';
|
||||||
*fileBuffer = buffer;
|
*fileString = buffer;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL Utf8ToUtf16(LPCCH utf8String, const PZPWSTR utf16String, const int length)
|
BOOL OpenReadFileUtf8(const LPCSTR lpFileName, LPCH* fileString, DWORD* fileLength)
|
||||||
{
|
{
|
||||||
LPWSTR string = malloc(length * 2 + 2);
|
HANDLE hFile = NULL;
|
||||||
if (!string)
|
if (!OpenFileRead(lpFileName, &hFile))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!MultiByteToWideChar(CP_UTF8, 0, utf8String, length, string, length))
|
BOOL success = ReadFileUtf8(hFile, fileString, fileLength);
|
||||||
{
|
CloseHandle(hFile);
|
||||||
free(string);
|
|
||||||
return FALSE;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[length] = L'\0';
|
INT TerminateLineCrlf(const LPCH fileString)
|
||||||
*utf16String = string;
|
{
|
||||||
|
for (INT i = 0; ; i++)
|
||||||
return TRUE;
|
{
|
||||||
|
if (fileString[i] == '\r' &&
|
||||||
|
fileString[i + 1] == '\n')
|
||||||
|
{
|
||||||
|
fileString[i] = fileString[i + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
int NextLine(const LPWSTR text)
|
if (fileString[i] == '\0')
|
||||||
{
|
|
||||||
for (int i = 0; ; i++)
|
|
||||||
{
|
|
||||||
if (text[i] == L'\r' &&
|
|
||||||
text[i + 1] == L'\n')
|
|
||||||
{
|
|
||||||
text[i] = text[i + 1] = L'\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (text[i] == L'\0')
|
|
||||||
{
|
{
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "pch.h"
|
|
||||||
|
|
||||||
BOOL Error(LPWSTR message);
|
UINT ErrBoxType = MB_ICONERROR | MB_TOPMOST;
|
||||||
BOOL OpenRead(LPCSTR lpFileName, HANDLE* fileHandle);
|
|
||||||
BOOL ReadUtf8File(HANDLE fileHandle, LPCH* fileBuffer, DWORD* fileLength);
|
BOOL OpenReadFileUtf8(LPCSTR lpFileName, LPCH* fileBuffer, DWORD* fileLength);
|
||||||
BOOL Utf8ToUtf16(LPCCH utf8String, PZPWSTR utf16String, int length);
|
INT TerminateLineCrlf(LPCH fileString);
|
||||||
int NextLine(LPWSTR text);
|
|
Loading…
Reference in New Issue