Konuyu Oyla:
  • Derecelendirme: 0/5 - 0 oy
  • 1
  • 2
  • 3
  • 4
  • 5
Exe veya Dll'yi Unit haline dönüştürmek
#1
Arkadaşlar selamlar;

Bazı projemde: yan dosyaları, dll, exe, resim gibi: RESOURCE dosyası haline getirerek çalışan EXE'nin bizzat kendisine gömüp kullanıyorum. Fakat ben resource olarak kullanmak istemiyorum. 

Bir DLL veya exe dosyasını bir filestream ile byte byte okuyup, HEX kodları ile, bunu UNIT haline dönüştürebilirmiyiz? 
Daha sonra bunu  projelerimizde bu UNIT'i uSES ekleyerek kullanabilirmiyiz? Yani bir exe veya dll dosyasını UNIT halide dönüştürüp projeme ekleyip kullanabilirmiyim. Bu konuda yardım etmenizi rica ederim.
Cevapla
#2
Yıllar yıllar önce benzer bir ihtiyacım olmuş kaynak kodlarıyla paylaşmıştım.


linki burada
Saygılarımla
Muharrem ARMAN

guplouajuixjzfm15eqb.gif
Cevapla
#3
(11-05-2020, Saat: 00:51)mrmarman Adlı Kullanıcıdan Alıntı: Yıllar yıllar önce benzer bir ihtiyacım olmuş kaynak kodlarıyla paylaşmıştım.


linki burada

Çok teşekkür ederim muharrem abi, ama verdiginiz linkteki FileToDelphiUnit.rar dosyası arızalı indirdim açılmıyor. Rica etsem tekrar gönderebilirmisiniz bana.
Cevapla
#4
Merhaba.

Gönderdiğim sitenin veritabanı sorunsalıdır. 

Tozlu raflardan çıkardım  Smile kodlar aşağıdaki şekilde.

Dilerseniz diske yazar kullanırsınız dilerseniz MemoryStream'e atar DLL ise LoadLibrary( )  FreeLibrary( ) ile dilerseniz nette bulabileceğiniz şekilde EXE from Stream gibi kullanabilirsiniz.

Var
 xDurdur : Boolean = False;

procedure FileToUnit( aSourceFile: String; aTargetUnit, aFunc:TStrings; aStatusPanel:TStatusPanel; aGauge: TGauge );
var
 fsDosya  : TFileStream;
 strHedef : String;
 bBuffer  : array of byte;
 iSayac,
 iByteSay : Integer;
 strUnit,
 strSatir : String;
 tBas, tTahmin: TDateTime;
 boolIlkSatir : Boolean;
begin
 tBas := Now();
