Fixed spelling errors, syntax errors, and improved the test for script decoding

This commit is contained in:
bwhitn 2017-08-29 10:46:34 -07:00
parent 0fc2a219a7
commit 934ed1af09
4 changed files with 22 additions and 18 deletions

View File

@ -66,7 +66,7 @@ const Categories = [
"Encode text",
"Decode text",
"Swap endianness",
"Micrsoft Script Decoder",
"Microsoft Script Decoder",
]
},
{

View File

@ -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,
@ -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",

View File

@ -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]
@ -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);
@ -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 "";
}

View File

@ -1,7 +1,7 @@
/**
* CharEnc tests.
* MS tests.
*
* @author tlwr [toby@toby.codes]
* @author bwhitn [brian.m.whitney@outlook.com]
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
@ -9,12 +9,12 @@ 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": []
},
],