Here is a quick example to get the extension of a filename :
.386
.model flat,stdcall
option casemap:none
StrLen PROTO :DWORD
.code
GetFileExtension PROC USES esi edi pFileName:DWORD
mov esi,pFileName
mov edi,1
invoke StrLen,esi
mov cl,BYTE PTR [esi]
push ecx
mov BYTE PTR [esi],'.'
add eax,esi
@@:
sub eax,edi
cmp BYTE PTR [eax],'.'
jne @b
pop ecx
mov BYTE PTR [esi],cl
ret
GetFileExtension ENDP
END
The procedure returns the address of the string if there is no file extension.
include Demo.inc
BUFFER_SIZE equ 128
.data
file db 'C:\WINDOWS\system32\kernel32.dll',0
format1 db 'Extension = %s',0
.data?
buffer db BUFFER_SIZE dup(?)
.code
start:
invoke GetFileExtension,ADDR file
invoke wsprintf,ADDR buffer,ADDR format1,eax
invoke StdOut,ADDR buffer
invoke ExitProcess,0
END start