procedure TfrmMain.tmrChangeServerNameTimer(Sender: TObject);
function GetProcessID(FileName: string = ''): TProcessEntry32;
var
Ret: BOOL;
s: string;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, );
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
Ret := Process32First(FSnapshotHandle, FProcessEntry32);
while Ret do
begin
s := ExtractFileName(FProcessEntry32.szExeFile);
if (AnsiCompareText(Trim(s),Trim(FileName))=) and (FileName <> '') then begin
result := FProcessEntry32;
break;
end;
Ret := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
var
FProcessEntry32: TProcessEntry32;
ProcessID: integer;
ProcessHandle: THandle;
lpBuffer: PChar;
nSize: DWORD;
lpNumberOfBytes: DWORD;
mbi_thunk:TMemoryBasicInformation;
dwOldProtect:dword;
const
LeftAddress = $02370C68;
RightAddress1 = $02370C74;
RightAddress2 = $02370C84;
// ServerName = '京信三国';
begin
FProcessEntry32 := GetProcessID('aLogin.exe');
if FProcessEntry32.th32ProcessID = then exit;
ProcessID := FProcessEntry32.th32ProcessID;
ProcessHandle := OpenProcess(PROCESS_ALL_ACCESS, false, ProcessID);
//---------------写left
lpBuffer := PChar(GB2Big5('01.' + ServerName));
nSize:= ; //N是数据长度
//写LeftAddress数据
VirtualQueryEx(ProcessHandle,Pointer(LeftAddress),mbi_thunk, sizeof(TMemoryBasicInformation));
VirtualProtectEx(ProcessHandle,Pointer(LeftAddress),nSize,PAGE_EXECUTE_READWRITE,mbi_thunk.Protect);
WriteProcessMemory(ProcessHandle, Pointer(LeftAddress), lpBuffer, nSize, lpNumberOfBytes);
VirtualProtectEx(ProcessHandle,Pointer(LeftAddress), nSize, mbi_thunk.Protect,dwOldProtect);
//---------------写right
lpBuffer := PChar(GB2Big5(ServerName)); //要写的内容
nSize:= ; //数据长度
//写RightAddress1数据
VirtualQueryEx(ProcessHandle,Pointer(RightAddress1),mbi_thunk, sizeof(TMemoryBasicInformation));
VirtualProtectEx(ProcessHandle,Pointer(RightAddress1),nSize,PAGE_EXECUTE_READWRITE,mbi_thunk.Protect);
WriteProcessMemory(ProcessHandle, Pointer(RightAddress1), lpBuffer, nSize, lpNumberOfBytes);
VirtualProtectEx(ProcessHandle,Pointer(RightAddress1), nSize, mbi_thunk.Protect,dwOldProtect);
//写RightAddress2数据
VirtualQueryEx(ProcessHandle,Pointer(RightAddress2),mbi_thunk, sizeof(TMemoryBasicInformation));
VirtualProtectEx(ProcessHandle,Pointer(RightAddress2),nSize,PAGE_EXECUTE_READWRITE,mbi_thunk.Protect);
WriteProcessMemory(ProcessHandle, Pointer(RightAddress2), lpBuffer, nSize, lpNumberOfBytes);
VirtualProtectEx(ProcessHandle,Pointer(RightAddress2), nSize, mbi_thunk.Protect,dwOldProtect);
//读内容,确定是否修改成功
lpBuffer := AllocMem(nSize);
ReadProcessMemory(ProcessHandle, Pointer(RightAddress2), lpBuffer, nSize, lpNumberOfBytes);
if ServerName = Big52GB(lpBuffer) then begin
Caption := '内存内容为:' + Big52GB(lpBuffer);
tmrChangeServerName.Enabled := False;
end;
CloseHandle(ProcessHandle);
// Memo1.Lines.Add(Big52GB(lpBuffer));
//MEMO显示信息
// Memo1.Lines.Clear;
// memo1.lines.add('Process ID ' + IntToHex(FProcessEntry32.th32ProcessID, ));
// memo1.lines.Add('File name ' + FProcessEntry32.szExeFile);
// memo1.Lines.Add('Process Handle ' + intTohex(ProcessHandle, ));
// Memo1.Lines.Add('虚拟内存中的数据:');
end;

