Hi!
I'm trying to develop a DLL that reverses a String.
I have two main problems:
1) I don't know how to reverse a String in ASM (But I think i will figure that out)
2) I'm not sure how to deliver the reversed string. Currently a messagebox pops up to show the passed parameter
but I don't want the box:
I'm not sure if the code is correct:
Thanks
Jsam
I'm trying to develop a DLL that reverses a String.
I have two main problems:
1) I don't know how to reverse a String in ASM (But I think i will figure that out)
2) I'm not sure how to deliver the reversed string. Currently a messagebox pops up to show the passed parameter
but I don't want the box:
I'm not sure if the code is correct:
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
.code
LibMain proc hInstDLL:DWORD, reason:DWORD, unused:DWORD
.if reason == DLL_PROCESS_ATTACH
.elseif reason == DLL_PROCESS_DETACH
.elseif reason == DLL_THREAD_ATTACH
.elseif reason == DLL_THREAD_DETACH
.endif
ret
LibMain Endp
supp proc MyString:DWORD
invoke MessageBox,NULL,MyString,NULL,MB_OK
ret
supp endp
End LibMain
Thanks
Jsam
Following Proc is from the masm library:
So all you'd need to do is call it correctly, inside your DLL.
szRev proc src:DWORD,dst:DWORD
? ; ------------------------------------
? ; this version will reverses a string
? ; in a single memory buffer so it can
? ; accept the same address as both src
? ; and dst.
? ; ------------------------------------
? ? push esi
? ? push edi
? ? mov esi, src
? ? mov edi, dst
? ? xor eax, eax? ? ? ? ? ? ; use EAX as a counter
? ; ---------------------------------------
? ; first loop gets the buffer length and
? ; copies the first buffer into the second
? ; ---------------------------------------
? @@:
? ? mov dl, ? ? ? ?; copy source to dest
? ? mov , dl
? ? add eax, 1? ? ? ? ? ? ? ; get the length in ECX
? ? test dl, dl
? ? jne @B
? ? mov esi, dst? ? ? ? ? ? ; put dest address in ESI
? ? mov edi, dst? ? ? ? ? ? ; same in EDI
? ? sub eax, 1? ? ? ? ? ? ? ; correct for exit from 1st loop
? ? lea edi, ? ? ; end address in edi
? ? shr eax, 1? ? ? ? ? ? ? ; int divide length by 2
? ? neg eax? ? ? ? ? ? ? ? ?; invert sign
? ? sub esi, eax? ? ? ? ? ? ; sub half len from ESI
? ; ------------------------------------------
? ; second loop swaps end pairs of bytes until
? ; it reaches the middle of the buffer
? ; ------------------------------------------
? @@:
? ? mov cl, ? ? ? ?; load end pairs
? ? mov dl,
? ? mov , dl? ? ? ?; swap end pairs
? ? mov , cl
? ? sub edi, 1
? ? add eax, 1
? ? jnz @B? ? ? ? ? ? ? ? ? ; exit on half length
? ? mov eax, dst? ? ? ? ? ? ; return destination address
? ? pop edi
? ? pop esi
? ? ret
szRev endp
So all you'd need to do is call it correctly, inside your DLL.
Thank you!!
Jsam
Jsam