各位高手请发标。。。本人向您请教了!关于文件读取!!!(有源代码)(200分)

  • 主题发起人 主题发起人 sforever
  • 开始时间 开始时间
S

sforever

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个程序,把30条信息写入某个EXE文件尾部,然后再读出来!!!下面是原代码,但是程序在操作时,老出现问题
可以把30条信息写入,但是读取的时候却出现问题!!!大家帮忙看看,给你高分!!
unit Mail;

interface

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

type
TForm1 = class(TForm)
exe1: TEdit;
exe2: TEdit;
exe3: TEdit;
exe4: TEdit;
exe5: TEdit;
server1: TEdit;
server2: TEdit;
server3: TEdit;
server4: TEdit;
server5: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
exe6: TEdit;
Label12: TLabel;
server6: TEdit;
edit: TEdit;
Button1: TButton;
Button2: TButton;
Label13: TLabel;
Label14: TLabel;
exe7: TEdit;
Label15: TLabel;
Label16: TLabel;
server7: TEdit;
Label17: TLabel;
exe8: TEdit;
server8: TEdit;
Label18: TLabel;
exe9: TEdit;
server9: TEdit;
exe10: TEdit;
server10: TEdit;
Label19: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
SkinData1: TSkinData;
exe11: TEdit;
Label23: TLabel;
Label24: TLabel;
exe12: TEdit;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label30: TLabel;
Label31: TLabel;
Label32: TLabel;
exe13: TEdit;
exe14: TEdit;
exe15: TEdit;
exe16: TEdit;
exe17: TEdit;
exe18: TEdit;
exe19: TEdit;
exe20: TEdit;
OpenDialog1: TOpenDialog;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

////////////
procedure TForm1.Button1Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
edit.Text :=Opendialog1.FileName;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
f:File;
str:array [1..120] of char;
Each_size:array [1..50] of char;
i :integer;
S:String;
procedure setfile;
var I:integer;
begin
AssignFile(f,edit.Text );//打开文件
Reset(f,1);
Seek(f,filesize(f));//用SEEK把指针调到文件尾

for i:=1 to 120 do str:=char(0); {初始化Str}
S:=exe1.Text;
for i:=1 to length(s) do str:=S;
BlockWrite(f,str,length(s));{往文件里写配置信息}
Each_size[1]:=char(length(s)); {得到写入的字节数,好让服务程序正确读出}

for i:=1 to 120 do str:=char(0);
S:=exe2.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[2]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe3.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[3]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe4.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[4]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe5.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[5]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe6.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[6]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe7.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[7]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe8.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[8]:=char(length(s));


for i:=1 to 120 do str:=char(0);
S:=exe9.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[9]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe10.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[10]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe11.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[11]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe12.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[12]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe13.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[13]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe14.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[14]:=char(length(s));


for i:=1 to 120 do str:=char(0);
S:=exe15.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[15]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe16.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[16]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe17.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[17]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe18.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[18]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe19.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[19]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=exe20.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[20]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server1.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[21]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server2.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[22]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server3.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[23]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server4.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[24]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server5.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[25]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server6.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[26]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server7.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[27]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server8.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[28]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server9.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[29]:=char(length(s));

for i:=1 to 120 do str:=char(0);
S:=server10.Text ;
For i:=1 to length(s) do str:=S;
Blockwrite(f,str,length(s));
Each_size[30]:=char(length(s));


blockwrite(f,Each_size,30);

CloseFile(f);
end;
begin
if not FileExists(edit.Text) then
begin
Application.MessageBox('您配置的文件不存在!','提示!',mb_ok+mb_iconinformation);
exit;
end;
if Application.MessageBox('您是否采用该配置?','提示!',mb_okcancel+MB_ICONQUESTION)=idok then
begin
setfile;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
f:File;
str:array [1..120] of char;
Each_size:array [1..50] of char;
len,i :integer;
Setstr:String;
begin
AssignFile(f,edit.Text );//关联文件
Reset(f,1);//打开文件
Seek(f,filesize(f)-30);//将指针移到倒数第三个字节,后面两个字节记录了两个配置的长度
BlockRead(f,Each_size,30);
len:=0;
for i:=1 to 30 do len:=len+ord(each_size); //算出总长度 len
seek(f,filesize(f)-30-len); //将指针移到信息开始处
for i:=1 to 120 do str:=' ';
blockread(f,str,len); //读取所有信息,总长度为 len
setstr:=trim(str); //字符串 setstr 为所有信息
exe1.Text:= copy(setstr,1,ord(each_size[1])); //分割字符串 setstr,得到配置信息

