I am trying to declare some md5 checksums for use in my program.
check1 should be E9FE198C56219C3832F75D1F5D7CD1B7
The format of the hashes I have are hex dump (almost all md5 hashes come in this format)
Is there an easy syntax in masm to declare a 16 byte array equal to a hex dump such as E9FE198C56219C3832F75D1F5D7CD1B7?
Or would I have to create a macro and do something like this:
check1 db MD5(<E9FE198C56219C3832F75D1F5D7CD1B7>)
I am not very good at macros so this is why I ask.
If your hex dump is a string, why not simply:
check1 db "E9FE198C56219C3832F75D1F5D7CD1B7",0
and then do a string compare with the dump?
Quote from: ChrisLeslie on February 02, 2007, 11:29:44 AM
If your hex dump is a string, why not simply:
check1 db "E9FE198C56219C3832F75D1F5D7CD1B7",0
and then do a string compare with the dump?
Seems like a rather inefficient way - the comparison will need to be quick because it will be called many times.
When I say my dump is a string, I mean the md5 hashes I have and want to declare are in this hex dump format.
The hashes I will be comparing to at runtime are in binary format.
A macro should be alright.
MD5 MACRO varname:REQ, hash:REQ
LOCAL hash_temp
varname LABEL BYTE
hash_temp TEXTEQU <hash>
WHILE @SizeStr(hash_temp) GE 2
%BYTE @CatStr(<0>, @SubStr(hash_temp,1,2), <h>)
hash_temp SUBSTR hash_temp, 2
ENDW
ENDM
See how that works. I've written that totally off-the-cuff and referred to nothing, so my SUBSTR numbers will probably be all off. Turn all listing on (.listmacroall) and see what code it generates to make sure it's right.
Cheers,
Zooba :U
Even after I corrected the ENDW to ENDM I could not get the macro to work. The @SizeStr(hash_temp) does not return the expected value. It's nice to know that I'm not the only one who needs the references :bg
This appears to work OK:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
MD5 MACRO varname:REQ,hash:REQ
varname LABEL BYTE
cnt = @SizeStr(hash)
IF cnt NE 32
echo Expected 32 digits
.err
ENDIF
i = 1
;%echo @CatStr(<count = >,%cnt)
WHILE i LT cnt
%BYTE @CatStr(<0>, @SubStr(hash,i,2), <h>)
i = i + 2
ENDM
ENDM
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
MD5 cksum1, E9FE198C56219C3832F75D1F5D7CD1B7
MD5 cksum2, 00112233445566778899aabbccddeeff
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
print "E9FE198C56219C3832F75D1F5D7CD1B7",13,10
xor ebx,ebx
.WHILE ebx < 16
movzx eax, BYTE PTR [cksum1+ebx]
print right$(uhex$(eax),2)
inc ebx
.ENDW
print chr$(13,10)
print "00112233445566778899aabbccddeeff",13,10
xor ebx,ebx
.WHILE ebx < 16
movzx eax, BYTE PTR [cksum2+ebx]
print right$(uhex$(eax),2)
inc ebx
.ENDW
print chr$(13,10)
inkey "Press any key to exit..."
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
Quote from: MichaelW on February 02, 2007, 10:36:56 PMEven after I corrected the ENDW to ENDM I could not get the macro to work.
Oops... :red
Quote from: MichaelW on February 02, 2007, 10:36:56 PMThe @SizeStr(hash_temp) does not return the expected value.
Possibly there is a % missing then. It could go either at the start of the line or right before hash_temp. (Does a quick look up) Yep. @SizeStr(%hash_temp) should work.
Quote from: MichaelW on February 02, 2007, 10:36:56 PMIt's nice to know that I'm not the only one who needs the references :bg
Unfortunately, nobody has figured out how to remember absolutely everything yet :bg
Cheers,
Zooba :U
Thanks a lot both of you!
Appreciated! :clap:
Could you post the code that creates the hash please? I'd like to see how to make a counter that would convert '1', '2', '3' into a hash and compare it with the hash you have in your program post.
Thanks,