读写另一EXE的内存的更多相关文章

  1. 解决服务器上 w3wp.exe 和 sqlservr.exe 的内存占用率居高不下的方案

    SQL Server是如何使用内存 最大的开销一般是用于数据缓存,如果内存足够,它会把用过的数据和觉得你会用到的数据统统扔到内存中,直到内存不足的时候,才把命中率低的数据给清掉.所以一般我们在看sta ...

  2. 使用PageHeap.EXE或GFlags.EXE检查内存越界错误 (转)

    2011-05-27 20:19 290人阅读 评论(0) 收藏 举报 microsoftdebuggingstructureoutputimagefile 必先利其器之一:使用PageHeap.EX ...

  3. 使用PageHeap.EXE或GFlags.EXE检查内存越界错误

    必先利其器之一:使用PageHeap.EXE或GFlags.EXE检查内存越界错误 Article last modified on 2002-6-3 ------------------------ ...

  4. win7 64位的 svchost.exe 占用内存过大的问题

    svchost.exe 是用来启动系统服务的,所以某个 svchost.exe 占用内存过大,可能就是它启动的那个服务占用内存过大,所以只要停止并禁用那个服务就行了. 一般来说占用内存最大的服务是 S ...

  5. win7的svchost.exe占用内存过高如何解决

    方法/步骤 1 在我的电脑上点击鼠标右键,选择[管理] 步骤阅读 2 选择右侧[服务和应用程序]下的[服务]选项 步骤阅读 3 找到名称我Superfetch的服务,双击鼠标左键. 步骤阅读 4 选择 ...

  6. powershell加载EXE进内存运行

    当实战中我们想在目标上运行一些相当复杂的功能,这些功能常是 EXE 文件的一部分.我不想直接在目标上放置一个二进制文件,因为这样可能会触发反病毒机制.一个很好的思路就是将二进制文件嵌入到 Powers ...

  7. delphi 实现两个exe文件共享内存映像的代码

    创建内存映像的程序 ------------------------------------------------------------------------------------------ ...

  8. 两个exe共享内存数据

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  9. svchost.exe 占用内存过多

    http://www.tomshardware.com/forum/20583-63-svchost-netsvcs-speed By Lokesh Chandra: Just Go to Contr ...

随机推荐

  1. spring的cglib代理

    1.被代理类Person.java package com.xiaostudy; /** * @desc 被代理类 * * @author xiaostudy * */ public class Pe ...

  2. I方法怎么不能获取多选框的数据

    前端代码 <input type="checkbox" name="m_name" value="{$vo.name}" class ...

  3. Python基础笔记系列三:list列表

    本系列教程供个人学习笔记使用,如果您要浏览可能需要其它编程语言基础(如C语言),why?因为我写得烂啊,只有我自己看得懂!! python中的list列表是一种序列型数据类型,一有序数据集合用逗号间隔 ...

  4. Spark- 根据ip地址计算归属地

    主要考察的是广播变量的使用: 1.将要广播的数据 IP 规则数据存放在HDFS上,(广播出去的内容一旦广播出去产就不能改变了,如果需要实时改变的规则,可以将规则放到Redis中) 2.在Spark中转 ...

  5. GDI+ 双缓冲字体模糊

    只是记录自己的UI库,对其他估计没什么帮助 void CListCtrlUI::ReFillRect(HDC hdc){ if (!m_pImage) { Graphics gs(hdc); int ...

  6. spring3: 对JDBC的支持 之 Spring提供的其它帮助 SimpleJdbcInsert/SimpleJdbcCall/SqlUpdate/JdbcTemplate 生成主键/批量处理

    7.4  Spring提供的其它帮助 7.4.1  SimpleJdbc方式 Spring JDBC抽象框架提供SimpleJdbcInsert和SimpleJdbcCall类,这两个类通过利用JDB ...

  7. java环信服务端注册IM代码

    下载环信api代码 https://github.com/easemob/emchat-server-examples 里面包含各种语言版本,我只下载了java版emchat-server-java ...

  8. Angular路由的定义和使用

    一.什么是routing(路由) Almost all non-trivial, non-demo Single Page App (SPA) require multiple pages. A se ...

  9. python 在头文件添加 #include \"stdafx.h\"\r\n

    import osimport shutil#-*- coding:cp936 -*-import codecsfrom sys import argv def replace_all_files(p ...

  10. SQLSERVER store procedure 临时表

    有些时候显示重复数据时,使用: ) 但有些时候表A过大或者逻辑复杂.显示数据时,会造成性能的影响,这时你就可以使用临时表:   ) create table #temp( XXX , XXX) )in ...