You last visited: Today at 05:24
Advertisement
[MASM] - MD5
Discussion on [MASM] - MD5 within the Coding Snippets forum part of the Coding Releases category.
12/29/2013, 01:51
#1
elite*gold: 110
Join Date: Jun 2013
Posts: 599
Received Thanks: 510
[MASM] - MD5
Hi,
Da ich eine MD5 - Funktion in MASM brauche die nicht alt zu groß ist, hab ich beschlossen sie selbst zu Implementieren ( Quelle ist im Source angegeben ).
Ich habe ein Beispiel mit in den Anhang gepackt ( Passwort: epvp_tension ).
Code:
Code:
;====================================;
;= Message Digest Algorithm =;
;= MASM implementation =;
;= by Ten$ion =;
;====================================;
;============= SOURCE ==============;
;= http://en.wikipedia.org/wiki/MD5 ;
;===================================;
.const
MD5 proto :DWORD, :DWORD
mfree proto :DWORD
malloc proto :DWORD
memcpy proto :DWORD, :DWORD, :DWORD
modulo macro x, y
push ebx
push edx
mov eax, x
mov ebx, y
xor edx, edx
div ebx
mov eax, edx
pop edx
pop ebx
endm
.data?
.data
MD5_Table DWORD 0D76AA478h, 0E8C7B756h, 0242070DBh, 0C1BDCEEEh, 0F57C0FAFh, 04787C62Ah, 0A8304613h, 0FD469501h
DWORD 0698098D8h, 08B44F7AFh, 0FFFF5BB1h, 0895CD7BEh, 06B901122h, 0FD987193h, 0A679438Eh, 049B40821h
DWORD 0F61E2562h, 0C040B340h, 0265E5A51h, 0E9B6C7AAh, 0D62F105Dh, 02441453h, 0D8A1E681h, 0E7D3FBC8h
DWORD 021E1CDE6h, 0C33707D6h, 0F4D50D87h, 0455A14EDh, 0A9E3E905h, 0FCEFA3F8h, 0676F02D9h, 08D2A4C8Ah
DWORD 0FFFA3942h, 08771F681h, 06D9D6122h, 0FDE5380Ch, 0A4BEEA44h, 04BDECFA9h, 0F6BB4B60h, 0BEBFBC70h
DWORD 0289B7EC6h, 0EAA127FAh, 0D4EF3085h, 04881D05h, 0D9D4D039h, 0E6DB99E5h, 01FA27CF8h, 0C4AC5665h
DWORD 0F4292244h, 0432AFF97h, 0AB9423A7h, 0FC93A039h, 0655B59C3h, 08F0CCC92h, 0FFEFF47Dh, 085845DD1h
DWORD 06FA87E4Fh, 0FE2CE6E0h, 0A3014314h, 04E0811A1h, 0F7537E82h, 0BD3AF235h, 02AD7D2BBh, 0EB86D391h
MD5_Rotate DWORD 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22 ;Round 1
DWORD 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20 ;Round 2
DWORD 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23 ;Round 3
DWORD 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21 ;Round 4
MD5_State DWORD 4 dup(0)
szFormat db '%s%2.2x',0
szMD5Final db MAX_PATH dup(0)
szMD5Digest db 16 dup(0)
.code
;===========================;
;= ToBytes val, bytes =;
;===========================;
;= val => DWORD value to =;
;= Convert =;
;= bytes => Buffer where =;
;= the DWORD =;
;= gets Stored =;
;===========================;
;= bytes contains the =;
;= DWORD =;
;===========================;
ToBytes proc val:DWORD, bytes:DWORD
pushad
mov esi, bytes
mov ebx, val
mov byte ptr ds:[esi], bl
shr ebx, 8
mov byte ptr ds:[esi+1], bl
shr ebx, 8
mov byte ptr ds:[esi+2], bl
shr ebx, 8
mov byte ptr ds:[esi+3], bl
popad
ret
ToBytes endp
;===========================;
;= ToDWORD, bytes =;
;===========================;
;= bytes => Bytes to =;
;= Convert =;
;===========================;
;= EAX contains the DWORD =;
;===========================;
ToDWORD proc bytes:DWORD
LOCAL res:DWORD
pushad
mov esi, bytes
movzx ebx, byte ptr ds:[esi]
mov res, ebx
movzx ebx, byte ptr ds:[esi+1]
shl ebx, 8
or res, ebx
movzx ebx, byte ptr ds:[esi+2]
shl ebx, 16
or res, ebx
movzx ebx, byte ptr ds:[esi+3]
shl ebx, 24
or res, ebx
popad
mov eax, res
ret
ToDWORD endp
;===========================;
;= MD5, i_msg, i_len =;
;===========================;
;= i_msg => Message to =;
;= hash =;
;= i_len => Length of =;
;= the Message =;
;===========================;
;= EAX contains the hash =;
;===========================;
MD5 proc i_msg:DWORD, i_len:DWORD
LOCAL msg:DWORD, n_len:DWORD, n_offset:DWORD
LOCAL w[16]:DWORD
LOCAL _a:DWORD, _b:DWORD, _c:DWORD, _d:DWORD, _o:DWORD
LOCAL i:DWORD, f:DWORD, g:DWORD, tmp:DWORD
pushad
mov dword ptr ds:[MD5_State], 067452301h
mov dword ptr ds:[MD5_State+4], 0EFCDAB89h
mov dword ptr ds:[MD5_State+8], 098BADCFEh
mov dword ptr ds:[MD5_State+0Ch], 010325476h
mov edx, i_len
inc edx
mov n_len, edx
@@:
inc n_len
modulo n_len, 40h
cmp eax, 38h
jne @B
mov edx, n_len
add edx, 8
invoke malloc, edx
mov msg, eax
invoke memcpy, msg, i_msg, i_len
mov ecx, i_len
mov esi, msg
mov byte ptr ds:[esi+ecx], 80h
push i_len
pop n_offset
inc n_offset
@@:
pushad
mov ecx, n_offset
mov esi, msg
mov byte ptr ds:[esi+ecx], 0h
popad
inc n_offset
mov ecx, n_len
cmp n_offset, ecx
jl @B
mov ecx, i_len
imul ecx, 8
mov esi, msg
add esi, n_len
invoke ToBytes, ecx, esi
mov ecx, i_len
shr ecx, 1Dh
mov esi, msg
add esi, n_len
add esi, 4
invoke ToBytes, ecx, esi
mov n_offset, 0
@ProcessLoop:
pushad
mov i, 0
@@:
pushad
mov esi, msg
mov ecx, i
imul ecx, 4
add ecx, n_offset
add esi, ecx
invoke ToDWORD, esi
mov ecx, i
mov dword ptr ds:[w+4*ecx], eax
popad
inc i
cmp i, 10h
jl @B
mov eax, dword ptr ds:[MD5_State]
mov _a, eax
mov eax, dword ptr ds:[MD5_State+4]
mov _b, eax
mov eax, dword ptr ds:[MD5_State+8]
mov _c, eax
mov eax, dword ptr ds:[MD5_State+0Ch]
mov _d, eax
mov i, 0
@MainLoop:
pushad
cmp i, 16
jl @FF
cmp i, 32
jl @GG
cmp i, 48
jl @HH
jmp @II
@FF:
pushad
mov eax, _b
and eax, _c
mov ebx, _b
not ebx
and ebx, _d
or eax, ebx
mov f, eax
mov eax, i
mov g, eax
popad
jmp @SS
@GG:
pushad
mov eax, _d
and eax, _b
mov ebx, _d
not ebx
and ebx, _c
or eax, ebx
mov f, eax
mov eax, i
imul eax, 5
inc eax
modulo eax, 16
mov g, eax
popad
jmp @SS
@HH:
pushad
mov eax, _b
xor eax, _c
xor eax, _d
mov f, eax
mov eax, i
imul eax, 3
add eax, 5
modulo eax, 16
mov g, eax
popad
jmp @SS
@II:
pushad
mov eax, _c
mov ebx, _b
mov ecx, _d
not ecx
or ebx, ecx
xor eax, ebx
mov f, eax
mov eax, i
imul eax, 7
modulo eax, 16
mov g, eax
popad
jmp @SS
@SS:
mov ebx, _d
mov tmp, ebx
mov ebx, _c
mov _d, ebx
mov ebx, _b
mov _c, ebx
mov eax, _a
add eax, f
mov ecx, i
add eax, dword ptr ds:[MD5_Table+4*ecx]
mov edx, g
add eax, dword ptr ds:[w+4*edx]
mov _o, eax
mov ecx, i
mov ecx, dword ptr ds:[MD5_Rotate+4*ecx]
mov eax, _o
rol eax, cl
add eax, _b
mov _b, eax
mov ebx, tmp
mov _a, ebx
popad
inc i
cmp i, 40h
jl @MainLoop
mov eax, _a
add dword ptr ds:[MD5_State], eax
mov eax, _b
add dword ptr ds:[MD5_State+4], eax
mov eax, _c
add dword ptr ds:[MD5_State+8], eax
mov eax, _d
add dword ptr ds:[MD5_State+0Ch], eax
popad
add n_offset, 40h
mov ecx, n_len
cmp n_offset, ecx
jl @ProcessLoop
invoke mfree, msg
mov i, 0
@@:
pushad
lea esi, szMD5Digest
mov ecx, i
mov ebx, dword ptr ds:[MD5_State+4*ecx]
imul ecx, 4
add esi, ecx
invoke ToBytes, ebx, esi
popad
inc i
cmp i, 4
jl @B
invoke RtlZeroMemory, addr szMD5Final, MAX_PATH
mov i, 0
@@:
pushad
lea esi, szMD5Digest
mov ecx, i
movzx ebx, byte ptr ds:[esi+ecx]
invoke wsprintf, addr szMD5Final, addr szFormat, addr szMD5Final, ebx
popad
inc i
cmp i, 10h
jl @B
popad
lea eax, szMD5Final
ret
MD5 endp
;=== Some "Important" Functions ===;
;= http://msdn.microsoft.com/de-de/library/we1whae7(v=vs.90).aspx =;
mfree proc dwAddr:DWORD
pushad
invoke GetProcessHeap
invoke HeapFree, eax, 0, dwAddr
popad
ret
mfree endp
;= http://msdn.microsoft.com/de-de/library/6ewkz86d(v=vs.90).aspx =;
malloc proc len:DWORD
LOCAL res:DWORD
pushad
invoke GetProcessHeap
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY, len
mov res, eax
popad
mov eax, res
ret
malloc endp
;= http://msdn.microsoft.com/de-de/library/dswaw1wk(v=vs.90).aspx =;
memcpy proc output:DWORD, input:DWORD, len:DWORD
pushad
mov esi, input
mov edi, output
mov ecx, len
rep movsb
popad
ret
memcpy endp
Anwendung:
Code:
invoke MD5, BUFFER, LENGTH
// EAX => Hash
// Beispiel:
.data
szBuffer db 'Hallo',0
dwLen equ $-szBuffer //oder auch einfach equ 5
.code
invoke MD5, addr szBuffer, dwLen
invoke MessageBox, 0, eax, 0, MB_OK
//Ausgabe:
//d1bf93299de1b68e6d382c893bf1215f
MfG,
Ten$ion
Attached Files
MD5 - MASM.rar
(57.0 KB, 12 views)
12/29/2013, 04:22
#2
elite*gold: 1
Join Date: Feb 2009
Posts: 6,378
Received Thanks: 7,996
Nett. Hab's jetzt nicht genauer angeschaut, aber auf die Schnelle ist mir aufgefallen, dass du dir eigene Speicherverwaltungsroutinen definierst, obwohl es bereits
halloc und
hfree in
macros.asm (liegt MASM bei) definiert werden. VirtualAlloc ist zum Allozieren von Speicher übrigens auch etwas suboptimal, da es immer direkt ganze Pages holt und du so 'ne Menge Speicher verschwendest und auch jedes mal einen Sysenter caused, der in vielen Fällen nicht sein müsste. Solltest du die Makros nicht verwenden wollen, würde ich dir empfehlen die
der K32 zu nutzen, welche wesentlich performanter sein dürften.
12/29/2013, 13:32
#3
elite*gold: 110
Join Date: Jun 2013
Posts: 599
Received Thanks: 510
Danke! Ich hab nun die Heap-Funktionen verwendet.
Hab eigentlich bis jetzt immer VirtualAlloc verwendet, wieso weiß ich aber auch nicht genau..
Similar Threads
[Release]MASM Process Suspender + Injector + more !
09/09/2013 - Cabal Hacks, Bots, Cheats, Exploits & Macros - 31 Replies
Here's another tool i build for fun !
main features:
Suspend Process
Resume Process
Kill Process
Inject and Eject dll (manual)
in case you were wondering where can you use it ;P
Assembler NASM oder MASM?
07/21/2012 - General Coding - 8 Replies
Guten Tag,
da ich mich in der nächsten Zeit mit der Programmierung von Assembler auseinander setzen möchte, und dass auf x84 und x64 bit Versionen, habe ich folgende Frage an die ASM Coder.
Womit soll ich Arbeiten, MASM oder NASM oder ganz etwas anderes?
Ich hab schon gelesen, dass nur NASM über x64 Können verfügt, stimmt das so?
Hilfe wäre nett..
Greetz
NASM, FASM & MASM
11/12/2011 - CO2 Programming - 11 Replies
Alright, which one would be best to learn?
Atm. I have been learning NASM, but I don't know if it's any better or worse than FASM or MASM.
I have heard from some assembly programmers that I should just not use MASM.
Opinions?
Call COs jump function in masm?
10/28/2006 - Conquer Online 2 - 0 Replies
well i followed the tutorial on how to do this but it didnt give a very good masm example. how would i call the function in masm? does anyone have a good example or code? i have a bunch of other functions to use for hacks but i need to get this done first. im new to masm so i dont really know wat to do. i know how to call functions that dont have variables in other games but no clue when it comes to variables (x and y for jumping.)
thanks, high6.
p.s. here is the jump function location...
All times are GMT +2. The time now is 05:25 .