如何编写自动生成exe文件的程序?(100分)

  • 主题发起人 主题发起人 zycjf
  • 开始时间 开始时间
Z

zycjf

Unregistered / Unconfirmed
GUEST, unregistred user!
一些贺卡程序能自动生成exe文件,请问是如何实现的?
 
未必吧,它可能只是换换资源文件。
有知道的吗?
 
对呀,换资源的办法比较可行呀!
 
其实它并不是自动生成可执行文件,而是动态的向一个可执行文件中插入数据。这样
的程序很多,一般你都会在其目录下打到一个扩展名为BIN或者SFX的文件,其实这种
文件即可执行文件(不久你改一下名便知)。应用程序所要做的事情就是向这些已经
准备好的可执行文件插入数据即可。
其实我也很想了解这种技术,如果你以后知道了应该怎么做不要忘记告诉我一下。
 
它的原理很简单,就是预先准备好一个文件,然后要求你输入一些信息,并将这些信
息加入到文件中适当的位置,并将它改为exe文件,但是说起来容易做起来难,我也只
是理解它的原理,不知道实际怎么操作。^_^
 
我有一个笨办法:
比如,你有一个b.exe,它的作用是输出一个字符串string.
设计时将string定义为200个空格.
那么,a.exe就可以让b.exe输出"Hello",你要做的就是
将b.exe的string替换为"Hello".
当然,你还有很多其他的事情要做,比如b.exe里面还需要
一个去掉string末尾多余的空格的过程,等等.
不过,思路已经有了,最困难的时刻也就过去了.
还有问题,可以来信慢慢探讨: mophy@188.net
 
替换资源的确比较简单,但东西一多就不行了,zycjf,你看一下在你说的贺卡
软件生成一个EXE文件后,没有在临时目录下生成文件,比如*。EXE等。如果
生成了,那实现方法跟我想的一样。
 
是那个EXE文件在运行时,有没有在临时目录下生成EXE文件。
 
用动态链接库的方法也可以
 
呵呵,虽然exe出不来了,但这方法也妙得很,我试试吧!
 
关注
txt文件建立
 
西西,很久没有来骗分了,原理其实很简单的,这里正好有个外国人写自执行文件的设计文件+范例,大家看看吧!

> Does anyone know how you can calcualate the real size of an EXE file so you
> know where the position in the EXE file is where there's an external data
> file attatched.
>
> e.g. a file create by
> COPY /B TEST.EXE + TEST.DTA PROG.EXE
>
> I can do it in plain old Dos but i cant get i to work in Delphi.

You can't. Windows binaries have all sorts of things in them
that it is difficult to pinpoint exactly where the binary ends from
the information in the header. PE (Win32) binaries are even worse
than NE (Win16) binaries in this respect.

My advice is join the data to the EXE via source code, and
then to write a little header to the end of the joined file which
contains offsets to the beginning and end of the data.

e.g.,
1. create a record;
Var MyRec = Record
Signature : String[4];
ExeSize,
DataSize: Longint;
end;

2. open your EXE file and your data file

3. fill the record;
With MyRec do begin
Signature := #4#3#3#5; {a unique signature}
ExeSize := FileSize(MyExeFile);
DataSize := FileSize(MyDataFile);
end;

4. create destination file
5. copy EXE file into it (using BlockRead/BlockWrite)
6. then copy data file into it (--ditto--)
7. then write the record to it (using BlockWrite)
8. close all files

When you want to read the data, all you need to do is
to;
1. open the file
2. Seek(MyFile, FileSize(MyFile)-Sizeof(MyRec))
3. BlockRead(MyFile, MyRec, Sizeof(MyRec))
4. do checks -
- If Ioresult = 0
- and MyRec.Signature = #4#3#3#5
- and MyRec.ExeSize > 0
- and MyRec.DataSize > 0
then - everything is okay
- so
- Seek(MyFile, MyRec.ExeSize)
- read your data, until MyRec.DataSize,
etc, etc.

All this may look tedious and involved - but believe me,
it is *far* less tedious than trying to walk through the
PE header.
 
举个例子,winzip的zip文件生成自解压文件(exe)
exe文件的模板已经有了,里面有个数据段叫_winzip_
生成exe文件时将整个zip文件加进来,再改文件头,将_winzip_指向
加进来的zip文件的数据。
而可执行代码部分是早做好了的,就是将_winzip_段的数据读出来解压而已。

这需要了解可执行文件的格式。
 
我觉得我的办法不错呀.
那,Pipi,你就说说可执行文件的格式吧!
(何必搞的那么麻烦嘛.)
 
后退
顶部