Recover a DFM from your EXE

How to get a DFM back from a delphi compiled EXE.

function ExtractDFM(ApplicationName, FormClassName: string): string;

var

  AppHandle: THandle;

  ResStream: TResourceStream;

  ResultStream: TStringStream;

begin

  Result := '';

  AppHandle := LoadLibraryEx(PChar(ApplicationName), 0, LOAD_LIBRARY_AS_DATAFILE);

  if AppHandle = 0 then

    raise Exception.Create('Could not load application');

  ResStream := nil;

  ResultStream := nil;

  try

    ResStream := TResourceStream.Create(AppHandle, FormClassName, RT_RCDATA);

    ResultStream := TStringStream.Create('');

    ObjectBinaryToText(ResStream, ResultStream);

    Result := ResultStream.DataString;

  finally



    ResultStream.Free;

    ResStream.Free;

    FreeLibrary(AppHandle);

  end;

end;

 

Share this article!

Follow us!

Find more helpful articles: