Skip to content

Commit

Permalink
Fixed spelling errors, syntax errors, and improved the test for scrip…
Browse files Browse the repository at this point in the history
…t decoding
  • Loading branch information
bwhitn committed Aug 29, 2017
1 parent 0fc2a21 commit 934ed1a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/core/config/Categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Categories = [
"Encode text",
"Decode text",
"Swap endianness",
"Micrsoft Script Decoder",
"Microsoft Script Decoder",
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions src/core/config/OperationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ const OperationConfig = {
}
]
},

"To Charcode": {
description: "Converts text to its unicode character code equivalent.<br><br>e.g. <code>Γειά σου</code> becomes <code>0393 03b5 03b9 03ac 20 03c3 03bf 03c5</code>",
run: ByteRepr.runToCharcode,
Expand Down Expand Up @@ -3205,8 +3206,8 @@ const OperationConfig = {
}
]
},
"Micrsoft Script Decoder": {
description: "Decodes Microsoft Encoded Script files that have been encoded with Microsoft's custom encoding.",
"Microsoft Script Decoder": {
description: "Decodes Microsoft Encoded Script files that have been encoded with Microsoft's custom encoding. These are often VBS (Visual Basic Script) files that are encoded and often renamed &#34;.vbe&#34; extention or JS (JScript) files renamed with &#34;.jse&#34; extention.",
run: MS.runDecodeScript,
inputType: "string",
outputType: "string",
Expand Down
21 changes: 12 additions & 9 deletions src/core/operations/MS.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Decodes Microsft Encoded Script files that can be read and executed by cscript.exe/wscript.exe.
* Decodes Microsoft Encoded Script files that can be read and executed by cscript.exe/wscript.exe.
* This is a conversion of a Python script that was originally created by Didier Stevens (https://DidierStevens.com).
*
* @author bmwhitn [brian.m.whitney@outlook.com]
Expand Down Expand Up @@ -215,17 +215,18 @@ const MS = {
],

/**
* @private
* @param {string} data
* @returns {string}
*/
decode: function (data) {
_decode: function (data) {
let result = [];
let index = -1;
data = data.replace(/@&/g, String.fromCharCode(10));
data = data.replace(/@#/g, String.fromCharCode(13));
data = data.replace(/@\*/g, ">");
data = data.replace(/@!/g, "<");
data = data.replace(/@\$/g, "@");
data = data.replace(/@&/g, String.fromCharCode(10))
.replace(/@#/g, String.fromCharCode(13))
.replace(/@\*/g, ">")
.replace(/@!/g, "<")
.replace(/@\$/g, "@");
for (let i = 0; i < data.length; i++) {
let byte = data.charCodeAt(i);
let char = data.charAt(i);
Expand All @@ -241,15 +242,17 @@ const MS = {
},

/**
* Microsoft Script Decoder operation
*
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
runDecodeScript: function (input, args) {
let matcher = /#@~\^......==(.+)......==\^#~@/;
let matcher = /#@~\^.{6}==(.+).{6}==\^#~@/;
let encodedData = matcher.exec(input);
if (encodedData){
return MS.decode(encodedData[1]);
return MS._decode(encodedData[1]);
} else {
return "";
}
Expand Down
12 changes: 6 additions & 6 deletions test/tests/operations/MS.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* CharEnc tests.
* MS tests.
*
* @author tlwr [toby@toby.codes]
* @author bwhitn [brian.m.whitney@outlook.com]
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../../TestRegister.js";

TestRegister.addTests([
{
name: "Micrsoft Script Decoder",
input: "##@~^DgAAAA==\\ko$K6,JCV^GJqAQAAA==^#~@",
expectedOutput: "MsgBox \"Hello\"",
name: "Microsoft Script Decoder",
input: "#@~^RQAAAA==-mD~sX|:/TP{~J:+dYbxL~@!F@*@!+@*@!&@*eEI@#@&@#@&\x7fjm.raY 214Wv:zms/obI0xEAAA==^#~@",
expectedOutput: "var my_msg = \"Testing <1><2><3>!\";\r\n\r\nWScript.Echo(my_msg);",
recipeConfig: [
{
"op": "Micrsoft Script Decoder",
"op": "Microsoft Script Decoder",
"args": []
},
],
Expand Down

0 comments on commit 934ed1a

Please sign in to comment.