能不能把一个现在的exe文件整合在DLL文件中?

博客探讨了将C语言写成的可执行文件(如ping.exe)集成到dll文件中,并做成函数调用实现相应功能的问题。给出了编写和调用的代码示例,还提到dll和exe有相似之处,介绍了exe合并到dll的简单办法及不释放临时exe的思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

例如,现在有一个现在的用C语言写成的可执行文件,如DOS下的ping.exe,他可以接收到一个参数的,如ping 127.0.0.1 ,能不能把这个ping.exe集成在一个dll文件中,并做成ping(ip)函数,然后通过调用这个dll中的ping(ip) 函数,来实现ping功能呢?我只是举个例子说明我的意图,我并不是想做ping 这个功能的,希望哪位高手能给出个例子参考一下。

---------------------------------------

做为资源编译到DLL里,调用函数的时候释放出来。

--------------------------------------

一、编写:
library PingDLL;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}
exports
   DoPing;
begin
end.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

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

var
  Form1: TForm1;

Procedure DoPing; cdecl;

implementation

{$R *.dfm}

Procedure DoPing;
begin
  Application.CreateForm(TForm1, Form1);
  Form1.ShowModal;
  Form1.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  WinExec(Pchar('Ping.exe '+Edit1.text),9);
end;

end.

二、调用:

unit Unit_TestDLL;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TTestDLL = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  TestDLL: TTestDLL;

implementation

{$R *.dfm}

procedure DoPing;stdcall;external 'PingDll.dll';

procedure TTestDLL.Button1Click(Sender: TObject);
begin
  DoPing;
end;

end.

-------------------------------------------

dll和exe有很多相似之处,你甚至可以干脆先把dll想象成exe。那么你的问题就变成了怎么在一个exe文件里调用另外一个exe文件。说来说去,就变成winexec api了。
至于打包不打包只不过是为了保证客户机器上也有那个要运行的exe罢了。
不释放出来怎么运行呢?完全的合二为一吗?那问题可能就变成破解重写那个软件了。

--------------------------------------------

dll和exe是一个东西,exe合并的办法同样适用于dll

一个简单的办法是用文件流或copy命令,在dll文件后面追加另一个exe,
执行的时候读取另一个exe的字节流,然后释放到一个临时文件夹下,
再winexec/shellexecute/createprocess运行这个临时exe

要想不释放临时exe的话,得先研究一下PE格式,使dll在执行的时候跳转到exe文件入口地址,
很多病毒、木马就是这样做的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值