Recent

Author Topic: Executable into executable  (Read 14247 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2259
    • Lazarus and Free Pascal italian community
Executable into executable
« on: November 08, 2010, 01:53:54 pm »
I wanted to ask a question. How can I embed an executable within another executable? I extract from the executable 1 so that the executable 2?  :)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

eny

  • Hero Member
  • *****
  • Posts: 1648
Re: Executable into executable
« Reply #1 on: November 08, 2010, 02:02:53 pm »
I wanted to ask a question. How can I embed an executable within another executable? I extract from the executable 1 so that the executable 2?  :)
Just add the 2nd executable as a resource; extract it at runtime and run it...
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #2 on: November 08, 2010, 02:04:26 pm »
You can use this tool ( http://lazarusbrasil.org/Resources.zip ) to create the resource from the executable and embed it.

xinyiman

  • Hero Member
  • *****
  • Posts: 2259
    • Lazarus and Free Pascal italian community
Re: Executable into executable
« Reply #3 on: November 08, 2010, 02:04:51 pm »
Is cross-platform solution?  :)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #4 on: November 08, 2010, 02:06:45 pm »
AFAIK, no. But the code is there, you can change it and share it.

xinyiman

  • Hero Member
  • *****
  • Posts: 2259
    • Lazarus and Free Pascal italian community
Re: Executable into executable
« Reply #5 on: November 08, 2010, 02:07:45 pm »
This is crossplatform solution?

I wanted to ask a question. How can I embed an executable within another executable? I extract from the executable 1 so that the executable 2?  :)
Just add the 2nd executable as a resource; extract it at runtime and run it...
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #6 on: November 08, 2010, 02:20:38 pm »
Well, the solution itself, AFAIK, is cross-platform.

xinyiman

  • Hero Member
  • *****
  • Posts: 2259
    • Lazarus and Free Pascal italian community
Re: Executable into executable
« Reply #7 on: November 08, 2010, 02:27:40 pm »
You can have a simple example of a procedure that inserts the executable c:\pippo.exe in c:\pluto.exe? Thank you very much
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #8 on: November 08, 2010, 02:35:08 pm »
Virtual Magnifying Glass, http://www.lazarus.freepascal.org/index.php/topic,2683.0.html

It is not for executables, but for resources in general.

Another example: http://www.lazarus.freepascal.org/index.php/topic,8848.msg43391/topicseen.html#msg43391 , this one for executables.
« Last Edit: November 08, 2010, 02:44:30 pm by typo »

xinyiman

  • Hero Member
  • *****
  • Posts: 2259
    • Lazarus and Free Pascal italian community
Re: Executable into executable
« Reply #9 on: November 08, 2010, 02:42:41 pm »
Or I did not understand me or not is what I need! I want to create an Installer-maker. And I have my executable in a place already created other executable to be extracted during installation!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #10 on: November 08, 2010, 02:46:42 pm »
See the second example.

You create your resource, embed it, and save it through this procedure:

Code: [Select]
procedure SaveResourceAsFile(const ResName: string; ResType: pchar;
  const FileName: string);
begin
  with TResourceStream.Create(hInstance, ResName, ResType) do
    try
      SaveToFile(FileName);
    finally
      Free;
    end;
end;   
« Last Edit: November 08, 2010, 02:51:11 pm by typo »

xinyiman

  • Hero Member
  • *****
  • Posts: 2259
    • Lazarus and Free Pascal italian community
Re: Executable into executable
« Reply #11 on: November 08, 2010, 02:59:00 pm »
If I want to put an executable file, and two that just call the procedure three times with the same name? And then to extract those files that I included in the executable file? How do I?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Executable into executable
« Reply #12 on: November 08, 2010, 03:17:42 pm »
Do you want to copy the same file three times? Why?

After embedding the file, you simply need to call the procedure like that:

Code: [Select]
SaveResourceAsFile('myexe','EXE','c:\test');
« Last Edit: November 08, 2010, 03:23:52 pm by typo »

LazaruX

  • Hero Member
  • *****
  • Posts: 597
  • Lazarus original cheetah.The cheetah doesn't cheat
Re: Executable into executable
« Reply #13 on: November 08, 2010, 04:41:31 pm »
Embedding an executble is a nice solution to create an installer...or a virus...
Remember if you know how too use a gun, it doesn't mean you have to use it ;-).

xinyiman

  • Hero Member
  • *****
  • Posts: 2259
    • Lazarus and Free Pascal italian community
Re: Executable into executable
« Reply #14 on: December 28, 2010, 08:46:40 am »
Sorry for the delay, but I was not able to follow the speech as the installer.

So I did some tests, but I do not work. The code that I wrote to embed an executable file within an executable file does not work. Who knows why? Thanks for your help.

Errore: The name of the executable file that must contain the other executable not found


unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.lfm}

procedure SaveResourceAsFile(const ResName: string; ResType: pchar; const FileName: string);
begin
  with TResourceStream.Create(hInstance, ResName, ResType) do
    try
      SaveToFile(FileName);
    finally
      Free;
    end;
end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
   val: string;
begin
     val:=Edit1.Text;
     val:= ExtractFilePath (Application.ExeName) + val;
     SaveResourceAsFile(Application.ExeName,'exe', val);
end;

end.

initialization
{$I program.lrs}     
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018