elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Obtener puntero de funcion dentro de un form o class.
0 Usuarios y 2 Visitantes están viendo este tema.
Páginas: 1 2 [3] Ir Abajo Respuesta Imprimir
Autor Tema: Obtener puntero de funcion dentro de un form o class.  (Leído 10,062 veces)
LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
Re: Obtener puntero de funcion dentro de un form o class.
« Respuesta #20 en: 8 Mayo 2011, 09:30 am »

Hola BlackZeroX si funciona quizas lo probaste con un STATIC y no recibe el WM_MouseMove proba con BUTTON

Class1
Código:
Option Explicit
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function SetWindowLongA Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProcA Lib "user32" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const GWL_WNDPROC As Long = -4
Private Const WM_DESTROY As Long = &H2
 
Private PrevWndProc As Long
Private bvASM(40) As Byte

Private Declare Function DestroyWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Const WS_VISIBLE As Long = &H10000000
Private mWnd As Long

Public Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    WindowProc = CallWindowProcA(PrevWndProc, hwnd, Msg, wParam, lParam)
 
    If Msg = WM_DESTROY Then
        Call StopSubclassing(hwnd)
    End If
   
    Debug.Print Msg, wParam, lParam
End Function
 
Private Sub SetSubclassing(Obj As Object, hwnd As Long)
    Dim WindowProcAddress As Long
    Dim pObj As Long
    Dim pVar As Long
 
    Dim i As Long
 
    For i = 0 To 40
        bvASM(i) = Choose(i + 1, &H55, &H8B, &HEC, &H83, &HC4, &HFC, &H8D, &H45, &HFC, &H50, &HFF, &H75, &H14, _
                                 &HFF, &H75, &H10, &HFF, &H75, &HC, &HFF, &H75, &H8, &H68, &H0, &H0, &H0, &H0, _
                                 &HB8, &H0, &H0, &H0, &H0, &HFF, &HD0, &H8B, &H45, &HFC, &HC9, &HC2, &H10, &H0)
    Next i
 
    pObj = ObjPtr(Obj)
 
    Call CopyMemory(pVar, ByVal pObj, 4)
    Call CopyMemory(WindowProcAddress, ByVal (pVar + 28), 4)
 
    Call LongToByte(pObj, bvASM, 23)
    Call LongToByte(WindowProcAddress, bvASM, 28)
 
    PrevWndProc = SetWindowLongA(hwnd, GWL_WNDPROC, VarPtr(bvASM(0)))
End Sub
 
Private Sub StopSubclassing(hwnd)
    Call SetWindowLongA(hwnd, GWL_WNDPROC, PrevWndProc)
End Sub
 
Private Sub LongToByte(ByVal lLong As Long, ByRef bReturn() As Byte, Optional i As Integer = 0)
    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
End Sub

Private Sub Class_Initialize()
    mWnd = CreateWindowEx(0&, "Button", "Hola Mundo", WS_VISIBLE, 0&, 0&, 300, 300, 0&, 0&, App.hInstance, ByVal 0&)
    If mWnd <> 0 Then Call SetSubclassing(Me, mWnd)
End Sub

Private Sub Class_Terminate()
    If mWnd <> 0 Then
        Call StopSubclassing(mWnd)
        DestroyWindow mWnd
    End If
End Sub

Saludos.


En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.148


I'Love...!¡.


Ver Perfil WWW
Re: Obtener puntero de funcion dentro de un form o class.
« Respuesta #21 en: 8 Mayo 2011, 11:11 am »

...
Edito:

Cuando declaro algunas cosas mas crashea  >:D... ya encontre el horror, es que el ASM modifica la 1ra cosa publica y como tenia una variable publica pues crasheaba ya que no era mi WinProc...

Código
  1.  
  2. Dim c As Class1
  3. Private Sub Form_Load()
  4.    Set c = New Class1
  5. End Sub
  6.  
  7.  

