116 lines
3.3 KiB
Markdown
Raw Normal View History

javascript protocol for scripting (includes 15+ proto libs) (#4109) * rebase js-layer PR from @ice3man543 * package restructuring * working * fix duplicated event & matcher status * fix lint error * fix response field * add new functions * multiple minor improvements * fix incorrect stats in js protocol * sort output metadata in cli * remove temp files * remove dead code * add unit and integration test * fix lint error * add jsdoclint using llm * fix error in test * add js lint using llm * generate docs of libs * llm lint * remove duplicated docs * update generated docs * update prompt in doclint * update docs * temp disable version check test * fix unit test and add retry * fix panic in it * update and move jsdocs * updated jsdocs * update docs * update container platform in test * dir restructure and adding docs * add api_reference and remove markdown docs * fix imports * add javascript design and contribution docs * add js protocol documentation * update integration test and docs * update doc ext mdx->md * minor update to docs * new integration test and more * move go libs and add docs * gen new net docs and more * final docs update * add new devtool * use fastdialer * fix build fail * use fastdialer + network sandbox support * add reserved keyword 'Port' * update Port to new syntax * misc update * always enable templatectx in js protocol * move docs to 'js-proto-docs' repo * remove scrapefuncs binary --------- Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
2023-09-16 16:02:17 +05:30
## jsdocgen
jsdocgen is LLM (OpenAI) based dev tool it takes generated javascript files and annotes them with jsdoc comments using predefined prompt
### Usage
```bash
./jsdocgen -h
Usage of ./jsdocgen:
-dir string
directory to process
-key string
openai api key
-keyfile string
openai api key file
```
### Example
```bash
./jsdocgen -dir modules/generated/js/libmysql -keyfile ~/.openai/key
```
### Example Conversion
when `bindgen` is executed it generates basic javascript (which currently is incorrect) and looks like this but the idea is to generate bare minimum that LLM has idea what we are trying to do
```javascript
/**@module rdp */
// rdp implements bindings for rdp protocol in javascript
// to be used from nuclei scanner.
// RDPClient is a client for rdp servers
class RDPClient {
// CheckRDPAuth checks if the given host and port are running rdp server
// with authentication and returns their metadata.
CheckRDPAuth(host, port) {
return CheckRDPAuthResponse, error;
};
// IsRDP checks if the given host and port are running rdp server.
//
// If connection is successful, it returns true.
// If connection is unsuccessful, it returns false and error.
//
// The Name of the OS is also returned if the connection is successful.
IsRDP(host, port) {
return IsRDPResponse, error;
};
};
module.exports = {
RDPClient: RDPClient,
};
```
And when `jsdocgen` is executed it generates the following output
```javascript
/**
* @module rdp
* This module implements bindings for rdp protocol in javascript to be used from nuclei scanner.
*/
/**
* @class
* @classdesc RDPClient is a client for rdp servers
*/
class RDPClient {
/**
* @method
* @name CheckRDPAuth
* @description checks if the given host and port are running rdp server with authentication and returns their metadata.
* @param {string} host - The host of the rdp server
* @param {number} port - The port of the rdp server
* @returns {CheckRDPAuthResponse} - The response from the rdp server
* @throws {error} If there is an error in the request
* @example
* let client = new RDPClient();
* client.CheckRDPAuth("localhost", 3389);
*/
CheckRDPAuth(host, port) {
// implemented in go
};
/**
* @method
* @name IsRDP
* @description checks if the given host and port are running rdp server.
* If connection is successful, it returns true.
* If connection is unsuccessful, it throws an error.
* The Name of the OS is also returned if the connection is successful.
* @param {string} host - The host of the rdp server
* @param {number} port - The port of the rdp server
* @returns {IsRDPResponse} - The response from the rdp server
* @throws {error} If there is an error in the request
* @example
* let client = new RDPClient();
* client.IsRDP("localhost", 3389);
*/
IsRDP(host, port) {
// implemented in go
};
};
module.exports = {
RDPClient: RDPClient,
};
```
Now we can see the output is much more readable and make sense.
## Note:
jsdocgen is not perfect and it is not supposed to be, it is intended to **almost** automate boooring stuff but will always require some manual intervention to make it perfect.