| 发表于:2007-03-09 13:32:312楼 得分:50 |
private declare function globallock lib "kernel32 " (byval hmem as long) as long private declare function globalsize lib "kernel32 " (byval hmem as long) as long private declare function globalunlock lib "kernel32 " (byval hmem as long) as long private declare sub copymemory lib "kernel32 " alias "rtlmovememory " (lpvdest as any, lpvsource as any, byval cbcopy as long) private declare function globalalloc lib "kernel32 " (byval wflags as long, byval dwbytes as long) as long private declare function globalfree lib "kernel32 " (byval hmem as long) as long private mmydata() as byte private mmydatasize as long private mhmem as long public enum englobalmemoryallocationconstants gmem_fixed = &;amp;h0 gmem_discardable = &;amp;h100 gmem_moveable = &;amp;h2 gmem_nocompact = &;amp;h10 gmem_nodiscard = &;amp;h20 gmem_zeroinit = &;amp;h40 end enum public sub copyfromhandle(byval hmemhandle as long) dim lret as long dim lptr as long lret = globalsize(hmemhandle) if lret > 0 then mmydatasize = lret lptr = globallock(hmemhandle) if lptr > 0 then redim mmydata(0 to mmydatasize - 1) as byte copymemory mmydata(0), byval lptr, mmydatasize call globalunlock(hmemhandle) end if end if end sub '\\ --[copytohandle]-------------------- ' --------- '\\ copies the private data to a memory ' handle '\\ passed in '\\ ------------------------------------ ' --------- public sub copytohandle(byval hmemhandle as long) dim lsize as long dim lptr as long '\\ don 't copy if its empty if not (mmydatasize = 0) then lsize = globalsize(hmemhandle) '\\ don 't attempt to copy if zero size.. ' . if lsize > 0 then if lptr > 0 then copymemory byval lptr, mmydata(0), lsize call globalunlock(hmemhandle) end if end if end if end sub 是上面這個嗎?在planet-source-code.com上有 //************************************** // //windows api/global declarations for :p // ossible sharable vb memory //************************************** // declare function readprocessmemory lib "kernel32 " alias "readprocessmemory " (byval hprocess as long, lpbaseaddress as any, lpbuffer as any, byval nsize as long, lpnumberofbyteswritten as long) as long declare function writeprocessmemory lib "kernel32 " alias "writeprocessmemory " (byval hprocess as long, lpbaseaddress as any, lpbuffer as any, byval nsize as long, lpnumberofbyteswritten as long) as long declare function getcurrentprocessid lib "kernel32 " alias "getcurrentprocessid " () as long declare function openprocess lib "kernel32 " (byval dwdesiredaccess as long, byval binherithandle as long, byval dwprocessid as long) as long public const specific_rights_all =&;amp;h0000ffff public const standard_rights_required = &;amp;h000f0000 public const standard_rights_all = &;amp;h001f0000 =============================================================== dim a as long a = 'process id to open dim b as long b = openprocess((specific_rights_all and standard_rights_all), false, a) 'opens a process handle for memory access --- dim a as long dim b as long dim c as long dim d as boolean dim e as long dim f as long d = readprocessmemory(a, byval b, byval varptr(c), 4, e) <-- reads from a openprocess handle 's memory address. d = writeprocessmemory(a, byval b, c, 4, e) <-- writes instead of reads. | | |
|