Browse Source

Update for unit split + use TrustedFile before loading ISCmplr.dll.

Martijn Laan 6 months ago
parent
commit
0759cc7b87

+ 9 - 0
Projects/Compil32.dpr

@@ -15,12 +15,14 @@ uses
   SysUtils,
   SysUtils,
   Forms,
   Forms,
   PathFunc in '..\Components\PathFunc.pas',
   PathFunc in '..\Components\PathFunc.pas',
+  TrustFunc in '..\Components\TrustFunc.pas',
   IDE.MainForm in 'Src\IDE.MainForm.pas' {MainForm},
   IDE.MainForm in 'Src\IDE.MainForm.pas' {MainForm},
   Shared.CommonFunc.Vcl in 'Src\Shared.CommonFunc.Vcl.pas',
   Shared.CommonFunc.Vcl in 'Src\Shared.CommonFunc.Vcl.pas',
   Shared.CommonFunc in 'Src\Shared.CommonFunc.pas',
   Shared.CommonFunc in 'Src\Shared.CommonFunc.pas',
   IDE.HelperFunc in 'Src\IDE.HelperFunc.pas',
   IDE.HelperFunc in 'Src\IDE.HelperFunc.pas',
   IDE.Messages in 'Src\IDE.Messages.pas',
   IDE.Messages in 'Src\IDE.Messages.pas',
   Shared.CompilerInt in 'Src\Shared.CompilerInt.pas',
   Shared.CompilerInt in 'Src\Shared.CompilerInt.pas',
+  Shared.CompilerInt.Struct in 'Src\Shared.CompilerInt.Struct.pas',
   IDE.OptionsForm in 'Src\IDE.OptionsForm.pas' {OptionsForm},
   IDE.OptionsForm in 'Src\IDE.OptionsForm.pas' {OptionsForm},
   IDE.StartupForm in 'Src\IDE.StartupForm.pas' {StartupForm},
   IDE.StartupForm in 'Src\IDE.StartupForm.pas' {StartupForm},
   IDE.Wizard.WizardForm in 'Src\IDE.Wizard.WizardForm.pas' {WizardForm},
   IDE.Wizard.WizardForm in 'Src\IDE.Wizard.WizardForm.pas' {WizardForm},
@@ -200,6 +202,13 @@ begin
 end;
 end;
 
 
 begin
 begin
+  {$IFNDEF STATICCOMPILER}
+  if ISCmplrLibary = 0 then begin
+    MessageBox(0, PChar(Format('Could not load %s.', [ISCmplrDLL])), nil, MB_OK or MB_ICONSTOP);
+    Halt(3);
+  end;
+  {$ENDIF}
+
   {$IFDEF DEBUG}
   {$IFDEF DEBUG}
   ReportMemoryLeaksOnShutdown := True;
   ReportMemoryLeaksOnShutdown := True;
   {$ENDIF}
   {$ENDIF}

+ 2 - 0
Projects/Compil32.dproj

@@ -78,6 +78,7 @@
         </DelphiCompile>
         </DelphiCompile>
         <DCCReference Include="..\Components\SafeDLLPath.pas"/>
         <DCCReference Include="..\Components\SafeDLLPath.pas"/>
         <DCCReference Include="..\Components\PathFunc.pas"/>
         <DCCReference Include="..\Components\PathFunc.pas"/>
+        <DCCReference Include="..\Components\TrustFunc.pas"/>
         <DCCReference Include="Src\IDE.MainForm.pas">
         <DCCReference Include="Src\IDE.MainForm.pas">
             <Form>MainForm</Form>
             <Form>MainForm</Form>
         </DCCReference>
         </DCCReference>
@@ -86,6 +87,7 @@
         <DCCReference Include="Src\IDE.HelperFunc.pas"/>
         <DCCReference Include="Src\IDE.HelperFunc.pas"/>
         <DCCReference Include="Src\IDE.Messages.pas"/>
         <DCCReference Include="Src\IDE.Messages.pas"/>
         <DCCReference Include="Src\Shared.CompilerInt.pas"/>
         <DCCReference Include="Src\Shared.CompilerInt.pas"/>
