ASM en VB6 [Respuesta a Myserik]

Iniciado por BlackZeroX, 9 Junio 2011, 09:17 AM

0 Miembros y 1 Visitante están viendo este tema.

BlackZeroX

.
el código lo pongo publico ya que a mas de a uno le interese a la larga, no soy experto en ASM pero bueno.

Código (vb) [Seleccionar]


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 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"

    '   Cada Instruccion pesa {1 Bytes} y el numero de "_" son la cantidad de bytes esperados habitualmente si son 4 es que sea normalmente un puntero, pero eso depende del formato de la instruccion.
    '   Para informacion de los OpCodes:
    '   //  http://ref.x86asm.net/geek.html
    '   PUSH ____
    '   PUSH ____
    '   PUSH ____
    '   PUSH ____
    '   MOV EAX, ____
    '   CALL EAX
    '   RET
    i = 0
    bASM(i) = &H68: i = LongToByte(vbYesNoCancel, bASM(), i + 1)    ' PUSH {vbYesNoCancel}      5 bytes ( 1(&H68) + long(vbYesNoCancel) ).
    bASM(i) = &H68: i = LongToByte(StrPtr(sTitulo), bASM(), i + 1)  ' PUSH {StrPtr(sTitulo)}    5 bytes ( 1(&H68) + long(StrPtr(sTitulo)) )..
    bASM(i) = &H68: i = LongToByte(StrPtr(sMsg), bASM(), i + 1)     ' PUSH {StrPtr(sMsg)}       5 bytes ( 1(&H68) + long(StrPtr(sMsg)) )..
    bASM(i) = &H68: i = LongToByte(&H0, bASM(), i + 1)              ' PUSH {&H0}                5 bytes ( 1(&H68) + long(&H0) )..
   
    ' MOV {EAX},{LongToByte(GetProcAddress(LoadLibrary("user32.dll"), "MessageBoxW")}
    bASM(i) = &HB8: i = LongToByte(GetProcAddress(LoadLibrary("user32.dll"), "MessageBoxW"), bASM(), i + 1) ' 5 bytes
    bASM(i) = &HFF: i = i + 1 ' CALL ___    1 bytes
    bASM(i) = &HD0: i = i + 1 ' EAX         1 bytes
    bASM(i) = &HC3: i = i + 1 ' RET         1 bytes
    MsgBox CallWindowProc(ByVal VarPtr(bASM(0)), 0&, 0&, 0&, 0&)    ' Run ASM
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 &HFF00&) \ &H100
    bReturn(i + 2) = (lLong And &HFF0000) \ &H10000
    bReturn(i + 3) = (lLong And &HFF000000) \ &H1000000
    LongToByte = i + 4
End Function



Dulces Lunas!¡.
The Dark Shadow is my passion.

BlackZeroX

.
Solo agrego lo siguiente.

Código (Vb) [Seleccionar]


    '   Cada Instruccion pesa {1 Bytes} y el numero de "_" son la cantidad de bytes esperados habitualmente si son 4 es que sea normalmente un puntero, pero eso depende del formato de la instruccion.
    '   Para informacion de los OpCodes:
    '   //  http://ref.x86asm.net/geek.html
    '   PUSH ____
    '   PUSH ____
    '   PUSH ____
    '   PUSH ____
    '   MOV EAX, ____
    '   CALL EAX
    '   RET



Dulces Lunas!¡.
The Dark Shadow is my passion.

raul338

Al menos podrias poner un link al tema de donde venia (si es que no fue para revivirlo) para asi todos podamos entender de que se trataba :P

Miseryk

:D:D:D gracias, lo había pensado así pero no agregar al array el GetProc, a veces la respuesta suele ser como uno la piensa :P. Gracias (Y)(Y)(Y)
Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It's never too late to change our luck
So, don't let them steal your light
Don't let them break your stride
There is light on the other side
And you'll see all the raindrops falling behind
Make it out tonight
it's a revolution

CL!!!