Skip to content

Commit

Permalink
Remove un-needed mutex.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetopia committed Jan 26, 2025
1 parent c172ff7 commit 8a9bc40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
11 changes: 2 additions & 9 deletions src/DllMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ HRESULT(*__put_PointerCursor__)
(__x_ABI_CWindows_CUI_CCore_CICoreWindow *, __x_ABI_CWindows_CUI_CCore_CICoreCursor *) = {};

HRESULT(*__CreateSwapChainForCoreWindow__)
(IDXGIFactory2 *, IUnknown *, __x_ABI_CWindows_CUI_CCore_CICoreWindow *, DXGI_SWAP_CHAIN_DESC1 *, IDXGIOutput *,
(IDXGIFactory2 *, LPUNKNOWN, __x_ABI_CWindows_CUI_CCore_CICoreWindow *, DXGI_SWAP_CHAIN_DESC1 *, IDXGIOutput *,
IDXGISwapChain1 **) = {};

HWND (*__CreateWindowExW__)(DWORD, LPCWSTR, LPCWSTR, DWORD, INT, INT, INT, INT, HWND, HMENU, HINSTANCE, LPVOID) = {};
Expand Down Expand Up @@ -54,7 +54,7 @@ HRESULT _put_PointerCursor_(__x_ABI_CWindows_CUI_CCore_CICoreWindow *This,
return __put_PointerCursor__(This, value);
}

HRESULT _CreateSwapChainForCoreWindow_(IDXGIFactory2 *This, IUnknown *pDevice,
HRESULT _CreateSwapChainForCoreWindow_(IDXGIFactory2 *This, LPUNKNOWN pDevice,
__x_ABI_CWindows_CUI_CCore_CICoreWindow *pWindow, DXGI_SWAP_CHAIN_DESC1 *pDesc,
IDXGIOutput *pRestrictToOutput, IDXGISwapChain1 **ppSwapChain)
{
Expand Down Expand Up @@ -125,13 +125,6 @@ BOOL DllMainCRTStartup(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
CSTR_EQUAL)
return FALSE;

HANDLE hMutex = CreateMutexW(NULL, FALSE, L"Stonecutter");
if (!hMutex || GetLastError())
{
CloseHandle(hMutex);
return FALSE;
}

WCHAR szFileName[MAX_PATH] = {};
ExpandEnvironmentStringsW(L"%LOCALAPPDATA%\\..\\RoamingState\\Stonecutter.ini", szFileName, MAX_PATH);
fForce = GetPrivateProfileIntW(L"", L"", FALSE, szFileName) == TRUE;
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/DllMain.rc
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1, 5, 3, 1
FILEVERSION 1, 5, 3, 2
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "Stonecutter"
VALUE "ProductName", "Stonecutter"
VALUE "ProductVersion", "1.5.3.1"
VALUE "ProductVersion", "1.5.3.2"
VALUE "LegalCopyright", "Copyright (C) 2024 - 25"
END
END
Expand Down
16 changes: 8 additions & 8 deletions src/WinMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ VOID WinMainCRTStartup()
WCHAR szPath[MAX_PATH] = {};
QueryFullProcessImageNameW(GetCurrentProcess(), (DWORD){}, szPath, &((DWORD){MAX_PATH}));

HANDLE hObject = CreateMutexW(NULL, FALSE, L"Stonecutter");
if (!hObject)
HANDLE hMutex = CreateMutexW(NULL, FALSE, L"Stonecutter");
if (!hMutex)
ExitProcess(EXIT_SUCCESS);
else if (GetLastError())
{
PathRemoveFileSpecW(szPath);

PACL pAcl = {};
PathRemoveFileSpecW(szPath);
GetNamedSecurityInfoW(lstrcatW(szPath, L"\\Stonecutter.dll"), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL,
NULL, &pAcl, NULL, NULL);
SetEntriesInAclW(PACKAGE_GRAPH_MIN_SIZE,
Expand All @@ -31,14 +30,15 @@ VOID WinMainCRTStartup()
SetNamedSecurityInfoW(szPath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, pAcl, NULL);

PWSTR *pArgs = CommandLineToArgvW(GetCommandLineW(), &((INT){}));

HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, StrToIntW(pArgs[2]));

LPVOID lpBaseAddress = VirtualAllocEx(hProcess, NULL, sizeof(szPath), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(hProcess, lpBaseAddress, szPath, sizeof(szPath), NULL);

HANDLE hThread = CreateRemoteThread(hProcess, NULL, (SIZE_T){}, (LPTHREAD_START_ROUTINE)LoadLibraryW,
lpBaseAddress, 0, NULL);

WaitForSingleObject(hThread, INFINITE);

VirtualFreeEx(hProcess, lpBaseAddress, (SIZE_T){}, MEM_RELEASE);
CloseHandle(hThread);
CloseHandle(hProcess);
Expand All @@ -47,7 +47,7 @@ VOID WinMainCRTStartup()
ResumeThread(hThread);
CloseHandle(hThread);

CloseHandle(hObject);
CloseHandle(hMutex);
ExitProcess(EXIT_SUCCESS);
}

Expand All @@ -74,6 +74,6 @@ VOID WinMainCRTStartup()
pSettings->lpVtbl->DisableDebugging(pSettings, szPackageFullName);
pSettings->lpVtbl->EnableDebugging(pSettings, szPackageFullName, NULL, NULL);

CloseHandle(hObject);
CloseHandle(hMutex);
ExitProcess(EXIT_SUCCESS);
}

0 comments on commit 8a9bc40

Please sign in to comment.