DXGL r921 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r920‎ | r921 | r922 >
Date:18:26, 10 May 2019
Author:admin
Status:new
Tags:
Comment:
Add digital signature support to build process.
Modified paths:
  • /Installer/dxgl.nsi (modified) (history)
  • /buildtool/buildtool.c (modified) (history)
  • /common/releasever.h (modified) (history)
  • /common/version.nsh.in (modified) (history)
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /dxgl.sln (modified) (history)
  • /dxglcfg/dxglcfg.vcxproj (modified) (history)

Diff [purge]

Index: Installer/dxgl.nsi
@@ -423,4 +423,11 @@
424424 DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
425425 DeleteRegKey HKLM "Software\DXGL"
426426 SetAutoClose true
427 -SectionEnd
\ No newline at end of file
 427+SectionEnd
 428+
 429+!if ${SIGNTOOL} == 1
 430+!finalize 'signtool sign /t http://timestamp.comodoca.com %1'
 431+!if ${COMPILER} == "VC2019_0"
 432+!finalize 'signtool sign /tr http://timestamp.comodoca.com /td sha256 /fd sha256 /as %1'
 433+!endif
 434+!endif
\ No newline at end of file
Index: buildtool/buildtool.c
@@ -106,6 +106,12 @@
107107 FILE *filein;
108108 FILE *fileout;
109109 int revision = GetSVNRev(path);
 110+ BOOL nosign = FALSE;
 111+ if (SIGNMODE < 1) nosign = TRUE;
 112+ if ((SIGNMODE == 1) && DXGLBETA) nosign = TRUE;
 113+ #ifdef _DEBUG
 114+ if (SIGNMODE <= 2) nosign = TRUE;
 115+ #endif
110116 strncpy(pathin,path,FILENAME_MAX);
111117 pathin[FILENAME_MAX] = 0;
112118 strncpy(pathout,path,FILENAME_MAX);
@@ -135,7 +141,7 @@
136142 findptr = strstr(buffer,"$MINOR");
137143 if(findptr) strncpy(findptr,STR(DXGLMINORVER) "\n",6);
138144 findptr = strstr(buffer,"$POINT");
139 - if(findptr) strncpy(findptr,STR(DXGLPOINTVER) "\n",6);
 145+ if(findptr) strncpy(findptr,STR(DXGLPOINTVER) "\n",9);
140146 findptr = strstr(buffer,"$REVISION");
141147 if(findptr)
142148 {
@@ -163,6 +169,12 @@
164170 {
165171 if (strstr(buffer, "//#define DXGLBETA")) strcpy(buffer, "#define DXGLBETA");
166172 }
 173+ findptr = strstr(buffer, "$SIGNTOOL");
 174+ if (findptr)
 175+ {
 176+ if (nosign) strncpy(findptr, "0", 10);
 177+ else strncpy(findptr, "1", 10);
 178+ }
167179 fputs(buffer,fileout);
168180 }
169181 fclose(filein);
@@ -442,7 +454,7 @@
443455 {
444456 int result = MessageBoxA(NULL,"Could not find NSIS, would you like to download it?","NSIS not found",
445457 MB_YESNO|MB_ICONERROR);
446 - if(result == IDYES) ShellExecuteA(NULL,"open","http://nsis.sourceforge.net/Main_Page",NULL,NULL,SW_SHOWNORMAL);
 458+ if(result == IDYES) ShellExecuteA(NULL,"open","https://nsis.sourceforge.io/Main_Page",NULL,NULL,SW_SHOWNORMAL);
447459 puts("ERROR: NSIS not found.");
448460 return -1;
449461 }
@@ -449,6 +461,52 @@
450462 return 0;
451463 }
452464
 465+int SignEXE(char *exefile)
 466+{
 467+ PROCESS_INFORMATION process;
 468+ STARTUPINFOA startinfo;
 469+ const char signtoolsha1path[] = "signtool sign /t http://timestamp.comodoca.com ";
 470+ const char signtoolsha256path[] = "signtool sign /tr http://timestamp.comodoca.com /td sha256 /fd sha256 /as ";
 471+ char signpath[MAX_PATH + 80];
 472+ BOOL nosign = FALSE;
 473+ if (SIGNMODE < 1) nosign = TRUE;
 474+ if ((SIGNMODE == 1) && DXGLBETA) nosign = TRUE;
 475+ #ifdef _DEBUG
 476+ if (SIGNMODE <= 2) nosign = TRUE;
 477+ #endif
 478+ if (nosign)
 479+ {
 480+ puts("Skipping file signature.");
 481+ return 0;
 482+ }
 483+ strcpy(&signpath, &signtoolsha1path);
 484+ strcat(&signpath, "\"");
 485+ strncat(&signpath, exefile, MAX_PATH);
 486+ strcat(&signpath, "\"");
 487+ ZeroMemory(&startinfo, sizeof(STARTUPINFOA));
 488+ startinfo.cb = sizeof(STARTUPINFOA);
 489+ if (CreateProcessA(NULL, &signpath, NULL, NULL, FALSE, 0, NULL, NULL, &startinfo, &process))
 490+ {
 491+ WaitForSingleObject(process.hProcess, INFINITE);
 492+ CloseHandle(process.hProcess);
 493+ CloseHandle(process.hThread);
 494+ Sleep(15000);
 495+ }
 496+ strcpy(&signpath, &signtoolsha256path);
 497+ strcat(&signpath, "\"");
 498+ strncat(&signpath, exefile, MAX_PATH);
 499+ strcat(&signpath, "\"");
 500+ ZeroMemory(&startinfo, sizeof(STARTUPINFOA));
 501+ startinfo.cb = sizeof(STARTUPINFOA);
 502+ if (CreateProcessA(NULL, &signpath, NULL, NULL, FALSE, 0, NULL, NULL, &startinfo, &process))
 503+ {
 504+ WaitForSingleObject(process.hProcess, INFINITE);
 505+ CloseHandle(process.hProcess);
 506+ CloseHandle(process.hThread);
 507+ Sleep(15000);
 508+ }
 509+ return 0;
 510+}
