Skip to content

Commit 60079c7

Browse files
committed
Initial commit
0 parents  commit 60079c7

File tree

5 files changed

+245
-0
lines changed

5 files changed

+245
-0
lines changed

.clang-format

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Generated from CLion C/C++ Code Style settings
2+
BasedOnStyle: LLVM
3+
AccessModifierOffset: -2
4+
AlignAfterOpenBracket: BlockIndent
5+
AlignArrayOfStructures: Right
6+
AlignConsecutiveAssignments: None
7+
AlignConsecutiveBitFields: AcrossEmptyLinesAndComments
8+
AlignConsecutiveMacros: Consecutive
9+
AlignEscapedNewlines: Left
10+
AlignOperands: Align
11+
AlignTrailingComments: true
12+
AllowAllArgumentsOnNextLine: false
13+
AllowAllConstructorInitializersOnNextLine: false
14+
AllowAllParametersOfDeclarationOnNextLine: false
15+
AllowShortBlocksOnASingleLine: Always
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortFunctionsOnASingleLine: Inline
18+
AllowShortIfStatementsOnASingleLine: Never
19+
AllowShortLambdasOnASingleLine: All
20+
AllowShortLoopsOnASingleLine: false
21+
AlwaysBreakAfterReturnType: None
22+
AlwaysBreakBeforeMultilineStrings: true
23+
AlwaysBreakTemplateDeclarations: MultiLine
24+
BinPackArguments: false
25+
BinPackParameters: false
26+
BitFieldColonSpacing: Before
27+
BreakBeforeBraces: Custom
28+
BraceWrapping:
29+
AfterCaseLabel: false
30+
AfterClass: false
31+
AfterControlStatement: Never
32+
AfterEnum: false
33+
AfterFunction: false
34+
AfterNamespace: false
35+
AfterStruct: false
36+
AfterUnion: false
37+
AfterExternBlock: false
38+
BeforeCatch: false
39+
BeforeElse: false
40+
BeforeLambdaBody: false
41+
BeforeWhile: false
42+
IndentBraces: false
43+
SplitEmptyFunction: false
44+
SplitEmptyRecord: false
45+
SplitEmptyNamespace: false
46+
BreakBeforeBinaryOperators: NonAssignment
47+
BreakBeforeConceptDeclarations: Allowed
48+
BreakBeforeTernaryOperators: true
49+
BreakConstructorInitializers: BeforeComma
50+
BreakInheritanceList: BeforeComma
51+
BreakStringLiterals: false
52+
ColumnLimit: 0
53+
CompactNamespaces: false
54+
ContinuationIndentWidth: 2
55+
EmptyLineAfterAccessModifier: Never
56+
EmptyLineBeforeAccessModifier: Always
57+
FixNamespaceComments: true
58+
IncludeBlocks: Preserve
59+
IndentAccessModifiers: false
60+
IndentCaseLabels: false
61+
IndentExternBlock: NoIndent
62+
IndentGotoLabels: false
63+
IndentPPDirectives: None
64+
IndentWidth: 2
65+
IndentWrappedFunctionNames: false
66+
InsertTrailingCommas: Wrapped
67+
KeepEmptyLinesAtTheStartOfBlocks: false
68+
LambdaBodyIndentation: Signature
69+
MaxEmptyLinesToKeep: 2
70+
NamespaceIndentation: All
71+
PackConstructorInitializers: CurrentLine
72+
PointerAlignment: Left
73+
QualifierAlignment: Custom
74+
QualifierOrder: [ 'inline', 'static', 'constexpr', 'const', 'volatile', 'type', 'restrict' ]
75+
ReferenceAlignment: Left
76+
ReflowComments: false
77+
RequiresClausePosition: OwnLine
78+
SeparateDefinitionBlocks: Always
79+
ShortNamespaceLines: 10
80+
SortIncludes: CaseInsensitive
81+
SortUsingDeclarations: true
82+
SpaceAfterCStyleCast: false
83+
SpaceAfterLogicalNot: false
84+
SpaceAfterTemplateKeyword: true
85+
SpaceBeforeAssignmentOperators: true
86+
SpaceBeforeCpp11BracedList: false
87+
SpaceBeforeCtorInitializerColon: true
88+
SpaceBeforeInheritanceColon: true
89+
SpaceBeforeParens: ControlStatements
90+
SpaceBeforeRangeBasedForLoopColon: true
91+
SpaceBeforeSquareBrackets: false
92+
SpaceInEmptyBlock: false
93+
SpaceInEmptyParentheses: false
94+
SpacesBeforeTrailingComments: 1
95+
SpacesInAngles: false
96+
SpacesInCStyleCastParentheses: false
97+
SpacesInConditionalStatement: false
98+
SpacesInContainerLiterals: false
99+
SpacesInLineCommentPrefix:
100+
Minimum: 1
101+
Maximum: -1
102+
SpacesInParentheses: false
103+
SpacesInSquareBrackets: false
104+
Standard: c++20
105+
TabWidth: 2
106+
UseTab: Never

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
3+
project(MagicSigner)
4+
5+
add_library(${PROJECT_NAME} SHARED library.cpp)
6+
7+
target_link_libraries(${PROJECT_NAME} PRIVATE crypt32)
8+
9+
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "XmlLite")
10+
11+
target_link_options(${PROJECT_NAME} PRIVATE
12+
/ENTRY:DllEntry
13+
/NOCOFFGRPINFO
14+
/Brepro
15+
/PDBALTPATH:%_PDB%
16+
)

LICENSE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
BSD Zero Clause License
2+
3+
Copyright (c) 2023 namazso <[email protected]>
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14+
PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MagicSigner
2+
3+
Patcher dll for signtool that allows signing with expired certificates
4+
5+
## Usage
6+
7+
Just place next to signtool.exe
8+
9+
## License
10+
11+
BSD Zero Clause License
12+
13+
Copyright (c) 2023 namazso <[email protected]>
14+
15+
Permission to use, copy, modify, and/or distribute this software for any
16+
purpose with or without fee is hereby granted.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24+
PERFORMANCE OF THIS SOFTWARE.

library.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) 2023 namazso <[email protected]>
2+
//
3+
// Permission to use, copy, modify, and/or distribute this software for any
4+
// purpose with or without fee is hereby granted.
5+
//
6+
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
7+
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
8+
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
9+
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
10+
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
11+
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
12+
// PERFORMANCE OF THIS SOFTWARE.
13+
14+
#include <Windows.h>
15+
16+
#include <strsafe.h>
17+
18+
#include <cstdint>
19+
20+
using fnCreateXmlWriter = HRESULT(WINAPI*)(REFIID, void**, IMalloc*);
21+
22+
EXTERN_C __declspec(dllexport) HRESULT STDAPICALLTYPE CreateXmlWriter(REFIID riid, void** ppvObject, IMalloc* pMalloc) {
23+
static fnCreateXmlWriter p{};
24+
if (!p) {
25+
const auto lib = LoadLibraryExA("XmlLite.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
26+
p = (fnCreateXmlWriter)GetProcAddress(lib, "CreateXmlWriter");
27+
}
28+
return p(riid, ppvObject, pMalloc);
29+
}
30+
31+
void* follow_jumps(void* p) {
32+
auto pb = (uint8_t*)p;
33+
while (true) {
34+
if (pb[0] == 0xEB) {
35+
pb += 2 + (intptr_t) * ((int8_t*)&pb[1]);
36+
continue;
37+
}
38+
if (pb[0] == 0xE9) {
39+
pb += 5 + (intptr_t) * ((int32_t*)&pb[1]);
40+
continue;
41+
}
42+
if (pb[0] == 0xFF && pb[1] == 0x25) {
43+
pb = *(uint8_t**)(pb + 6 + (intptr_t) * ((int32_t*)&pb[2]));
44+
continue;
45+
}
46+
if (pb[0] == 0x48 && pb[1] == 0xFF && pb[2] == 0x25) {
47+
pb = *(uint8_t**)(pb + 7 + (intptr_t) * ((int32_t*)&pb[3]));
48+
continue;
49+
}
50+
break;
51+
}
52+
return pb;
53+
}
54+
55+
LONG WINAPI hooked_CertVerifyTimeValidity(LPFILETIME pTimeToVerify, PCERT_INFO pCertInfo) {
56+
return 0;
57+
}
58+
59+
VOID WINAPI hooked_GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime) {
60+
*lpSystemTimeAsFileTime = {};
61+
}
62+
63+
static BOOL hook(void* fn, void* hook_fn) {
64+
const auto patch = follow_jumps(fn);
65+
66+
struct hkstruct {
67+
uint8_t arr[8] = {0xff, 0x25, 2, 0, 0, 0, 0x90, 0x90};
68+
void* p{};
69+
} s;
70+
71+
s.p = hook_fn;
72+
SIZE_T w{};
73+
return WriteProcessMemory((HANDLE)-1, patch, &s, sizeof(s), &w);
74+
}
75+
76+
static void initialize() {
77+
hook((void*)&CertVerifyTimeValidity, (void*)hooked_CertVerifyTimeValidity);
78+
hook((void*)&GetSystemTimeAsFileTime, (void*)hooked_GetSystemTimeAsFileTime);
79+
}
80+
81+
extern "C" BOOL WINAPI DllEntry(HINSTANCE, DWORD reason, LPVOID) {
82+
if (reason == DLL_PROCESS_ATTACH)
83+
initialize();
84+
return TRUE;
85+
}

0 commit comments

Comments
 (0)