Código
  1.  
  2. Option Explicit
  3.  
  4. Private Const GWL_WNDPROC                   As Long = -4
  5. Private Const WM_DESTROY                    As Long = &H2
  6. Private Const WS_VISIBLE                    As Long = &H10000000
  7. Private Const MAX_PATH                      As Integer = 260
  8. Private Const MAXDWORD                      As Long = &HFFFF
  9. Private Const INVALID_HANDLE_VALUE          As Long = -1
  10.  
  11. Private Type FILETIME
  12.    dwLowDateTime                           As Long
  13.    dwHighDateTime                          As Long
  14. End Type
  15.  
  16. Private Type WIN32_FIND_DATA                                        '// Bytes...
  17.    dwFileAttributes                        As Long                 '// 4
  18.    ftCreationTime                          As FILETIME             '// 8
  19.    ftLastAccessTime                        As FILETIME             '// 8
  20.    ftLastWriteTime                         As FILETIME             '// 8
  21.    nFileSizeHigh                           As Long                 '// 4
  22.    nFileSizeLow                            As Long                 '// 4
  23.    dwReserved0                             As Long                 '// 4
  24.    dwReserved1                             As Long                 '// 4
  25.    cFileName                               As String * MAX_PATH    '// MAX_PATH*2 = 260*2 = 520
  26.    cAlternate                              As String * 14          '// 14*2 = 28
  27. End Type                                                            '// total bytes: 592 bytes...  = &H250
  28.  
  29. Private Declare Function WaitMessage Lib "user32" () As Long
  30. Private Declare Function lstrcmp Lib "KERNEL32" Alias "lstrcmpA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
  31. Private Declare Function FindFirstFile& Lib "KERNEL32" Alias "FindFirstFileA" (ByVal lpFileName$, lpFindFileData As WIN32_FIND_DATA)
  32. Private Declare Function FindNextFile& Lib "KERNEL32" Alias "FindNextFileA" (ByVal hFindFile&, lpFindFileData As WIN32_FIND_DATA)
  33. Private Declare Function GetFileAttributes Lib "KERNEL32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
  34. Private Declare Function FindClose Lib "KERNEL32" (ByVal hFindFile As Long) As Long
  35.  
  36. '   //  SubClassing
  37. Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
  38. Private Declare Function SetWindowLongA Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  39. Private Declare Function CallWindowProcA Lib "user32" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  40. Private Declare Function DestroyWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
  41. Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
  42.  
  43. Private bIni                                As Boolean
  44. Private sDir                                As String
  45. Private sCriterios()                        As String
  46. Private bIncludeFolders                     As Boolean
  47. Private bCancel                             As Boolean
  48. Private tVBFAFoundInDir                     As VbFileAttribute
  49. Private tVBFAFoundInFile                    As VbFileAttribute
  50. Private lhSearchF()                         As Long
  51. Private lsIndex(0 To 1)                     As Long
  52. Private dblBytesNow_                        As Double
  53. Private tWFDFound                           As WIN32_FIND_DATA
  54. Private bRun                                As Boolean
  55. Private bFound                              As Boolean
  56. Private bPause                              As Boolean
  57. 'public AllowEvents                        As Boolean ' // No pongan nada en modo publico xS.
  58. private bAllowEvents                        As Boolean ' // No pongan nada en modo publico xS.
  59.  
  60. Private PrevWndProc                         As Long
  61. Private bvASM(40)                           As Byte
  62. Private mWnd                                As Long
  63.  
  64. Event Folder(ByRef PathFolder As String)
  65. Event File(ByVal TypeOfFile As Long)
  66. Event Begin()
  67. Event Finish()
  68.  
  69. Public Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  70.    WindowProc = CallWindowProcA(PrevWndProc, hwnd, Msg, wParam, lParam)
  71.  
  72.    If Msg = WM_DESTROY Then
  73.        Call StopSubclassing(hwnd)
  74.    End If
  75.  
  76.    Debug.Print Msg, wParam, lParam
  77. End Function
  78.  
  79. Private Sub SetSubclassing(Obj As Object, hwnd As Long)
  80.    Dim WindowProcAddress As Long
  81.    Dim pObj As Long
  82.    Dim pVar As Long
  83.  
  84.    Dim i As Long
  85.  
  86.    For i = 0 To 40
  87.        bvASM(i) = Choose(i + 1, &H55, &H8B, &HEC, &H83, &HC4, &HFC, &H8D, &H45, &HFC, &H50, &HFF, &H75, &H14, _
  88.                                 &HFF, &H75, &H10, &HFF, &H75, &HC, &HFF, &H75, &H8, &H68, &H0, &H0, &H0, &H0, _
  89.                                 &HB8, &H0, &H0, &H0, &H0, &HFF, &HD0, &H8B, &H45, &HFC, &HC9, &HC2, &H10, &H0)
  90.    Next i
  91.  
  92.    pObj = ObjPtr(Obj)
  93.  
  94.    Call CopyMemory(pVar, ByVal pObj, 4)
  95.    Call CopyMemory(WindowProcAddress, ByVal (pVar + 28), 4)
  96.  
  97.    Call LongToByte(pObj, bvASM, 23)
  98.    Call LongToByte(WindowProcAddress, bvASM, 28)
  99.  
  100.    PrevWndProc = SetWindowLongA(hwnd, GWL_WNDPROC, VarPtr(bvASM(0)))
  101. End Sub
  102.  
  103. Private Sub StopSubclassing(hwnd)
  104.    Call SetWindowLongA(hwnd, GWL_WNDPROC, PrevWndProc)
  105. End Sub
  106.  
  107. Private Sub LongToByte(ByVal lLong As Long, ByRef bReturn() As Byte, Optional i As Integer = 0)
  108.    bReturn(i) = lLong And &HFF
  109.    bReturn(i + 1) = (lLong And 65280) / &H100
  110.    bReturn(i + 2) = (lLong And &HFF0000) / &H10000
  111.    bReturn(i + 3) = ((lLong And &HFF000000) \ &H1000000) And &HFF
  112. End Sub
  113.  
  114. Private Sub Class_Initialize()
  115.    mWnd = CreateWindowEx(0&, "Button", "Hola Mundo", WS_VISIBLE, 0&, 0&, 300, 300, 0&, 0&, App.hInstance, ByVal 0&)
  116.    If mWnd <> 0 Then Call SetSubclassing(Me, mWnd)
  117. End Sub
  118.  
  119. Private Sub Class_Terminate()
  120.    If mWnd <> 0 Then
  121.        Call StopSubclassing(mWnd)
  122.        DestroyWindow mWnd
  123.    End If
  124. End Sub
  125.  
  126.  

