Projects STRLCPY CVS Commits c2a827e8
🤬
  • ■ ■ ■ ■ ■ ■
    README.md
    skipped 48 lines
    49 49   - Output format support - **JSON**
    50 50   
    51 51  ## Usage
    52  -CVS consists of three parts: **CVS scanner**, **PoC IDE**, and **OOB server**. CVS scanner is used to read the scaned target information generated by Senluo and load PoC for vulnerability scanning. PoC IDE is used to write and debug vulnerability scripts and generate PoC files. OOB server is used for reverse connection platforms such as some vulnerabilities without echo to confirm the existence of vulnerabilities.
     52 +CVS consists of three parts: **CVS scanner**, **PoC IDE**, and **OOB server**. CVS scanner is used to read the scaned target information generated by Senluo and load PoC for vulnerability scanning. PoC IDE is used to write and debug vulnerability scripts and generate PoC files. OOB server is used for reverse connection platforms such as some vulnerabilities without echo to confirm the existence of vulnerabilities.VDSL syntax can be referenced https://github.com/Safe3/CVS/blob/main/VDSL.md
    53 53   
    54 54  ### Write PoC
    55 55   
    skipped 11 lines
    67 67  </h3>
    68 68   
    69 69   
    70  -The upper right corner of the above picture shows the Run, Save, and Refresh buttons, which are used to debug PoC scripts. The syntax of the script is similar to Golang. The **cvs structure** in the picture will be automatically generated by the CVS scanner based on target.json, without the need for implementation. It is only convenient for testing during debugging and can be declared by oneself. This picture shows the writing process of the CVE-2022-46169 no echo vulnerability test script. CVS IDE provides the **debug function** for printing debugging information, which is compatible with **fmt.Printf** in the go language The usage is shown in the text box below. For vulnerabilities with echoes, the existence of the vulnerability can be confirmed directly by returning true. For scenarios that require some information to be returned, such as password cracking, a string can be returned to save the result, which is located in the info field of the result. json generated by the CVS scanner. The functions in the PoC script are compatible with the help functions of Nuclei, please refer to them for details https://docs.projectdiscovery.io/templates/reference/helper-functions So it is very convenient to convert Nuclei's vulnerability template into CVS's PoC. For more PoC examples, please refer to the yaml file in the poc directory of the CVS scanner.
     70 +The upper right corner of the above picture shows the Run, Save, and Refresh buttons, which are used to debug PoC scripts. The syntax of the script is similar to Golang. The **cvs structure** in the picture will be automatically generated by the CVS scanner based on target.json, without the need for implementation. It is only convenient for testing during debugging and can be declared by oneself. This picture shows the writing process of the CVE-2022-46169 no echo vulnerability test script. CVS IDE provides the **debug function** for printing debugging information, which is compatible with **fmt.Printf** in the go language The usage is shown in the text box below. For vulnerabilities with echoes, the existence of the vulnerability can be confirmed directly by returning true. For scenarios that require some information to be returned, such as password cracking, a string can be returned to save the result, which is located in the info field of the result. json generated by the CVS scanner. The functions in the PoC script are compatible with the help functions of Nuclei, please refer to them for details https://docs.projectdiscovery.io/templates/reference/helper-functions .In addition, CVS also provides a network library, please refer to https://github.com/Safe3/CVS/blob/main/library.md for details,so it is very convenient to convert Nuclei's vulnerability template into CVS's PoC. For more PoC examples, please refer to the yaml file in the poc directory of the CVS scanner.
    71 71   
    72 72  ### Setting up an OOB server
    73 73   
    skipped 76 lines
  • ■ ■ ■ ■ ■ ■
    README_CN.md
    skipped 54 lines
    55 55   
    56 56  ## 使用
    57 57   
    58  -CVS由三部分组成:**CVS扫描器**、**PoC IDE**和**OOB服务器**。CVS扫描器用于读取森罗空间测绘引擎生成的扫描目标信息,并加载PoC进行漏洞扫描。PoC IDE用于编写和调试漏洞脚本以及生成PoC文件。OOB服务器用于反向连接平台,如一些没有回显的漏洞,以确认漏洞的存在。
     58 +CVS由三部分组成:**CVS扫描器**、**PoC IDE**和**OOB服务器**。CVS扫描器用于读取森罗空间测绘引擎生成的扫描目标信息,并加载PoC进行漏洞扫描。PoC IDE用于编写和调试漏洞脚本以及生成PoC文件。OOB服务器用于反向连接平台,如一些没有回显的漏洞,以确认漏洞的存在。VDSLhttps://github.com/Safe3/CVS/blob/main/VDSL_CN.md
    59 59   
    60 60   
    61 61  ### 编写PoC
    skipped 3 lines
    65 65  ```sh
    66 66  ide.exe
    67 67  ```
    68  -浏览器打开http://127.0.0.1:777/即可看到PoC开发环境,该IDE提供了PoC的编写、调试和保存等功能,并支持代码补全和智能提示,如下图所示:
     68 +浏览器打开http://127.0.0.1:777/ 即可看到PoC开发环境,该IDE提供了PoC的编写、调试和保存等功能,并支持代码补全和智能提示,如下图所示:
    69 69   
    70 70  <h3 align="center">
    71 71   <img src="https://github.com/Safe3/CVS/blob/main/ide.png" alt="IDE" width="700px">
    72 72   <br>
    73 73  </h3>
    74  - 
    75  -上图右上角分别为运行、保存、刷新按钮,运行按钮用于调试PoC脚本,该脚本语法类似golang,图中**cvs结构体**在CVS扫描器中会自动根据target.json生成,无需实现,仅在调试时方便测试,自行声明。此图展示的是CVE-2022-46169无回显漏洞测试脚本的编写过程,图中提供了**debug函数**用于打印调试信息,该函数兼容go语言中fmt.Printf的用法,结果显示于下方方框。对于有回显的漏洞可以直接通过**return true**返回来确认漏洞存在,对于需要返回一些信息的场景,如密码破解等,可以return一个字符串来保存结果,结果位于CVS扫描器生成的result.json中的info字段中。PoC脚本中的函数兼容Nuclei的帮助函数,详见https://docs.projectdiscovery.io/templates/reference/helper-functions,所以可以很方便的将Nuclei的漏洞模板转换成CVS的PoC。更多PoC样例可参考CVS扫描器poc目录下的yaml文件。
     74 +上图右上角分别为运行、保存、刷新按钮,运行按钮用于调试PoC脚本,该脚本语法类似golang,图中**cvs结构体**在CVS扫描器中会自动根据target.json生成,无需实现,仅在调试时方便测试,自行声明。此图展示的是CVE-2022-46169无回显漏洞测试脚本的编写过程,图中提供了**debug函数**用于打印调试信息,该函数兼容go语言中fmt.Printf的用法,结果显示于下方方框。对于有回显的漏洞可以直接通过**return true**返回来确认漏洞存在,对于需要返回一些信息的场景,如密码破解等,可以return一个字符串来保存结果,结果位于CVS扫描器生成的result.json中的info字段中。PoC脚本中的函数兼容Nuclei的帮助函数,详见https://docs.projectdiscovery.io/templates/reference/helper-functions ,另外CVS也提供了网络请求相关lib库,详见https://github.com/Safe3/CVS/blob/main/library.md 。所以你可以很方便的将Nuclei的漏洞模板转换成CVS的PoC。更多PoC样例可参考CVS扫描器poc目录下的yaml文件。
    76 75   
    77 76  ### 架设OOB服务器
    78 77   
    skipped 13 lines
    92 91  log_level: info
    93 92  ```
    94 93   
    95  -4.放开服务器的80、53、33333端口访问,并将OOB服务器设置为NS解析服务器,如阿里云上的域名可以参考https://help.aliyun.com/zh/dws/user-guide/custom-dns-host进行配置
     94 +4.放开服务器的80、53、33333端口访问,并将OOB服务器设置为NS解析服务器,如阿里云上的域名可以参考https://help.aliyun.com/zh/dws/user-guide/custom-dns-host 进行配置
    96 95   
    97 96  ### 开启CVS扫描器
    98 97   
    skipped 56 lines
  • ■ ■ ■ ■ ■ ■
    VDSL.md
     1 +# VDSL Language Syntax
     2 + 
     3 +VDSL's syntax is designed to be familiar to Go developers while being a bit
     4 +simpler and more streamlined.
     5 + 
     6 +**You can test the VDSL code in CVE PoC IDE.**
     7 + 
     8 +## Values and Value Types
     9 + 
     10 +In VDSL, everything is a value, and, all values are associated with a type.
     11 + 
     12 +```golang
     13 +11 + 22 // int values
     14 +"aa" + `bb` // string values
     15 +-1.22 + 3e9 // float values
     16 +true || false // bool values
     17 +'七' > '7' // char values
     18 +[33, false, "xx"] // array value
     19 +{a: true, b: "oo"} // map value
     20 +func() { /*...*/ } // function value
     21 +```
     22 + 
     23 +Here's a list of all available value types in VDSL.
     24 + 
     25 +| VDSL Type | Description | Equivalent Type in Go |
     26 +| :---: | :---: | :---: |
     27 +| int | signed 64-bit integer value | `int64` |
     28 +| float | 64-bit floating point value | `float64` |
     29 +| bool | boolean value | `bool` |
     30 +| char | unicode character | `rune` |
     31 +| string | unicode string | `string` |
     32 +| bytes | byte array | `[]byte` |
     33 +| error | [error](#error-values) value | - |
     34 +| time | time value | `time.Time` |
     35 +| array | value array _(mutable)_ | `[]any` |
     36 +| const array | [const](#const-values) array | - |
     37 +| map | value map with string keys _(mutable)_ | `map[string]any` |
     38 +| const map | [const](#const-values) map | - |
     39 +| nil | [nil](#nil-values) value | - |
     40 +| function | [function](#function-values) value | - |
     41 +| _user-defined_ | value of [user-defined types](https://github.com/Safe3/dsl/blob/master/docs/objects.md) | - |
     42 + 
     43 +### Error Values
     44 + 
     45 +In VDSL, an error can be represented using "error" typed values. An error
     46 +value is created using `error` expression, and, it must have an underlying
     47 +value. The underlying value of an error value can be access using `.value`
     48 +selector.
     49 + 
     50 +```golang
     51 +err1 := error("oops") // error with string value
     52 +err2 := error(1+2+3) // error with int value
     53 +if is_error(err1) { // 'is_error' builtin function
     54 + err_val := err1.value // get underlying value
     55 +}
     56 +```
     57 + 
     58 +### Const Values
     59 + 
     60 +In VDSL, basically all values (except for array and map) are const.
     61 + 
     62 +```golang
     63 +s := "12345"
     64 +s[1] = 'b' // illegal: String is const
     65 + 
     66 +a := [1, 2, 3]
     67 +a[1] = "two" // ok: a is now [1, "two", 3]
     68 +```
     69 + 
     70 +An array or map value can be made const using `const` expression.
     71 + 
     72 +```golang
     73 +b := const([1, 2, 3])
     74 +b[1] = "foo" // illegal: 'b' references to an const array.
     75 +```
     76 + 
     77 +Note that re-assigning a new value to the variable has nothing to do with the
     78 +value immutability.
     79 + 
     80 +```golang
     81 +s := "abc"
     82 +s = "foo" // ok
     83 +a := const([1, 2, 3])
     84 +a = false // ok
     85 +```
     86 + 
     87 +Note that, if you copy (using `copy` builtin function) an const value, it
     88 +will return a "mutable" copy. Also, immutability is not applied to the
     89 +individual elements of the array or map value, unless they are explicitly made
     90 +const.
     91 + 
     92 +```golang
     93 +a := const({b: 4, c: [1, 2, 3]})
     94 +a.b = 5 // illegal
     95 +a.c[1] = 5 // ok: because 'a.c' is not const
     96 + 
     97 +a = const({b: 4, c: const([1, 2, 3])})
     98 +a.c[1] = 5 // illegal
     99 +```
     100 + 
     101 +### Nil Values
     102 + 
     103 +In VDSL, an "nil" value can be used to represent an unexpected or
     104 +non-existing value:
     105 + 
     106 +- A function that does not return a value explicitly considered to return
     107 +`nil` value.
     108 +- Indexer or selector on composite value types may return `nil` if the
     109 +key or index does not exist.
     110 +- Type conversion builtin functions without a default value will return
     111 +`nil` if conversion fails.
     112 + 
     113 +```golang
     114 +a := func() { b := 4 }() // a == nil
     115 +b := [1, 2, 3][10] // b == nil
     116 +c := {a: "foo"}["b"] // c == nil
     117 +d := int("foo") // d == nil
     118 +```
     119 + 
     120 +### Array Values
     121 + 
     122 +In VDSL, array is an ordered list of values of any types. Elements of an array
     123 +can be accessed using indexer `[]`.
     124 + 
     125 +```golang
     126 +[1, 2, 3][0] // == 1
     127 +[1, 2, 3][2] // == 3
     128 +[1, 2, 3][3] // == nil
     129 + 
     130 +["foo", "bar", [1, 2, 3]] // ok: array with an array element
     131 +```
     132 + 
     133 +### Map Values
     134 + 
     135 +In VDSL, map is a set of key-value pairs where key is string and the value is
     136 +of any value types. Value of a map can be accessed using indexer `[]` or
     137 +selector '.' operators.
     138 + 
     139 +```golang
     140 +m := { a: 1, b: false, c: "foo" }
     141 +m["b"] // == false
     142 +m.c // == "foo"
     143 +m.x // == nil
     144 + 
     145 +{a: [1,2,3], b: {c: "foo", d: "bar"}} // ok: map with an array element and a map element
     146 +```
     147 + 
     148 +### Function Values
     149 + 
     150 +In VDSL, function is a callable value with a number of function arguments and
     151 +a return value. Just like any other values, functions can be passed into or
     152 +returned from another function.
     153 + 
     154 +```golang
     155 +my_func := func(arg1, arg2) {
     156 + return arg1 + arg2
     157 +}
     158 + 
     159 +adder := func(base) {
     160 + return func(x) { return base + x } // capturing 'base'
     161 +}
     162 +add5 := adder(5)
     163 +nine := add5(4) // == 9
     164 +```
     165 + 
     166 +Unlike Go, VDSL does not have declarations. So the following code is illegal:
     167 + 
     168 +```golang
     169 +func my_func(arg1, arg2) { // illegal
     170 + return arg1 + arg2
     171 +}
     172 +```
     173 + 
     174 +VDSL also supports variadic functions/closures:
     175 + 
     176 +```golang
     177 +variadic := func (a, b, ...c) {
     178 + return [a, b, c]
     179 +}
     180 +variadic(1, 2, 3, 4) // [1, 2, [3, 4]]
     181 + 
     182 +variadicClosure := func(a) {
     183 + return func(b, ...c) {
     184 + return [a, b, c]
     185 + }
     186 +}
     187 +variadicClosure(1)(2, 3, 4) // [1, 2, [3, 4]]
     188 +```
     189 + 
     190 +Only the last parameter can be variadic. The following code is also illegal:
     191 + 
     192 +```golang
     193 +// illegal, because a is variadic and is not the last parameter
     194 +illegal := func(a..., b) { /*... */ }
     195 +```
     196 + 
     197 +When calling a function, the number of passing arguments must match that of
     198 +function definition.
     199 + 
     200 +```golang
     201 +f := func(a, b) {}
     202 +f(1, 2, 3) // Runtime Error: wrong number of arguments: want=2, got=3
     203 +```
     204 + 
     205 +Like Go, you can use ellipsis `...` to pass array-type value as its last parameter:
     206 + 
     207 +```golang
     208 +f1 := func(a, b, c) { return a + b + c }
     209 +f1([1, 2, 3]...) // => 6
     210 +f1(1, [2, 3]...) // => 6
     211 +f1(1, 2, [3]...) // => 6
     212 +f1([1, 2]...) // Runtime Error: wrong number of arguments: want=3, got=2
     213 + 
     214 +f2 := func(a, ...b) {}
     215 +f2(1) // valid; a = 1, b = []
     216 +f2(1, 2) // valid; a = 1, b = [2]
     217 +f2(1, 2, 3) // valid; a = 1, b = [2, 3]
     218 +f2([1, 2, 3]...) // valid; a = 1, b = [2, 3]
     219 +```
     220 + 
     221 +## Variables and Scopes
     222 + 
     223 +A value can be assigned to a variable using assignment operator `:=` and `=`.
     224 + 
     225 +- `:=` operator defines a new variable in the scope and assigns a value.
     226 +- `=` operator assigns a new value to an existing variable in the scope.
     227 + 
     228 +Variables are defined either in global scope (defined outside function) or in
     229 +local scope (defined inside function).
     230 + 
     231 +```golang
     232 +a := "foo" // define 'a' in global scope
     233 + 
     234 +func() { // function scope A
     235 + b := 52 // define 'b' in function scope A
     236 + 
     237 + func() { // function scope B
     238 + c := 19.84 // define 'c' in function scope B
     239 + 
     240 + a = "bee" // ok: assign new value to 'a' from global scope
     241 + b = 20 // ok: assign new value to 'b' from function scope A
     242 + 
     243 + b := true // ok: define new 'b' in function scope B
     244 + // (shadowing 'b' from function scope A)
     245 + }
     246 + 
     247 + a = "bar" // ok: assigne new value to 'a' from global scope
     248 + b = 10 // ok: assigne new value to 'b'
     249 + a := -100 // ok: define new 'a' in function scope A
     250 + // (shadowing 'a' from global scope)
     251 + 
     252 + c = -9.1 // illegal: 'c' is not defined
     253 + b := [1, 2] // illegal: 'b' is already defined in the same scope
     254 +}
     255 + 
     256 +b = 25 // illegal: 'b' is not defined
     257 +a := {d: 2} // illegal: 'a' is already defined in the same scope
     258 +```
     259 + 
     260 +Unlike Go, a variable can be assigned a value of different types.
     261 + 
     262 +```golang
     263 +a := 123 // assigned 'int'
     264 +a = "123" // re-assigned 'string'
     265 +a = [1, 2, 3] // re-assigned 'array'
     266 +```
     267 + 
     268 +## Type Conversions
     269 + 
     270 +Although the type is not directly specified in VDSL, one can use type
     271 +conversion
     272 +[builtin functions](https://github.com/Safe3/dsl/blob/master/docs/builtins.md)
     273 +to convert between value types.
     274 + 
     275 +```golang
     276 +s1 := string(1984) // "1984"
     277 +i2 := int("-999") // -999
     278 +f3 := float(-51) // -51.0
     279 +b4 := bool(1) // true
     280 +c5 := char("X") // 'X'
     281 +```
     282 + 
     283 +See [Operators](https://github.com/Safe3/dsl/blob/master/docs/operators.md)
     284 +for more details on type coercions.
     285 + 
     286 +## Operators
     287 + 
     288 +### Unary Operators
     289 + 
     290 +| Operator | Usage | Types |
     291 +| :---: | :---: | :---: |
     292 +| `+` | same as `0 + x` | int, float |
     293 +| `-` | same as `0 - x` | int, float |
     294 +| `!` | logical NOT | all types* |
     295 +| `^` | bitwise complement | int |
     296 + 
     297 +_In VDSL, all values can be either
     298 +[truthy or falsy](https://github.com/Safe3/dsl/blob/d5-patch-1/docs/runtime-types.md#objectisfalsy)._
     299 + 
     300 +### Binary Operators
     301 + 
     302 +| Operator | Usage | Types |
     303 +| :---: | :---: | :---: |
     304 +| `==` | equal | all types |
     305 +| `!=` | not equal | all types |
     306 +| `&&` | logical AND | all types |
     307 +| `\|\|` | logical OR | all types |
     308 +| `+` | add/concat | int, float, string, char, time, array |
     309 +| `-` | subtract | int, float, char, time |
     310 +| `*` | multiply | int, float |
     311 +| `/` | divide | int, float |
     312 +| `&` | bitwise AND | int |
     313 +| `\|` | bitwise OR | int |
     314 +| `^` | bitwise XOR | int |
     315 +| `&^` | bitclear (AND NOT) | int |
     316 +| `<<` | shift left | int |
     317 +| `>>` | shift right | int |
     318 +| `<` | less than | int, float, char, time, string |
     319 +| `<=` | less than or equal to | int, float, char, time, string |
     320 +| `>` | greater than | int, float, char, time, string |
     321 +| `>=` | greater than or equal to | int, float, char, time, string |
     322 + 
     323 +_See [Operators](https://github.com/Safe3/dsl/blob/master/docs/operators.md)
     324 +for more details._
     325 + 
     326 +### Ternary Operators
     327 + 
     328 +VDSL has a ternary conditional operator `(condition expression) ? (true expression) : (false expression)`.
     329 + 
     330 +```golang
     331 +a := true ? 1 : -1 // a == 1
     332 + 
     333 +min := func(a, b) {
     334 + return a < b ? a : b
     335 +}
     336 +b := min(5, 10) // b == 5
     337 +```
     338 + 
     339 +### Assignment and Increment Operators
     340 + 
     341 +| Operator | Usage |
     342 +| :---: | :---: |
     343 +| `+=` | `(lhs) = (lhs) + (rhs)` |
     344 +| `-=` | `(lhs) = (lhs) - (rhs)` |
     345 +| `*=` | `(lhs) = (lhs) * (rhs)` |
     346 +| `/=` | `(lhs) = (lhs) / (rhs)` |
     347 +| `%=` | `(lhs) = (lhs) % (rhs)` |
     348 +| `&=` | `(lhs) = (lhs) & (rhs)` |
     349 +| `\|=` | `(lhs) = (lhs) \| (rhs)` |
     350 +| `&^=` | `(lhs) = (lhs) &^ (rhs)` |
     351 +| `^=` | `(lhs) = (lhs) ^ (rhs)` |
     352 +| `<<=` | `(lhs) = (lhs) << (rhs)` |
     353 +| `>>=` | `(lhs) = (lhs) >> (rhs)` |
     354 +| `++` | `(lhs) = (lhs) + 1` |
     355 +| `--` | `(lhs) = (lhs) - 1` |
     356 + 
     357 +### Operator Precedences
     358 + 
     359 +Unary operators have the highest precedence, and, ternary operator has the
     360 +lowest precedence. There are five precedence levels for binary operators.
     361 +Multiplication operators bind strongest, followed by addition operators,
     362 +comparison operators, `&&` (logical AND), and finally `||` (logical OR):
     363 + 
     364 +| Precedence | Operator |
     365 +| :---: | :---: |
     366 +| 5 | `*` `/` `%` `<<` `>>` `&` `&^` |
     367 +| 4 | `+` `-` `\|` `^` |
     368 +| 3 | `==` `!=` `<` `<=` `>` `>=` |
     369 +| 2 | `&&` |
     370 +| 1 | `\|\|` |
     371 + 
     372 +Like Go, `++` and `--` operators form statements, not expressions, they fall
     373 +outside the operator hierarchy.
     374 + 
     375 +### Selector and Indexer
     376 + 
     377 +One can use selector (`.`) and indexer (`[]`) operators to read or write
     378 +elements of composite types (array, map, string, bytes).
     379 + 
     380 +```golang
     381 +["one", "two", "three"][1] // == "two"
     382 + 
     383 +m := {
     384 + a: 1,
     385 + b: [2, 3, 4],
     386 + c: func() { return 10 }
     387 +}
     388 +m.a // == 1
     389 +m["b"][1] // == 3
     390 +m.c() // == 10
     391 +m.x = 5 // add 'x' to map 'm'
     392 +m["b"][5] // == nil
     393 +m["b"][5].d // == nil
     394 +m.b[5] = 0 // == nil
     395 +m.x.y.z // == nil
     396 +```
     397 + 
     398 +Like Go, one can use slice operator `[:]` for sequence value types such as
     399 +array, string, bytes.
     400 + 
     401 +```golang
     402 +a := [1, 2, 3, 4, 5][1:3] // == [2, 3]
     403 +b := [1, 2, 3, 4, 5][3:] // == [4, 5]
     404 +c := [1, 2, 3, 4, 5][:3] // == [1, 2, 3]
     405 +d := "hello world"[2:10] // == "llo worl"
     406 +c := [1, 2, 3, 4, 5][-1:10] // == [1, 2, 3, 4, 5]
     407 +```
     408 + 
     409 +**Note: Keywords cannot be used as selectors.**
     410 + 
     411 +```golang
     412 +a := {in: true} // Parse Error: expected map key, found 'in'
     413 +a.func = "" // Parse Error: expected selector, found 'func'
     414 +```
     415 + 
     416 +Use double quotes and indexer to use keywords with maps.
     417 + 
     418 +```golang
     419 +a := {"in": true}
     420 +a["func"] = ""
     421 +```
     422 + 
     423 +## Statements
     424 + 
     425 +### If Statement
     426 + 
     427 +"If" statement is very similar to Go.
     428 + 
     429 +```golang
     430 +if a < 0 {
     431 + // execute if 'a' is negative
     432 +} else if a == 0 {
     433 + // execute if 'a' is zero
     434 +} else {
     435 + // execute if 'a' is positive
     436 +}
     437 +```
     438 + 
     439 +Like Go, the condition expression may be preceded by a simple statement,
     440 +which executes before the expression is evaluated.
     441 + 
     442 +```golang
     443 +if a := foo(); a < 0 {
     444 + // execute if 'a' is negative
     445 +}
     446 +```
     447 + 
     448 +### For Statement
     449 + 
     450 +"For" statement is very similar to Go.
     451 + 
     452 +```golang
     453 +// for (init); (condition); (post) {}
     454 +for a:=0; a<10; a++ {
     455 + // ...
     456 +}
     457 + 
     458 +// for (condition) {}
     459 +for a < 10 {
     460 + // ...
     461 +}
     462 + 
     463 +// for {}
     464 +for {
     465 + // ...
     466 +}
     467 +```
     468 + 
     469 +### For-In Statement
     470 + 
     471 +"For-In" statement is new in VDSL. It's similar to Go's `for range` statement.
     472 +"For-In" statement can iterate any iterable value types (array, map, bytes,
     473 +string, nil).
     474 + 
     475 +```golang
     476 +for v in [1, 2, 3] { // array: element
     477 + // 'v' is value
     478 +}
     479 +for i, v in [1, 2, 3] { // array: index and element
     480 + // 'i' is index
     481 + // 'v' is value
     482 +}
     483 +for k, v in {k1: 1, k2: 2} { // map: key and value
     484 + // 'k' is key
     485 + // 'v' is value
     486 +}
     487 +```
     488 + 
     489 +## Modules
     490 + 
     491 +Module is the basic compilation unit in VDSL. A module can import another
     492 +module using `import` expression.
     493 + 
     494 +Main module:
     495 + 
     496 +```golang
     497 +sum := import("./sum") // load module from a local file
     498 +fmt.print(sum(10)) // module function
     499 +```
     500 + 
     501 +Another module in `sum.dsl` file:
     502 + 
     503 +```golang
     504 +base := 5
     505 + 
     506 +export func(x) {
     507 + return x + base
     508 +}
     509 +```
     510 + 
     511 +By default, `import` solves the missing extension name of a module file as
     512 +"`.dsl`"[^note].
     513 +Thus, `sum := import("./sum")` is equivalent to `sum := import("./sum.dsl")`.
     514 + 
     515 +[^note]:
     516 + If using VDSL as a library in Go, the file extension name "`.dsl`" can
     517 + be customized. In that case, use the `SetImportFileExt` function of the
     518 + `Compiler` type.
     519 + See the [Go reference](https://pkg.go.dev/dsl) for details.
     520 + 
     521 +In VDSL, modules are very similar to functions.
     522 + 
     523 +- `import` expression loads the module code and execute it like a function.
     524 +- Module should return a value using `export` statement.
     525 + - Module can return `export` a value of any types: int, map, function, etc.
     526 + - `export` in a module is like `return` in a function: it stops execution and
     527 + return a value to the importing code.
     528 + - `export`-ed values are always const.
     529 + - If the module does not have any `export` statement, `import` expression
     530 + simply returns `nil`. _(Just like the function that has no `return`.)_
     531 + - Note that `export` statement is completely ignored and not evaluated if
     532 + the code is executed as a main module.
     533 + 
     534 +Also, you can use `import` expression to load the
     535 +[Standard Library](https://github.com/Safe3/dsl/blob/master/docs/stdlib.md) as
     536 +well.
     537 + 
     538 +```golang
     539 +math := import("math")
     540 +a := math.abs(-19.84) // == 19.84
     541 +```
     542 + 
     543 +## Comments
     544 + 
     545 +Like Go, VDSL supports line comments (`//...`) and block comments
     546 +(`/* ... */`).
     547 + 
     548 +```golang
     549 +/*
     550 + multi-line block comments
     551 +*/
     552 + 
     553 +a := 5 // line comments
     554 +```
     555 + 
     556 +## Differences from Go
     557 + 
     558 +Unlike Go, VDSL does not have the following:
     559 + 
     560 +- Declarations
     561 +- Imaginary values
     562 +- Structs
     563 +- Pointers
     564 +- Channels
     565 +- Goroutines
     566 +- Tuple assignment
     567 +- Variable parameters
     568 +- Switch statement
     569 +- Goto statement
     570 +- Defer statement
     571 +- Panic
     572 +- Type assertion
     573 + 
  • ■ ■ ■ ■ ■ ■
    VDSL_CN.md
     1 +# VDSL语法
     2 + 
     3 +VDSL的语法设计为Go开发人员所熟悉,同时更简单、更精简。
     4 + 
     5 +**您可以在CVE PoC IDE中测试VDSL代码**
     6 + 
     7 +## 值和值类型
     8 + 
     9 +在VDSL中,一切都是一个值,并且所有值都与一个类型相关联。
     10 + 
     11 +```golang
     12 +11 + 22 // int 值
     13 +"aa" + `bb` // string 值
     14 +-1.22 + 3e9 // float 值
     15 +true || false // bool 值
     16 +'七' > '7' // char 值
     17 +[33, false, "xx"] // array 值
     18 +{a: true, b: "oo"} // map 值
     19 +func() { /*...*/ } // function 值
     20 +```
     21 + 
     22 +以下是VDSL中所有可用值类型的列表。
     23 + 
     24 +| VDSL 类型 | 描述 | go中的等效类型 |
     25 +| :---: | :---: | :---: |
     26 +| int | 有符号64位整数值 | `int64` |
     27 +| float | 64位浮点值 | `float64` |
     28 +| bool | 布尔值 | `bool` |
     29 +| char | unicode字符 | `rune` |
     30 +| string | unicode字符串 | `string` |
     31 +| bytes | 字节数组 | `[]byte` |
     32 +| error | [错误](#error-values) 值 | - |
     33 +| time | 时间值 | `time.Time` |
     34 +| array | 值数组_(可变 )_ | `[]any` |
     35 +| const array | [常量](#const-values) 数组 | - |
     36 +| map | 具有字符串键的值映射 _(可变)_ | `map[string]any` |
     37 +| const map | [常量](#const-values) 映射 | - |
     38 +| nil | [nil](#nil-values) 值 | - |
     39 +| function | [函数](#function-values) 值 | - |
     40 +| _user-defined_ | 用户定义类型 | - |
     41 + 
     42 +### Error 值
     43 + 
     44 +在VDSL中,可以使用“error”类型的值来表示错误。一个错误值是使用“error”表达式创建的,并且它必须有一个底层值可以使用`.value`访问错误值的基础值选择器。
     45 + 
     46 +```golang
     47 +err1 := error("oops") // error with string value
     48 +err2 := error(1+2+3) // error with int value
     49 +if is_error(err1) { // 'is_error' builtin function
     50 + err_val := err1.value // get underlying value
     51 +}
     52 +```
     53 + 
     54 +### Const 值
     55 + 
     56 +在VDSL中,基本上所有的值(除了数组和映射)都是常量。
     57 + 
     58 +```golang
     59 +s := "12345"
     60 +s[1] = 'b' // illegal: String is const
     61 + 
     62 +a := [1, 2, 3]
     63 +a[1] = "two" // ok: a is now [1, "two", 3]
     64 +```
     65 + 
     66 +可以使用“const”表达式将数组或映射值设为const。
     67 + 
     68 +```golang
     69 +b := const([1, 2, 3])
     70 +b[1] = "foo" // illegal: 'b' references to an const array.
     71 +```
     72 + 
     73 +请注意,将新值重新分配给变量与值不变性不冲突。
     74 + 
     75 +```golang
     76 +s := "abc"
     77 +s = "foo" // ok
     78 +a := const([1, 2, 3])
     79 +a = false // ok
     80 +```
     81 + 
     82 +请注意,如果复制(使用“copy”内置函数)常量值将返回一个“可变”副本。此外,不变性不适用于数组或映射值的各个元素,除非它们是显式生成的常量。
     83 + 
     84 +```golang
     85 +a := const({b: 4, c: [1, 2, 3]})
     86 +a.b = 5 // illegal
     87 +a.c[1] = 5 // ok: because 'a.c' is not const
     88 + 
     89 +a = const({b: 4, c: const([1, 2, 3])})
     90 +a.c[1] = 5 // illegal
     91 +```
     92 + 
     93 +### Nil 值
     94 + 
     95 +在VDSL中,“nil”值可用于表示意外的或不存在的值:
     96 + 
     97 +- 一个函数,它不返回或明确返回`nil`值,都被认为返回nil值。
     98 +- 如果键或索引不存在,则复合值类型的索引器或选择器可能返回`nil`。
     99 +- 如果转换失败,没有默认值的类型转换内置函数将返回“nil”。
     100 + 
     101 +```golang
     102 +a := func() { b := 4 }() // a == nil
     103 +b := [1, 2, 3][10] // b == nil
     104 +c := {a: "foo"}["b"] // c == nil
     105 +d := int("foo") // d == nil
     106 +```
     107 + 
     108 +### Array 值
     109 + 
     110 +在VDSL中,数组是任何类型的值的有序列表。可以使用索引器“[]”访问数组的元素。
     111 + 
     112 +```golang
     113 +[1, 2, 3][0] // == 1
     114 +[1, 2, 3][2] // == 3
     115 +[1, 2, 3][3] // == nil
     116 + 
     117 +["foo", "bar", [1, 2, 3]] // ok: array with an array element
     118 +```
     119 + 
     120 +### Map 值
     121 + 
     122 +在VDSL中,map是一组键值对,其中key是字符串,value是任何值类型。可以使用索引器“[]”或选择器“”访问映射的值操作员。
     123 + 
     124 +```golang
     125 +m := { a: 1, b: false, c: "foo" }
     126 +m["b"] // == false
     127 +m.c // == "foo"
     128 +m.x // == nil
     129 + 
     130 +{a: [1,2,3], b: {c: "foo", d: "bar"}} // ok: map with an array element and a map element
     131 +```
     132 + 
     133 +### Function 值
     134 + 
     135 +在VDSL中,函数是一个具有多个函数参数和一个返回值的可调用值。就像任何其他值一样,函数可以传递到另一个函数中,也可以从该函数返回。
     136 + 
     137 +```golang
     138 +my_func := func(arg1, arg2) {
     139 + return arg1 + arg2
     140 +}
     141 + 
     142 +adder := func(base) {
     143 + return func(x) { return base + x } // capturing 'base'
     144 +}
     145 +add5 := adder(5)
     146 +nine := add5(4) // == 9
     147 +```
     148 + 
     149 +与Go不同,VDSL没有声明。因此,以下代码是非法的:
     150 + 
     151 +```golang
     152 +func my_func(arg1, arg2) { // illegal
     153 + return arg1 + arg2
     154 +}
     155 +```
     156 + 
     157 +VDSL还支持可变函数/闭包:
     158 + 
     159 +```golang
     160 +variadic := func (a, b, ...c) {
     161 + return [a, b, c]
     162 +}
     163 +variadic(1, 2, 3, 4) // [1, 2, [3, 4]]
     164 + 
     165 +variadicClosure := func(a) {
     166 + return func(b, ...c) {
     167 + return [a, b, c]
     168 + }
     169 +}
     170 +variadicClosure(1)(2, 3, 4) // [1, 2, [3, 4]]
     171 +```
     172 + 
     173 +只有最后一个参数可以是可变的。以下代码也是非法的:
     174 + 
     175 +```golang
     176 +// illegal, because a is variadic and is not the last parameter
     177 +illegal := func(a..., b) { /*... */ }
     178 +```
     179 + 
     180 +调用函数时,传递参数的数量必须与该函数定义相匹配。
     181 + 
     182 +```golang
     183 +f := func(a, b) {}
     184 +f(1, 2, 3) // Runtime Error: wrong number of arguments: want=2, got=3
     185 +```
     186 + 
     187 +像Go一样,您可以使用省略号“…”要传递数组类型值作为其最后一个参数:
     188 + 
     189 +```golang
     190 +f1 := func(a, b, c) { return a + b + c }
     191 +f1([1, 2, 3]...) // => 6
     192 +f1(1, [2, 3]...) // => 6
     193 +f1(1, 2, [3]...) // => 6
     194 +f1([1, 2]...) // Runtime Error: wrong number of arguments: want=3, got=2
     195 + 
     196 +f2 := func(a, ...b) {}
     197 +f2(1) // valid; a = 1, b = []
     198 +f2(1, 2) // valid; a = 1, b = [2]
     199 +f2(1, 2, 3) // valid; a = 1, b = [2, 3]
     200 +f2([1, 2, 3]...) // valid; a = 1, b = [2, 3]
     201 +```
     202 + 
     203 +## 变量和范围
     204 + 
     205 +可以使用赋值运算符“:=”和“=”将值赋值给变量。
     206 + 
     207 +- `:=`运算符在作用域中定义一个新变量并赋值。
     208 +- `=`运算符为作用域中的现有变量分配一个新值。
     209 + 
     210 +变量在全局范围(在函数外部定义)或本地范围(在功能内部定义)中定义。
     211 + 
     212 +```golang
     213 +a := "foo" // define 'a' in global scope
     214 + 
     215 +func() { // function scope A
     216 + b := 52 // define 'b' in function scope A
     217 + 
     218 + func() { // function scope B
     219 + c := 19.84 // define 'c' in function scope B
     220 + 
     221 + a = "bee" // ok: assign new value to 'a' from global scope
     222 + b = 20 // ok: assign new value to 'b' from function scope A
     223 + 
     224 + b := true // ok: define new 'b' in function scope B
     225 + // (shadowing 'b' from function scope A)
     226 + }
     227 + 
     228 + a = "bar" // ok: assigne new value to 'a' from global scope
     229 + b = 10 // ok: assigne new value to 'b'
     230 + a := -100 // ok: define new 'a' in function scope A
     231 + // (shadowing 'a' from global scope)
     232 + 
     233 + c = -9.1 // illegal: 'c' is not defined
     234 + b := [1, 2] // illegal: 'b' is already defined in the same scope
     235 +}
     236 + 
     237 +b = 25 // illegal: 'b' is not defined
     238 +a := {d: 2} // illegal: 'a' is already defined in the same scope
     239 +```
     240 + 
     241 +与Go不同,可以为变量指定不同类型的值。
     242 + 
     243 +```golang
     244 +a := 123 // assigned 'int'
     245 +a = "123" // re-assigned 'string'
     246 +a = [1, 2, 3] // re-assigned 'array'
     247 +```
     248 + 
     249 +## 类型转换
     250 + 
     251 +虽然VDSL中没有直接指定类型,但可以使用类型转换在值类型之间进行转换。
     252 + 
     253 +```golang
     254 +s1 := string(1984) // "1984"
     255 +i2 := int("-999") // -999
     256 +f3 := float(-51) // -51.0
     257 +b4 := bool(1) // true
     258 +c5 := char("X") // 'X'
     259 +```
     260 + 
     261 +## 操作符
     262 + 
     263 +### 单目运算符
     264 + 
     265 +| Operator | Usage | Types |
     266 +| :---: | :---: | :---: |
     267 +| `+` | same as `0 + x` | int, float |
     268 +| `-` | same as `0 - x` | int, float |
     269 +| `!` | logical NOT | all types* |
     270 +| `^` | bitwise complement | int |
     271 + 
     272 +在VDSL中,所有值都可以是真值也可以是假值
     273 + 
     274 +### Binary Operators
     275 + 
     276 +| Operator | Usage | Types |
     277 +| :---: | :---: | :---: |
     278 +| `==` | equal | all types |
     279 +| `!=` | not equal | all types |
     280 +| `&&` | logical AND | all types |
     281 +| `\|\|` | logical OR | all types |
     282 +| `+` | add/concat | int, float, string, char, time, array |
     283 +| `-` | subtract | int, float, char, time |
     284 +| `*` | multiply | int, float |
     285 +| `/` | divide | int, float |
     286 +| `&` | bitwise AND | int |
     287 +| `\|` | bitwise OR | int |
     288 +| `^` | bitwise XOR | int |
     289 +| `&^` | bitclear (AND NOT) | int |
     290 +| `<<` | shift left | int |
     291 +| `>>` | shift right | int |
     292 +| `<` | less than | int, float, char, time, string |
     293 +| `<=` | less than or equal to | int, float, char, time, string |
     294 +| `>` | greater than | int, float, char, time, string |
     295 +| `>=` | greater than or equal to | int, float, char, time, string |
     296 + 
     297 +### 三目操作符
     298 + 
     299 +VDSL有一个三元条件运算符`(条件表达式)?(true表达式):(false表达式)`。
     300 + 
     301 +```golang
     302 +a := true ? 1 : -1 // a == 1
     303 + 
     304 +min := func(a, b) {
     305 + return a < b ? a : b
     306 +}
     307 +b := min(5, 10) // b == 5
     308 +```
     309 + 
     310 +### 赋值和增量运算符
     311 + 
     312 +| Operator | Usage |
     313 +| :---: | :---: |
     314 +| `+=` | `(lhs) = (lhs) + (rhs)` |
     315 +| `-=` | `(lhs) = (lhs) - (rhs)` |
     316 +| `*=` | `(lhs) = (lhs) * (rhs)` |
     317 +| `/=` | `(lhs) = (lhs) / (rhs)` |
     318 +| `%=` | `(lhs) = (lhs) % (rhs)` |
     319 +| `&=` | `(lhs) = (lhs) & (rhs)` |
     320 +| `\|=` | `(lhs) = (lhs) \| (rhs)` |
     321 +| `&^=` | `(lhs) = (lhs) &^ (rhs)` |
     322 +| `^=` | `(lhs) = (lhs) ^ (rhs)` |
     323 +| `<<=` | `(lhs) = (lhs) << (rhs)` |
     324 +| `>>=` | `(lhs) = (lhs) >> (rhs)` |
     325 +| `++` | `(lhs) = (lhs) + 1` |
     326 +| `--` | `(lhs) = (lhs) - 1` |
     327 + 
     328 +### 操作符优先级
     329 + 
     330 +一元运算符具有最高优先级,三元运算符具有最低优先级。二进制运算符有五个优先级。
     331 + 
     332 +乘法运算符绑定最强,其次是加法运算符,比较运算符,“&&”(逻辑AND),最后是“||”(逻辑OR):
     333 + 
     334 +| 优先级 | 操作符 |
     335 +| :---: | :---: |
     336 +| 5 | `*` `/` `%` `<<` `>>` `&` `&^` |
     337 +| 4 | `+` `-` `\|` `^` |
     338 +| 3 | `==` `!=` `<` `<=` `>` `>=` |
     339 +| 2 | `&&` |
     340 +| 1 | `\|\|` |
     341 + 
     342 +与Go一样,“++”和“--”运算符形成语句,而不是表达式,它们位于运算符层次结构之外。
     343 + 
     344 +### 选择器和索引器
     345 + 
     346 +可以使用选择器(`.`)和索引器(`[]`)运算符来读取或写入复合类型(数组、映射、字符串、字节)的元素。
     347 + 
     348 +```golang
     349 +["one", "two", "three"][1] // == "two"
     350 + 
     351 +m := {
     352 + a: 1,
     353 + b: [2, 3, 4],
     354 + c: func() { return 10 }
     355 +}
     356 +m.a // == 1
     357 +m["b"][1] // == 3
     358 +m.c() // == 10
     359 +m.x = 5 // add 'x' to map 'm'
     360 +m["b"][5] // == nil
     361 +m["b"][5].d // == nil
     362 +m.b[5] = 0 // == nil
     363 +m.x.y.z // == nil
     364 +```
     365 + 
     366 +与Go一样,可以对数组、字符串、字节等序列值类型使用切片运算符“[:]”。
     367 + 
     368 +```golang
     369 +a := [1, 2, 3, 4, 5][1:3] // == [2, 3]
     370 +b := [1, 2, 3, 4, 5][3:] // == [4, 5]
     371 +c := [1, 2, 3, 4, 5][:3] // == [1, 2, 3]
     372 +d := "hello world"[2:10] // == "llo worl"
     373 +c := [1, 2, 3, 4, 5][-1:10] // == [1, 2, 3, 4, 5]
     374 +```
     375 + 
     376 +**注意:关键字不能用作选择器**
     377 + 
     378 +```golang
     379 +a := {in: true} // Parse Error: expected map key, found 'in'
     380 +a.func = "" // Parse Error: expected selector, found 'func'
     381 +```
     382 + 
     383 +使用双引号和索引器将关键字与映射一起使用。
     384 + 
     385 +```golang
     386 +a := {"in": true}
     387 +a["func"] = ""
     388 +```
     389 + 
     390 +## 语句
     391 + 
     392 +### If 语句
     393 + 
     394 +“If”语句与Go非常相似。
     395 + 
     396 +```golang
     397 +if a < 0 {
     398 + // execute if 'a' is negative
     399 +} else if a == 0 {
     400 + // execute if 'a' is zero
     401 +} else {
     402 + // execute if 'a' is positive
     403 +}
     404 +```
     405 + 
     406 +与Go一样,条件表达式前面可能有一个简单的语句,该语句在计算表达式之前执行。
     407 + 
     408 +```golang
     409 +if a := foo(); a < 0 {
     410 + // execute if 'a' is negative
     411 +}
     412 +```
     413 + 
     414 +### For 语句
     415 + 
     416 +“For”语句与Go非常相似。
     417 + 
     418 +```golang
     419 +// for (init); (condition); (post) {}
     420 +for a:=0; a<10; a++ {
     421 + // ...
     422 +}
     423 + 
     424 +// for (condition) {}
     425 +for a < 10 {
     426 + // ...
     427 +}
     428 + 
     429 +// for {}
     430 +for {
     431 + // ...
     432 +}
     433 +```
     434 + 
     435 +### For-In 语句
     436 + 
     437 +VDSL中新增了“For In”语句。它类似于Go的“for range”语句。
     438 + 
     439 +“For In”语句可以迭代任何可迭代的值类型(数组、映射、字节、字符串、nil)。
     440 + 
     441 +```golang
     442 +for v in [1, 2, 3] { // array: element
     443 + // 'v' is value
     444 +}
     445 +for i, v in [1, 2, 3] { // array: index and element
     446 + // 'i' is index
     447 + // 'v' is value
     448 +}
     449 +for k, v in {k1: 1, k2: 2} { // map: key and value
     450 + // 'k' is key
     451 + // 'v' is value
     452 +}
     453 +```
     454 + 
     455 +## 模块
     456 + 
     457 +模块是VDSL中的基本编译单元。一个模块可以使用“import”表达式导入另一个模块。
     458 + 
     459 +主模块:
     460 + 
     461 +```golang
     462 +sum := import("./sum") // load module from a local file
     463 +fmt.print(sum(10)) // module function
     464 +```
     465 + 
     466 +“sum.dsl”文件中的另一个模块:
     467 + 
     468 +```golang
     469 +base := 5
     470 + 
     471 +export func(x) {
     472 + return x + base
     473 +}
     474 +```
     475 + 
     476 +默认情况下,“import”将模块文件缺少的扩展名解决为"`.dsl`"[^note]。
     477 +因此,“sum:=import("./sum")”相当于“sum:=import("./sum.dsl")”。
     478 + 
     479 +[^note]:
     480 + 如果在Go中使用VDSL作为库,则可以自定义文件扩展名“`.dsl`”。在这种情况下,请使用“Compiler”类型的“SetImportFileExt”函数。
     481 +
     482 + 请参阅[转到参考](https://pkg.go.dev/dsl)详细信息。
     483 + 
     484 +在VDSL中,模块与函数非常相似。
     485 + 
     486 +- `import` 表达式加载模块代码并像函数一样执行它。
     487 +- 模块应使用“export”语句返回一个值。
     488 + - 模块可以返回“导出”任何类型的值:int、map、function等。
     489 + - 模块中的export类似于函数中的return:它停止执行并导入代码返回一个值。
     490 + - `export`的值总是常量。
     491 + - 如果模块没有任何“export”语句,则“import”表达式只返回“nil”_(就像没有“return”的函数一样。)_
     492 + - 请注意,如果代码作为主模块执行,则“export”语句将被完全忽略,并且不会进行求值。
     493 + 
     494 +此外,您还可以使用“import”表达式来加载标准库。
     495 + 
     496 +```golang
     497 +math := import("math")
     498 +a := math.abs(-19.84) // == 19.84
     499 +```
     500 + 
     501 +## Comments
     502 + 
     503 +与Go一样,VDSL支持行注释(`//…`)和块注释(`/* ... */`).
     504 + 
     505 +```golang
     506 +/*
     507 + multi-line block comments
     508 +*/
     509 + 
     510 +a := 5 // line comments
     511 +```
     512 + 
     513 +## 与Go的区别
     514 + 
     515 +与Go不同,VDSL没有以下功能:
     516 + 
     517 +- Declarations
     518 +- Imaginary values
     519 +- Structs
     520 +- Pointers
     521 +- Channels
     522 +- Goroutines
     523 +- Tuple assignment
     524 +- Variable parameters
     525 +- Switch statement
     526 +- Goto statement
     527 +- Defer statement
     528 +- Panic
     529 +- Type assertion
     530 + 
  • ■ ■ ■ ■ ■ ■
    library.md
     1 +# Library - "http"
     2 + 
     3 +```golang
     4 +resp := http.req("https://www.uusec.com", {method: "PUT"})
     5 +if is_error(resp) {
     6 + debug("err: %s",resp.value)
     7 + return
     8 +}
     9 +debug("%d %s %s",resp.status,resp.headers["Content-Type"],resp.body)
     10 +```
     11 +## Functions
     12 + 
     13 +- `req(url string,{method: string, headers: map, body: string, follow_redirects: bool, max_read_length: int, timeout: int }) => Http/error`: send http request and return Http or error,the second parameter is optional.
     14 + 
     15 +## Http
     16 + 
     17 +- `status => int`: http response status code.
     18 +- `headers => map`: http response headers.
     19 +- `body => string`: http response body.
     20 + 
     21 + 
     22 + 
     23 +# Library - "net"
     24 + 
     25 +```golang
     26 +sock := net.dial("www.uusec.com:80")
     27 +if is_error(sock) {
     28 + debug("err: %s",sock.value)
     29 + return
     30 +}
     31 +n := sock.write_all("GET / HTTP/1.0\r\nHost: www.uusec.com\r\n\r\n")
     32 +if is_error(n) {
     33 + debug("err: %s",n.value)
     34 + return
     35 +}
     36 +data := sock.read_all()
     37 +debug("data: %s",string(data))
     38 +```
     39 +## Functions
     40 + 
     41 +- `dial(addr string, {proto: string, tls: bool, idle_timeout: int, total_timeout: int}) => Net/error`: dial with tcp or udp protocol with or with no tls and return Net or error,the second parameter is optional.
     42 + 
     43 +## Net
     44 + 
     45 +- `close() => error`: close the socket.
     46 +- `read(out bytes) => int/error`: read once data from socket into parameter out and return read length,
     47 + rendering it unusable in the future.
     48 +- `write(data bytes) => int/error`: write once data to the socket and return written length.
     49 +- `set_read_deadline(seconds int) => error`: set read timeout for read function.
     50 +- `set_write_deadline(seconds int) => error`: set write timeout for write function.
     51 +- `read_all(maxlen int) => bytes/error`: read the max length data from socket if possible,the maxlen parameter is optional.
     52 +- `read_until(pattern string) => bytes/error`: read data from socket until the regex pattern is matched.
     53 + 
     54 +- `write_all(data bytes) => int/error`: write all data to the socket if possible and return written length.
     55 + 
Please wait...
Page is in error, reload to recover