把 字符串 写入内存 我的代码前辈来帮看!

byyouxin 2010-01-20 10:41:37

procedure xie;
var
txt:pwidechar;
WriteCount: DWORD;
begin
txt:=allocmem(256);
stringtowidechar('问世间,情为何物,直叫人生死相许',txt,256);
Threadd:=VirtualAllocEx(HPro, nil, 256, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(HPro,Threadd,txt, 256, WriteCount);

end;


我调试写入后提示

"
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0040404B in module 'Project1.exe'. Read of address 0BEF0000'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------

"
...全文
110 2 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
postren 2010-01-20
  • 打赏
  • 举报
回复

procedure xie;
var
txt:pwidechar;
WriteCount: DWORD;
Threadd: Pointer;
HPro: DWORD;
begin
txt:=allocmem(256);
HPro := OpenProcess(PROCESS_ALL_ACCESS, True, GetCurrentProcessId);
stringtowidechar('问世间,情为何物,直叫人生死相许',txt,256);
Threadd:=VirtualAllocEx(HPro, nil, 256, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(HPro, Threadd, txt, 256, WriteCount);
ZeroMemory(txt, 256);
ReadProcessMemory(hPro, Threadd, txt, 256, WriteCount);
CloseHandle(HPro);
ShowMessageFmt('%s, Count=%d', [txt, WriteCount] );
end;
pathletboy 2010-01-20
  • 打赏
  • 举报
回复
try this
procedure xie;
var
txt:PWideChar;
WriteCount: DWORD;
HPRo: Cardinal;
begin
txt:= '问世间,情为何物,直叫人生死相许';
Threadd:=VirtualAllocEx(HPro, nil, 256, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(HPro,Threadd,txt, Length(txt) * 2, WriteCount);
end;
相关推荐
发帖
Windows SDK/API

1177

社区成员

Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
帖子事件
创建了帖子
2010-01-20 10:41
社区公告
暂无公告