Hi all:
I want to Copy all item texts of ListView in other applicaion to my ListView in my application.

I have gotten the handle of ListView in other applicaion.
But I fail to get the first item texts of the ListView by using the following code:


CopyRAVList proc
LOCAL lvi: LV_ITEM
LOCAL dwloopVar; DWORD
LOCAL dwRowNo: DWORD


mov dwRowNo, 0 ;The first item is 0
mov dwloopVar, 0 ;current column number.

push dwRowNo
pop lvi.iItem

.while (dwloopVar < 4) ;The ListView has 4 columns.
;------------------------------------------------------------
; Get the item text of listview in other application
;------------------------------------------------------------
invoke SendMessage,
g_hlvRAVList, ; the handle of listview in other application
LVM_GETNEXTITEM,
dwloopVar,
LVNI_TORIGHT

.IF (eax != -1)
mov lvi.imask, LVIF_TEXT

push dwloopVar
pop lvi.iSubItem

push OFFSET g_szTmpBuf
pop lvi.pszText

mov lvi.cchTextMax, SIZEOF g_szTmpBuf

invoke SendMessage, g_hlvRAVList, LVM_GETITEM, 0, addr lvi


.if (eax == FALSE)
invoke MessageBox, g_hDlg, OFFSET g_szFailCopyItem, OFFSET g_szAppName, NULL
ret
.endif

;----------------------------------------------
;Copy the item text to my listview
;----------------------------------------------
mov lvi.imask, LVIF_TEXT + LVIF_PARAM
push dwRowNo
pop lvi.iItem

push dwloopVar
pop lvi.iSubItem

push OFFSET g_szTmpBuf
pop lvi.pszText

push dwRowNo
pop lvi.lParam
invoke SendMessage, g_hlvVirusList, LVM_INSERTITEM, 0, addr lvi
inc dwloopVar
.ENDIF
.endw


ret
CopyRAVList endp
Posted on 2004-04-17 04:40:01 by purpleendurer
Mmmm,

Amazing how often this is coming up these days. All of a sudden we have a flood of posts to get data from listviews in other processes:

http://www.asmcommunity.net/board/index.php?topic=17427&perpage=12&pagenumber=2
Posted on 2004-04-17 06:02:18 by donkey
Check again closely LVM_GETNEXTITEM message.

iStart (wParam)

Index of the item to begin the searching with, or -1 to find the first item that matches the specified flags. The specified item itself is excluded from the search.

If you try to get info for item with index 0 with LVM_GETNEXTITEM message you will get nothing. You will get next item which index is 1 (this is second item in LV control).
You can try with checking state (LVIS_SELECTED or LVIS_FOCUSED...depends what you want) of item with index 0. If it is selected (or focused) then grab info, else continu with LVM_GETNEXTITEM message.
I simply retrieve all indexes in array of dword's and then with LVM_GETITEM (copy index from array to iItem) i get all info i need (in your example you need text).

stanks
Posted on 2004-04-17 06:23:58 by stanks
Hi,donkey

I used your code in

http://www.asmcommunity.net/board/index.php?topic=17427&perpage=12&pagenumber=2

but return nothing.

can you tell where is error?



CopyRAVList proc
LOCAL lvi: LV_ITEM
LOCAL dwloopVar; DWORD
LOCAL dwRowNo: DWORD


mov [lvi.imask],LVIF_TEXT
mov [lvi.pszText],OFFSET g_szTmpBuf
mov [lvi.cchTextMax],255
mov [lvi.iItem],0
mov [lvi.iSubItem], 0
invoke GetRemoteItem, g_hlvRAVList, ADDR lvi

invoke MessageBox, g_hDlg, OFFSET g_szTmpBuf, OFFSET g_szAppName, MB_ICONWARNING

mov lvi.imask, LVIF_TEXT + LVIF_PARAM
push dwRowNo
pop lvi.iItem

push dwloopVar
pop lvi.iSubItem

push OFFSET g_szTmpBuf
pop lvi.pszText

push dwRowNo
pop lvi.lParam

invoke SendMessage, g_hlvVirusList, LVM_INSERTITEM, 0, addr lvi
inc dwloopVar

ret
CopyRAVList endp


GetRemoteItem proc uses ebx hlv: HANDLE, pLVItem: DWORD
LOCAL pMem :DWORD
LOCAL PID :DWORD
LOCAL hProcess :DWORD
LOCAL cbWritten :DWORD

invoke GetWindowThreadProcessId,[hlv],ADDR PID
invoke OpenProcess,PROCESS_VM_OPERATION + \
PROCESS_VM_READ + PROCESS_VM_WRITE,NULL,[PID]
mov [hProcess],eax

invoke VirtualAllocEx, eax, NULL, 1024, MEM_COMMIT, PAGE_READWRITE
mov [pMem],eax

