4 messages in net.java.dev.jna.usersRe: [jna-users] HELP! The instruction...
FromSent OnAttachments
Lei DingFeb 27, 2008 4:01 am 
Timothy WallFeb 27, 2008 7:57 am 
Lei DingFeb 27, 2008 7:45 pm 
Timothy WallFeb 27, 2008 8:38 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] HELP! The instruction referenced at .... could not be writtenActions...
From:Timothy Wall (twal@dev.java.net)
Date:Feb 27, 2008 8:38:07 pm
List:net.java.dev.jna.users

Re-read what I said about Java long vs native long.

On Feb 27, 2008, at 10:46 PM, Lei Ding wrote:

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!!