如何编写Copymem Lib" Kernel32"别名“Rtlmovememory”在Vb.Net [英] How To I Write Copymem Lib "Kernel32" Alias "Rtlmovememory" In Vb.Net
本文介绍了如何编写Copymem Lib" Kernel32"别名“Rtlmovememory”在Vb.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的vb6代码
私有 声明 Sub CopyMem Lib kernel32 别名 RtlMoveMemory(目的地 As Any,Source 如任何, ByVal 长度 As Long )
公共 属性 让键(New_Value As String )
Dim i As 长
Dim j 作为 长
Dim K 作为 长
Dim dataX 作为 长
Dim datal 作为 长
Dim datar 作为 长
Dim 键()作为 字节
Dim KeyLength As 长
' 如果密钥不执行任何操作缓冲
如果(m_KeyValue = New_Value)那么 退出 属性
m_KeyValue = New_Value
' 将新密钥转换为bytearray
KeyLength = Len(New_Value)
Key()= StrConv(New_Value,vbFromUnicode)
' 创建与密钥相关的p-box
j = < span class =code-digit> 0
对于 i = 0 要(ROUNDS + 1 )
dataX = 0
对于 K = 0 至 3
调用 CopyMem( ByVal VarPtr(dataX)+ 1 ,dataX, 3 )' 问题在这里
dataX =(dataX 或键(j))
j = j + 1
如果(j> = KeyLength)那么 j = 0
下一步
m_pBox(i)= m_pBox(i) Xor dataX
下一步
结束 属性
CopyMem sub lib我如何使用它在vb.net
现在这里是我的vb.net代码相同
私人 声明 Sub CopyMem Lib KERNEL32 Alias RtlMoveMemory( ByVal pDst 作为 对象, ByVal pSrc 作为 对象, ByVal ByteLen 作为 整数)
公众 WriteOnly 属性键()作为 字符串
设置( ByVal 值作为 字符串)
Dim i As 长
Dim j As 长
Dim K As 长
Dim dataX As 长
Dim datal As 长
Dim datar As 长
Dim 键()作为 字节
Dim KeyLength 作为 长
' 如果密钥被缓冲则不执行任何操作
If (m_KeyValue = Value)然后 退出 Property
m_KeyValue = Value
' 转换将新密钥转换为bytearray
KeyLength = Len(值)
Key = System.Text.Encoding.Unicode.GetBytes(Value)
' 创建与密钥相关的p-box
j = 0
对于 i = 0 到(ROUNDS + 1 )
dataX = 0
对于 K = 0 3
CopyMem(VarPtr(dataX) + 1 ,dataX, 3 )' 问题在这里
dataX =(dataX 或 Key(j))
j = j + 1
如果(j> = KeyLength)然后 j = 0
下一页
m_pBox(i)= m_pBox(i) Xor dataX
下一步
结束 物业
这里是代码
VarPtr
公共 功能 VarPtr( ByVal e 作为 对象)作为 对象
Dim GC 作为 GCHandle = GCHandle.Alloc(e, GCHandleType.Pinned)
Dim GC2 As 整数 = GC.AddrOfPinnedObject.ToInt32
GC.Free()
返回 GC2
结束 功能
i已提到等效的CopyMemory
但我仍然没有得到这个
请有人帮忙!!!
解决方案
根据我之前的评论,请勿尝试逐字转换此VB6代码。弄清楚它想要做什么并用VB.NET编写
我们现在已经确定它正在处理Blowfish Cipher,这些CodeProject资源应该证明是有用的
Blowfish加密实施。 NET [ ^ ]
Blowfish .Net中的加密实施 [ ^ ]
below is my vb6 code
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Property Let Key(New_Value As String)
Dim i As Long
Dim j As Long
Dim K As Long
Dim dataX As Long
Dim datal As Long
Dim datar As Long
Dim Key() As Byte
Dim KeyLength As Long
'Do nothing if the key is buffered
If (m_KeyValue = New_Value) Then Exit Property
m_KeyValue = New_Value
'Convert the new key into a bytearray
KeyLength = Len(New_Value)
Key() = StrConv(New_Value, vbFromUnicode)
'Create key-dependant p-boxes
j = 0
For i = 0 To (ROUNDS + 1)
dataX = 0
For K = 0 To 3
Call CopyMem(ByVal VarPtr(dataX) + 1, dataX, 3) 'the problem is here
dataX = (dataX Or Key(j))
j = j + 1
If (j >= KeyLength) Then j = 0
Next
m_pBox(i) = m_pBox(i) Xor dataX
Next
End Property
CopyMem sub lib how do i use it in vb.net
now here is my vb.net code for the same
Private Declare Sub CopyMem Lib "KERNEL32" Alias "RtlMoveMemory" (ByVal pDst As Object, ByVal pSrc As Object, ByVal ByteLen As Integer)
Public WriteOnly Property Key() As String
Set(ByVal Value As String)
Dim i As Long
Dim j As Long
Dim K As Long
Dim dataX As Long
Dim datal As Long
Dim datar As Long
Dim Key() As Byte
Dim KeyLength As Long
'Do nothing if the key is buffered
If (m_KeyValue = Value) Then Exit Property
m_KeyValue = Value
'Convert the new key into a bytearray
KeyLength = Len(Value)
Key = System.Text.Encoding.Unicode.GetBytes(Value)
'Create key-dependant p-boxes
j = 0
For i = 0 To (ROUNDS + 1)
dataX = 0
For K = 0 To 3
CopyMem(VarPtr(dataX) + 1, dataX, 3) ' the problem is here
dataX = (dataX Or Key(j))
j = j + 1
If (j >= KeyLength) Then j = 0
Next
m_pBox(i) = m_pBox(i) Xor dataX
Next
End Property
here is code for
VarPtr
Public Function VarPtr(ByVal e As Object) As Object
Dim GC As GCHandle = GCHandle.Alloc(e, GCHandleType.Pinned)
Dim GC2 As Integer = GC.AddrOfPinnedObject.ToInt32
GC.Free()
Return GC2
End Function
i have refered to Equivalent of CopyMemory
but still i am not getting this
please somebody help!!!
解决方案
As per my earlier comment, do not attempt to convert this VB6 code verbatim. Work out what it is trying to do and write it in VB.NET
As we have now established that it is handling the Blowfish Cipher these CodeProject resources should prove useful
Blowfish Encryption Implementation in .NET[^]
Blowfish Encryption Implementation in .Net[^]
这篇关于如何编写Copymem Lib" Kernel32"别名“Rtlmovememory”在Vb.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文