Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: .:Weeds:. en 10 Agosto 2013, 02:28 am



Título: Detectar tipo de teclado
Publicado por: .:Weeds:. en 10 Agosto 2013, 02:28 am
Bueno estoy trabajando en un keylogger y funciona todo a la perfección, pero investigando el tema me he dado cuenta que no todos los teclados son iguales.
Código:
http://es.wikipedia.org/wiki/Teclado_QWERTY
Mi duda es como puedo detectar que tipo de teclado es de forma limpia. Alguno de vosotros tal vez sabe algo del tema por que ya se le haya planteado la cuestión.

Código
  1. Keys.OemOpenBrackets

Esto en el teclado ingles da este valor [, pero en el teclado español da este '. Para que me entendais mejor.

Saludos y gracias.


Título: Re: Detectar tipo de teclado
Publicado por: raul338 en 10 Agosto 2013, 02:50 am
Que metodo utilizas para obtener las entradas? Quizás se pueda partir de ahí


Título: Re: Detectar tipo de teclado
Publicado por: .:Weeds:. en 10 Agosto 2013, 03:27 am
DLL
Código
  1.        Private Declare Function CallNextHookEx Lib "user32" _
  2.        (ByVal hHook As Integer, _
  3.        ByVal nCode As Integer, _
  4.        ByVal wParam As Integer, _
  5.        ByVal lParam As KBDLLHOOKSTRUCT) As Integer

Funcion
Código
  1.        Private Shared Function KeyboardProc(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
  2.            If (nCode = HC_ACTION) Then
  3.                Select Case wParam
  4.                    Case WM_KEYDOWN, WM_SYSKEYDOWN
  5.                        RaiseEvent KeyDown(CType(lParam.vkCode, Keys))
  6.                    Case WM_KEYUP, WM_SYSKEYUP
  7.                        RaiseEvent KeyUp(CType(lParam.vkCode, Keys))
  8.                End Select
  9.            End If
  10.            Return CallNextHookEx(KeyHook, nCode, wParam, lParam)
  11.        End Function

Lo tipico vamos.. xD

Saludos.


Título: Re: Detectar tipo de teclado
Publicado por: Eleкtro en 10 Agosto 2013, 09:54 am
Siento decirte que según mis informaciones es símplemente imposible hacerlo en VBNET (al menos usando un hook de bajo nivel como haces),
es más, si quisieras hacerlo en otro lenguaje necesitarías pasar a un siguiente nivel muy superior de experiencia para escribir el hook, inyectarlo, hacerlo compatible con 64 bits, y bypassear UAC.

Intenté solucionar el mismo problema, pero mis capacidades para esto son igual de limitadas e inexpertas, te cito la respuesta a mi problema por parte de un Dios de la programación, para que lo entiendas mejor:

Cita de: Hans Passant
You can never write a correct low-level keyboard hook that translates virtual keys to typing keys. The keyboard state and the active keyboard layout are properties of the process that owns the foreground window. Never of the process that implements the hook.

In particular the keyboard state will be wrong, you don't know if the logical state of the keyboard for the process has the shift, alt, control and Windows key active. That state is recorded when the program receives a keyboard event. Particular to a keyboard layout for languages that use diacritics are the state of the dead keys, the ones you type to get the next typed letter to have an accent. This keyboard state is a per-process state and cannot be retrieved from another process. It is only discoverable within the process itself, GetKeyboardState() function. Much the same for the active keyboard layout, GetKeyboardLayout() function. The language bar allows processes to use different layouts.

It can only ever work 100% correctly when you use a WH_KEYBOARD hook. It requires a DLL that can be injected into other processes. The 3rd argument of SetWindowsHookEx(). Which ensures that GetKeyboardState and GetKeyboardLayout return accurate information. You cannot write such a DLL in VB.NET, the process you inject won't have the CLR loaded to execute managed code. A language like C, C++ or Delphi is required, languages that have very modest runtime support requirements. This is usually where the project peters out. Not just because of the runtime injection problem, debugging such code and dealing with the bitness of a process on a 64-bit operating system as well as UAC are major headaches.

You can limp along somewhat by using GetAsyncKeyState() to get the state of the modifier keys. There is no solution for dead keys other than an injected DLL. This is not a helpful answer, it merely explains why you can never make it work completely reliably in vb.net.

The mapping of Keys.Oemtilde to a typing key is the job of the keyboard layout. Different keyboards produce different letters for that key. The underlying winapi function is ToUnicodeEx(). Note how it requires the keyboard state and layout as I described.

Si quieres leer el resto: http://stackoverflow.com/questions/16893190/issue-with-the-keys-enumeration-and-a-low-level-keyboard-hook#comment24389665_16900034

EDITO: y esto por otra parte para aclarártelo aún más:

Citar
A global WH_KEYBOARD hook however executes in teh context of the app. that is recieving the keyboard message so your code has to be injected into every running process. This is NOT a good idea IMHO.

Saludos


Título: Re: Detectar tipo de teclado
Publicado por: .:Weeds:. en 10 Agosto 2013, 10:57 am
Gracias electro, me temia algo asi. En la programación siempre pasa algo asi  :xD, pero bueno mi próximo lenguaje es delphi y ahi ya intentare hacer cosas mas serias en cuanto a virus se refiera.

De todas formas para el uso que le voi a dar me sobra, normalmente casi todos los teclados tienen distribución QWERTY (por lo menos en españa), y simplemente quiero que funcione en américa latina y españa. Mi duda es donde se almacena en windows el idioma del teclado, así yo en función de cual sea le doi un valor a la tecla, total es para sacar cuentas de un jueguecillo. También me asalta la duda de que pasaria si hubiera dos teclados conectados jaja.

Posdata: Este es mi mensaje 100 jaja, llevo aqui desde el 2007 (tenia 14 años), y soñaba con hacer troyanos y 'super virus destructivos', que tiempos, ahora que ya lo veo mas factible paso del tema jajajaj, como cambian las cosas.

Saludos!