写内存写错了
procedure TForm1.Button1Click(Sender: TObject);
var
pItem: TLVItem;
Buff: PChar;
PID,PRC: THandle;
R: Cardinal;
hwnd:tHandle;
begin
hwnd:= FindWindow('#32770','Windows 任务管理器');
hwnd:= FindWindowEx(hwnd,0,'#32770',0);
hwnd:= FindWindowEx(hwnd,0,'SysListView32',0);
GetWindowThreadProcessId(hwnd, @PID);
PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, PID);
Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
ZeroMemory(@pItem,SizeOf(pItem));
with pItem do
begin
mask := LVIF_TEXT;
pszText := PChar(integer(Buff) + SizeOf(pItem) * 4);
cchTextMax := Length(Edit1.Text)+1;
end;
WriteProcessMemory(PRC, Buff, @pItem, Sizeof(pItem), R);
WriteProcessMemory(PRC, PChar(integer(Buff) + SizeOf(pItem) * 4),
PChar(Edit1.Text), Length(Edit1.Text)+1, R);
SendMessage(hwnd,LVM_INSERTITEM,0,LongInt(Buff));
VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE);
CloseHandle(PRC);
end;
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课