分享
 
 
 

小弟为共享软件作者制作的管理软件注册的动态链接库

王朝vb·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

小弟为共享软件作者制作的管理软件注册的动态链接库

作为共享软件作者,注册码被非法公布是件令你十分头疼的事情。小弟制作了这么一个类库。希望能有所帮助。它每次在RegestCheck被执行一遍的时候生成动态的用户名及密码,并保存入注册表。但软件已经注册的话则不改变原来的注册信息。所以,盗用注册码对它是没用的。

它有三个方法,四个属性。RegestCheck用来检查您的共享软件是否注册,Regest用来注册您的共享软件。GetNamePassword是为Name,Password属性赋一个合法的值。Regested 属性是保存共享软件是否注册过的信息的。RegestedKey是您的软件在注册表LOCAL_MACHINE主键中注册的键名。至于RegestName,RegestPassword就是保存合法的用户名及密码的了。

例子程序如下:

Option Explicit

Private Sub Form_Load()

Dim Temp As ClassRegest ‘请先在”引用”中引用这个类(动态链接库)

Set Temp = New ClassRegest

Temp.RegestKey = "Software\RegestTest" ‘设置你的软件在注册表中注册的键名

Temp.Regestcheck ‘判断是否注册, 判断结果保存在Regested属性中

‘必须先赋值RegestKey及执行一遍RegestCheck,其它的属性及方法才能被正确执行

MsgBox "Regeted is " & Temp.Regested

Temp.GetNamePassword ’通过一定的算法为RegestName,RegestPassword赋于一个合法的值

MsgBox "name is: " & Temp.RegestName

MsgBox "password is: " & Temp.RegestPassword

Temp.Regest ‘如果共享软件没有注册,则注册这个软件

Set Temp=Nothing

End Sub

现在把这个DLL动态链接库的源代码提供如下:

(VB6.0测试通过)

Option Explicit

Private Const HKEY_LOCAL_MACHINE As Long = &H80000002 '注册表函数的几个参数

Private Const KEY_QUERY_VALUE As Long = &H1

Private Const KEY_SET_VALUE As Long = &H2

Private Const REG_SZ As Long = 1

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 RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, 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, ByVal lpData As String, ByVal cbData As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private m_Regested As Boolean '是否注册属性

Private m_RegestKey As String '注册表中的子键名

Private m_Name As String '用户名属性

Private m_Password As String '密码属性

Private nCount As Integer '用来临时计数

Private lReturn As Long '接收返回值

Private Const sTarget As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.;:" '用来生成随机文本

Private FSO As FileSystemObject '用来产生随机文件的文件系统对象

Private FSOFile As File

Private FSOString As TextStream

Private Sub Class_Initialize()

m_Regested = False

m_RegestKey = ""

End Sub

Public Sub RegestCheck()

Dim sName As String * 9 '保存注册表中读出的用户名

Dim sPassword As String * 26 '保存注册表中读出的密码

Dim hEditKey As Long '保存打开的注册表键的句柄

Dim lRegOpenError As Long '保存打开注册表某主键的返回值

lRegOpenError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, m_RegestKey, 0, KEY_QUERY_VALUE, hEditKey)

If lRegOpenError <> 0 Then '如果打开出错

MsgBox "Open Reg Error!Terminate!Please examine RegestKey."

Exit Sub

End If

lReturn = RegQueryValueEx(hEditKey, "Name", 0, REG_SZ, sName, 9)

If lReturn = 2 Then '如果Name键值不存在

GoTo FORNEXT

End If

lReturn = RegQueryValueEx(hEditKey, "Password", 0, REG_SZ, sPassword, 26)

If lReturn = 2 Then

GoTo FORNEXT

End If

If KeyCheck(Left(sName, 8), Left(sPassword, 25)) = True Then

m_Regested = True 'KeyCheck检查Name和Password是否为合法,合法则m_regested被设为True

Exit Sub

End If

FORNEXT:

m_Regested = False '未通过KeyCheck则m_Regested设为否

Randomize '初始化随机数生成器

Dim hFileNumber As Integer '打开当前目录下的Key.dat文件,该文件用来保存用以生成Name及Password的一个随机字符串

hFileNumber = FreeFile

If Right(App.Path, 1) = "\" Then

Open App.Path & "Key.dat" For Binary As hFileNumber

