• Welcome to Valhalla Legends Archive.
 

Explanation of CopyMemory

Started by FrostWraith, August 22, 2006, 05:32 PM

Previous topic - Next topic

Ante

#15
Quote from: FrostWraith on August 22, 2006, 09:03 PM
Yes, but if this function had to be recoded w/o using copymemory, what would it look like?

Function Makedword(Value as long) as string
if value >= 0 then
makedword = makedword & chr(value mod 256) & chr((value mod (256^2)) \ (256^1)) & chr((value mod (256^3)) \ (256^2)) & chr((value mod (256^4)) \ (256^3))
else
value=value + 2147483648#
makedword = makedword & chr(value mod 256) & chr((value mod (256^2)) \ (256^1)) & chr((value mod (256^3)) \ (256^2)) & chr(((value mod (256^4)) \ (256^3))+128)
end if
End Function


notice they are backward slashes (\), which mean integer division, not normal division

if its not the above, then add Makedword=strreverse(makedword) right below the "End if"
Efficiency is the Key to Productivity, and
Productivity is the Key to Success.

Joe[x86]

Quote from: Ante on February 14, 2007, 10:08 AM
Quote from: FrostWraith on August 22, 2006, 09:03 PM
Yes, but if this function had to be recoded w/o using copymemory, what would it look like?

Function Makedword(Value as long) as string
if value >= 0 then
makedword = makedword & chr(value mod 256) & chr((value mod (256^2)) \ (256^1)) & chr((value mod (256^3)) \ (256^2)) & chr((value mod (256^4)) \ (256^3))
else
value=value + 2147483648#
makedword = makedword & chr(value mod 256) & chr((value mod (256^2)) \ (256^1)) & chr((value mod (256^3)) \ (256^2)) & chr(((value mod (256^4)) \ (256^3))+128)
end if
End Function


notice they are backward slashes (\), which mean integer division, not normal division

if its not the above, then add Makedword=strreverse(makedword) right below the "End if"

OH DEAR GOD THAT HURT, lol.

Function MakeDWORD(Value as Long) As String
    Dim RET as String * 4
    Mid(RET, 1, 1) = Value And &HFF000000
    Mid(RET, 2, 1) = Value And &HFF0000
    Mid(RET, 3, 1) = Value And &HFF00
    Mid(RET, 4, 1) = Value And &HFF
    MakeDWORD = RET
End Function


Note that you're doing three bad things:
1. Using return as a variable.
2. Concatenating to a string that has no contents.
3. Modifying a value passed to the function with out intention of making a ByRef return.

I don't even know what that whole if is about. :P
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Ante

Function MakeDWORD(Value as Long) As String
    Dim RET as String * 4
    Mid(RET, 1, 1) = Value And &HFF000000
    Mid(RET, 2, 1) = Value And &HFF0000
    Mid(RET, 3, 1) = Value And &HFF00
    Mid(RET, 4, 1) = Value And &HFF
    MakeDWORD = RET
End Function


that's setting values of longs into chars. for example, if the value is &H11111111, the first line will read Mid(RET, 1, 1) = &H11000000. at least add chr to convert it to string. make sure to shift it over several places
Efficiency is the Key to Productivity, and
Productivity is the Key to Success.

l2k-Shadow

FYI, neither one of those functions work.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

l)ragon

#19
Frozen's will also overflow at random for no reason btw, can tell you this without even testing it.
You should never use a straight out value of 256 in that manor.
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

Ante

Quote from: l2k-Shadow on February 17, 2007, 09:17 AM
FYI, neither one of those functions work.
does mine work if u add Makedword=strreverse(makedword) at the end of the function?
Efficiency is the Key to Productivity, and
Productivity is the Key to Success.

l2k-Shadow

Quote from: Ante on February 18, 2007, 11:24 AM
Quote from: l2k-Shadow on February 17, 2007, 09:17 AM
FYI, neither one of those functions work.
does mine work if u add Makedword=strreverse(makedword) at the end of the function?

lol... no it overflows on the first statement you can see it from the code.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Joe[x86]

Oh yeah.. add Chr() to mine.

I'm so used to byte[] now. :P
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

l2k-Shadow

#23
Quote from: Joex86] link=topic=15573.msg165117#msg165117 date=1171830197]
Oh yeah.. add Chr() to mine.

I'm so used to byte[] now. :P

No that won't work either, you are forgetting that all variables in VB except char are signed. You'd have to do something like this to overcome that barrier (this won't work in all cases such as VB will think that &HFFFF = &HFFFFFFFF because both produce same result, -1.. therefore you'd have to have multiple functions recognizing each one, so if you must not use RtlMoveMemory, you'd best go with the Chr$(eachbyte of the DWORD) function as postead earlier):

Function MakeDWORD(Value As Long) As String
Dim Outbuf As String, nLng As Long

    Outbuf = Chr$((Value And &HFF))
   
    nLng = (((Value And &HFF00) \ (2 ^ 8)) Mod 256)
    If nLng < 0 Then nLng = (nLng + 256)
    Outbuf = Outbuf & Chr$(nLng)
   
    nLng = (((Value And &HFF0000) \ (2 ^ 16)) Mod 256)
    If nLng < 0 Then nLng = (nLng + 256)
    Outbuf = Outbuf & Chr$(nLng)
   
    nLng = (((Value And &HFF000000) \ (2 ^ 24)) Mod 256)
    If nLng < 0 Then nLng = (nLng + 256)
    Outbuf = Outbuf & Chr$(nLng)
   
    MakeDWORD = Outbuf
End Function
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Ante

#24
Quote from: l2k-Shadow on February 18, 2007, 01:36 PM
Quote from: Ante on February 18, 2007, 11:24 AM
Quote from: l2k-Shadow on February 17, 2007, 09:17 AM
FYI, neither one of those functions work.
does mine work if u add Makedword=strreverse(makedword) at the end of the function?

lol... no it overflows on the first statement you can see it from the code.
did u mean the if value >= 0 then line? cuz theres no place for that to overflow
i can't imagine which other line it could overflow from...every chr() has a value within it that is positive and less than 256
and the negative values are bumped into positive with that line, and put back into "negative" with the last char
Efficiency is the Key to Productivity, and
Productivity is the Key to Success.

l2k-Shadow

Quote from: Ante on February 18, 2007, 08:24 PM
Quote from: l2k-Shadow on February 18, 2007, 01:36 PM
Quote from: Ante on February 18, 2007, 11:24 AM
Quote from: l2k-Shadow on February 17, 2007, 09:17 AM
FYI, neither one of those functions work.
does mine work if u add Makedword=strreverse(makedword) at the end of the function?

lol... no it overflows on the first statement you can see it from the code.
did u mean the if value >= 0 then line? cuz theres no place for that to overflow
i can't imagine which other line it could overflow from...every chr() has a value within it that is positive and less than 256
and the negative values are bumped into positive with that line, and put back into "negative" with the last char

no i mean the statement after value >=0 line. it's because VB does math operations using long variables.. and (256 ^ 4) is &HFFFFFFFF which is an unsigned long, however since longs in VB are signed, overflow occurs.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Ante

hm...
u coulda jus doen this then

Function Makedword(Value as long) as string
if value >= 0 then
makedword = makedword & chr(value mod 256) & chr((value mod (256^2)) \ (256^1)) & chr((value mod (256^3)) \ (256^2)) & chr(value \ (256^3)
else
value=value + 2147483648#
makedword = makedword & chr(value mod 256) & chr((value mod (256^2)) \ (256^1)) & chr((value mod (256^3)) \ (256^2)) & chr((value  \ (256^3))+128)
end if
End Function
Efficiency is the Key to Productivity, and
Productivity is the Key to Success.

Imperceptus

Quote from: A2 on February 12, 2007, 09:06 PM
[code]copy memory is really usefull, especially for filling vb types which can be build alot like cstructs

double = 8bytes
long = 4bytes
integer = 2bytes
byte = 1byte

to answer your question, without copymem that function looks like

function long2str(byval n as long) as string

  long2str = _
    chr((n and &HFF000000&) mod 256) & _
    chr((n and &H00FF0000&) mod 256) & _
    chr((n and &H0000FF00&) mod 256) & _
    chr(n and &H000000FF&)

end function[/code]

or backwards... dont know offhand, too lazy for testing!

omg this post was more then 3 months old when you replied to it. jeez.
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

l2k-Shadow

#28
Quote from: Ante on February 19, 2007, 09:40 AM
hm...
u coulda jus doen this then

Function Makedword(Value as long) as string
if value >= 0 then
makedword = makedword & chr(value mod 256) & chr((value mod (256^2)) \ (256^1)) & chr((value mod (256^3)) \ (256^2)) & chr(value \ (256^3)
else
value=value + 2147483648#
makedword = makedword & chr(value mod 256) & chr((value mod (256^2)) \ (256^1)) & chr((value mod (256^3)) \ (256^2)) & chr((value  \ (256^3))+128)
end if
End Function


Then your function produces the same result as any MakeDWORD VB function.. you get the -1 problem where &HFFFF = &HFFFFFFFF and produces ÿÿÿÿ if you input &HFFFF or &HFFFFFFFF... :'(
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.