Merge pull request #3 from artemisbot/features/add-pgp-kbpgp
Update to master & add verify/sign
This commit is contained in:
commit
aa3f781e18
@ -35,7 +35,6 @@
|
|||||||
}],
|
}],
|
||||||
|
|
||||||
// disable rules from base configurations
|
// disable rules from base configurations
|
||||||
"no-console": "off",
|
|
||||||
"no-control-regex": "off",
|
"no-control-regex": "off",
|
||||||
|
|
||||||
// stylistic conventions
|
// stylistic conventions
|
||||||
@ -90,6 +89,7 @@
|
|||||||
"$": false,
|
"$": false,
|
||||||
"jQuery": false,
|
"jQuery": false,
|
||||||
"moment": false,
|
"moment": false,
|
||||||
|
"log": false,
|
||||||
|
|
||||||
"COMPILE_TIME": false,
|
"COMPILE_TIME": false,
|
||||||
"COMPILE_MSG": false,
|
"COMPILE_MSG": false,
|
||||||
|
13
.github/ISSUE_TEMPLATE.md
vendored
13
.github/ISSUE_TEMPLATE.md
vendored
@ -5,21 +5,10 @@
|
|||||||
<!-- Misc: -->
|
<!-- Misc: -->
|
||||||
|
|
||||||
### Summary
|
### Summary
|
||||||
<!-- If you're describing a bug, tell us what's wrong -->
|
|
||||||
<!-- If you're suggesting a change/improvement, tell us what it is and how it should work -->
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
<!-- If describing a bug, tell us what happens instead of the expected behavior -->
|
<!-- If describing a bug, tell us what happens instead of the expected behavior -->
|
||||||
<!-- Include a link that triggers the bug if possible -->
|
<!-- Include a link that triggers the bug if possible -->
|
||||||
<!-- If you are requesting a new operation, include example input and output -->
|
<!-- If you are requesting a new operation, include example input and output -->
|
||||||
|
|
||||||
### Possible solutions
|
|
||||||
<!-- Not obligatory, but suggest a fix/reason for the bug, or ideas for how to -->
|
|
||||||
<!-- implement the addition or change, including links to relevant resources -->
|
|
||||||
|
|
||||||
### Environment
|
|
||||||
<!-- Include any relevant details about the environment you experienced the bug in -->
|
|
||||||
<!-- This information is displayed in the About/Support pane -->
|
|
||||||
* CyberChef compile time:
|
|
||||||
* User-Agent:
|
|
||||||
* [Link to reproduce]()
|
|
||||||
|
@ -39,4 +39,10 @@ deploy:
|
|||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
branch: master
|
branch: master
|
||||||
|
notifications:
|
||||||
|
webhooks:
|
||||||
|
urls:
|
||||||
|
- https://webhooks.gitter.im/e/83c143a6822e218d5b34
|
||||||
|
on_success: change
|
||||||
|
on_failure: always
|
||||||
|
on_start: never
|
||||||
|
29
README.md
29
README.md
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
[![Build Status](https://travis-ci.org/gchq/CyberChef.svg?branch=master)](https://travis-ci.org/gchq/CyberChef)
|
[![Build Status](https://travis-ci.org/gchq/CyberChef.svg?branch=master)](https://travis-ci.org/gchq/CyberChef)
|
||||||
[![dependencies Status](https://david-dm.org/gchq/CyberChef/status.svg)](https://david-dm.org/gchq/CyberChef)
|
[![dependencies Status](https://david-dm.org/gchq/CyberChef/status.svg)](https://david-dm.org/gchq/CyberChef)
|
||||||
[![npm](http://img.shields.io/npm/v/cyberchef.svg)](https://www.npmjs.com/package/cyberchef)
|
[![npm](https://img.shields.io/npm/v/cyberchef.svg)](https://www.npmjs.com/package/cyberchef)
|
||||||
![](https://reposs.herokuapp.com/?path=gchq/CyberChef&color=blue)
|
![](https://reposs.herokuapp.com/?path=gchq/CyberChef&color=blue)
|
||||||
[![](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/gchq/CyberChef/blob/master/LICENSE)
|
[![](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/gchq/CyberChef/blob/master/LICENSE)
|
||||||
|
[![Gitter](https://badges.gitter.im/gchq/CyberChef.svg)](https://gitter.im/gchq/CyberChef?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||||
|
|
||||||
|
|
||||||
#### *The Cyber Swiss Army Knife*
|
#### *The Cyber Swiss Army Knife*
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ Cryptographic operations in CyberChef should not be relied upon to provide secur
|
|||||||
|
|
||||||
There are four main areas in CyberChef:
|
There are four main areas in CyberChef:
|
||||||
|
|
||||||
1. The **input** box in the top right, where you can paste, type or drag the data you want to operate on.
|
1. The **input** box in the top right, where you can paste, type or drag the text or file you want to operate on.
|
||||||
2. The **output** box in the bottom right, where the outcome of your processing will be displayed.
|
2. The **output** box in the bottom right, where the outcome of your processing will be displayed.
|
||||||
3. The **operations** list on the far left, where you can find all the operations that CyberChef is capable of in categorised lists, or by searching.
|
3. The **operations** list on the far left, where you can find all the operations that CyberChef is capable of in categorised lists, or by searching.
|
||||||
4. The **recipe** area in the middle, where you can drag the operations that you want to use and specify arguments and options.
|
4. The **recipe** area in the middle, where you can drag the operations that you want to use and specify arguments and options.
|
||||||
@ -40,32 +42,32 @@ You can use as many operations as you like in simple or complex ways. Some examp
|
|||||||
- [Display multiple timestamps as full dates][7]
|
- [Display multiple timestamps as full dates][7]
|
||||||
- [Carry out different operations on data of different types][8]
|
- [Carry out different operations on data of different types][8]
|
||||||
- [Use parts of the input as arguments to operations][9]
|
- [Use parts of the input as arguments to operations][9]
|
||||||
|
- [Perform AES decryption, extracting the IV from the beginning of the cipher stream][10]
|
||||||
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Drag and drop
|
- Drag and drop
|
||||||
- Operations can be dragged in and out of the recipe list, or reorganised.
|
- Operations can be dragged in and out of the recipe list, or reorganised.
|
||||||
- Files can be dragged over the input box to load them directly.
|
- Files can be dragged over the input box to load them directly into the browser.
|
||||||
- Auto Bake
|
- Auto Bake
|
||||||
- Whenever you modify the input or the recipe, CyberChef will automatically “bake” for you and produce the output immediately.
|
- Whenever you modify the input or the recipe, CyberChef will automatically "bake" for you and produce the output immediately.
|
||||||
- This can be turned off and operated manually if it is affecting performance (if the input is very large, for instance).
|
- This can be turned off and operated manually if it is affecting performance (if the input is very large, for instance).
|
||||||
- If any bake takes longer than 200 milliseconds, auto bake will be switched off automatically to prevent further performance issues.
|
|
||||||
- Breakpoints
|
- Breakpoints
|
||||||
- You can set breakpoints on any operation in your recipe to pause execution before running it.
|
- You can set breakpoints on any operation in your recipe to pause execution before running it.
|
||||||
- You can also step through the recipe one operation at a time to see what the data looks like at each stage.
|
- You can also step through the recipe one operation at a time to see what the data looks like at each stage.
|
||||||
- Save and load recipes
|
- Save and load recipes
|
||||||
- If you come up with an awesome recipe that you know you’ll want to use again, just click save and add it to your local storage. It'll be waiting for you next time you visit CyberChef.
|
- If you come up with an awesome recipe that you know you’ll want to use again, just click "Save recipe" and add it to your local storage. It'll be waiting for you next time you visit CyberChef.
|
||||||
- You can also copy a URL which includes your recipe and input which can be shared with others.
|
- You can also copy the URL, which includes your recipe and input, to easily share it with others.
|
||||||
- Search
|
- Search
|
||||||
- If you know the name of the operation you want or a word associated with it, start typing it into the search field and any matching operations will immediately be shown.
|
- If you know the name of the operation you want or a word associated with it, start typing it into the search field and any matching operations will immediately be shown.
|
||||||
- Highlighting
|
- Highlighting
|
||||||
- When you highlight text in the input or output, the offset and length values will be displayed and, if possible, the corresponding data will be highlighted in the output or input respectively (example: [highlight the word 'question' in the input to see where it appears in the output][10]).
|
- When you highlight text in the input or output, the offset and length values will be displayed and, if possible, the corresponding data will be highlighted in the output or input respectively (example: [highlight the word 'question' in the input to see where it appears in the output][11]).
|
||||||
- Save to file and load from file
|
- Save to file and load from file
|
||||||
- You can save the output to a file at any time or load a file by dragging and dropping it into the input field (note that files larger than about 500kb may cause your browser to hang or even crash due to the way that browsers handle large amounts of textual data).
|
- You can save the output to a file at any time or load a file by dragging and dropping it into the input field. Files up to around 500MB are supported (depending on your browser), however some operations may take a very long time to run over this much data.
|
||||||
- CyberChef is entirely client-side
|
- CyberChef is entirely client-side
|
||||||
- It should be noted that none of your input or recipe configuration is ever sent to the CyberChef web server - all processing is carried out within your browser, on your own computer.
|
- It should be noted that none of your recipe configuration or input (either text or files) is ever sent to the CyberChef web server - all processing is carried out within your browser, on your own computer.
|
||||||
- Due to this feature, CyberChef can be compiled into a single HTML file. You can download this file and drop it into a virtual machine, share it with other people, or use it independently on your desktop.
|
- Due to this feature, CyberChef can be compiled into a single HTML file. You can download this file and drop it into a virtual machine, share it with other people, or use it independently on your local machine.
|
||||||
|
|
||||||
|
|
||||||
## Browser support
|
## Browser support
|
||||||
@ -98,6 +100,7 @@ CyberChef is released under the [Apache 2.0 Licence](https://www.apache.org/lice
|
|||||||
[5]: https://gchq.github.io/CyberChef/#recipe=From_Hexdump()Gunzip()&input=MDAwMDAwMDAgIDFmIDhiIDA4IDAwIDEyIGJjIGYzIDU3IDAwIGZmIDBkIGM3IGMxIDA5IDAwIDIwICB8Li4uLi6881cu/y7HwS4uIHwKMDAwMDAwMTAgIDA4IDA1IGQwIDU1IGZlIDA0IDJkIGQzIDA0IDFmIGNhIDhjIDQ0IDIxIDViIGZmICB8Li7QVf4uLdMuLsouRCFb/3wKMDAwMDAwMjAgIDYwIGM3IGQ3IDAzIDE2IGJlIDQwIDFmIDc4IDRhIDNmIDA5IDg5IDBiIDlhIDdkICB8YMfXLi6%2BQC54Sj8uLi4ufXwKMDAwMDAwMzAgIDRlIGM4IDRlIDZkIDA1IDFlIDAxIDhiIDRjIDI0IDAwIDAwIDAwICAgICAgICAgICB8TshObS4uLi5MJC4uLnw
|
[5]: https://gchq.github.io/CyberChef/#recipe=From_Hexdump()Gunzip()&input=MDAwMDAwMDAgIDFmIDhiIDA4IDAwIDEyIGJjIGYzIDU3IDAwIGZmIDBkIGM3IGMxIDA5IDAwIDIwICB8Li4uLi6881cu/y7HwS4uIHwKMDAwMDAwMTAgIDA4IDA1IGQwIDU1IGZlIDA0IDJkIGQzIDA0IDFmIGNhIDhjIDQ0IDIxIDViIGZmICB8Li7QVf4uLdMuLsouRCFb/3wKMDAwMDAwMjAgIDYwIGM3IGQ3IDAzIDE2IGJlIDQwIDFmIDc4IDRhIDNmIDA5IDg5IDBiIDlhIDdkICB8YMfXLi6%2BQC54Sj8uLi4ufXwKMDAwMDAwMzAgIDRlIGM4IDRlIDZkIDA1IDFlIDAxIDhiIDRjIDI0IDAwIDAwIDAwICAgICAgICAgICB8TshObS4uLi5MJC4uLnw
|
||||||
[6]: https://gchq.github.io/CyberChef/#recipe=RC4(%7B'option':'UTF8','string':'secret'%7D,'Hex','Hex')Disassemble_x86('64','Full%20x86%20architecture',16,0,true,true)&input=MjFkZGQyNTQwMTYwZWU2NWZlMDc3NzEwM2YyYTM5ZmJlNWJjYjZhYTBhYWJkNDE0ZjkwYzZjYWY1MzEyNzU0YWY3NzRiNzZiM2JiY2QxOTNjYjNkZGZkYmM1YTI2NTMzYTY4NmI1OWI4ZmVkNGQzODBkNDc0NDIwMWFlYzIwNDA1MDcxMzhlMmZlMmIzOTUwNDQ2ZGIzMWQyYmM2MjliZTRkM2YyZWIwMDQzYzI5M2Q3YTVkMjk2MmMwMGZlNmRhMzAwNzJkOGM1YTZiNGZlN2Q4NTlhMDQwZWVhZjI5OTczMzYzMDJmNWEwZWMxOQ
|
[6]: https://gchq.github.io/CyberChef/#recipe=RC4(%7B'option':'UTF8','string':'secret'%7D,'Hex','Hex')Disassemble_x86('64','Full%20x86%20architecture',16,0,true,true)&input=MjFkZGQyNTQwMTYwZWU2NWZlMDc3NzEwM2YyYTM5ZmJlNWJjYjZhYTBhYWJkNDE0ZjkwYzZjYWY1MzEyNzU0YWY3NzRiNzZiM2JiY2QxOTNjYjNkZGZkYmM1YTI2NTMzYTY4NmI1OWI4ZmVkNGQzODBkNDc0NDIwMWFlYzIwNDA1MDcxMzhlMmZlMmIzOTUwNDQ2ZGIzMWQyYmM2MjliZTRkM2YyZWIwMDQzYzI5M2Q3YTVkMjk2MmMwMGZlNmRhMzAwNzJkOGM1YTZiNGZlN2Q4NTlhMDQwZWVhZjI5OTczMzYzMDJmNWEwZWMxOQ
|
||||||
[7]: https://gchq.github.io/CyberChef/#recipe=Fork('%5C%5Cn','%5C%5Cn',false)From_UNIX_Timestamp('Seconds%20(s)')&input=OTc4MzQ2ODAwCjEwMTI2NTEyMDAKMTA0NjY5NjQwMAoxMDgxMDg3MjAwCjExMTUzMDUyMDAKMTE0OTYwOTYwMA
|
[7]: https://gchq.github.io/CyberChef/#recipe=Fork('%5C%5Cn','%5C%5Cn',false)From_UNIX_Timestamp('Seconds%20(s)')&input=OTc4MzQ2ODAwCjEwMTI2NTEyMDAKMTA0NjY5NjQwMAoxMDgxMDg3MjAwCjExMTUzMDUyMDAKMTE0OTYwOTYwMA
|
||||||
[8]: https://gchq.github.io/CyberChef/#recipe=Fork('%5C%5Cn','%5C%5Cn',false)Conditional_Jump('1',2,10)To_Hex('Space')Return()To_Base64('A-Za-z0-9%2B/%3D')&input=U29tZSBkYXRhIHdpdGggYSAxIGluIGl0ClNvbWUgZGF0YSB3aXRoIGEgMiBpbiBpdA
|
[8]: https://gchq.github.io/CyberChef/#recipe=Fork('%5C%5Cn','%5C%5Cn',false)Conditional_Jump('1',false,'base64',10)To_Hex('Space')Return()Label('base64')To_Base64('A-Za-z0-9%2B/%3D')&input=U29tZSBkYXRhIHdpdGggYSAxIGluIGl0ClNvbWUgZGF0YSB3aXRoIGEgMiBpbiBpdA
|
||||||
[9]: https://gchq.github.io/CyberChef/#recipe=Register('key%3D(%5B%5C%5Cda-f%5D*)',true,false)Find_/_Replace(%7B'option':'Regex','string':'.*data%3D(.*)'%7D,'$1',true,false,true)RC4(%7B'option':'Hex','string':'$R0'%7D,'Hex','Latin1')&input=aHR0cDovL21hbHdhcmV6LmJpei9iZWFjb24ucGhwP2tleT0wZTkzMmE1YyZkYXRhPThkYjdkNWViZTM4NjYzYTU0ZWNiYjMzNGUzZGIxMQ
|
[9]: https://gchq.github.io/CyberChef/#recipe=Register('key%3D(%5B%5C%5Cda-f%5D*)',true,false)Find_/_Replace(%7B'option':'Regex','string':'.*data%3D(.*)'%7D,'$1',true,false,true)RC4(%7B'option':'Hex','string':'$R0'%7D,'Hex','Latin1')&input=aHR0cDovL21hbHdhcmV6LmJpei9iZWFjb24ucGhwP2tleT0wZTkzMmE1YyZkYXRhPThkYjdkNWViZTM4NjYzYTU0ZWNiYjMzNGUzZGIxMQ
|
||||||
[10]: https://gchq.github.io/CyberChef/#recipe=XOR(%7B'option':'Hex','string':'3a'%7D,'',false)To_Hexdump(16,false,false)&input=VGhlIGFuc3dlciB0byB0aGUgdWx0aW1hdGUgcXVlc3Rpb24gb2YgbGlmZSwgdGhlIFVuaXZlcnNlLCBhbmQgZXZlcnl0aGluZyBpcyA0Mi4
|
[10]: https://gchq.github.io/CyberChef/#recipe=Register('(.%7B32%7D)',true,false)Drop_bytes(0,32,false)AES_Decrypt(%7B'option':'Hex','string':'1748e7179bd56570d51fa4ba287cc3e5'%7D,%7B'option':'Hex','string':'$R0'%7D,'CTR','Hex','Raw',%7B'option':'Hex','string':''%7D)&input=NTFlMjAxZDQ2MzY5OGVmNWY3MTdmNzFmNWI0NzEyYWYyMGJlNjc0YjNiZmY1M2QzODU0NjM5NmVlNjFkYWFjNDkwOGUzMTljYTNmY2Y3MDg5YmZiNmIzOGVhOTllNzgxZDI2ZTU3N2JhOWRkNmYzMTFhMzk0MjBiODk3OGU5MzAxNGIwNDJkNDQ3MjZjYWVkZjU0MzZlYWY2NTI0MjljMGRmOTRiNTIxNjc2YzdjMmNlODEyMDk3YzI3NzI3M2M3YzcyY2Q4OWFlYzhkOWZiNGEyNzU4NmNjZjZhYTBhZWUyMjRjMzRiYTNiZmRmN2FlYjFkZGQ0Nzc2MjJiOTFlNzJjOWU3MDlhYjYwZjhkYWY3MzFlYzBjYzg1Y2UwZjc0NmZmMTU1NGE1YTNlYzI5MWNhNDBmOWU2MjlhODcyNTkyZDk4OGZkZDgzNDUzNGFiYTc5YzFhZDE2NzY3NjlhN2MwMTBiZjA0NzM5ZWNkYjY1ZDk1MzAyMzcxZDYyOWQ5ZTM3ZTdiNGEzNjFkYTQ2OGYxZWQ1MzU4OTIyZDJlYTc1MmRkMTFjMzY2ZjMwMTdiMTRhYTAxMWQyYWYwM2M0NGY5NTU3OTA5OGExNWUzY2Y5YjQ0ODZmOGZmZTljMjM5ZjM0ZGU3MTUxZjZjYTY1MDBmZTRiODUwYzNmMWMwMmU4MDFjYWYzYTI0NDY0NjE0ZTQyODAxNjE1YjhmZmFhMDdhYzgyNTE0OTNmZmRhN2RlNWRkZjMzNjg4ODBjMmI5NWIwMzBmNDFmOGYxNTA2NmFkZDA3MWE2NmNmNjBlNWY0NmYzYTIzMGQzOTdiNjUyOTYzYTIxYTUzZg
|
||||||
|
[11]: https://gchq.github.io/CyberChef/#recipe=XOR(%7B'option':'Hex','string':'3a'%7D,'',false)To_Hexdump(16,false,false)&input=VGhlIGFuc3dlciB0byB0aGUgdWx0aW1hdGUgcXVlc3Rpb24gb2YgbGlmZSwgdGhlIFVuaXZlcnNlLCBhbmQgZXZlcnl0aGluZyBpcyA0Mi4
|
||||||
|
782
package-lock.json
generated
782
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
44
package.json
44
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cyberchef",
|
"name": "cyberchef",
|
||||||
"version": "6.4.0",
|
"version": "7.4.0",
|
||||||
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
|
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
|
||||||
"author": "n1474335 <n1474335@gmail.com>",
|
"author": "n1474335 <n1474335@gmail.com>",
|
||||||
"homepage": "https://gchq.github.io/CyberChef",
|
"homepage": "https://gchq.github.io/CyberChef",
|
||||||
@ -32,15 +32,15 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.26.0",
|
"babel-core": "^6.26.0",
|
||||||
"babel-loader": "^7.1.2",
|
"babel-loader": "^7.1.2",
|
||||||
|
"babel-preset-env": "^1.6.0",
|
||||||
"babel-plugin-transform-runtime": "^6.23.0",
|
"babel-plugin-transform-runtime": "^6.23.0",
|
||||||
"babel-polyfill": "^6.26.0",
|
"babel-polyfill": "^6.26.0",
|
||||||
"babel-preset-env": "^1.6.0",
|
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"babel-preset-es2015": "^6.24.1",
|
||||||
"babel-preset-stage-0": "^6.24.1",
|
"babel-preset-stage-0": "^6.24.1",
|
||||||
"css-loader": "^0.28.7",
|
"css-loader": "^0.28.7",
|
||||||
"exports-loader": "^0.6.4",
|
"exports-loader": "^0.6.4",
|
||||||
"extract-text-webpack-plugin": "^3.0.1",
|
"extract-text-webpack-plugin": "^3.0.2",
|
||||||
"file-loader": "^1.1.4",
|
"file-loader": "^1.1.6",
|
||||||
"grunt": ">=1.0.1",
|
"grunt": ">=1.0.1",
|
||||||
"grunt-accessibility": "~5.0.0",
|
"grunt-accessibility": "~5.0.0",
|
||||||
"grunt-chmod": "~1.1.1",
|
"grunt-chmod": "~1.1.1",
|
||||||
@ -54,23 +54,25 @@
|
|||||||
"grunt-webpack": "^3.0.2",
|
"grunt-webpack": "^3.0.2",
|
||||||
"html-webpack-plugin": "^2.30.1",
|
"html-webpack-plugin": "^2.30.1",
|
||||||
"imports-loader": "^0.7.1",
|
"imports-loader": "^0.7.1",
|
||||||
"ink-docstrap": "^1.3.0",
|
"ink-docstrap": "^1.3.2",
|
||||||
"jsdoc-babel": "^0.3.0",
|
"jsdoc-babel": "^0.3.0",
|
||||||
"less": "^2.7.2",
|
"less": "^2.7.3",
|
||||||
"less-loader": "^4.0.5",
|
"less-loader": "^4.0.5",
|
||||||
"postcss-css-variables": "^0.8.0",
|
"postcss-css-variables": "^0.8.0",
|
||||||
"postcss-import": "^11.0.0",
|
"postcss-import": "^11.0.0",
|
||||||
"postcss-loader": "^2.0.6",
|
"postcss-loader": "^2.0.9",
|
||||||
"style-loader": "^0.19.0",
|
"style-loader": "^0.19.1",
|
||||||
"url-loader": "^0.6.2",
|
"url-loader": "^0.6.2",
|
||||||
"val-loader": "^1.0.2",
|
"val-loader": "^1.1.0",
|
||||||
"web-resource-inliner": "^4.2.0",
|
"web-resource-inliner": "^4.2.0",
|
||||||
"webpack": "^3.6.0",
|
"webpack": "^3.10.0",
|
||||||
"webpack-dev-server": "^2.9.1",
|
"webpack-dev-server": "^2.9.7",
|
||||||
"webpack-node-externals": "^1.6.0",
|
"webpack-node-externals": "^1.6.0",
|
||||||
"worker-loader": "^1.0.0"
|
"worker-loader": "^1.1.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"babel-polyfill": "^6.26.0",
|
||||||
|
"bignumber.js": "^5.0.0",
|
||||||
"bootstrap": "^3.3.7",
|
"bootstrap": "^3.3.7",
|
||||||
"bootstrap-colorpicker": "^2.5.2",
|
"bootstrap-colorpicker": "^2.5.2",
|
||||||
"bootstrap-switch": "^3.3.4",
|
"bootstrap-switch": "^3.3.4",
|
||||||
@ -82,25 +84,31 @@
|
|||||||
"esmangle": "^1.0.1",
|
"esmangle": "^1.0.1",
|
||||||
"esprima": "^4.0.0",
|
"esprima": "^4.0.0",
|
||||||
"exif-parser": "^0.1.12",
|
"exif-parser": "^0.1.12",
|
||||||
|
"file-saver": "^1.3.3",
|
||||||
"google-code-prettify": "^1.0.5",
|
"google-code-prettify": "^1.0.5",
|
||||||
"jquery": "^3.2.1",
|
"jquery": "^3.2.1",
|
||||||
"js-crc": "^0.2.0",
|
"js-crc": "^0.2.0",
|
||||||
"js-sha3": "^0.6.1",
|
"js-sha3": "^0.7.0",
|
||||||
"jsbn": "^1.1.0",
|
"jsbn": "^1.1.0",
|
||||||
"jsonpath": "^0.2.12",
|
"jsonpath": "^1.0.0",
|
||||||
"jsrsasign": "8.0.4",
|
"jsrsasign": "8.0.4",
|
||||||
"kbpgp": "^2.0.76",
|
"kbpgp": "^2.0.76",
|
||||||
"lodash": "^4.17.4",
|
"lodash": "^4.17.4",
|
||||||
"moment": "^2.18.1",
|
"loglevel": "^1.6.0",
|
||||||
"moment-timezone": "^0.5.13",
|
"loglevel-message-prefix": "^3.0.0",
|
||||||
|
"moment": "^2.20.1",
|
||||||
|
"moment-timezone": "^0.5.14",
|
||||||
|
"node-forge": "^0.7.1",
|
||||||
"node-md6": "^0.1.0",
|
"node-md6": "^0.1.0",
|
||||||
|
"nwmatcher": "^1.4.3",
|
||||||
"otp": "^0.1.3",
|
"otp": "^0.1.3",
|
||||||
"sladex-blowfish": "^0.8.1",
|
"sladex-blowfish": "^0.8.1",
|
||||||
"sortablejs": "^1.6.1",
|
"sortablejs": "^1.7.0",
|
||||||
"split.js": "^1.3.5",
|
"split.js": "^1.3.5",
|
||||||
|
"utf8": "^3.0.0",
|
||||||
"vkbeautify": "^0.99.3",
|
"vkbeautify": "^0.99.3",
|
||||||
"xmldom": "^0.1.27",
|
"xmldom": "^0.1.27",
|
||||||
"xpath": "0.0.24",
|
"xpath": "0.0.27",
|
||||||
"zlibjs": "^0.3.1"
|
"zlibjs": "^0.3.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -19,7 +19,7 @@ const Chef = function() {
|
|||||||
/**
|
/**
|
||||||
* Runs the recipe over the input.
|
* Runs the recipe over the input.
|
||||||
*
|
*
|
||||||
* @param {string} inputText - The input data as a string
|
* @param {string|ArrayBuffer} input - The input data as a string or ArrayBuffer
|
||||||
* @param {Object[]} recipeConfig - The recipe configuration object
|
* @param {Object[]} recipeConfig - The recipe configuration object
|
||||||
* @param {Object} options - The options object storing various user choices
|
* @param {Object} options - The options object storing various user choices
|
||||||
* @param {boolean} options.attempHighlight - Whether or not to attempt highlighting
|
* @param {boolean} options.attempHighlight - Whether or not to attempt highlighting
|
||||||
@ -33,11 +33,13 @@ const Chef = function() {
|
|||||||
* @returns {number} response.duration - The number of ms it took to execute the recipe
|
* @returns {number} response.duration - The number of ms it took to execute the recipe
|
||||||
* @returns {number} response.error - The error object thrown by a failed operation (false if no error)
|
* @returns {number} response.error - The error object thrown by a failed operation (false if no error)
|
||||||
*/
|
*/
|
||||||
Chef.prototype.bake = async function(inputText, recipeConfig, options, progress, step) {
|
Chef.prototype.bake = async function(input, recipeConfig, options, progress, step) {
|
||||||
let startTime = new Date().getTime(),
|
log.debug("Chef baking");
|
||||||
|
const startTime = new Date().getTime(),
|
||||||
recipe = new Recipe(recipeConfig),
|
recipe = new Recipe(recipeConfig),
|
||||||
containsFc = recipe.containsFlowControl(),
|
containsFc = recipe.containsFlowControl(),
|
||||||
error = false;
|
notUTF8 = options && options.hasOwnProperty("treatAsUtf8") && !options.treatAsUtf8;
|
||||||
|
let error = false;
|
||||||
|
|
||||||
if (containsFc && ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
|
if (containsFc && ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
|
||||||
|
|
||||||
@ -62,22 +64,30 @@ Chef.prototype.bake = async function(inputText, recipeConfig, options, progress,
|
|||||||
|
|
||||||
// If starting from scratch, load data
|
// If starting from scratch, load data
|
||||||
if (progress === 0) {
|
if (progress === 0) {
|
||||||
this.dish.set(inputText, Dish.STRING);
|
const type = input instanceof ArrayBuffer ? Dish.ARRAY_BUFFER : Dish.STRING;
|
||||||
|
this.dish.set(input, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
progress = await recipe.execute(this.dish, progress);
|
progress = await recipe.execute(this.dish, progress);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Return the error in the result so that everything else gets correctly updated
|
log.error(err);
|
||||||
// rather than throwing it here and losing state info.
|
error = {
|
||||||
error = err;
|
displayStr: err.displayStr,
|
||||||
|
};
|
||||||
progress = err.progress;
|
progress = err.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Depending on the size of the output, we may send it back as a string or an ArrayBuffer.
|
||||||
|
// This can prevent unnecessary casting as an ArrayBuffer can be easily downloaded as a file.
|
||||||
|
// The threshold is specified in KiB.
|
||||||
|
const threshold = (options.ioDisplayThreshold || 1024) * 1024;
|
||||||
|
const returnType = this.dish.size() > threshold ? Dish.ARRAY_BUFFER : Dish.STRING;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result: this.dish.type === Dish.HTML ?
|
result: this.dish.type === Dish.HTML ?
|
||||||
this.dish.get(Dish.HTML) :
|
this.dish.get(Dish.HTML, notUTF8) :
|
||||||
this.dish.get(Dish.STRING),
|
this.dish.get(returnType, notUTF8),
|
||||||
type: Dish.enumLookup(this.dish.type),
|
type: Dish.enumLookup(this.dish.type),
|
||||||
progress: progress,
|
progress: progress,
|
||||||
duration: new Date().getTime() - startTime,
|
duration: new Date().getTime() - startTime,
|
||||||
@ -104,6 +114,8 @@ Chef.prototype.bake = async function(inputText, recipeConfig, options, progress,
|
|||||||
* @returns {number} The time it took to run the silent bake in milliseconds.
|
* @returns {number} The time it took to run the silent bake in milliseconds.
|
||||||
*/
|
*/
|
||||||
Chef.prototype.silentBake = function(recipeConfig) {
|
Chef.prototype.silentBake = function(recipeConfig) {
|
||||||
|
log.debug("Running silent bake");
|
||||||
|
|
||||||
let startTime = new Date().getTime(),
|
let startTime = new Date().getTime(),
|
||||||
recipe = new Recipe(recipeConfig),
|
recipe = new Recipe(recipeConfig),
|
||||||
dish = new Dish("", Dish.STRING);
|
dish = new Dish("", Dish.STRING);
|
||||||
|
@ -11,6 +11,15 @@ import Chef from "./Chef.js";
|
|||||||
import OperationConfig from "./config/MetaConfig.js";
|
import OperationConfig from "./config/MetaConfig.js";
|
||||||
import OpModules from "./config/modules/Default.js";
|
import OpModules from "./config/modules/Default.js";
|
||||||
|
|
||||||
|
// Add ">" to the start of all log messages in the Chef Worker
|
||||||
|
import loglevelMessagePrefix from "loglevel-message-prefix";
|
||||||
|
|
||||||
|
loglevelMessagePrefix(log, {
|
||||||
|
prefixes: [],
|
||||||
|
staticPrefixes: [">"],
|
||||||
|
prefixFormat: "%p"
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Set up Chef instance
|
// Set up Chef instance
|
||||||
self.chef = new Chef();
|
self.chef = new Chef();
|
||||||
@ -42,6 +51,8 @@ self.postMessage({
|
|||||||
self.addEventListener("message", function(e) {
|
self.addEventListener("message", function(e) {
|
||||||
// Handle message
|
// Handle message
|
||||||
const r = e.data;
|
const r = e.data;
|
||||||
|
log.debug("ChefWorker receiving command '" + r.action + "'");
|
||||||
|
|
||||||
switch (r.action) {
|
switch (r.action) {
|
||||||
case "bake":
|
case "bake":
|
||||||
bake(r.data);
|
bake(r.data);
|
||||||
@ -61,6 +72,9 @@ self.addEventListener("message", function(e) {
|
|||||||
r.data.pos
|
r.data.pos
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case "setLogLevel":
|
||||||
|
log.setLevel(r.data, false);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -86,7 +100,7 @@ async function bake(data) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
self.postMessage({
|
self.postMessage({
|
||||||
action: "bakeSuccess",
|
action: "bakeComplete",
|
||||||
data: response
|
data: response
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -121,7 +135,7 @@ function loadRequiredModules(recipeConfig) {
|
|||||||
let module = self.OperationConfig[op.op].module;
|
let module = self.OperationConfig[op.op].module;
|
||||||
|
|
||||||
if (!OpModules.hasOwnProperty(module)) {
|
if (!OpModules.hasOwnProperty(module)) {
|
||||||
console.log("Loading module " + module);
|
log.info("Loading module " + module);
|
||||||
self.sendStatusMessage("Loading module " + module);
|
self.sendStatusMessage("Loading module " + module);
|
||||||
self.importScripts(self.docURL + "/" + module + ".js");
|
self.importScripts(self.docURL + "/" + module + ".js");
|
||||||
}
|
}
|
||||||
|
126
src/core/Dish.js
126
src/core/Dish.js
@ -1,18 +1,20 @@
|
|||||||
import Utils from "./Utils.js";
|
import Utils from "./Utils.js";
|
||||||
|
import BigNumber from "bignumber.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data being operated on by each operation.
|
* The data being operated on by each operation.
|
||||||
*
|
*
|
||||||
* @author n1474335 [n1474335@gmail.com]
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
|
* @author Matt C [matt@artemisbot.uk]
|
||||||
* @copyright Crown Copyright 2016
|
* @copyright Crown Copyright 2016
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
*
|
||||||
* @class
|
* @class
|
||||||
* @param {byteArray|string|number} value - The value of the input data.
|
* @param {byteArray|string|number|ArrayBuffer|BigNumber} value - The value of the input data.
|
||||||
* @param {number} type - The data type of value, see Dish enums.
|
* @param {number} type - The data type of value, see Dish enums.
|
||||||
*/
|
*/
|
||||||
const Dish = function(value, type) {
|
const Dish = function(value, type) {
|
||||||
this.value = value || typeof value == "string" ? value : null;
|
this.value = value || typeof value === "string" ? value : null;
|
||||||
this.type = type || Dish.BYTE_ARRAY;
|
this.type = type || Dish.BYTE_ARRAY;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,6 +43,18 @@ Dish.NUMBER = 2;
|
|||||||
* @enum
|
* @enum
|
||||||
*/
|
*/
|
||||||
Dish.HTML = 3;
|
Dish.HTML = 3;
|
||||||
|
/**
|
||||||
|
* Dish data type enum for ArrayBuffers.
|
||||||
|
* @readonly
|
||||||
|
* @enum
|
||||||
|
*/
|
||||||
|
Dish.ARRAY_BUFFER = 4;
|
||||||
|
/**
|
||||||
|
* Dish data type enum for BigNumbers.
|
||||||
|
* @readonly
|
||||||
|
* @enum
|
||||||
|
*/
|
||||||
|
Dish.BIG_NUMBER = 5;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,19 +65,22 @@ Dish.HTML = 3;
|
|||||||
* @returns {number} The data type enum value.
|
* @returns {number} The data type enum value.
|
||||||
*/
|
*/
|
||||||
Dish.typeEnum = function(typeStr) {
|
Dish.typeEnum = function(typeStr) {
|
||||||
switch (typeStr) {
|
switch (typeStr.toLowerCase()) {
|
||||||
case "byteArray":
|
case "bytearray":
|
||||||
case "Byte array":
|
case "byte array":
|
||||||
return Dish.BYTE_ARRAY;
|
return Dish.BYTE_ARRAY;
|
||||||
case "string":
|
case "string":
|
||||||
case "String":
|
|
||||||
return Dish.STRING;
|
return Dish.STRING;
|
||||||
case "number":
|
case "number":
|
||||||
case "Number":
|
|
||||||
return Dish.NUMBER;
|
return Dish.NUMBER;
|
||||||
case "html":
|
case "html":
|
||||||
case "HTML":
|
|
||||||
return Dish.HTML;
|
return Dish.HTML;
|
||||||
|
case "arraybuffer":
|
||||||
|
case "array buffer":
|
||||||
|
return Dish.ARRAY_BUFFER;
|
||||||
|
case "bignumber":
|
||||||
|
case "big number":
|
||||||
|
return Dish.BIG_NUMBER;
|
||||||
default:
|
default:
|
||||||
throw "Invalid data type string. No matching enum.";
|
throw "Invalid data type string. No matching enum.";
|
||||||
}
|
}
|
||||||
@ -74,8 +91,8 @@ Dish.typeEnum = function(typeStr) {
|
|||||||
* Returns the data type string for the given type enum.
|
* Returns the data type string for the given type enum.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @param {string} typeEnum - The enum value of the data type.
|
* @param {number} typeEnum - The enum value of the data type.
|
||||||
* @returns {number} The data type as a string.
|
* @returns {string} The data type as a string.
|
||||||
*/
|
*/
|
||||||
Dish.enumLookup = function(typeEnum) {
|
Dish.enumLookup = function(typeEnum) {
|
||||||
switch (typeEnum) {
|
switch (typeEnum) {
|
||||||
@ -87,6 +104,10 @@ Dish.enumLookup = function(typeEnum) {
|
|||||||
return "number";
|
return "number";
|
||||||
case Dish.HTML:
|
case Dish.HTML:
|
||||||
return "html";
|
return "html";
|
||||||
|
case Dish.ARRAY_BUFFER:
|
||||||
|
return "ArrayBuffer";
|
||||||
|
case Dish.BIG_NUMBER:
|
||||||
|
return "BigNumber";
|
||||||
default:
|
default:
|
||||||
throw "Invalid data type enum. No matching type.";
|
throw "Invalid data type enum. No matching type.";
|
||||||
}
|
}
|
||||||
@ -96,10 +117,11 @@ Dish.enumLookup = function(typeEnum) {
|
|||||||
/**
|
/**
|
||||||
* Sets the data value and type and then validates them.
|
* Sets the data value and type and then validates them.
|
||||||
*
|
*
|
||||||
* @param {byteArray|string|number} value - The value of the input data.
|
* @param {byteArray|string|number|ArrayBuffer|BigNumber} value - The value of the input data.
|
||||||
* @param {number} type - The data type of value, see Dish enums.
|
* @param {number} type - The data type of value, see Dish enums.
|
||||||
*/
|
*/
|
||||||
Dish.prototype.set = function(value, type) {
|
Dish.prototype.set = function(value, type) {
|
||||||
|
log.debug("Dish type: " + Dish.enumLookup(type));
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
@ -114,11 +136,12 @@ Dish.prototype.set = function(value, type) {
|
|||||||
* Returns the value of the data in the type format specified.
|
* Returns the value of the data in the type format specified.
|
||||||
*
|
*
|
||||||
* @param {number} type - The data type of value, see Dish enums.
|
* @param {number} type - The data type of value, see Dish enums.
|
||||||
* @returns {byteArray|string|number} The value of the output data.
|
* @param {boolean} [notUTF8] - Do not treat strings as UTF8.
|
||||||
|
* @returns {byteArray|string|number|ArrayBuffer|BigNumber} The value of the output data.
|
||||||
*/
|
*/
|
||||||
Dish.prototype.get = function(type) {
|
Dish.prototype.get = function(type, notUTF8) {
|
||||||
if (this.type !== type) {
|
if (this.type !== type) {
|
||||||
this.translate(type);
|
this.translate(type, notUTF8);
|
||||||
}
|
}
|
||||||
return this.value;
|
return this.value;
|
||||||
};
|
};
|
||||||
@ -128,37 +151,59 @@ Dish.prototype.get = function(type) {
|
|||||||
* Translates the data to the given type format.
|
* Translates the data to the given type format.
|
||||||
*
|
*
|
||||||
* @param {number} toType - The data type of value, see Dish enums.
|
* @param {number} toType - The data type of value, see Dish enums.
|
||||||
|
* @param {boolean} [notUTF8] - Do not treat strings as UTF8.
|
||||||
*/
|
*/
|
||||||
Dish.prototype.translate = function(toType) {
|
Dish.prototype.translate = function(toType, notUTF8) {
|
||||||
|
log.debug(`Translating Dish from ${Dish.enumLookup(this.type)} to ${Dish.enumLookup(toType)}`);
|
||||||
|
const byteArrayToStr = notUTF8 ? Utils.byteArrayToChars : Utils.byteArrayToUtf8;
|
||||||
|
|
||||||
// Convert data to intermediate byteArray type
|
// Convert data to intermediate byteArray type
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case Dish.STRING:
|
case Dish.STRING:
|
||||||
this.value = this.value ? Utils.strToByteArray(this.value) : [];
|
this.value = this.value ? Utils.strToByteArray(this.value) : [];
|
||||||
this.type = Dish.BYTE_ARRAY;
|
|
||||||
break;
|
break;
|
||||||
case Dish.NUMBER:
|
case Dish.NUMBER:
|
||||||
this.value = typeof this.value == "number" ? Utils.strToByteArray(this.value.toString()) : [];
|
this.value = typeof this.value == "number" ? Utils.strToByteArray(this.value.toString()) : [];
|
||||||
this.type = Dish.BYTE_ARRAY;
|
|
||||||
break;
|
break;
|
||||||
case Dish.HTML:
|
case Dish.HTML:
|
||||||
this.value = this.value ? Utils.strToByteArray(Utils.unescapeHtml(Utils.stripHtmlTags(this.value, true))) : [];
|
this.value = this.value ? Utils.strToByteArray(Utils.unescapeHtml(Utils.stripHtmlTags(this.value, true))) : [];
|
||||||
this.type = Dish.BYTE_ARRAY;
|
break;
|
||||||
|
case Dish.ARRAY_BUFFER:
|
||||||
|
// Array.from() would be nicer here, but it's slightly slower
|
||||||
|
this.value = Array.prototype.slice.call(new Uint8Array(this.value));
|
||||||
|
break;
|
||||||
|
case Dish.BIG_NUMBER:
|
||||||
|
this.value = this.value instanceof BigNumber ? Utils.strToByteArray(this.value.toString()) : [];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.type = Dish.BYTE_ARRAY;
|
||||||
|
|
||||||
// Convert from byteArray to toType
|
// Convert from byteArray to toType
|
||||||
switch (toType) {
|
switch (toType) {
|
||||||
case Dish.STRING:
|
case Dish.STRING:
|
||||||
case Dish.HTML:
|
case Dish.HTML:
|
||||||
this.value = this.value ? Utils.byteArrayToUtf8(this.value) : "";
|
this.value = this.value ? byteArrayToStr(this.value) : "";
|
||||||
this.type = Dish.STRING;
|
this.type = Dish.STRING;
|
||||||
break;
|
break;
|
||||||
case Dish.NUMBER:
|
case Dish.NUMBER:
|
||||||
this.value = this.value ? parseFloat(Utils.byteArrayToUtf8(this.value)) : 0;
|
this.value = this.value ? parseFloat(byteArrayToStr(this.value)) : 0;
|
||||||
this.type = Dish.NUMBER;
|
this.type = Dish.NUMBER;
|
||||||
break;
|
break;
|
||||||
|
case Dish.ARRAY_BUFFER:
|
||||||
|
this.value = new Uint8Array(this.value).buffer;
|
||||||
|
this.type = Dish.ARRAY_BUFFER;
|
||||||
|
break;
|
||||||
|
case Dish.BIG_NUMBER:
|
||||||
|
try {
|
||||||
|
this.value = new BigNumber(byteArrayToStr(this.value));
|
||||||
|
} catch (err) {
|
||||||
|
this.value = new BigNumber(NaN);
|
||||||
|
}
|
||||||
|
this.type = Dish.BIG_NUMBER;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -180,7 +225,7 @@ Dish.prototype.valid = function() {
|
|||||||
|
|
||||||
// Check that every value is a number between 0 - 255
|
// Check that every value is a number between 0 - 255
|
||||||
for (let i = 0; i < this.value.length; i++) {
|
for (let i = 0; i < this.value.length; i++) {
|
||||||
if (typeof this.value[i] != "number" ||
|
if (typeof this.value[i] !== "number" ||
|
||||||
this.value[i] < 0 ||
|
this.value[i] < 0 ||
|
||||||
this.value[i] > 255) {
|
this.value[i] > 255) {
|
||||||
return false;
|
return false;
|
||||||
@ -189,18 +234,41 @@ Dish.prototype.valid = function() {
|
|||||||
return true;
|
return true;
|
||||||
case Dish.STRING:
|
case Dish.STRING:
|
||||||
case Dish.HTML:
|
case Dish.HTML:
|
||||||
if (typeof this.value == "string") {
|
return typeof this.value === "string";
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
case Dish.NUMBER:
|
case Dish.NUMBER:
|
||||||
if (typeof this.value == "number") {
|
return typeof this.value === "number";
|
||||||
return true;
|
case Dish.ARRAY_BUFFER:
|
||||||
}
|
return this.value instanceof ArrayBuffer;
|
||||||
return false;
|
case Dish.BIG_NUMBER:
|
||||||
|
return this.value instanceof BigNumber;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines how much space the Dish takes up.
|
||||||
|
* Numbers in JavaScript are 64-bit floating point, however for the purposes of the Dish,
|
||||||
|
* we measure how many bytes are taken up when the number is written as a string.
|
||||||
|
*
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
Dish.prototype.size = function() {
|
||||||
|
switch (this.type) {
|
||||||
|
case Dish.BYTE_ARRAY:
|
||||||
|
case Dish.STRING:
|
||||||
|
case Dish.HTML:
|
||||||
|
return this.value.length;
|
||||||
|
case Dish.NUMBER:
|
||||||
|
case Dish.BIG_NUMBER:
|
||||||
|
return this.value.toString().length;
|
||||||
|
case Dish.ARRAY_BUFFER:
|
||||||
|
return this.value.byteLength;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export default Dish;
|
export default Dish;
|
||||||
|
@ -56,6 +56,7 @@ const FlowControl = {
|
|||||||
|
|
||||||
// Run recipe over each tranche
|
// Run recipe over each tranche
|
||||||
for (i = 0; i < inputs.length; i++) {
|
for (i = 0; i < inputs.length; i++) {
|
||||||
|
log.debug(`Entering tranche ${i + 1} of ${inputs.length}`);
|
||||||
const dish = new Dish(inputs[i], inputType);
|
const dish = new Dish(inputs[i], inputType);
|
||||||
try {
|
try {
|
||||||
progress = await recipe.execute(dish, 0);
|
progress = await recipe.execute(dish, 0);
|
||||||
@ -169,20 +170,19 @@ const FlowControl = {
|
|||||||
* @returns {Object} The updated state of the recipe.
|
* @returns {Object} The updated state of the recipe.
|
||||||
*/
|
*/
|
||||||
runJump: function(state) {
|
runJump: function(state) {
|
||||||
let ings = state.opList[state.progress].getIngValues(),
|
const ings = state.opList[state.progress].getIngValues(),
|
||||||
jumpNum = ings[0],
|
label = ings[0],
|
||||||
maxJumps = ings[1];
|
maxJumps = ings[1],
|
||||||
|
jmpIndex = FlowControl._getLabelIndex(label, state);
|
||||||
|
|
||||||
if (jumpNum < 0) {
|
if (state.numJumps >= maxJumps || jmpIndex === -1) {
|
||||||
jumpNum--;
|
log.debug("Maximum jumps reached or label cannot be found");
|
||||||
}
|
|
||||||
|
|
||||||
if (state.numJumps >= maxJumps) {
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.progress += jumpNum;
|
state.progress = jmpIndex;
|
||||||
state.numJumps++;
|
state.numJumps++;
|
||||||
|
log.debug(`Jumping to label '${label}' at position ${jmpIndex} (jumps = ${state.numJumps})`);
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -198,23 +198,26 @@ const FlowControl = {
|
|||||||
* @returns {Object} The updated state of the recipe.
|
* @returns {Object} The updated state of the recipe.
|
||||||
*/
|
*/
|
||||||
runCondJump: function(state) {
|
runCondJump: function(state) {
|
||||||
let ings = state.opList[state.progress].getIngValues(),
|
const ings = state.opList[state.progress].getIngValues(),
|
||||||
dish = state.dish,
|
dish = state.dish,
|
||||||
regexStr = ings[0],
|
regexStr = ings[0],
|
||||||
jumpNum = ings[1],
|
invert = ings[1],
|
||||||
maxJumps = ings[2];
|
label = ings[2],
|
||||||
|
maxJumps = ings[3],
|
||||||
|
jmpIndex = FlowControl._getLabelIndex(label, state);
|
||||||
|
|
||||||
if (jumpNum < 0) {
|
if (state.numJumps >= maxJumps || jmpIndex === -1) {
|
||||||
jumpNum--;
|
log.debug("Maximum jumps reached or label cannot be found");
|
||||||
}
|
|
||||||
|
|
||||||
if (state.numJumps >= maxJumps) {
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regexStr !== "" && dish.get(Dish.STRING).search(regexStr) > -1) {
|
if (regexStr !== "") {
|
||||||
state.progress += jumpNum;
|
let strMatch = dish.get(Dish.STRING).search(regexStr) > -1;
|
||||||
|
if (!invert && strMatch || invert && !strMatch) {
|
||||||
|
state.progress = jmpIndex;
|
||||||
state.numJumps++;
|
state.numJumps++;
|
||||||
|
log.debug(`Jumping to label '${label}' at position ${jmpIndex} (jumps = ${state.numJumps})`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
@ -249,6 +252,27 @@ const FlowControl = {
|
|||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the index of a label.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} state
|
||||||
|
* @param {string} name
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
_getLabelIndex: function(name, state) {
|
||||||
|
for (let o = 0; o < state.opList.length; o++) {
|
||||||
|
let operation = state.opList[o];
|
||||||
|
if (operation.name === "Label"){
|
||||||
|
let ings = operation.getIngValues();
|
||||||
|
if (name === ings[0]) {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FlowControl;
|
export default FlowControl;
|
||||||
|
@ -146,18 +146,23 @@ Recipe.prototype.lastOpIndex = function(startIndex) {
|
|||||||
Recipe.prototype.execute = async function(dish, startFrom) {
|
Recipe.prototype.execute = async function(dish, startFrom) {
|
||||||
startFrom = startFrom || 0;
|
startFrom = startFrom || 0;
|
||||||
let op, input, output, numJumps = 0, numRegisters = 0;
|
let op, input, output, numJumps = 0, numRegisters = 0;
|
||||||
|
log.debug(`[*] Executing recipe of ${this.opList.length} operations, starting at ${startFrom}`);
|
||||||
|
|
||||||
for (let i = startFrom; i < this.opList.length; i++) {
|
for (let i = startFrom; i < this.opList.length; i++) {
|
||||||
op = this.opList[i];
|
op = this.opList[i];
|
||||||
|
log.debug(`[${i}] ${op.name} ${JSON.stringify(op.getIngValues())}`);
|
||||||
if (op.isDisabled()) {
|
if (op.isDisabled()) {
|
||||||
|
log.debug("Operation is disabled, skipping");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (op.isBreakpoint()) {
|
if (op.isBreakpoint()) {
|
||||||
|
log.debug("Pausing at breakpoint");
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
input = dish.get(op.inputType);
|
input = dish.get(op.inputType);
|
||||||
|
log.debug("Executing operation");
|
||||||
|
|
||||||
if (op.isFlowControl()) {
|
if (op.isFlowControl()) {
|
||||||
// Package up the current state
|
// Package up the current state
|
||||||
@ -193,6 +198,7 @@ Recipe.prototype.execute = async function(dish, startFrom) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("Recipe complete");
|
||||||
return this.opList.length;
|
return this.opList.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import CryptoJS from "crypto-js";
|
import utf8 from "utf8";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,58 +64,6 @@ const Utils = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds leading zeros to strings
|
|
||||||
*
|
|
||||||
* @param {string} str - String to add leading characters to.
|
|
||||||
* @param {number} max - Maximum width of the string.
|
|
||||||
* @param {char} [chr='0'] - The character to pad with.
|
|
||||||
* @returns {string}
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* // returns "0a"
|
|
||||||
* Utils.padLeft("a", 2);
|
|
||||||
*
|
|
||||||
* // returns "000a"
|
|
||||||
* Utils.padLeft("a", 4);
|
|
||||||
*
|
|
||||||
* // returns "xxxa"
|
|
||||||
* Utils.padLeft("a", 4, "x");
|
|
||||||
*
|
|
||||||
* // returns "bcabchello"
|
|
||||||
* Utils.padLeft("hello", 10, "abc");
|
|
||||||
*/
|
|
||||||
padLeft: function(str, max, chr) {
|
|
||||||
chr = chr || "0";
|
|
||||||
let startIndex = chr.length - (max - str.length);
|
|
||||||
startIndex = startIndex < 0 ? 0 : startIndex;
|
|
||||||
return str.length < max ?
|
|
||||||
Utils.padLeft(chr.slice(startIndex, chr.length) + str, max, chr) : str;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds trailing spaces to strings.
|
|
||||||
*
|
|
||||||
* @param {string} str - String to add trailing characters to.
|
|
||||||
* @param {number} max - Maximum width of the string.
|
|
||||||
* @param {char} [chr='0'] - The character to pad with.
|
|
||||||
* @returns {string}
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* // returns "a "
|
|
||||||
* Utils.padRight("a", 4);
|
|
||||||
*
|
|
||||||
* // returns "axxx"
|
|
||||||
* Utils.padRight("a", 4, "x");
|
|
||||||
*/
|
|
||||||
padRight: function(str, max, chr) {
|
|
||||||
chr = chr || " ";
|
|
||||||
return str.length < max ?
|
|
||||||
Utils.padRight(str + chr.slice(0, max-str.length), max, chr) : str;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds trailing bytes to a byteArray.
|
* Adds trailing bytes to a byteArray.
|
||||||
*
|
*
|
||||||
@ -152,14 +100,6 @@ const Utils = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @alias Utils.padLeft
|
|
||||||
*/
|
|
||||||
pad: function(str, max, chr) {
|
|
||||||
return Utils.padLeft(str, max, chr);
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncates a long string to max length and adds suffix.
|
* Truncates a long string to max length and adds suffix.
|
||||||
*
|
*
|
||||||
@ -201,7 +141,7 @@ const Utils = {
|
|||||||
hex: function(c, length) {
|
hex: function(c, length) {
|
||||||
c = typeof c == "string" ? Utils.ord(c) : c;
|
c = typeof c == "string" ? Utils.ord(c) : c;
|
||||||
length = length || 2;
|
length = length || 2;
|
||||||
return Utils.pad(c.toString(16), length);
|
return c.toString(16).padStart(length, "0");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -222,7 +162,7 @@ const Utils = {
|
|||||||
bin: function(c, length) {
|
bin: function(c, length) {
|
||||||
c = typeof c == "string" ? Utils.ord(c) : c;
|
c = typeof c == "string" ? Utils.ord(c) : c;
|
||||||
length = length || 8;
|
length = length || 8;
|
||||||
return Utils.pad(c.toString(2), length);
|
return c.toString(2).padStart(length, "0");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -261,7 +201,7 @@ const Utils = {
|
|||||||
* Utils.parseEscapedChars("\\n");
|
* Utils.parseEscapedChars("\\n");
|
||||||
*/
|
*/
|
||||||
parseEscapedChars: function(str) {
|
parseEscapedChars: function(str) {
|
||||||
return str.replace(/(\\)?\\([nrtbf]|x[\da-f]{2})/g, function(m, a, b) {
|
return str.replace(/(\\)?\\([nrtbf]|x[\da-fA-F]{2})/g, function(m, a, b) {
|
||||||
if (a === "\\") return "\\"+b;
|
if (a === "\\") return "\\"+b;
|
||||||
switch (b[0]) {
|
switch (b[0]) {
|
||||||
case "n":
|
case "n":
|
||||||
@ -340,6 +280,72 @@ const Utils = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coverts data of varying types to a byteArray.
|
||||||
|
* Accepts hex, Base64, UTF8 and Latin1 strings.
|
||||||
|
*
|
||||||
|
* @param {string} str
|
||||||
|
* @param {string} type - One of "Hex", "Base64", "UTF8" or "Latin1"
|
||||||
|
* @returns {byteArray}
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||||
|
* Utils.convertToByteArray("Привет", "utf8");
|
||||||
|
*
|
||||||
|
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||||
|
* Utils.convertToByteArray("d097d0b4d180d0b0d0b2d181d182d0b2d183d0b9d182d0b5", "hex");
|
||||||
|
*
|
||||||
|
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||||
|
* Utils.convertToByteArray("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64");
|
||||||
|
*/
|
||||||
|
convertToByteArray: function(str, type) {
|
||||||
|
switch (type.toLowerCase()) {
|
||||||
|
case "hex":
|
||||||
|
return Utils.fromHex(str);
|
||||||
|
case "base64":
|
||||||
|
return Utils.fromBase64(str, null, "byteArray");
|
||||||
|
case "utf8":
|
||||||
|
return Utils.strToUtf8ByteArray(str);
|
||||||
|
case "latin1":
|
||||||
|
default:
|
||||||
|
return Utils.strToByteArray(str);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coverts data of varying types to a byte string.
|
||||||
|
* Accepts hex, Base64, UTF8 and Latin1 strings.
|
||||||
|
*
|
||||||
|
* @param {string} str
|
||||||
|
* @param {string} type - One of "Hex", "Base64", "UTF8" or "Latin1"
|
||||||
|
* @returns {string}
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||||
|
* Utils.convertToByteArray("Привет", "utf8");
|
||||||
|
*
|
||||||
|
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||||
|
* Utils.convertToByteArray("d097d0b4d180d0b0d0b2d181d182d0b2d183d0b9d182d0b5", "hex");
|
||||||
|
*
|
||||||
|
* // returns [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
|
||||||
|
* Utils.convertToByteArray("0JfQtNGA0LDQstGB0YLQstGD0LnRgtC1", "base64");
|
||||||
|
*/
|
||||||
|
convertToByteString: function(str, type) {
|
||||||
|
switch (type.toLowerCase()) {
|
||||||
|
case "hex":
|
||||||
|
return Utils.byteArrayToChars(Utils.fromHex(str));
|
||||||
|
case "base64":
|
||||||
|
return Utils.byteArrayToChars(Utils.fromBase64(str, null, "byteArray"));
|
||||||
|
case "utf8":
|
||||||
|
return utf8.encode(str);
|
||||||
|
case "latin1":
|
||||||
|
default:
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a string to a byte array.
|
* Converts a string to a byte array.
|
||||||
* Treats the string as UTF-8 if any values are over 255.
|
* Treats the string as UTF-8 if any values are over 255.
|
||||||
@ -381,17 +387,17 @@ const Utils = {
|
|||||||
* Utils.strToUtf8ByteArray("你好");
|
* Utils.strToUtf8ByteArray("你好");
|
||||||
*/
|
*/
|
||||||
strToUtf8ByteArray: function(str) {
|
strToUtf8ByteArray: function(str) {
|
||||||
let wordArray = CryptoJS.enc.Utf8.parse(str),
|
const utf8Str = utf8.encode(str);
|
||||||
byteArray = Utils.wordArrayToByteArray(wordArray);
|
|
||||||
|
|
||||||
if (str.length !== wordArray.sigBytes) {
|
if (str.length !== utf8Str.length) {
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (ENVIRONMENT_IS_WORKER()) {
|
||||||
self.setOption("attemptHighlight", false);
|
self.setOption("attemptHighlight", false);
|
||||||
} else if (ENVIRONMENT_IS_WEB()) {
|
} else if (ENVIRONMENT_IS_WEB()) {
|
||||||
window.app.options.attemptHighlight = false;
|
window.app.options.attemptHighlight = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return byteArray;
|
|
||||||
|
return Utils.strToByteArray(utf8Str);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -443,26 +449,21 @@ const Utils = {
|
|||||||
* Utils.byteArrayToUtf8([228,189,160,229,165,189]);
|
* Utils.byteArrayToUtf8([228,189,160,229,165,189]);
|
||||||
*/
|
*/
|
||||||
byteArrayToUtf8: function(byteArray) {
|
byteArrayToUtf8: function(byteArray) {
|
||||||
|
const str = Utils.byteArrayToChars(byteArray);
|
||||||
try {
|
try {
|
||||||
// Try to output data as UTF-8 string
|
const utf8Str = utf8.decode(str);
|
||||||
const words = [];
|
|
||||||
for (let i = 0; i < byteArray.length; i++) {
|
|
||||||
words[i >>> 2] |= byteArray[i] << (24 - (i % 4) * 8);
|
|
||||||
}
|
|
||||||
let wordArray = new CryptoJS.lib.WordArray.init(words, byteArray.length),
|
|
||||||
str = CryptoJS.enc.Utf8.stringify(wordArray);
|
|
||||||
|
|
||||||
if (str.length !== wordArray.sigBytes) {
|
if (str.length !== utf8Str.length) {
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (ENVIRONMENT_IS_WORKER()) {
|
||||||
self.setOption("attemptHighlight", false);
|
self.setOption("attemptHighlight", false);
|
||||||
} else if (ENVIRONMENT_IS_WEB()) {
|
} else if (ENVIRONMENT_IS_WEB()) {
|
||||||
window.app.options.attemptHighlight = false;
|
window.app.options.attemptHighlight = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return utf8Str;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// If it fails, treat it as ANSI
|
// If it fails, treat it as ANSI
|
||||||
return Utils.byteArrayToChars(byteArray);
|
return str;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -470,7 +471,7 @@ const Utils = {
|
|||||||
/**
|
/**
|
||||||
* Converts a charcode array to a string.
|
* Converts a charcode array to a string.
|
||||||
*
|
*
|
||||||
* @param {byteArray} byteArray
|
* @param {byteArray|Uint8Array} byteArray
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@ -491,33 +492,25 @@ const Utils = {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a CryptoJS.lib.WordArray to a byteArray.
|
* Converts an ArrayBuffer to a string.
|
||||||
*
|
*
|
||||||
* @param {CryptoJS.lib.WordArray} wordArray
|
* @param {ArrayBuffer} arrayBuffer
|
||||||
* @returns {byteArray}
|
* @returns {string}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // returns [84, 101, 115, 116]
|
* // returns "hello"
|
||||||
* Utils.wordArrayToByteArray(CryptoJS.enc.Hex.parse("54657374"));
|
* Utils.arrayBufferToStr(Uint8Array.from([104,101,108,108,111]).buffer);
|
||||||
*/
|
*/
|
||||||
wordArrayToByteArray: function(wordArray) {
|
arrayBufferToStr: function(arrayBuffer) {
|
||||||
if (wordArray.sigBytes <= 0) return [];
|
const byteArray = Array.prototype.slice.call(new Uint8Array(arrayBuffer));
|
||||||
|
return Utils.byteArrayToUtf8(byteArray);
|
||||||
let words = wordArray.words,
|
|
||||||
byteArray = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < wordArray.sigBytes; i++) {
|
|
||||||
byteArray.push((words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
return byteArray;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base64's the input byte array using the given alphabet, returning a string.
|
* Base64's the input byte array using the given alphabet, returning a string.
|
||||||
*
|
*
|
||||||
* @param {byteArray|string} data
|
* @param {byteArray|Uint8Array|string} data
|
||||||
* @param {string} [alphabet]
|
* @param {string} [alphabet]
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*
|
*
|
||||||
@ -636,7 +629,7 @@ const Utils = {
|
|||||||
/**
|
/**
|
||||||
* Convert a byte array into a hex string.
|
* Convert a byte array into a hex string.
|
||||||
*
|
*
|
||||||
* @param {byteArray} data
|
* @param {Uint8Array|byteArray} data
|
||||||
* @param {string} [delim=" "]
|
* @param {string} [delim=" "]
|
||||||
* @param {number} [padding=2]
|
* @param {number} [padding=2]
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@ -656,7 +649,7 @@ const Utils = {
|
|||||||
let output = "";
|
let output = "";
|
||||||
|
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
output += Utils.pad(data[i].toString(16), padding) + delim;
|
output += data[i].toString(16).padStart(padding, "0") + delim;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add \x or 0x to beginning
|
// Add \x or 0x to beginning
|
||||||
@ -1248,21 +1241,6 @@ const Utils = {
|
|||||||
"None": /\s+/g // Included here to remove whitespace when there shouldn't be any
|
"None": /\s+/g // Included here to remove whitespace when there shouldn't be any
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A mapping of string formats to their classes in the CryptoJS library.
|
|
||||||
* @constant
|
|
||||||
*/
|
|
||||||
format: {
|
|
||||||
"Hex": CryptoJS.enc.Hex,
|
|
||||||
"Base64": CryptoJS.enc.Base64,
|
|
||||||
"UTF8": CryptoJS.enc.Utf8,
|
|
||||||
"UTF16": CryptoJS.enc.Utf16,
|
|
||||||
"UTF16LE": CryptoJS.enc.Utf16LE,
|
|
||||||
"UTF16BE": CryptoJS.enc.Utf16BE,
|
|
||||||
"Latin1": CryptoJS.enc.Latin1,
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Utils;
|
export default Utils;
|
||||||
@ -1376,29 +1354,43 @@ String.prototype.count = function(chr) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
/*
|
||||||
// Library overrides ///////////////////////////////////////////////////////////////////////////////
|
* Polyfills
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override for the CryptoJS Hex encoding parser to remove whitespace before attempting to parse
|
|
||||||
* the hex string.
|
|
||||||
*
|
|
||||||
* @param {string} hexStr
|
|
||||||
* @returns {CryptoJS.lib.WordArray}
|
|
||||||
*/
|
*/
|
||||||
CryptoJS.enc.Hex.parse = function (hexStr) {
|
|
||||||
// Remove whitespace
|
|
||||||
hexStr = hexStr.replace(/\s/g, "");
|
|
||||||
|
|
||||||
// Shortcut
|
// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
|
||||||
const hexStrLength = hexStr.length;
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
|
||||||
|
if (!String.prototype.padStart) {
|
||||||
// Convert
|
String.prototype.padStart = function padStart(targetLength, padString) {
|
||||||
const words = [];
|
targetLength = targetLength>>0; //floor if number or convert non-number to 0;
|
||||||
for (let i = 0; i < hexStrLength; i += 2) {
|
padString = String((typeof padString !== "undefined" ? padString : " "));
|
||||||
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
|
if (this.length > targetLength) {
|
||||||
|
return String(this);
|
||||||
|
} else {
|
||||||
|
targetLength = targetLength-this.length;
|
||||||
|
if (targetLength > padString.length) {
|
||||||
|
padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
|
||||||
}
|
}
|
||||||
|
return padString.slice(0, targetLength) + String(this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return new CryptoJS.lib.WordArray.init(words, hexStrLength / 2);
|
|
||||||
};
|
// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
|
||||||
|
if (!String.prototype.padEnd) {
|
||||||
|
String.prototype.padEnd = function padEnd(targetLength, padString) {
|
||||||
|
targetLength = targetLength>>0; //floor if number or convert non-number to 0;
|
||||||
|
padString = String((typeof padString !== "undefined" ? padString : " "));
|
||||||
|
if (this.length > targetLength) {
|
||||||
|
return String(this);
|
||||||
|
} else {
|
||||||
|
targetLength = targetLength-this.length;
|
||||||
|
if (targetLength > padString.length) {
|
||||||
|
padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
|
||||||
|
}
|
||||||
|
return String(this) + padString.slice(0, targetLength);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -79,8 +79,8 @@ const Categories = [
|
|||||||
"DES Decrypt",
|
"DES Decrypt",
|
||||||
"Triple DES Encrypt",
|
"Triple DES Encrypt",
|
||||||
"Triple DES Decrypt",
|
"Triple DES Decrypt",
|
||||||
"Rabbit Encrypt",
|
"RC2 Encrypt",
|
||||||
"Rabbit Decrypt",
|
"RC2 Decrypt",
|
||||||
"RC4",
|
"RC4",
|
||||||
"RC4 Drop",
|
"RC4 Drop",
|
||||||
"ROT13",
|
"ROT13",
|
||||||
@ -99,6 +99,7 @@ const Categories = [
|
|||||||
"Substitute",
|
"Substitute",
|
||||||
"Derive PBKDF2 key",
|
"Derive PBKDF2 key",
|
||||||
"Derive EVP key",
|
"Derive EVP key",
|
||||||
|
"Pseudo-Random Number Generator",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -113,7 +114,7 @@ const Categories = [
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Logical operations",
|
name: "Arithmetic / Logic",
|
||||||
ops: [
|
ops: [
|
||||||
"XOR",
|
"XOR",
|
||||||
"XOR Brute Force",
|
"XOR Brute Force",
|
||||||
@ -122,6 +123,13 @@ const Categories = [
|
|||||||
"AND",
|
"AND",
|
||||||
"ADD",
|
"ADD",
|
||||||
"SUB",
|
"SUB",
|
||||||
|
"Sum",
|
||||||
|
"Subtract",
|
||||||
|
"Multiply",
|
||||||
|
"Divide",
|
||||||
|
"Mean",
|
||||||
|
"Median",
|
||||||
|
"Standard Deviation",
|
||||||
"Bit shift left",
|
"Bit shift left",
|
||||||
"Bit shift right",
|
"Bit shift right",
|
||||||
"Rotate left",
|
"Rotate left",
|
||||||
@ -191,6 +199,7 @@ const Categories = [
|
|||||||
"Parse colour code",
|
"Parse colour code",
|
||||||
"Escape string",
|
"Escape string",
|
||||||
"Unescape string",
|
"Unescape string",
|
||||||
|
"Pseudo-Random Number Generator",
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -288,6 +297,7 @@ const Categories = [
|
|||||||
"XPath expression",
|
"XPath expression",
|
||||||
"JPath expression",
|
"JPath expression",
|
||||||
"CSS selector",
|
"CSS selector",
|
||||||
|
"PHP Deserialize",
|
||||||
"Microsoft Script Decoder",
|
"Microsoft Script Decoder",
|
||||||
"Strip HTML tags",
|
"Strip HTML tags",
|
||||||
"Diff",
|
"Diff",
|
||||||
@ -301,9 +311,11 @@ const Categories = [
|
|||||||
ops: [
|
ops: [
|
||||||
"Entropy",
|
"Entropy",
|
||||||
"Frequency distribution",
|
"Frequency distribution",
|
||||||
|
"Chi Square",
|
||||||
"Detect File Type",
|
"Detect File Type",
|
||||||
"Scan for Embedded Files",
|
"Scan for Embedded Files",
|
||||||
"Disassemble x86",
|
"Disassemble x86",
|
||||||
|
"Pseudo-Random Number Generator",
|
||||||
"Generate UUID",
|
"Generate UUID",
|
||||||
"Generate TOTP",
|
"Generate TOTP",
|
||||||
"Generate HOTP",
|
"Generate HOTP",
|
||||||
@ -319,6 +331,7 @@ const Categories = [
|
|||||||
"Fork",
|
"Fork",
|
||||||
"Merge",
|
"Merge",
|
||||||
"Register",
|
"Register",
|
||||||
|
"Label",
|
||||||
"Jump",
|
"Jump",
|
||||||
"Conditional Jump",
|
"Conditional Jump",
|
||||||
"Return",
|
"Return",
|
||||||
|
1077
src/core/config/OperationConfig.js
Executable file → Normal file
1077
src/core/config/OperationConfig.js
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,6 @@ import CharEnc from "../../operations/CharEnc.js";
|
|||||||
*
|
*
|
||||||
* Libraries:
|
* Libraries:
|
||||||
* - cptable
|
* - cptable
|
||||||
* - CryptoJS
|
|
||||||
*
|
*
|
||||||
* @author n1474335 [n1474335@gmail.com]
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
|
@ -7,6 +7,7 @@ import Cipher from "../../operations/Cipher.js";
|
|||||||
* Libraries:
|
* Libraries:
|
||||||
* - CryptoJS
|
* - CryptoJS
|
||||||
* - Blowfish
|
* - Blowfish
|
||||||
|
* - Forge
|
||||||
*
|
*
|
||||||
* @author n1474335 [n1474335@gmail.com]
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
@ -23,12 +24,12 @@ OpModules.Ciphers = {
|
|||||||
"DES Decrypt": Cipher.runDesDec,
|
"DES Decrypt": Cipher.runDesDec,
|
||||||
"Triple DES Encrypt": Cipher.runTripleDesEnc,
|
"Triple DES Encrypt": Cipher.runTripleDesEnc,
|
||||||
"Triple DES Decrypt": Cipher.runTripleDesDec,
|
"Triple DES Decrypt": Cipher.runTripleDesDec,
|
||||||
"Rabbit Encrypt": Cipher.runRabbitEnc,
|
|
||||||
"Rabbit Decrypt": Cipher.runRabbitDec,
|
|
||||||
"Derive PBKDF2 key": Cipher.runPbkdf2,
|
"Derive PBKDF2 key": Cipher.runPbkdf2,
|
||||||
"Derive EVP key": Cipher.runEvpkdf,
|
"Derive EVP key": Cipher.runEvpkdf,
|
||||||
"RC4": Cipher.runRc4,
|
"RC4": Cipher.runRc4,
|
||||||
"RC4 Drop": Cipher.runRc4drop,
|
"RC4 Drop": Cipher.runRc4drop,
|
||||||
|
"RC2 Encrypt": Cipher.runRc2Enc,
|
||||||
|
"RC2 Decrypt": Cipher.runRc2Dec,
|
||||||
"Vigenère Encode": Cipher.runVigenereEnc,
|
"Vigenère Encode": Cipher.runVigenereEnc,
|
||||||
"Vigenère Decode": Cipher.runVigenereDec,
|
"Vigenère Decode": Cipher.runVigenereDec,
|
||||||
"Bifid Cipher Encode": Cipher.runBifidEnc,
|
"Bifid Cipher Encode": Cipher.runBifidEnc,
|
||||||
@ -37,6 +38,7 @@ OpModules.Ciphers = {
|
|||||||
"Affine Cipher Decode": Cipher.runAffineDec,
|
"Affine Cipher Decode": Cipher.runAffineDec,
|
||||||
"Atbash Cipher": Cipher.runAtbash,
|
"Atbash Cipher": Cipher.runAtbash,
|
||||||
"Substitute": Cipher.runSubstitute,
|
"Substitute": Cipher.runSubstitute,
|
||||||
|
"Pseudo-Random Number Generator": Cipher.runPRNG,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default OpModules;
|
export default OpModules;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import FlowControl from "../../FlowControl.js";
|
import FlowControl from "../../FlowControl.js";
|
||||||
|
import Arithmetic from "../../operations/Arithmetic.js";
|
||||||
import Base from "../../operations/Base.js";
|
import Base from "../../operations/Base.js";
|
||||||
import Base58 from "../../operations/Base58.js";
|
import Base58 from "../../operations/Base58.js";
|
||||||
import Base64 from "../../operations/Base64.js";
|
import Base64 from "../../operations/Base64.js";
|
||||||
@ -20,16 +21,15 @@ import NetBIOS from "../../operations/NetBIOS.js";
|
|||||||
import Numberwang from "../../operations/Numberwang.js";
|
import Numberwang from "../../operations/Numberwang.js";
|
||||||
import OS from "../../operations/OS.js";
|
import OS from "../../operations/OS.js";
|
||||||
import OTP from "../../operations/OTP.js";
|
import OTP from "../../operations/OTP.js";
|
||||||
|
import PHP from "../../operations/PHP.js";
|
||||||
import QuotedPrintable from "../../operations/QuotedPrintable.js";
|
import QuotedPrintable from "../../operations/QuotedPrintable.js";
|
||||||
import Rotate from "../../operations/Rotate.js";
|
import Rotate from "../../operations/Rotate.js";
|
||||||
import SeqUtils from "../../operations/SeqUtils.js";
|
import SeqUtils from "../../operations/SeqUtils.js";
|
||||||
import StrUtils from "../../operations/StrUtils.js";
|
import StrUtils from "../../operations/StrUtils.js";
|
||||||
import Tidy from "../../operations/Tidy.js";
|
import Tidy from "../../operations/Tidy.js";
|
||||||
import Unicode from "../../operations/Unicode.js";
|
import Unicode from "../../operations/Unicode.js";
|
||||||
import URL_ from "../../operations/URL.js";
|
|
||||||
import UUID from "../../operations/UUID.js";
|
import UUID from "../../operations/UUID.js";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default module.
|
* Default module.
|
||||||
*
|
*
|
||||||
@ -38,8 +38,8 @@ import UUID from "../../operations/UUID.js";
|
|||||||
*
|
*
|
||||||
* Libraries:
|
* Libraries:
|
||||||
* - Utils.js
|
* - Utils.js
|
||||||
* - CryptoJS
|
|
||||||
* - otp
|
* - otp
|
||||||
|
* - crypto
|
||||||
*
|
*
|
||||||
* @author n1474335 [n1474335@gmail.com]
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
@ -77,9 +77,6 @@ OpModules.Default = {
|
|||||||
"From HTML Entity": HTML.runFromEntity,
|
"From HTML Entity": HTML.runFromEntity,
|
||||||
"Strip HTML tags": HTML.runStripTags,
|
"Strip HTML tags": HTML.runStripTags,
|
||||||
"Parse colour code": HTML.runParseColourCode,
|
"Parse colour code": HTML.runParseColourCode,
|
||||||
"URL Encode": URL_.runTo,
|
|
||||||
"URL Decode": URL_.runFrom,
|
|
||||||
"Parse URI": URL_.runParse,
|
|
||||||
"Unescape Unicode Characters": Unicode.runUnescape,
|
"Unescape Unicode Characters": Unicode.runUnescape,
|
||||||
"To Quoted Printable": QuotedPrintable.runTo,
|
"To Quoted Printable": QuotedPrintable.runTo,
|
||||||
"From Quoted Printable": QuotedPrintable.runFrom,
|
"From Quoted Printable": QuotedPrintable.runFrom,
|
||||||
@ -146,6 +143,7 @@ OpModules.Default = {
|
|||||||
"Microsoft Script Decoder": MS.runDecodeScript,
|
"Microsoft Script Decoder": MS.runDecodeScript,
|
||||||
"Entropy": Entropy.runEntropy,
|
"Entropy": Entropy.runEntropy,
|
||||||
"Frequency distribution": Entropy.runFreqDistrib,
|
"Frequency distribution": Entropy.runFreqDistrib,
|
||||||
|
"Chi Square": Entropy.runChiSq,
|
||||||
"Detect File Type": FileType.runDetect,
|
"Detect File Type": FileType.runDetect,
|
||||||
"Scan for Embedded Files": FileType.runScanForEmbeddedFiles,
|
"Scan for Embedded Files": FileType.runScanForEmbeddedFiles,
|
||||||
"Generate UUID": UUID.runGenerateV4,
|
"Generate UUID": UUID.runGenerateV4,
|
||||||
@ -155,10 +153,19 @@ OpModules.Default = {
|
|||||||
"Fork": FlowControl.runFork,
|
"Fork": FlowControl.runFork,
|
||||||
"Merge": FlowControl.runMerge,
|
"Merge": FlowControl.runMerge,
|
||||||
"Register": FlowControl.runRegister,
|
"Register": FlowControl.runRegister,
|
||||||
|
"Label": FlowControl.runComment,
|
||||||
"Jump": FlowControl.runJump,
|
"Jump": FlowControl.runJump,
|
||||||
"Conditional Jump": FlowControl.runCondJump,
|
"Conditional Jump": FlowControl.runCondJump,
|
||||||
"Return": FlowControl.runReturn,
|
"Return": FlowControl.runReturn,
|
||||||
"Comment": FlowControl.runComment,
|
"Comment": FlowControl.runComment,
|
||||||
|
"PHP Deserialize": PHP.runDeserialize,
|
||||||
|
"Sum": Arithmetic.runSum,
|
||||||
|
"Subtract": Arithmetic.runSub,
|
||||||
|
"Multiply": Arithmetic.runMulti,
|
||||||
|
"Divide": Arithmetic.runDiv,
|
||||||
|
"Mean": Arithmetic.runMean,
|
||||||
|
"Median": Arithmetic.runMedian,
|
||||||
|
"Standard Deviation": Arithmetic.runStdDev,
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -19,6 +19,7 @@ import ImageModule from "./Image.js";
|
|||||||
import JSBNModule from "./JSBN.js";
|
import JSBNModule from "./JSBN.js";
|
||||||
import PublicKeyModule from "./PublicKey.js";
|
import PublicKeyModule from "./PublicKey.js";
|
||||||
import ShellcodeModule from "./Shellcode.js";
|
import ShellcodeModule from "./Shellcode.js";
|
||||||
|
import URLModule from "./URL.js";
|
||||||
|
|
||||||
Object.assign(
|
Object.assign(
|
||||||
OpModules,
|
OpModules,
|
||||||
@ -33,7 +34,8 @@ Object.assign(
|
|||||||
ImageModule,
|
ImageModule,
|
||||||
JSBNModule,
|
JSBNModule,
|
||||||
PublicKeyModule,
|
PublicKeyModule,
|
||||||
ShellcodeModule
|
ShellcodeModule,
|
||||||
|
URLModule
|
||||||
);
|
);
|
||||||
|
|
||||||
export default OpModules;
|
export default OpModules;
|
||||||
|
@ -8,6 +8,7 @@ import PGP from "../../operations/PGP.js";
|
|||||||
* - kbpgp
|
* - kbpgp
|
||||||
*
|
*
|
||||||
* @author tlwr [toby@toby.codes]
|
* @author tlwr [toby@toby.codes]
|
||||||
|
* @author Matt C [matt@artemisbot.uk]
|
||||||
* @copyright Crown Copyright 2017
|
* @copyright Crown Copyright 2017
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -17,6 +18,8 @@ OpModules.PGP = {
|
|||||||
"Generate PGP Key Pair": PGP.runGenerateKeyPair,
|
"Generate PGP Key Pair": PGP.runGenerateKeyPair,
|
||||||
"PGP Encrypt": PGP.runEncrypt,
|
"PGP Encrypt": PGP.runEncrypt,
|
||||||
"PGP Decrypt": PGP.runDecrypt,
|
"PGP Decrypt": PGP.runDecrypt,
|
||||||
|
"PGP Sign": PGP.runSign,
|
||||||
|
"PGP Verify": PGP.runVerify,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default OpModules;
|
export default OpModules;
|
||||||
|
23
src/core/config/modules/URL.js
Normal file
23
src/core/config/modules/URL.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import URL_ from "../../operations/URL.js";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL module.
|
||||||
|
*
|
||||||
|
* Libraries:
|
||||||
|
* - Utils.js
|
||||||
|
* - url
|
||||||
|
*
|
||||||
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2017
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
let OpModules = typeof self === "undefined" ? {} : self.OpModules || {};
|
||||||
|
|
||||||
|
OpModules.URL = {
|
||||||
|
"URL Encode": URL_.runTo,
|
||||||
|
"URL Decode": URL_.runFrom,
|
||||||
|
"Parse URI": URL_.runParse,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OpModules;
|
253
src/core/operations/Arithmetic.js
Normal file
253
src/core/operations/Arithmetic.js
Normal file
@ -0,0 +1,253 @@
|
|||||||
|
import Utils from "../Utils.js";
|
||||||
|
import BigNumber from "bignumber.js";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Math operations on numbers.
|
||||||
|
*
|
||||||
|
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||||
|
* @copyright Crown Copyright 2016
|
||||||
|
* @license Apache-2.0
|
||||||
|
*
|
||||||
|
* @namespace
|
||||||
|
*/
|
||||||
|
const Arithmetic = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
DELIM_OPTIONS: ["Line feed", "Space", "Comma", "Semi-colon", "Colon", "CRLF"],
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a string based on a delimiter and calculates the sum of numbers.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
runSum: function(input, args) {
|
||||||
|
const val = Arithmetic._sum(Arithmetic._createNumArray(input, args[0]));
|
||||||
|
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a string based on a delimiter and subtracts all the numbers.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
runSub: function(input, args) {
|
||||||
|
let val = Arithmetic._sub(Arithmetic._createNumArray(input, args[0]));
|
||||||
|
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a string based on a delimiter and multiplies the numbers.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
runMulti: function(input, args) {
|
||||||
|
let val = Arithmetic._multi(Arithmetic._createNumArray(input, args[0]));
|
||||||
|
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a string based on a delimiter and divides the numbers.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
runDiv: function(input, args) {
|
||||||
|
let val = Arithmetic._div(Arithmetic._createNumArray(input, args[0]));
|
||||||
|
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a string based on a delimiter and computes the mean (average).
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
runMean: function(input, args) {
|
||||||
|
let val = Arithmetic._mean(Arithmetic._createNumArray(input, args[0]));
|
||||||
|
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits a string based on a delimiter and finds the median.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
runMedian: function(input, args) {
|
||||||
|
let val = Arithmetic._median(Arithmetic._createNumArray(input, args[0]));
|
||||||
|
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* splits a string based on a delimiter and computes the standard deviation.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
runStdDev: function(input, args) {
|
||||||
|
let val = Arithmetic._stdDev(Arithmetic._createNumArray(input, args[0]));
|
||||||
|
return val instanceof BigNumber ? val : new BigNumber(NaN);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a string array to a number array.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string[]} input
|
||||||
|
* @param {string} delim
|
||||||
|
* @returns {BigNumber[]}
|
||||||
|
*/
|
||||||
|
_createNumArray: function(input, delim) {
|
||||||
|
delim = Utils.charRep[delim || "Space"];
|
||||||
|
let splitNumbers = input.split(delim),
|
||||||
|
numbers = [],
|
||||||
|
num;
|
||||||
|
|
||||||
|
for (let i = 0; i < splitNumbers.length; i++) {
|
||||||
|
try {
|
||||||
|
num = BigNumber(splitNumbers[i].trim());
|
||||||
|
if (!num.isNaN()) {
|
||||||
|
numbers.push(num);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// This line is not a valid number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return numbers;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an array of numbers and returns the value.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {BigNumber[]} data
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
_sum: function(data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
return data.reduce((acc, curr) => acc.plus(curr));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subtracts an array of numbers and returns the value.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {BigNumber[]} data
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
_sub: function(data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
return data.reduce((acc, curr) => acc.minus(curr));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiplies an array of numbers and returns the value.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {BigNumber[]} data
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
_multi: function(data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
return data.reduce((acc, curr) => acc.times(curr));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Divides an array of numbers and returns the value.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {BigNumber[]} data
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
_div: function(data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
return data.reduce((acc, curr) => acc.div(curr));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes mean of a number array and returns the value.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {BigNumber[]} data
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
_mean: function(data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
return Arithmetic._sum(data).div(data.length);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes median of a number array and returns the value.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {BigNumber[]} data
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
_median: function (data) {
|
||||||
|
if ((data.length % 2) === 0 && data.length > 0) {
|
||||||
|
let first, second;
|
||||||
|
data.sort(function(a, b){
|
||||||
|
return a.minus(b);
|
||||||
|
});
|
||||||
|
first = data[Math.floor(data.length / 2)];
|
||||||
|
second = data[Math.floor(data.length / 2) - 1];
|
||||||
|
return Arithmetic._mean([first, second]);
|
||||||
|
} else {
|
||||||
|
return data[Math.floor(data.length / 2)];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes standard deviation of a number array and returns the value.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {BigNumber[]} data
|
||||||
|
* @returns {BigNumber}
|
||||||
|
*/
|
||||||
|
_stdDev: function (data) {
|
||||||
|
if (data.length > 0) {
|
||||||
|
let avg = Arithmetic._mean(data);
|
||||||
|
let devSum = new BigNumber(0);
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
devSum = devSum.plus(data[i].minus(avg).pow(2));
|
||||||
|
}
|
||||||
|
return devSum.div(data.length).sqrt();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Arithmetic;
|
@ -1,4 +1,5 @@
|
|||||||
import Utils from "../Utils.js";
|
import Utils from "../Utils.js";
|
||||||
|
import BigNumber from "bignumber.js";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,14 +62,14 @@ const BCD = {
|
|||||||
/**
|
/**
|
||||||
* To BCD operation.
|
* To BCD operation.
|
||||||
*
|
*
|
||||||
* @param {number} input
|
* @param {BigNumber} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runToBCD: function(input, args) {
|
runToBCD: function(input, args) {
|
||||||
if (isNaN(input))
|
if (input.isNaN())
|
||||||
return "Invalid input";
|
return "Invalid input";
|
||||||
if (Math.floor(input) !== input)
|
if (!input.floor().equals(input))
|
||||||
return "Fractional values are not supported by BCD";
|
return "Fractional values are not supported by BCD";
|
||||||
|
|
||||||
const encoding = BCD.ENCODING_LOOKUP[args[0]],
|
const encoding = BCD.ENCODING_LOOKUP[args[0]],
|
||||||
@ -77,7 +78,7 @@ const BCD = {
|
|||||||
outputFormat = args[3];
|
outputFormat = args[3];
|
||||||
|
|
||||||
// Split input number up into separate digits
|
// Split input number up into separate digits
|
||||||
const digits = input.toString().split("");
|
const digits = input.toFixed().split("");
|
||||||
|
|
||||||
if (digits[0] === "-" || digits[0] === "+") {
|
if (digits[0] === "-" || digits[0] === "+") {
|
||||||
digits.shift();
|
digits.shift();
|
||||||
@ -134,11 +135,11 @@ const BCD = {
|
|||||||
switch (outputFormat) {
|
switch (outputFormat) {
|
||||||
case "Nibbles":
|
case "Nibbles":
|
||||||
return nibbles.map(n => {
|
return nibbles.map(n => {
|
||||||
return Utils.padLeft(n.toString(2), 4);
|
return n.toString(2).padStart(4, "0");
|
||||||
}).join(" ");
|
}).join(" ");
|
||||||
case "Bytes":
|
case "Bytes":
|
||||||
return bytes.map(b => {
|
return bytes.map(b => {
|
||||||
return Utils.padLeft(b.toString(2), 8);
|
return b.toString(2).padStart(8, "0");
|
||||||
}).join(" ");
|
}).join(" ");
|
||||||
case "Raw":
|
case "Raw":
|
||||||
default:
|
default:
|
||||||
@ -152,7 +153,7 @@ const BCD = {
|
|||||||
*
|
*
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {BigNumber}
|
||||||
*/
|
*/
|
||||||
runFromBCD: function(input, args) {
|
runFromBCD: function(input, args) {
|
||||||
const encoding = BCD.ENCODING_LOOKUP[args[0]],
|
const encoding = BCD.ENCODING_LOOKUP[args[0]],
|
||||||
@ -206,7 +207,7 @@ const BCD = {
|
|||||||
output += val.toString();
|
output += val.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
return parseInt(output, 10);
|
return new BigNumber(output);
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import BigNumber from "bignumber.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Numerical base operations.
|
* Numerical base operations.
|
||||||
*
|
*
|
||||||
@ -18,7 +20,7 @@ const Base = {
|
|||||||
/**
|
/**
|
||||||
* To Base operation.
|
* To Base operation.
|
||||||
*
|
*
|
||||||
* @param {number} input
|
* @param {BigNumber} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
@ -39,7 +41,7 @@ const Base = {
|
|||||||
*
|
*
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {BigNumber}
|
||||||
*/
|
*/
|
||||||
runFrom: function(input, args) {
|
runFrom: function(input, args) {
|
||||||
const radix = args[0] || Base.DEFAULT_RADIX;
|
const radix = args[0] || Base.DEFAULT_RADIX;
|
||||||
@ -48,14 +50,14 @@ const Base = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let number = input.replace(/\s/g, "").split("."),
|
let number = input.replace(/\s/g, "").split("."),
|
||||||
result = parseInt(number[0], radix) || 0;
|
result = new BigNumber(number[0], radix) || 0;
|
||||||
|
|
||||||
if (number.length === 1) return result;
|
if (number.length === 1) return result;
|
||||||
|
|
||||||
// Fractional part
|
// Fractional part
|
||||||
for (let i = 0; i < number[1].length; i++) {
|
for (let i = 0; i < number[1].length; i++) {
|
||||||
const digit = parseInt(number[1][i], radix);
|
const digit = new BigNumber(number[1][i], radix);
|
||||||
result += digit / Math.pow(radix, i+1);
|
result += digit.div(Math.pow(radix, i+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -40,13 +40,13 @@ const Base64 = {
|
|||||||
/**
|
/**
|
||||||
* To Base64 operation.
|
* To Base64 operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runTo: function(input, args) {
|
runTo: function(input, args) {
|
||||||
const alphabet = args[0] || Base64.ALPHABET;
|
const alphabet = args[0] || Base64.ALPHABET;
|
||||||
return Utils.toBase64(input, alphabet);
|
return Utils.toBase64(new Uint8Array(input), alphabet);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ const BitwiseOp = {
|
|||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
KEY_FORMAT: ["Hex", "Base64", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1"],
|
KEY_FORMAT: ["Hex", "Base64", "UTF8", "Latin1"],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XOR operation.
|
* XOR operation.
|
||||||
@ -77,12 +77,10 @@ const BitwiseOp = {
|
|||||||
* @returns {byteArray}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
runXor: function (input, args) {
|
runXor: function (input, args) {
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string || ""),
|
const key = Utils.convertToByteArray(args[0].string || "", args[0].option),
|
||||||
scheme = args[1],
|
scheme = args[1],
|
||||||
nullPreserving = args[2];
|
nullPreserving = args[2];
|
||||||
|
|
||||||
key = Utils.wordArrayToByteArray(key);
|
|
||||||
|
|
||||||
return BitwiseOp._bitOp(input, key, BitwiseOp._xor, nullPreserving, scheme);
|
return BitwiseOp._bitOp(input, key, BitwiseOp._xor, nullPreserving, scheme);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -200,8 +198,7 @@ const BitwiseOp = {
|
|||||||
* @returns {byteArray}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
runAnd: function (input, args) {
|
runAnd: function (input, args) {
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string || "");
|
const key = Utils.convertToByteArray(args[0].string || "", args[0].option);
|
||||||
key = Utils.wordArrayToByteArray(key);
|
|
||||||
|
|
||||||
return BitwiseOp._bitOp(input, key, BitwiseOp._and);
|
return BitwiseOp._bitOp(input, key, BitwiseOp._and);
|
||||||
},
|
},
|
||||||
@ -215,8 +212,7 @@ const BitwiseOp = {
|
|||||||
* @returns {byteArray}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
runOr: function (input, args) {
|
runOr: function (input, args) {
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string || "");
|
const key = Utils.convertToByteArray(args[0].string || "", args[0].option);
|
||||||
key = Utils.wordArrayToByteArray(key);
|
|
||||||
|
|
||||||
return BitwiseOp._bitOp(input, key, BitwiseOp._or);
|
return BitwiseOp._bitOp(input, key, BitwiseOp._or);
|
||||||
},
|
},
|
||||||
@ -230,8 +226,7 @@ const BitwiseOp = {
|
|||||||
* @returns {byteArray}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
runAdd: function (input, args) {
|
runAdd: function (input, args) {
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string || "");
|
const key = Utils.convertToByteArray(args[0].string || "", args[0].option);
|
||||||
key = Utils.wordArrayToByteArray(key);
|
|
||||||
|
|
||||||
return BitwiseOp._bitOp(input, key, BitwiseOp._add);
|
return BitwiseOp._bitOp(input, key, BitwiseOp._add);
|
||||||
},
|
},
|
||||||
@ -245,8 +240,7 @@ const BitwiseOp = {
|
|||||||
* @returns {byteArray}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
runSub: function (input, args) {
|
runSub: function (input, args) {
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string || "");
|
const key = Utils.convertToByteArray(args[0].string || "", args[0].option);
|
||||||
key = Utils.wordArrayToByteArray(key);
|
|
||||||
|
|
||||||
return BitwiseOp._bitOp(input, key, BitwiseOp._sub);
|
return BitwiseOp._bitOp(input, key, BitwiseOp._sub);
|
||||||
},
|
},
|
||||||
|
@ -31,13 +31,13 @@ const ByteRepr = {
|
|||||||
/**
|
/**
|
||||||
* To Hex operation.
|
* To Hex operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runToHex: function(input, args) {
|
runToHex: function(input, args) {
|
||||||
const delim = Utils.charRep[args[0] || "Space"];
|
const delim = Utils.charRep[args[0] || "Space"];
|
||||||
return Utils.toHex(input, delim, 2);
|
return Utils.toHex(new Uint8Array(input), delim, 2);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ const ByteRepr = {
|
|||||||
padding = 8;
|
padding = 8;
|
||||||
|
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
output += Utils.pad(input[i].toString(2), padding) + delim;
|
output += input[i].toString(2).padStart(padding, "0") + delim;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delim.length) {
|
if (delim.length) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import Utils from "../Utils.js";
|
import Utils from "../Utils.js";
|
||||||
import CryptoJS from "crypto-js";
|
import CryptoJS from "crypto-js";
|
||||||
|
import forge from "imports-loader?jQuery=>null!node-forge/dist/forge.min.js";
|
||||||
import {blowfish as Blowfish} from "sladex-blowfish";
|
import {blowfish as Blowfish} from "sladex-blowfish";
|
||||||
|
import BigNumber from "bignumber.js";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,132 +20,27 @@ const Cipher = {
|
|||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT1: ["Hex", "Base64", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1"],
|
IO_FORMAT1: ["Hex", "UTF8", "Latin1", "Base64"],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT2: ["UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1", "Hex", "Base64"],
|
IO_FORMAT2: ["UTF8", "Latin1", "Hex", "Base64"],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT3: ["Hex", "Base64", "UTF16", "UTF16LE", "UTF16BE", "Latin1"],
|
IO_FORMAT3: ["Raw", "Hex"],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT4: ["Latin1", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Hex", "Base64"],
|
IO_FORMAT4: ["Hex", "Raw"],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
MODES: ["CBC", "CFB", "CTR", "OFB", "ECB"],
|
AES_MODES: ["CBC", "CFB", "OFB", "CTR", "GCM", "ECB"],
|
||||||
/**
|
|
||||||
* @constant
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
PADDING: ["Pkcs7", "Iso97971", "AnsiX923", "Iso10126", "ZeroPadding", "NoPadding"],
|
|
||||||
/**
|
|
||||||
* @constant
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
RESULT_TYPE: ["Show all", "Ciphertext", "Key", "IV", "Salt"],
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs encryption operations using the CryptoJS framework.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {function} algo - The CryptoJS algorithm to use
|
|
||||||
* @param {byteArray} input
|
|
||||||
* @param {function} args
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
_enc: function (algo, input, args) {
|
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string || ""),
|
|
||||||
iv = Utils.format[args[1].option].parse(args[1].string || ""),
|
|
||||||
salt = Utils.format[args[2].option].parse(args[2].string || ""),
|
|
||||||
mode = CryptoJS.mode[args[3]],
|
|
||||||
padding = CryptoJS.pad[args[4]],
|
|
||||||
resultOption = args[5].toLowerCase(),
|
|
||||||
outputFormat = args[6];
|
|
||||||
|
|
||||||
if (iv.sigBytes === 0) {
|
|
||||||
// Use passphrase rather than key. Need to convert it to a string.
|
|
||||||
key = key.toString(CryptoJS.enc.Latin1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const encrypted = algo.encrypt(input, key, {
|
|
||||||
salt: salt.sigBytes > 0 ? salt : false,
|
|
||||||
iv: iv.sigBytes > 0 ? iv : null,
|
|
||||||
mode: mode,
|
|
||||||
padding: padding
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = "";
|
|
||||||
if (resultOption === "show all") {
|
|
||||||
result += "Key: " + encrypted.key.toString(Utils.format[outputFormat]);
|
|
||||||
result += "\nIV: " + encrypted.iv.toString(Utils.format[outputFormat]);
|
|
||||||
if (encrypted.salt) result += "\nSalt: " + encrypted.salt.toString(Utils.format[outputFormat]);
|
|
||||||
result += "\n\nCiphertext: " + encrypted.ciphertext.toString(Utils.format[outputFormat]);
|
|
||||||
} else {
|
|
||||||
result = encrypted[resultOption].toString(Utils.format[outputFormat]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs decryption operations using the CryptoJS framework.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {function} algo - The CryptoJS algorithm to use
|
|
||||||
* @param {byteArray} input
|
|
||||||
* @param {function} args
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
_dec: function (algo, input, args) {
|
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string || ""),
|
|
||||||
iv = Utils.format[args[1].option].parse(args[1].string || ""),
|
|
||||||
salt = Utils.format[args[2].option].parse(args[2].string || ""),
|
|
||||||
mode = CryptoJS.mode[args[3]],
|
|
||||||
padding = CryptoJS.pad[args[4]],
|
|
||||||
inputFormat = args[5],
|
|
||||||
outputFormat = args[6];
|
|
||||||
|
|
||||||
// The ZeroPadding option causes a crash when the input length is 0
|
|
||||||
if (!input.length) {
|
|
||||||
return "No input";
|
|
||||||
}
|
|
||||||
|
|
||||||
const ciphertext = Utils.format[inputFormat].parse(input);
|
|
||||||
|
|
||||||
if (iv.sigBytes === 0) {
|
|
||||||
// Use passphrase rather than key. Need to convert it to a string.
|
|
||||||
key = key.toString(CryptoJS.enc.Latin1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const decrypted = algo.decrypt({
|
|
||||||
ciphertext: ciphertext,
|
|
||||||
salt: salt.sigBytes > 0 ? salt : false
|
|
||||||
}, key, {
|
|
||||||
iv: iv.sigBytes > 0 ? iv : null,
|
|
||||||
mode: mode,
|
|
||||||
padding: padding
|
|
||||||
});
|
|
||||||
|
|
||||||
let result;
|
|
||||||
try {
|
|
||||||
result = decrypted.toString(Utils.format[outputFormat]);
|
|
||||||
} catch (err) {
|
|
||||||
result = "Decrypt error: " + err.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AES Encrypt operation.
|
* AES Encrypt operation.
|
||||||
@ -153,7 +50,41 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runAesEnc: function (input, args) {
|
runAesEnc: function (input, args) {
|
||||||
return Cipher._enc(CryptoJS.AES, input, args);
|
const key = Utils.convertToByteArray(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
|
if ([16, 24, 32].indexOf(key.length) < 0) {
|
||||||
|
return `Invalid key length: ${key.length} bytes
|
||||||
|
|
||||||
|
The following algorithms will be used based on the size of the key:
|
||||||
|
16 bytes = AES-128
|
||||||
|
24 bytes = AES-192
|
||||||
|
32 bytes = AES-256`;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
const cipher = forge.cipher.createCipher("AES-" + mode, key);
|
||||||
|
cipher.start({iv: iv});
|
||||||
|
cipher.update(forge.util.createBuffer(input));
|
||||||
|
cipher.finish();
|
||||||
|
|
||||||
|
if (outputType === "Hex") {
|
||||||
|
if (mode === "GCM") {
|
||||||
|
return cipher.output.toHex() + "\n\n" +
|
||||||
|
"Tag: " + cipher.mode.tag.toHex();
|
||||||
|
}
|
||||||
|
return cipher.output.toHex();
|
||||||
|
} else {
|
||||||
|
if (mode === "GCM") {
|
||||||
|
return cipher.output.getBytes() + "\n\n" +
|
||||||
|
"Tag: " + cipher.mode.tag.getBytes();
|
||||||
|
}
|
||||||
|
return cipher.output.getBytes();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -165,10 +96,46 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runAesDec: function (input, args) {
|
runAesDec: function (input, args) {
|
||||||
return Cipher._dec(CryptoJS.AES, input, args);
|
const key = Utils.convertToByteArray(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4],
|
||||||
|
gcmTag = Utils.convertToByteString(args[5].string, args[5].option);
|
||||||
|
|
||||||
|
if ([16, 24, 32].indexOf(key.length) < 0) {
|
||||||
|
return `Invalid key length: ${key.length} bytes
|
||||||
|
|
||||||
|
The following algorithms will be used based on the size of the key:
|
||||||
|
16 bytes = AES-128
|
||||||
|
24 bytes = AES-192
|
||||||
|
32 bytes = AES-256`;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
const decipher = forge.cipher.createDecipher("AES-" + mode, key);
|
||||||
|
decipher.start({
|
||||||
|
iv: iv,
|
||||||
|
tag: gcmTag
|
||||||
|
});
|
||||||
|
decipher.update(forge.util.createBuffer(input));
|
||||||
|
const result = decipher.finish();
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
|
||||||
|
} else {
|
||||||
|
return "Unable to decrypt input with these parameters.";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
DES_MODES: ["CBC", "CFB", "OFB", "CTR", "ECB"],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DES Encrypt operation.
|
* DES Encrypt operation.
|
||||||
*
|
*
|
||||||
@ -177,7 +144,27 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runDesEnc: function (input, args) {
|
runDesEnc: function (input, args) {
|
||||||
return Cipher._enc(CryptoJS.DES, input, args);
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
|
if (key.length !== 8) {
|
||||||
|
return `Invalid key length: ${key.length} bytes
|
||||||
|
|
||||||
|
DES uses a key length of 8 bytes (64 bits).
|
||||||
|
Triple DES uses a key length of 24 bytes (192 bits).`;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
const cipher = forge.cipher.createCipher("DES-" + mode, key);
|
||||||
|
cipher.start({iv: iv});
|
||||||
|
cipher.update(forge.util.createBuffer(input));
|
||||||
|
cipher.finish();
|
||||||
|
|
||||||
|
return outputType === "Hex" ? cipher.output.toHex() : cipher.output.getBytes();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -189,7 +176,31 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runDesDec: function (input, args) {
|
runDesDec: function (input, args) {
|
||||||
return Cipher._dec(CryptoJS.DES, input, args);
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
|
if (key.length !== 8) {
|
||||||
|
return `Invalid key length: ${key.length} bytes
|
||||||
|
|
||||||
|
DES uses a key length of 8 bytes (64 bits).
|
||||||
|
Triple DES uses a key length of 24 bytes (192 bits).`;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
const decipher = forge.cipher.createDecipher("DES-" + mode, key);
|
||||||
|
decipher.start({iv: iv});
|
||||||
|
decipher.update(forge.util.createBuffer(input));
|
||||||
|
const result = decipher.finish();
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
|
||||||
|
} else {
|
||||||
|
return "Unable to decrypt input with these parameters.";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -201,7 +212,27 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runTripleDesEnc: function (input, args) {
|
runTripleDesEnc: function (input, args) {
|
||||||
return Cipher._enc(CryptoJS.TripleDES, input, args);
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
|
if (key.length !== 24) {
|
||||||
|
return `Invalid key length: ${key.length} bytes
|
||||||
|
|
||||||
|
Triple DES uses a key length of 24 bytes (192 bits).
|
||||||
|
DES uses a key length of 8 bytes (64 bits).`;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
const cipher = forge.cipher.createCipher("3DES-" + mode, key);
|
||||||
|
cipher.start({iv: iv});
|
||||||
|
cipher.update(forge.util.createBuffer(input));
|
||||||
|
cipher.finish();
|
||||||
|
|
||||||
|
return outputType === "Hex" ? cipher.output.toHex() : cipher.output.getBytes();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -213,31 +244,79 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runTripleDesDec: function (input, args) {
|
runTripleDesDec: function (input, args) {
|
||||||
return Cipher._dec(CryptoJS.TripleDES, input, args);
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
|
if (key.length !== 24) {
|
||||||
|
return `Invalid key length: ${key.length} bytes
|
||||||
|
|
||||||
|
Triple DES uses a key length of 24 bytes (192 bits).
|
||||||
|
DES uses a key length of 8 bytes (64 bits).`;
|
||||||
|
}
|
||||||
|
|
||||||
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
const decipher = forge.cipher.createDecipher("3DES-" + mode, key);
|
||||||
|
decipher.start({iv: iv});
|
||||||
|
decipher.update(forge.util.createBuffer(input));
|
||||||
|
const result = decipher.finish();
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
|
||||||
|
} else {
|
||||||
|
return "Unable to decrypt input with these parameters.";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rabbit Encrypt operation.
|
* RC2 Encrypt operation.
|
||||||
*
|
*
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runRabbitEnc: function (input, args) {
|
runRc2Enc: function (input, args) {
|
||||||
return Cipher._enc(CryptoJS.Rabbit, input, args);
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteString(args[1].string, args[1].option),
|
||||||
|
inputType = args[2],
|
||||||
|
outputType = args[3],
|
||||||
|
cipher = forge.rc2.createEncryptionCipher(key);
|
||||||
|
|
||||||
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
cipher.start(iv || null);
|
||||||
|
cipher.update(forge.util.createBuffer(input));
|
||||||
|
cipher.finish();
|
||||||
|
|
||||||
|
return outputType === "Hex" ? cipher.output.toHex() : cipher.output.getBytes();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rabbit Decrypt operation.
|
* RC2 Decrypt operation.
|
||||||
*
|
*
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runRabbitDec: function (input, args) {
|
runRc2Dec: function (input, args) {
|
||||||
return Cipher._dec(CryptoJS.Rabbit, input, args);
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
|
iv = Utils.convertToByteString(args[1].string, args[1].option),
|
||||||
|
inputType = args[2],
|
||||||
|
outputType = args[3],
|
||||||
|
decipher = forge.rc2.createDecryptionCipher(key);
|
||||||
|
|
||||||
|
input = Utils.convertToByteString(input, inputType);
|
||||||
|
|
||||||
|
decipher.start(iv || null);
|
||||||
|
decipher.update(forge.util.createBuffer(input));
|
||||||
|
decipher.finish();
|
||||||
|
|
||||||
|
return outputType === "Hex" ? decipher.output.toHex() : decipher.output.getBytes();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -245,12 +324,29 @@ const Cipher = {
|
|||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BLOWFISH_MODES: ["ECB", "CBC", "PCBC", "CFB", "OFB", "CTR"],
|
BLOWFISH_MODES: ["CBC", "PCBC", "CFB", "OFB", "CTR", "ECB"],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BLOWFISH_OUTPUT_TYPES: ["Base64", "Hex", "String", "Raw"],
|
BLOWFISH_OUTPUT_TYPES: ["Hex", "Base64", "Raw"],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup table for Blowfish output types.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_BLOWFISH_OUTPUT_TYPE_LOOKUP: {
|
||||||
|
Base64: 0, Hex: 1, String: 2, Raw: 3
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Lookup table for Blowfish modes.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_BLOWFISH_MODE_LOOKUP: {
|
||||||
|
ECB: 0, CBC: 1, PCBC: 2, CFB: 3, OFB: 4, CTR: 5
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blowfish Encrypt operation.
|
* Blowfish Encrypt operation.
|
||||||
@ -260,19 +356,24 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runBlowfishEnc: function (input, args) {
|
runBlowfishEnc: function (input, args) {
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string).toString(Utils.format.Latin1),
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
mode = args[1],
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
outputFormat = args[2];
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
if (key.length === 0) return "Enter a key";
|
if (key.length === 0) return "Enter a key";
|
||||||
|
|
||||||
let encHex = Blowfish.encrypt(input, key, {
|
input = Utils.convertToByteString(input, inputType);
|
||||||
outputType: 1,
|
|
||||||
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode)
|
|
||||||
}),
|
|
||||||
enc = CryptoJS.enc.Hex.parse(encHex);
|
|
||||||
|
|
||||||
return enc.toString(Utils.format[outputFormat]);
|
Blowfish.setIV(Utils.toBase64(iv), 0);
|
||||||
|
|
||||||
|
const enc = Blowfish.encrypt(input, key, {
|
||||||
|
outputType: Cipher._BLOWFISH_OUTPUT_TYPE_LOOKUP[outputType],
|
||||||
|
cipherMode: Cipher._BLOWFISH_MODE_LOOKUP[mode]
|
||||||
|
});
|
||||||
|
|
||||||
|
return outputType === "Raw" ? Utils.byteArrayToChars(enc) : enc ;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -284,18 +385,24 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runBlowfishDec: function (input, args) {
|
runBlowfishDec: function (input, args) {
|
||||||
let key = Utils.format[args[0].option].parse(args[0].string).toString(Utils.format.Latin1),
|
const key = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
mode = args[1],
|
iv = Utils.convertToByteArray(args[1].string, args[1].option),
|
||||||
inputFormat = args[2];
|
mode = args[2],
|
||||||
|
inputType = args[3],
|
||||||
|
outputType = args[4];
|
||||||
|
|
||||||
if (key.length === 0) return "Enter a key";
|
if (key.length === 0) return "Enter a key";
|
||||||
|
|
||||||
input = Utils.format[inputFormat].parse(input);
|
input = inputType === "Raw" ? Utils.strToByteArray(input) : input;
|
||||||
|
|
||||||
return Blowfish.decrypt(input.toString(CryptoJS.enc.Base64), key, {
|
Blowfish.setIV(Utils.toBase64(iv), 0);
|
||||||
outputType: 0, // This actually means inputType. The library is weird.
|
|
||||||
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode)
|
const result = Blowfish.decrypt(input, key, {
|
||||||
|
outputType: Cipher._BLOWFISH_OUTPUT_TYPE_LOOKUP[inputType], // This actually means inputType. The library is weird.
|
||||||
|
cipherMode: Cipher._BLOWFISH_MODE_LOOKUP[mode]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return outputType === "Hex" ? Utils.toHexFast(Utils.strToByteArray(result)) : result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -303,7 +410,7 @@ const Cipher = {
|
|||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
KDF_KEY_SIZE: 256,
|
KDF_KEY_SIZE: 128,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
@ -313,7 +420,7 @@ const Cipher = {
|
|||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
HASHERS: ["MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SHA3", "RIPEMD160"],
|
HASHERS: ["SHA1", "SHA256", "SHA384", "SHA512", "MD5"],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derive PBKDF2 key operation.
|
* Derive PBKDF2 key operation.
|
||||||
@ -323,20 +430,15 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runPbkdf2: function (input, args) {
|
runPbkdf2: function (input, args) {
|
||||||
let keySize = args[0] / 32,
|
const passphrase = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
iterations = args[1],
|
keySize = args[1],
|
||||||
hasher = args[2],
|
iterations = args[2],
|
||||||
salt = CryptoJS.enc.Hex.parse(args[3] || ""),
|
hasher = args[3],
|
||||||
inputFormat = args[4],
|
salt = Utils.convertToByteString(args[4].string, args[4].option) ||
|
||||||
outputFormat = args[5],
|
forge.random.getBytesSync(keySize),
|
||||||
passphrase = Utils.format[inputFormat].parse(input),
|
derivedKey = forge.pkcs5.pbkdf2(passphrase, salt, iterations, keySize / 8, hasher.toLowerCase());
|
||||||
key = CryptoJS.PBKDF2(passphrase, salt, {
|
|
||||||
keySize: keySize,
|
|
||||||
hasher: CryptoJS.algo[hasher],
|
|
||||||
iterations: iterations,
|
|
||||||
});
|
|
||||||
|
|
||||||
return key.toString(Utils.format[outputFormat]);
|
return forge.util.bytesToHex(derivedKey);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -348,23 +450,33 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runEvpkdf: function (input, args) {
|
runEvpkdf: function (input, args) {
|
||||||
let keySize = args[0] / 32,
|
const passphrase = Utils.convertToByteString(args[0].string, args[0].option),
|
||||||
iterations = args[1],
|
keySize = args[1] / 32,
|
||||||
hasher = args[2],
|
iterations = args[2],
|
||||||
salt = CryptoJS.enc.Hex.parse(args[3] || ""),
|
hasher = args[3],
|
||||||
inputFormat = args[4],
|
salt = Utils.convertToByteString(args[4].string, args[4].option),
|
||||||
outputFormat = args[5],
|
|
||||||
passphrase = Utils.format[inputFormat].parse(input),
|
|
||||||
key = CryptoJS.EvpKDF(passphrase, salt, {
|
key = CryptoJS.EvpKDF(passphrase, salt, {
|
||||||
keySize: keySize,
|
keySize: keySize,
|
||||||
hasher: CryptoJS.algo[hasher],
|
hasher: CryptoJS.algo[hasher],
|
||||||
iterations: iterations,
|
iterations: iterations,
|
||||||
});
|
});
|
||||||
|
|
||||||
return key.toString(Utils.format[outputFormat]);
|
return key.toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
RC4_KEY_FORMAT: ["UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1", "Hex", "Base64"],
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
CJS_IO_FORMAT: ["Latin1", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Hex", "Base64"],
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RC4 operation.
|
* RC4 operation.
|
||||||
*
|
*
|
||||||
@ -373,11 +485,11 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runRc4: function (input, args) {
|
runRc4: function (input, args) {
|
||||||
let message = Utils.format[args[1]].parse(input),
|
let message = Cipher._format[args[1]].parse(input),
|
||||||
passphrase = Utils.format[args[0].option].parse(args[0].string),
|
passphrase = Cipher._format[args[0].option].parse(args[0].string),
|
||||||
encrypted = CryptoJS.RC4.encrypt(message, passphrase);
|
encrypted = CryptoJS.RC4.encrypt(message, passphrase);
|
||||||
|
|
||||||
return encrypted.ciphertext.toString(Utils.format[args[2]]);
|
return encrypted.ciphertext.toString(Cipher._format[args[2]]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -395,12 +507,59 @@ const Cipher = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runRc4drop: function (input, args) {
|
runRc4drop: function (input, args) {
|
||||||
let message = Utils.format[args[1]].parse(input),
|
let message = Cipher._format[args[1]].parse(input),
|
||||||
passphrase = Utils.format[args[0].option].parse(args[0].string),
|
passphrase = Cipher._format[args[0].option].parse(args[0].string),
|
||||||
drop = args[3],
|
drop = args[3],
|
||||||
encrypted = CryptoJS.RC4Drop.encrypt(message, passphrase, { drop: drop });
|
encrypted = CryptoJS.RC4Drop.encrypt(message, passphrase, { drop: drop });
|
||||||
|
|
||||||
return encrypted.ciphertext.toString(Utils.format[args[2]]);
|
return encrypted.ciphertext.toString(Cipher._format[args[2]]);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
PRNG_BYTES: 32,
|
||||||
|
PRNG_OUTPUT: ["Hex", "Integer", "Byte array", "Raw"],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pseudo-Random Number Generator operation.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
runPRNG: function(input, args) {
|
||||||
|
const numBytes = args[0],
|
||||||
|
outputAs = args[1];
|
||||||
|
|
||||||
|
let bytes;
|
||||||
|
|
||||||
|
if (ENVIRONMENT_IS_WORKER() && self.crypto) {
|
||||||
|
bytes = self.crypto.getRandomValues(new Uint8Array(numBytes));
|
||||||
|
bytes = Utils.arrayBufferToStr(bytes.buffer);
|
||||||
|
} else {
|
||||||
|
bytes = forge.random.getBytesSync(numBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
let value = new BigNumber(0),
|
||||||
|
i;
|
||||||
|
|
||||||
|
switch (outputAs) {
|
||||||
|
case "Hex":
|
||||||
|
return forge.util.bytesToHex(bytes);
|
||||||
|
case "Integer":
|
||||||
|
for (i = bytes.length - 1; i >= 0; i--) {
|
||||||
|
value = value.mul(256).plus(bytes.charCodeAt(i));
|
||||||
|
}
|
||||||
|
return value.toFixed();
|
||||||
|
case "Byte array":
|
||||||
|
return JSON.stringify(Utils.strToCharcode(bytes));
|
||||||
|
case "Raw":
|
||||||
|
default:
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -783,6 +942,23 @@ const Cipher = {
|
|||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A mapping of string formats to their classes in the CryptoJS library.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @constant
|
||||||
|
*/
|
||||||
|
_format: {
|
||||||
|
"Hex": CryptoJS.enc.Hex,
|
||||||
|
"Base64": CryptoJS.enc.Base64,
|
||||||
|
"UTF8": CryptoJS.enc.Utf8,
|
||||||
|
"UTF16": CryptoJS.enc.Utf16,
|
||||||
|
"UTF16LE": CryptoJS.enc.Utf16LE,
|
||||||
|
"UTF16BE": CryptoJS.enc.Utf16BE,
|
||||||
|
"Latin1": CryptoJS.enc.Latin1,
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Cipher;
|
export default Cipher;
|
||||||
@ -827,3 +1003,27 @@ CryptoJS.kdf.OpenSSL.execute = function (password, keySize, ivSize, salt) {
|
|||||||
// Return params
|
// Return params
|
||||||
return CryptoJS.lib.CipherParams.create({ key: key, iv: iv, salt: salt });
|
return CryptoJS.lib.CipherParams.create({ key: key, iv: iv, salt: salt });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override for the CryptoJS Hex encoding parser to remove whitespace before attempting to parse
|
||||||
|
* the hex string.
|
||||||
|
*
|
||||||
|
* @param {string} hexStr
|
||||||
|
* @returns {CryptoJS.lib.WordArray}
|
||||||
|
*/
|
||||||
|
CryptoJS.enc.Hex.parse = function (hexStr) {
|
||||||
|
// Remove whitespace
|
||||||
|
hexStr = hexStr.replace(/\s/g, "");
|
||||||
|
|
||||||
|
// Shortcut
|
||||||
|
const hexStrLength = hexStr.length;
|
||||||
|
|
||||||
|
// Convert
|
||||||
|
const words = [];
|
||||||
|
for (let i = 0; i < hexStrLength; i += 2) {
|
||||||
|
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CryptoJS.lib.WordArray.init(words, hexStrLength / 2);
|
||||||
|
};
|
||||||
|
@ -2,9 +2,10 @@ import {camelCase, kebabCase, snakeCase} from "lodash";
|
|||||||
|
|
||||||
import Utils from "../Utils.js";
|
import Utils from "../Utils.js";
|
||||||
import vkbeautify from "vkbeautify";
|
import vkbeautify from "vkbeautify";
|
||||||
import {DOMParser as dom} from "xmldom";
|
import {DOMParser} from "xmldom";
|
||||||
import xpath from "xpath";
|
import xpath from "xpath";
|
||||||
import jpath from "jsonpath";
|
import jpath from "jsonpath";
|
||||||
|
import nwmatcher from "nwmatcher";
|
||||||
import prettyPrintOne from "imports-loader?window=>global!exports-loader?prettyPrintOne!google-code-prettify/bin/prettify.min.js";
|
import prettyPrintOne from "imports-loader?window=>global!exports-loader?prettyPrintOne!google-code-prettify/bin/prettify.min.js";
|
||||||
|
|
||||||
|
|
||||||
@ -336,7 +337,7 @@ const Code = {
|
|||||||
|
|
||||||
let doc;
|
let doc;
|
||||||
try {
|
try {
|
||||||
doc = new dom().parseFromString(input);
|
doc = new DOMParser().parseFromString(input, "application/xml");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return "Invalid input XML.";
|
return "Invalid input XML.";
|
||||||
}
|
}
|
||||||
@ -423,7 +424,7 @@ const Code = {
|
|||||||
let query = args[0],
|
let query = args[0],
|
||||||
delimiter = args[1],
|
delimiter = args[1],
|
||||||
parser = new DOMParser(),
|
parser = new DOMParser(),
|
||||||
html,
|
dom,
|
||||||
result;
|
result;
|
||||||
|
|
||||||
if (!query.length || !input.length) {
|
if (!query.length || !input.length) {
|
||||||
@ -431,32 +432,32 @@ const Code = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
html = parser.parseFromString(input, "text/html");
|
dom = parser.parseFromString(input);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return "Invalid input HTML.";
|
return "Invalid input HTML.";
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = html.querySelectorAll(query);
|
const matcher = nwmatcher({document: dom});
|
||||||
|
result = matcher.select(query, dom);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return "Invalid CSS Selector. Details:\n" + err.message;
|
return "Invalid CSS Selector. Details:\n" + err.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeToString = function(node) {
|
const nodeToString = function(node) {
|
||||||
|
return node.toString();
|
||||||
|
/* xmldom does not return the outerHTML value.
|
||||||
switch (node.nodeType) {
|
switch (node.nodeType) {
|
||||||
case Node.ELEMENT_NODE: return node.outerHTML;
|
case node.ELEMENT_NODE: return node.outerHTML;
|
||||||
case Node.ATTRIBUTE_NODE: return node.value;
|
case node.ATTRIBUTE_NODE: return node.value;
|
||||||
case Node.COMMENT_NODE: return node.data;
|
case node.TEXT_NODE: return node.wholeText;
|
||||||
case Node.TEXT_NODE: return node.wholeText;
|
case node.COMMENT_NODE: return node.data;
|
||||||
case Node.DOCUMENT_NODE: return node.outerHTML;
|
case node.DOCUMENT_NODE: return node.outerHTML;
|
||||||
default: throw new Error("Unknown Node Type: " + node.nodeType);
|
default: throw new Error("Unknown Node Type: " + node.nodeType);
|
||||||
}
|
}*/
|
||||||
};
|
};
|
||||||
|
|
||||||
return Array.apply(null, Array(result.length))
|
return result
|
||||||
.map(function(_, i) {
|
|
||||||
return result[i];
|
|
||||||
})
|
|
||||||
.map(nodeToString)
|
.map(nodeToString)
|
||||||
.join(delimiter);
|
.join(delimiter);
|
||||||
},
|
},
|
||||||
|
@ -418,9 +418,9 @@ const Compress = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileSize = Utils.padLeft(input.length.toString(8), 11, "0");
|
const fileSize = input.length.toString(8).padStart(11, "0");
|
||||||
const currentUnixTimestamp = Math.floor(Date.now() / 1000);
|
const currentUnixTimestamp = Math.floor(Date.now() / 1000);
|
||||||
const lastModTime = Utils.padLeft(currentUnixTimestamp.toString(8), 11, "0");
|
const lastModTime = currentUnixTimestamp.toString(8).padStart(11, "0");
|
||||||
|
|
||||||
const file = {
|
const file = {
|
||||||
fileName: Utils.padBytesRight(args[0], 100),
|
fileName: Utils.padBytesRight(args[0], 100),
|
||||||
@ -452,7 +452,7 @@ const Compress = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checksum = Utils.padBytesRight(Utils.padLeft(checksum.toString(8), 7, "0"), 8);
|
checksum = Utils.padBytesRight(checksum.toString(8).padStart(7, "0"), 8);
|
||||||
file.checksum = checksum;
|
file.checksum = checksum;
|
||||||
|
|
||||||
const tarball = new Tarball();
|
const tarball = new Tarball();
|
||||||
|
@ -60,17 +60,16 @@ const Convert = {
|
|||||||
/**
|
/**
|
||||||
* Convert distance operation.
|
* Convert distance operation.
|
||||||
*
|
*
|
||||||
* @param {number} input
|
* @param {BigNumber} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {BigNumber}
|
||||||
*/
|
*/
|
||||||
runDistance: function (input, args) {
|
runDistance: function (input, args) {
|
||||||
let inputUnits = args[0],
|
let inputUnits = args[0],
|
||||||
outputUnits = args[1];
|
outputUnits = args[1];
|
||||||
|
|
||||||
input = input * Convert.DISTANCE_FACTOR[inputUnits];
|
input = input.mul(Convert.DISTANCE_FACTOR[inputUnits]);
|
||||||
return input / Convert.DISTANCE_FACTOR[outputUnits];
|
return input.div(Convert.DISTANCE_FACTOR[outputUnits]);
|
||||||
// TODO Remove rounding errors (e.g. 1.000000000001)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -141,16 +140,16 @@ const Convert = {
|
|||||||
/**
|
/**
|
||||||
* Convert data units operation.
|
* Convert data units operation.
|
||||||
*
|
*
|
||||||
* @param {number} input
|
* @param {BigNumber} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {BigNumber}
|
||||||
*/
|
*/
|
||||||
runDataSize: function (input, args) {
|
runDataSize: function (input, args) {
|
||||||
let inputUnits = args[0],
|
let inputUnits = args[0],
|
||||||
outputUnits = args[1];
|
outputUnits = args[1];
|
||||||
|
|
||||||
input = input * Convert.DATA_FACTOR[inputUnits];
|
input = input.mul(Convert.DATA_FACTOR[inputUnits]);
|
||||||
return input / Convert.DATA_FACTOR[outputUnits];
|
return input.div(Convert.DATA_FACTOR[outputUnits]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -221,16 +220,16 @@ const Convert = {
|
|||||||
/**
|
/**
|
||||||
* Convert area operation.
|
* Convert area operation.
|
||||||
*
|
*
|
||||||
* @param {number} input
|
* @param {BigNumber} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {BigNumber}
|
||||||
*/
|
*/
|
||||||
runArea: function (input, args) {
|
runArea: function (input, args) {
|
||||||
let inputUnits = args[0],
|
let inputUnits = args[0],
|
||||||
outputUnits = args[1];
|
outputUnits = args[1];
|
||||||
|
|
||||||
input = input * Convert.AREA_FACTOR[inputUnits];
|
input = input.mul(Convert.AREA_FACTOR[inputUnits]);
|
||||||
return input / Convert.AREA_FACTOR[outputUnits];
|
return input.div(Convert.AREA_FACTOR[outputUnits]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -332,16 +331,16 @@ const Convert = {
|
|||||||
/**
|
/**
|
||||||
* Convert mass operation.
|
* Convert mass operation.
|
||||||
*
|
*
|
||||||
* @param {number} input
|
* @param {BigNumber} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {BigNumber}
|
||||||
*/
|
*/
|
||||||
runMass: function (input, args) {
|
runMass: function (input, args) {
|
||||||
let inputUnits = args[0],
|
let inputUnits = args[0],
|
||||||
outputUnits = args[1];
|
outputUnits = args[1];
|
||||||
|
|
||||||
input = input * Convert.MASS_FACTOR[inputUnits];
|
input = input.mul(Convert.MASS_FACTOR[inputUnits]);
|
||||||
return input / Convert.MASS_FACTOR[outputUnits];
|
return input.div(Convert.MASS_FACTOR[outputUnits]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -397,16 +396,16 @@ const Convert = {
|
|||||||
/**
|
/**
|
||||||
* Convert speed operation.
|
* Convert speed operation.
|
||||||
*
|
*
|
||||||
* @param {number} input
|
* @param {BigNumber} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {BigNumber}
|
||||||
*/
|
*/
|
||||||
runSpeed: function (input, args) {
|
runSpeed: function (input, args) {
|
||||||
let inputUnits = args[0],
|
let inputUnits = args[0],
|
||||||
outputUnits = args[1];
|
outputUnits = args[1];
|
||||||
|
|
||||||
input = input * Convert.SPEED_FACTOR[inputUnits];
|
input = input.mul(Convert.SPEED_FACTOR[inputUnits]);
|
||||||
return input / Convert.SPEED_FACTOR[outputUnits];
|
return input.div(Convert.SPEED_FACTOR[outputUnits]);
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -81,22 +81,23 @@ const Entropy = {
|
|||||||
/**
|
/**
|
||||||
* Frequency distribution operation.
|
* Frequency distribution operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
runFreqDistrib: function (input, args) {
|
runFreqDistrib: function (input, args) {
|
||||||
if (!input.length) return "No data";
|
const data = new Uint8Array(input);
|
||||||
|
if (!data.length) return "No data";
|
||||||
|
|
||||||
let distrib = new Array(256).fill(0),
|
let distrib = new Array(256).fill(0),
|
||||||
percentages = new Array(256),
|
percentages = new Array(256),
|
||||||
len = input.length,
|
len = data.length,
|
||||||
showZeroes = args[0],
|
showZeroes = args[0],
|
||||||
i;
|
i;
|
||||||
|
|
||||||
// Count bytes
|
// Count bytes
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
distrib[input[i]]++;
|
distrib[data[i]]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate percentages
|
// Calculate percentages
|
||||||
@ -126,7 +127,7 @@ const Entropy = {
|
|||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (distrib[i] || showZeroes) {
|
if (distrib[i] || showZeroes) {
|
||||||
output += " " + Utils.hex(i, 2) + " (" +
|
output += " " + Utils.hex(i, 2) + " (" +
|
||||||
Utils.padRight(percentages[i].toFixed(2).replace(".00", "") + "%)", 8) +
|
(percentages[i].toFixed(2).replace(".00", "") + "%)").padEnd(8, " ") +
|
||||||
Array(Math.ceil(percentages[i])+1).join("|") + "\n";
|
Array(Math.ceil(percentages[i])+1).join("|") + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,6 +136,32 @@ const Entropy = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chi Square operation.
|
||||||
|
*
|
||||||
|
* @param {ArrayBuffer} data
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
runChiSq: function(input, args) {
|
||||||
|
const data = new Uint8Array(input);
|
||||||
|
let distArray = new Array(256).fill(0),
|
||||||
|
total = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
distArray[data[i]]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < distArray.length; i++) {
|
||||||
|
if (distArray[i] > 0) {
|
||||||
|
total += Math.pow(distArray[i] - data.length / 256, 2) / (data.length / 256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the Shannon entropy for a given chunk of data.
|
* Calculates the Shannon entropy for a given chunk of data.
|
||||||
*
|
*
|
||||||
|
@ -15,12 +15,13 @@ const FileType = {
|
|||||||
/**
|
/**
|
||||||
* Detect File Type operation.
|
* Detect File Type operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runDetect: function(input, args) {
|
runDetect: function(input, args) {
|
||||||
const type = FileType.magicType(input);
|
const data = new Uint8Array(input),
|
||||||
|
type = FileType.magicType(data);
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
return "Unknown file type. Have you tried checking the entropy of this data to determine whether it might be encrypted or compressed?";
|
return "Unknown file type. Have you tried checking the entropy of this data to determine whether it might be encrypted or compressed?";
|
||||||
@ -46,20 +47,21 @@ const FileType = {
|
|||||||
/**
|
/**
|
||||||
* Scan for Embedded Files operation.
|
* Scan for Embedded Files operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runScanForEmbeddedFiles: function(input, args) {
|
runScanForEmbeddedFiles: function(input, args) {
|
||||||
let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any suffiently long file is likely to contain these magic bytes coincidentally.\n",
|
let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any suffiently long file is likely to contain these magic bytes coincidentally.\n",
|
||||||
type,
|
type,
|
||||||
ignoreCommon = args[0],
|
|
||||||
commonExts = ["ico", "ttf", ""],
|
|
||||||
numFound = 0,
|
numFound = 0,
|
||||||
numCommonFound = 0;
|
numCommonFound = 0;
|
||||||
|
const ignoreCommon = args[0],
|
||||||
|
commonExts = ["ico", "ttf", ""],
|
||||||
|
data = new Uint8Array(input);
|
||||||
|
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
type = FileType.magicType(input.slice(i));
|
type = FileType.magicType(data.slice(i));
|
||||||
if (type) {
|
if (type) {
|
||||||
if (ignoreCommon && commonExts.indexOf(type.ext) > -1) {
|
if (ignoreCommon && commonExts.indexOf(type.ext) > -1) {
|
||||||
numCommonFound++;
|
numCommonFound++;
|
||||||
@ -96,7 +98,7 @@ const FileType = {
|
|||||||
* Given a buffer, detects magic byte sequences at specific positions and returns the
|
* Given a buffer, detects magic byte sequences at specific positions and returns the
|
||||||
* extension and mime type.
|
* extension and mime type.
|
||||||
*
|
*
|
||||||
* @param {byteArray} buf
|
* @param {Uint8Array} buf
|
||||||
* @returns {Object} type
|
* @returns {Object} type
|
||||||
* @returns {string} type.ext - File extension
|
* @returns {string} type.ext - File extension
|
||||||
* @returns {string} type.mime - Mime type
|
* @returns {string} type.mime - Mime type
|
||||||
|
@ -215,9 +215,9 @@ const HTML = {
|
|||||||
k = k.toFixed(2);
|
k = k.toFixed(2);
|
||||||
|
|
||||||
let hex = "#" +
|
let hex = "#" +
|
||||||
Utils.padLeft(Math.round(r).toString(16), 2) +
|
Math.round(r).toString(16).padStart(2, "0") +
|
||||||
Utils.padLeft(Math.round(g).toString(16), 2) +
|
Math.round(g).toString(16).padStart(2, "0") +
|
||||||
Utils.padLeft(Math.round(b).toString(16), 2),
|
Math.round(b).toString(16).padStart(2, "0"),
|
||||||
rgb = "rgb(" + r + ", " + g + ", " + b + ")",
|
rgb = "rgb(" + r + ", " + g + ", " + b + ")",
|
||||||
rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")",
|
rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")",
|
||||||
hsl = "hsl(" + h + ", " + s + "%, " + l + "%)",
|
hsl = "hsl(" + h + ", " + s + "%, " + l + "%)",
|
||||||
|
@ -16,6 +16,22 @@ import Checksum from "./Checksum.js";
|
|||||||
*/
|
*/
|
||||||
const Hash = {
|
const Hash = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic hash function.
|
||||||
|
*
|
||||||
|
* @param {string} name
|
||||||
|
* @param {string} input
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
runHash: function(name, input) {
|
||||||
|
const hasher = CryptoApi.hasher(name);
|
||||||
|
hasher.state.message = input;
|
||||||
|
hasher.state.length += input.length;
|
||||||
|
hasher.process();
|
||||||
|
return hasher.finalize().stringify("hex");
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MD2 operation.
|
* MD2 operation.
|
||||||
*
|
*
|
||||||
@ -24,7 +40,7 @@ const Hash = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runMD2: function (input, args) {
|
runMD2: function (input, args) {
|
||||||
return CryptoApi.hash("md2", input, {}).stringify("hex");
|
return Hash.runHash("md2", input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +52,7 @@ const Hash = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runMD4: function (input, args) {
|
runMD4: function (input, args) {
|
||||||
return CryptoApi.hash("md4", input, {}).stringify("hex");
|
return Hash.runHash("md4", input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -48,7 +64,7 @@ const Hash = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runMD5: function (input, args) {
|
runMD5: function (input, args) {
|
||||||
return CryptoApi.hash("md5", input, {}).stringify("hex");
|
return Hash.runHash("md5", input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -92,7 +108,7 @@ const Hash = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runSHA0: function (input, args) {
|
runSHA0: function (input, args) {
|
||||||
return CryptoApi.hash("sha0", input, {}).stringify("hex");
|
return Hash.runHash("sha0", input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +120,7 @@ const Hash = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runSHA1: function (input, args) {
|
runSHA1: function (input, args) {
|
||||||
return CryptoApi.hash("sha1", input, {}).stringify("hex");
|
return Hash.runHash("sha1", input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -123,7 +139,7 @@ const Hash = {
|
|||||||
*/
|
*/
|
||||||
runSHA2: function (input, args) {
|
runSHA2: function (input, args) {
|
||||||
const size = args[0];
|
const size = args[0];
|
||||||
return CryptoApi.hash("sha" + size, input, {}).stringify("hex");
|
return Hash.runHash("sha" + size, input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -259,7 +275,7 @@ const Hash = {
|
|||||||
*/
|
*/
|
||||||
runRIPEMD: function (input, args) {
|
runRIPEMD: function (input, args) {
|
||||||
const size = args[0];
|
const size = args[0];
|
||||||
return CryptoApi.hash("ripemd" + size, input, {}).stringify("hex");
|
return Hash.runHash("ripemd" + size, input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -271,7 +287,7 @@ const Hash = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runHAS: function (input, args) {
|
runHAS: function (input, args) {
|
||||||
return CryptoApi.hash("has160", input, {}).stringify("hex");
|
return Hash.runHash("has160", input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -290,7 +306,7 @@ const Hash = {
|
|||||||
*/
|
*/
|
||||||
runWhirlpool: function (input, args) {
|
runWhirlpool: function (input, args) {
|
||||||
const variant = args[0].toLowerCase();
|
const variant = args[0].toLowerCase();
|
||||||
return CryptoApi.hash(variant, input, {}).stringify("hex");
|
return Hash.runHash(variant, input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -315,7 +331,7 @@ const Hash = {
|
|||||||
runSnefru: function (input, args) {
|
runSnefru: function (input, args) {
|
||||||
const rounds = args[0],
|
const rounds = args[0],
|
||||||
size = args[1];
|
size = args[1];
|
||||||
return CryptoApi.hash(`snefru-${rounds}-${size}`, input, {}).stringify("hex");
|
return Hash.runHash(`snefru-${rounds}-${size}`, input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,18 +31,19 @@ const Hexdump = {
|
|||||||
/**
|
/**
|
||||||
* To Hexdump operation.
|
* To Hexdump operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runTo: function(input, args) {
|
runTo: function(input, args) {
|
||||||
|
const data = new Uint8Array(input);
|
||||||
const length = args[0] || Hexdump.WIDTH;
|
const length = args[0] || Hexdump.WIDTH;
|
||||||
const upperCase = args[1];
|
const upperCase = args[1];
|
||||||
const includeFinalLength = args[2];
|
const includeFinalLength = args[2];
|
||||||
|
|
||||||
let output = "", padding = 2;
|
let output = "", padding = 2;
|
||||||
for (let i = 0; i < input.length; i += length) {
|
for (let i = 0; i < data.length; i += length) {
|
||||||
const buff = input.slice(i, i+length);
|
const buff = data.slice(i, i+length);
|
||||||
let hexa = "";
|
let hexa = "";
|
||||||
for (let j = 0; j < buff.length; j++) {
|
for (let j = 0; j < buff.length; j++) {
|
||||||
hexa += Utils.hex(buff[j], padding) + " ";
|
hexa += Utils.hex(buff[j], padding) + " ";
|
||||||
@ -56,10 +57,10 @@ const Hexdump = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
output += lineNo + " " +
|
output += lineNo + " " +
|
||||||
Utils.padRight(hexa, (length*(padding+1))) +
|
hexa.padEnd(length*(padding+1), " ") +
|
||||||
" |" + Utils.padRight(Utils.printable(Utils.byteArrayToChars(buff)), buff.length) + "|\n";
|
" |" + Utils.printable(Utils.byteArrayToChars(buff)).padEnd(buff.length, " ") + "|\n";
|
||||||
|
|
||||||
if (includeFinalLength && i+buff.length === input.length) {
|
if (includeFinalLength && i+buff.length === data.length) {
|
||||||
output += Utils.hex(i+buff.length, 8) + "\n";
|
output += Utils.hex(i+buff.length, 8) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,13 @@ const Image = {
|
|||||||
*
|
*
|
||||||
* Extracts EXIF data from a byteArray, representing a JPG or a TIFF image.
|
* Extracts EXIF data from a byteArray, representing a JPG or a TIFF image.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runExtractEXIF(input, args) {
|
runExtractEXIF(input, args) {
|
||||||
try {
|
try {
|
||||||
const bytes = Uint8Array.from(input);
|
const parser = ExifParser.create(input);
|
||||||
const parser = ExifParser.create(bytes.buffer);
|
|
||||||
const result = parser.parse();
|
const result = parser.parse();
|
||||||
|
|
||||||
let lines = [];
|
let lines = [];
|
||||||
@ -53,7 +52,7 @@ const Image = {
|
|||||||
* @author David Moodie [davidmoodie12@gmail.com]
|
* @author David Moodie [davidmoodie12@gmail.com]
|
||||||
* @param {byteArray} input
|
* @param {byteArray} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {byteArray}
|
||||||
*/
|
*/
|
||||||
runRemoveEXIF(input, args) {
|
runRemoveEXIF(input, args) {
|
||||||
// Do nothing if input is empty
|
// Do nothing if input is empty
|
||||||
|
@ -26,10 +26,15 @@ const NetBIOS = {
|
|||||||
let output = [],
|
let output = [],
|
||||||
offset = args[0];
|
offset = args[0];
|
||||||
|
|
||||||
|
if (input.length <= 16) {
|
||||||
|
let len = input.length;
|
||||||
|
input.length = 16;
|
||||||
|
input.fill(32, len, 16);
|
||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
output.push((input[i] >> 4) + offset);
|
output.push((input[i] >> 4) + offset);
|
||||||
output.push((input[i] & 0xf) + offset);
|
output.push((input[i] & 0xf) + offset);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
@ -46,9 +51,15 @@ const NetBIOS = {
|
|||||||
let output = [],
|
let output = [],
|
||||||
offset = args[0];
|
offset = args[0];
|
||||||
|
|
||||||
|
if (input.length <= 32 && (input.length % 2) === 0) {
|
||||||
for (let i = 0; i < input.length; i += 2) {
|
for (let i = 0; i < input.length; i += 2) {
|
||||||
output.push(((input[i] - offset) << 4) |
|
output.push((((input[i] & 0xff) - offset) << 4) |
|
||||||
((input[i + 1] - offset) & 0xf));
|
(((input[i + 1] & 0xff) - offset) & 0xf));
|
||||||
|
}
|
||||||
|
for (let i = output.length - 1; i > 0; i--) {
|
||||||
|
if (output[i] === 32) output.splice(i, i);
|
||||||
|
else break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
@ -14,16 +14,72 @@ const Numberwang = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run: function(input, args) {
|
run: function(input, args) {
|
||||||
if (!input) return "Let's play Wangernumb!";
|
let output;
|
||||||
const match = input.match(/\d+/);
|
if (!input) {
|
||||||
|
output = "Let's play Wangernumb!";
|
||||||
|
} else {
|
||||||
|
const match = input.match(/(f0rty-s1x|shinty-six|filth-hundred and neeb|-?√?\d+(\.\d+)?i?([a-z]?)%?)/i);
|
||||||
if (match) {
|
if (match) {
|
||||||
return match[0] + "! That's Numberwang!";
|
if (match[3]) output = match[0] + "! That's AlphaNumericWang!";
|
||||||
|
else output = match[0] + "! That's Numberwang!";
|
||||||
} else {
|
} else {
|
||||||
// That's a bad miss!
|
// That's a bad miss!
|
||||||
return "Sorry, that's not Numberwang. Let's rotate the board!";
|
output = "Sorry, that's not Numberwang. Let's rotate the board!";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const rand = Math.floor(Math.random() * Numberwang._didYouKnow.length);
|
||||||
|
return output + "\n\nDid you know: " + Numberwang._didYouKnow[rand];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Taken from http://numberwang.wikia.com/wiki/Numberwang_Wikia
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @constant
|
||||||
|
*/
|
||||||
|
_didYouKnow: [
|
||||||
|
"Numberwang, contrary to popular belief, is a fruit and not a vegetable.",
|
||||||
|
"Robert Webb once got WordWang while presenting an episode of Numberwang.",
|
||||||
|
"The 6705th digit of pi is Numberwang.",
|
||||||
|
"Numberwang was invented on a Sevenday.",
|
||||||
|
"Contrary to popular belief, Albert Einstein always got good grades in Numberwang at school. He once scored ^4$ on a test.",
|
||||||
|
"680 asteroids have been named after Numberwang.",
|
||||||
|
"Archimedes is most famous for proclaiming \"That's Numberwang!\" during an epiphany about water displacement he had while taking a bath.",
|
||||||
|
"Numberwang Day is celebrated in Japan on every day of the year apart from June 6.",
|
||||||
|
"Biologists recently discovered Numberwang within a strand of human DNA.",
|
||||||
|
"Numbernot is a special type of non-Numberwang number. It is divisible by 3 and the letter \"y\".",
|
||||||
|
"Julie once got 612.04 Numberwangs in a single episode of Emmerdale.",
|
||||||
|
"In India, it is traditional to shout out \"Numberwang!\" instead of checkmate during games of chess.",
|
||||||
|
"There is a rule on Countdown which states that if you get Numberwang in the numbers round, you automatically win. It has only ever been invoked twice.",
|
||||||
|
"\"Numberwang\" was the third-most common baby name for a brief period in 1722.",
|
||||||
|
"\"The Lion King\" was loosely based on Numberwang.",
|
||||||
|
"\"A Numberwang a day keeps the doctor away\" is how Donny Cosy, the oldest man in the world, explained how he was in such good health at the age of 136.",
|
||||||
|
"The \"number lock\" button on a keyboard is based on the popular round of the same name in \"Numberwang\".",
|
||||||
|
"Cambridge became the first university to offer a course in Numberwang in 1567.",
|
||||||
|
"Schrödinger's Numberwang is a number that has been confusing dentists for centuries.",
|
||||||
|
"\"Harry Potter and the Numberwang of Numberwang\" was rejected by publishers -41 times before it became a bestseller.",
|
||||||
|
"\"Numberwang\" is the longest-running British game show in history; it has aired 226 seasons, each containing 19 episodes, which makes a grand total of 132 episodes.",
|
||||||
|
"The triple Numberwang bonus was discovered by archaeologist Thomas Jefferson in Somerset.",
|
||||||
|
"Numberwang is illegal in parts of Czechoslovakia.",
|
||||||
|
"Numberwang was discovered in India in the 12th century.",
|
||||||
|
"Numberwang has the chemical formula Zn4SO2(HgEs)3.",
|
||||||
|
"The first pack of cards ever created featured two \"Numberwang\" cards instead of jokers.",
|
||||||
|
"Julius Caesar was killed by an overdose of Numberwang.",
|
||||||
|
"The most Numberwang musical note is G#.",
|
||||||
|
"In 1934, the forty-third Google Doodle promoted the upcoming television show \"Numberwang on Ice\".",
|
||||||
|
"A recent psychology study found that toddlers were 17% faster at identifying numbers which were Numberwang.",
|
||||||
|
"There are 700 ways to commit a foul in the television show \"Numberwang\". All 700 of these fouls were committed by Julie in one single episode in 1473.",
|
||||||
|
"Astronomers suspect God is Numberwang.",
|
||||||
|
"Numberwang is the official beverage of Canada.",
|
||||||
|
"In the pilot episode of \"The Price is Right\", if a contestant got the value of an item exactly right they were told \"That's Numberwang!\" and immediately won ₹5.7032.",
|
||||||
|
"The first person to get three Numberwangs in a row was Madonna.",
|
||||||
|
"\"Numberwang\" has the code U+46402 in Unicode.",
|
||||||
|
"The musical note \"Numberwang\" is between D# and E♮.",
|
||||||
|
"Numberwang was first played on the moon in 1834.",
|
||||||
|
],
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Numberwang;
|
export default Numberwang;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import otp from "otp";
|
import otp from "otp";
|
||||||
import Base64 from "./Base64.js";
|
import Base64 from "./Base64.js";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One-Time Password operations.
|
* One-Time Password operations.
|
||||||
*
|
*
|
||||||
|
@ -11,6 +11,7 @@ const KEY_TYPES = ["RSA", "ECC"];
|
|||||||
* PGP operations.
|
* PGP operations.
|
||||||
*
|
*
|
||||||
* @author tlwr [toby@toby.codes]
|
* @author tlwr [toby@toby.codes]
|
||||||
|
* @author Matt C [matt@artemisbot.uk]
|
||||||
* @copyright Crown Copyright 2016
|
* @copyright Crown Copyright 2016
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*
|
*
|
||||||
@ -21,10 +22,12 @@ const PGP = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate PGP Key Size
|
* Validate PGP Key Size
|
||||||
|
*
|
||||||
|
* @private
|
||||||
* @param {string} keySize
|
* @param {string} keySize
|
||||||
* @returns {Integer}
|
* @returns {Integer}
|
||||||
*/
|
*/
|
||||||
validateKeySize(keySize, keyType) {
|
_validateKeySize(keySize, keyType) {
|
||||||
if (KEY_SIZES.indexOf(keySize) < 0) {
|
if (KEY_SIZES.indexOf(keySize) < 0) {
|
||||||
throw `Invalid key size ${keySize}, must be in ${JSON.stringify(KEY_SIZES)}`;
|
throw `Invalid key size ${keySize}, must be in ${JSON.stringify(KEY_SIZES)}`;
|
||||||
}
|
}
|
||||||
@ -46,10 +49,12 @@ const PGP = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get size of subkey
|
* Get size of subkey
|
||||||
|
*
|
||||||
|
* @private
|
||||||
* @param {Integer} keySize
|
* @param {Integer} keySize
|
||||||
* @returns {Integer}
|
* @returns {Integer}
|
||||||
*/
|
*/
|
||||||
getSubkeySize(keySize) {
|
_getSubkeySize(keySize) {
|
||||||
return {
|
return {
|
||||||
1024: 1024,
|
1024: 1024,
|
||||||
2048: 1024,
|
2048: 1024,
|
||||||
@ -64,18 +69,65 @@ const PGP = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate PGP Key Type
|
* Validate PGP Key Type
|
||||||
|
*
|
||||||
|
* @private
|
||||||
* @param {string} keyType
|
* @param {string} keyType
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
validateKeyType(keyType) {
|
_validateKeyType(keyType) {
|
||||||
if (KEY_TYPES.indexOf(keyType) >= 0) return keyType.toLowerCase();
|
if (KEY_TYPES.indexOf(keyType) >= 0) return keyType.toLowerCase();
|
||||||
throw `Invalid key type ${keyType}, must be in ${JSON.stringify(KEY_TYPES)}`;
|
throw `Invalid key type ${keyType}, must be in ${JSON.stringify(KEY_TYPES)}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import private key and unlock if necessary
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} privateKey
|
||||||
|
* @param {string} [passphrase]
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
async _importPrivateKey (privateKey, passphrase) {
|
||||||
|
try {
|
||||||
|
const key = await promisify(kbpgp.KeyManager.import_from_armored_pgp)({
|
||||||
|
armored: privateKey,
|
||||||
|
});
|
||||||
|
if (key.is_pgp_locked() && passphrase) {
|
||||||
|
if (passphrase) {
|
||||||
|
await promisify(key.unlock_pgp, key)({
|
||||||
|
passphrase
|
||||||
|
});
|
||||||
|
} else if (!passphrase) {
|
||||||
|
throw "Did not provide passphrase with locked private key.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return key;
|
||||||
|
} catch (err) {
|
||||||
|
throw `Could not import private key: ${err}`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import public key
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} publicKey
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
async _importPublicKey (publicKey) {
|
||||||
|
try {
|
||||||
|
const key = await promisify(kbpgp.KeyManager.import_from_armored_pgp)({
|
||||||
|
armored: publicKey,
|
||||||
|
});
|
||||||
|
return key;
|
||||||
|
} catch (err) {
|
||||||
|
throw `Could not import public key: ${err}`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate PGP Key Pair operation.
|
* Generate PGP Key Pair operation.
|
||||||
*
|
*
|
||||||
* @author tlwr [toby@toby.codes]
|
|
||||||
* @param {string} input
|
* @param {string} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@ -87,8 +139,8 @@ const PGP = {
|
|||||||
name = args[3],
|
name = args[3],
|
||||||
email = args[4];
|
email = args[4];
|
||||||
|
|
||||||
keyType = PGP.validateKeyType(keyType);
|
keyType = PGP._validateKeyType(keyType);
|
||||||
keySize = PGP.validateKeySize(keySize, keyType);
|
keySize = PGP._validateKeySize(keySize, keyType);
|
||||||
|
|
||||||
let userIdentifier = "";
|
let userIdentifier = "";
|
||||||
if (name) userIdentifier += name;
|
if (name) userIdentifier += name;
|
||||||
@ -109,11 +161,11 @@ const PGP = {
|
|||||||
expire_in: 0
|
expire_in: 0
|
||||||
},
|
},
|
||||||
subkeys: [{
|
subkeys: [{
|
||||||
nbits: PGP.getSubkeySize(keySize),
|
nbits: PGP._getSubkeySize(keySize),
|
||||||
flags: kbpgp.const.openpgp.sign_data,
|
flags: kbpgp.const.openpgp.sign_data,
|
||||||
expire_in: 86400 * 365 * 8
|
expire_in: 86400 * 365 * 8
|
||||||
}, {
|
}, {
|
||||||
nbits: PGP.getSubkeySize(keySize),
|
nbits: PGP._getSubkeySize(keySize),
|
||||||
flags: kbpgp.const.openpgp.encrypt_comm | kbpgp.const.openpgp.encrypt_storage,
|
flags: kbpgp.const.openpgp.encrypt_comm | kbpgp.const.openpgp.encrypt_storage,
|
||||||
expire_in: 86400 * 365 * 2
|
expire_in: 86400 * 365 * 2
|
||||||
}],
|
}],
|
||||||
@ -134,6 +186,13 @@ const PGP = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PGP Encrypt operation.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
async runEncrypt(input, args) {
|
async runEncrypt(input, args) {
|
||||||
let plaintextMessage = input,
|
let plaintextMessage = input,
|
||||||
plainPubKey = args[0];
|
plainPubKey = args[0];
|
||||||
@ -145,7 +204,6 @@ const PGP = {
|
|||||||
armored: plainPubKey,
|
armored: plainPubKey,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
|
||||||
throw `Could not import public key: ${err}`;
|
throw `Could not import public key: ${err}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,30 +213,27 @@ const PGP = {
|
|||||||
encrypt_for: key,
|
encrypt_for: key,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
throw `Couldn't encrypt message with provided public key: ${err}`;
|
||||||
throw `Could encrypt message to provided public key: ${err}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(encryptedMessage);
|
return encryptedMessage.toString();
|
||||||
|
|
||||||
return encryptedMessage;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PGP Decrypt operation.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
async runDecrypt(input, args) {
|
async runDecrypt(input, args) {
|
||||||
let encryptedMessage = input,
|
let encryptedMessage = input,
|
||||||
plainPrivateKey = args[0],
|
privateKey = args[0],
|
||||||
|
passphrase = args[1],
|
||||||
keyring = new kbpgp.keyring.KeyRing();
|
keyring = new kbpgp.keyring.KeyRing();
|
||||||
|
|
||||||
let key, plaintextMessage;
|
let plaintextMessage;
|
||||||
|
const key = await PGP._importPrivateKey(privateKey, passphrase);
|
||||||
try {
|
|
||||||
key = await promisify(kbpgp.KeyManager.import_from_armored_pgp)({
|
|
||||||
armored: plainPrivateKey,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
throw `Could not import private key: ${err}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
keyring.add_key_manager(key);
|
keyring.add_key_manager(key);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -187,10 +242,97 @@ const PGP = {
|
|||||||
keyfetch: keyring,
|
keyfetch: keyring,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw `Could decrypt message to provided private key: ${err}`;
|
throw `Couldn't decrypt message with provided private key: ${err}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return plaintextMessage;
|
return plaintextMessage.toString();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PGP Sign Message operation.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
async runSign(input, args) {
|
||||||
|
let message = input,
|
||||||
|
privateKey = args[0],
|
||||||
|
passphrase = args[1],
|
||||||
|
publicKey = args[2];
|
||||||
|
|
||||||
|
let signedMessage;
|
||||||
|
const privKey = await PGP._importPrivateKey(privateKey, passphrase);
|
||||||
|
const pubKey = await PGP._importPublicKey(publicKey);
|
||||||
|
|
||||||
|
try {
|
||||||
|
signedMessage = await promisify(kbpgp.box)({
|
||||||
|
msg: message,
|
||||||
|
encrypt_for: pubKey,
|
||||||
|
sign_with: privKey
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
throw `Couldn't sign message: ${err}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return signedMessage;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PGP Verify Message operation.
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
async runVerify(input, args) {
|
||||||
|
let signedMessage = input,
|
||||||
|
publicKey = args[0],
|
||||||
|
privateKey = args[1],
|
||||||
|
passphrase = args[2],
|
||||||
|
keyring = new kbpgp.keyring.KeyRing();
|
||||||
|
|
||||||
|
let unboxedLiterals;
|
||||||
|
const privKey = await PGP._importPrivateKey(privateKey, passphrase);
|
||||||
|
const pubKey = await PGP._importPublicKey(publicKey);
|
||||||
|
keyring.add_key_manager(privKey);
|
||||||
|
keyring.add_key_manager(pubKey);
|
||||||
|
|
||||||
|
try {
|
||||||
|
unboxedLiterals = await promisify(kbpgp.unbox)({
|
||||||
|
armored: signedMessage,
|
||||||
|
keyfetch: keyring
|
||||||
|
});
|
||||||
|
const ds = unboxedLiterals[0].get_data_signer();
|
||||||
|
if (ds) {
|
||||||
|
const km = ds.get_key_manager();
|
||||||
|
if (km) {
|
||||||
|
const signer = km.get_userids_mark_primary()[0].components;
|
||||||
|
let text = "Signed by ";
|
||||||
|
if (signer.email || signer.username || signer.comment) {
|
||||||
|
if (signer.username) {
|
||||||
|
text += `${signer.username} `;
|
||||||
|
}
|
||||||
|
if (signer.comment) {
|
||||||
|
text += `${signer.comment} `;
|
||||||
|
}
|
||||||
|
if (signer.email) {
|
||||||
|
text += `<${signer.email}>`;
|
||||||
|
}
|
||||||
|
text += "\n";
|
||||||
|
}
|
||||||
|
text += [
|
||||||
|
`PGP fingerprint: ${km.get_pgp_fingerprint().toString("hex")}`,
|
||||||
|
`Signed on ${new Date(ds.sig.hashed_subpackets[0].time * 1000).toUTCString()}`,
|
||||||
|
"----------------------------------\n"
|
||||||
|
].join("\n");
|
||||||
|
text += unboxedLiterals.toString();
|
||||||
|
return text.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw `Couldn't verify message: ${err}`;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
160
src/core/operations/PHP.js
Normal file
160
src/core/operations/PHP.js
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/**
|
||||||
|
* PHP operations.
|
||||||
|
*
|
||||||
|
* @author Jarmo van Lenthe [github.com/jarmovanlenthe]
|
||||||
|
* @copyright Jarmo van Lenthe
|
||||||
|
* @license Apache-2.0
|
||||||
|
*
|
||||||
|
* @namespace
|
||||||
|
*/
|
||||||
|
const PHP = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
OUTPUT_VALID_JSON: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP Deserialize operation.
|
||||||
|
*
|
||||||
|
* This Javascript implementation is based on the Python implementation by
|
||||||
|
* Armin Ronacher (2016), who released it under the 3-Clause BSD license.
|
||||||
|
* See: https://github.com/mitsuhiko/phpserialize/
|
||||||
|
*
|
||||||
|
* @param {string} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
runDeserialize: function (input, args) {
|
||||||
|
/**
|
||||||
|
* Recursive method for deserializing.
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
function handleInput() {
|
||||||
|
/**
|
||||||
|
* Read `length` characters from the input, shifting them out the input.
|
||||||
|
* @param length
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function read(length) {
|
||||||
|
let result = "";
|
||||||
|
for (let idx = 0; idx < length; idx++) {
|
||||||
|
let char = inputPart.shift();
|
||||||
|
if (char === undefined) {
|
||||||
|
throw "End of input reached before end of script";
|
||||||
|
}
|
||||||
|
result += char;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read characters from the input until `until` is found.
|
||||||
|
* @param until
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function readUntil(until) {
|
||||||
|
let result = "";
|
||||||
|
for (;;) {
|
||||||
|
let char = read(1);
|
||||||
|
if (char === until) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
result += char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read characters from the input that must be equal to `expect`
|
||||||
|
* @param expect
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function expect(expect) {
|
||||||
|
let result = read(expect.length);
|
||||||
|
if (result !== expect) {
|
||||||
|
throw "Unexpected input found";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to handle deserialized arrays.
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
function handleArray() {
|
||||||
|
let items = parseInt(readUntil(":"), 10) * 2;
|
||||||
|
expect("{");
|
||||||
|
let result = [];
|
||||||
|
let isKey = true;
|
||||||
|
let lastItem = null;
|
||||||
|
for (let idx = 0; idx < items; idx++) {
|
||||||
|
let item = handleInput();
|
||||||
|
if (isKey) {
|
||||||
|
lastItem = item;
|
||||||
|
isKey = false;
|
||||||
|
} else {
|
||||||
|
let numberCheck = lastItem.match(/[0-9]+/);
|
||||||
|
if (args[0] && numberCheck && numberCheck[0].length === lastItem.length) {
|
||||||
|
result.push("\"" + lastItem + "\": " + item);
|
||||||
|
} else {
|
||||||
|
result.push(lastItem + ": " + item);
|
||||||
|
}
|
||||||
|
isKey = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect("}");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let kind = read(1).toLowerCase();
|
||||||
|
|
||||||
|
switch (kind) {
|
||||||
|
case "n":
|
||||||
|
expect(";");
|
||||||
|
return "";
|
||||||
|
|
||||||
|
case "i":
|
||||||
|
case "d":
|
||||||
|
case "b": {
|
||||||
|
expect(":");
|
||||||
|
let data = readUntil(";");
|
||||||
|
if (kind === "b") {
|
||||||
|
return (parseInt(data, 10) !== 0);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "a":
|
||||||
|
expect(":");
|
||||||
|
return "{" + handleArray() + "}";
|
||||||
|
|
||||||
|
case "s": {
|
||||||
|
expect(":");
|
||||||
|
let length = readUntil(":");
|
||||||
|
expect("\"");
|
||||||
|
let value = read(length);
|
||||||
|
expect("\";");
|
||||||
|
if (args[0]) {
|
||||||
|
return "\"" + value.replace(/"/g, "\\\"") + "\"";
|
||||||
|
} else {
|
||||||
|
return "\"" + value + "\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw "Unknown type: " + kind;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let inputPart = input.split("");
|
||||||
|
return handleInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PHP;
|
@ -121,8 +121,7 @@ const PublicKey = {
|
|||||||
// Format Public Key fields
|
// Format Public Key fields
|
||||||
for (let i = 0; i < pkFields.length; i++) {
|
for (let i = 0; i < pkFields.length; i++) {
|
||||||
pkStr += " " + pkFields[i].key + ":" +
|
pkStr += " " + pkFields[i].key + ":" +
|
||||||
Utils.padLeft(
|
(pkFields[i].value + "\n").padStart(
|
||||||
pkFields[i].value + "\n",
|
|
||||||
18 - (pkFields[i].key.length + 3) + pkFields[i].value.length + 1,
|
18 - (pkFields[i].key.length + 3) + pkFields[i].value.length + 1,
|
||||||
" "
|
" "
|
||||||
);
|
);
|
||||||
@ -286,9 +285,9 @@ ${extensions}`;
|
|||||||
|
|
||||||
key = fields[i].split("=")[0];
|
key = fields[i].split("=")[0];
|
||||||
value = fields[i].split("=")[1];
|
value = fields[i].split("=")[1];
|
||||||
str = Utils.padRight(key, maxKeyLen) + " = " + value + "\n";
|
str = key.padEnd(maxKeyLen, " ") + " = " + value + "\n";
|
||||||
|
|
||||||
output += Utils.padLeft(str, indent + str.length, " ");
|
output += str.padStart(indent + str.length, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.slice(0, -1);
|
return output.slice(0, -1);
|
||||||
@ -314,7 +313,7 @@ ${extensions}`;
|
|||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
output += str;
|
output += str;
|
||||||
} else {
|
} else {
|
||||||
output += Utils.padLeft(str, indent + str.length, " ");
|
output += str.padStart(indent + str.length, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ const SeqUtils = {
|
|||||||
width = lines.length.toString().length;
|
width = lines.length.toString().length;
|
||||||
|
|
||||||
for (let n = 0; n < lines.length; n++) {
|
for (let n = 0; n < lines.length; n++) {
|
||||||
output += Utils.pad((n+1).toString(), width, " ") + " " + lines[n] + "\n";
|
output += (n+1).toString().padStart(width, " ") + " " + lines[n] + "\n";
|
||||||
}
|
}
|
||||||
return output.slice(0, output.length-1);
|
return output.slice(0, output.length-1);
|
||||||
},
|
},
|
||||||
@ -249,7 +249,7 @@ const SeqUtils = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return a.localeCompare(b);
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
import Utils from "../Utils.js";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tidy operations.
|
* Tidy operations.
|
||||||
*
|
*
|
||||||
@ -104,32 +101,39 @@ const Tidy = {
|
|||||||
/**
|
/**
|
||||||
* Drop bytes operation.
|
* Drop bytes operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byteArray}
|
* @returns {ArrayBuffer}
|
||||||
*/
|
*/
|
||||||
runDropBytes: function(input, args) {
|
runDropBytes: function(input, args) {
|
||||||
let start = args[0],
|
const start = args[0],
|
||||||
length = args[1],
|
length = args[1],
|
||||||
applyToEachLine = args[2];
|
applyToEachLine = args[2];
|
||||||
|
|
||||||
if (start < 0 || length < 0)
|
if (start < 0 || length < 0)
|
||||||
throw "Error: Invalid value";
|
throw "Error: Invalid value";
|
||||||
|
|
||||||
if (!applyToEachLine)
|
if (!applyToEachLine) {
|
||||||
return input.slice(0, start).concat(input.slice(start+length, input.length));
|
const left = input.slice(0, start),
|
||||||
|
right = input.slice(start + length, input.byteLength);
|
||||||
|
let result = new Uint8Array(left.byteLength + right.byteLength);
|
||||||
|
result.set(new Uint8Array(left), 0);
|
||||||
|
result.set(new Uint8Array(right), left.byteLength);
|
||||||
|
return result.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
// Split input into lines
|
// Split input into lines
|
||||||
|
const data = new Uint8Array(input);
|
||||||
let lines = [],
|
let lines = [],
|
||||||
line = [],
|
line = [],
|
||||||
i;
|
i;
|
||||||
|
|
||||||
for (i = 0; i < input.length; i++) {
|
for (i = 0; i < data.length; i++) {
|
||||||
if (input[i] === 0x0a) {
|
if (data[i] === 0x0a) {
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
line = [];
|
line = [];
|
||||||
} else {
|
} else {
|
||||||
line.push(input[i]);
|
line.push(data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
@ -139,7 +143,7 @@ const Tidy = {
|
|||||||
output = output.concat(lines[i].slice(0, start).concat(lines[i].slice(start+length, lines[i].length)));
|
output = output.concat(lines[i].slice(0, start).concat(lines[i].slice(start+length, lines[i].length)));
|
||||||
output.push(0x0a);
|
output.push(0x0a);
|
||||||
}
|
}
|
||||||
return output.slice(0, output.length-1);
|
return new Uint8Array(output.slice(0, output.length-1)).buffer;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -157,12 +161,12 @@ const Tidy = {
|
|||||||
/**
|
/**
|
||||||
* Take bytes operation.
|
* Take bytes operation.
|
||||||
*
|
*
|
||||||
* @param {byteArray} input
|
* @param {ArrayBuffer} input
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byteArray}
|
* @returns {ArrayBuffer}
|
||||||
*/
|
*/
|
||||||
runTakeBytes: function(input, args) {
|
runTakeBytes: function(input, args) {
|
||||||
let start = args[0],
|
const start = args[0],
|
||||||
length = args[1],
|
length = args[1],
|
||||||
applyToEachLine = args[2];
|
applyToEachLine = args[2];
|
||||||
|
|
||||||
@ -173,16 +177,17 @@ const Tidy = {
|
|||||||
return input.slice(start, start+length);
|
return input.slice(start, start+length);
|
||||||
|
|
||||||
// Split input into lines
|
// Split input into lines
|
||||||
|
const data = new Uint8Array(input);
|
||||||
let lines = [],
|
let lines = [],
|
||||||
line = [];
|
line = [],
|
||||||
let i;
|
i;
|
||||||
|
|
||||||
for (i = 0; i < input.length; i++) {
|
for (i = 0; i < data.length; i++) {
|
||||||
if (input[i] === 0x0a) {
|
if (data[i] === 0x0a) {
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
line = [];
|
line = [];
|
||||||
} else {
|
} else {
|
||||||
line.push(input[i]);
|
line.push(data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
@ -192,7 +197,7 @@ const Tidy = {
|
|||||||
output = output.concat(lines[i].slice(start, start+length));
|
output = output.concat(lines[i].slice(start, start+length));
|
||||||
output.push(0x0a);
|
output.push(0x0a);
|
||||||
}
|
}
|
||||||
return output.slice(0, output.length-1);
|
return new Uint8Array(output.slice(0, output.length-1)).buffer;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -229,11 +234,11 @@ const Tidy = {
|
|||||||
|
|
||||||
if (position === "Start") {
|
if (position === "Start") {
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (i = 0; i < lines.length; i++) {
|
||||||
output += Utils.padLeft(lines[i], lines[i].length+len, chr) + "\n";
|
output += lines[i].padStart(lines[i].length+len, chr) + "\n";
|
||||||
}
|
}
|
||||||
} else if (position === "End") {
|
} else if (position === "End") {
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (i = 0; i < lines.length; i++) {
|
||||||
output += Utils.padRight(lines[i], lines[i].length+len, chr) + "\n";
|
output += lines[i].padEnd(lines[i].length+len, chr) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* globals unescape */
|
/* globals unescape */
|
||||||
import Utils from "../Utils.js";
|
import url from "url";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,56 +58,36 @@ const URL_ = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runParse: function(input, args) {
|
runParse: function(input, args) {
|
||||||
if (!document) {
|
const uri = url.parse(input, true);
|
||||||
throw "This operation only works in a browser.";
|
|
||||||
}
|
|
||||||
|
|
||||||
const a = document.createElement("a");
|
|
||||||
|
|
||||||
// Overwrite base href which will be the current CyberChef URL to reduce confusion.
|
|
||||||
a.href = "http://example.com/";
|
|
||||||
a.href = input;
|
|
||||||
|
|
||||||
if (a.protocol) {
|
|
||||||
let output = "";
|
let output = "";
|
||||||
if (a.hostname !== window.location.hostname) {
|
|
||||||
output = "Protocol:\t" + a.protocol + "\n";
|
|
||||||
if (a.hostname) output += "Hostname:\t" + a.hostname + "\n";
|
|
||||||
if (a.port) output += "Port:\t\t" + a.port + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.pathname && a.pathname !== window.location.pathname) {
|
if (uri.protocol) output += "Protocol:\t" + uri.protocol + "\n";
|
||||||
let pathname = a.pathname;
|
if (uri.auth) output += "Auth:\t\t" + uri.auth + "\n";
|
||||||
if (pathname.indexOf(window.location.pathname) === 0)
|
if (uri.hostname) output += "Hostname:\t" + uri.hostname + "\n";
|
||||||
pathname = pathname.replace(window.location.pathname, "");
|
if (uri.port) output += "Port:\t\t" + uri.port + "\n";
|
||||||
if (pathname)
|
if (uri.pathname) output += "Path name:\t" + uri.pathname + "\n";
|
||||||
output += "Path name:\t" + pathname + "\n";
|
if (uri.query) {
|
||||||
}
|
let keys = Object.keys(uri.query),
|
||||||
|
padding = 0;
|
||||||
|
|
||||||
if (a.hash && a.hash !== window.location.hash) {
|
keys.forEach(k => {
|
||||||
output += "Hash:\t\t" + a.hash + "\n";
|
padding = (k.length > padding) ? k.length : padding;
|
||||||
}
|
});
|
||||||
|
|
||||||
if (a.search && a.search !== window.location.search) {
|
|
||||||
output += "Arguments:\n";
|
output += "Arguments:\n";
|
||||||
const args_ = (a.search.slice(1, a.search.length)).split("&");
|
for (let key in uri.query) {
|
||||||
let splitArgs = [], padding = 0, i;
|
output += "\t" + key.padEnd(padding, " ");
|
||||||
for (i = 0; i < args_.length; i++) {
|
if (uri.query[key].length) {
|
||||||
splitArgs.push(args_[i].split("="));
|
output += " = " + uri.query[key] + "\n";
|
||||||
padding = (splitArgs[i][0].length > padding) ? splitArgs[i][0].length : padding;
|
} else {
|
||||||
}
|
output += "\n";
|
||||||
for (i = 0; i < splitArgs.length; i++) {
|
|
||||||
output += "\t" + Utils.padRight(splitArgs[i][0], padding);
|
|
||||||
if (splitArgs[i].length > 1 && splitArgs[i][1].length)
|
|
||||||
output += " = " + splitArgs[i][1] + "\n";
|
|
||||||
else output += "\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (uri.hash) output += "Hash:\t\t" + uri.hash + "\n";
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
|
||||||
|
|
||||||
return "Invalid URI";
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import crypto from "crypto";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UUID operations.
|
* UUID operations.
|
||||||
*
|
*
|
||||||
@ -17,25 +20,17 @@ const UUID = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runGenerateV4: function(input, args) {
|
runGenerateV4: function(input, args) {
|
||||||
if (window && typeof(window.crypto) !== "undefined" && typeof(window.crypto.getRandomValues) !== "undefined") {
|
const buf = new Uint32Array(4).map(() => {
|
||||||
let buf = new Uint32Array(4),
|
return crypto.randomBytes(4).readUInt32BE(0, true);
|
||||||
i = 0;
|
});
|
||||||
window.crypto.getRandomValues(buf);
|
let i = 0;
|
||||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
||||||
let r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf,
|
let r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf,
|
||||||
v = c === "x" ? r : (r & 0x3 | 0x8);
|
v = c === "x" ? r : (r & 0x3 | 0x8);
|
||||||
i++;
|
i++;
|
||||||
return v.toString(16);
|
return v.toString(16);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
||||||
let r = Math.random() * 16 | 0,
|
|
||||||
v = c === "x" ? r : (r & 0x3 | 0x8);
|
|
||||||
return v.toString(16);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default UUID;
|
export default UUID;
|
||||||
|
@ -49,9 +49,11 @@ App.prototype.setup = function() {
|
|||||||
this.manager.setup();
|
this.manager.setup();
|
||||||
this.resetLayout();
|
this.resetLayout();
|
||||||
this.setCompileMessage();
|
this.setCompileMessage();
|
||||||
this.loadURIParams();
|
|
||||||
|
|
||||||
|
log.debug("App loaded");
|
||||||
this.appLoaded = true;
|
this.appLoaded = true;
|
||||||
|
|
||||||
|
this.loadURIParams();
|
||||||
this.loaded();
|
this.loaded();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,9 +90,10 @@ App.prototype.loaded = function() {
|
|||||||
* An error handler for displaying the error to the user.
|
* An error handler for displaying the error to the user.
|
||||||
*
|
*
|
||||||
* @param {Error} err
|
* @param {Error} err
|
||||||
|
* @param {boolean} [logToConsole=false]
|
||||||
*/
|
*/
|
||||||
App.prototype.handleError = function(err) {
|
App.prototype.handleError = function(err, logToConsole) {
|
||||||
console.error(err);
|
if (logToConsole) log.error(err);
|
||||||
const msg = err.displayStr || err.toString();
|
const msg = err.displayStr || err.toString();
|
||||||
this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors);
|
this.alert(msg, "danger", this.options.errorTimeout, !this.options.showErrors);
|
||||||
};
|
};
|
||||||
@ -128,6 +131,7 @@ App.prototype.autoBake = function() {
|
|||||||
if (this.autoBakePause) return false;
|
if (this.autoBakePause) return false;
|
||||||
|
|
||||||
if (this.autoBake_ && !this.baking) {
|
if (this.autoBake_ && !this.baking) {
|
||||||
|
log.debug("Auto-baking");
|
||||||
this.bake();
|
this.bake();
|
||||||
} else {
|
} else {
|
||||||
this.manager.controls.showStaleIndicator();
|
this.manager.controls.showStaleIndicator();
|
||||||
@ -568,7 +572,7 @@ App.prototype.isLocalStorageAvailable = function() {
|
|||||||
App.prototype.alert = function(str, style, timeout, silent) {
|
App.prototype.alert = function(str, style, timeout, silent) {
|
||||||
const time = new Date();
|
const time = new Date();
|
||||||
|
|
||||||
console.log("[" + time.toLocaleString() + "] " + str);
|
log.info("[" + time.toLocaleString() + "] " + str);
|
||||||
if (silent) return;
|
if (silent) return;
|
||||||
|
|
||||||
style = style || "danger";
|
style = style || "danger";
|
||||||
|
217
src/web/BindingsWaiter.js
Normal file
217
src/web/BindingsWaiter.js
Normal file
@ -0,0 +1,217 @@
|
|||||||
|
/**
|
||||||
|
* Waiter to handle keybindings to CyberChef functions (i.e. Bake, Step, Save, Load etc.)
|
||||||
|
*
|
||||||
|
* @author Matt C [matt@artemisbot.uk]
|
||||||
|
* @copyright Crown Copyright 2016
|
||||||
|
* @license Apache-2.0
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @param {App} app - The main view object for CyberChef.
|
||||||
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
|
*/
|
||||||
|
const BindingsWaiter = function (app, manager) {
|
||||||
|
this.app = app;
|
||||||
|
this.manager = manager;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for all keydown events
|
||||||
|
* Checks whether valid keyboard shortcut has been instated
|
||||||
|
*
|
||||||
|
* @fires Manager#statechange
|
||||||
|
* @param {event} e
|
||||||
|
*/
|
||||||
|
BindingsWaiter.prototype.parseInput = function(e) {
|
||||||
|
const modKey = this.app.options.useMetaKey ? e.metaKey : e.altKey;
|
||||||
|
|
||||||
|
if (e.ctrlKey && modKey) {
|
||||||
|
let elem;
|
||||||
|
switch (e.code) {
|
||||||
|
case "KeyF": // Focus search
|
||||||
|
e.preventDefault();
|
||||||
|
document.getElementById("search").focus();
|
||||||
|
break;
|
||||||
|
case "KeyI": // Focus input
|
||||||
|
e.preventDefault();
|
||||||
|
document.getElementById("input-text").focus();
|
||||||
|
break;
|
||||||
|
case "KeyO": // Focus output
|
||||||
|
e.preventDefault();
|
||||||
|
document.getElementById("output-text").focus();
|
||||||
|
break;
|
||||||
|
case "Period": // Focus next operation
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
elem = document.activeElement.closest(".operation") || document.querySelector("#rec-list .operation");
|
||||||
|
if (elem.parentNode.lastChild === elem) {
|
||||||
|
// If operation is last in recipe, loop around to the top operation's first argument
|
||||||
|
elem.parentNode.firstChild.querySelectorAll(".arg")[0].focus();
|
||||||
|
} else {
|
||||||
|
// Focus first argument of next operation
|
||||||
|
elem.nextSibling.querySelectorAll(".arg")[0].focus();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// do nothing, just don't throw an error
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "KeyB": // Set breakpoint
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
elem = document.activeElement.closest(".operation").querySelectorAll(".breakpoint")[0];
|
||||||
|
if (elem.getAttribute("break") === "false") {
|
||||||
|
elem.setAttribute("break", "true"); // add break point if not already enabled
|
||||||
|
elem.classList.add("breakpoint-selected");
|
||||||
|
} else {
|
||||||
|
elem.setAttribute("break", "false"); // remove break point if already enabled
|
||||||
|
elem.classList.remove("breakpoint-selected");
|
||||||
|
}
|
||||||
|
window.dispatchEvent(this.manager.statechange);
|
||||||
|
} catch (e) {
|
||||||
|
// do nothing, just don't throw an error
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "KeyD": // Disable operation
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
elem = document.activeElement.closest(".operation").querySelectorAll(".disable-icon")[0];
|
||||||
|
if (elem.getAttribute("disabled") === "false") {
|
||||||
|
elem.setAttribute("disabled", "true"); // disable operation if enabled
|
||||||
|
elem.classList.add("disable-elem-selected");
|
||||||
|
elem.parentNode.parentNode.classList.add("disabled");
|
||||||
|
} else {
|
||||||
|
elem.setAttribute("disabled", "false"); // enable operation if disabled
|
||||||
|
elem.classList.remove("disable-elem-selected");
|
||||||
|
elem.parentNode.parentNode.classList.remove("disabled");
|
||||||
|
}
|
||||||
|
this.app.progress = 0;
|
||||||
|
window.dispatchEvent(this.manager.statechange);
|
||||||
|
} catch (e) {
|
||||||
|
// do nothing, just don't throw an error
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "Space": // Bake
|
||||||
|
e.preventDefault();
|
||||||
|
this.app.bake();
|
||||||
|
break;
|
||||||
|
case "Quote": // Step through
|
||||||
|
e.preventDefault();
|
||||||
|
this.app.bake(true);
|
||||||
|
break;
|
||||||
|
case "KeyC": // Clear recipe
|
||||||
|
e.preventDefault();
|
||||||
|
this.manager.recipe.clearRecipe();
|
||||||
|
break;
|
||||||
|
case "KeyS": // Save output to file
|
||||||
|
e.preventDefault();
|
||||||
|
this.manager.output.saveClick();
|
||||||
|
break;
|
||||||
|
case "KeyL": // Load recipe
|
||||||
|
e.preventDefault();
|
||||||
|
this.manager.controls.loadClick();
|
||||||
|
break;
|
||||||
|
case "KeyM": // Switch input and output
|
||||||
|
e.preventDefault();
|
||||||
|
this.manager.output.switchClick();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (e.code.match(/Digit[0-9]/g)) { // Select nth operation
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
// Select the first argument of the operation corresponding to the number pressed
|
||||||
|
document.querySelector(`li:nth-child(${e.code.substr(-1)}) .arg`).focus();
|
||||||
|
} catch (e) {
|
||||||
|
// do nothing, just don't throw an error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates keybinding list when metaKey option is toggled
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
BindingsWaiter.prototype.updateKeybList = function() {
|
||||||
|
let modWinLin = "Alt";
|
||||||
|
let modMac = "Opt";
|
||||||
|
if (this.app.options.useMetaKey) {
|
||||||
|
modWinLin = "Win";
|
||||||
|
modMac = "Cmd";
|
||||||
|
}
|
||||||
|
document.getElementById("keybList").innerHTML = `
|
||||||
|
<tr>
|
||||||
|
<td><b>Command</b></td>
|
||||||
|
<td><b>Shortcut (Win/Linux)</b></td>
|
||||||
|
<td><b>Shortcut (Mac)</b></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Place cursor in search field</td>
|
||||||
|
<td>Ctrl+${modWinLin}+f</td>
|
||||||
|
<td>Ctrl+${modMac}+f</td>
|
||||||
|
<tr>
|
||||||
|
<td>Place cursor in input box</td>
|
||||||
|
<td>Ctrl+${modWinLin}+i</td>
|
||||||
|
<td>Ctrl+${modMac}+i</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Place cursor in output box</td>
|
||||||
|
<td>Ctrl+${modWinLin}+o</td>
|
||||||
|
<td>Ctrl+${modMac}+o</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Place cursor in first argument field of the next operation in the recipe</td>
|
||||||
|
<td>Ctrl+${modWinLin}+.</td>
|
||||||
|
<td>Ctrl+${modMac}+.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Place cursor in first argument field of the nth operation in the recipe</td>
|
||||||
|
<td>Ctrl+${modWinLin}+[1-9]</td>
|
||||||
|
<td>Ctrl+${modMac}+[1-9]</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Disable current operation</td>
|
||||||
|
<td>Ctrl+${modWinLin}+d</td>
|
||||||
|
<td>Ctrl+${modMac}+d</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Set/clear breakpoint</td>
|
||||||
|
<td>Ctrl+${modWinLin}+b</td>
|
||||||
|
<td>Ctrl+${modMac}+b</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Bake</td>
|
||||||
|
<td>Ctrl+${modWinLin}+Space</td>
|
||||||
|
<td>Ctrl+${modMac}+Space</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Step</td>
|
||||||
|
<td>Ctrl+${modWinLin}+'</td>
|
||||||
|
<td>Ctrl+${modMac}+'</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Clear recipe</td>
|
||||||
|
<td>Ctrl+${modWinLin}+c</td>
|
||||||
|
<td>Ctrl+${modMac}+c</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Save to file</td>
|
||||||
|
<td>Ctrl+${modWinLin}+s</td>
|
||||||
|
<td>Ctrl+${modMac}+s</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Load recipe</td>
|
||||||
|
<td>Ctrl+${modWinLin}+l</td>
|
||||||
|
<td>Ctrl+${modMac}+l</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Move output to input</td>
|
||||||
|
<td>Ctrl+${modWinLin}+m</td>
|
||||||
|
<td>Ctrl+${modMac}+m</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BindingsWaiter;
|
@ -1,6 +1,3 @@
|
|||||||
import Utils from "../core/Utils.js";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waiter to handle events related to highlighting in CyberChef.
|
* Waiter to handle events related to highlighting in CyberChef.
|
||||||
*
|
*
|
||||||
@ -312,9 +309,9 @@ HighlighterWaiter.prototype.outputHtmlMousemove = function(e) {
|
|||||||
HighlighterWaiter.prototype.selectionInfo = function(start, end) {
|
HighlighterWaiter.prototype.selectionInfo = function(start, end) {
|
||||||
const len = end.toString().length;
|
const len = end.toString().length;
|
||||||
const width = len < 2 ? 2 : len;
|
const width = len < 2 ? 2 : len;
|
||||||
const startStr = Utils.pad(start.toString(), width, " ").replace(/ /g, " ");
|
const startStr = start.toString().padStart(width, " ").replace(/ /g, " ");
|
||||||
const endStr = Utils.pad(end.toString(), width, " ").replace(/ /g, " ");
|
const endStr = end.toString().padStart(width, " ").replace(/ /g, " ");
|
||||||
const lenStr = Utils.pad((end-start).toString(), width, " ").replace(/ /g, " ");
|
const lenStr = (end-start).toString().padStart(width, " ").replace(/ /g, " ");
|
||||||
|
|
||||||
return "start: " + startStr + "<br>end: " + endStr + "<br>length: " + lenStr;
|
return "start: " + startStr + "<br>end: " + endStr + "<br>length: " + lenStr;
|
||||||
};
|
};
|
||||||
@ -402,7 +399,7 @@ HighlighterWaiter.prototype.highlight = function(textarea, highlighter, pos) {
|
|||||||
|
|
||||||
// Check if there is a carriage return in the output dish as this will not
|
// Check if there is a carriage return in the output dish as this will not
|
||||||
// be displayed by the HTML textarea and will mess up highlighting offsets.
|
// be displayed by the HTML textarea and will mess up highlighting offsets.
|
||||||
if (!this.app.dishStr || this.app.dishStr.indexOf("\r") >= 0) return false;
|
if (this.manager.output.containsCR()) return false;
|
||||||
|
|
||||||
const startPlaceholder = "[startHighlight]";
|
const startPlaceholder = "[startHighlight]";
|
||||||
const startPlaceholderRegex = /\[startHighlight\]/g;
|
const startPlaceholderRegex = /\[startHighlight\]/g;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Utils from "../core/Utils.js";
|
import LoaderWorker from "worker-loader?inline&fallback=false!./LoaderWorker.js";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,6 +33,9 @@ const InputWaiter = function(app, manager) {
|
|||||||
144, //Num
|
144, //Num
|
||||||
145, //Scroll
|
145, //Scroll
|
||||||
];
|
];
|
||||||
|
|
||||||
|
this.loaderWorker = null;
|
||||||
|
this.fileBuffer = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -42,20 +45,52 @@ const InputWaiter = function(app, manager) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.get = function() {
|
InputWaiter.prototype.get = function() {
|
||||||
return document.getElementById("input-text").value;
|
return this.fileBuffer || document.getElementById("input-text").value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the input in the input textarea.
|
* Sets the input in the input area.
|
||||||
*
|
*
|
||||||
* @param {string} input
|
* @param {string|File} input
|
||||||
*
|
*
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.set = function(input) {
|
InputWaiter.prototype.set = function(input) {
|
||||||
document.getElementById("input-text").value = input;
|
const inputText = document.getElementById("input-text");
|
||||||
|
if (input instanceof File) {
|
||||||
|
this.setFile(input);
|
||||||
|
inputText.value = "";
|
||||||
|
this.setInputInfo(input.size, null);
|
||||||
|
} else {
|
||||||
|
inputText.value = input;
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
|
const lines = input.length < (this.app.options.ioDisplayThreshold * 1024) ?
|
||||||
|
input.count("\n") + 1 : null;
|
||||||
|
this.setInputInfo(input.length, lines);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows file details.
|
||||||
|
*
|
||||||
|
* @param {File} file
|
||||||
|
*/
|
||||||
|
InputWaiter.prototype.setFile = function(file) {
|
||||||
|
// Display file overlay in input area with details
|
||||||
|
const fileOverlay = document.getElementById("input-file"),
|
||||||
|
fileName = document.getElementById("input-file-name"),
|
||||||
|
fileSize = document.getElementById("input-file-size"),
|
||||||
|
fileType = document.getElementById("input-file-type"),
|
||||||
|
fileLoaded = document.getElementById("input-file-loaded");
|
||||||
|
|
||||||
|
this.fileBuffer = new ArrayBuffer();
|
||||||
|
fileOverlay.style.display = "block";
|
||||||
|
fileName.textContent = file.name;
|
||||||
|
fileSize.textContent = file.size.toLocaleString() + " bytes";
|
||||||
|
fileType.textContent = file.type || "unknown";
|
||||||
|
fileLoaded.textContent = "0%";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -69,22 +104,29 @@ InputWaiter.prototype.setInputInfo = function(length, lines) {
|
|||||||
let width = length.toString().length;
|
let width = length.toString().length;
|
||||||
width = width < 2 ? 2 : width;
|
width = width < 2 ? 2 : width;
|
||||||
|
|
||||||
const lengthStr = Utils.pad(length.toString(), width, " ").replace(/ /g, " ");
|
const lengthStr = length.toString().padStart(width, " ").replace(/ /g, " ");
|
||||||
const linesStr = Utils.pad(lines.toString(), width, " ").replace(/ /g, " ");
|
let msg = "length: " + lengthStr;
|
||||||
|
|
||||||
document.getElementById("input-info").innerHTML = "length: " + lengthStr + "<br>lines: " + linesStr;
|
if (typeof lines === "number") {
|
||||||
|
const linesStr = lines.toString().padStart(width, " ").replace(/ /g, " ");
|
||||||
|
msg += "<br>lines: " + linesStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("input-info").innerHTML = msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for input scroll events.
|
* Handler for input change events.
|
||||||
* Scrolls the highlighter pane to match the input textarea position and updates history state.
|
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*
|
*
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.inputChange = function(e) {
|
InputWaiter.prototype.inputChange = function(e) {
|
||||||
|
// Ignore this function if the input is a File
|
||||||
|
if (this.fileBuffer) return;
|
||||||
|
|
||||||
// Remove highlighting from input and output panes as the offsets might be different now
|
// Remove highlighting from input and output panes as the offsets might be different now
|
||||||
this.manager.highlighter.removeHighlights();
|
this.manager.highlighter.removeHighlights();
|
||||||
|
|
||||||
@ -93,18 +135,47 @@ InputWaiter.prototype.inputChange = function(e) {
|
|||||||
|
|
||||||
// Update the input metadata info
|
// Update the input metadata info
|
||||||
const inputText = this.get();
|
const inputText = this.get();
|
||||||
const lines = inputText.count("\n") + 1;
|
const lines = inputText.length < (this.app.options.ioDisplayThreshold * 1024) ?
|
||||||
|
inputText.count("\n") + 1 : null;
|
||||||
|
|
||||||
this.setInputInfo(inputText.length, lines);
|
this.setInputInfo(inputText.length, lines);
|
||||||
|
|
||||||
|
if (e && this.badKeys.indexOf(e.keyCode) < 0) {
|
||||||
if (this.badKeys.indexOf(e.keyCode) < 0) {
|
|
||||||
// Fire the statechange event as the input has been modified
|
// Fire the statechange event as the input has been modified
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for input paste events.
|
||||||
|
* Checks that the size of the input is below the display limit, otherwise treats it as a file/blob.
|
||||||
|
*
|
||||||
|
* @param {event} e
|
||||||
|
*/
|
||||||
|
InputWaiter.prototype.inputPaste = function(e) {
|
||||||
|
const pastedData = e.clipboardData.getData("Text");
|
||||||
|
|
||||||
|
if (pastedData.length < (this.app.options.ioDisplayThreshold * 1024)) {
|
||||||
|
this.inputChange(e);
|
||||||
|
} else {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
const file = new File([pastedData], "PastedData", {
|
||||||
|
type: "text/plain",
|
||||||
|
lastModified: Date.now()
|
||||||
|
});
|
||||||
|
|
||||||
|
this.loaderWorker = new LoaderWorker();
|
||||||
|
this.loaderWorker.addEventListener("message", this.handleLoaderMessage.bind(this));
|
||||||
|
this.loaderWorker.postMessage({"file": file});
|
||||||
|
this.set(file);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for input dragover events.
|
* Handler for input dragover events.
|
||||||
* Gives the user a visual cue to show that items can be dropped here.
|
* Gives the user a visual cue to show that items can be dropped here.
|
||||||
@ -118,7 +189,7 @@ InputWaiter.prototype.inputDragover = function(e) {
|
|||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.target.classList.add("dropping-file");
|
e.target.closest("#input-text,#input-file").classList.add("dropping-file");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -131,7 +202,8 @@ InputWaiter.prototype.inputDragover = function(e) {
|
|||||||
InputWaiter.prototype.inputDragleave = function(e) {
|
InputWaiter.prototype.inputDragleave = function(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.target.classList.remove("dropping-file");
|
document.getElementById("input-text").classList.remove("dropping-file");
|
||||||
|
document.getElementById("input-file").classList.remove("dropping-file");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -149,55 +221,62 @@ InputWaiter.prototype.inputDrop = function(e) {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const el = e.target;
|
|
||||||
const file = e.dataTransfer.files[0];
|
const file = e.dataTransfer.files[0];
|
||||||
const text = e.dataTransfer.getData("Text");
|
const text = e.dataTransfer.getData("Text");
|
||||||
const reader = new FileReader();
|
|
||||||
let inputCharcode = "";
|
|
||||||
let offset = 0;
|
|
||||||
const CHUNK_SIZE = 20480; // 20KB
|
|
||||||
|
|
||||||
const setInput = function() {
|
document.getElementById("input-text").classList.remove("dropping-file");
|
||||||
const recipeConfig = this.app.getRecipeConfig();
|
document.getElementById("input-file").classList.remove("dropping-file");
|
||||||
if (!recipeConfig[0] || recipeConfig[0].op !== "From Hex") {
|
|
||||||
recipeConfig.unshift({op: "From Hex", args: ["Space"]});
|
|
||||||
this.app.setRecipeConfig(recipeConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.set(inputCharcode);
|
if (text) {
|
||||||
|
this.closeFile();
|
||||||
el.classList.remove("loadingFile");
|
this.set(text);
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
const seek = function() {
|
|
||||||
if (offset >= file.size) {
|
|
||||||
setInput();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
el.value = "Processing... " + Math.round(offset / file.size * 100) + "%";
|
|
||||||
const slice = file.slice(offset, offset + CHUNK_SIZE);
|
|
||||||
reader.readAsArrayBuffer(slice);
|
|
||||||
};
|
|
||||||
|
|
||||||
reader.onload = function(e) {
|
|
||||||
const data = new Uint8Array(reader.result);
|
|
||||||
inputCharcode += Utils.toHexFast(data);
|
|
||||||
offset += CHUNK_SIZE;
|
|
||||||
seek();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
el.classList.remove("dropping-file");
|
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
el.classList.add("loadingFile");
|
this.closeFile();
|
||||||
seek();
|
this.loaderWorker = new LoaderWorker();
|
||||||
} else if (text) {
|
this.loaderWorker.addEventListener("message", this.handleLoaderMessage.bind(this));
|
||||||
this.set(text);
|
this.loaderWorker.postMessage({"file": file});
|
||||||
|
this.set(file);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for messages sent back by the LoaderWorker.
|
||||||
|
*
|
||||||
|
* @param {MessageEvent} e
|
||||||
|
*/
|
||||||
|
InputWaiter.prototype.handleLoaderMessage = function(e) {
|
||||||
|
const r = e.data;
|
||||||
|
if (r.hasOwnProperty("progress")) {
|
||||||
|
const fileLoaded = document.getElementById("input-file-loaded");
|
||||||
|
fileLoaded.textContent = r.progress + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r.hasOwnProperty("error")) {
|
||||||
|
this.app.alert(r.error, "danger", 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r.hasOwnProperty("fileBuffer")) {
|
||||||
|
log.debug("Input file loaded");
|
||||||
|
this.fileBuffer = r.fileBuffer;
|
||||||
|
window.dispatchEvent(this.manager.statechange);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for file close events.
|
||||||
|
*/
|
||||||
|
InputWaiter.prototype.closeFile = function() {
|
||||||
|
if (this.loaderWorker) this.loaderWorker.terminate();
|
||||||
|
this.fileBuffer = null;
|
||||||
|
document.getElementById("input-file").style.display = "none";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for clear IO events.
|
* Handler for clear IO events.
|
||||||
* Resets the input, output and info areas.
|
* Resets the input, output and info areas.
|
||||||
@ -205,6 +284,8 @@ InputWaiter.prototype.inputDrop = function(e) {
|
|||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.clearIoClick = function() {
|
InputWaiter.prototype.clearIoClick = function() {
|
||||||
|
this.closeFile();
|
||||||
|
this.manager.output.closeFile();
|
||||||
this.manager.highlighter.removeHighlights();
|
this.manager.highlighter.removeHighlights();
|
||||||
document.getElementById("input-text").value = "";
|
document.getElementById("input-text").value = "";
|
||||||
document.getElementById("output-text").value = "";
|
document.getElementById("output-text").value = "";
|
||||||
|
54
src/web/LoaderWorker.js
Normal file
54
src/web/LoaderWorker.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* Web Worker to load large amounts of data without locking up the UI.
|
||||||
|
*
|
||||||
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2017
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Respond to message from parent thread.
|
||||||
|
*/
|
||||||
|
self.addEventListener("message", function(e) {
|
||||||
|
const r = e.data;
|
||||||
|
if (r.hasOwnProperty("file")) {
|
||||||
|
self.loadFile(r.file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a file object into an ArrayBuffer, then transfers it back to the parent thread.
|
||||||
|
*
|
||||||
|
* @param {File} file
|
||||||
|
*/
|
||||||
|
self.loadFile = function(file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
let data = new Uint8Array(file.size);
|
||||||
|
let offset = 0;
|
||||||
|
const CHUNK_SIZE = 10485760; // 10MiB
|
||||||
|
|
||||||
|
const seek = function() {
|
||||||
|
if (offset >= file.size) {
|
||||||
|
self.postMessage({"progress": 100});
|
||||||
|
self.postMessage({"fileBuffer": data.buffer}, [data.buffer]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.postMessage({"progress": Math.round(offset / file.size * 100)});
|
||||||
|
const slice = file.slice(offset, offset + CHUNK_SIZE);
|
||||||
|
reader.readAsArrayBuffer(slice);
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.onload = function(e) {
|
||||||
|
data.set(new Uint8Array(reader.result), offset);
|
||||||
|
offset += CHUNK_SIZE;
|
||||||
|
seek();
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.onerror = function(e) {
|
||||||
|
self.postMessage({"error": file.error.message});
|
||||||
|
};
|
||||||
|
|
||||||
|
seek();
|
||||||
|
};
|
@ -8,6 +8,7 @@ import OutputWaiter from "./OutputWaiter.js";
|
|||||||
import OptionsWaiter from "./OptionsWaiter.js";
|
import OptionsWaiter from "./OptionsWaiter.js";
|
||||||
import HighlighterWaiter from "./HighlighterWaiter.js";
|
import HighlighterWaiter from "./HighlighterWaiter.js";
|
||||||
import SeasonalWaiter from "./SeasonalWaiter.js";
|
import SeasonalWaiter from "./SeasonalWaiter.js";
|
||||||
|
import BindingsWaiter from "./BindingsWaiter.js";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,9 +58,10 @@ const Manager = function(app) {
|
|||||||
this.ops = new OperationsWaiter(this.app, this);
|
this.ops = new OperationsWaiter(this.app, this);
|
||||||
this.input = new InputWaiter(this.app, this);
|
this.input = new InputWaiter(this.app, this);
|
||||||
this.output = new OutputWaiter(this.app, this);
|
this.output = new OutputWaiter(this.app, this);
|
||||||
this.options = new OptionsWaiter(this.app);
|
this.options = new OptionsWaiter(this.app, this);
|
||||||
this.highlighter = new HighlighterWaiter(this.app, this);
|
this.highlighter = new HighlighterWaiter(this.app, this);
|
||||||
this.seasonal = new SeasonalWaiter(this.app, this);
|
this.seasonal = new SeasonalWaiter(this.app, this);
|
||||||
|
this.bindings = new BindingsWaiter(this.app, this);
|
||||||
|
|
||||||
// Object to store dynamic handlers to fire on elements that may not exist yet
|
// Object to store dynamic handlers to fire on elements that may not exist yet
|
||||||
this.dynamicHandlers = {};
|
this.dynamicHandlers = {};
|
||||||
@ -75,6 +77,7 @@ Manager.prototype.setup = function() {
|
|||||||
this.worker.registerChefWorker();
|
this.worker.registerChefWorker();
|
||||||
this.recipe.initialiseOperationDragNDrop();
|
this.recipe.initialiseOperationDragNDrop();
|
||||||
this.controls.autoBakeChange();
|
this.controls.autoBakeChange();
|
||||||
|
this.bindings.updateKeybList();
|
||||||
this.seasonal.load();
|
this.seasonal.load();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -116,7 +119,7 @@ Manager.prototype.initialiseEventListeners = function() {
|
|||||||
this.addDynamicListener(".op-list .op-icon", "mouseover", this.ops.opIconMouseover, this.ops);
|
this.addDynamicListener(".op-list .op-icon", "mouseover", this.ops.opIconMouseover, this.ops);
|
||||||
this.addDynamicListener(".op-list .op-icon", "mouseleave", this.ops.opIconMouseleave, this.ops);
|
this.addDynamicListener(".op-list .op-icon", "mouseleave", this.ops.opIconMouseleave, this.ops);
|
||||||
this.addDynamicListener(".op-list", "oplistcreate", this.ops.opListCreate, this.ops);
|
this.addDynamicListener(".op-list", "oplistcreate", this.ops.opListCreate, this.ops);
|
||||||
this.addDynamicListener("li.operation", "operationadd", this.recipe.opAdd.bind(this.recipe));
|
this.addDynamicListener("li.operation", "operationadd", this.recipe.opAdd, this.recipe);
|
||||||
|
|
||||||
// Recipe
|
// Recipe
|
||||||
this.addDynamicListener(".arg:not(select)", "input", this.recipe.ingChange, this.recipe);
|
this.addDynamicListener(".arg:not(select)", "input", this.recipe.ingChange, this.recipe);
|
||||||
@ -129,19 +132,22 @@ Manager.prototype.initialiseEventListeners = function() {
|
|||||||
this.addDynamicListener("#rec-list", "operationremove", this.recipe.opRemove.bind(this.recipe));
|
this.addDynamicListener("#rec-list", "operationremove", this.recipe.opRemove.bind(this.recipe));
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
this.addMultiEventListener("#input-text", "keyup paste", this.input.inputChange, this.input);
|
this.addMultiEventListener("#input-text", "keyup", this.input.inputChange, this.input);
|
||||||
|
this.addMultiEventListener("#input-text", "paste", this.input.inputPaste, this.input);
|
||||||
document.getElementById("reset-layout").addEventListener("click", this.app.resetLayout.bind(this.app));
|
document.getElementById("reset-layout").addEventListener("click", this.app.resetLayout.bind(this.app));
|
||||||
document.getElementById("clr-io").addEventListener("click", this.input.clearIoClick.bind(this.input));
|
document.getElementById("clr-io").addEventListener("click", this.input.clearIoClick.bind(this.input));
|
||||||
document.getElementById("input-text").addEventListener("dragover", this.input.inputDragover.bind(this.input));
|
this.addListeners("#input-text,#input-file", "dragover", this.input.inputDragover, this.input);
|
||||||
document.getElementById("input-text").addEventListener("dragleave", this.input.inputDragleave.bind(this.input));
|
this.addListeners("#input-text,#input-file", "dragleave", this.input.inputDragleave, this.input);
|
||||||
document.getElementById("input-text").addEventListener("drop", this.input.inputDrop.bind(this.input));
|
this.addListeners("#input-text,#input-file", "drop", this.input.inputDrop, this.input);
|
||||||
document.getElementById("input-text").addEventListener("scroll", this.highlighter.inputScroll.bind(this.highlighter));
|
document.getElementById("input-text").addEventListener("scroll", this.highlighter.inputScroll.bind(this.highlighter));
|
||||||
document.getElementById("input-text").addEventListener("mouseup", this.highlighter.inputMouseup.bind(this.highlighter));
|
document.getElementById("input-text").addEventListener("mouseup", this.highlighter.inputMouseup.bind(this.highlighter));
|
||||||
document.getElementById("input-text").addEventListener("mousemove", this.highlighter.inputMousemove.bind(this.highlighter));
|
document.getElementById("input-text").addEventListener("mousemove", this.highlighter.inputMousemove.bind(this.highlighter));
|
||||||
this.addMultiEventListener("#input-text", "mousedown dblclick select", this.highlighter.inputMousedown, this.highlighter);
|
this.addMultiEventListener("#input-text", "mousedown dblclick select", this.highlighter.inputMousedown, this.highlighter);
|
||||||
|
document.querySelector("#input-file .close").addEventListener("click", this.input.clearIoClick.bind(this.input));
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
document.getElementById("save-to-file").addEventListener("click", this.output.saveClick.bind(this.output));
|
document.getElementById("save-to-file").addEventListener("click", this.output.saveClick.bind(this.output));
|
||||||
|
document.getElementById("copy-output").addEventListener("click", this.output.copyClick.bind(this.output));
|
||||||
document.getElementById("switch").addEventListener("click", this.output.switchClick.bind(this.output));
|
document.getElementById("switch").addEventListener("click", this.output.switchClick.bind(this.output));
|
||||||
document.getElementById("undo-switch").addEventListener("click", this.output.undoSwitchClick.bind(this.output));
|
document.getElementById("undo-switch").addEventListener("click", this.output.undoSwitchClick.bind(this.output));
|
||||||
document.getElementById("maximise-output").addEventListener("click", this.output.maximiseOutputClick.bind(this.output));
|
document.getElementById("maximise-output").addEventListener("click", this.output.maximiseOutputClick.bind(this.output));
|
||||||
@ -153,18 +159,24 @@ Manager.prototype.initialiseEventListeners = function() {
|
|||||||
this.addMultiEventListener("#output-text", "mousedown dblclick select", this.highlighter.outputMousedown, this.highlighter);
|
this.addMultiEventListener("#output-text", "mousedown dblclick select", this.highlighter.outputMousedown, this.highlighter);
|
||||||
this.addMultiEventListener("#output-html", "mousedown dblclick select", this.highlighter.outputHtmlMousedown, this.highlighter);
|
this.addMultiEventListener("#output-html", "mousedown dblclick select", this.highlighter.outputHtmlMousedown, this.highlighter);
|
||||||
this.addDynamicListener(".file-switch", "click", this.output.fileSwitch, this.output);
|
this.addDynamicListener(".file-switch", "click", this.output.fileSwitch, this.output);
|
||||||
|
this.addDynamicListener("#output-file-download", "click", this.output.downloadFile, this.output);
|
||||||
|
this.addDynamicListener("#output-file-slice", "click", this.output.displayFileSlice, this.output);
|
||||||
|
document.getElementById("show-file-overlay").addEventListener("click", this.output.showFileOverlayClick.bind(this.output));
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
document.getElementById("options").addEventListener("click", this.options.optionsClick.bind(this.options));
|
document.getElementById("options").addEventListener("click", this.options.optionsClick.bind(this.options));
|
||||||
document.getElementById("reset-options").addEventListener("click", this.options.resetOptionsClick.bind(this.options));
|
document.getElementById("reset-options").addEventListener("click", this.options.resetOptionsClick.bind(this.options));
|
||||||
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.switchChange.bind(this.options));
|
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.switchChange.bind(this.options));
|
||||||
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.setWordWrap.bind(this.options));
|
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.setWordWrap.bind(this.options));
|
||||||
|
$(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox#useMetaKey", this.bindings.updateKeybList.bind(this.bindings));
|
||||||
this.addDynamicListener(".option-item input[type=number]", "keyup", this.options.numberChange, this.options);
|
this.addDynamicListener(".option-item input[type=number]", "keyup", this.options.numberChange, this.options);
|
||||||
this.addDynamicListener(".option-item input[type=number]", "change", this.options.numberChange, this.options);
|
this.addDynamicListener(".option-item input[type=number]", "change", this.options.numberChange, this.options);
|
||||||
this.addDynamicListener(".option-item select", "change", this.options.selectChange, this.options);
|
this.addDynamicListener(".option-item select", "change", this.options.selectChange, this.options);
|
||||||
document.getElementById("theme").addEventListener("change", this.options.themeChange.bind(this.options));
|
document.getElementById("theme").addEventListener("change", this.options.themeChange.bind(this.options));
|
||||||
|
document.getElementById("logLevel").addEventListener("change", this.options.logLevelChange.bind(this.options));
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
|
window.addEventListener("keydown", this.bindings.parseInput.bind(this.bindings));
|
||||||
document.getElementById("alert-close").addEventListener("click", this.app.alertCloseClick.bind(this.app));
|
document.getElementById("alert-close").addEventListener("click", this.app.alertCloseClick.bind(this.app));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,8 +8,9 @@
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @param {App} app - The main view object for CyberChef.
|
* @param {App} app - The main view object for CyberChef.
|
||||||
*/
|
*/
|
||||||
const OptionsWaiter = function(app) {
|
const OptionsWaiter = function(app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
this.manager = manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ OptionsWaiter.prototype.switchChange = function(e, state) {
|
|||||||
const el = e.target;
|
const el = e.target;
|
||||||
const option = el.getAttribute("option");
|
const option = el.getAttribute("option");
|
||||||
|
|
||||||
|
log.debug(`Setting ${option} to ${state}`);
|
||||||
this.app.options[option] = state;
|
this.app.options[option] = state;
|
||||||
|
|
||||||
if (this.app.isLocalStorageAvailable())
|
if (this.app.isLocalStorageAvailable())
|
||||||
@ -102,8 +104,10 @@ OptionsWaiter.prototype.switchChange = function(e, state) {
|
|||||||
OptionsWaiter.prototype.numberChange = function(e) {
|
OptionsWaiter.prototype.numberChange = function(e) {
|
||||||
const el = e.target;
|
const el = e.target;
|
||||||
const option = el.getAttribute("option");
|
const option = el.getAttribute("option");
|
||||||
|
const val = parseInt(el.value, 10);
|
||||||
|
|
||||||
this.app.options[option] = parseInt(el.value, 10);
|
log.debug(`Setting ${option} to ${val}`);
|
||||||
|
this.app.options[option] = val;
|
||||||
|
|
||||||
if (this.app.isLocalStorageAvailable())
|
if (this.app.isLocalStorageAvailable())
|
||||||
localStorage.setItem("options", JSON.stringify(this.app.options));
|
localStorage.setItem("options", JSON.stringify(this.app.options));
|
||||||
@ -120,6 +124,7 @@ OptionsWaiter.prototype.selectChange = function(e) {
|
|||||||
const el = e.target;
|
const el = e.target;
|
||||||
const option = el.getAttribute("option");
|
const option = el.getAttribute("option");
|
||||||
|
|
||||||
|
log.debug(`Setting ${option} to ${el.value}`);
|
||||||
this.app.options[option] = el.value;
|
this.app.options[option] = el.value;
|
||||||
|
|
||||||
if (this.app.isLocalStorageAvailable())
|
if (this.app.isLocalStorageAvailable())
|
||||||
@ -149,6 +154,8 @@ OptionsWaiter.prototype.setWordWrap = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the theme by setting the class of the <html> element.
|
* Changes the theme by setting the class of the <html> element.
|
||||||
|
*
|
||||||
|
* @param {Event} e
|
||||||
*/
|
*/
|
||||||
OptionsWaiter.prototype.themeChange = function (e) {
|
OptionsWaiter.prototype.themeChange = function (e) {
|
||||||
const themeClass = e.target.value;
|
const themeClass = e.target.value;
|
||||||
@ -156,4 +163,16 @@ OptionsWaiter.prototype.themeChange = function (e) {
|
|||||||
document.querySelector(":root").className = themeClass;
|
document.querySelector(":root").className = themeClass;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the console logging level.
|
||||||
|
*
|
||||||
|
* @param {Event} e
|
||||||
|
*/
|
||||||
|
OptionsWaiter.prototype.logLevelChange = function (e) {
|
||||||
|
const level = e.target.value;
|
||||||
|
log.setLevel(level, false);
|
||||||
|
this.manager.worker.setLogLevel();
|
||||||
|
};
|
||||||
|
|
||||||
export default OptionsWaiter;
|
export default OptionsWaiter;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Utils from "../core/Utils.js";
|
import Utils from "../core/Utils.js";
|
||||||
|
import FileSaver from "file-saver";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,6 +16,9 @@ import Utils from "../core/Utils.js";
|
|||||||
const OutputWaiter = function(app, manager) {
|
const OutputWaiter = function(app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
|
this.dishBuffer = null;
|
||||||
|
this.dishStr = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -31,47 +35,151 @@ OutputWaiter.prototype.get = function() {
|
|||||||
/**
|
/**
|
||||||
* Sets the output in the output textarea.
|
* Sets the output in the output textarea.
|
||||||
*
|
*
|
||||||
* @param {string} dataStr - The output string/HTML
|
* @param {string|ArrayBuffer} data - The output string/HTML/ArrayBuffer
|
||||||
* @param {string} type - The data type of the output
|
* @param {string} type - The data type of the output
|
||||||
* @param {number} duration - The length of time (ms) it took to generate the output
|
* @param {number} duration - The length of time (ms) it took to generate the output
|
||||||
|
* @param {boolean} [preserveBuffer=false] - Whether to preserve the dishBuffer
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.set = function(dataStr, type, duration) {
|
OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
|
||||||
|
log.debug("Output type: " + type);
|
||||||
const outputText = document.getElementById("output-text");
|
const outputText = document.getElementById("output-text");
|
||||||
const outputHtml = document.getElementById("output-html");
|
const outputHtml = document.getElementById("output-html");
|
||||||
|
const outputFile = document.getElementById("output-file");
|
||||||
const outputHighlighter = document.getElementById("output-highlighter");
|
const outputHighlighter = document.getElementById("output-highlighter");
|
||||||
const inputHighlighter = document.getElementById("input-highlighter");
|
const inputHighlighter = document.getElementById("input-highlighter");
|
||||||
|
let scriptElements, lines, length;
|
||||||
|
|
||||||
if (type === "html") {
|
if (!preserveBuffer) {
|
||||||
|
this.closeFile();
|
||||||
|
document.getElementById("show-file-overlay").style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case "html":
|
||||||
outputText.style.display = "none";
|
outputText.style.display = "none";
|
||||||
outputHtml.style.display = "block";
|
outputHtml.style.display = "block";
|
||||||
|
outputFile.style.display = "none";
|
||||||
outputHighlighter.display = "none";
|
outputHighlighter.display = "none";
|
||||||
inputHighlighter.display = "none";
|
inputHighlighter.display = "none";
|
||||||
|
|
||||||
outputText.value = "";
|
outputText.value = "";
|
||||||
outputHtml.innerHTML = dataStr;
|
outputHtml.innerHTML = data;
|
||||||
|
this.dishStr = Utils.stripHtmlTags(data, true);
|
||||||
|
length = data.length;
|
||||||
|
lines = this.dishStr.count("\n") + 1;
|
||||||
|
|
||||||
// Execute script sections
|
// Execute script sections
|
||||||
const scriptElements = outputHtml.querySelectorAll("script");
|
scriptElements = outputHtml.querySelectorAll("script");
|
||||||
for (let i = 0; i < scriptElements.length; i++) {
|
for (let i = 0; i < scriptElements.length; i++) {
|
||||||
try {
|
try {
|
||||||
eval(scriptElements[i].innerHTML); // eslint-disable-line no-eval
|
eval(scriptElements[i].innerHTML); // eslint-disable-line no-eval
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
log.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
|
case "ArrayBuffer":
|
||||||
outputText.style.display = "block";
|
outputText.style.display = "block";
|
||||||
outputHtml.style.display = "none";
|
outputHtml.style.display = "none";
|
||||||
|
outputHighlighter.display = "none";
|
||||||
|
inputHighlighter.display = "none";
|
||||||
|
|
||||||
|
outputText.value = "";
|
||||||
|
outputHtml.innerHTML = "";
|
||||||
|
this.dishStr = "";
|
||||||
|
length = data.byteLength;
|
||||||
|
|
||||||
|
this.setFile(data);
|
||||||
|
break;
|
||||||
|
case "string":
|
||||||
|
default:
|
||||||
|
outputText.style.display = "block";
|
||||||
|
outputHtml.style.display = "none";
|
||||||
|
outputFile.style.display = "none";
|
||||||
outputHighlighter.display = "block";
|
outputHighlighter.display = "block";
|
||||||
inputHighlighter.display = "block";
|
inputHighlighter.display = "block";
|
||||||
|
|
||||||
outputText.value = Utils.printable(dataStr, true);
|
outputText.value = Utils.printable(data, true);
|
||||||
outputHtml.innerHTML = "";
|
outputHtml.innerHTML = "";
|
||||||
|
|
||||||
|
lines = data.count("\n") + 1;
|
||||||
|
length = data.length;
|
||||||
|
this.dishStr = data;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.manager.highlighter.removeHighlights();
|
this.manager.highlighter.removeHighlights();
|
||||||
const lines = dataStr.count("\n") + 1;
|
this.setOutputInfo(length, lines, duration);
|
||||||
this.setOutputInfo(dataStr.length, lines, duration);
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows file details.
|
||||||
|
*
|
||||||
|
* @param {ArrayBuffer} buf
|
||||||
|
*/
|
||||||
|
OutputWaiter.prototype.setFile = function(buf) {
|
||||||
|
this.dishBuffer = buf;
|
||||||
|
const file = new File([buf], "output.dat");
|
||||||
|
|
||||||
|
// Display file overlay in output area with details
|
||||||
|
const fileOverlay = document.getElementById("output-file"),
|
||||||
|
fileSize = document.getElementById("output-file-size");
|
||||||
|
|
||||||
|
fileOverlay.style.display = "block";
|
||||||
|
fileSize.textContent = file.size.toLocaleString() + " bytes";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the output file and nulls its memory.
|
||||||
|
*/
|
||||||
|
OutputWaiter.prototype.closeFile = function() {
|
||||||
|
this.dishBuffer = null;
|
||||||
|
document.getElementById("output-file").style.display = "none";
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for file download events.
|
||||||
|
*/
|
||||||
|
OutputWaiter.prototype.downloadFile = function() {
|
||||||
|
this.filename = window.prompt("Please enter a filename:", this.filename || "download.dat");
|
||||||
|
const file = new File([this.dishBuffer], this.filename);
|
||||||
|
|
||||||
|
if (this.filename) FileSaver.saveAs(file, this.filename, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for file slice display events.
|
||||||
|
*/
|
||||||
|
OutputWaiter.prototype.displayFileSlice = function() {
|
||||||
|
const startTime = new Date().getTime(),
|
||||||
|
showFileOverlay = document.getElementById("show-file-overlay"),
|
||||||
|
sliceFromEl = document.getElementById("output-file-slice-from"),
|
||||||
|
sliceToEl = document.getElementById("output-file-slice-to"),
|
||||||
|
sliceFrom = parseInt(sliceFromEl.value, 10),
|
||||||
|
sliceTo = parseInt(sliceToEl.value, 10),
|
||||||
|
str = Utils.arrayBufferToStr(this.dishBuffer.slice(sliceFrom, sliceTo));
|
||||||
|
|
||||||
|
showFileOverlay.style.display = "block";
|
||||||
|
this.set(str, "string", new Date().getTime() - startTime, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for show file overlay events.
|
||||||
|
*
|
||||||
|
* @param {Event} e
|
||||||
|
*/
|
||||||
|
OutputWaiter.prototype.showFileOverlayClick = function(e) {
|
||||||
|
const outputFile = document.getElementById("output-file"),
|
||||||
|
showFileOverlay = e.target;
|
||||||
|
|
||||||
|
outputFile.style.display = "block";
|
||||||
|
showFileOverlay.style.display = "none";
|
||||||
|
this.setOutputInfo(this.dishBuffer.byteLength, null, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -86,13 +194,17 @@ OutputWaiter.prototype.setOutputInfo = function(length, lines, duration) {
|
|||||||
let width = length.toString().length;
|
let width = length.toString().length;
|
||||||
width = width < 4 ? 4 : width;
|
width = width < 4 ? 4 : width;
|
||||||
|
|
||||||
const lengthStr = Utils.pad(length.toString(), width, " ").replace(/ /g, " ");
|
const lengthStr = length.toString().padStart(width, " ").replace(/ /g, " ");
|
||||||
const linesStr = Utils.pad(lines.toString(), width, " ").replace(/ /g, " ");
|
const timeStr = (duration.toString() + "ms").padStart(width, " ").replace(/ /g, " ");
|
||||||
const timeStr = Utils.pad(duration.toString() + "ms", width, " ").replace(/ /g, " ");
|
|
||||||
|
|
||||||
document.getElementById("output-info").innerHTML = "time: " + timeStr +
|
let msg = "time: " + timeStr + "<br>length: " + lengthStr;
|
||||||
"<br>length: " + lengthStr +
|
|
||||||
"<br>lines: " + linesStr;
|
if (typeof lines === "number") {
|
||||||
|
const linesStr = lines.toString().padStart(width, " ").replace(/ /g, " ");
|
||||||
|
msg += "<br>lines: " + linesStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("output-info").innerHTML = msg;
|
||||||
document.getElementById("input-selection-info").innerHTML = "";
|
document.getElementById("input-selection-info").innerHTML = "";
|
||||||
document.getElementById("output-selection-info").innerHTML = "";
|
document.getElementById("output-selection-info").innerHTML = "";
|
||||||
};
|
};
|
||||||
@ -105,17 +217,20 @@ OutputWaiter.prototype.setOutputInfo = function(length, lines, duration) {
|
|||||||
OutputWaiter.prototype.adjustWidth = function() {
|
OutputWaiter.prototype.adjustWidth = function() {
|
||||||
const output = document.getElementById("output");
|
const output = document.getElementById("output");
|
||||||
const saveToFile = document.getElementById("save-to-file");
|
const saveToFile = document.getElementById("save-to-file");
|
||||||
|
const copyOutput = document.getElementById("copy-output");
|
||||||
const switchIO = document.getElementById("switch");
|
const switchIO = document.getElementById("switch");
|
||||||
const undoSwitch = document.getElementById("undo-switch");
|
const undoSwitch = document.getElementById("undo-switch");
|
||||||
const maximiseOutput = document.getElementById("maximise-output");
|
const maximiseOutput = document.getElementById("maximise-output");
|
||||||
|
|
||||||
if (output.clientWidth < 680) {
|
if (output.clientWidth < 680) {
|
||||||
saveToFile.childNodes[1].nodeValue = "";
|
saveToFile.childNodes[1].nodeValue = "";
|
||||||
|
copyOutput.childNodes[1].nodeValue = "";
|
||||||
switchIO.childNodes[1].nodeValue = "";
|
switchIO.childNodes[1].nodeValue = "";
|
||||||
undoSwitch.childNodes[1].nodeValue = "";
|
undoSwitch.childNodes[1].nodeValue = "";
|
||||||
maximiseOutput.childNodes[1].nodeValue = "";
|
maximiseOutput.childNodes[1].nodeValue = "";
|
||||||
} else {
|
} else {
|
||||||
saveToFile.childNodes[1].nodeValue = " Save to file";
|
saveToFile.childNodes[1].nodeValue = " Save to file";
|
||||||
|
copyOutput.childNodes[1].nodeValue = " Copy output";
|
||||||
switchIO.childNodes[1].nodeValue = " Move output to input";
|
switchIO.childNodes[1].nodeValue = " Move output to input";
|
||||||
undoSwitch.childNodes[1].nodeValue = " Undo";
|
undoSwitch.childNodes[1].nodeValue = " Undo";
|
||||||
maximiseOutput.childNodes[1].nodeValue =
|
maximiseOutput.childNodes[1].nodeValue =
|
||||||
@ -126,24 +241,51 @@ OutputWaiter.prototype.adjustWidth = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for save click events.
|
* Handler for save click events.
|
||||||
* Saves the current output to a file, downloaded as a URL octet stream.
|
* Saves the current output to a file.
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.saveClick = function() {
|
OutputWaiter.prototype.saveClick = function() {
|
||||||
const data = Utils.toBase64(this.app.dishStr);
|
if (!this.dishBuffer) {
|
||||||
const filename = window.prompt("Please enter a filename:", "download.dat");
|
this.dishBuffer = new Uint8Array(Utils.strToCharcode(this.dishStr)).buffer;
|
||||||
|
|
||||||
if (filename) {
|
|
||||||
const el = document.createElement("a");
|
|
||||||
el.setAttribute("href", "data:application/octet-stream;base64;charset=utf-8," + data);
|
|
||||||
el.setAttribute("download", filename);
|
|
||||||
|
|
||||||
// Firefox requires that the element be added to the DOM before it can be clicked
|
|
||||||
el.style.display = "none";
|
|
||||||
document.body.appendChild(el);
|
|
||||||
|
|
||||||
el.click();
|
|
||||||
el.remove();
|
|
||||||
}
|
}
|
||||||
|
this.downloadFile();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for copy click events.
|
||||||
|
* Copies the output to the clipboard.
|
||||||
|
*/
|
||||||
|
OutputWaiter.prototype.copyClick = function() {
|
||||||
|
// Create invisible textarea to populate with the raw dishStr (not the printable version that
|
||||||
|
// contains dots instead of the actual bytes)
|
||||||
|
const textarea = document.createElement("textarea");
|
||||||
|
textarea.style.position = "fixed";
|
||||||
|
textarea.style.top = 0;
|
||||||
|
textarea.style.left = 0;
|
||||||
|
textarea.style.width = 0;
|
||||||
|
textarea.style.height = 0;
|
||||||
|
textarea.style.border = "none";
|
||||||
|
|
||||||
|
textarea.value = this.dishStr;
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
|
||||||
|
// Select and copy the contents of this textarea
|
||||||
|
let success = false;
|
||||||
|
try {
|
||||||
|
textarea.select();
|
||||||
|
success = this.dishStr && document.execCommand("copy");
|
||||||
|
} catch (err) {
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
this.app.alert("Copied raw output successfully.", "success", 2000);
|
||||||
|
} else {
|
||||||
|
this.app.alert("Sorry, the output could not be copied.", "danger", 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
document.body.removeChild(textarea);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -154,7 +296,17 @@ OutputWaiter.prototype.saveClick = function() {
|
|||||||
OutputWaiter.prototype.switchClick = function() {
|
OutputWaiter.prototype.switchClick = function() {
|
||||||
this.switchOrigData = this.manager.input.get();
|
this.switchOrigData = this.manager.input.get();
|
||||||
document.getElementById("undo-switch").disabled = false;
|
document.getElementById("undo-switch").disabled = false;
|
||||||
this.app.setInput(this.app.dishStr);
|
if (this.dishBuffer) {
|
||||||
|
this.manager.input.setFile(new File([this.dishBuffer], "output.dat"));
|
||||||
|
this.manager.input.handleLoaderMessage({
|
||||||
|
data: {
|
||||||
|
progress: 100,
|
||||||
|
fileBuffer: this.dishBuffer
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.app.setInput(this.dishStr);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -169,7 +321,7 @@ OutputWaiter.prototype.undoSwitchClick = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for file switch click events.
|
* Handler for file switch click events.
|
||||||
* Moves a files data for items created via Utils.displayFilesAsHTML to the input.
|
* Moves a file's data for items created via Utils.displayFilesAsHTML to the input.
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.fileSwitch = function(e) {
|
OutputWaiter.prototype.fileSwitch = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -241,4 +393,14 @@ OutputWaiter.prototype.setStatusMsg = function(msg) {
|
|||||||
el.textContent = msg;
|
el.textContent = msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the output contains carriage returns
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
OutputWaiter.prototype.containsCR = function() {
|
||||||
|
return this.dishStr.indexOf("\r") >= 0;
|
||||||
|
};
|
||||||
|
|
||||||
export default OutputWaiter;
|
export default OutputWaiter;
|
||||||
|
@ -253,7 +253,7 @@ RecipeWaiter.prototype.breakpointClick = function(e) {
|
|||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.operationDblclick = function(e) {
|
RecipeWaiter.prototype.operationDblclick = function(e) {
|
||||||
e.target.remove();
|
e.target.remove();
|
||||||
window.dispatchEvent(this.manager.statechange);
|
this.opRemove(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ RecipeWaiter.prototype.operationDblclick = function(e) {
|
|||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.operationChildDblclick = function(e) {
|
RecipeWaiter.prototype.operationChildDblclick = function(e) {
|
||||||
e.target.parentNode.remove();
|
e.target.parentNode.remove();
|
||||||
window.dispatchEvent(this.manager.statechange);
|
this.opRemove(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -421,6 +421,7 @@ RecipeWaiter.prototype.dropdownToggleClick = function(e) {
|
|||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.opAdd = function(e) {
|
RecipeWaiter.prototype.opAdd = function(e) {
|
||||||
|
log.debug(`'${e.target.querySelector(".arg-title").textContent}' added to recipe`);
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -433,6 +434,7 @@ RecipeWaiter.prototype.opAdd = function(e) {
|
|||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.opRemove = function(e) {
|
RecipeWaiter.prototype.opRemove = function(e) {
|
||||||
|
log.debug("Operation removed from recipe");
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import Utils from "../core/Utils.js";
|
|
||||||
import ChefWorker from "worker-loader?inline&fallback=false!../core/ChefWorker.js";
|
import ChefWorker from "worker-loader?inline&fallback=false!../core/ChefWorker.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,8 +21,10 @@ const WorkerWaiter = function(app, manager) {
|
|||||||
* Sets up the ChefWorker and associated listeners.
|
* Sets up the ChefWorker and associated listeners.
|
||||||
*/
|
*/
|
||||||
WorkerWaiter.prototype.registerChefWorker = function() {
|
WorkerWaiter.prototype.registerChefWorker = function() {
|
||||||
|
log.debug("Registering new ChefWorker");
|
||||||
this.chefWorker = new ChefWorker();
|
this.chefWorker = new ChefWorker();
|
||||||
this.chefWorker.addEventListener("message", this.handleChefMessage.bind(this));
|
this.chefWorker.addEventListener("message", this.handleChefMessage.bind(this));
|
||||||
|
this.setLogLevel();
|
||||||
|
|
||||||
let docURL = document.location.href.split(/[#?]/)[0];
|
let docURL = document.location.href.split(/[#?]/)[0];
|
||||||
const index = docURL.lastIndexOf("/");
|
const index = docURL.lastIndexOf("/");
|
||||||
@ -41,8 +42,10 @@ WorkerWaiter.prototype.registerChefWorker = function() {
|
|||||||
*/
|
*/
|
||||||
WorkerWaiter.prototype.handleChefMessage = function(e) {
|
WorkerWaiter.prototype.handleChefMessage = function(e) {
|
||||||
const r = e.data;
|
const r = e.data;
|
||||||
|
log.debug("Receiving '" + r.action + "' from ChefWorker");
|
||||||
|
|
||||||
switch (r.action) {
|
switch (r.action) {
|
||||||
case "bakeSuccess":
|
case "bakeComplete":
|
||||||
this.bakingComplete(r.data);
|
this.bakingComplete(r.data);
|
||||||
break;
|
break;
|
||||||
case "bakeError":
|
case "bakeError":
|
||||||
@ -53,12 +56,14 @@ WorkerWaiter.prototype.handleChefMessage = function(e) {
|
|||||||
break;
|
break;
|
||||||
case "workerLoaded":
|
case "workerLoaded":
|
||||||
this.app.workerLoaded = true;
|
this.app.workerLoaded = true;
|
||||||
|
log.debug("ChefWorker loaded");
|
||||||
this.app.loaded();
|
this.app.loaded();
|
||||||
break;
|
break;
|
||||||
case "statusMessage":
|
case "statusMessage":
|
||||||
this.manager.output.setStatusMsg(r.data);
|
this.manager.output.setStatusMsg(r.data);
|
||||||
break;
|
break;
|
||||||
case "optionUpdate":
|
case "optionUpdate":
|
||||||
|
log.debug(`Setting ${r.data.option} to ${r.data.value}`);
|
||||||
this.app.options[r.data.option] = r.data.value;
|
this.app.options[r.data.option] = r.data.value;
|
||||||
break;
|
break;
|
||||||
case "setRegisters":
|
case "setRegisters":
|
||||||
@ -68,7 +73,7 @@ WorkerWaiter.prototype.handleChefMessage = function(e) {
|
|||||||
this.manager.highlighter.displayHighlights(r.data.pos, r.data.direction);
|
this.manager.highlighter.displayHighlights(r.data.pos, r.data.direction);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error("Unrecognised message from ChefWorker", e);
|
log.error("Unrecognised message from ChefWorker", e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -111,10 +116,10 @@ WorkerWaiter.prototype.bakingComplete = function(response) {
|
|||||||
this.app.handleError(response.error);
|
this.app.handleError(response.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.app.dishStr = response.type === "html" ? Utils.stripHtmlTags(response.result, true) : response.result;
|
|
||||||
this.app.progress = response.progress;
|
this.app.progress = response.progress;
|
||||||
this.manager.recipe.updateBreakpointIndicator(response.progress);
|
this.manager.recipe.updateBreakpointIndicator(response.progress);
|
||||||
this.manager.output.set(response.result, response.type, response.duration);
|
this.manager.output.set(response.result, response.type, response.duration);
|
||||||
|
log.debug("--- Bake complete ---");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +152,7 @@ WorkerWaiter.prototype.bake = function(input, recipeConfig, options, progress, s
|
|||||||
* Asks the ChefWorker to run a silent bake, forcing the browser to load and cache all the relevant
|
* Asks the ChefWorker to run a silent bake, forcing the browser to load and cache all the relevant
|
||||||
* JavaScript code needed to do a real bake.
|
* JavaScript code needed to do a real bake.
|
||||||
*
|
*
|
||||||
* @param {Objectp[]} [recipeConfig]
|
* @param {Object[]} [recipeConfig]
|
||||||
*/
|
*/
|
||||||
WorkerWaiter.prototype.silentBake = function(recipeConfig) {
|
WorkerWaiter.prototype.silentBake = function(recipeConfig) {
|
||||||
this.chefWorker.postMessage({
|
this.chefWorker.postMessage({
|
||||||
@ -180,4 +185,19 @@ WorkerWaiter.prototype.highlight = function(recipeConfig, direction, pos) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the console log level in the worker.
|
||||||
|
*
|
||||||
|
* @param {string} level
|
||||||
|
*/
|
||||||
|
WorkerWaiter.prototype.setLogLevel = function(level) {
|
||||||
|
if (!this.chefWorker) return;
|
||||||
|
|
||||||
|
this.chefWorker.postMessage({
|
||||||
|
action: "setLogLevel",
|
||||||
|
data: log.getLevel()
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export default WorkerWaiter;
|
export default WorkerWaiter;
|
||||||
|
@ -59,6 +59,9 @@
|
|||||||
"for i in range(additional): Pylon()",
|
"for i in range(additional): Pylon()",
|
||||||
"(creating unresolved tension...",
|
"(creating unresolved tension...",
|
||||||
"Symlinking emacs and vim to ed...",
|
"Symlinking emacs and vim to ed...",
|
||||||
|
"Training branch predictor...",
|
||||||
|
"Timing cache hits...",
|
||||||
|
"Speculatively executing recipes..."
|
||||||
];
|
];
|
||||||
|
|
||||||
// Shuffle array using Durstenfeld algorithm
|
// Shuffle array using Durstenfeld algorithm
|
||||||
@ -115,7 +118,7 @@
|
|||||||
<span id="notice">
|
<span id="notice">
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// Must be text/javascript rather than application/javascript otherwise IE won't recognise it...
|
// Must be text/javascript rather than application/javascript otherwise IE won't recognise it...
|
||||||
if (navigator.userAgent && navigator.userAgent.match(/MSIE \d\d?\./)) {
|
if (navigator.userAgent && navigator.userAgent.match(/Trident/)) {
|
||||||
document.write("Internet Explorer is not supported, please use Firefox or Chrome instead");
|
document.write("Internet Explorer is not supported, please use Firefox or Chrome instead");
|
||||||
alert("Internet Explorer is not supported, please use Firefox or Chrome instead");
|
alert("Internet Explorer is not supported, please use Firefox or Chrome instead");
|
||||||
}
|
}
|
||||||
@ -181,6 +184,20 @@
|
|||||||
<div class="textarea-wrapper no-select">
|
<div class="textarea-wrapper no-select">
|
||||||
<div id="input-highlighter" class="no-select"></div>
|
<div id="input-highlighter" class="no-select"></div>
|
||||||
<textarea id="input-text"></textarea>
|
<textarea id="input-text"></textarea>
|
||||||
|
<div id="input-file">
|
||||||
|
<div style="position: relative; height: 100%;">
|
||||||
|
<div class="card">
|
||||||
|
<img aria-hidden="true" src="<%- require('../static/images/file-128x128.png') %>" alt="File icon"/>
|
||||||
|
<div class="card-body">
|
||||||
|
<button type="button" class="close" id="input-file-close">×</button>
|
||||||
|
Name: <span id="input-file-name"></span><br>
|
||||||
|
Size: <span id="input-file-size"></span><br>
|
||||||
|
Type: <span id="input-file-type"></span><br>
|
||||||
|
Loaded: <span id="input-file-loaded"></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -189,6 +206,7 @@
|
|||||||
<label for="output-text">Output</label>
|
<label for="output-text">Output</label>
|
||||||
<div class="btn-group io-btn-group">
|
<div class="btn-group io-btn-group">
|
||||||
<button type="button" class="btn btn-default btn-sm" id="save-to-file" title="Save to file"><img aria-hidden="true" src="<%- require('../static/images/save_as-16x16.png') %>" alt="Save Icon"/> Save to file</button>
|
<button type="button" class="btn btn-default btn-sm" id="save-to-file" title="Save to file"><img aria-hidden="true" src="<%- require('../static/images/save_as-16x16.png') %>" alt="Save Icon"/> Save to file</button>
|
||||||
|
<button type="button" class="btn btn-default btn-sm" id="copy-output" title="Copy output"><img aria-hidden="true" src="<%- require('../static/images/copy-16x16.png') %>" alt="Copy Icon"/> Copy raw output</button>
|
||||||
<button type="button" class="btn btn-default btn-sm" id="switch" title="Move output to input"><img aria-hidden="true" src="<%- require('../static/images/switch-16x16.png') %>" alt="Switch Icon"/> Move output to input</button>
|
<button type="button" class="btn btn-default btn-sm" id="switch" title="Move output to input"><img aria-hidden="true" src="<%- require('../static/images/switch-16x16.png') %>" alt="Switch Icon"/> Move output to input</button>
|
||||||
<button type="button" class="btn btn-default btn-sm" id="undo-switch" title="Undo move" disabled="disabled"><img aria-hidden="true" src="<%- require('../static/images/undo-16x16.png') %>" alt="Undo Icon"/> Undo</button>
|
<button type="button" class="btn btn-default btn-sm" id="undo-switch" title="Undo move" disabled="disabled"><img aria-hidden="true" src="<%- require('../static/images/undo-16x16.png') %>" alt="Undo Icon"/> Undo</button>
|
||||||
<button type="button" class="btn btn-default btn-sm" id="maximise-output" title="Maximise"><img aria-hidden="true" src="<%- require('../static/images/maximise-16x16.png') %>" alt="Maximise Icon"/> Max</button>
|
<button type="button" class="btn btn-default btn-sm" id="maximise-output" title="Maximise"><img aria-hidden="true" src="<%- require('../static/images/maximise-16x16.png') %>" alt="Maximise Icon"/> Max</button>
|
||||||
@ -201,6 +219,26 @@
|
|||||||
<div id="output-highlighter" class="no-select"></div>
|
<div id="output-highlighter" class="no-select"></div>
|
||||||
<div id="output-html"></div>
|
<div id="output-html"></div>
|
||||||
<textarea id="output-text" readonly="readonly"></textarea>
|
<textarea id="output-text" readonly="readonly"></textarea>
|
||||||
|
<img id="show-file-overlay" aria-hidden="true" src="<%- require('../static/images/file-32x32.png') %>" alt="Show file overlay" title="Show file overlay"/>
|
||||||
|
<div id="output-file">
|
||||||
|
<div style="position: relative; height: 100%;">
|
||||||
|
<div class="card">
|
||||||
|
<img aria-hidden="true" src="<%- require('../static/images/file-128x128.png') %>" alt="File icon"/>
|
||||||
|
<div class="card-body">
|
||||||
|
Size: <span id="output-file-size"></span><br>
|
||||||
|
<button id="output-file-download" type="button" class="btn btn-primary">Download</button>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button id="output-file-slice" type="button" class="btn btn-default" title="View slice">🔍</button>
|
||||||
|
</span>
|
||||||
|
<input type="number" class="form-control" id="output-file-slice-from" placeholder="From" value="0" step="1024" min="0">
|
||||||
|
<div class="input-group-addon">to</div>
|
||||||
|
<input type="number" class="form-control" id="output-file-slice-to" placeholder="To" value="1024" step="1024" min="0">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div id="output-loader">
|
<div id="output-loader">
|
||||||
<div class="loader"></div>
|
<div class="loader"></div>
|
||||||
<div class="loading-msg"></div>
|
<div class="loading-msg"></div>
|
||||||
@ -307,27 +345,46 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="option-item">
|
<div class="option-item">
|
||||||
<input type="checkbox" option="updateUrl" id="updateUrl" checked />
|
<input type="checkbox" option="updateUrl" id="updateUrl" checked />
|
||||||
<label for="updateUrl"> Update the URL when the input or recipe changes </label>
|
<label for="updateUrl"> Update the URL when the input or recipe changes</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="option-item">
|
<div class="option-item">
|
||||||
<input type="checkbox" option="showHighlighter" id="showHighlighter" checked />
|
<input type="checkbox" option="showHighlighter" id="showHighlighter" checked />
|
||||||
<label for="showHighlighter"> Highlight selected bytes in output and input (when possible) </label>
|
<label for="showHighlighter"> Highlight selected bytes in output and input (when possible)</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="option-item">
|
<div class="option-item">
|
||||||
<input type="checkbox" option="treatAsUtf8" id="treatAsUtf8" checked />
|
<input type="checkbox" option="treatAsUtf8" id="treatAsUtf8" checked />
|
||||||
<label for="treatAsUtf8"> Treat output as UTF-8 if possible </label>
|
<label for="treatAsUtf8"> Treat output as UTF-8 if possible</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="option-item">
|
<div class="option-item">
|
||||||
<input type="checkbox" option="wordWrap" id="wordWrap" checked />
|
<input type="checkbox" option="wordWrap" id="wordWrap" checked />
|
||||||
<label for="wordWrap"> Word wrap the input and output </label>
|
<label for="wordWrap"> Word wrap the input and output</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="option-item">
|
<div class="option-item">
|
||||||
<input type="checkbox" option="showErrors" id="showErrors" checked />
|
<input type="checkbox" option="showErrors" id="showErrors" checked />
|
||||||
<label for="showErrors"> Operation error reporting (recommended) </label>
|
<label for="showErrors"> Operation error reporting (recommended)</label>
|
||||||
|
</div>
|
||||||
|
<div class="option-item">
|
||||||
|
<input type="checkbox" option="useMetaKey" id="useMetaKey" />
|
||||||
|
<label for="useMetaKey"> Use meta key for keybindings (Windows ⊞/Command ⌘)</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="option-item">
|
<div class="option-item">
|
||||||
<input type="number" option="errorTimeout" id="errorTimeout" />
|
<input type="number" option="errorTimeout" id="errorTimeout" />
|
||||||
<label for="errorTimeout"> Operation error timeout in ms (0 for never) </label>
|
<label for="errorTimeout"> Operation error timeout in ms (0 for never)</label>
|
||||||
|
</div>
|
||||||
|
<div class="option-item">
|
||||||
|
<input type="number" option="ioDisplayThreshold" id="ioDisplayThreshold" />
|
||||||
|
<label for="ioDisplayThreshold"> Size threshold for treating the input and output as a file (KiB)</label>
|
||||||
|
</div>
|
||||||
|
<div class="option-item">
|
||||||
|
<select option="logLevel" id="logLevel">
|
||||||
|
<option value="silent">Silent</option>
|
||||||
|
<option value="error">Error</option>
|
||||||
|
<option value="warn">Warn</option>
|
||||||
|
<option value="info">Info</option>
|
||||||
|
<option value="debug">Debug</option>
|
||||||
|
<option value="trace">Trace</option>
|
||||||
|
</select>
|
||||||
|
<label for="logLevel"> Console logging level</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
@ -380,6 +437,11 @@
|
|||||||
</p>
|
</p>
|
||||||
<p>© Crown Copyright 2016.</p>
|
<p>© Crown Copyright 2016.</p>
|
||||||
<p>Released under the Apache Licence, Version 2.0.</p>
|
<p>Released under the Apache Licence, Version 2.0.</p>
|
||||||
|
<p>
|
||||||
|
<a href="https://gitter.im/gchq/CyberChef">
|
||||||
|
<img src="<%- require('../static/images/gitter-badge.svg') %>">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<div>
|
<div>
|
||||||
@ -396,6 +458,10 @@
|
|||||||
<img aria-hidden="true" src="<%- require('../static/images/speech-16x16.png') %>" alt="Speech Balloon Icon"/>
|
<img aria-hidden="true" src="<%- require('../static/images/speech-16x16.png') %>" alt="Speech Balloon Icon"/>
|
||||||
About
|
About
|
||||||
</a></li>
|
</a></li>
|
||||||
|
<li role="presentation"><a href="#keybindings" aria-controls="messages" role="tab" data-toggle="tab">
|
||||||
|
<img aria-hidden="true" src="<%- require('../static/images/code-16x16.png') %>" alt="List Icon"/>
|
||||||
|
Keybindings
|
||||||
|
</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div role="tabpanel" class="tab-pane active" id="faqs">
|
<div role="tabpanel" class="tab-pane active" id="faqs">
|
||||||
@ -414,7 +480,7 @@
|
|||||||
<li><a href="#recipe=From_Hexdump()Gunzip()&input=MDAwMDAwMDAgIDFmIDhiIDA4IDAwIDEyIGJjIGYzIDU3IDAwIGZmIDBkIGM3IGMxIDA5IDAwIDIwICB8Li4uLi6881cu/y7HwS4uIHwKMDAwMDAwMTAgIDA4IDA1IGQwIDU1IGZlIDA0IDJkIGQzIDA0IDFmIGNhIDhjIDQ0IDIxIDViIGZmICB8Li7QVf4uLdMuLsouRCFb/3wKMDAwMDAwMjAgIDYwIGM3IGQ3IDAzIDE2IGJlIDQwIDFmIDc4IDRhIDNmIDA5IDg5IDBiIDlhIDdkICB8YMfXLi6%2BQC54Sj8uLi4ufXwKMDAwMDAwMzAgIDRlIGM4IDRlIDZkIDA1IDFlIDAxIDhiIDRjIDI0IDAwIDAwIDAwICAgICAgICAgICB8TshObS4uLi5MJC4uLnw">Convert data from a hexdump, then decompress</a></li>
|
<li><a href="#recipe=From_Hexdump()Gunzip()&input=MDAwMDAwMDAgIDFmIDhiIDA4IDAwIDEyIGJjIGYzIDU3IDAwIGZmIDBkIGM3IGMxIDA5IDAwIDIwICB8Li4uLi6881cu/y7HwS4uIHwKMDAwMDAwMTAgIDA4IDA1IGQwIDU1IGZlIDA0IDJkIGQzIDA0IDFmIGNhIDhjIDQ0IDIxIDViIGZmICB8Li7QVf4uLdMuLsouRCFb/3wKMDAwMDAwMjAgIDYwIGM3IGQ3IDAzIDE2IGJlIDQwIDFmIDc4IDRhIDNmIDA5IDg5IDBiIDlhIDdkICB8YMfXLi6%2BQC54Sj8uLi4ufXwKMDAwMDAwMzAgIDRlIGM4IDRlIDZkIDA1IDFlIDAxIDhiIDRjIDI0IDAwIDAwIDAwICAgICAgICAgICB8TshObS4uLi5MJC4uLnw">Convert data from a hexdump, then decompress</a></li>
|
||||||
<li><a href="#recipe=RC4(%7B'option':'UTF8','string':'secret'%7D,'Hex','Hex')Disassemble_x86('64','Full%20x86%20architecture',16,0,true,true)&input=MjFkZGQyNTQwMTYwZWU2NWZlMDc3NzEwM2YyYTM5ZmJlNWJjYjZhYTBhYWJkNDE0ZjkwYzZjYWY1MzEyNzU0YWY3NzRiNzZiM2JiY2QxOTNjYjNkZGZkYmM1YTI2NTMzYTY4NmI1OWI4ZmVkNGQzODBkNDc0NDIwMWFlYzIwNDA1MDcxMzhlMmZlMmIzOTUwNDQ2ZGIzMWQyYmM2MjliZTRkM2YyZWIwMDQzYzI5M2Q3YTVkMjk2MmMwMGZlNmRhMzAwNzJkOGM1YTZiNGZlN2Q4NTlhMDQwZWVhZjI5OTczMzYzMDJmNWEwZWMxOQ">Decrypt and disassemble shellcode</a></li>
|
<li><a href="#recipe=RC4(%7B'option':'UTF8','string':'secret'%7D,'Hex','Hex')Disassemble_x86('64','Full%20x86%20architecture',16,0,true,true)&input=MjFkZGQyNTQwMTYwZWU2NWZlMDc3NzEwM2YyYTM5ZmJlNWJjYjZhYTBhYWJkNDE0ZjkwYzZjYWY1MzEyNzU0YWY3NzRiNzZiM2JiY2QxOTNjYjNkZGZkYmM1YTI2NTMzYTY4NmI1OWI4ZmVkNGQzODBkNDc0NDIwMWFlYzIwNDA1MDcxMzhlMmZlMmIzOTUwNDQ2ZGIzMWQyYmM2MjliZTRkM2YyZWIwMDQzYzI5M2Q3YTVkMjk2MmMwMGZlNmRhMzAwNzJkOGM1YTZiNGZlN2Q4NTlhMDQwZWVhZjI5OTczMzYzMDJmNWEwZWMxOQ">Decrypt and disassemble shellcode</a></li>
|
||||||
<li><a href="#recipe=Fork('%5C%5Cn','%5C%5Cn',false)From_UNIX_Timestamp('Seconds%20(s)')&input=OTc4MzQ2ODAwCjEwMTI2NTEyMDAKMTA0NjY5NjQwMAoxMDgxMDg3MjAwCjExMTUzMDUyMDAKMTE0OTYwOTYwMA">Display multiple timestamps as full dates</a></li>
|
<li><a href="#recipe=Fork('%5C%5Cn','%5C%5Cn',false)From_UNIX_Timestamp('Seconds%20(s)')&input=OTc4MzQ2ODAwCjEwMTI2NTEyMDAKMTA0NjY5NjQwMAoxMDgxMDg3MjAwCjExMTUzMDUyMDAKMTE0OTYwOTYwMA">Display multiple timestamps as full dates</a></li>
|
||||||
<li><a href="#recipe=Fork('%5C%5Cn','%5C%5Cn',false)Conditional_Jump('1',2,10)To_Hex('Space')Return()To_Base64('A-Za-z0-9%2B/%3D')&input=U29tZSBkYXRhIHdpdGggYSAxIGluIGl0ClNvbWUgZGF0YSB3aXRoIGEgMiBpbiBpdA">Carry out different operations on data of different types</a></li>
|
<li><a href="#recipe=Fork('%5C%5Cn','%5C%5Cn',false)Conditional_Jump('1',false,'base64',10)To_Hex('Space')Return()Label('base64')To_Base64('A-Za-z0-9%2B/%3D')&input=U29tZSBkYXRhIHdpdGggYSAxIGluIGl0ClNvbWUgZGF0YSB3aXRoIGEgMiBpbiBpdA">Carry out different operations on data of different types</a></li>
|
||||||
<li><a href="#recipe=Register('key%3D(%5B%5C%5Cda-f%5D*)',true,false)Find_/_Replace(%7B'option':'Regex','string':'.*data%3D(.*)'%7D,'$1',true,false,true)RC4(%7B'option':'Hex','string':'$R0'%7D,'Hex','Latin1')&input=aHR0cDovL21hbHdhcmV6LmJpei9iZWFjb24ucGhwP2tleT0wZTkzMmE1YyZkYXRhPThkYjdkNWViZTM4NjYzYTU0ZWNiYjMzNGUzZGIxMQ">Use parts of the input as arguments to operations</a></li>
|
<li><a href="#recipe=Register('key%3D(%5B%5C%5Cda-f%5D*)',true,false)Find_/_Replace(%7B'option':'Regex','string':'.*data%3D(.*)'%7D,'$1',true,false,true)RC4(%7B'option':'Hex','string':'$R0'%7D,'Hex','Latin1')&input=aHR0cDovL21hbHdhcmV6LmJpei9iZWFjb24ucGhwP2tleT0wZTkzMmE1YyZkYXRhPThkYjdkNWViZTM4NjYzYTU0ZWNiYjMzNGUzZGIxMQ">Use parts of the input as arguments to operations</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -424,8 +490,9 @@
|
|||||||
</a>
|
</a>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<div class="collapse" id="faq-load-files">
|
<div class="collapse" id="faq-load-files">
|
||||||
<p>Yes! Just drag your file over the input box and drop it. The contents of the file will be converted into hexadecimal and the 'From Hex' operation will be added to the beginning of the recipe (if it's not already there). This is so that special characters like carriage returns aren't removed by your browser.</p>
|
<p>Yes! Just drag your file over the input box and drop it.</p>
|
||||||
<p>Please note that loading large files is likely to cause a crash. There's not a lot that can be done about this - browsers just aren't very good at handling and displaying large amounts of data.</p>
|
<p>CyberChef can handle files up to around 500MB (depending on your browser), however some of the operations may take a very long time to run over this much data.</p>
|
||||||
|
<p>If the output is larger than a certain threshold (default 1MiB), it will be presented to you as a file available for download. Slices of the file can be viewed in the output if you need to inspect them.</p>
|
||||||
</div>
|
</div>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<a data-toggle="collapse" data-target="#faq-fork">
|
<a data-toggle="collapse" data-target="#faq-fork">
|
||||||
@ -468,9 +535,12 @@
|
|||||||
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<p>There are around 150 useful operations in CyberChef for anyone working on anything vaguely Internet-related, whether you just want to convert a timestamp to a different format, decompress gzipped data, create a SHA3 hash, or parse an X.509 certificate to find out who issued it.</p>
|
<p>There are around 200 useful operations in CyberChef for anyone working on anything vaguely Internet-related, whether you just want to convert a timestamp to a different format, decompress gzipped data, create a SHA3 hash, or parse an X.509 certificate to find out who issued it.</p>
|
||||||
<p>It’s the Cyber Swiss Army Knife.</p>
|
<p>It’s the Cyber Swiss Army Knife.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div role="tabpanel" class="tab-pane" id="keybindings" style="padding: 20px;">
|
||||||
|
<table class="table table-condensed table-bordered table-hover" id="keybList"></table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -46,6 +46,9 @@ function main() {
|
|||||||
errorTimeout: 4000,
|
errorTimeout: 4000,
|
||||||
attemptHighlight: true,
|
attemptHighlight: true,
|
||||||
theme: "classic",
|
theme: "classic",
|
||||||
|
useMetaKey: false,
|
||||||
|
ioDisplayThreshold: 512,
|
||||||
|
logLevel: "info"
|
||||||
};
|
};
|
||||||
|
|
||||||
document.removeEventListener("DOMContentLoaded", main, false);
|
document.removeEventListener("DOMContentLoaded", main, false);
|
||||||
@ -53,9 +56,6 @@ function main() {
|
|||||||
window.app.setup();
|
window.app.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix issues with browsers that don't support console.log()
|
|
||||||
window.console = console || {log: function() {}, error: function() {}};
|
|
||||||
|
|
||||||
window.compileTime = moment.tz(COMPILE_TIME, "DD/MM/YYYY HH:mm:ss z", "UTC").valueOf();
|
window.compileTime = moment.tz(COMPILE_TIME, "DD/MM/YYYY HH:mm:ss z", "UTC").valueOf();
|
||||||
window.compileMessage = COMPILE_MSG;
|
window.compileMessage = COMPILE_MSG;
|
||||||
|
|
||||||
|
BIN
src/web/static/images/copy-16x16.png
Executable file
BIN
src/web/static/images/copy-16x16.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 432 B |
BIN
src/web/static/images/file-128x128.png
Normal file
BIN
src/web/static/images/file-128x128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
BIN
src/web/static/images/file-32x32.png
Normal file
BIN
src/web/static/images/file-32x32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
0
src/web/static/images/fork_me.png
Normal file → Executable file
0
src/web/static/images/fork_me.png
Normal file → Executable file
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
1
src/web/static/images/gitter-badge.svg
Executable file
1
src/web/static/images/gitter-badge.svg
Executable file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="92" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="92" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h34v20H0z"/><path fill="#46BC99" d="M34 0h58v20H34z"/><path fill="url(#b)" d="M0 0h92v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="17" y="15" fill="#010101" fill-opacity=".3">chat</text><text x="17" y="14">chat</text><text x="62" y="15" fill="#010101" fill-opacity=".3">on gitter</text><text x="62" y="14">on gitter</text></g></svg>
|
After Width: | Height: | Size: 733 B |
@ -28,3 +28,56 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
|
||||||
|
transition: 0.3s;
|
||||||
|
width: 400px;
|
||||||
|
height: 150px;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
font-family: var(--primary-font-family);
|
||||||
|
color: var(--primary-font-colour);
|
||||||
|
line-height: 30px;
|
||||||
|
background-color: var(--primary-background-colour);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card:hover {
|
||||||
|
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card>img {
|
||||||
|
float: left;
|
||||||
|
width: 128px;
|
||||||
|
height: 128px;
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-top: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-body .close {
|
||||||
|
position: absolute;
|
||||||
|
right: 10px;
|
||||||
|
top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-body {
|
||||||
|
float: left;
|
||||||
|
padding: 16px;
|
||||||
|
width: 250px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
user-select: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-body>.btn {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card input[type=number] {
|
||||||
|
padding-right: 6px;
|
||||||
|
padding-left: 6px;
|
||||||
|
}
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.textarea-wrapper textarea,
|
.textarea-wrapper textarea,
|
||||||
.textarea-wrapper div {
|
.textarea-wrapper>div {
|
||||||
font-family: var(--fixed-width-font-family);
|
font-family: var(--fixed-width-font-family);
|
||||||
font-size: var(--fixed-width-font-size);
|
font-size: var(--fixed-width-font-size);
|
||||||
color: var(--fixed-width-font-colour);
|
color: var(--fixed-width-font-colour);
|
||||||
@ -77,6 +77,25 @@
|
|||||||
transition: all 0.5s ease;
|
transition: all 0.5s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#input-file,
|
||||||
|
#output-file {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: var(--title-background-colour);
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#show-file-overlay {
|
||||||
|
position: absolute;
|
||||||
|
right: 15px;
|
||||||
|
top: 15px;
|
||||||
|
cursor: pointer;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.io-btn-group {
|
.io-btn-group {
|
||||||
float: right;
|
float: right;
|
||||||
margin-top: -4px;
|
margin-top: -4px;
|
||||||
@ -92,6 +111,8 @@
|
|||||||
font-family: var(--fixed-width-font-family);
|
font-family: var(--fixed-width-font-family);
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-size: 8pt;
|
font-size: 8pt;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#input-info {
|
#input-info {
|
||||||
|
@ -64,7 +64,8 @@ a:focus {
|
|||||||
.alert,
|
.alert,
|
||||||
.modal-content,
|
.modal-content,
|
||||||
.tooltip-inner,
|
.tooltip-inner,
|
||||||
.dropdown-menu {
|
.dropdown-menu,
|
||||||
|
.input-group-addon {
|
||||||
border-radius: 0 !important;
|
border-radius: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +188,15 @@ optgroup {
|
|||||||
color: var(--primary-font-colour);
|
color: var(--primary-font-colour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.input-group-addon:not(:first-child):not(:last-child) {
|
||||||
|
border-left: 0;
|
||||||
|
border-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group-btn:first-child>.btn {
|
||||||
|
border-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Bootstrap-switch */
|
/* Bootstrap-switch */
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
/* eslint no-console: 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestRunner.js
|
* TestRunner.js
|
||||||
*
|
*
|
||||||
@ -25,6 +27,9 @@ import "./tests/operations/Hash.js";
|
|||||||
import "./tests/operations/Image.js";
|
import "./tests/operations/Image.js";
|
||||||
import "./tests/operations/MorseCode.js";
|
import "./tests/operations/MorseCode.js";
|
||||||
import "./tests/operations/MS.js";
|
import "./tests/operations/MS.js";
|
||||||
|
import "./tests/operations/PHP.js";
|
||||||
|
import "./tests/operations/NetBIOS.js";
|
||||||
|
import "./tests/operations/OTP.js";
|
||||||
import "./tests/operations/StrUtils.js";
|
import "./tests/operations/StrUtils.js";
|
||||||
import "./tests/operations/SeqUtils.js";
|
import "./tests/operations/SeqUtils.js";
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -310,4 +310,26 @@ TestRegister.addTests([
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "CSS selector",
|
||||||
|
input: '<div id="test">\n<p class="a">hello</p>\n<p>world</p>\n<p class="a">again</p>\n</div>',
|
||||||
|
expectedOutput: '<p class="a">hello</p>\n<p class="a">again</p>',
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "CSS selector",
|
||||||
|
"args": ["#test p.a", "\\n"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "XPath expression",
|
||||||
|
input: '<div id="test">\n<p class="a">hello</p>\n<p>world</p>\n<p class="a">again</p>\n</div>',
|
||||||
|
expectedOutput: '<p class="a">hello</p>\n<p class="a">again</p>',
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "XPath expression",
|
||||||
|
"args": ["/div/p[@class=\"a\"]", "\\n"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
]);
|
]);
|
||||||
|
@ -37,7 +37,7 @@ TestRegister.addTests([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Fork, (expect) Error, Merge",
|
name: "Fork, (expect) Error, Merge",
|
||||||
input: "1\n2\na\n4",
|
input: "1.1\n2.5\na\n3.4",
|
||||||
expectedError: true,
|
expectedError: true,
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
@ -45,8 +45,8 @@ TestRegister.addTests([
|
|||||||
args: ["\n", "\n", false],
|
args: ["\n", "\n", false],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "To Base",
|
op: "Object Identifier to Hex",
|
||||||
args: [16],
|
args: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "Merge",
|
op: "Merge",
|
||||||
@ -60,14 +60,15 @@ TestRegister.addTests([
|
|||||||
expectedOutput: "U29tZSBkYXRhIHdpdGggYSAxIGluIGl0\n53 6f 6d 65 20 64 61 74 61 20 77 69 74 68 20 61 20 32 20 69 6e 20 69 74\n",
|
expectedOutput: "U29tZSBkYXRhIHdpdGggYSAxIGluIGl0\n53 6f 6d 65 20 64 61 74 61 20 77 69 74 68 20 61 20 32 20 69 6e 20 69 74\n",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{"op": "Fork", "args": ["\\n", "\\n", false]},
|
{"op": "Fork", "args": ["\\n", "\\n", false]},
|
||||||
{"op": "Conditional Jump", "args": ["1", "2", "10"]},
|
{"op": "Conditional Jump", "args": ["1", false, "skipReturn", "10"]},
|
||||||
{"op": "To Hex", "args": ["Space"]},
|
{"op": "To Hex", "args": ["Space"]},
|
||||||
{"op": "Return", "args": []},
|
{"op": "Return", "args": []},
|
||||||
|
{"op": "Label", "args": ["skipReturn"]},
|
||||||
{"op": "To Base64", "args": ["A-Za-z0-9+/="]}
|
{"op": "To Base64", "args": ["A-Za-z0-9+/="]}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Jump: skips 0",
|
name: "Jump: Empty Label",
|
||||||
input: [
|
input: [
|
||||||
"should be changed",
|
"should be changed",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
@ -77,7 +78,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Jump",
|
op: "Jump",
|
||||||
args: [0, 10],
|
args: ["", 10],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "Find / Replace",
|
op: "Find / Replace",
|
||||||
@ -105,7 +106,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Jump",
|
op: "Jump",
|
||||||
args: [1, 10],
|
args: ["skipReplace", 10],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "Find / Replace",
|
op: "Find / Replace",
|
||||||
@ -120,6 +121,10 @@ TestRegister.addTests([
|
|||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
op: "Label",
|
||||||
|
args: ["skipReplace"]
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -137,7 +142,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Conditional Jump",
|
op: "Conditional Jump",
|
||||||
args: ["match", 0, 0],
|
args: ["match", false, "", 0],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "Find / Replace",
|
op: "Find / Replace",
|
||||||
@ -212,7 +217,7 @@ TestRegister.addTests([
|
|||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
op: "Conditional Jump",
|
op: "Conditional Jump",
|
||||||
args: ["match", 1, 10],
|
args: ["match", false, "skip match", 10],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "Find / Replace",
|
op: "Find / Replace",
|
||||||
@ -227,6 +232,9 @@ TestRegister.addTests([
|
|||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
op: "Label", args: ["skip match"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
op: "Find / Replace",
|
op: "Find / Replace",
|
||||||
args: [
|
args: [
|
||||||
@ -251,9 +259,13 @@ TestRegister.addTests([
|
|||||||
"replaced",
|
"replaced",
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Label",
|
||||||
|
args: ["back to the beginning"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
op: "Jump",
|
op: "Jump",
|
||||||
args: [1],
|
args: ["skip replace"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: "Find / Replace",
|
op: "Find / Replace",
|
||||||
@ -268,9 +280,13 @@ TestRegister.addTests([
|
|||||||
true,
|
true,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
op: "Label",
|
||||||
|
args: ["skip replace"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
op: "Conditional Jump",
|
op: "Conditional Jump",
|
||||||
args: ["match", -2, 10],
|
args: ["match", false, "back to the beginning", 10],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
34
test/tests/operations/NetBIOS.js
Normal file
34
test/tests/operations/NetBIOS.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* NetBIOS tests.
|
||||||
|
*
|
||||||
|
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||||
|
*
|
||||||
|
* @copyright Crown Copyright 2017
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../TestRegister.js";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "Encode NetBIOS name",
|
||||||
|
input: "The NetBIOS name",
|
||||||
|
expectedOutput: "FEGIGFCAEOGFHEECEJEPFDCAGOGBGNGF",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Encode NetBIOS Name",
|
||||||
|
args: [65],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Decode NetBIOS Name",
|
||||||
|
input: "FEGIGFCAEOGFHEECEJEPFDCAGOGBGNGF",
|
||||||
|
expectedOutput: "The NetBIOS name",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Decode NetBIOS Name",
|
||||||
|
args: [65],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
23
test/tests/operations/OTP.js
Normal file
23
test/tests/operations/OTP.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* OTP HOTP tests.
|
||||||
|
*
|
||||||
|
* @author bwhitn [brian.m.whitney@outlook.com]
|
||||||
|
*
|
||||||
|
* @copyright Crown Copyright 2017
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../TestRegister.js";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "Generate HOTP",
|
||||||
|
input: "12345678901234567890",
|
||||||
|
expectedOutput: "URI: otpauth://hotp/OTPAuthentication?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ\n\nPassword: 755224",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Generate HOTP",
|
||||||
|
args: ["", 32, 6, 0],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
68
test/tests/operations/PHP.js
Normal file
68
test/tests/operations/PHP.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/**
|
||||||
|
* PHP tests.
|
||||||
|
*
|
||||||
|
* @author Jarmo van Lenthe
|
||||||
|
*
|
||||||
|
* @copyright Crown Copyright 2017
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import TestRegister from "../../TestRegister.js";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "PHP Deserialize empty array",
|
||||||
|
input: "a:0:{}",
|
||||||
|
expectedOutput: "{}",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "PHP Deserialize",
|
||||||
|
args: [true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "PHP Deserialize integer",
|
||||||
|
input: "i:10;",
|
||||||
|
expectedOutput: "10",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "PHP Deserialize",
|
||||||
|
args: [true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "PHP Deserialize string",
|
||||||
|
input: "s:17:\"PHP Serialization\";",
|
||||||
|
expectedOutput: "\"PHP Serialization\"",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "PHP Deserialize",
|
||||||
|
args: [true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "PHP Deserialize array (JSON)",
|
||||||
|
input: "a:2:{s:1:\"a\";i:10;i:0;a:1:{s:2:\"ab\";b:1;}}",
|
||||||
|
expectedOutput: "{\"a\": 10,\"0\": {\"ab\": true}}",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "PHP Deserialize",
|
||||||
|
args: [true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "PHP Deserialize array (non-JSON)",
|
||||||
|
input: "a:2:{s:1:\"a\";i:10;i:0;a:1:{s:2:\"ab\";b:1;}}",
|
||||||
|
expectedOutput: "{\"a\": 10,0: {\"ab\": true}}",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "PHP Deserialize",
|
||||||
|
args: [false],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
@ -10,8 +10,8 @@ import TestRegister from "../../TestRegister.js";
|
|||||||
TestRegister.addTests([
|
TestRegister.addTests([
|
||||||
{
|
{
|
||||||
name: "SeqUtils - Numeric sort photos",
|
name: "SeqUtils - Numeric sort photos",
|
||||||
input: "Photo-1.jpg\nPhoto-4.jpg\nPhoto-2.jpg\nPhoto-3.jpg\n",
|
input: "Photo-1.jpg\nPhoto-4.jpg\nPhoto-2.jpg\nPhoto-3.jpg",
|
||||||
expectedOutput: "Photo-1.jpg\nPhoto-2.jpg\nPhoto-3.jpg\nPhoto-4.jpg\n",
|
expectedOutput: "Photo-1.jpg\nPhoto-2.jpg\nPhoto-3.jpg\nPhoto-4.jpg",
|
||||||
recipeConfig: [
|
recipeConfig: [
|
||||||
{
|
{
|
||||||
"op": "Sort",
|
"op": "Sort",
|
||||||
|
@ -35,7 +35,8 @@ module.exports = {
|
|||||||
new webpack.ProvidePlugin({
|
new webpack.ProvidePlugin({
|
||||||
$: "jquery",
|
$: "jquery",
|
||||||
jQuery: "jquery",
|
jQuery: "jquery",
|
||||||
moment: "moment-timezone"
|
moment: "moment-timezone",
|
||||||
|
log: "loglevel"
|
||||||
}),
|
}),
|
||||||
new webpack.BannerPlugin({
|
new webpack.BannerPlugin({
|
||||||
banner: banner,
|
banner: banner,
|
||||||
|
Loading…
Reference in New Issue
Block a user