|
@@ -265,9 +265,10 @@ class Magic {
|
|
* performance)
|
|
* performance)
|
|
* @param {Object[]} [recipeConfig=[]] - The recipe configuration up to this point
|
|
* @param {Object[]} [recipeConfig=[]] - The recipe configuration up to this point
|
|
* @param {boolean} [useful=false] - Whether the current recipe should be scored highly
|
|
* @param {boolean} [useful=false] - Whether the current recipe should be scored highly
|
|
|
|
+ * @param {string} [filter=null] - The regex crib provided by the user, to filter the operation output
|
|
* @returns {Object[]} - A sorted list of the recipes most likely to result in correct decoding
|
|
* @returns {Object[]} - A sorted list of the recipes most likely to result in correct decoding
|
|
*/
|
|
*/
|
|
- async speculativeExecution(depth=0, extLang=false, intensive=false, recipeConfig=[], useful=false) {
|
|
|
|
|
|
+ async speculativeExecution(depth=0, extLang=false, intensive=false, recipeConfig=[], useful=false, filter=null) {
|
|
if (depth < 0) return [];
|
|
if (depth < 0) return [];
|
|
|
|
|
|
// Find any operations that can be run on this data
|
|
// Find any operations that can be run on this data
|
|
@@ -276,17 +277,20 @@ class Magic {
|
|
let results = [];
|
|
let results = [];
|
|
|
|
|
|
// Record the properties of the current data
|
|
// Record the properties of the current data
|
|
- results.push({
|
|
|
|
- recipe: recipeConfig,
|
|
|
|
- data: this.inputStr.slice(0, 100),
|
|
|
|
- languageScores: this.detectLanguage(extLang),
|
|
|
|
- fileType: this.detectFileType(),
|
|
|
|
- isUTF8: this.isUTF8(),
|
|
|
|
- entropy: this.calcEntropy(),
|
|
|
|
- matchingOps: matchingOps,
|
|
|
|
- useful: useful
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ // Only if there either wasn't a filter provided,
|
|
|
|
+ // or the filter matches in the data
|
|
|
|
+ if (filter == null || new RegExp(filter).test(this.inputStr)){
|
|
|
|
+ results.push({
|
|
|
|
+ recipe: recipeConfig,
|
|
|
|
+ data: this.inputStr.slice(0, 100),
|
|
|
|
+ languageScores: this.detectLanguage(extLang),
|
|
|
|
+ fileType: this.detectFileType(),
|
|
|
|
+ isUTF8: this.isUTF8(),
|
|
|
|
+ entropy: this.calcEntropy(),
|
|
|
|
+ matchingOps: matchingOps,
|
|
|
|
+ useful: useful
|
|
|
|
+ });
|
|
|
|
+ }
|
|
const prevOp = recipeConfig[recipeConfig.length - 1];
|
|
const prevOp = recipeConfig[recipeConfig.length - 1];
|
|
|
|
|
|
// Execute each of the matching operations, then recursively call the speculativeExecution()
|
|
// Execute each of the matching operations, then recursively call the speculativeExecution()
|
|
@@ -305,7 +309,7 @@ class Magic {
|
|
|
|
|
|
const magic = new Magic(output, this.opPatterns),
|
|
const magic = new Magic(output, this.opPatterns),
|
|
speculativeResults = await magic.speculativeExecution(
|
|
speculativeResults = await magic.speculativeExecution(
|
|
- depth-1, extLang, intensive, [...recipeConfig, opConfig], op.useful);
|
|
|
|
|
|
+ depth-1, extLang, intensive, [...recipeConfig, opConfig], op.useful, filter);
|
|
|
|
|
|
results = results.concat(speculativeResults);
|
|
results = results.concat(speculativeResults);
|
|
}));
|
|
}));
|
|
@@ -317,7 +321,7 @@ class Magic {
|
|
await Promise.all(bfEncodings.map(async enc => {
|
|
await Promise.all(bfEncodings.map(async enc => {
|
|
const magic = new Magic(enc.data, this.opPatterns),
|
|
const magic = new Magic(enc.data, this.opPatterns),
|
|
bfResults = await magic.speculativeExecution(
|
|
bfResults = await magic.speculativeExecution(
|
|
- depth-1, extLang, false, [...recipeConfig, enc.conf]);
|
|
|
|
|
|
+ depth-1, extLang, false, [...recipeConfig, enc.conf], useful, filter);
|
|
|
|
|
|
results = results.concat(bfResults);
|
|
results = results.concat(bfResults);
|
|
}));
|
|
}));
|