-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPath_NameFromPath.asm
More file actions
92 lines (79 loc) · 2.24 KB
/
Path_NameFromPath.asm
File metadata and controls
92 lines (79 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
;==============================================================================
;
; UASM64 Library
;
; https://github.com/mrfearless/UASM64-Library
;
;==============================================================================
.686
.MMX
.XMM
.x64
option casemap : none
IF @Platform EQ 1
option win64 : 11
ENDIF
option frame : auto
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; Path_NameFromPath
;
; Reads the filename from a complete path and returns it in the buffer
; specified in the lpszFilename parameter.
;
; Parameters:
;
; * lpszFullFilenamePath - The address of the full path that has the file name.
;
; * lpszFilename - The address of the buffer to receive the filename.
;
; Returns:
;
; The file name is returned in the buffer supplied in the lpszPath parameter.
;
; Notes:
;
; The buffer to receive the filename must be large enough to accept the
; filename. For safety reasons if dealing with both long path and file name,
; the buffer can be made the same length as the source buffer.
;
; See Also:
;
; Path_GetAppPath, Path_GetPathOnly
;
;------------------------------------------------------------------------------
Path_NameFromPath PROC FRAME USES RCX RDX RDI RSI lpszFullFilenamePath:QWORD, lpszFilename:QWORD
mov rsi, lpszFullFilenamePath
mov rcx, rsi
mov rdx, -1
xor rax, rax
@@:
add rdx, 1
cmp BYTE PTR [rsi+rdx], 0 ; test for terminator
je @F
cmp BYTE PTR [rsi+rdx], "\" ; test for "\"
jne @B
mov rcx, rdx
jmp @B
@@:
cmp rcx, rsi ; test if rcx has been modified
je error ; exit on error if it is the same
lea rcx, [rcx+rsi+1] ; add rsi to rcx and increment to following character
mov rdi, lpszFilename ; load destination address
mov rdx, -1
@@:
add rdx, 1
mov al, [rcx+rdx] ; copy file name to destination
mov [rdi+rdx], al
test al, al ; test for written terminator
jnz @B
sub rax, rax ; return value zero on success
jmp nfpout
error:
mov rax, -1 ; invalid path no "\"
nfpout:
ret
Path_NameFromPath ENDP
END