mov eax,[pMem]
add eax,256
mov ecx,[pLVItem]
mov ebx,[ecx+LV_ITEM.pszText]
mov [ecx+LV_ITEM.pszText],eax
invoke WriteProcessMemory, [hProcess], [pMem], [pLVItem], SIZEOF LV_ITEM, ADDR cbWritten

invoke SendMessage,[hlv],LVM_GETITEM,0,[pMem]

invoke ReadProcessMemory, [hProcess], [pMem], \
[pLVItem], SIZEOF LV_ITEM, ADDR cbWritten

mov eax,[pLVItem]
mov ecx,[eax+LV_ITEM.cchTextMax]
mov [eax+LV_ITEM.pszText],ebx

mov esi,[pMem]
add esi, 256
invoke ReadProcessMemory, [hProcess], esi, ebx, ecx, ADDR cbWritten

invoke VirtualFreeEx, [hProcess], [pMem], 1024, MEM_RELEASE
invoke CloseHandle, [hProcess]

RET

GetRemoteItem endp

end start

Posted on 2004-04-18 03:10:46 by purpleendurer
Well, I would start by making sure that you can open the process and have virtual memory access, does hProcess contain a value? Also what OS version are you running? There are many reasons that it does not work, you have to see what API is not returning the proper value and figure it out from there. Without the program that you are requesting data from or any knowledge of your system or access rights I can't really say. The routine works though, I have used it for the desktop and the taskmanager without any problems.
Posted on 2004-04-18 04:27:58 by donkey
Thanks all.

I has resolved it.

The var passed to pLVItem in GetRemoteItem() must be a global var.

in my code



CopyRAVList proc
LOCAL dwloopVar; DWORD
LOCAL dwRowNo: DWORD

; int ListView_GetItemCount(
; HWND hwnd
; );
invoke SendMessage, g_hlvRAVList, LVM_GETITEMCOUNT, 0, 0
mov g_dwItemCount, eax

ShowVirusCount

.if (eax <= 0)
invoke MessageBox, g_hDlg, OFFSET g_szNoVirus, OFFSET g_szAppName, MB_ICONWARNING
ret
.endif

mov dwRowNo, 0
mov eax, g_dwItemCount
.while (dwRowNo < eax)
mov dwloopVar, 0
.WHILE (dwloopVar < 4)
mov [g_lvi.imask], LVIF_TEXT
mov [g_lvi.pszText], OFFSET g_szTmpBuf1
mov [g_lvi.cchTextMax], SIZEOF g_szTmpBuf1

push dwRowNo
pop [g_lvi.iItem]

push dwloopVar
pop [g_lvi.iSubItem]

invoke GetRemoteItem, g_hlvRAVList, OFFSET g_lvi

.if (dwloopVar == 0)
mov eax, LVM_INSERTITEM
.else
mov eax, LVM_SETITEM
.endif
invoke SendMessage, g_hlvVirusList, eax, 0, addr g_lvi


inc dwloopVar

;invoke wsprintf, OFFSET g_szTmpBuf1, OFFSET g_szFmt, dwloopVar
;invoke MessageBox, g_hDlg, OFFSET g_szTmpBuf1, OFFSET g_szAppName, MB_ICONWARNING

.ENDW
inc dwRowNo
mov eax, g_dwItemCount
.endw
ret
CopyRAVList endp


;######################################
; Author: donkey
; Source: [url]http://www.asmcommunity.net/board/showthread.php?s=&threadid=17427&perpage=12&pagenumber=2[/url]
;######################################
GetRemoteItem proc uses ebx hlv: HANDLE, pLVItem: DWORD
LOCAL pMem :DWORD
LOCAL PID :DWORD
LOCAL hProcess :DWORD
LOCAL cbWritten :DWORD

invoke GetWindowThreadProcessId,[hlv],ADDR PID
invoke OpenProcess,PROCESS_VM_OPERATION + \
PROCESS_VM_READ + PROCESS_VM_WRITE,NULL,[PID]
mov [hProcess],eax

invoke VirtualAllocEx, eax, NULL, 1024, MEM_COMMIT, PAGE_READWRITE
mov [pMem],eax

mov eax,[pMem]
add eax,256
mov ecx,[pLVItem]
mov ebx,[ecx+LV_ITEM.pszText]
mov [ecx+LV_ITEM.pszText],eax
invoke WriteProcessMemory, [hProcess], [pMem], [pLVItem], SIZEOF LV_ITEM, ADDR cbWritten

invoke SendMessage,[hlv],LVM_GETITEM,0,[pMem]

invoke ReadProcessMemory, [hProcess], [pMem], \
[pLVItem], SIZEOF LV_ITEM, ADDR cbWritten

mov eax,[pLVItem]
mov ecx,[eax+LV_ITEM.cchTextMax]
mov [eax+LV_ITEM.pszText],ebx

mov esi,[pMem]
add esi, 256
invoke ReadProcessMemory, [hProcess], esi, ebx, ecx, ADDR cbWritten

invoke VirtualFreeEx, [hProcess], [pMem], 1024, MEM_RELEASE
invoke CloseHandle, [hProcess]

RET

GetRemoteItem endp


the var "lvi" must be defined as a global var.
Posted on 2004-04-18 05:53:04 by purpleendurer
Hi,

There was a memory leakin the code that was later corrected, you have not done it in this one...

invoke VirtualFreeEx, , , 1024, MEM_RELEASE

Should be:

invoke VirtualFreeEx, , , NULL, MEM_RELEASE
Posted on 2004-04-18 06:35:42 by donkey
I will correct my code immediately??
Posted on 2004-04-18 09:08:48 by purpleendurer
Hi donkey,

My application including your code works normally under win 2000 pro,

but it can not get data under win 98. I can get the item number of listview in other application, but can not get
the item text.

and it causes an error under win 95/97. when my application runs, a blank dialog pops, the title of dialog is "The program error", even your code no run.

Do you test your code under win 95/98?
Posted on 2004-04-27 02:31:48 by purpleendurer

VirtualAllocEx
Client: Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.

No win9x listed there...
I thought it *did* work in 9x, though, even though PSDK says otherwise. *shrug*. Anyway, I believe EliCZ has code to emulate VirtualAllocEx, CreateRemoteThread (...) under 9x.
Posted on 2004-04-27 03:26:59 by f0dder


No win9x listed there...
I thought it *did* work in 9x, though, even though PSDK says otherwise. *shrug*. Anyway, I believe EliCZ has code to emulate VirtualAllocEx, CreateRemoteThread (...) under 9x.


Hi f0dder.

Thanks for your help.:alright:

I forgot to look the MSDN.

Can you tell me what is shrug? and who is EliCZ?

Purple Endurer
Posted on 2004-04-27 04:30:21 by purpleendurer
f0dder,

He did.

purpleendurer,
Take a look at http://www.anticracking.sk/EliCZ/
Posted on 2004-04-27 07:35:51 by roticv
there's also an undocumented flag to allocate shared memory with virtualalloc for 9x, which y0da uses in his ForceLibrary.

e.g.


VA_SHARED equ 08000000h

..

invoke VirtualAlloc,NULL,dwLen,MEM_COMMIT or VA_SHARED,PAGE_EXECUTE_READWRITE


shrug means to raise the shoulders, especially as a gesture of doubt, disdain, or indifference (dictionary.com)
Posted on 2004-04-27 08:30:02 by stormix
VirtualAllocEx is avaiable as of Win98 (out of the box normal 98) It has the function exported as part of KERNEL32.DLL DLL Version 4.10.0.1998 (the first Kernel32 that the function appears in)
Posted on 2004-04-27 08:56:47 by donkey
exporting it doesn't necessarily mean it works, though - VirtualLock is exported on 9x but doesn't do anything. I do seem to remember that some 9x has working VirtualAllocEx though, but... it's been years since I worked with 9x :)
Posted on 2004-04-27 09:34:52 by f0dder
Hi f0dder,

I would have to test it and really don't feel like it. But you can always just find a free page above 2gig for Win9x and it will be shared by all processes. I think it works that way in 9x, never really bothered to try it because I have never needed it.
Posted on 2004-04-27 09:39:23 by donkey
I have tested it on two 9x machines before and VirtualAllocEx will fail with ERROR_CALL_NOT_IMPLEMENTED
Posted on 2004-04-27 10:01:15 by stormix

I have tested it on two 9x machines before and VirtualAllocEx will fail with ERROR_CALL_NOT_IMPLEMENTED


Thanks Stormix,

Good to know.
Posted on 2004-04-27 10:56:37 by donkey
Afternoon, purpleendurer.

Which application are you wishing to retrieve the ListView text from? I've noticed that you've named your listview as g_hlvVirusList.

Cheers,
Scronty
Posted on 2004-04-27 19:55:58 by Scronty

f0dder,

He did.

purpleendurer,
Take a look at http://www.anticracking.sk/EliCZ/


Thanks, roticv.


there's also an undocumented flag to allocate shared memory with virtualalloc for 9x, which y0da uses in his ForceLibrary.

e.g.


VA_SHARED equ 08000000h

..

invoke VirtualAlloc,NULL,dwLen,MEM_COMMIT or VA_SHARED,PAGE_EXECUTE_READWRITE


shrug means to raise the shoulders, especially as a gesture of doubt, disdain, or indifference (dictionary.com)


Thanks Stormix,

I will try in your way.




Afternoon, purpleendurer.

Which application are you wishing to retrieve the ListView text from? I've noticed that you've named your listview as g_hlvVirusList.

Cheers,
Scronty


Hi, Scronty

I want to copy the ListView text in other application(an Anti-Virus softeware) to my ListView in my application.

Yes, the var "g_hlvVirusList" is the handle of ListView in my application.

The procudure that Donkey gave me can work normally under win 2000 pro, but no work under win 95/97/98.
Posted on 2004-04-27 21:31:51 by purpleendurer