// Dosya yoksa dışarı...
 if NOT FileExists(aSourceFile) then EXIT;

 TThread.CreateAnonymousThread( procedure
   begin
     strUnit  := 'Delphi_' + ExtractFileName(ChangeFileExt(aSourceFile, ''));
     strHedef := ExtractFilePath( aSourceFile ) + strUnit + '.PAS';

     // Func
     With aFunc do begin
       Clear;
       Add( '// Dönüşüm Fonksiyonu //' );
       Add( '// ------------------ //' );
       Add( '' );
       Add('USES ' + strUnit );
       Add( '' );
       Add( 'Function Donusum( strDosyaAdi: String ): Boolean; ');
       Add( 'Var                                               ');
       Add( '  fsDosya  : TFileStream;                         ');
       Add( 'begin                                             ');
       Add( '  Result := False;                                ');
       Add( '  Try                                             ');
       Add( '    fsDosya  := TFileStream.Create( strDosyaAdi, fmCreate ); ');
       Add( '    fsDosya.Write( Dizi_'+strUnit+', High( Dizi_'+strUnit+')+1 );   ');
       Add( '    fsDosya.Free;                                 ');
       Add( '  Finally');
       Add( '    Result := True;                               ');
       Add( '  End;');
       Add( 'end;                                              ');
       Add( '' );
       Add( '// Herhangi bir dosya ise aşağıdaki şekil yeterli //              ');
       Add( 'begin;                                            ');
       Add( '  Donusum( ExtractFilePath(Application.Exename) + strOrjDosya )   ');
       Add( 'end;                                              ');
       Add( '' );
       Add( '' );
     end; // with

     // UNIT
     With aTargetUnit do begin
       Clear;
       Add( Format('Unit %s;', [ strUnit ]) );
       Add( '' );
       Add( 'Interface' );
       Add( '' );
       Add( 'Const' );
       Add( '  strOrjDosya = '+ QuotedStr( ExtractFileName(aSourceFile) )+';' );
       Add( '' );
     end; // with

     fsDosya := TFileStream.Create( aSourceFile, fmOpenread );

     aTargetUnit.Add( Format('  Dizi_%s : Array [0..%d] of Byte = ', [ strUnit, fsDosya.Size - 1 ]) );
     aTargetUnit.Add('  (');

     SetLength( bBuffer, fsDosya.Size );
     fsDosya.Read( bBuffer[0], fsDosya.Size );
     iSayac   := 0;
     iByteSay := 0;
     strSatir := '';

     if aGauge <> nil then
     begin
       aGauge.MinValue := 0;
       aGauge.MaxValue := fsDosya.Size;
       aGauge.Visible  := True;
     end;
     boolIlkSatir := True;

     aTargetUnit.BeginUpdate;
     while (iSayac < fsDosya.Size) AND (NOT xDurdur) do
     begin
       if iByteSay = 0 then
       begin
         if strSatir <> '' then aTargetUnit.Add( strSatir );
         iByteSay := 30;
         strSatir := '';
         // 10   100 byte
         tTahmin  := tBas;
         if iSayac > 0 then
           tTahmin  := IncMilliSecond( tBas, (fsDosya.Size * MilliSecondsBetween( Now(), tBas ) div iSayac) );
         if aStatusPanel <> nil
           then aStatusPanel.Text := Format('%d / %d byte (-%d sn.)', [iSayac, fsDosya.Size, SecondsBetween(tTahmin, Now()) ]);
       end;

       if strSatir = '' then
       begin
         if boolIlkSatir then
         begin
           strSatir :=            Format('  $%.2x', [ bBuffer[iSayac] ]);
           boolIlkSatir := False;
         end else begin
           strSatir :=            Format(' ,$%.2x', [ bBuffer[iSayac] ]);
         end;
       end
       else strSatir := strSatir + Format(',$%.2x', [ bBuffer[iSayac] ]);

       inc(iSayac);
       Dec(iByteSay);

       if aGauge <> nil then
         TThread.Synchronize(nil, procedure
           begin
             aGauge.Progress := iSayac;
           end );
       // Application.ProcessMessages;
     end; // while
     aTargetUnit.EndUpdate;

     if strSatir <> '' then aTargetUnit.Add( strSatir );
     if aGauge    <> nil then aGauge.Visible := False;

     if xDurdur then
     begin
       aTargetUnit.Add('');
       aTargetUnit.Add('// -------------------------------------------- //');
       aTargetUnit.Add('//   !!!   Kullanıcı Tarafından Durduruldu !!!  //');
       aTargetUnit.Add('// -------------------------------------------- //');
     end else
     begin
       aTargetUnit.Add('  );');
       aTargetUnit.Add('implementation');
       aTargetUnit.Add('end.');
     end;

   end ).Start;
 fsDosya.Free;
end;



Kullanımı :
Edit1 : Kaynak Dosya
Memo1 : Üretilen Unit
Memo2 : dönüşüm Function
StatusBar Panel : Durum ve kalan süre
Gauge1 : % olarak durum

- işlem sırasında global değişken xDurdur  değeri TRUE olursa işlem iptal edilip döngüden çıkılır.
 
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
 if TBitBtn(Sender).Caption = 'Dönüştür' then
 begin
   BitBtn3.Enabled := False;
   xDurdur := False;
   TBitBtn(Sender).Caption := 'Durdur';
   Memo1.Visible := False;

   FileToUnit( Edit1.Text, Memo1.Lines, Memo2.Lines, StatusBar1.Panels[0], Gauge1 );

   Memo1.Visible   := True;
   BitBtn3.Enabled := True;
 end else begin
   BitBtn3.Enabled := True;
   xDurdur := True;
   TBitBtn(Sender).Caption := 'Dönüştür';
   Memo1.Visible := True;
 end;
