提取Delphi(BCB)编译过的exe和dll或bpl,dpl文件中的窗体代码
function EnumResProc (hMod: THandle; ResType, ResName: PChar; Self: TPeekForm): Boolean; stdcall;
var
h: THandle;
p: pDWord;
begin
// OK - we've got a rc_Data resource, but is it a DFM?
h := LoadResource (hMod, FindResource (hMod, ResName, ResType));
p := LockResource (h);
if p^ = $30465054 then Self.FormList.Items.Add (ResName);
Result := True;
end;
procedure TPeekForm.Clear;
begin
if hMod > 0 then FreeLibrary (hMod);
FormData.Lines.Clear;
FormList.Clear;
end;
procedure TPeekForm.GetResourceInfo;
var
hTemp: THandle;
begin
hTemp := LoadLibraryEx (PChar (OpenDialog.FileName), 0, Load_Library_As_DataFile);
if hTemp <> 0 then begin
Clear; hMod := hTemp;
Caption := Format ('Form Peeker - [%s]', [OpenDialog.FileName]);
EnumResourceNames (hMod, rt_rcData, @EnumResProc, Integer (Self));
if FormList.Items.Count > 0 then begin
FormList.ItemIndex := 0;
FormListClick (Self);
end;
end;
end;
procedure TPeekForm.FormDestroy (Sender: TObject);
begin
Clear;
end;
procedure TPeekForm.OpenButtonClick(Sender: TObject);
begin
if OpenDialog.Execute then GetResourceInfo;
end;
procedure TPeekForm.FormListClick(Sender: TObject);
var
sText: TMemoryStream;
sRes: TResourceStream;
begin
with FormList do if ItemIndex <> -1 then begin
sRes := TResourceStream.Create (hMod, Items [ItemIndex], rt_rcData);
try
sText := TMemoryStream.Create;
try
ObjectBinaryToText (sRes, sText);
sText.Position := 0;
FormData.Lines.LoadFromStream (sText);
finally
sText.Free;
end;
finally
sRes.Free;
end;
end;
end;