-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathArg_GetCommandLineExW.asm
More file actions
128 lines (114 loc) · 3.61 KB
/
Arg_GetCommandLineExW.asm
File metadata and controls
128 lines (114 loc) · 3.61 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
;==============================================================================
;
; 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
IF @Platform EQ 1 ; Win x64
GetCommandLineW PROTO
includelib kernel32.lib
ENDIF
IF @Platform EQ 3 ; Linux x64
; https://baturin.org/blog/hello-from-a-compiler-free-x86-64-world/
; https://gist.github.com/Gydo194/730c1775f1e05fdca6e9b0c175636f5b
ENDIF
include UASM64.inc
.CODE
IF @Platform EQ 1 ; Win x64
UASM64_ALIGN
;------------------------------------------------------------------------------
; Arg_GetCommandLineExW
;
; Extended version of Arg_GetCommandLine. This Arg_GetCommandLineEx function
; uses the Arg_GetArgument function to obtain the selected argument from a
; command line. It differs from the original version in that it will read a
; command line of any length and the arguments can be delimited by spaces, tabs,
; commas or any combination of the three.
; It is also faster but as the Arg_GetArgument function is table driven, it is
; also larger.
;
; Parameters:
;
; * nArgument - The argument number to return from a command line.
;
; * lpszArgumentBuffer - The buffer to receive the selected argument.
;
; Returns:
;
; There are three (3) possible return values:
; 1 = successful operation
; 2 = no argument exists at specified arg number
; 3 = non matching quotation marks
;
; See Also:
;
; Arg_GetCommandLineW, Arg_GetArgumentW
;
;------------------------------------------------------------------------------
Arg_GetCommandLineExW PROC FRAME USES RCX nArgument:QWORD, lpszArgumentBuffer:QWORD
LOCAL lpszArgsList:QWORD
add nArgument, 1
Invoke GetCommandLineW
mov lpszArgsList, rax
Invoke Arg_GetArgumentW, lpszArgsList, lpszArgumentBuffer, nArgument, 0
.if rax >= 0
mov rcx, lpszArgumentBuffer
.if WORD PTR [rcx] != 0
mov rax, 1 ; successful operation
.else
mov rax, 2 ; no argument at specified number
.endif
.elseif rax == -1
mov rax, 3 ; non matching quotation marks
.endif
ret
Arg_GetCommandLineExW ENDP
ENDIF
IF @Platform EQ 3 ; Linux x64
UASM64_ALIGN
;------------------------------------------------------------------------------
; Arg_GetCommandLineExW
;
; Extended version of Arg_GetCommandLine. This Arg_GetCommandLineEx function
; uses the Arg_GetArgument function to obtain the selected argument from a
; command line. It differs from the original version in that it will read a
; command line of any length and the arguments can be delimited by spaces, tabs,
; commas or any combination of the three.
; It is also faster but as the Arg_GetArgument function is table driven, it is
; also larger.
;
; Parameters:
;
; * nArgument - The argument number to return from a command line.
;
; * lpszArgumentBuffer - The buffer to receive the selected argument.
;
; Returns:
;
; There are three (3) possible return values:
; 1 = successful operation
; 2 = no argument exists at specified arg number
; 3 = non matching quotation marks
;
; See Also:
;
; Arg_GetCommandLineW, Arg_GetArgumentW
;
;------------------------------------------------------------------------------
Arg_GetCommandLineExW PROC FRAME nArgument:QWORD, lpszArgumentBuffer:QWORD
mov rax, 0 ; maybe we can get command line later with
; ; https://baturin.org/blog/hello-from-a-compiler-free-x86-64-world/
ret
Arg_GetCommandLineExW ENDP
ENDIF
END