Else

Open App.Path & "\Key.dat" For Binary As hFileNumber

End If

Dim iRandom As Integer '生成随机字符数组baRandom()

Dim baRandom(1 To 100) As Byte

Dim iTemp As Integer

Dim iNameLength As Integer

Dim iPasswordLength As Integer

Dim iKeyLength As Integer

iNameLength = 0

iPasswordLength = 0

For nCount = 1 To 100 Step 3

If iNameLength = 8 Then

baRandom(nCount) = &HFF

nCount = nCount + 1

iNameLength = 9

End If

baRandom(nCount) = CByte(CStr(Int(32 * Rnd)))

iTemp = (CInt(baRandom(nCount)) + 1) ^ 2 - CInt(baRandom(nCount)) ^ 2

baRandom(nCount + 1) = CByte(CInt(iTemp * Rnd))

If iNameLength < 8 Then

baRandom(nCount + 2) = CByte(Int((8 - iNameLength) * Rnd) + 1)

iNameLength = iNameLength + CInt(baRandom(nCount + 2))

Else

If iPasswordLength < 25 Then

baRandom(nCount + 2) = CByte(Int((25 - iPasswordLength) * Rnd + 1))

iPasswordLength = iPasswordLength + CInt(baRandom(nCount + 2))

Else

iKeyLength = nCount - 1

nCount = 100

End If

End If

Next

For nCount = 1 To iKeyLength '在Key.dat中写入baRandom()

Put #hFileNumber, nCount, baRandom(nCount)

Next

Close #hFileNumber

Set FSO = CreateObject("Scripting.FileSystemObject") '生成一个1024字节的随机字符组成的ASIIC文件

If Right(App.Path, 1) = "\" Then

If FSO.FileExists(App.Path & "Value.dat") Then

Set FSOFile = FSO.GetFile(App.Path & "Value.dat")

Set FSOString = FSOFile.OpenAsTextStream(ForWriting, TristateFalse)

Else

Set FSOString = FSO.CreateTextFile(App.Path & "Value.dat", True, False)

End If

Else

If FSO.FileExists(App.Path & "\Value.dat") Then

Set FSOFile = FSO.GetFile(App.Path & "\Value.dat")

Set FSOString = FSOFile.OpenAsTextStream(ForWriting, TristateFalse)

Else

Set FSOString = FSO.CreateTextFile(App.Path & "\Value.dat", True, False)

End If

End If

For nCount = 1 To 1024

FSOString.Write (Mid(sTarget, Int(56 * Rnd + 1), 1))

Next

lReturn = RegCloseKey(hEditKey)

Erase baRandom

Set FSO = Nothing

Set FSOFile = Nothing

Set FSOString = Nothing

Close #hFileNumber

End Sub

Private Function KeyCheck(ForCheckName As String, ForCheckPassword As String) As Boolean

'接收两个从注册表中读出的字符串Name和Password

'如果注册表中没有Name和Password键值则此二值为空,以下检测该字符串第一个字符是否在sTarget中

If InStr(1, sTarget, Left(ForCheckName, 1), vbTextCompare) = 0 Or InStr(1, sTarget, Left(ForCheckPassword, 1), vbTextCompare) = 0 Then

KeyCheck = False

Exit Function

End If

'调用CalculateNamePassword,返回合法的Name及Password

'返回值的形式为Name%Password

Dim sTotal As String

sTotal = CalculateNamePassword

Dim sCalName As String

Dim sCalPassword As String

sCalName = Left(sTotal, 8)

sCalPassword = Right(sTotal, 25)

'检测是否符合

For nCount = 1 To 8

If Mid(ForCheckName, nCount, 1) <> Mid(sCalName, nCount, 1) Then

KeyCheck = False

Exit Function

End If

Next

For nCount = 1 To 25

If Mid(ForCheckPassword, nCount, 1) <> Mid(sCalPassword, nCount, 1) Then

KeyCheck = False

Exit Function

End If

Next

KeyCheck = True

End Function

Public Property Get Regested() As Variant '是否注册的只读属性

Regested = m_Regested

End Property

Public Property Get RegestKey() As String '客户应用程序在注册表中的注册键

RegestKey = m_RegestKey

End Property

Public Property Let RegestKey(ByVal vNewValue As String)

