Título: Inyectar Dll?
Publicado por: Keyen Night en 26 Diciembre 2009, 19:04 pm
Hice está función para inyección de una dll en un proceso pero cuando la llamo el proceso a inyectar da error y se cierra, que está mal? Public Function InyectDLL(ByVal Dll As String, ByVal PID As Integer) As Boolean On Error GoTo 0 Dim Buffer1 As Integer, _ Buffer2 As Integer, _ OpenedP As Integer = OpenProcess(PROCESS_ALL_ACCESS, False, PID), _ AddressP As Integer = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryW"), _ rems As Integer = VirtualAllocEx(OpenedP, 0, Len(Dll), MEM_COMMIT, PAGE_READWRITE) WriteProcessMemory(OpenedP, rems, Dll, Len(Dll), Buffer2) CreateRemoteThread(OpenedP, 0, 0, AddressP, rems, 0, Buffer1) WaitForSingleObject(rems, &HFFFFFF) CloseHandle(OpenedP) : CloseHandle(rems) Return True End Function
Título: Re: Inyectar Dll?
Publicado por: raul338 en 26 Diciembre 2009, 20:34 pm
Esa funcion funcionaria para vb6 no? Intentaste depurar? que error te da?
Título: Re: Inyectar Dll?
Publicado por: seba123neo en 26 Diciembre 2009, 22:58 pm
puede ser que tengas mal declaradas los tipos de datos de las api's, pone todo el codigo.
Título: Re: Inyectar Dll?
Publicado por: Keyen Night en 26 Diciembre 2009, 23:11 pm
Const PAGE_READWRITE As Integer = &H4 Const MEM_RELEASE As Integer = &H8000 Const MEM_COMMIT As Integer = &H1000 Const STANDARD_RIGHTS_REQUIRED As Integer = &HF0000 Const SYNCHRONIZE As Integer = &H100000 Const PROCESS_VM_READ As Integer = &H10 Const PROCESS_VM_WRITE As Integer = (&H20) Const PROCESS_VM_OPERATION As Integer = (&H8) Const PROCESS_QUERY_INFORMATION As Integer = (&H400) Const PROCESS_READ_WRITE_QUERY As Integer = PROCESS_VM_READ + PROCESS_VM_WRITE + PROCESS_VM_OPERATION + PROCESS_QUERY_INFORMATION Const PROCESS_ALL_ACCESS As Integer = &H1F0FFF Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Integer, ByVal lpProcName As String) As Integer Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Integer Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Integer, ByVal lpAddress As Integer, ByVal dwSize As Integer, ByVal flAllocationType As Integer, ByVal flProtect As Integer) As Integer Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Integer, ByVal lpBaseAddress As Object, ByVal lpBuffer As Object, ByVal nSize As Integer, ByVal lpNumberOfBytesWritten As Integer) As Integer Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Integer, ByVal lpThreadAttributes As Integer, ByVal dwStackSize As Integer, ByVal lpStartAddress As Integer, ByVal lpParameter As Object, ByVal dwCreationFlags As Integer, ByVal lpThreadId As Integer) As Integer Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Integer, ByVal dwMilliseconds As Integer) As Integer Public Function InyectDLL(ByVal Dll As String, ByVal PID As Integer) As Boolean On Error GoTo 0 Dim Buffer1 As Integer, _ Buffer2 As Integer, _ OpenedP As Integer = OpenProcess(PROCESS_ALL_ACCESS, False, PID), _ AddressP As Integer = GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryW"), _ rems As Integer = VirtualAllocEx(OpenedP, 0, Len(Dll), MEM_COMMIT, PAGE_READWRITE) WriteProcessMemory(OpenedP, rems, Dll, Len(Dll), Buffer2) CreateRemoteThread(OpenedP, 0, 0, AddressP, rems, 0, Buffer1) WaitForSingleObject(rems, &HFFFFFF) CloseHandle(OpenedP) : CloseHandle(rems) Return True End Function
Título: Re: Inyectar Dll?
Publicado por: raul338 en 26 Diciembre 2009, 23:17 pm
Eso esta en "formato" vb6, reemplaza esas declaraciones API por las que aparecen en esta pagina http://www.pinvoke.net/ (http://www.pinvoke.net/) No uses la funcion "Len()" usa "String.Length"
Si vas a programar en .net, hazlo al estilo de .net, no al de vb6 ;-)
Título: Re: Inyectar Dll?
Publicado por: Keyen Night en 26 Diciembre 2009, 23:26 pm
Yo he hecho esto siempre así y siempre ha funcionado ._. uso Microsoft Visual Basic 2008 Exprres Edition Tambien cabe destacar que esto siempre me ha confundido siempre dicen que asi no se declara y no entiendo porque ya que siempre me ha funcionado.
pd: Yo aún no estudio esto me falta 1 año para entrar a la universidad.
Título: Re: Inyectar Dll?
Publicado por: raul338 en 26 Diciembre 2009, 23:31 pm
De funcionar funciona, pero no debe usarse asi, es mala practica
Si no funciona intenta depurando, mejora las declaraciones y fijate las salidas de las API, cualquier cosa intenta con GetLastError :P
|