DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: cuiqingbo
今日帖子: 20
在线用户: 12
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/1/17 9:25:18
标题:
Exclusive: TMS SetupID Generator for InnoSetup (Delphi Source - no EXE !) 浏览:1017
加入我的收藏
楼主: Example for a SetupID:

1. 2. 3. 1403EC,9085467,85504 
----------
1. Handle to SetupLdr's Notify Window (random value !) 
2. DataOffset 0 
3. DataOffset 1
----------

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;

  TSetupLdrOffsetTable = packed record
    ID: array [1 .. 12] of AnsiChar;
    Version: LongWord;
    TotalSize: LongWord;
    OffsetEXE: LongWord;
    UncompressedSizeEXE: LongWord;
    CRCEXE: Longint;
    Offset0: LongWord;
    Offset1: LongWord;
    TableCRC: Longint;
  end;

  TMySetupLdrOffsetTable = record
    ID: AnsiString;
    TotalSize, OffsetEXE, CompressedSizeEXE, UncompressedSizeEXE, CRCEXE, Offset0, Offset1: Longint;
    TableCRC: Longint;
    TableCRCUsed: boolean;
  end;

const
  SetupLdrOffsetTableResID   = 11111;
  SetupLdrOffsetTableID      = 'rDlPtS'#$CD#$E6#$D7#$7B#$0B#$2A;
  SetupLdrOffsetTableVersion = 1;
  SetupExeModeOffset         = $30;

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;

  TSetupLdrOffsetTable = packed record
    ID: array [1 .. 12] of AnsiChar;
    Version: LongWord;
    TotalSize: LongWord;
    OffsetEXE: LongWord;
    UncompressedSizeEXE: LongWord;
    CRCEXE: Longint;
    Offset0: LongWord;
    Offset1: LongWord;
    TableCRC: Longint;
  end;

  TMySetupLdrOffsetTable = record
    ID: AnsiString;
    TotalSize, OffsetEXE, CompressedSizeEXE, UncompressedSizeEXE, CRCEXE, Offset0, Offset1: Longint;
    TableCRC: Longint;
    TableCRCUsed: boolean;
  end;

const
  SetupLdrOffsetTableResID   = 11111;
  SetupLdrOffsetTableID      = 'rDlPtS'#$CD#$E6#$D7#$7B#$0B#$2A;
  SetupLdrOffsetTableVersion = 1;
  SetupExeModeOffset         = $30;

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 GetResData(FileName: string): TArray<System.Byte>;
var
  binfile          : file of byte;
  filebytes, resbytes: TArray<System.Byte>;
  strFile          : string;
  offset          : Integer;
begin
  AssignFile(binfile, FileName);
  Reset(binfile);
  SetLength(filebytes, FileSize(binfile));
  BlockRead(binfile, filebytes[0], Length(filebytes));
  offset := FindPattern(filebytes, [$72, $44, $6C, $50, $74, $53, $CD, $E6, $D7, $7B, $0B, $2A]);
  SetLength(resbytes, 44);
  Seek(binfile, offset);
  BlockRead(binfile, resbytes[0], Length(resbytes));
  CloseFile(binfile);
  Result := resbytes;
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
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行70.3125毫秒 RSS