mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 15:26:16 -04:00
Ported Image operations + some cleanup
This commit is contained in:
parent
eb3a2502f5
commit
709630f39b
8 changed files with 202 additions and 672 deletions
56
src/core/operations/ExtractEXIF.mjs
Normal file
56
src/core/operations/ExtractEXIF.mjs
Normal file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import ExifParser from "exif-parser";
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
|
||||
/**
|
||||
* Extract EXIF operation
|
||||
*/
|
||||
class ExtractEXIF extends Operation {
|
||||
|
||||
/**
|
||||
* ExtractEXIF constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Extract EXIF";
|
||||
this.module = "Image";
|
||||
this.description = "Extracts EXIF data from an image.\n<br><br>\nEXIF data is metadata embedded in images (JPEG, JPG, TIFF) and audio files.\n<br><br>\nEXIF data from photos usually contains information about the image file itself as well as the device used to create it.";
|
||||
this.inputType = "ArrayBuffer";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
const parser = ExifParser.create(input);
|
||||
const result = parser.parse();
|
||||
|
||||
const lines = [];
|
||||
for (const tagName in result.tags) {
|
||||
const value = result.tags[tagName];
|
||||
lines.push(`${tagName}: ${value}`);
|
||||
}
|
||||
|
||||
const numTags = lines.length;
|
||||
lines.unshift(`Found ${numTags} tags.\n`);
|
||||
return lines.join("\n");
|
||||
} catch (err) {
|
||||
throw new OperationError(`Could not extract EXIF data from image: ${err}`);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ExtractEXIF;
|
Loading…
Add table
Add a link
Reference in a new issue