Skip to content

Commit

Permalink
Tweak {srcexe} protection to allow copy etc once the installation has…
Browse files Browse the repository at this point in the history
… started, making it more like how [Files] allows {srcexe} copy.
  • Loading branch information
martijnlaan committed Aug 14, 2024
1 parent 72db34c commit e5a2cdf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions ISHelp/isxfunc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ end;</pre></example>
<p>The WorkingDir parameter can be an empty string, in which case it will try to extract a pathname from the Filename parameter and use that as the initial current directory for the process. If no pathname was specified in Filename, a default directory will be used.</p>
<p>If you have a single string containing both a filename and parameters (e.g. a command line obtained from an UninstallString registry value), you need not separate them yourself; just pass <tt>'>'</tt> in the Filename parameter, and the full command line in the Params parameter. (Note that when this is done, the function's special platform-independent support for .bat and .cmd files is disabled; it simply passes the specified command line to CreateProcess without any processing.)</p>
<p>By default, when Setup/Uninstall is running in <link topic="32vs64bitinstalls">64-bit install mode</link>, this function disables WOW64 file system redirection when calling CreateProcess. It is possible to override this by calling <link topic="isxfunc_EnableFsRedirection">EnableFsRedirection</link>.</p>
<p>Can't be used to execute Setup itself.</p>
<p>Can't be used to execute Setup itself until the installation has started.</p>
<p><i>Note: compared to ISPP's Exec the ShowCmd and Wait parameters are swapped!</i></p></remarks>
<example><pre>var
ResultCode: Integer;
Expand Down Expand Up @@ -1687,7 +1687,7 @@ end;</pre></example>
<p><tt>TExecWait = (ewNoWait, ewWaitUntilTerminated, ewWaitUntilIdle);</tt></p>
<p>Note that passing a Wait value other than <tt>ewNoWait</tt> will have no effect if a new process isn't spawned (for example, if the file is opened inside an already-running instance of the program that handles the file type).</p>
<p>Refer to the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381.aspx">system error codes on MSDN</a>.</p>
<p>Can't be used to execute Setup itself.</p></remarks>
<p>Can't be used to execute Setup itself until the installation has started.</p></remarks>
<example><pre>var
ErrorCode: Integer;
begin
Expand Down Expand Up @@ -1840,13 +1840,13 @@ end;</pre>
<name>RenameFile</name>
<prototype>function RenameFile(const OldName, NewName: String): Boolean;</prototype>
<description><p>Attempts to change the name of the file or directory specified by OldFile to NewFile. If the operation succeeds, RenameFile returns True. If it cannot rename the file (for example, if a file called NewName already exists), it returns False.</p></description>
<remarks><p>Can't be used to rename Setup itself.</p></remarks>
<remarks><p>Can't be used to rename Setup itself until the installation has started.</p></remarks>
</function>
<function>
<name>CopyFile</name>
<prototype>function CopyFile(const ExistingFile, NewFile: String; const FailIfExists: Boolean): Boolean;</prototype>
<description><p>Copies ExistingFile to NewFile, preserving time stamp and file attributes.<br />If FailIfExists is True it will fail if NewFile already exists, otherwise it will overwrite it.<br />Returns True if successful, False otherwise.</p></description>
<remarks><p>Can't be used to copy Setup itself.</p></remarks>
<remarks><p>Can't be used to copy Setup itself until the installation has started.</p></remarks>
</function>
<function>
<name>DeleteFile</name>
Expand Down
17 changes: 10 additions & 7 deletions Projects/Src/Setup.ScriptFunc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ procedure InitializeScaleBaseUnits;
ScaleBaseUnitsInitialized := True;
end;

function IsSrcExe(const Filename: String): Boolean;
function IsProtectedSrcExe(const Filename: String): Boolean;
begin
var ExpandedFilename := PathExpand(Filename);
Result := PathCompare(ExpandedFilename, SetupLdrOriginalFilename) = 0;
if (MainForm = nil) or (MainForm.CurStep < ssInstall) then begin
var ExpandedFilename := PathExpand(Filename);
Result := PathCompare(ExpandedFilename, SetupLdrOriginalFilename) = 0;
end else
Result := False;
end;

{---}
Expand Down Expand Up @@ -557,7 +560,7 @@ function CommonFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack
Stack.SetBool(PStart, True);
end else if (Proc.Name = 'COPYFILE') or (Proc.Name = 'FILECOPY') then begin
ExistingFilename := Stack.GetString(PStart-1);
if not IsSrcExe(ExistingFilename) then
if not IsProtectedSrcExe(ExistingFilename) then
Stack.SetBool(PStart, CopyFileRedir(ScriptFuncDisableFsRedir,
ExistingFilename, Stack.GetString(PStart-2), Stack.GetBool(PStart-3)))
else
Expand Down Expand Up @@ -948,7 +951,7 @@ function InstFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack:
InternalError(Format('Must call "%s" function with Wait = ewWaitUntilTerminated', [Proc.Name]));

Filename := Stack.GetString(PStart-1);
if not IsSrcExe(Filename) then begin
if not IsProtectedSrcExe(Filename) then begin
{ Disable windows so the user can't utilize our UI during the InstExec
call }
WindowDisabler := TWindowDisabler.Create;
Expand Down Expand Up @@ -976,7 +979,7 @@ function InstFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack:
NoUninstallFuncError(Proc.Name);

Filename := Stack.GetString(PStart-2);
if not IsSrcExe(Filename) then begin
if not IsProtectedSrcExe(Filename) then begin
{ Disable windows so the user can't utilize our UI during the
InstShellExec call }
WindowDisabler := TWindowDisabler.Create;
Expand Down Expand Up @@ -1410,7 +1413,7 @@ function SysUtilsProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack:
Stack.SetString(PStart, NewFileSearch(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1), Stack.GetString(PStart-2)));
end else if Proc.Name = 'RENAMEFILE' then begin
OldName := Stack.GetString(PStart-1);
if not IsSrcExe(OldName) then
if not IsProtectedSrcExe(OldName) then
Stack.SetBool(PStart, MoveFileRedir(ScriptFuncDisableFsRedir, OldName, Stack.GetString(PStart-2)))
else
Stack.SetBool(PStart, False);
Expand Down

0 comments on commit e5a2cdf

Please sign in to comment.