+        <DCCReference Include="Src\Shared.CompilerInt.Struct.pas"/>
         <DCCReference Include="Src\IDE.OptionsForm.pas">
         <DCCReference Include="Src\IDE.OptionsForm.pas">
             <Form>OptionsForm</Form>
             <Form>OptionsForm</Form>
         </DCCReference>
         </DCCReference>

+ 6 - 0
Projects/ISCC.dpr

@@ -23,8 +23,10 @@ uses
   Classes,
   Classes,
   {$IFDEF STATICCOMPILER} Compiler.Compile, {$ENDIF}
   {$IFDEF STATICCOMPILER} Compiler.Compile, {$ENDIF}
   PathFunc in '..\Components\PathFunc.pas',
   PathFunc in '..\Components\PathFunc.pas',
+  TrustFunc in '..\Components\TrustFunc.pas',
   Shared.CommonFunc in 'Src\Shared.CommonFunc.pas',
   Shared.CommonFunc in 'Src\Shared.CommonFunc.pas',
   Shared.CompilerInt in 'Src\Shared.CompilerInt.pas',
   Shared.CompilerInt in 'Src\Shared.CompilerInt.pas',
+  Shared.CompilerInt.Struct in 'Src\Shared.CompilerInt.Struct.pas',
   Shared.FileClass in 'Src\Shared.FileClass.pas',
   Shared.FileClass in 'Src\Shared.FileClass.pas',
   Shared.ConfigIniFile in 'Src\Shared.ConfigIniFile.pas',
   Shared.ConfigIniFile in 'Src\Shared.ConfigIniFile.pas',
   Shared.SignToolsFunc in 'Src\Shared.SignToolsFunc.pas',
   Shared.SignToolsFunc in 'Src\Shared.SignToolsFunc.pas',
@@ -559,6 +561,10 @@ begin
   end;
   end;
 
 
   {$IFNDEF STATICCOMPILER}
   {$IFNDEF STATICCOMPILER}
+  if ISCmplrLibary = 0 then begin
+    WriteStdErr(Format('Could not load %s.', [ISCmplrDLL]), True);
+    Halt(1);
+  end;
   Ver := ISDllGetVersion;
   Ver := ISDllGetVersion;
   {$ELSE}
   {$ELSE}
   Ver := ISGetVersion;
   Ver := ISGetVersion;

+ 2 - 0
Projects/ISCC.dproj

@@ -77,8 +77,10 @@
         </DelphiCompile>
         </DelphiCompile>
         <DCCReference Include="..\Components\SafeDLLPath.pas"/>
         <DCCReference Include="..\Components\SafeDLLPath.pas"/>
         <DCCReference Include="..\Components\PathFunc.pas"/>
         <DCCReference Include="..\Components\PathFunc.pas"/>
+        <DCCReference Include="..\Components\TrustFunc.pas"/>
         <DCCReference Include="Src\Shared.CommonFunc.pas"/>
         <DCCReference Include="Src\Shared.CommonFunc.pas"/>
         <DCCReference Include="Src\Shared.CompilerInt.pas"/>
         <DCCReference Include="Src\Shared.CompilerInt.pas"/>
+        <DCCReference Include="Src\Shared.CompilerInt.Struct.pas"/>
         <DCCReference Include="Src\Shared.FileClass.pas"/>
         <DCCReference Include="Src\Shared.FileClass.pas"/>
         <DCCReference Include="Src\Shared.ConfigIniFile.pas"/>
         <DCCReference Include="Src\Shared.ConfigIniFile.pas"/>
         <DCCReference Include="Src\Shared.SignToolsFunc.pas"/>
         <DCCReference Include="Src\Shared.SignToolsFunc.pas"/>

+ 1 - 1
Projects/ISCmplr.dpr

@@ -12,7 +12,7 @@ library ISCmplr;
 uses
 uses
   SafeDLLPath in '..\Components\SafeDLLPath.pas',
   SafeDLLPath in '..\Components\SafeDLLPath.pas',
   SysUtils,
   SysUtils,
