Here is a version that fixes invalid extensions or no extension at all. I don't personally like the technique and if this was release commercial software, I would loop back with an error message if there was an invalid or missing extension. The technique used is to test if there is a valid extension and simply add one if it has not. This is the safest way but you can end up with double extension file names.
flename.bmp.jpg
To back analyse alternatives is a very unreliable way to perform this task.
This is the algo used.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
fixext proc pname:QWORD,extt:QWORD
; -----------------------------------
; note that the buffer address is
; reused each time the proc is called
; -----------------------------------
LOCAL pbuf :QWORD
LOCAL pst1 :QWORD
LOCAL str1[32]:BYTE
.data?
Buff@@$$@@ db 260 dup (?) ; buffer with mangled name
.code
mov pst1, ptr$(str1) ; get both pointers
mov pbuf, ptr$(Buff@@$$@@)
rcall szCopy,pname,pbuf ; copy file name to Buff@@$$@@
rcall szRight,pbuf,pst1,4 ; get the right 4 characters
mov pst1, lcase$(pst1) ; convert both strings to lower case
mov extt, lcase$(extt)
rcall szCmp,pst1,extt ; test if they are the same
.If rax eq 0
rcall szCatStr,pbuf,extt ; append the extension if invalid
mov rax, pbuf ; return address of modified buffer
ret
.Else
mov rax, pbuf ; just return the buffer address
ret
.EndIf
fixext endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