|
@@ -12,7 +12,7 @@ unit Setup.InstFunc;
|
|
interface
|
|
interface
|
|
|
|
|
|
uses
|
|
uses
|
|
- Windows, SysUtils, Shared.Int64Em, MD5, SHA1, Shared.CommonFunc;
|
|
|
|
|
|
+ Windows, SysUtils, Shared.Int64Em, SHA256, Shared.CommonFunc;
|
|
|
|
|
|
type
|
|
type
|
|
PSimpleStringListArray = ^TSimpleStringListArray;
|
|
PSimpleStringListArray = ^TSimpleStringListArray;
|
|
@@ -58,15 +58,9 @@ function GenerateNonRandomUniqueTempDir(const LimitCurrentUserSidAccess: Boolean
|
|
function GetComputerNameString: String;
|
|
function GetComputerNameString: String;
|
|
function GetFileDateTime(const DisableFsRedir: Boolean; const Filename: String;
|
|
function GetFileDateTime(const DisableFsRedir: Boolean; const Filename: String;
|
|
var DateTime: TFileTime): Boolean;
|
|
var DateTime: TFileTime): Boolean;
|
|
-function GetMD5OfFile(const DisableFsRedir: Boolean; const Filename: String): TMD5Digest;
|
|
|
|
-function GetMD5OfAnsiString(const S: AnsiString): TMD5Digest;
|
|
|
|
-function GetMD5OfUnicodeString(const S: UnicodeString): TMD5Digest;
|
|
|
|
-function GetSHA1OfFile(const DisableFsRedir: Boolean; const Filename: String): TSHA1Digest;
|
|
|
|
-function GetSHA1OfAnsiString(const S: AnsiString): TSHA1Digest;
|
|
|
|
-function GetSHA1OfUnicodeString(const S: UnicodeString): TSHA1Digest;
|
|
|
|
-function GetSHA256OfFile(const DisableFsRedir: Boolean; const Filename: String): String;
|
|
|
|
-function GetSHA256OfAnsiString(const S: AnsiString): String;
|
|
|
|
-function GetSHA256OfUnicodeString(const S: UnicodeString): String;
|
|
|
|
|
|
+function GetSHA256OfFile(const DisableFsRedir: Boolean; const Filename: String): TSHA256Digest;
|
|
|
|
+function GetSHA256OfAnsiString(const S: AnsiString): TSHA256Digest;
|
|
|
|
+function GetSHA256OfUnicodeString(const S: UnicodeString): TSHA256Digest;
|
|
function GetRegRootKeyName(const RootKey: HKEY): String;
|
|
function GetRegRootKeyName(const RootKey: HKEY): String;
|
|
function GetSpaceOnDisk(const DisableFsRedir: Boolean; const DriveRoot: String;
|
|
function GetSpaceOnDisk(const DisableFsRedir: Boolean; const DriveRoot: String;
|
|
var FreeBytes, TotalBytes: Integer64): Boolean;
|
|
var FreeBytes, TotalBytes: Integer64): Boolean;
|
|
@@ -87,7 +81,7 @@ procedure InternalErrorFmt(const S: String; const Args: array of const);
|
|
function IsDirEmpty(const DisableFsRedir: Boolean; const Dir: String): Boolean;
|
|
function IsDirEmpty(const DisableFsRedir: Boolean; const Dir: String): Boolean;
|
|
function IsProtectedSystemFile(const DisableFsRedir: Boolean;
|
|
function IsProtectedSystemFile(const DisableFsRedir: Boolean;
|
|
const Filename: String): Boolean;
|
|
const Filename: String): Boolean;
|
|
-function MakePendingFileRenameOperationsChecksum: TMD5Digest;
|
|
|
|
|
|
+function MakePendingFileRenameOperationsChecksum: TSHA256Digest;
|
|
function ModifyPifFile(const Filename: String; const CloseOnExit: Boolean): Boolean;
|
|
function ModifyPifFile(const Filename: String; const CloseOnExit: Boolean): Boolean;
|
|
procedure RaiseFunctionFailedError(const FunctionName: String);
|
|
procedure RaiseFunctionFailedError(const FunctionName: String);
|
|
procedure RaiseOleError(const FunctionName: String; const ResultCode: HRESULT);
|
|
procedure RaiseOleError(const FunctionName: String; const ResultCode: HRESULT);
|
|
@@ -106,7 +100,7 @@ implementation
|
|
uses
|
|
uses
|
|
Messages, ShellApi, PathFunc, SetupLdrAndSetup.InstFunc, SetupLdrAndSetup.Messages,
|
|
Messages, ShellApi, PathFunc, SetupLdrAndSetup.InstFunc, SetupLdrAndSetup.Messages,
|
|
Shared.SetupMessageIDs, Shared.FileClass, SetupLdrAndSetup.RedirFunc, Shared.SetupTypes,
|
|
Shared.SetupMessageIDs, Shared.FileClass, SetupLdrAndSetup.RedirFunc, Shared.SetupTypes,
|
|
- Hash, Classes, RegStr, Math;
|
|
|
|
|
|
+ Classes, RegStr, Math;
|
|
|
|
|
|
procedure InternalError(const Id: String);
|
|
procedure InternalError(const Id: String);
|
|
begin
|
|
begin
|
|
@@ -556,110 +550,36 @@ begin
|
|
DateTime.dwHighDateTime := 0;
|
|
DateTime.dwHighDateTime := 0;
|
|
end;
|
|
end;
|
|
|
|
|
|
-function GetMD5OfFile(const DisableFsRedir: Boolean; const Filename: String): TMD5Digest;
|
|
|
|
-{ Gets MD5 sum of the file Filename. An exception will be raised upon
|
|
|
|
- failure. }
|
|
|
|
-var
|
|
|
|
- Buf: array[0..65535] of Byte;
|
|
|
|
-begin
|
|
|
|
- var Context: TMD5Context;
|
|
|
|
- MD5Init(Context);
|
|
|
|
- var F := TFileRedir.Create(DisableFsRedir, Filename, fdOpenExisting, faRead, fsReadWrite);
|
|
|
|
- try
|
|
|
|
- while True do begin
|
|
|
|
- var NumRead := F.Read(Buf, SizeOf(Buf));
|
|
|
|
- if NumRead = 0 then
|
|
|
|
- Break;
|
|
|
|
- MD5Update(Context, Buf, NumRead);
|
|
|
|
- end;
|
|
|
|
- finally
|
|
|
|
- F.Free;
|
|
|
|
- end;
|
|
|
|
- Result := MD5Final(Context);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function GetSHA1OfFile(const DisableFsRedir: Boolean; const Filename: String): TSHA1Digest;
|
|
|
|
-{ Gets SHA-1 sum of the file Filename. An exception will be raised upon
|
|
|
|
|
|
+function GetSHA256OfFile(const DisableFsRedir: Boolean; const Filename: String): TSHA256Digest;
|
|
|
|
+{ Gets SHA-256 sum as a string of the file Filename. An exception will be raised upon
|
|
failure. }
|
|
failure. }
|
|
var
|
|
var
|
|
Buf: array[0..65535] of Byte;
|
|
Buf: array[0..65535] of Byte;
|
|
begin
|
|
begin
|
|
- var Context: TSHA1Context;
|
|
|
|
- SHA1Init(Context);
|
|
|
|
|
|
+ var Context: TSHA256Context;
|
|
|
|
+ SHA256Init(Context);
|
|
var F := TFileRedir.Create(DisableFsRedir, Filename, fdOpenExisting, faRead, fsReadWrite);
|
|
var F := TFileRedir.Create(DisableFsRedir, Filename, fdOpenExisting, faRead, fsReadWrite);
|
|
try
|
|
try
|
|
while True do begin
|
|
while True do begin
|
|
var NumRead := F.Read(Buf, SizeOf(Buf));
|
|
var NumRead := F.Read(Buf, SizeOf(Buf));
|
|
if NumRead = 0 then
|
|
if NumRead = 0 then
|
|
Break;
|
|
Break;
|
|
- SHA1Update(Context, Buf, NumRead);
|
|
|
|
|
|
+ SHA256Update(Context, Buf, NumRead);
|
|
end;
|
|
end;
|
|
finally
|
|
finally
|
|
F.Free;
|
|
F.Free;
|
|
end;
|
|
end;
|
|
- Result := SHA1Final(Context);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function GetSHA256OfFile(const DisableFsRedir: Boolean; const Filename: String): String;
|
|
|
|
-{ Gets SHA-256 sum as a string of the file Filename. An exception will be raised upon
|
|
|
|
- failure. }
|
|
|
|
-begin
|
|
|
|
- var PrevState: TPreviousFsRedirectionState;
|
|
|
|
- if not DisableFsRedirectionIf(DisableFsRedir, PrevState) then
|
|
|
|
- InternalError('GetSHA256OfFile: DisableFsRedirectionIf failed.');
|
|
|
|
- try
|
|
|
|
- Result := THashSHA2.GetHashStringFromFile(Filename, SHA256);
|
|
|
|
- finally
|
|
|
|
- RestoreFsRedirection(PrevState);
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function GetMD5OfAnsiString(const S: AnsiString): TMD5Digest;
|
|
|
|
-begin
|
|
|
|
- Result := MD5Buf(Pointer(S)^, Length(S)*SizeOf(S[1]));
|
|
|
|
|
|
+ Result := SHA256Final(Context);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function GetMD5OfUnicodeString(const S: UnicodeString): TMD5Digest;
|
|
|
|
|
|
+function GetSHA256OfAnsiString(const S: AnsiString): TSHA256Digest;
|
|
begin
|
|
begin
|
|
- Result := MD5Buf(Pointer(S)^, Length(S)*SizeOf(S[1]));
|
|
|
|
|
|
+ Result := SHA256Buf(Pointer(S)^, Length(S)*SizeOf(S[1]));
|
|
end;
|
|
end;
|
|
|
|
|
|
-function GetSHA1OfAnsiString(const S: AnsiString): TSHA1Digest;
|
|
|
|
|
|
+function GetSHA256OfUnicodeString(const S: UnicodeString): TSHA256Digest;
|
|
begin
|
|
begin
|
|
- Result := SHA1Buf(Pointer(S)^, Length(S)*SizeOf(S[1]));
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function GetSHA1OfUnicodeString(const S: UnicodeString): TSHA1Digest;
|
|
|
|
-begin
|
|
|
|
- Result := SHA1Buf(Pointer(S)^, Length(S)*SizeOf(S[1]));
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function GetSHA256OfAnsiString(const S: AnsiString): String;
|
|
|
|
-var
|
|
|
|
- M: TMemoryStream;
|
|
|
|
-begin
|
|
|
|
- M := TMemoryStream.Create;
|
|
|
|
- try
|
|
|
|
- M.Write(Pointer(S)^, Length(S)*SizeOf(S[1]));
|
|
|
|
- M.Seek(0, soFromBeginning);
|
|
|
|
- Result := THashSHA2.GetHashString(M, SHA256);
|
|
|
|
- finally
|
|
|
|
- M.Free;
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function GetSHA256OfUnicodeString(const S: UnicodeString): String;
|
|
|
|
-var
|
|
|
|
- M: TMemoryStream;
|
|
|
|
-begin
|
|
|
|
- M := TMemoryStream.Create;
|
|
|
|
- try
|
|
|
|
- M.Write(Pointer(S)^, Length(S)*SizeOf(S[1]));
|
|
|
|
- M.Seek(0, soFromBeginning);
|
|
|
|
- Result := THashSHA2.GetHashString(M, SHA256);
|
|
|
|
- finally
|
|
|
|
- M.Free;
|
|
|
|
- end;
|
|
|
|
|
|
+ Result := SHA256Buf(Pointer(S)^, Length(S)*SizeOf(S[1]));
|
|
end;
|
|
end;
|
|
|
|
|
|
var
|
|
var
|
|
@@ -940,31 +860,31 @@ begin
|
|
Result := '';
|
|
Result := '';
|
|
end;
|
|
end;
|
|
|
|
|
|
-function MakePendingFileRenameOperationsChecksum: TMD5Digest;
|
|
|
|
|
|
+function MakePendingFileRenameOperationsChecksum: TSHA256Digest;
|
|
{ Calculates a checksum of the current PendingFileRenameOperations registry
|
|
{ Calculates a checksum of the current PendingFileRenameOperations registry
|
|
value The caller can use this checksum to determine if
|
|
value The caller can use this checksum to determine if
|
|
PendingFileRenameOperations was changed (perhaps by another program). }
|
|
PendingFileRenameOperations was changed (perhaps by another program). }
|
|
var
|
|
var
|
|
- Context: TMD5Context;
|
|
|
|
|
|
+ Context: TSHA256Context;
|
|
K: HKEY;
|
|
K: HKEY;
|
|
S: String;
|
|
S: String;
|
|
begin
|
|
begin
|
|
- MD5Init(Context);
|
|
|
|
|
|
+ SHA256Init(Context);
|
|
try
|
|
try
|
|
if RegOpenKeyExView(rvDefault, HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager',
|
|
if RegOpenKeyExView(rvDefault, HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager',
|
|
0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
|
|
0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
|
|
if RegQueryMultiStringValue(K, 'PendingFileRenameOperations', S) then
|
|
if RegQueryMultiStringValue(K, 'PendingFileRenameOperations', S) then
|
|
- MD5Update(Context, S[1], Length(S)*SizeOf(S[1]));
|
|
|
|
|
|
+ SHA256Update(Context, S[1], Length(S)*SizeOf(S[1]));
|
|
{ When "PendingFileRenameOperations" is full, it spills over into
|
|
{ When "PendingFileRenameOperations" is full, it spills over into
|
|
"PendingFileRenameOperations2" }
|
|
"PendingFileRenameOperations2" }
|
|
if RegQueryMultiStringValue(K, 'PendingFileRenameOperations2', S) then
|
|
if RegQueryMultiStringValue(K, 'PendingFileRenameOperations2', S) then
|
|
- MD5Update(Context, S[1], Length(S)*SizeOf(S[1]));
|
|
|
|
|
|
+ SHA256Update(Context, S[1], Length(S)*SizeOf(S[1]));
|
|
RegCloseKey(K);
|
|
RegCloseKey(K);
|
|
end;
|
|
end;
|
|
except
|
|
except
|
|
{ don't propagate exceptions }
|
|
{ don't propagate exceptions }
|
|
end;
|
|
end;
|
|
- Result := MD5Final(Context);
|
|
|
|
|
|
+ Result := SHA256Final(Context);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure EnumFileReplaceOperationsFilenames(const EnumFunc: TEnumFROFilenamesProc;
|
|
procedure EnumFileReplaceOperationsFilenames(const EnumFunc: TEnumFROFilenamesProc;
|