-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPath_GetAppPath.asm
72 lines (61 loc) · 1.78 KB
/
Path_GetAppPath.asm
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
;==============================================================================
;
; 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
; getpid 27h
IF @Platform EQ 1 ; Win x64
GetModuleFileNameA PROTO hModule:QWORD, lpFilename:QWORD, nSize:DWORD
includelib kernel32.lib
ENDIF
include UASM64.inc
.CODE
UASM64_ALIGN
;------------------------------------------------------------------------------
; Path_GetAppPath
;
; Returns the address of the running application's path as a zero terminated
; string with the filename removed. The last character in the string is a
; trailing backslash "\" to facilitate parsing different filenames to the path.
;
; Parameters:
;
; * lpszPath - The address of the buffer that will receive the application path.
;
; Returns:
;
; There is no return value.
;
; See Also:
;
; Path_GetPathOnly, Path_NameFromPath
;
;------------------------------------------------------------------------------
Path_GetAppPath PROC FRAME lpszPath:QWORD
IF @Platform EQ 1 ; Win x64
invoke GetModuleFileNameA, 0, lpszPath, 128 ; return length in rax
add rax, lpszPath
; ---------------------------------------
; scan backwards for first "\" character
; ---------------------------------------
@@:
dec rax ; dec ECX
cmp BYTE PTR [rax],'\' ; compare if "\"
jne @B ; jump back to @@: if not "\"
mov BYTE PTR [rax+1],0 ; write zero terminator after "\"
mov rax, lpszPath
ENDIF
ret
Path_GetAppPath ENDP
END