-  Shared.CompilerInt in 'Src\Shared.CompilerInt.pas',
+  Shared.CompilerInt.Struct in 'Src\Shared.CompilerInt.Struct.pas',
   Shared.PreprocInt in 'Src\Shared.PreprocInt.pas',
   Shared.PreprocInt in 'Src\Shared.PreprocInt.pas',
   Compiler.Compile in 'Src\Compiler.Compile.pas',
   Compiler.Compile in 'Src\Compiler.Compile.pas',
   Compiler.SetupCompiler in 'Src\Compiler.SetupCompiler.pas',
   Compiler.SetupCompiler in 'Src\Compiler.SetupCompiler.pas',

+ 1 - 1
Projects/ISCmplr.dproj

@@ -79,7 +79,7 @@
             <MainSource>MainSource</MainSource>
             <MainSource>MainSource</MainSource>
         </DelphiCompile>
         </DelphiCompile>
         <DCCReference Include="..\Components\SafeDLLPath.pas"/>
         <DCCReference Include="..\Components\SafeDLLPath.pas"/>
-        <DCCReference Include="Src\Shared.CompilerInt.pas"/>
+        <DCCReference Include="Src\Shared.CompilerInt.Struct.pas"/>
         <DCCReference Include="Src\Shared.PreprocInt.pas"/>
         <DCCReference Include="Src\Shared.PreprocInt.pas"/>
         <DCCReference Include="Src\Compiler.Compile.pas"/>
         <DCCReference Include="Src\Compiler.Compile.pas"/>
         <DCCReference Include="Src\Compiler.SetupCompiler.pas"/>
         <DCCReference Include="Src\Compiler.SetupCompiler.pas"/>

+ 1 - 1
Projects/Src/Compiler.Compile.pas

@@ -12,7 +12,7 @@ unit Compiler.Compile;
 interface
 interface
 
 
 uses
 uses
-  Shared.CompilerInt;
+  Shared.CompilerInt.Struct;
 
 
 function ISCompileScript(const Params: TCompileScriptParamsEx;
 function ISCompileScript(const Params: TCompileScriptParamsEx;
   const PropagateExceptions: Boolean): Integer;
   const PropagateExceptions: Boolean): Integer;

+ 1 - 1
Projects/Src/Compiler.SetupCompiler.pas

@@ -20,7 +20,7 @@ interface
 uses
 uses
   Windows, SysUtils, Classes, Generics.Collections,
   Windows, SysUtils, Classes, Generics.Collections,
   SimpleExpression, SHA256, ChaCha20,
   SimpleExpression, SHA256, ChaCha20,
-  Shared.Struct, Shared.CompilerInt, Shared.PreprocInt, Shared.SetupMessageIDs,
+  Shared.Struct, Shared.CompilerInt.Struct, Shared.PreprocInt, Shared.SetupMessageIDs,
   Shared.SetupSectionDirectives, Shared.VerInfoFunc, Shared.Int64Em, Shared.DebugStruct,
   Shared.SetupSectionDirectives, Shared.VerInfoFunc, Shared.Int64Em, Shared.DebugStruct,
   Compiler.ScriptCompiler, Compiler.StringLists, Compression.LZMACompressor;
   Compiler.ScriptCompiler, Compiler.StringLists, Compression.LZMACompressor;
 
 

+ 3 - 2
Projects/Src/IDE.MainForm.pas

@@ -25,7 +25,7 @@ uses
   Windows, Messages, SysUtils, Classes, Contnrs, Graphics, Controls, Forms, Dialogs, CommDlg,
   Windows, Messages, SysUtils, Classes, Contnrs, Graphics, Controls, Forms, Dialogs, CommDlg,
   Generics.Collections, UIStateForm, StdCtrls, ExtCtrls, Menus, Buttons, ComCtrls, CommCtrl,
   Generics.Collections, UIStateForm, StdCtrls, ExtCtrls, Menus, Buttons, ComCtrls, CommCtrl,
   ScintInt, ScintEdit, IDE.ScintStylerInnoSetup, NewTabSet, ModernColors, IDE.IDEScintEdit,
   ScintInt, ScintEdit, IDE.ScintStylerInnoSetup, NewTabSet, ModernColors, IDE.IDEScintEdit,
