-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
cwd-in-beacon-status-bar.cna
122 lines (100 loc) · 3.27 KB
/
cwd-in-beacon-status-bar.cna
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
#
# Simple Beacon console status bar enhancement showing Beacon's last known current
# working directory path, as well as adding fixed-width to last-seen meter.
#
# Additionally, this script enhances 'cd' command to make it restore previous path
# if "cd -" was issued (and previous path is known).
#
# Author:
# Mariusz Banach / mgeeky, '20
# <mb [at] binary-offensive.com>
# (https://github.com/mgeeky)
#
global('%OPERATING_BEACONS');
%OPERATING_BEACONS = %();
beacon_command_register(
"cd",
"Change directory on host. Use '-' to get back to previous cwd.",
"Use: cd [directory]\n\nChange directory on host. Use '-' to get back to previous cwd.");
set BEACON_SBAR_LEFT {
local('$hostname $username $pid $arch $pwd');
$hostname = $2["computer"];
$username = $2["user"];
$pid = $2["pid"];
$arch = $2["arch"];
$pwd = %OPERATING_BEACONS[$1]['cwd'];
return "[\c2 $+ $hostname $+ \o] $username $+ / $+ $pid \cE( $+ $arch $+ )\o\c2 $pwd \o";
}
set BEACON_SBAR_RIGHT {
local('$note $last');
$note = $2["note"];
$last = $2["lastf"];
return "\c6 $note \cE(last: $+ $[5]last $+ )\o";
}
on beacon_tasked {
local('$pwd $sep');
if('cd *' iswm $2) {
$pwd = substr($2, strlen("cd "));
$sep = iff(binfo($1, "os") eq "Windows", "\\", "/");
if($pwd eq "..") {
$pwd = substr(%OPERATING_BEACONS[$1]['cwd'], 0, lindexOf(%OPERATING_BEACONS[$1]['cwd'], $sep));
if($pwd eq "..") {
return "\cC[*]\o $2";
}
}
else if($pwd eq ".") {
return "\cC[*]\o $2";
}
else if((strlen($pwd) >= 2) && (charAt($pwd, 1) ne ":")) {
# relative path?
$pwd = %OPERATING_BEACONS[$1]['cwd'] . $sep . $pwd;
}
%OPERATING_BEACONS[$1]['prev-cwd'] = %OPERATING_BEACONS[$1]['cwd'];
%OPERATING_BEACONS[$1]['cwd'] = $pwd;
return "\cC[*]\o $2";
}
}
set BEACON_OUTPUT_ALT {
local('$pwd');
if($2 ismatch 'Current directory is (.+)') {
$pwd = matched()[0];
%OPERATING_BEACONS[$1]['prev-cwd'] = %OPERATING_BEACONS[$1]['cwd'];
%OPERATING_BEACONS[$1]['cwd'] = $pwd;
return "\cC[*]\o Current directory is \cC" . $pwd . "\o\n";
}
return "\cC[*]\o $2\n";
}
on beacon_input {
if (["$3" trim] eq "ls") {
%OPERATING_BEACONS[$1]['cwd-use-ls'] = 1;
}
}
on beacon_output_ls {
local('$pwd');
if(%OPERATING_BEACONS[$1]['cwd-use-ls'] == 1) {
$pwd = split("\n", ["$2" trim])[0];
if(right($pwd, 2) eq "\\*") {
$pwd = substr($pwd, 0, -2);
}
%OPERATING_BEACONS[$1]['prev-cwd'] = %OPERATING_BEACONS[$1]['cwd'];
%OPERATING_BEACONS[$1]['cwd'] = $pwd;
%OPERATING_BEACONS[$1]['cwd-use-ls'] = 0;
}
}
on beacons {
if(%OPERATING_BEACONS is $null) {
%OPERATING_BEACONS = %();
}
foreach $b ($1) {
if(iff($b in keys(%OPERATING_BEACONS), "true", $null)) {
%OPERATING_BEACONS[$b] = %();
}
}
}
alias cd {
if(($2 eq "-") && (strlen(%OPERATING_BEACONS[$1]['prev-cwd']) > 0)) {
bcd($1, %OPERATING_BEACONS[$1]['prev-cwd']);
return;
}
bcd($1, $2);
}