Home > Code > Calling Pointers in VB6

Calling Pointers in VB6

Option Explicit

Private Type SUBROUTINE
    lNull           As Long '// Must be 0
    lPtr            As Long
End Type

Private Declare Function GoSubReturn Lib "MSVBVM60" Alias "__vbaGosubReturn" (ByRef lpSubRoutine As Long) As Long

'---------------------------------------------------------------------------------------
' Procedure : GoToPtr
' Author    : Karcrack
' Date      : 08/05/2010
' Purpose   : GoTo a pointer
' Warning   : It's not a JMP, is a GoTo, so the execution of the program won't continue
'           where you made the GoTo...
'---------------------------------------------------------------------------------------
'
Public Sub GoToPtr(ByVal lPtr As Long)
    Dim tSubRoutine As SUBROUTINE

    tSubRoutine.lPtr = lPtr
    Call GoSubReturn(VarPtr(tSubRoutine))
End Sub

Due some problems with Stack you won’t be able to return the place you call this function… So generally you will need to close process in the code pointed by lPtr :)

Example:

Sub Main()
    Call GoToPtr(gP(AddressOf RMain))
End Sub

Function gP(ByVal lPtr As Long) As Long
    gP = lPtr
End Function

Sub RMain()
    MsgBox "Hi!"
    End
End Sub
Categories: Code
  1. May 8th, 2010 at 15:30 | #1

    Really good source, Ive been looking for a way to do this without the classic stuff, callwindowproc or vtable patch and this looks really good. Great work!

  2. May 9th, 2010 at 14:30 | #2

    thanks This i verry Good stuff

  3. hideabone
    May 16th, 2010 at 04:10 | #3

    Awesome, i wll use this in one packer.

  1. No trackbacks yet.
You must be logged in to post a comment.