end;

kal6ak7a5mgd9cgv5bv1.png
Saygılarımla
Muharrem ARMAN

guplouajuixjzfm15eqb.gif
Cevapla
#5
(11-05-2020, Saat: 09:25)mrmarman Adlı Kullanıcıdan Alıntı: Merhaba.

Gönderdiğim sitenin veritabanı sorunsalıdır. 

Tozlu raflardan çıkardım  Smile kodlar aşağıdaki şekilde.

Dilerseniz diske yazar kullanırsınız dilerseniz MemoryStream'e atar DLL ise LoadLibrary( )  FreeLibrary( ) ile dilerseniz nette bulabileceğiniz şekilde EXE from Stream gibi kullanabilirsiniz.

Var
 xDurdur : Boolean = False;

procedure FileToUnit( aSourceFile: String; aTargetUnit, aFunc:TStrings; aStatusPanel:TStatusPanel; aGauge: TGauge );
var
 fsDosya  : TFileStream;
 strHedef : String;
 bBuffer  : array of byte;
 iSayac,
 iByteSay : Integer;
 strUnit,
 strSatir : String;
 tBas, tTahmin: TDateTime;
 boolIlkSatir : Boolean;
begin
 tBas := Now();
// Dosya yoksa dışarı...
 if NOT FileExists(aSourceFile) then EXIT;

 TThread.CreateAnonymousThread( procedure
   begin
     strUnit  := 'Delphi_' + ExtractFileName(ChangeFileExt(aSourceFile, ''));
     strHedef := ExtractFilePath( aSourceFile ) + strUnit + '.PAS';

     // Func
     With aFunc do begin
       Clear;
       Add( '// Dönüşüm Fonksiyonu //' );
       Add( '// ------------------ //' );
       Add( '' );
       Add('USES ' + strUnit );
       Add( '' );
       Add( 'Function Donusum( strDosyaAdi: String ): Boolean; ');
       Add( 'Var                                               ');
       Add( '  fsDosya  : TFileStream;                         ');
       Add( 'begin                                             ');
       Add( '  Result := False;                                ');
       Add( '  Try                                             ');
       Add( '    fsDosya  := TFileStream.Create( strDosyaAdi, fmCreate ); ');
       Add( '    fsDosya.Write( Dizi_'+strUnit+', High( Dizi_'+strUnit+')+1 );   ');
       Add( '    fsDosya.Free;                                 ');
       Add( '  Finally');
       Add( '    Result := True;                               ');
       Add( '  End;');
       Add( 'end;                                              ');
       Add( '' );
       Add( '// Herhangi bir dosya ise aşağıdaki şekil yeterli //              ');
       Add( 'begin;                                            ');
       Add( '  Donusum( ExtractFilePath(Application.Exename) + strOrjDosya )   ');
       Add( 'end;                                              ');
       Add( '' );
       Add( '' );
     end; // with

     // UNIT
     With aTargetUnit do begin
       Clear;
       Add( Format('Unit %s;', [ strUnit ]) );
       Add( '' );
       Add( 'Interface' );
       Add( '' );
       Add( 'Const' );
       Add( '  strOrjDosya = '+ QuotedStr( ExtractFileName(aSourceFile) )+';' );
       Add( '' );
     end; // with

     fsDosya := TFileStream.Create( aSourceFile, fmOpenread );

     aTargetUnit.Add( Format('  Dizi_%s : Array [0..%d] of Byte = ', [ strUnit, fsDosya.Size - 1 ]) );
     aTargetUnit.Add('  (');

     SetLength( bBuffer, fsDosya.Size );
     fsDosya.Read( bBuffer[0], fsDosya.Size );
     iSayac   := 0;
     iByteSay := 0;
     strSatir := '';

     if aGauge <> nil then
     begin
       aGauge.MinValue := 0;
       aGauge.MaxValue := fsDosya.Size;
       aGauge.Visible  := True;
     end;
     boolIlkSatir := True;

     aTargetUnit.BeginUpdate;
     while (iSayac < fsDosya.Size) AND (NOT xDurdur) do
     begin
       if iByteSay = 0 then
       begin
         if strSatir <> '' then aTargetUnit.Add( strSatir );
         iByteSay := 30;
         strSatir := '';
         // 10   100 byte
         tTahmin  := tBas;
         if iSayac > 0 then
           tTahmin  := IncMilliSecond( tBas, (fsDosya.Size * MilliSecondsBetween( Now(), tBas ) div iSayac) );
         if aStatusPanel <> nil
           then aStatusPanel.Text := Format('%d / %d byte (-%d sn.)', [iSayac, fsDosya.Size, SecondsBetween(tTahmin, Now()) ]);
       end;

       if strSatir = '' then
       begin
         if boolIlkSatir then
         begin
           strSatir :=            Format('  $%.2x', [ bBuffer[iSayac] ]);
           boolIlkSatir := False;
         end else begin
           strSatir :=            Format(' ,$%.2x', [ bBuffer[iSayac] ]);
         end;
       end
       else strSatir := strSatir + Format(',$%.2x', [ bBuffer[iSayac] ]);

       inc(iSayac);
       Dec(iByteSay);

       if aGauge <> nil then
         TThread.Synchronize(nil, procedure
           begin
             aGauge.Progress := iSayac;
           end );
       // Application.ProcessMessages;
     end; // while
     aTargetUnit.EndUpdate;

     if strSatir <> '' then aTargetUnit.Add( strSatir );
     if aGauge    <> nil then aGauge.Visible := False;

     if xDurdur then
     begin
       aTargetUnit.Add('');
       aTargetUnit.Add('// -------------------------------------------- //');
       aTargetUnit.Add('//   !!!   Kullanıcı Tarafından Durduruldu !!!  //');
       aTargetUnit.Add('// -------------------------------------------- //');
     end else
     begin
       aTargetUnit.Add('  );');
       aTargetUnit.Add('implementation');
       aTargetUnit.Add('end.');
     end;

   end ).Start;
 fsDosya.Free;
