VB编程中的循环右移问题
本帖最后由 海天一色001 于 2020-7-3 19:00 编辑【问题已解决,非常感谢JuncoJet和solly两位大神的热情指导!】
在学习160个CM之39时,已经爆破成功,也找出了注册算法,但在用VB编写注册机时遇到了问题:
VB等高级语言中没有循环位移等位移指令,根据汇编中的ror指令的说明,自己编写了一个VB的ROR函数,但是这个函数计算出的结果与汇编中得出的结果总是有差距,在换成16进制的表示形式后可以看出高位(第8位)的值不一样,百思不得其解,特向各位大神求助!!!!
Text1.Text = ROR("44414D4E", 1) = 2220A6A7 这一步是对的,但下一步 Text2.Text = ROR("44414D4E", 2) = 51105353就不对了;Text3.Text = ROR("2220A6A7", 1) = 31105353就更不对了!!!!
实际上在汇编程序中ROR("44414D4E", 2) = ROR("2220A6A7", 1) = 91105353
VB源程序见附件,因附件不支持压缩文件,故在后面加了一个txt的扩展名。
源码如下:
Option Explicit
Private Sub Command1_Click()
Text1.Text = ROR("44414D4E", 1)
Text2.Text = ROR("44414D4E", 2)
Text3.Text = ROR("2220A6A7", 1)
End Sub
Public Function ROR(nSource As String, N As Integer) As String 'nSource为16进制字符串形式,N为循环右移次数
'目的操作数右移,每移位一次,其最低位移入最高位,同时最低位也移入进位标志CF????????????????
Dim Tmp, TmpLeft, TmpRight, Result As String
Tmp = HexToBin(nSource)
If N = 1 Then
TmpLeft = Left(Tmp, 1)
TmpRight = Right(Tmp, Len(Tmp) - 1)
End If
TmpLeft = Left(Tmp, Len(Tmp) - N)
TmpRight = Right(Tmp, N)
Result = TmpRight & TmpLeft
ROR = BintoHex(Result)
End Function
Function HexToBin(HexStr As String) As String '任意长度的16进制整数转为2进制
Dim temp, BinStr, Bin As String
Dim i As Integer
HexStr = UCase(HexStr) '将小写转换成大写
For i = 1 To Len(HexStr)
Select Case Mid(HexStr, i, 1)
Case "0": BinStr = "0000"
Case "1": BinStr = "0001"
Case "2": BinStr = "0010"
Case "3": BinStr = "0011"
Case "4": BinStr = "0100"
Case "5": BinStr = "0101"
Case "6": BinStr = "0110"
Case "7": BinStr = "0111"
Case "8": BinStr = "1000"
Case "9": BinStr = "1001"
Case "A": BinStr = "1010"
Case "B": BinStr = "1011"
Case "C": BinStr = "1100"
Case "D": BinStr = "1101"
Case "E": BinStr = "1110"
Case "F": BinStr = "1111"
End Select
temp = temp & BinStr
Next i
While Left(temp, 1) = "0"
temp = Right(temp, Len(temp) - 1)
Wend
HexToBin = Trim(temp)
End Function
Function BintoHex(BinStr As String) As String '任意长度的2进制整数转为16进制
Dim H As String
Dim i As Integer
If Len(BinStr) Mod 4 <> 0 Then BinStr = String(4 - (Len(BinStr) Mod 4), "0") & BinStr
For i = 1 To Len(BinStr) Step 4
Select Case Mid(BinStr, i, 4)
Case "0000": H = H & "0"
Case "0001": H = H & "1"
Case "0010": H = H & "2"
Case "0011": H = H & "3"
Case "0100": H = H & "4"
Case "0101": H = H & "5"
Case "0110": H = H & "6"
Case "0111": H = H & "7"
Case "1000": H = H & "8"
Case "1001": H = H & "9"
Case "1010": H = H & "A"
Case "1011": H = H & "B"
Case "1100": H = H & "C"
Case "1101": H = H & "D"
Case "1110": H = H & "E"
Case "1111": H = H & "F"
End Select
Next i
BintoHex = H
End Function
VB并不支持逻辑移动,使用只能乘除取余数来实现,性能低下
不如C语言写个DLL给VB调用 另外实现注册机不是CM里直接抄汇编代码最方便吗,或者IDA F5抄袭C语言(出错率高) JuncoJet 发表于 2020-7-3 10:15
VB并不支持逻辑移动,使用只能乘除取余数来实现,性能低下
不如C语言写个DLL给VB调用
你好!谢谢你的回复!
但我只是个半调子,目前只是学了点VB,还不会用C语言。下一步的汇编、C语言也必须列入学习日程中了。现在我更想知道我这样做错误在哪儿了,你能帮我解决一下吗? 海天一色001 发表于 2020-7-3 10:23
你好!谢谢你的回复!
但我只是个半调子,目前只是学了点VB,还不会用C语言。下一步的汇编、C语言也必须 ...
Private Sub Command1_Click()
Text1.Text = MYROR("44414D4E", 1)
Text2.Text = MYROR("44414D4E", 2)
Text3.Text = MYROR("2220A6A7", 1)
End Sub
Function MYROR(nSource As String, N As Integer) As String
Dim i As Long, x As String
x = nSource
For i = 1 To N
x = ROR(x, 1)
Next
MYROR = x
End Function
JuncoJet 发表于 2020-7-3 10:31
Private Sub Command1_Click()
Text1.Text = MYROR("44414D4E", 1)
...
好像你的实现本身就有问题 JuncoJet 发表于 2020-7-3 10:31
Private Sub Command1_Click()
Text1.Text = MYROR("44414D4E", 1)
...
谢谢!!
您的MYROR函数解决了两次结果不一致的问题,但和汇编的结果还不一样。
我自己计算也应该是31105353,但汇编的是91105353,是补码还是其他原因一直搞不明白。
这个CM是用汇编语言编写的,可能还是需要用汇编语言来编写注册机更好一些吧。 海天一色001 发表于 2020-7-3 10:41
谢谢!!
您的MYROR函数解决了两次结果不一致的问题,但和汇编的结果还不一样。
我自己计算也应该是311 ...
看了下,应该是ROR指令的特殊性,想要快速实现,还是调用汇编快 Public Function ROR(nSource As String, N As Integer) As String 'nSource为16进制字符串形式,N为循环右移次数
'目的操作数右移,每移位一次,其最低位移入最高位,同时最低位也移入进位标志CF????????????????
Dim Tmp, TmpLeft, TmpRight, Result As String
Tmp = HexToBin(nSource)
If N = 1 Then
TmpLeft = Left(Tmp, 1)
TmpRight = Right(Tmp, Len(Tmp) - 1)
else
TmpLeft = Left(Tmp, Len(Tmp) - N)
TmpRight = Right(Tmp, N)
End If
Result = TmpRight & TmpLeft
ROR = BintoHex(Result)
End Function
是要 else 吧? 看起来,你这个象是 ROL,而不是 ROR 呀
页:
[1]
2