i:=ord(each_size[1])+1;

exe2.Text:= copy(setstr,i,ord(each_size[2]));

i:=ord(each_size[1])+2;

exe3.Text:= copy(setstr,i,ord(each_size[3]));

i:=ord(each_size[1])+3;

exe4.Text:= copy(setstr,i,ord(each_size[4]));

i:=ord(each_size[1])+4;

exe5.Text:= copy(setstr,i,ord(each_size[5]));

i:=ord(each_size[1])+5;

exe6.Text:= copy(setstr,i,ord(each_size[6]));

i:=ord(each_size[1])+6;

exe7.Text:= copy(setstr,i,ord(each_size[7]));

i:=ord(each_size[1])+7;

exe8.Text:= copy(setstr,i,ord(each_size[8]));

i:=ord(each_size[1])+8;

exe9.Text:= copy(setstr,i,ord(each_size[9]));

i:=ord(each_size[1])+9;

exe10.Text:= copy(setstr,i,ord(each_size[10]));

i:=ord(each_size[1])+10;

exe11.Text:= copy(setstr,i,ord(each_size[11]));

i:=ord(each_size[1])+11;

exe12.Text:= copy(setstr,i,ord(each_size[12]));

i:=ord(each_size[1])+12;

exe13.Text:= copy(setstr,i,ord(each_size[13]));

i:=ord(each_size[1])+13;

exe14.Text:= copy(setstr,i,ord(each_size[14]));

i:=ord(each_size[1])+14;

exe15.Text:= copy(setstr,i,ord(each_size[15]));

i:=ord(each_size[1])+15;

exe16.Text:= copy(setstr,i,ord(each_size[16]));

i:=ord(each_size[1])+16;

exe17.Text:= copy(setstr,i,ord(each_size[17]));

i:=ord(each_size[1])+17;

exe18.Text:= copy(setstr,i,ord(each_size[18]));

i:=ord(each_size[1])+18;

exe19.Text:= copy(setstr,i,ord(each_size[19]));

i:=ord(each_size[1])+19;

exe20.Text:= copy(setstr,i,ord(each_size[20]));

i:=ord(each_size[1])+20;

server1.Text:= copy(setstr,i,ord(each_size[21]));

i:=ord(each_size[1])+21;

server2.Text:= copy(setstr,i,ord(each_size[22]));

i:=ord(each_size[1])+22;

server3.Text:= copy(setstr,i,ord(each_size[23]));

i:=ord(each_size[1])+23;

server4.Text:= copy(setstr,i,ord(each_size[24]));

i:=ord(each_size[1])+24;

server5.Text:= copy(setstr,i,ord(each_size[25]));

i:=ord(each_size[1])+25;

server6.Text:= copy(setstr,i,ord(each_size[26]));

i:=ord(each_size[1])+26;

server7.Text:= copy(setstr,i,ord(each_size[27]));

i:=ord(each_size[1])+27;

server8.Text:= copy(setstr,i,ord(each_size[28]));

i:=ord(each_size[1])+28;

server9.Text:= copy(setstr,i,ord(each_size[29]));

i:=ord(each_size[1])+29;

server10.Text:= copy(setstr,i,ord(each_size[30]));


Closefile(f);
end;

end.
 
难道没有人会吗??
 
提示什么错误?
 
想做木马还是咋的?
现在木马都用远程线程了

exe文件是PE格式的,你随便写些东西在里边不行吧
你看看PE文件的格式就知道了
你要写东西到Exe中,难!
研究一下PE文件吧
 
re:JamesBond_L

不提示错误,只是写入的东西跟读出的东西不匹配。从第三个EDIT中就出现错误!!
 
当然不对了,起始位置不对嘛,应该依次为:
1
ord(each_size[1])+1
ord(each_size[1])+ord(each_size[2])+1
...
 
多人接受答案了。
 

Similar threads

后退
顶部