• CallAPI ( ASM in Line ) para Drinky.

 #293379  por BlackZeroX
 09 May 2011, 01:35
.
Amigo aquí te dejo el código por el cual nos esta-vamos peleando arduamente.

Tu Codigoe era este:
Código: [ Debe registrarse para ver este enlace ]

Option Explicit
Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "USER32" Alias "CallWindowProcW" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 
Private Sub form_load()
    Dim ASM() As Long
 
    ASM(0) = &H68 'push 0
    ASM(1) = &H0
    
    ASM(2) = &H68 'push 0
    ASM(3) = &H0
    
    ASM(4) = &H68 'push 0
    ASM(5) = &H0
    
    ASM(6) = &H68 'push 0
    ASM(7) = &H0
    
    ASM(8) = &HE8 'Call
    
    ASM(9) = GetProcAddress(LoadLibrary("user32.dll"), "MessageBoxA") ' direccion de la api.
    
    CallWindowProc VarPtr(ASM()), 0&, 0&, 0&, 0& 'ejecutamos.
End Sub

y aquí el corregido, como ves solo son opcodes, recuerda que los punteros en arquitectura de 32 bytes es de 4 bytes y en la de 64 es de 8 bytes. ya que tu error radicaba en que llamabas a punteros de 1 byte que en si no existen si por ende leía la computadora 4 bytes y como no era un código completo y formado adecuadamente crasheaba.
Código: [ Debe registrarse para ver este enlace ]

Option Explicit

Private Type tlong
    l As Long
End Type

Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32.dll" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallWindowProc Lib "USER32" Alias "CallWindowProcW" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 
Private Sub form_load()
Dim bASM(0 To 27)           As Byte
Dim i                       As Integer
Dim sMsg                    As String
Dim sTitulo                 As String

    sMsg = "Hola Mundo"
    sTitulo = "Titulo de un msgbox"

    i = 0
    bASM(i) = &H68: i = LongToByte(vbYesNoCancel, bASM(), i + 1) ' 5 bytes
    bASM(i) = &H68: i = LongToByte(StrPtr(sTitulo), bASM(), i + 1)' 5 bytes
    bASM(i) = &H68: i = LongToByte(StrPtr(sMsg), bASM(), i + 1)' 5 bytes
    bASM(i) = &H68: i = LongToByte(&H0, bASM(), i + 1)' 5 bytes
    bASM(i) = &HB8: i = LongToByte(GetProcAddress(LoadLibrary("user32.dll"), "MessageBoxW"), bASM(), i + 1)' 5 bytes
    bASM(i) = &HFF: i = i + 1' 1 bytes
    bASM(i) = &HD0: i = i + 1' 1 bytes
    bASM(i) = &HC3: i = i + 1' 1 bytes
    MsgBox CallWindowProc(ByVal VarPtr(bASM(0)), 0&, 0&, 0&, 0&)                             'ejecutamos.
End Sub

Private Function LongToByte(ByVal lLong As Long, ByRef bReturn() As Byte, Optional i As Integer = 0) As Long
    bReturn(i) = lLong And &HFF
    bReturn(i + 1) = (lLong And 65280) / &H100
    bReturn(i + 2) = (lLong And &HFF0000) / &H10000
    bReturn(i + 3) = ((lLong And &HFF000000) \ &H1000000) And &HFF
    LongToByte = i + 4
End Function

Temibles Lunas!¡.
.