Results 1 to 12 of 12

Thread: Problems with this module

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13

    Problems with this module

    This is a module to help read values in memory from a chosen process.


    VB Code:
    1. Module Module1
    2.     Public Const PROCESS_ALL_ACCESS = &H1F0FFF
    3.     'This above code makes it work on Windows XP
    4.     Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, ByVal lpdwProcessId As Long) As Long
    5.     Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    6.     Public Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Integer, ByVal lpBuffer As Integer, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
    7.     Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    8.     Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
    9.     Public Declare Function ReadProcessMem Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As Long, ByVal lpBaseAddress As Integer, ByRef lpBuffer As Integer, ByVal nSize As Long, ByVal lpNumberOfBytesWritten As Long) As Long
    10.  
    11.  
    12.     Public Function ReadFour(ByVal GameClass As String, ByVal Address As Long, ByVal valbuffer As Long)
    13.         Dim hWnd As Long
    14.         Dim pId As Long
    15.         Dim phandle As Long
    16.         hWnd = FindWindow(GameClass, vbNullString)
    17.         If (hWnd = 0) Then
    18.             [COLOR=red]frmmain[/COLOR].lbl_debug.Caption = "Debug: Please Run x and restart the application."
    19.             Exit Function
    20.         End If
    21.         GetWindowThreadProcessId(hWnd, pId)
    22.         phandle = OpenProcess(PROCESS_ALL_ACCESS, False, pId)
    23.         If (phandle = 0) Then
    24.             MsgBox("Can't get ProcessId", vbCritical, "Error")
    25.             Exit Function
    26.         End If
    27.         ReadProcessMem(phandle, Address, valbuffer, 4, 0&)
    28.         CloseHandle([COLOR=red]hProcess[/COLOR])
    29.     End Function
    30. End Module

    I put in red the places that Visual studio is reporting errors. Anyone have any ideas? (I'm using VS.NET 2003)



    The author then suggest a possible use for this module:


    Get the CLASS NAME of your game.. and now ..
    go to your form.

    Add a timer and a textbox or label. I suggest label.. its cleaner..
    we are going to call our timer Timer1

    Timer1_Timer()

    Call Module1.ReadMorph("Game Class Name", &HAddress, variable)

    'Im using a label for this example

    Label1.caption = variable

    End Sub




    There you go!

    Simple code so that you can read an address and put its value in a label or textbox ect ect.

    Hope that was educational/helpful.
    Last edited by Tortle; Jan 11th, 2004 at 03:33 PM.

  2. #2

  3. #3
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Not sure, see if you can fix

    CloseHandle(hProcess)

    by using

    CloseHandle phandle

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13
    Originally posted by BrianS
    Not sure, see if you can fix

    CloseHandle(hProcess)

    by using

    CloseHandle phandle
    That removed the error, yes, but I don't know if it can replace 'hProcess'.


    I don't have any form called 'frmmain'. I just have a blank default Form1.vb

  5. #5

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13
    Originally posted by MartinLiss
    Is this .Net?
    I don't know what his code is.

    But I am using .net 2003

  7. #7
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    The code doesn't appear to be functional with the hProcess in that spot. Following the logic, it only makes sense to do it the way I posted.



    Originally posted by Tortle
    That removed the error, yes, but I don't know if it can replace 'hProcess'.


    I don't have any form called 'frmmain'. I just have a blank default Form1.vb

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by MartinLiss
    Is this .Net?
    I don't think so... I think it is 6..


    Has someone helped you? Then you can Rate their helpful post.

  9. #9
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Then change

    frmmain.lbl_debug.Caption = "Debug: Please Run x and restart the application."

    to

    Form1.lbl_debug.Caption = "Debug: Please Run x and restart the application."


    And create a label called lbl_debug on your Form1.

    I dont use .net, so not sure if this is the proper syntax, but you should be able to make it work since now you know what it's supposed to do.

    Originally posted by Tortle

    I don't have any form called 'frmmain'. I just have a blank default Form1.vb

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13
    Originally posted by BrianS
    Then change

    frmmain.lbl_debug.Caption = "Debug: Please Run x and restart the application."

    to

    Form1.lbl_debug.Caption = "Debug: Please Run x and restart the application."


    And create a label called lbl_debug on your Form1.

    I dont use .net, so not sure if this is the proper syntax, but you should be able to make it work since now you know what it's supposed to do.
    Ok, I did that, and now I am getting the error "Reference to a non-shared member requires an object reference."

  11. #11
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Probably a .net error, can't help you there sorry.

  12. #12

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13
    Ok, I removed that, it's just for error messaging.

    Now for the actual program, this is what I have so far.

    VB Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.  
    3.         Call Module1.ReadFour(GameClass, &H0, Valbuffer)
    4.  
    5.  
    6.         TextBox1.Show()
    7.  
    8.     End Sub

    What do I put in the Valbuffer parameter?

    I also want to put the value into a variable, so that I can show it with TextBox1.show
    Last edited by Tortle; Jan 11th, 2004 at 06:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width