浏览代码

Merge branch 'esm' of github.com:gchq/CyberChef into esm

n1474335 7 年之前
父节点
当前提交
40a1da10e3
共有 1 个文件被更改,包括 18 次插入12 次删除
  1. 18 12
      src/core/lib/Magic.mjs

+ 18 - 12
src/core/lib/Magic.mjs

@@ -229,17 +229,22 @@ class Magic {
         const testEnc = async op => {
             for (let i = 0; i < encodings.length; i++) {
                 const conf = {
-                        op: op,
-                        args: [encodings[i]]
-                    },
-                    data = await this._runRecipe([conf], sample.buffer);
-
-                // Only add to the results if it changed the data
-                if (!_buffersEqual(data, sample.buffer)) {
-                    results.push({
-                        data: data,
-                        conf: conf
-                    });
+                    op: op,
+                    args: [encodings[i]]
+                };
+
+                try {
+                    const data = await this._runRecipe([conf], sample.buffer);
+
+                    // Only add to the results if it changed the data
+                    if (!_buffersEqual(data, sample.buffer)) {
+                        results.push({
+                            data: data,
+                            conf: conf
+                        });
+                    }
+                } catch (err) {
+                    continue;
                 }
             }
         };
@@ -361,8 +366,9 @@ class Magic {
      * @returns {ArrayBuffer}
      */
     async _runRecipe(recipeConfig, input=this.inputBuffer) {
+        input = input instanceof ArrayBuffer ? input : input.buffer;
         const dish = new Dish();
-        dish.set(input.buffer, Dish.ARRAY_BUFFER);
+        dish.set(input, Dish.ARRAY_BUFFER);
 
         if (ENVIRONMENT_IS_WORKER()) self.loadRequiredModules(recipeConfig);