-  Shared.DebugStruct, Shared.CompilerInt, NewUxTheme, ImageList, ImgList, ToolWin, IDE.HelperFunc,
+  Shared.DebugStruct, Shared.CompilerInt.Struct, NewUxTheme, ImageList, ImgList, ToolWin, IDE.HelperFunc,
   VirtualImageList, BaseImageCollection;
   VirtualImageList, BaseImageCollection;
 
 
 const
 const
@@ -681,7 +681,8 @@ uses
   {$IFDEF STATICCOMPILER} Compiler.Compile, {$ENDIF}
   {$IFDEF STATICCOMPILER} Compiler.Compile, {$ENDIF}
   IDE.OptionsForm, IDE.StartupForm, IDE.Wizard.WizardForm, IDE.SignToolsForm,
   IDE.OptionsForm, IDE.StartupForm, IDE.Wizard.WizardForm, IDE.SignToolsForm,
   Shared.ConfigIniFile, Shared.SignToolsFunc, IDE.InputQueryComboForm, IDE.MsgBoxDesignerForm,
   Shared.ConfigIniFile, Shared.SignToolsFunc, IDE.InputQueryComboForm, IDE.MsgBoxDesignerForm,
-  IDE.FilesDesignerForm, IDE.RegistryDesignerForm, IDE.Wizard.WizardFormRegistryHelper;
+  IDE.FilesDesignerForm, IDE.RegistryDesignerForm, IDE.Wizard.WizardFormRegistryHelper,
+  Shared.CompilerInt;
 
 
 {$R *.DFM}
 {$R *.DFM}
 
 

+ 25 - 3
Projects/Src/Shared.CompilerInt.pas

@@ -17,16 +17,38 @@ uses
 const
 const
   ISCmplrDLL = 'ISCmplr.dll';
   ISCmplrDLL = 'ISCmplr.dll';
 
 
+var
+  ISCmplrLibary: HMODULE;
+
 { The ISDllCompileScript function begins compilation of a script. See the above
 { The ISDllCompileScript function begins compilation of a script. See the above
   description of the TCompileScriptParams record. Return value is one of the
   description of the TCompileScriptParams record. Return value is one of the
   isce* constants. }
   isce* constants. }
-function ISDllCompileScript(const Params: TCompileScriptParamsEx): Integer;
-  stdcall; external ISCmplrDLL name 'ISDllCompileScriptW';
+  ISDllCompileScript: function(const Params: TCompileScriptParamsEx): Integer; stdcall;
 
 
 { The ISDllGetVersion returns a pointer to a TCompilerVersionInfo record which
 { The ISDllGetVersion returns a pointer to a TCompilerVersionInfo record which
   contains information about the compiler version. }
   contains information about the compiler version. }
-function ISDllGetVersion: PCompilerVersionInfo; stdcall; external ISCmplrDLL;
+  ISDllGetVersion: function: PCompilerVersionInfo; stdcall;
 
 
 implementation
 implementation
 
 
+uses
+  Windows,
+  SysUtils,
+  PathFunc, TrustFunc;
+
+initialization
+  var FileName := AddBackslash(PathExtractPath(ParamStr(0))) + ISCmplrDLL;
+  if TrustedFile(FileName) then begin
+    ISCmplrLibary := SafeLoadLibrary(PChar(FileName), SEM_NOOPENFILEERRORBOX);
+    if ISCmplrLibary <> 0 then begin
+      ISDllCompileScript := GetProcAddress(ISCmplrLibary, 'ISDllCompileScriptW');
+      ISDllGetVersion := GetProcAddress(ISCmplrLibary, 'ISDllGetVersion');
+      if not Assigned(ISDllCompileScript) or not Assigned(ISDllGetVersion) then begin
+        FreeLibrary(ISCmplrLibary);
+        ISCmplrLibary := 0;
+        ISDllCompileScript := nil;
+        ISDllGetVersion := nil;
+      end;
+    end;
+  end;
 end.
 end.