[VB.NET]Basics of undetected Battlefield 3 hacking

Discussion in 'Mixed Languages' started by stevemk14ebr, Apr 13, 2013.

  1. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #1 stevemk14ebr, Apr 13, 2013
    Last edited by a moderator: Apr 20, 2017
    i've been working on a vb.net BF3 hack, i know i know should be using c++ and dlls, but i was just curious to see if it is possible in vb, and well it is! Using some depreciated api's and a little creativity it is possible to manipulate what i call the 3 methods of input, mouse clicks-keyboard buttons-and mouse movement, ALL OF THEM UNDETECTED BY ANTI-CHEAT. Its should be said that this is as far as this goes, it doesn't check memory adresses to find enemies and aim at them (which it could easily be made to do) it simply is the basics of an undetected hack and a very good api exercise.

    Api's used-
    mouse clicks-mouse_event(depreciated)
    the following code is the mouse_event api
    Code:
    Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
    
    Code:
    'press
    mouse_event(&H2, 0, 0, 0, 1)
    'release
     mouse_event(&H4, 0, 0, 0, 1)
    mouse movement-mouse_event(depreciated), setup to use either relative or absolute values (ie, can move from current pos or it can jump directly to a position)
    Code:
    'gets current mouse pos needed for absolute movement requires aformentioned mouse_event api 
    Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As PointAPI) As Boolean
     
     Structure PointAPI
            Public x As Integer
            Public y As Integer
        End Structure
    
    Const MOUSEEVENTF_MOVE As Int32 = &H1 '  mouse move
        Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2 '  left button down
        Const MOUSEEVENTF_LEFTUP As Int32 = &H4 '  left button up
        Const MOUSEEVENTF_RIGHTDOWN As Int32 = &H8 '  right button down
        Const MOUSEEVENTF_RIGHTUP As Int32 = &H10 '  right button up
        Const MOUSEEVENTF_MIDDLEDOWN As Int32 = &H20 '  middle button down
        Const MOUSEEVENTF_MIDDLEUP As Int32 = &H40 '  middle button up
        Const MOUSEEVENTF_ABSOLUTE As Int32 = &H8000 '  absolute move
        Const MOUSEEVENTF_WHEEL As Int32 = &H800 ' wheel button rolled
    
    Code:
      'this is for mousemove absolute which moves to an x,y pos instead of mousemove which moves the cursor relative to the current position
                Dim screen_x As Single = Screen.PrimaryScreen.Bounds.Width
                Dim screen_y As Single = Screen.PrimaryScreen.Bounds.Height
    
                Dim MouseLocation As New PointAPI
                GetCursorPos(MouseLocation)
                normalizedXCoord = MouseLocation.x / (screen_x) * 65535
                normalizedYCoord = MouseLocation.y / (screen_y) * 65535
    'absolute move
    mouse_event(MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE, normalizedXCoord, normalizedYCoord, 0, 0)
    'relative move
     mouse_event(MOUSEEVENTF_MOVE, 0, 2, 0, 0)
    
    keyboard events-keybd_event with mapvirtualkey(very important)
    Code:
      Const KEYEVENTF_EXTENDEDKEY = &H1
        Const KEYEVENTF_KEYUP = &H2
        Const SPI_GETKEYBOARDDELAY = 22
        Const SPI_GETKEYBOARDSPEED = 10
        Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Integer, ByVal bScan As Integer, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
       Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Integer, ByVal wMapType As Integer) As Integer
    Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByRef lpvParam As Integer, ByVal fuWinIni As Integer) As Integer
    Code:
      Private Sub release(ByVal key As Byte)
            Dim kb_delay As Integer
            Dim kb_speed As Integer
            SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, kb_delay, 0)
            SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, kb_speed, 0)
            keybd_event(key, MapVirtualKey(key, 0), 2, 0)
        End Sub
       
     Private Sub press(ByVal key As Byte)
            Dim kb_delay As Integer
            Dim kb_speed As Integer
            SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, kb_delay, 0)
            SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, kb_speed, 0)
            keybd_event(key, MapVirtualKey(key, 0), 0, 0)
        End Sub
    'use is:
    press(Keys.D)
    release(Keys.D)
    if you need help with how to use these or find an error, think of a better way, or just want to talk about other ways to do this please comment also feel free to use this code, thanks goes out to all the websites I used as references.

    here is the exact project i use as testing (might have extra variables because as i said it is used for testing), it shows all 3 input methods working just press the 1 key (not numpad 1) to toggle on and off, you may have to press it more than once: http://www.solidfiles.com/d/5da48e228d/
    note that it uses a module called apikit it is imported simply because it is useful and is only used once to use the getasynckeystate api, i was testing it and its testing led to this whole project