m_RegestKey = vNewValue

End Property

Private Function CalculateNamePassword() As String '用来以Name%Password格式返回

'合法用户名及密码的私有方法

'如果Value.dat不存在,则立即退出

Set FSO = CreateObject("Scripting.FileSystemObject")

If Right(App.Path, 1) = "\" Then

If FSO.FileExists(App.Path & "Value.dat") = False Then

CalculateNamePassword = ""

Set FSO = Nothing

Exit Function

End If

Else

If FSO.FileExists(App.Path & "\Value.dat") = False Then

CalculateNamePassword = ""

Set FSO = Nothing

Exit Function

End If

End If

Dim sCalculateName As String '合法的用户名

Dim sCalculatePassword As String '合法的密码

sCalculateName = ""

sCalculatePassword = ""

Dim hFileNumberKey As Integer '打开两个文件Key.dat和Value.dat

hFileNumberKey = FreeFile

If Right(App.Path, 1) = "\" Then

Open App.Path & "Key.dat" For Binary As hFileNumberKey

Else

Open App.Path & "\Key.dat" For Binary As hFileNumberKey

End If

Dim hFileNumberValue As Integer

hFileNumberValue = FreeFile

If Right(App.Path, 1) = "\" Then

Open App.Path & "Value.dat" For Binary As hFileNumberValue

Else

Open App.Path & "\Value.dat" For Binary As hFileNumberValue

End If

Dim bFirst As Byte

Dim bSecond As Byte

Dim bLength As Byte

Dim bFF As Byte

Dim bCode As Byte

Dim iPasswordStart As Integer

Dim iLength As Integer

For nCount = 1 To 24 Step 3

Get #hFileNumberKey, nCount, bFF

If bFF <> &HFF Then

Get #hFileNumberKey, nCount, bFirst

Get #hFileNumberKey, nCount + 1, bSecond

Get #hFileNumberKey, nCount + 2, bLength

For iLength = 1 To CInt(bLength)

Get #hFileNumberValue, CInt(bFirst) ^ 2 + CInt(bSecond) + iLength - 1, bCode

sCalculateName = sCalculateName & Chr(bCode)

Next

Else

iPasswordStart = nCount

Exit For

End If

Next

For nCount = iPasswordStart + 1 To 100 Step 3

Get #hFileNumberKey, nCount, bFirst

Get #hFileNumberKey, nCount + 1, bSecond

Get #hFileNumberKey, nCount + 2, bLength

For iLength = 1 To CInt(bLength)

Get #hFileNumberValue, CInt(bFirst) ^ 2 + CInt(bSecond) + iLength - 1, bCode

sCalculatePassword = sCalculatePassword & Chr(bCode)

If Len(sCalculatePassword) = 25 Then

nCount = 100

Exit For

End If

Next

Next

CalculateNamePassword = sCalculateName & "%" & sCalculatePassword

Set FSO = Nothing

Close #hFileNumberKey

Close #hFileNumberValue

End Function

Public Property Get RegestName() As String '只读用户名属性

RegestName = m_Name

End Property

Public Property Get RegestPassword() As String '只读密码属性

RegestPassword = m_Password

End Property

Public Sub GetNamePassword() '获得用户名及密码的公用方法

'调用一次就会给用户名属性和密码属性赋一合法值

Dim sTotal As String

sTotal = CalculateNamePassword

m_Name = Left(sTotal, 8)

m_Password = Right(sTotal, 25)

End Sub

Public Sub Regest() '以合法用户名及密码注册软件的公有方法

Dim sTotal As String

Dim sSubName As String

Dim sSubPassword As String

Dim hEditKey As Long

sTotal = CalculateNamePassword

sSubName = Left(sTotal, 8)

sSubPassword = Right(sTotal, 25)

Dim lRegOpenError As Long

lRegOpenError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, m_RegestKey, 0, KEY_SET_VALUE, hEditKey)

If lRegOpenError <> 0 Then

MsgBox "Open Reg Error!Terminate!Please examine RegestKey."

Exit Sub

End If

Dim lReturn As Long

lReturn = RegSetValueEx(hEditKey, "Name", 0, REG_SZ, sSubName, 8)

lReturn = RegSetValueEx(hEditKey, "Password", 0, REG_SZ, sSubPassword, 25)

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有