-
Notifications
You must be signed in to change notification settings - Fork 3
/
env.S
79 lines (62 loc) · 1.23 KB
/
env.S
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
env_username: .ascii "USER"
env_shell: .ascii "SHELL"
env_desktop: .ascii "XDG_CURRENT_DESKTOP"
env_session: .ascii "XDG_SESSION_TYPE"
.lcomm username, 65
.lcomm username_length, 8
.lcomm shell_path, 65
.lcomm shell_path_length, 8
.lcomm desktop, 65
.lcomm desktop_length, 8
.lcomm session, 65
.lcomm session_length, 8
.lcomm target, 65
parse_envs:
mov rsi, 4
mov rdx, offset env_username
mov rdi, offset username
call find_env_var
mov username_length, rcx
xor rcx, rcx
mov rsi, 5
mov rdx, offset env_shell
mov rdi, offset shell_path
call find_env_var
mov shell_path_length, rcx
xor rcx, rcx
mov rsi, 19
mov rdx, offset env_desktop
mov rdi, offset desktop
call find_env_var
mov desktop_length, rcx
xor rcx, rcx
mov rsi, 16
mov rdx, offset env_session
mov rdi, offset session
call find_env_var
mov session_length, rcx
ret
find_env_var:
mov rax, [rbp]
xor r8, r8
xor r9, r9
env_match_loop:
test rax, rax
je find_env_var_done
mov bl, [rax + r9]
cmp bl, [rdx + r9]
je env_char_matched
xor r9, r9
inc r8
mov rax, [rbp + r8 * 8]
jmp env_match_loop
env_char_matched:
inc r9
cmp r9, rsi
jne env_match_loop
mov rsi, rax
add rsi, r9
inc rsi
call copy
find_env_var_done:
ret