The two DataOffset values are stored as resource (RCDATA) in the InnoSetup EXE.
Here are two different sources for generating the SetupID: 1. Reading the required OffsetData values from the embedded resource (=44 bytes) using WinAPI functions; 2. Reading the required OffsetData values by searching the HEX-Pattern for the constant OffsetTableID and reading the 44 bytes directly;
1. Generating SetupID by reading embedded resource data uSetupId.pas: (118 lines) ********** unit uSetUpId;
interface
function GetSetupID(FileName: string): string;
implementation
uses Winapi.Windows, System.SysUtils, Math;
type PSetupLdrOffsetTable = ^TSetupLdrOffsetTable;
procedure UnifySetupLdrOffsetTable(const p; var ot: TMySetupLdrOffsetTable); var oot: TSetupLdrOffsetTable absolute p; begin with ot do begin ID := oot.ID; TotalSize := oot.TotalSize; OffsetEXE := oot.OffsetEXE; UncompressedSizeEXE := oot.UncompressedSizeEXE; CRCEXE := oot.CRCEXE; Offset0 := oot.Offset0; Offset1 := oot.Offset1; TableCRC := oot.TableCRC; TableCRCUsed := true; end; end;
function GetSetupLdrOffsetTableFromResource(FileName: string; var OffsetTable: TMySetupLdrOffsetTable): boolean; var hMod : NativeUInt; Rsrc : HRSRC; ResData: HGLOBAL; p : pointer; begin Result := false; hMod := LoadLibraryEx(PWideChar(FileName), 0, LOAD_LIBRARY_AS_DATAFILE); if (hMod = 0) and (GetLastError() = ERROR_NOT_ENOUGH_MEMORY) then hMod := LoadLibraryEx(PChar(FileName), 0, 0); if hMod = 0 then exit; repeat Rsrc := FindResource(hMod, MAKEINTRESOURCE(SetupLdrOffsetTableResID), RT_RCDATA); if Rsrc = 0 then break; ResData := LoadResource(hMod, Rsrc); if ResData = 0 then break; p := LockResource(ResData); if p = nil then break; UnifySetupLdrOffsetTable(p^, OffsetTable); Result := true; until true; FreeLibrary(hMod); end;
function GetSetupID(FileName: string): string; var OffsetTable: TMySetupLdrOffsetTable; ID : string; rnd : Integer; begin ID := '<empty>'; if GetSetupLdrOffsetTableFromResource(FileName, OffsetTable) then begin rnd := RandomRange($1E8480, $6ACFC0); ID := IntToHex(rnd, 6) + ',' + IntToStr(OffsetTable.Offset0) + ',' + IntToStr(OffsetTable.Offset1); end; Result := ID; end;
end.
********** 2. Generating SetupID by reading the 44 bytes directly ********** uSetupId2.pas: (128 lines)
Code:
unit uSetUpId2; interface
function GetSetupID(FileName: string): string;
implementation
uses Winapi.Windows, System.SysUtils, Math;
type PSetupLdrOffsetTable = ^TSetupLdrOffsetTable;
procedure UnifySetupLdrOffsetTable(const p; var ot: TMySetupLdrOffsetTable); var oot: TSetupLdrOffsetTable absolute p; begin with ot do begin ID := oot.ID; TotalSize := oot.TotalSize; OffsetEXE := oot.OffsetEXE; UncompressedSizeEXE := oot.UncompressedSizeEXE; CRCEXE := oot.CRCEXE; Offset0 := oot.Offset0; Offset1 := oot.Offset1; TableCRC := oot.TableCRC; TableCRCUsed := true; end; end;
function FindPattern(source: TBytes; seq: TBytes): Integer; var i, j : Integer; offset: Integer; begin for i := 0 to Length(source) - Length(seq) + 1 do begin for j := 0 to Length(seq) - 1 do begin if source[i + j] <> seq[j] then break; end; if (j = Length(seq)) then begin offset := i; break; end; end; Result := offset; end;
function GetSetupID(FileName: string): string; var OffsetTable: TMySetupLdrOffsetTable; ResData : TArray<System.Byte>; ID : string; rnd : Integer; begin ID := '<empty>'; ResData := GetResData(FileName); UnifySetupLdrOffsetTable(ResData[0], OffsetTable); if OffsetTable.Offset0 <> 0 then begin rnd := RandomRange($1E8480, $6ACFC0); ID := IntToHex(rnd, 6) + ',' + IntToStr(OffsetTable.Offset0) + ',' + IntToStr(OffsetTable.Offset1); end; Result := ID; end;
end. ********** How To: ---------- 1. Add unit "uSetupId.pas" to application 2. Add unit name "uSetupId" to the uses clause of the main unit 3. Call function "GetSetupID('<FileName>')" 4. SetupID will be returned as string ---------- Example: unit Demo; ... uses uSetUpId, ... procedure TForm1.Button1Click(Sender: TObject); var SetupID: String; begin SetupID := GetSetupID('<InnoSetup.exe>'); end; ...
如果你有时间并且可以阅读它,如果可能的话。 谢谢 bbs.2ccc.com/topic.asp?topicid=622461
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3