如何读取和修改一个EXE文件中某地址的数据!? ( 积分: 300 )

  • 主题发起人 主题发起人 高手贵姓
  • 开始时间 开始时间

高手贵姓

Unregistered / Unconfirmed
GUEST, unregistred user!
例如打开一个名为1.exe文件,读取其中00089AC9这个地址的数据,假设是17,16进制转换为10进制后结果是23(10进制),这个结果要能显示出来。对于显示的结果可以修改比如改为25(10进制),那么修改后写入00089AC9这个地址为19(16进制),并能保存修改。我想知道如何用程序实现!?
 
内存修改器的代码<br>unit&nbsp;Unit2;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;StdCtrls,&nbsp;ExtCtrls,&nbsp;Tlhelp32,&nbsp;ComCtrls;<br><br>type<br>&nbsp;&nbsp;pint=^integer;<br>&nbsp;&nbsp;TForm1&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;GroupBox1:&nbsp;TGroupBox;<br>&nbsp;&nbsp;&nbsp;&nbsp;ListView1:&nbsp;TListView;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button3:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;Panel1:&nbsp;TPanel;<br>&nbsp;&nbsp;&nbsp;&nbsp;Label2:&nbsp;TLabel;<br>&nbsp;&nbsp;&nbsp;&nbsp;Label3:&nbsp;TLabel;<br>&nbsp;&nbsp;&nbsp;&nbsp;Edit1:&nbsp;TEdit;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button1:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;Edit2:&nbsp;TEdit;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button2:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;Edit3:&nbsp;TEdit;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button4:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;Label6:&nbsp;TLabel;<br>&nbsp;&nbsp;&nbsp;&nbsp;Label7:&nbsp;TLabel;<br>&nbsp;&nbsp;&nbsp;&nbsp;Edit4:&nbsp;TEdit;<br>&nbsp;&nbsp;&nbsp;&nbsp;GroupBox2:&nbsp;TGroupBox;<br>&nbsp;&nbsp;&nbsp;&nbsp;ListBox1:&nbsp;TListBox;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button5:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;Label1:&nbsp;TLabel;<br>&nbsp;&nbsp;&nbsp;&nbsp;sb1:&nbsp;TStatusBar;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;FormCreate(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button1Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Edit1KeyPress(Sender:&nbsp;TObject;&nbsp;var&nbsp;Key:&nbsp;Char);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Edit4KeyPress(Sender:&nbsp;TObject;&nbsp;var&nbsp;Key:&nbsp;Char);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button2Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button4Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button3Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;ListView1SelectItem(Sender:&nbsp;TObject;&nbsp;Item:&nbsp;TListItem;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Selected:&nbsp;Boolean);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button5Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;ListBox1Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;end;<br><br>const&nbsp;bSize=1024;<br>var<br>&nbsp;&nbsp;Form1:&nbsp;TForm1;<br>&nbsp;&nbsp;pc,pcbak:integer;//相符地址数组尾指针,//多次查找时做前者备份<br>&nbsp;&nbsp;found:array[1..65535]&nbsp;of&nbsp;pointer;//相符地址数组<br>&nbsp;&nbsp;fBak&nbsp;:array[1..65535]&nbsp;of&nbsp;pointer;//多次查找时做上述备份<br><br>&nbsp;&nbsp;first:boolean;&nbsp;//是否第一次查找?<br>&nbsp;&nbsp;sysinfo:SYSTEM_INFO;<br>&nbsp;&nbsp;hProc:dword;<br>implementation<br><br>{$R&nbsp;*.dfm}<br><br>procedure&nbsp;GetProc();<br>var<br>&nbsp;&nbsp;sProc:PROCESSENTRY32;<br>&nbsp;&nbsp;hSnap:dword;<br>&nbsp;&nbsp;ok:bool;<br>begin<br>&nbsp;&nbsp;Form1.ListView1.Clear;<br>&nbsp;&nbsp;sProc.dwSize:=SizeOf(sProc);<br>&nbsp;&nbsp;hSnap:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp;&nbsp;ok:=Process32First(hSnap,sProc);<br>&nbsp;&nbsp;While&nbsp;ok&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;With&nbsp;Form1.ListView1.Items.Add&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Caption:=sProc.szExeFile;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SubItems.Add(IntToHex(sproc.th32ProcessID,0));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ok:=Process32Next(hSnap,sProc);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;CloseHandle(hSnap);<br>&nbsp;&nbsp;if&nbsp;Form1.ListView1.Items.Count&lt;&gt;0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;Form1.ListView1.Items.Item[0].Selected:=true;<br>end;<br><br>{//在4k内存中查找符合指定数值的内存单元地址,返回值说明读入内存块是否成功<br>function&nbsp;FindMemBlock(PH:Thandle;add:pointer;v:integer):boolean;<br>var&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//进程句柄,起始地址,需要查找的数值<br>&nbsp;&nbsp;i,t:integer;//计数器<br>&nbsp;&nbsp;Buffer:array[1..bSize]&nbsp;of&nbsp;byte;//用来装4KB的内存块<br>&nbsp;&nbsp;ok:boolean;//装入内存块是否成功<br>&nbsp;&nbsp;LPDW:DWORD;<br>begin<br>&nbsp;&nbsp;ok:=ReadProcessMemory(PH,add,pointer(@(buffer[1])),bSize,Lpdw);<br>&nbsp;&nbsp;if&nbsp;ok&nbsp;then&nbsp;//读取成功&nbsp;^_^<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i:=1&nbsp;to&nbsp;bSize&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t:=(pint(@(buffer)))^;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;t=V&nbsp;then//找到<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pc:=pc+1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found[pc]:=pointer(dword(add)+i-1);&nbsp;&nbsp;&nbsp;//保存地址<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;result:=true;<br>&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;else&nbsp;//读取失败&nbsp;:(<br>&nbsp;&nbsp;&nbsp;begin<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showmessage(inttohex(dword(add)+i-1,0));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result:=false;<br>&nbsp;&nbsp;&nbsp;end;<br>end;}<br><br>function&nbsp;FindMemBlock(PH:Thandle;add:pointer;v:integer):boolean;<br>var&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//进程句柄,起始地址,需要查找的数值<br>&nbsp;&nbsp;i:integer;//计数器<br>&nbsp;&nbsp;Buffer:array[1..bSize]&nbsp;of&nbsp;byte;//用来装4KB的内存块<br>&nbsp;&nbsp;p:&nbsp;PInteger;&nbsp;//&nbsp;(beta)<br>&nbsp;&nbsp;ok:boolean;//装入内存块是否成功<br>&nbsp;&nbsp;LPDW:DWORD;<br>begin<br>&nbsp;&nbsp;ok:=ReadProcessMemory(PH,add,pointer(@(buffer[1])),bSize,Lpdw);<br>&nbsp;&nbsp;if&nbsp;ok&nbsp;then&nbsp;//读取成功&nbsp;^_^<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;:=&nbsp;@Buffer[1];&nbsp;//&nbsp;(beta)<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i:=&nbsp;1&nbsp;to&nbsp;bSize&nbsp;div&nbsp;4&nbsp;do&nbsp;//&nbsp;每次递增&nbsp;4&nbsp;个字节,可以少找很多次(beta)<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;p^&nbsp;=&nbsp;V&nbsp;then//找到<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pc:=pc+1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found[pc]:=&nbsp;Pointer(Integer(p)&nbsp;-&nbsp;Integer(@Buffer[1])&nbsp;+&nbsp;Integer(add));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Inc(p);&nbsp;//&nbsp;每次递增&nbsp;4&nbsp;个字节,因为变量几乎肯定是&nbsp;4&nbsp;字节对齐的(beta)<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;result:=true;<br>&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;else&nbsp;//读取失败&nbsp;:(<br>&nbsp;&nbsp;&nbsp;begin<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showmessage(inttohex(dword(add)+i-1,0));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result:=false;<br>&nbsp;&nbsp;&nbsp;end;<br>end;<br><br>//将V写到指定进程指定位置,返回值代表写入是否成功<br>function&nbsp;writeMemory(PH:Thandle;Add:pointer;V:integer):boolean;<br>var<br>&nbsp;&nbsp;ok:boolean;<br>&nbsp;&nbsp;LPDW:DWORD;<br>begin<br>&nbsp;&nbsp;ok:=WriteProcessMemory(PH,Add,pointer(@V),4,LPDW);<br>&nbsp;&nbsp;if&nbsp;ok&nbsp;then&nbsp;Result:=True<br>&nbsp;&nbsp;else&nbsp;Result:=False;<br>end;<br>//取得指定进程指定位置处数值<br>function&nbsp;getAddressV(PH:Thandle;Add:pointer;var&nbsp;V:integer):boolean;<br>var<br>&nbsp;&nbsp;ok:boolean;<br>&nbsp;&nbsp;LPDW:DWORD;<br>begin<br>&nbsp;&nbsp;ok:=readProcessMemory(PH,add,pointer(@V),4,LPDW);<br>&nbsp;&nbsp;if&nbsp;ok&nbsp;then&nbsp;Result:=True<br>&nbsp;&nbsp;else&nbsp;Result:=False;<br>end;<br><br>procedure&nbsp;showlist();<br>var<br>&nbsp;&nbsp;i:Integer;<br>begin<br>&nbsp;&nbsp;Form1.ListBox1.Clear;<br>&nbsp;&nbsp;for&nbsp;i:=1&nbsp;to&nbsp;pc&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;Form1.ListBox1.Items.Add(IntTohex(DWORD(found),8));<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;if&nbsp;Form1.ListBox1.Count&lt;&gt;0&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;form1.Label1.Caption:=inttostr(form1.listbox1.Count);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form1.ListBox1.Selected[0]:=true;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form1.edit2.Text:='0x'+Form1.Listbox1.Items.Strings[0];<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;form1.Label1.Caption:='';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form1.edit2.Text:='';<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>end;<br><br>procedure&nbsp;TForm1.Button1Click(Sender:TObject);<br>var<br>i,test,V:integer;<br>j,e:Dword;<br><br>begin<br>&nbsp;&nbsp;&nbsp;//只是简单考虑非法输入啊!!请不要输入太大的数值!!!<br>&nbsp;&nbsp;if&nbsp;edit1.Text=''&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;showmessage('不可为空!');<br>&nbsp;&nbsp;&nbsp;&nbsp;exit;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;if&nbsp;edit3.Text=''&nbsp;then&nbsp;exit;<br>&nbsp;&nbsp;&nbsp;&nbsp;hProc:=OpenProcess(PROCESS_ALL_ACCESS,false,strtoint(edit3.text));<br><br>//&nbsp;&nbsp;GetSystemInfo(sysinfo);<br><br>&nbsp;&nbsp;V:=StrToInt(Edit1.Text);<br>&nbsp;&nbsp;if&nbsp;first&nbsp;then&nbsp;//是第一次查找<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;pc:=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;first:=false;<br>//查找从4M至2G的地址空间<br>&nbsp;&nbsp;//for&nbsp;i:=4M&nbsp;to&nbsp;2G&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;j:=4*1024*1024;<br>&nbsp;&nbsp;&nbsp;&nbsp;{e:=2*1024*1024;<br>&nbsp;&nbsp;&nbsp;&nbsp;e:=e*1024;}<br>&nbsp;&nbsp;&nbsp;&nbsp;e:=6*1024*1024;&nbsp;//&nbsp;不要找得太远,一个&nbsp;exe&nbsp;能映射多大?(beta)<br>//&nbsp;&nbsp;&nbsp;&nbsp;j:=dword(sysinfo.lpMinimumApplicationAddress);<br>//&nbsp;&nbsp;&nbsp;&nbsp;e:=dword(sysinfo.lpMaximumApplicationAddress);<br>&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;true&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;j&gt;e&nbsp;then&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;FindMemBlock(hProc,pointer(j),V)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb1.SimpleText:='读入成功'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sb1.SimpleText:='读入失败';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j:=j+bSize;&nbsp;&nbsp;//下一个4KB<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end<br>&nbsp;&nbsp;else&nbsp;&nbsp;&nbsp;//第n次查找<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;//先备份<br>&nbsp;&nbsp;&nbsp;&nbsp;pcbak:=pc;<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i:=1&nbsp;to&nbsp;pc&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fBak:=found;<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;//再比较<br>&nbsp;&nbsp;&nbsp;&nbsp;pc:=0;<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;i:=1&nbsp;to&nbsp;pcbak&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;GetAddressV(hProc,fBak,Test)&nbsp;then&nbsp;//读取成功<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;test=V&nbsp;then&nbsp;//相符<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pc:=pc+1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;found[pc]:=fBak;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;showlist();//显示地址列表到listBox1中<br><br>end;<br><br>procedure&nbsp;TForm1.Button2Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//只是简单考虑非法输入啊!!请不要输入太大的数值!!!<br>&nbsp;&nbsp;if&nbsp;edit4.Text=''&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;showmessage('不可为空!');<br>&nbsp;&nbsp;&nbsp;&nbsp;exit;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;if&nbsp;edit2.text=''&nbsp;then&nbsp;exit;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;MessageDlg('真的修改?',MtWarning,MbOKCancel,0)=MrCancel&nbsp;then&nbsp;exit;<br>&nbsp;&nbsp;if&nbsp;WriteMemory(hProc,pointer(strtoint(edit2.text)),strtoint(Edit4.Text))<br>&nbsp;&nbsp;then&nbsp;&nbsp;sb1.SimpleText:='修改成功!'<br>&nbsp;&nbsp;else&nbsp;&nbsp;sb1.SimpleText:='修改失败!';<br>end;<br><br>procedure&nbsp;TForm1.Edit1KeyPress(Sender:&nbsp;TObject;&nbsp;var&nbsp;Key:&nbsp;Char);<br>begin<br>if&nbsp;(key&gt;'9')or(key&lt;'0')&nbsp;then&nbsp;key:=#0;<br>end;<br>procedure&nbsp;TForm1.Edit4KeyPress(Sender:&nbsp;TObject;&nbsp;var&nbsp;Key:&nbsp;Char);<br>begin<br>&nbsp;&nbsp;if&nbsp;(key&gt;'9')or(key&lt;'0')&nbsp;then&nbsp;key:=#0;<br>end;<br>procedure&nbsp;TForm1.FormCreate(Sender:TObject);<br>begin<br>first:=true;<br>GetProc;<br>end;<br>procedure&nbsp;TForm1.Button4Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;first:=true;<br>end;<br><br>procedure&nbsp;TForm1.Button3Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;GetProc;<br>end;<br><br>procedure&nbsp;TForm1.ListView1SelectItem(Sender:&nbsp;TObject;&nbsp;Item:&nbsp;TListItem;<br>&nbsp;&nbsp;Selected:&nbsp;Boolean);<br>begin<br>&nbsp;&nbsp;Edit3.Text:='0x'+Item.SubItems.Strings[0];<br>end;<br><br>procedure&nbsp;TForm1.Button5Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;close;<br>end;<br><br>procedure&nbsp;TForm1.ListBox1Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;edit2.Text:='0x'+Listbox1.Items.Strings[listbox1.itemindex];<br>end;<br><br>end.
 
var&nbsp;<br>&nbsp;&nbsp;fs:&nbsp;TFileStream;<br>begin<br>&nbsp;&nbsp;fs&nbsp;:=&nbsp;TFileStream.create('......./1.exe');<br>&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;fs.position&nbsp;:=&nbsp;$00089AC9;<br>&nbsp;&nbsp;&nbsp;&nbsp;fs.readbuffer();&nbsp;//读<br>&nbsp;&nbsp;&nbsp;&nbsp;fs.writebuffer();//写<br>&nbsp;&nbsp;finally<br>&nbsp;&nbsp;&nbsp;&nbsp;fs.free;<br>&nbsp;&nbsp;end;<br>end;
 
有没有可用的函数!?
 
procedure&nbsp;TForm1.Button1Click(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;&nbsp;&nbsp;fs:&nbsp;TFileStream;<br>&nbsp;&nbsp;&nbsp;&nbsp;filename:String;<br>&nbsp;&nbsp;&nbsp;&nbsp;str:String;&nbsp;<br>begin<br>&nbsp;&nbsp;&nbsp;&nbsp;OpenDialog1.Execute&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;filename:=OpenDialog1.FileName&nbsp;;<br>&nbsp;&nbsp;&nbsp;&nbsp;fs:=TfileStream.Create(filename,fmopenread);<br>&nbsp;&nbsp;&nbsp;&nbsp;str:='';<br>&nbsp;&nbsp;&nbsp;&nbsp;str:=str+IntToHex(dword($0008F8FC));<br>&nbsp;&nbsp;&nbsp;&nbsp;showmessage(IntToStr(Str));<br>end;<br><br>请问我的代码为什么不对!?
 
给分:chgit('1.exe');<br>procedure&nbsp;chgit(fn:&nbsp;string);<br>var<br>&nbsp;&nbsp;Dest,&nbsp;Source:&nbsp;file;<br>&nbsp;&nbsp;TNCD:&nbsp;array[0..1]&nbsp;of&nbsp;byte;<br>&nbsp;&nbsp;Buffer:&nbsp;array[0..563911]&nbsp;of&nbsp;byte;<br>&nbsp;&nbsp;Read:&nbsp;integer;<br>&nbsp;&nbsp;tfn:&nbsp;string;<br>begin<br>&nbsp;&nbsp;tfn&nbsp;:=&nbsp;changefileext(fn,&nbsp;'.tmp');<br>&nbsp;&nbsp;AssignFile(Dest,&nbsp;tfn);<br>&nbsp;&nbsp;AssignFile(Source,&nbsp;fn);<br>&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;Rewrite(Dest,&nbsp;1);<br>&nbsp;&nbsp;&nbsp;&nbsp;Reset(Source,&nbsp;1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//FillChar(HashDigest,&nbsp;4,&nbsp;$FF);<br>&nbsp;&nbsp;&nbsp;&nbsp;//FillChar(TNCD,&nbsp;8,&nbsp;$0512);<br>&nbsp;&nbsp;&nbsp;&nbsp;TNCD[0]&nbsp;:=&nbsp;$05;<br>&nbsp;&nbsp;&nbsp;&nbsp;TNCD[1]&nbsp;:=&nbsp;$14;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;BlockRead(Source,&nbsp;Buffer,&nbsp;$89AC8,&nbsp;Read);&nbsp;//$448<br>&nbsp;&nbsp;&nbsp;&nbsp;BlockWrite(Dest,&nbsp;Buffer,&nbsp;Read);<br>&nbsp;&nbsp;&nbsp;&nbsp;BlockRead(Source,&nbsp;Buffer,&nbsp;2,&nbsp;Read);<br>&nbsp;&nbsp;&nbsp;&nbsp;showmessage(Format('%x&nbsp;%x',[Buffer[0],Buffer[1]]));<br>&nbsp;&nbsp;&nbsp;&nbsp;blockwrite(dest,&nbsp;TNCD[0],&nbsp;sizeof(TNCD));<br>&nbsp;&nbsp;&nbsp;&nbsp;repeat<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockRead(Source,&nbsp;Buffer,&nbsp;Sizeof(Buffer),&nbsp;Read);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockWrite(Dest,&nbsp;Buffer,&nbsp;Read);<br>&nbsp;&nbsp;&nbsp;&nbsp;until&nbsp;Read&nbsp;&lt;&gt;&nbsp;Sizeof(Buffer);<br>&nbsp;&nbsp;&nbsp;&nbsp;CloseFile(Source);<br>&nbsp;&nbsp;&nbsp;&nbsp;CloseFile(Dest);<br>&nbsp;&nbsp;&nbsp;&nbsp;DeleteFile(pchar(fn));<br>&nbsp;&nbsp;&nbsp;&nbsp;RenameFile(tfn,&nbsp;fn);<br>&nbsp;&nbsp;except<br>&nbsp;&nbsp;&nbsp;&nbsp;MessageDlg('无法打开输出文件!',&nbsp;mtInformation,&nbsp;[mbOK],&nbsp;0);<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit;<br>&nbsp;&nbsp;end;<br>end;
 
楼上的大哥,这个不对啊,这一个只读一个地址的,能不能帮我写一个通用的函数!
 
unit&nbsp;Unit1;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;StdCtrls,&nbsp;Math;<br><br>type<br>&nbsp;&nbsp;TForm1&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;OpenDialog1:&nbsp;TOpenDialog;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button5:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;Label1:&nbsp;TLabel;<br>&nbsp;&nbsp;&nbsp;&nbsp;Edit1:&nbsp;TEdit;<br>&nbsp;&nbsp;&nbsp;&nbsp;Button6:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;edt1:&nbsp;TEdit;<br>&nbsp;&nbsp;&nbsp;&nbsp;edt2:&nbsp;TEdit;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button5Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button6Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;end;<br><br>var<br>&nbsp;&nbsp;Form1:&nbsp;TForm1;<br><br>implementation<br><br>{$R&nbsp;*.dfm}<br><br>function&nbsp;ReadHex(fn:&nbsp;string;&nbsp;Pos:&nbsp;Integer):&nbsp;string;<br>var<br>&nbsp;&nbsp;Source:&nbsp;file;<br>&nbsp;&nbsp;Buffer:&nbsp;array[0..1]&nbsp;of&nbsp;byte;<br>&nbsp;&nbsp;Buffer0:&nbsp;PChar;<br>&nbsp;&nbsp;Read:&nbsp;integer;<br>begin<br>&nbsp;&nbsp;AssignFile(Source,&nbsp;fn);<br>&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;Reset(Source,&nbsp;1);<br>&nbsp;&nbsp;&nbsp;&nbsp;GetMem(Buffer0,&nbsp;pos);<br>&nbsp;&nbsp;&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//BlockRead(Source,&nbsp;Buffer0^,&nbsp;Pos);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockRead(Source,&nbsp;Buffer,&nbsp;2,&nbsp;Read);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result&nbsp;:=&nbsp;Format('%.2x&nbsp;%.2x',&nbsp;[Buffer[0],&nbsp;Buffer[1]]);<br>&nbsp;&nbsp;&nbsp;&nbsp;finally<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FreeMem(Buffer0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CloseFile(Source);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;except<br>&nbsp;&nbsp;&nbsp;&nbsp;MessageDlg('无法打开输出文件!',&nbsp;mtInformation,&nbsp;[mbOK],&nbsp;0);<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit;<br>&nbsp;&nbsp;end;<br>end;<br><br>function&nbsp;Hex2Dec(Value:&nbsp;string):&nbsp;integer;<br>var<br>&nbsp;&nbsp;c:&nbsp;char;<br>&nbsp;&nbsp;nIndex,&nbsp;nLength:&nbsp;integer;<br>begin<br>&nbsp;&nbsp;Result&nbsp;:=&nbsp;0;<br>&nbsp;&nbsp;nLength&nbsp;:=&nbsp;Length(Value);<br>&nbsp;&nbsp;for&nbsp;nIndex&nbsp;:=&nbsp;0&nbsp;to&nbsp;nLength&nbsp;-&nbsp;1&nbsp;do<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;:=&nbsp;Value[nLength&nbsp;-&nbsp;nIndex];<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((c&nbsp;&gt;=&nbsp;'A')&nbsp;and&nbsp;(c&nbsp;&lt;=&nbsp;'F'))&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inc(Result,&nbsp;(ord(c)&nbsp;-&nbsp;55)&nbsp;*&nbsp;Trunc(Power(16,&nbsp;nIndex)))<br>&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;if&nbsp;((c&nbsp;&gt;=&nbsp;'0')&nbsp;and&nbsp;(c&nbsp;&lt;=&nbsp;'9'))&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inc(Result,&nbsp;(ord(c)&nbsp;-&nbsp;48)&nbsp;*&nbsp;Trunc(Power(16,&nbsp;nIndex)));<br>&nbsp;&nbsp;end;<br>end;<br><br>procedure&nbsp;SetHex(FileName:&nbsp;string;&nbsp;StartPos:&nbsp;Integer;&nbsp;hex1,&nbsp;hex2:&nbsp;string);<br>var<br>&nbsp;&nbsp;Ori:&nbsp;TFileStream;<br>&nbsp;&nbsp;Tmp:&nbsp;TMemoryStream;<br>&nbsp;&nbsp;TempFile:&nbsp;string;<br>&nbsp;&nbsp;EndPos:&nbsp;Integer;<br>&nbsp;&nbsp;swap_char:&nbsp;char;<br>begin<br>&nbsp;&nbsp;EndPos&nbsp;:=&nbsp;StartPos&nbsp;+&nbsp;2;<br>&nbsp;&nbsp;Ori&nbsp;:=&nbsp;TFileStream.Create(FileName,&nbsp;fmOpenRead);<br>&nbsp;&nbsp;Tmp&nbsp;:=&nbsp;TMemoryStream.Create;<br>&nbsp;&nbsp;if&nbsp;(StartPos&nbsp;&lt;&gt;&nbsp;0)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;Tmp.CopyFrom(Ori,&nbsp;StartPos);<br><br>&nbsp;&nbsp;swap_char&nbsp;:=&nbsp;Char(Hex2Dec(hex1));<br>&nbsp;&nbsp;Tmp.WriteBuffer(swap_char,&nbsp;sizeof(swap_char));<br>&nbsp;&nbsp;swap_char&nbsp;:=&nbsp;Char(Hex2Dec(hex2));<br>&nbsp;&nbsp;Tmp.WriteBuffer(swap_char,&nbsp;sizeof(swap_char));<br><br>&nbsp;&nbsp;Ori.Seek(EndPos,&nbsp;soFromBeginning);<br>&nbsp;&nbsp;Tmp.CopyFrom(Ori,&nbsp;Ori.Size&nbsp;-&nbsp;EndPos);<br><br>&nbsp;&nbsp;TempFile&nbsp;:=&nbsp;ExtractFilePath(FileName)&nbsp;+&nbsp;'cxz.txt';<br>&nbsp;&nbsp;Tmp.SaveToFile(tempfile);<br>&nbsp;&nbsp;FreeAndNil(Ori);<br>&nbsp;&nbsp;FreeAndNil(Tmp);<br>&nbsp;&nbsp;DeleteFile(pchar(FileName));<br>&nbsp;&nbsp;RenameFile(TempFile,&nbsp;FileName);<br>end;<br><br>procedure&nbsp;TForm1.Button5Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;//&nbsp;showmessage(inttostr(Hex2Dec(Edit1.Text)));<br>&nbsp;&nbsp;Label1.Caption&nbsp;:=&nbsp;ReadHex('1.exe',&nbsp;Hex2Dec(Edit1.Text));<br>end;<br><br>procedure&nbsp;TForm1.Button6Click(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;//SetHex('1.exe',&nbsp;Hex2Dec(Edit1.Text),&nbsp;5,&nbsp;12);<br>&nbsp;&nbsp;SetHex('1.exe',&nbsp;Hex2Dec(Edit1.Text),edt1.Text,&nbsp;edt2.Text);<br>end;<br><br>end.
 
fs:=TfileStream.Create(filename,fmopenread);<br>//你没有读取啊,应该使用readbuffer读,如果要写,可以使用fmopenwrite或fmopenreadwrite模式打开文件,再用writebuffer写&nbsp;&nbsp;&nbsp;&nbsp;<br>{str:='';<br>str:=str+IntToHex(dword($0008F8FC));<br>showmessage(IntToStr(Str));<br>}
 
你想做外挂
 
请问&nbsp;fs.readbuffer();&nbsp;这段代码应该怎么写呢?
 
晕死&nbsp;偶发的代码不行吗?偶可是花了好多时间写的呢.
 
楼主又蠢又懒,给了这么多的代码都不肯花心思研究一下。。。
 
cxz9&nbsp;大哥,你的方法我还在测试中,不过看起来就觉得很好啊!非常谢谢你!<br>但是你这个是读取连续二个地址的吧?&nbsp;我还想要一个读取一个地址的!
 
晕&nbsp;那你改成两个啊<br>Buffer:&nbsp;array[0..1]&nbsp;of&nbsp;byte;<br>-&gt;<br>Buffer00,Buffer01:Char;
 
cxz9&nbsp;大哥,我用你的代码发现只能读取exe文件开头两个地址的,不能读任意地址的!Edit1.Text&nbsp;中敲入地址也没用!?比如我想读取地址&nbsp;0008F8FC&nbsp;的。<br>另外写入的代码好像有问题,第一次可以,关闭程序后再次运行,想再写入就会提示错误!
 
这句的注释去掉就可以了&nbsp;那时可能在测试时注释了<br>BlockRead(Source,&nbsp;Buffer0^,&nbsp;Pos);
 
大哥,我去掉注释以后,运行点击button5就会报错!
 
Label1.Caption&nbsp;:=&nbsp;ReadHex('1.exe',&nbsp;Hex2Dec(Edit1.Text));&nbsp;这里不对吧!<br>Hex2Dec(Edit1.Text)实际是地址的数据而不是地址!?
 
奇怪了&nbsp;我都测试了N次都没问题的&nbsp;给我邮箱&nbsp;我发你DEMO
 
后退
顶部