day2
还是在sleep.jar里操作,承接上文链接
函数引用
println("-----函数引用------------------");
$addf = &addTwoValues;
[$addf : "3", 55.0];
[&addTwoValues : "3", 55.0];
[{ println($1 + $2); } : "3", 55.0];
while循环
println("-----while------------------");
$a = 0;
while ($a lt 6){
println($a);
$a = $a + 1;
}
for循环
println("-----for------------------");
$a = 0;
for ($i = 1; $i lt 6 ; $i++){
println($a);
$a = $a + 1;
}
agscript
在C2里加载插件
交互式操作
command foo {
println("Hello $1");
}
控制台文本颜色
\c 控制文本颜色
println("\c0This is my color");
println("\c1This is my color");
println("\c2This is my color");
println("\c3This is my color");
println("\c4This is my color");
println("\c5This is my color");
println("\c6This is my color");
println("\c7This is my color");
println("\c8This is my color");
println("\c9This is my color");
println("\cAThis is my color");
println("\cBThis is my color");
println("\cCThis is my color");
println("\cDThis is my color");
println("\cEThis is my color");
println("\cFThis is my color");
数据模型
C2自身提供的函数,可供脚本调用,如获取上线机器的信息,通过以下代码获取
println("-------------数据模型--------");
command export {
local('$handle $model $row $entry $index');
$handle = openf(">export.txt");
foreach $model (data_keys()) {
println($handle, "== $model ==");
println($handle, data_query($model));
}
closef($handle);
println("See export.txt for the data.");
}
在导出的txt可以搜索到其中的数据模型信息,比如搜索socks
x users()
x targets()
x beacon_ids()
x beacons()