Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: x64core en 27 Junio 2011, 22:31 pm



Título: [Sources code] Obtener Path de un programa con el handle de ventana
Publicado por: x64core en 27 Junio 2011, 22:31 pm
Hola buenas panas!  ;D
bueno aqui aportando al foro por todo lo que me han ayudado todos por mis dudas  :xD tambien quiero ayudar  :xD
este sources hecho por mi es sencillo es para obtener la ruta de un programa por medio del handle de la ventana:

es sencillo perdon por cualquier error que tenga  :P

Ejemplo de uso:

Código:
msgbox PathEXEWindow(Win) ' donde Win es el handle de la ventana

Código
  1. Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
  2. Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
  3. Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  4. Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  5.  
  6.  
  7. Private Const PROCESS_ALL_ACCESS  As Long = &H1F0FFF
  8. Private Const MAX_PATH = 260
  9.  
  10. '------------------------------------------------------------------------------------------
  11. ' FUNCION: _
  12. -------------------------------------------------------------------------------------------
  13.  
  14.  
  15. Function PathEXEWindow(HndW As Long) As String
  16. Dim IDp As Long, HandleProcess As Long
  17. Dim Bufpath As String, LenBuf As Long
  18.  
  19. Call GetWindowThreadProcessId(HndW, IDp)
  20.  
  21. HandleProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, IDp)
  22.  
  23. Bufpath = String$(MAX_PATH, Chr$(0))
  24. LenBuf = MAX_PATH
  25.  
  26. If 0 = GetModuleFileNameExA(HandleProcess, 0, Bufpath, LenBuf) Then
  27.    MsgBox "No se puede obtener la ruta del proceso Verifique los valores", vbCritical
  28.    Exit Function
  29. End If
  30.  
  31. PathEXEWindow = Left(Bufpath, LenBuf)
  32. Call CloseHandle(HandleProcess)
  33. End Function

espero que les guste y mas que les sirva  ;D


Título: Re: [Sources code] Obtener Path de un programa con el handle de ventana
Publicado por: BlackZeroX en 28 Junio 2011, 03:19 am
.
Solo lo ordene y le añadi una funcion...

Código
  1.  
  2.  
  3. Option Explicit
  4.  
  5. Private Const PROCESS_QUERY_INFORMATION As Long = (&H400)
  6. Private Const PROCESS_VM_READ           As Long = (&H10)
  7.  
  8. Private Const MAX_PATH                  As Long = 260
  9.  
  10. Enum GetFileStr
  11.     Extensión = 1
  12.     FileName = 2
  13.     Ruta = 4
  14. End Enum
  15.  
  16. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
  17. Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
  18. Private Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)
  19. Private Declare Function GetModuleFileNameExA Lib "PSAPI.DLL" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As Long
  20.  
  21. Private Sub Form_Load()
  22.    MsgBox GetPatchInfohwnd(Me.hwnd, FileName + Extensión)
  23.    MsgBox GetPatchInfohwnd(Me.hwnd, Ruta Or Extensión)
  24.    MsgBox GetPatchInfohwnd(Me.hwnd, Ruta Or Extensión Or FileName)
  25. End Sub
  26.  
  27. ' ////////////////////////////////////////////////////////////////
  28. ' // http://infrangelux.hostei.com/index.php?option=com_content&view=article&id=17:artgetpatchinfo&catid=2:catprocmanager&Itemid=8
  29. ' ////////////////////////////////////////////////////////////////
  30. Public Function GetPatchInfo(ByRef StrRutaFull As String, Optional ByVal Options As GetFileStr = FileName) As String
  31. Dim lng_ptr(1)              As Long
  32. Dim lng_aux                 As Long
  33.     lng_aux = Len(StrRutaFull)
  34.     lng_ptr(0) = InStrRev(StrRutaFull, "\")
  35.     If lng_ptr(0) > 0 Then
  36.         lng_ptr(1) = InStrRev(StrRutaFull, ".")
  37.         If lng_ptr(1) > 0 And Not lng_ptr(0) < lng_ptr(1) Then
  38.             lng_ptr(1) = lng_aux + 1
  39.         End If
  40.         If (Options And Ruta) = Ruta Then
  41.             GetPatchInfo = Mid$(StrRutaFull, 1, lng_ptr(0)) & GetPatchInfo
  42.         End If
  43.         If (Options And FileName) = FileName Then
  44.             If lng_ptr(1) = lng_aux Then
  45.                 lng_aux = lng_aux - lng_ptr(0) - 1
  46.             Else
  47.                 lng_aux = lng_ptr(1) - lng_ptr(0) - 1
  48.             End If
  49.             GetPatchInfo = GetPatchInfo & Mid$(StrRutaFull, lng_ptr(0) + 1, lng_aux)
  50.         End If
  51.         If (Options And Extensi&#243;n) = Extensi&#243;n Then
  52.             GetPatchInfo = GetPatchInfo & Mid$(StrRutaFull, lng_ptr(1), lng_ptr(1))
  53.         End If
  54.     End If
  55. End Function
  56.  
  57. Public Function GetPatchInfohwnd(ByVal hwnd As Long, Optional GetDir As GetFileStr = Ruta) As String
  58. Dim PID     As Long
  59. Dim lProc   As Long
  60. Dim sTmp    As String * MAX_PATH
  61.  
  62.    If Not (GetWindowThreadProcessId(hwnd, PID) = 0) Then
  63.        lProc = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, PID)
  64.        If Not (lProc = 0) Then
  65.            GetPatchInfohwnd = GetPatchInfo(Mid$(sTmp, 1, GetModuleFileNameExA(lProc, 0, sTmp, MAX_PATH)), GetDir)
  66.            CloseHandle lProc
  67.        End If
  68.    End If
  69. End Function
  70.  
  71.  

Dulces Lunas!¡.


Título: Re: [Sources code] Obtener Path de un programa con el handle de ventana
Publicado por: CAR3S? en 28 Junio 2011, 05:08 am
buenisimo, cuando mi imaginacion se reactive, vere si lo uso :D


Título: Re: [Sources code] Obtener Path de un programa con el handle de ventana
Publicado por: Hasseds en 28 Junio 2011, 22:58 pm
Otra opción, no será la mas profesional, pero sí otra opción  :)

Código:

Option Explicit

Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Function PathExeWindow(ByVal hwnd As Long, ByRef sPath As String) As Long

  Dim HProc As Long, lngPid As Long, lnglen As Long, Bfpath As String * &H104
 
  Call GetWindowThreadProcessId(hwnd, lngPid)
  HProc = OpenProcess(&H410, &H0, lngPid)
  If HProc = 0 Then Exit Function
 
  lnglen = GetModuleFileNameExA(HProc, &H0, Bfpath, &H104)
  Call CloseHandle(HProc)
  If lnglen = 0 Then Exit Function
 
  sPath = Left$(Bfpath, lnglen)
  PathExeWindow = lnglen

End Function

Private Sub Form_Load()
 
  Dim sPath As String

  If PathExeWindow(hwnd, sPath) > 0 Then
    MsgBox sPath, , "sPath"
    MsgBox Mid$(sPath, 1, InStrRev(sPath, "\")), , "sDirectorio"
    MsgBox Mid$(sPath, InStrRev(sPath, "\") + 1), , "sFile"
    MsgBox Mid$(sPath, InStrRev(sPath, ".") + 1), , "sExtencion"
  End If

End Sub



Título: Re: [Sources code] Obtener Path de un programa con el handle de ventana
Publicado por: x64core en 29 Junio 2011, 10:19 am
buenoo!  :D