453511
454512 int main(int argc, char *argv[])
455513 {
@@ -486,6 +544,15 @@
487545 }
488546 return MakeInstaller(argv[2]);
489547 }
 548+ if (!strcmp(argv[1], "sign"))
 549+ {
 550+ if (argc < 3)
 551+ {
 552+ puts("ERROR: file specified.");
 553+ return 1;
 554+ }
 555+ return SignEXE(argv[2]);
 556+ }
490557 }
491558 else
492559 {
Index: common/releasever.h
@@ -12,6 +12,11 @@
1313
1414 #define DXGLSTRVER STR(DXGLMAJORVER) "." STR(DXGLMINORVER) "." STR(DXGLPOINTVER)
1515
 16+/* sign modes
 17+0 - never sign
 18+1 - sign non-beta only
 19+2 - sign release only
 20+3 - sign all */
 21+#define SIGNMODE 1
1622
17 -
1823 #endif //__VERSION_H
Index: common/version.nsh.in
@@ -1,5 +1,6 @@
22 !define PRODUCT_VERSION $PRODUCTVERSTRING
33 !define PRODUCT_REVISION $PRODUCTREVISION
44 !define COMPILER $COMPILERTYPE
 5+!define SIGNTOOL $SIGNTOOL
56 ;!define _BETA
67 ;!define _DEBUG
\ No newline at end of file
Index: ddraw/ddraw.vcxproj
@@ -151,6 +151,9 @@
152152 <PreBuildEvent>
153153 <Message>Create version headers</Message>
154154 </PreBuildEvent>
 155+ <PostBuildEvent>
 156+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 157+ </PostBuildEvent>
155158 </ItemDefinitionGroup>
156159 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug VS2019|Win32'">
157160 <ClCompile>
@@ -174,6 +177,9 @@
175178 <PreBuildEvent>
176179 <Message>Create version headers</Message>
177180 </PreBuildEvent>
 181+ <PostBuildEvent>
 182+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 183+ </PostBuildEvent>
178184 </ItemDefinitionGroup>
179185 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">
180186 <ClCompile>
@@ -197,6 +203,9 @@
198204 <PreBuildEvent>
199205 <Message>Create version headers</Message>
200206 </PreBuildEvent>
 207+ <PostBuildEvent>
 208+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 209+ </PostBuildEvent>
201210 </ItemDefinitionGroup>
202211 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">
203212 <ClCompile>
@@ -224,6 +233,7 @@
225234 <PreBuildEvent>
226235 <Message>Create version headers</Message>
227236 </PreBuildEvent>
 237+ <PostBuildEvent />
228238 </ItemDefinitionGroup>
229239 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
230240 <ClCompile>
@@ -252,6 +262,9 @@
253263 <PreBuildEvent>
254264 <Message>Create version headers</Message>
255265 </PreBuildEvent>
 266+ <PostBuildEvent>
 267+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 268+ </PostBuildEvent>
256269 </ItemDefinitionGroup>
257270 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release VS2019|Win32'">
258271 <ClCompile>
@@ -280,6 +293,9 @@
281294 <PreBuildEvent>
282295 <Message>Create version headers</Message>
283296 </PreBuildEvent>
 297+ <PostBuildEvent>
 298+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 299+ </PostBuildEvent>
284300 </ItemDefinitionGroup>
285301 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">
286302 <ClCompile>
@@ -310,6 +326,7 @@
311327 <PreBuildEvent>
312328 <Message>Create version headers</Message>
313329 </PreBuildEvent>
 330+ <PostBuildEvent />
314331 </ItemDefinitionGroup>
315332 <ItemGroup>
316333 <None Include="ddraw.def" />
Index: dxgl.sln
@@ -7,6 +7,7 @@
88 ProjectSection(ProjectDependencies) = postProject
99 {F142A341-5EE0-442D-A15F-98AE9B48DBAE} = {F142A341-5EE0-442D-A15F-98AE9B48DBAE}
1010 {55A95F84-E00E-4C65-BB09-41D27C5845AC} = {55A95F84-E00E-4C65-BB09-41D27C5845AC}
 11+ {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0} = {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}
1112 {87D591EB-B598-431B-9B3B-D0FF771AB473} = {87D591EB-B598-431B-9B3B-D0FF771AB473}
1213 EndProjectSection
1314 EndProject
Index: dxglcfg/dxglcfg.vcxproj
@@ -132,6 +132,9 @@
133133 <GenerateDebugInformation>true</GenerateDebugInformation>
134134 <AdditionalDependencies>winmm.lib;$(OutDir)cfgmgr.lib;opengl32.lib;Comctl32.lib;Version.lib;Htmlhelp.lib;$(OutDir)ddraw.lib;%(AdditionalDependencies)</AdditionalDependencies>
135135 </Link>
 136+ <PostBuildEvent>
 137+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 138+ </PostBuildEvent>
136139 </ItemDefinitionGroup>
137140 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug VS2019|Win32'">
138141 <ClCompile>
@@ -147,6 +150,9 @@
148151 <GenerateDebugInformation>true</GenerateDebugInformation>
149152 <AdditionalDependencies>winmm.lib;$(OutDir)cfgmgr.lib;opengl32.lib;Comctl32.lib;Version.lib;Htmlhelp.lib;$(OutDir)ddraw.lib;%(AdditionalDependencies)</AdditionalDependencies>
150153 </Link>
 154+ <PostBuildEvent>
 155+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 156+ </PostBuildEvent>
151157 </ItemDefinitionGroup>
152158 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">
153159 <ClCompile>
@@ -162,6 +168,9 @@
163169 <GenerateDebugInformation>true</GenerateDebugInformation>
164170 <AdditionalDependencies>winmm.lib;$(OutDir)cfgmgr.lib;opengl32.lib;Comctl32.lib;Version.lib;Htmlhelp.lib;$(OutDir)ddraw.lib;%(AdditionalDependencies)</AdditionalDependencies>
165171 </Link>
 172+ <PostBuildEvent>
 173+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 174+ </PostBuildEvent>
166175 </ItemDefinitionGroup>
167176 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
168177 <ClCompile>
@@ -181,6 +190,9 @@
182191 <OptimizeReferences>true</OptimizeReferences>
183192 <AdditionalDependencies>winmm.lib;$(OutDir)cfgmgr.lib;opengl32.lib;Comctl32.lib;Version.lib;Htmlhelp.lib;$(OutDir)ddraw.lib;%(AdditionalDependencies)</AdditionalDependencies>
184193 </Link>
 194+ <PostBuildEvent>
 195+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 196+ </PostBuildEvent>
185197 </ItemDefinitionGroup>
186198 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release VS2019|Win32'">
187199 <ClCompile>
@@ -200,6 +212,9 @@
201213 <OptimizeReferences>true</OptimizeReferences>
202214 <AdditionalDependencies>winmm.lib;$(OutDir)cfgmgr.lib;opengl32.lib;Comctl32.lib;Version.lib;Htmlhelp.lib;$(OutDir)ddraw.lib;%(AdditionalDependencies)</AdditionalDependencies>
203215 </Link>
 216+ <PostBuildEvent>
 217+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 218+ </PostBuildEvent>
204219 </ItemDefinitionGroup>
205220 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">
206221 <ClCompile>
@@ -219,6 +234,9 @@
220235 <OptimizeReferences>true</OptimizeReferences>
221236 <AdditionalDependencies>winmm.lib;$(OutDir)cfgmgr.lib;opengl32.lib;Comctl32.lib;Version.lib;Htmlhelp.lib;$(OutDir)ddraw.lib;%(AdditionalDependencies)</AdditionalDependencies>
222237 </Link>
 238+ <PostBuildEvent>
 239+ <Command>"$(OutDir)buildtool.exe" sign "$(OutDir)$(TargetName)$(TargetExt)"</Command>
 240+ </PostBuildEvent>
223241 </ItemDefinitionGroup>
224242 <ItemGroup>
225243 <ResourceCompile Include="dxglcfg.rc" />