Skip to content

Commit

Permalink
Merge branch 'feature-render-images'
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed May 19, 2017
2 parents 87c2ec6 + 5e79187 commit 67b78fc
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/core/config/Categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ const Categories = [
"Detect File Type",
"Scan for Embedded Files",
"Generate UUID",
"Render Image",
"Numberwang",
]
},
Expand Down
13 changes: 13 additions & 0 deletions src/core/config/OperationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3353,6 +3353,19 @@ const OperationConfig = {
outputType: "string",
args: [],
},
"Render Image": {
description: "Displays the input as an image. Supports the following formats:<br><br><ul><li>jpg/jpeg</li><li>png</li><li>gif</li><li>webp</li><li>bmp</li><li>ico</li></ul>",
run: Image.runRenderImage,
inputType: "string",
outputType: "html",
args: [
{
name: "Input format",
type: "option",
value: Image.INPUT_FORMAT
}
]
},
};

export default OperationConfig;
7 changes: 3 additions & 4 deletions src/core/operations/FileType.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FileType = {
* @returns {string}
*/
runDetect: function(input, args) {
const type = FileType._magicType(input);
const type = FileType.magicType(input);

if (!type) {
return "Unknown file type. Have you tried checking the entropy of this data to determine whether it might be encrypted or compressed?";
Expand Down Expand Up @@ -59,7 +59,7 @@ const FileType = {
numCommonFound = 0;

for (let i = 0; i < input.length; i++) {
type = FileType._magicType(input.slice(i));
type = FileType.magicType(input.slice(i));
if (type) {
if (ignoreCommon && commonExts.indexOf(type.ext) > -1) {
numCommonFound++;
Expand Down Expand Up @@ -96,14 +96,13 @@ const FileType = {
* Given a buffer, detects magic byte sequences at specific positions and returns the
* extension and mime type.
*
* @private
* @param {byteArray} buf
* @returns {Object} type
* @returns {string} type.ext - File extension
* @returns {string} type.mime - Mime type
* @returns {string} [type.desc] - Description
*/
_magicType: function (buf) {
magicType: function (buf) {
if (!(buf && buf.length > 1)) {
return null;
}
Expand Down
52 changes: 52 additions & 0 deletions src/core/operations/Image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as ExifParser from "exif-parser";
import Utils from "../Utils.js";
import FileType from "./FileType.js";


/**
Expand Down Expand Up @@ -42,6 +43,57 @@ const Image = {
}
},


/**
* @constant
* @default
*/
INPUT_FORMAT: ["Raw", "Base64", "Hex"],

/**
* Render Image operation.
*
* @author n1474335 [[email protected]]
* @param {string} input
* @param {Object[]} args
* @returns {html}
*/
runRenderImage(input, args) {
const inputFormat = args[0];
let dataURI = "data:";

if (!input.length) return "";

// Convert input to raw bytes
switch (inputFormat) {
case "Hex":
input = Utils.fromHex(input);
break;
case "Base64":
// Don't trust the Base64 entered by the user.
// Unwrap it first, then re-encode later.
input = Utils.fromBase64(input, null, "byteArray");
break;
case "Raw":
default:
input = Utils.strToByteArray(input);
break;
}

// Determine file type
const type = FileType.magicType(input);
if (type && type.mime.indexOf("image") === 0) {
dataURI += type.mime + ";";
} else {
throw "Invalid file type";
}

// Add image data to URI
dataURI += "base64," + Utils.toBase64(input);

return "<img src='" + dataURI + "'>";
},

};

export default Image;
2 changes: 1 addition & 1 deletion src/web/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ <h4 class="modal-title">CyberChef - The Cyber Swiss Army Knife</h4>
Version <%= htmlWebpackPlugin.options.version %><br>
Compile time: <%= htmlWebpackPlugin.options.compileTime %>
</p>
<p>&copy Crown Copyright 2016.</p>
<p>&copy; Crown Copyright 2016.</p>
<p>Licenced under the Apache Licence, Version 2.0.</p>
<br>
<br>
Expand Down
4 changes: 4 additions & 0 deletions src/web/stylesheets/layout/_structure.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @license Apache-2.0
*/

body {
overflow: hidden;
}

#content-wrapper {
position: absolute;
top: 0;
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function handleTestResult(testResult) {
setTimeout(function() {
console.log("Tests took longer than 10 seconds to run, returning.");
process.exit(1);
}, 1 * 1000);
}, 10 * 1000);


TestRegister.runTests()
Expand Down
34 changes: 34 additions & 0 deletions test/tests/operations/Image.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 67b78fc

Please sign in to comment.