consolidate
This commit is contained in:
parent
78781791c3
commit
a6131ef9ce
|
@ -43,7 +43,7 @@
|
|||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<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>
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
|
@ -59,7 +59,7 @@
|
|||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<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>
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
|
|
|
@ -32,35 +32,26 @@ BOOL APIENTRY DllMain(const HMODULE hModule, const DWORD fdwReason, LPCVOID lpRe
|
|||
if (fdwReason != DLL_PROCESS_ATTACH)
|
||||
return TRUE;
|
||||
|
||||
HANDLE hFile = NULL;
|
||||
if (!OpenRead("Libraries.txt", &hFile))
|
||||
return FALSE;
|
||||
|
||||
LPCH fileBuf = NULL;
|
||||
LPCH fileStr = NULL;
|
||||
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;
|
||||
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;)
|
||||
if (!OpenReadFileUtf8("Libraries.txt", &fileStr, &fileLen))
|
||||
{
|
||||
int numCharInVal = NextLine(dllPath);
|
||||
|
||||
LoadLibrary(dllPath);
|
||||
|
||||
dllPath += numCharInVal + 2;
|
||||
MessageBoxA(NULL, "Failed to read Libraries.txt", PROJECT_NAME, ErrBoxType);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
free(fileStr);
|
||||
int charsInLine;
|
||||
for (LPCH line = fileStr, fileEnd = fileStr + fileLen; line < fileEnd; line += charsInLine + 2)
|
||||
{
|
||||
charsInLine = TerminateLineCrlf(line);
|
||||
|
||||
if (!LoadLibraryA(line))
|
||||
{
|
||||
MessageBoxA(NULL, line, PROJECT_NAME" - Failed to load library", ErrBoxType);
|
||||
}
|
||||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, fileStr);
|
||||
return TRUE;
|
||||
}
|
|
@ -4,11 +4,7 @@
|
|||
// 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.
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#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
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
|
@ -6,71 +6,60 @@
|
|||
|
||||
#include "pch.h"
|
||||
|
||||
BOOL Error(const LPWSTR message)
|
||||
{
|
||||
MessageBox(NULL, message, L"VersionShim", MB_ICONHAND | MB_OK);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL OpenRead(LPCSTR lpFileName, HANDLE* fileHandle)
|
||||
BOOL OpenFileRead(const LPCSTR lpFileName, HANDLE* fileHandle)
|
||||
{
|
||||
OFSTRUCT ofStruct = { 0 };
|
||||
HFILE hFile = OpenFile(lpFileName, &ofStruct, OF_READ | OF_PROMPT);
|
||||
|
||||
*fileHandle = (HANDLE)hFile;
|
||||
*fileHandle = (HANDLE)(INT_PTR)hFile;
|
||||
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;
|
||||
|
||||
LPCH buffer = malloc(fileLen + 1);
|
||||
HANDLE heap = GetProcessHeap();
|
||||
LPCH buffer = HeapAlloc(heap, 0, fileLen + 1);
|
||||
if (!buffer)
|
||||
return FALSE;
|
||||
|
||||
if (!ReadFile(fileHandle, buffer, fileLen, NULL, NULL))
|
||||
{
|
||||
free(buffer);
|
||||
HeapFree(heap, 0, buffer);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
buffer[fileLen] = '\0';
|
||||
*fileBuffer = buffer;
|
||||
*fileString = buffer;
|
||||
|
||||
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);
|
||||
if (!string)
|
||||
HANDLE hFile = NULL;
|
||||
if (!OpenFileRead(lpFileName, &hFile))
|
||||
return FALSE;
|
||||
|
||||
if (!MultiByteToWideChar(CP_UTF8, 0, utf8String, length, string, length))
|
||||
{
|
||||
free(string);
|
||||
return FALSE;
|
||||
}
|
||||
BOOL success = ReadFileUtf8(hFile, fileString, fileLength);
|
||||
CloseHandle(hFile);
|
||||
|
||||
string[length] = L'\0';
|
||||
*utf16String = string;
|
||||
|
||||
return TRUE;
|
||||
return success;
|
||||
}
|
||||
|
||||
int NextLine(const LPWSTR text)
|
||||
INT TerminateLineCrlf(const LPCH fileString)
|
||||
{
|
||||
for (int i = 0; ; i++)
|
||||
for (INT i = 0; ; i++)
|
||||
{
|
||||
if (text[i] == L'\r' &&
|
||||
text[i + 1] == L'\n')
|
||||
if (fileString[i] == '\r' &&
|
||||
fileString[i + 1] == '\n')
|
||||
{
|
||||
text[i] = text[i + 1] = L'\0';
|
||||
fileString[i] = fileString[i + 1] = '\0';
|
||||
}
|
||||
|
||||
if (text[i] == L'\0')
|
||||
if (fileString[i] == '\0')
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#pragma once
|
||||
#include "pch.h"
|
||||
|
||||
BOOL Error(LPWSTR message);
|
||||
BOOL OpenRead(LPCSTR lpFileName, HANDLE* fileHandle);
|
||||
BOOL ReadUtf8File(HANDLE fileHandle, LPCH* fileBuffer, DWORD* fileLength);
|
||||
BOOL Utf8ToUtf16(LPCCH utf8String, PZPWSTR utf16String, int length);
|
||||
int NextLine(LPWSTR text);
|
||||
UINT ErrBoxType = MB_ICONERROR | MB_TOPMOST;
|
||||
|
||||
BOOL OpenReadFileUtf8(LPCSTR lpFileName, LPCH* fileBuffer, DWORD* fileLength);
|
||||
INT TerminateLineCrlf(LPCH fileString);
|
Loading…
Reference in New Issue