end;



Kullanımı :
Edit1 : Kaynak Dosya
Memo1 : Üretilen Unit
Memo2 : dönüşüm Function
StatusBar Panel : Durum ve kalan süre
Gauge1 : % olarak durum

- işlem sırasında global değişken xDurdur  değeri TRUE olursa işlem iptal edilip döngüden çıkılır.
 
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
 if TBitBtn(Sender).Caption = 'Dönüştür' then
 begin
   BitBtn3.Enabled := False;
   xDurdur := False;
   TBitBtn(Sender).Caption := 'Durdur';
   Memo1.Visible := False;

   FileToUnit( Edit1.Text, Memo1.Lines, Memo2.Lines, StatusBar1.Panels[0], Gauge1 );

   Memo1.Visible   := True;
   BitBtn3.Enabled := True;
 end else begin
   BitBtn3.Enabled := True;
   xDurdur := True;
   TBitBtn(Sender).Caption := 'Dönüştür';
   Memo1.Visible := True;
 end;
end;

kal6ak7a5mgd9cgv5bv1.png
Çok teşekkür ederim muharrem abi. Zahmet verdim çok sağol
Cevapla


Konu ile Alakalı Benzer Konular
Konular Yazar Yorumlar Okunma Son Yorum
  Delphi tms vcl ui pack veya alternatifi eroniko 0 772 25-02-2025, Saat: 20:09
Son Yorum: eroniko
  saat biciminin algilanmasi 12 saat veya 24 saat sadikacar60 1 865 11-11-2024, Saat: 09:36
Son Yorum: hi_selamlar
  Html veya Xml pdf e çevirme ahmet6513 11 6.120 02-01-2023, Saat: 15:22
Son Yorum: ahmet6513
  Delphi ile güvenlik kamerasından veya resimden cisimleri sayma koysuren 3 2.569 30-07-2022, Saat: 16:39
Son Yorum: Jakarta2
  XML Dosyayı Grid veya StrinGrid'e Aktarma MuhammedYasir 17 8.859 04-05-2022, Saat: 11:25
Son Yorum: mkysoft



Konuyu Okuyanlar: 1 Ziyaretçi