Skip to content

Commit 6c61ac6

Browse files
committed
SignTool: update to stdc17
1 parent 1c33a25 commit 6c61ac6

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

tools/CustomSignTool/CustomSignTool.vcxproj

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,32 @@
2222
<ProjectGuid>{E8CD0A41-1537-4EA6-98AC-E80CD59C478E}</ProjectGuid>
2323
<RootNamespace>CustomSignTool</RootNamespace>
2424
<Keyword>Win32Proj</Keyword>
25-
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
25+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2626
</PropertyGroup>
2727
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2828
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2929
<ConfigurationType>Application</ConfigurationType>
3030
<CharacterSet>Unicode</CharacterSet>
3131
<WholeProgramOptimization>true</WholeProgramOptimization>
32-
<PlatformToolset>v141</PlatformToolset>
32+
<PlatformToolset>v142</PlatformToolset>
3333
</PropertyGroup>
3434
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3535
<ConfigurationType>Application</ConfigurationType>
3636
<CharacterSet>Unicode</CharacterSet>
37-
<PlatformToolset>v141</PlatformToolset>
37+
<PlatformToolset>v142</PlatformToolset>
38+
<UseDebugLibraries>true</UseDebugLibraries>
3839
</PropertyGroup>
3940
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4041
<ConfigurationType>Application</ConfigurationType>
4142
<CharacterSet>Unicode</CharacterSet>
4243
<WholeProgramOptimization>true</WholeProgramOptimization>
43-
<PlatformToolset>v141</PlatformToolset>
44+
<PlatformToolset>v142</PlatformToolset>
4445
</PropertyGroup>
4546
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4647
<ConfigurationType>Application</ConfigurationType>
4748
<CharacterSet>Unicode</CharacterSet>
48-
<PlatformToolset>v141</PlatformToolset>
49+
<PlatformToolset>v142</PlatformToolset>
50+
<UseDebugLibraries>true</UseDebugLibraries>
4951
</PropertyGroup>
5052
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
5153
<ImportGroup Label="ExtensionSettings">
@@ -93,6 +95,9 @@
9395
<CallingConvention>StdCall</CallingConvention>
9496
<TreatWarningAsError>true</TreatWarningAsError>
9597
<MultiProcessorCompilation>true</MultiProcessorCompilation>
98+
<LanguageStandard>stdcpplatest</LanguageStandard>
99+
<LanguageStandard_C>stdc17</LanguageStandard_C>
100+
<StringPooling>true</StringPooling>
96101
</ClCompile>
97102
<Link>
98103
<AdditionalDependencies>noenv.obj;phlib.lib;ntdll.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -103,6 +108,7 @@
103108
<SubSystem>Console</SubSystem>
104109
<TargetMachine>MachineX86</TargetMachine>
105110
<MinimumRequiredVersion>5.01</MinimumRequiredVersion>
111+
<AdditionalOptions>/BREPRO /DEPENDENTLOADFLAG:0x800 /PDBALTPATH:%_PDB% %(AdditionalOptions)</AdditionalOptions>
106112
</Link>
107113
</ItemDefinitionGroup>
108114
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -117,6 +123,9 @@
117123
<CallingConvention>StdCall</CallingConvention>
118124
<TreatWarningAsError>true</TreatWarningAsError>
119125
<MultiProcessorCompilation>true</MultiProcessorCompilation>
126+
<LanguageStandard>stdcpplatest</LanguageStandard>
127+
<LanguageStandard_C>stdc17</LanguageStandard_C>
128+
<StringPooling>true</StringPooling>
120129
</ClCompile>
121130
<Link>
122131
<AdditionalDependencies>noenv.obj;phlib.lib;ntdll.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -127,6 +136,7 @@
127136
<SubSystem>Console</SubSystem>
128137
<TargetMachine>MachineX64</TargetMachine>
129138
<MinimumRequiredVersion>5.02</MinimumRequiredVersion>
139+
<AdditionalOptions>/BREPRO /DEPENDENTLOADFLAG:0x800 /PDBALTPATH:%_PDB% %(AdditionalOptions)</AdditionalOptions>
130140
</Link>
131141
</ItemDefinitionGroup>
132142
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -143,6 +153,9 @@
143153
<MultiProcessorCompilation>true</MultiProcessorCompilation>
144154
<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>
145155
<TreatWarningAsError>true</TreatWarningAsError>
156+
<LanguageStandard>stdcpplatest</LanguageStandard>
157+
<LanguageStandard_C>stdc17</LanguageStandard_C>
158+
<StringPooling>true</StringPooling>
146159
</ClCompile>
147160
<Link>
148161
<AdditionalDependencies>noenv.obj;phlib.lib;ntdll.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -156,6 +169,7 @@
156169
<TargetMachine>MachineX86</TargetMachine>
157170
<SetChecksum>true</SetChecksum>
158171
<MinimumRequiredVersion>5.01</MinimumRequiredVersion>
172+
<AdditionalOptions>/BREPRO /DEPENDENTLOADFLAG:0x800 /PDBALTPATH:%_PDB% %(AdditionalOptions)</AdditionalOptions>
159173
</Link>
160174
</ItemDefinitionGroup>
161175
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -171,6 +185,9 @@
171185
<CallingConvention>StdCall</CallingConvention>
172186
<MultiProcessorCompilation>true</MultiProcessorCompilation>
173187
<TreatWarningAsError>true</TreatWarningAsError>
188+
<LanguageStandard>stdcpplatest</LanguageStandard>
189+
<LanguageStandard_C>stdc17</LanguageStandard_C>
190+
<StringPooling>true</StringPooling>
174191
</ClCompile>
175192
<Link>
176193
<AdditionalDependencies>noenv.obj;phlib.lib;ntdll.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -184,6 +201,7 @@
184201
<TargetMachine>MachineX64</TargetMachine>
185202
<SetChecksum>true</SetChecksum>
186203
<MinimumRequiredVersion>5.02</MinimumRequiredVersion>
204+
<AdditionalOptions>/BREPRO /DEPENDENTLOADFLAG:0x800 /PDBALTPATH:%_PDB% %(AdditionalOptions)</AdditionalOptions>
187205
</Link>
188206
</ItemDefinitionGroup>
189207
<ItemGroup>
Binary file not shown.
Binary file not shown.

tools/CustomSignTool/main.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,37 @@ static PVOID CstHashFile(
191191
if (!NT_SUCCESS(status = PhCreateFileWin32(&fileHandle, FileName, FILE_GENERIC_READ, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE)))
192192
CstFailWithStatus(PhFormatString(L"Unable to open '%s'", FileName)->Buffer, status, 0);
193193

194-
buffer = PhAllocatePage(FILE_BUFFER_SIZE, NULL);
195-
196-
while (TRUE)
194+
if (buffer = PhAllocatePage(FILE_BUFFER_SIZE, NULL))
197195
{
198-
if (!NT_SUCCESS(status = NtReadFile(fileHandle, NULL, NULL, NULL, &iosb, buffer, FILE_BUFFER_SIZE, NULL, NULL)))
196+
while (TRUE)
199197
{
200-
if (status == STATUS_END_OF_FILE)
201-
break;
202-
203-
CstFailWithStatus(PhFormatString(L"Unable to read '%s'", FileName)->Buffer, status, 0);
198+
status = NtReadFile(
199+
fileHandle,
200+
NULL,
201+
NULL,
202+
NULL,
203+
&iosb,
204+
buffer,
205+
FILE_BUFFER_SIZE,
206+
NULL,
207+
NULL
208+
);
209+
210+
if (!NT_SUCCESS(status))
211+
{
212+
if (status == STATUS_END_OF_FILE)
213+
break;
214+
215+
CstFailWithStatus(PhFormatString(L"Unable to read '%s'", FileName)->Buffer, status, 0);
216+
}
217+
218+
if (!NT_SUCCESS(status = BCryptHashData(hashHandle, buffer, (ULONG)iosb.Information, 0)))
219+
CstFailWithStatus(L"Unable to hash file", status, 0);
204220
}
205221

206-
if (!NT_SUCCESS(status = BCryptHashData(hashHandle, buffer, (ULONG)iosb.Information, 0)))
207-
CstFailWithStatus(L"Unable to hash file", status, 0);
222+
PhFreePage(buffer);
208223
}
209224

210-
PhFreePage(buffer);
211225
NtClose(fileHandle);
212226

213227
hash = PhAllocate(hashSize);
@@ -294,7 +308,7 @@ int __cdecl wmain(int argc, wchar_t *argv[])
294308
CstFailWithStatus(L"Unable to open the signing algorithm provider", status, 0);
295309
buffer = CstReadFile(CstKeyFileName->Buffer, 1024 * 1024, &bufferSize);
296310
if (!NT_SUCCESS(status = BCryptImportKeyPair(signAlgHandle, NULL, CST_BLOB_PRIVATE, &keyHandle, buffer, bufferSize, 0)))
297-
CstFailWithStatus(PhFormatString(L"Unable to import the private key", CstKeyFileName->Buffer)->Buffer, status, 0);
311+
CstFailWithStatus(PhFormatString(L"Unable to import the private key: %s", CstKeyFileName->Buffer)->Buffer, status, 0);
298312
PhFree(buffer);
299313

300314
// Hash the file.
@@ -308,6 +322,7 @@ int __cdecl wmain(int argc, wchar_t *argv[])
308322
signature = PhAllocate(signatureSize);
309323
if (!NT_SUCCESS(status = BCryptSignHash(keyHandle, NULL, hash, hashSize, signature, signatureSize, &signatureSize, 0)))
310324
CstFailWithStatus(L"Unable to create the signature", status, 0);
325+
311326
PhFree(hash);
312327
BCryptDestroyKey(keyHandle);
313328
BCryptCloseAlgorithmProvider(signAlgHandle, 0);
@@ -356,7 +371,7 @@ int __cdecl wmain(int argc, wchar_t *argv[])
356371
CstFailWithStatus(L"Unable to open the signing algorithm provider", status, 0);
357372
buffer = CstReadFile(CstKeyFileName->Buffer, 1024 * 1024, &bufferSize);
358373
if (!NT_SUCCESS(status = BCryptImportKeyPair(signAlgHandle, NULL, CST_BLOB_PUBLIC, &keyHandle, buffer, bufferSize, 0)))
359-
CstFailWithStatus(PhFormatString(L"Unable to import the public key", CstKeyFileName->Buffer)->Buffer, status, 0);
374+
CstFailWithStatus(PhFormatString(L"Unable to import the public key: %s", CstKeyFileName->Buffer)->Buffer, status, 0);
360375
PhFree(buffer);
361376

362377
// Read the signature.
@@ -370,7 +385,8 @@ int __cdecl wmain(int argc, wchar_t *argv[])
370385
// Verify the hash.
371386

372387
if (!NT_SUCCESS(status = BCryptVerifySignature(keyHandle, NULL, hash, hashSize, signature, signatureSize, 0)))
373-
CstFailWithStatus(PhFormatString(L"Signature verification failed", CstKeyFileName->Buffer)->Buffer, status, 0);
388+
CstFailWithStatus(PhFormatString(L"Signature verification failed: %s", CstKeyFileName->Buffer)->Buffer, status, 0);
389+
374390
PhFree(signature);
375391
PhFree(hash);
376392

0 commit comments

Comments
 (0)