VarPtr Function
-
i am tryin to convert a project that was made in 6.0 to .net and its a little tough. I was wondering if anyone knew of a way to mimic the function of the varptr in some way. i have been trying to use the RTLmoveMemory dll call but in .net it is almost impossible to make it function. So i have been working to figure out how this function actually works. I would say i have it almost 75 percent pinned but when you send negative numbers to it comes back with numbers that i havent been able to put a mathmatical equation too. If there is any help with that it would be great.
Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
but anycase i need to know how to use the varptr function because in the following snippet heres the problem and the reason i need to use itFor i = 0 To (ROUNDS + 1) dataX = 0 For K = 0 To 3 Call CopyMem(ByVal VarPtr(dataX) + 1, dataX, 3) dataX = (dataX Or Key(j)) j = j + 1 If (j >= KeyLength) Then j = 0 Next m_pBox(i) = m_pBox(i) Xor dataX Next
rounds = 16 key contains a unicode work "text1" key(0) = 116 key(1) = 101 key(2) = 120 key(3) = 116 key(4) = 49 when it first interates through the second for loop datax = 116 which is the first number in the byte array but i have no idea where these other numbers are coming from 2 datax = 298313 3 datax = 7632253 4 datax = 1953856893 if i can figure out what varptr(datax) + 1 does and mimic its function and also figure out why when negative numbers are send to the api call it sends back really negative large numbers. Any help with any thing seen here would be awesome. thank you very much -
i am tryin to convert a project that was made in 6.0 to .net and its a little tough. I was wondering if anyone knew of a way to mimic the function of the varptr in some way. i have been trying to use the RTLmoveMemory dll call but in .net it is almost impossible to make it function. So i have been working to figure out how this function actually works. I would say i have it almost 75 percent pinned but when you send negative numbers to it comes back with numbers that i havent been able to put a mathmatical equation too. If there is any help with that it would be great.
Public Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
but anycase i need to know how to use the varptr function because in the following snippet heres the problem and the reason i need to use itFor i = 0 To (ROUNDS + 1) dataX = 0 For K = 0 To 3 Call CopyMem(ByVal VarPtr(dataX) + 1, dataX, 3) dataX = (dataX Or Key(j)) j = j + 1 If (j >= KeyLength) Then j = 0 Next m_pBox(i) = m_pBox(i) Xor dataX Next
rounds = 16 key contains a unicode work "text1" key(0) = 116 key(1) = 101 key(2) = 120 key(3) = 116 key(4) = 49 when it first interates through the second for loop datax = 116 which is the first number in the byte array but i have no idea where these other numbers are coming from 2 datax = 298313 3 datax = 7632253 4 datax = 1953856893 if i can figure out what varptr(datax) + 1 does and mimic its function and also figure out why when negative numbers are send to the api call it sends back really negative large numbers. Any help with any thing seen here would be awesome. thank you very muchVarPtr has no equivelent in VB.NET... All it does is return the address of the variable, which, in managed code, is not guarenteed to stay where it was created thereby invalidating the return of VarPtr. What you would have to do is, in VB6, step through this code and watch what happens to dataX. the variable dataX looks like it is a Long, or Integer in VB.NET...a 32-bit signed integer. What it looks like it's doing is copying bytes 2, 3, and 4 to byte 1 of dataX. It might help to look at the value of dataX in the Watch window in Hexadecimal.
dataX before CopyMem dataX after CopyMem
byte1 | byte2 | byte3 | byte4 byte1 | byte2 | byte3 | byte4
2B 1A 00 FE 1A 00 FE FEIn this case, what you would need to do is mask out byte 1, 2, and 3 to get the value of the 4th byte. Then move the numbers in dataX to the left by 8 bits and finally add back in the lastByte:
' From the example above... Dim dataX As Integer = &H2B1A00FE Dim lastByte As Integer = (dataX And &H000000FF) ' lastByte will equal &HFE. ' This moves the data left 8 bits. This will drop the first byte and move ' the remaining bytes to the left, leaving 00 in the last byte. ' 2B1A00FE becomes 1A00FE00 dataX = dataX \* 256 ' Now add back in, the byte that we saved above. ' 1A00FE00 becomes 1A00FEFE dataX = dataX + lastByte
RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome