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,
   Forms,
   PathFunc in '..\Components\PathFunc.pas',
+  TrustFunc in '..\Components\TrustFunc.pas',
   IDE.MainForm in 'Src\IDE.MainForm.pas' {MainForm},
   Shared.CommonFunc.Vcl in 'Src\Shared.CommonFunc.Vcl.pas',
   Shared.CommonFunc in 'Src\Shared.CommonFunc.pas',
   IDE.HelperFunc in 'Src\IDE.HelperFunc.pas',
   IDE.Messages in 'Src\IDE.Messages.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.StartupForm in 'Src\IDE.StartupForm.pas' {StartupForm},
   IDE.Wizard.WizardForm in 'Src\IDE.Wizard.WizardForm.pas' {WizardForm},
@@ -200,6 +202,13 @@ begin
 end;
 
 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}
   ReportMemoryLeaksOnShutdown := True;
   {$ENDIF}

+ 2 - 0
Projects/Compil32.dproj

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

+ 6 - 0
Projects/ISCC.dpr

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

+ 2 - 0
Projects/ISCC.dproj

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

+ 1 - 1
Projects/ISCmplr.dpr

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

+ 1 - 1
Projects/ISCmplr.dproj

@@ -79,7 +79,7 @@
             <MainSource>MainSource</MainSource>
         </DelphiCompile>
         <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\Compiler.Compile.pas"/>
         <DCCReference Include="Src\Compiler.SetupCompiler.pas"/>

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

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

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

@@ -20,7 +20,7 @@ interface
 uses
   Windows, SysUtils, Classes, Generics.Collections,
   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,
   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,
   Generics.Collections, UIStateForm, StdCtrls, ExtCtrls, Menus, Buttons, ComCtrls, CommCtrl,
   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;
 
 const
@@ -681,7 +681,8 @@ uses
   {$IFDEF STATICCOMPILER} Compiler.Compile, {$ENDIF}
   IDE.OptionsForm, IDE.StartupForm, IDE.Wizard.WizardForm, IDE.SignToolsForm,
   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}
 

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

@@ -17,16 +17,38 @@ uses
 const
   ISCmplrDLL = 'ISCmplr.dll';
 
+var
+  ISCmplrLibary: HMODULE;
+
 { The ISDllCompileScript function begins compilation of a script. See the above
   description of the TCompileScriptParams record. Return value is one of the
   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
   contains information about the compiler version. }
-function ISDllGetVersion: PCompilerVersionInfo; stdcall; external ISCmplrDLL;
+  ISDllGetVersion: function: PCompilerVersionInfo; stdcall;
 
 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.