Skip to content

Commit

Permalink
implement ThemeInvalidSigner with signature.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
namazso committed Mar 29, 2020
1 parent 9ff1b39 commit 4ced256
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 196 deletions.
183 changes: 0 additions & 183 deletions ThemeInvalidSigner/ThemeInvalidSigner.c

This file was deleted.

2 changes: 1 addition & 1 deletion ThemeInvalidSigner/ThemeInvalidSigner.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ThemeInvalidSigner.c" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
2 changes: 1 addition & 1 deletion ThemeInvalidSigner/ThemeInvalidSigner.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ThemeInvalidSigner.c">
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
46 changes: 46 additions & 0 deletions ThemeInvalidSigner/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SecureUxTheme - A secure boot compatible in-memory UxTheme patcher
// Copyright (C) 2019 namazso
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#include "../ThemeTool/signature.cpp"

int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
{
DWORD error;
WCHAR buf[1024];

if (argc < 2)
{
wprintf(L"Usage: ThemeInvalidSigner <filename>\n");
error = ERROR_INVALID_PARAMETER;
}
else
{
error = sig::fix_file(argv[1], false);
}

FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buf,
_ARRAYSIZE(buf),
nullptr
);

wprintf(L"Result: %s", buf);
return error;
}
2 changes: 1 addition & 1 deletion ThemeTool/MainDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void MainDialog::ApplyTheme(int id)
Static_SetText(_hwnd_STATIC_STYLE, style);

if (wcslen(style) > 1 && sig::check_file(style) == E_FAIL)
sig::fix_file(style);
sig::fix_file(style, !g_is_elevated);

SysFreeString(style);

Expand Down
2 changes: 1 addition & 1 deletion ThemeTool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static int main_silent(size_t file_count, wchar_t** files, bool verysilent)
for(auto i = 0u; i < file_count; ++i)
{
const auto file = files[i];
const auto error = sig::fix_file(file);
const auto error = sig::fix_file(file, !g_is_elevated);
if (hr == NOERROR && FAILED(error))
hr = error;
WCHAR buf[1024];
Expand Down
6 changes: 2 additions & 4 deletions ThemeTool/signature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "signature.h"

#include "main.h"

typedef struct _THEME_SIGNATURE_HEADER
{
ULONG Magic;
Expand Down Expand Up @@ -159,7 +157,7 @@ HRESULT sig::check_file(LPCWSTR path)
}


HRESULT sig::fix_file(LPCWSTR path)
HRESULT sig::fix_file(LPCWSTR path, bool allow_relaunch)
{
if (SUCCEEDED(check_file(path)))
return NOERROR;
Expand All @@ -170,7 +168,7 @@ HRESULT sig::fix_file(LPCWSTR path)
if (GetLastError() == ERROR_ACCESS_DENIED)
{
// seems like we just don't have access even when elevated. this is an user error
if (g_is_elevated)
if (!allow_relaunch)
return HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED);

const auto wstr = std::wstring(L"/S \"") + path + L"\"";
Expand Down
2 changes: 1 addition & 1 deletion ThemeTool/signature.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
namespace sig
{
HRESULT check_file(LPCWSTR path);
HRESULT fix_file(LPCWSTR path);
HRESULT fix_file(LPCWSTR path, bool allow_relaunch);
}
19 changes: 15 additions & 4 deletions installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,28 @@ Function MakeInstallPage
${NSD_CreateGroupBox} 0 0 50% 48u ""
Pop $1

${NSD_CreateButton} 52% 4u 48% 20u "Fix signature of style"
${NSD_CreateButton} 52% 4u 23% 19u "Fix signature"
Pop $1
GetFunctionAddress $0 OnFixSignature
nsDialogs::OnClick $1 $0

${NSD_CreateButton} 52% 28u 48% 20u "Hooked Personalization"
${NSD_CreateButton} 77% 4u 23% 19u "Personalization"
Pop $1
GetFunctionAddress $0 OnHookedPersonalization
nsDialogs::OnClick $1 $0

${NSD_CreateButton} 52% 27u 48% 18u "Start ThemeTool"
Pop $1
GetFunctionAddress $0 OnThemeTool
nsDialogs::OnClick $1 $0

${NSD_CreateLabel} 0 52u 100% 100u "\
- ThemeTool provides an interface for patching and applying installed themes$\n\
- Hooking SystemSettings enables custom themes in Themes (Settings app)$\n\
${U+00A0}${U+00A0}- However that is only available in Windows 10 1703+$\n\
- You can start a single hooked Personalization with $\"Hooked Personalization$\"$\n\
- You can start a single hooked Personalization with $\"Personalization$\"$\n\
- Styles need to be signed, the signature just doesn't need to be valid$\n\
${U+00A0}${U+00A0}- To add an invalid signature to a style click $\"Fix signature of style$\"$\n\
${U+00A0}${U+00A0}- To add an invalid signature to a style click $\"Fix signature$\"$\n\
${U+00A0}${U+00A0}- Alternatively, you can simply drag && drop files onto this window.$\n"
Pop $1

Expand Down Expand Up @@ -133,6 +139,11 @@ Function OnFileDrop
StrCpy $0 "" ; ask for next file
FunctionEnd

Function OnThemeTool
File /oname=$TEMP\ThemeTool.exe bin\Release\Win32\ThemeTool.exe
Exec '"$TEMP\ThemeTool.exe"'
FunctionEnd

Function OnFixSignature
nsDialogs::SelectFileDialog open "" "Style|*.msstyles"
Pop $0
Expand Down

0 comments on commit 4ced256

Please sign in to comment.