Temibles Lunas!¡.


« Última modificación: 8 Mayo 2011, 11:36 am por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
F3B14N

Desconectado Desconectado

Mensajes: 47


Ver Perfil
Re: Obtener puntero de funcion dentro de un form o class.
« Respuesta #22 en: 8 Mayo 2011, 18:53 pm »

En modulos clase:

Call CopyMemory(WindowProcAddress, ByVal (pVar + &H1C + (ProcIndex * 4&)), 4)
En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.148


I'Love...!¡.


Ver Perfil WWW
Re: Obtener puntero de funcion dentro de un form o class.
« Respuesta #23 en: 8 Mayo 2011, 20:25 pm »

En modulos clase:

Call CopyMemory(WindowProcAddress, ByVal (pVar + &H1C + (ProcIndex * 4&)), 4)

excelente con el ProcIndex podremos hacer varias subclasificaciones con el codigo xD

Dulces Lunas!¡.
En línea

The Dark Shadow is my passion.
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.148


I'Love...!¡.


Ver Perfil WWW
Re: Obtener puntero de funcion dentro de un form o class.
« Respuesta #24 en: 9 Mayo 2011, 05:52 am »

alguien tiene el ASM?, quiero ver que es lo que modifica/hace.

Dulces Lunas!¡.
En línea

The Dark Shadow is my passion.
Páginas: 1 2 [3] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
puntero a funcion
Programación C/C++
kondrag_X1 2 2,626 Último mensaje 30 Abril 2011, 19:49 pm
por leogtz
F1 - Problema con puntero a Función C#
.NET (C#, VB.NET, ASP)
Maurice_Lupin 0 1,511 Último mensaje 17 Mayo 2012, 16:14 pm
por Maurice_Lupin
Como obtener posicion mouse dentro de scrollpane?
Java
juancaa 2 2,878 Último mensaje 25 Junio 2012, 11:44 am
por juancaa
copiar contenido dentro de un div class con webbrowser?
.NET (C#, VB.NET, ASP)
housedir 1 2,049 Último mensaje 6 Agosto 2012, 22:58 pm
por seba123neo
[Resuelto] Obtener dentro de función referencia a llamante
PHP
Usuario Invitado 2 1,236 Último mensaje 20 Enero 2015, 20:37 pm
por Usuario Invitado
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines