VB read-write process memory

Source: Internet
Author: User

In the form section, it is simple to test the readprocessmemory and writeprocessmemory to read and write to another program process, which really works.

As a result of the temporary project changes, and do not need, so directly sealed class, delete the project. The following code does not have a function tested, the compilation is not done ...

Option ExplicitPrivate Declare FunctionOpenProcessLib "kernel32"(ByValdwDesiredAccess as Long,ByValbInheritHandle as Long,ByValDwprocessid as Long) as LongPrivate ConstProcess_all_access = &h1f0fffPrivate Declare FunctionReadProcessMemoryLib "kernel32"(ByValDwprocess as Long, lpbaseaddress asAny, lpbuffer asAny,ByValNSize as Long, Lpnumberofbyteswritten as Long) as LongPrivate Declare FunctionWriteProcessMemoryLib "kernel32"(ByValDwprocess as Long, lpbaseaddress asAny, lpbuffer asAny,ByValNSize as Long, Lpnumberofbyteswritten as Long) as LongPrivate Declare FunctionCloseHandleLib "kernel32"(ByValHobject as Long) as LongDimDwproc as LongDimDwpid as Long'Set Process Public FunctionSetprocess (Pid as Long)    PagerTerminate Dwproc= OpenProcess (Process_all_access,False, Pid) dwpid=PidEnd Function'read, corresponding byte groups, hexadecimal and integers, respectivelyPrivate FunctionReadmemorya (Addr as Long, Size as Long) as Byte()    IfSize <1  Then Exit Function    DimRet as Boolean, BUF () as Byte    ReDimBUF (Size-1) as ByteRet= ReadProcessMemory (Dwproc,ByValADDR, BUF (0), Size,0)    IfRet ThenReadMemory =bufEnd FunctionPrivate FunctionReadmemoryh (Addr as Long, Size as Long) as String    IfSize <1  Then Exit Function    DimRet as Boolean, BUF () as Byte    ReDimBUF (Size-1) as ByteRet= ReadProcessMemory (Dwproc,ByValADDR, BUF (0), Size,0)    IfRet Then        DimI as Long         fori =0  to UBound(BUF)IfBUF (i) > the  ThenReadmemoryh= Readmemoryh &Hex(BUF (i)) &" "            ElseReadmemoryh= Readmemoryh &"0"&Hex(BUF (i)) &" "            End If        Next    End IfEnd FunctionPrivate FunctionReadmemoryl (Addr as Long) as Long    IfSize <1  Then Exit Function    DimRet as Boolean, L as Longreadprocessmemory Dwproc,ByValADDR, L,4,0Readmemoryl=LEnd Function'write, corresponding to single byte, byte group, and Integer, respectivelyPrivate FunctionWriteMemory (Addr as Long, buf as Byte) WriteProcessMemory Dwproc,ByValADDR, BUF,1,0&End FunctionPrivate FunctionWritememorya (Addr as Long, BUF () as Byte) WriteProcessMemory Dwproc,ByValADDR, BUF (0),UBound(BUF) +1,0&End FunctionPrivate FunctionWritememoryl (Addr as Long, L as Long) WriteProcessMemory Dwproc,ByValADDR, L,4,0&End Function'Destroying resource consumptionPrivate SubTerminate ()IfDwpid <>0  ThenCloseHandle dwpidIfDwproc <>0  ThenCloseHandle DwprocEnd SubPrivate SubClass_Terminate ()PagerTerminateEnd Sub

VB read-write process memory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.