Dear timothy, thank you a lot! But still really need your help!
I jus tested and got the same memory written error in VC++, and then
found out that the error is because of Virtual Memory protection in
windows.
So I tried to create memory space in that target process, and here's
what I did in VC++ and suceeded, but failed in Java:
/* VC CODE */
hProcess=OpenProcess(PROCESS_VM_WRITE|PROCESS_VM_READ|
PROCESS_VM_OPERATION,false,PID);
plvitem=(LVITEM*)VirtualAllocEx(hProcess, 0, sizeof(LVITEM),
0x1000, 0x10);
pItem=(WCHAR*)VirtualAllocEx(hProcess, NULL, 512, MEM_COMMIT,
PAGE_READWRITE);
lvitem.pszText=pItem;
WriteProcessMemory(hProcess, plvitem, &lvitem, sizeof(LVITEM),
NULL);
SendMessage(orderlist, LVM_GETITEMTEXT, (WPARAM)0,
(LPARAM)plvitem);
In JNA, I always fail at the VirtualAllocEx function, which always
return a NULL or a random number, and I got a
87(ERROR_INVALID_PARAMETER) error through getLastError()
Here's my java code:
IntByReference pid = new IntByReference();
user32.GetWindowThreadProcessId(mainWindow, pid);
HANDLE handle = kernel32.OpenProcess(Kernel32.PROCESS_VM_OPERATION |
Kernel32.PROCESS_VM_READ|Kernel32.PROCESS_VM_WRITE, false, pid);
Pointer plvItem = kernel32.VirtualAllocEx(handle,null,
32,0x1000,0x10);
I also tried to change VirtualAllocEx method's return type to long/
int, but still the same. Here's it's signature:
public Pointer VirtualAllocEx(HANDLE process, long lpaddress, long
size_t, int flType, int flProtect);
Thanks a lot a lot in advance!!