VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 如何获得屏幕保护程序的密码
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:10226, 日期:2001-12-18
如果屏幕保护程序设置了密码,密码将被加密,然后写到注册表的“HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSave_Data”位置。屏保密码的最大长度为128位。加密方式是将密码与一特定字符串异或后得到密文,经过参考有关资料,笔者利用VB成功地破解了屏保的密码。
一、源程序
注释:通用声明
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
注释:加密和解密所用的字符串
Const Key = "48EE761D6769A11B7A8C47F85495975F78D9DA6C59D76B35C57785182A0E52FF00
E31B718D3463EB91C3240FB7C2F8E3B6544C3554E7C94928A385110B2C68FBEE7DF66CE39C2DE47
2C3BB851A123C32E36B4F4DF4A924C8FA78AD23A1E46D9A04CE2BC5B6C5EF935CA8852B413772FA
574541A1204F80B3D52302643F6CF10F"
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ = 1
Private Const KEY_READ = &H20019
注释:自定义函数,找到屏保密码
Public Function GetScreenSaverPwd() As String
Dim EncryptedPassword As String
Dim DecryptedPassword As String
Dim lngResult As Long
Dim lngHandle As Long
Dim lngcbData As Long
Dim strRetVal As String
注释:从注册表中读取已经加密的屏保密码
RegOpenKeyEx HKEY_CURRENT_USER, "Control Panel\desktop", 0&, KEY_READ, lngHandle
RegQueryValueEx lngHandle, "ScreenSave_Data", 0&, lngType, ByVal strRetVal, lngcbData
strRetVal = Space(lngcbData)
lngResult = RegQueryValueEx(lngHandle, "ScreenSave_Data", 0&, lngType, ByVal strRetVal, lngcbData)
RegCloseKey (lngHandle)
EncryptedPassword = strRetVal
注释:解密,得到密码
On Error Resume Next

If Len(EncryptedPassword) <> 1 Then
EncryptedPassword = Left$(EncryptedPassword, Len(EncryptedPassword) - 1)
注释:每2位与Key进行异或运算,得到密码
For i = 1 To Len(EncryptedPassword) Step 2
DecryptedPassword = DecryptedPassword & Chr(Val("&H" & (Mid(EncryptedPassword, i, 2))) Xor Val("&H" & (Mid(Key, i, 2))))
Next i
GetScreenSaverPwd = DecryptedPassword
Else
GetScreenSaverPwd = ""
End If
If GetScreenSaverPwd = "" Then GetScreenSaverPwd = "未设置屏保密码。"
End Function
注释:调用函数,有密码则显示,没有密码则提示。
Private Sub Command1_Click()
Label2.Caption = Len(GetScreenSaverPwd)
Text1.Text = GetScreenSaverPwd
End Sub

Private Sub Command2_Click()
Unload Me
End Sub
二、运行结果

该程序在Windows98,VB6.0中调试通过,点击这里下载程序。