Пример #1
0
function compareAttacked(hashSets) {
    console.log('Attacks');
    var attackCodes = attacks.map(function(attack, idx) {
        return String.fromCharCode(idx + 65);
    });
    for (var n = 0; n < attacks.length; n++) {
        console.log(attackCodes[n] + ' - ' + attacks[n]);
    }
    console.log('');
    
    var collisions = [];
    var format     = generateFormatString(attackCodes);
    var separator  = generateSeparatorString(attackCodes);
    var header     = sprintf.apply(null, [format, 'Input'].concat(attackCodes)) + '\n' + separator;
    for (var i = 0; i < fuzzinesses.length; i++) {
        collisions.push([]);
        console.log('    fuzziness = ' + fuzzinesses[i] + '\n');
        for (var j = 0; j < resolutions.length; j++) {
            collisions[i].push(attacks.map(function() { return 0; }));
            console.log('        resolution = ' + resolutions[j] + '\n');
            console.log(header);
            for (var k = 0; k < files.length; k++) {
                var attackedHashes = hashSets[i][j][k];
                var originalHash = hashesOriginal.value()[i][j][k];
                var distances = attackedHashes.map(function (hash, idx) {
                    return hd(hash, originalHash);
                });
                console.log(sprintf.apply(null, [format, files[k]].concat(distances)));
                distances.forEach(function (distance, idx) {
                    if (distance == 0) collisions[i][j][idx]++;
                });
            }
            console.log(separator);
            console.log(sprintf.apply(null, [format, 'Total collisions:'].concat(collisions[i][j])));
            console.log('');
        }
    }
    
    console.log('Percentage of collisions across all attacks per resolution/fuzziness pair:\n');
    console.log(sprintf('         %-6s res=%-6d res=%-6d res=%-6d', '', resolutions[0], resolutions[1], resolutions[2]));
    console.log('    ---------+------------------------------');
    var totalComparisons = files.length * attacks.length;
    for (var i = 0; i < fuzzinesses.length; i++) {
        process.stdout.write(sprintf('    fuzz=%-3d %-3s', fuzzinesses[i], '|'));
        for (var j = 0; j < resolutions.length; j++) {
            var totalCollisions = collisions[i][j].reduce(function (x, y) { return x + y });
            process.stdout.write(sprintf('%-10.2f ', totalCollisions / totalComparisons * 100));
        }
        process.stdout.write('\n');
    }
    console.log('\nA total of ' + files.length + ' images under ' + attacks.length + ' attacks were examined.\n');
}
 ClassMetadataWalker.prototype.visitNg2Directive = function (controller, decorator) {
     var name = controller.name;
     var className = name.text;
     if (!Rule.validate(className)) {
         this.addFailure(this.createFailure(name.getStart(), name.getWidth(), sprintf_js_1.sprintf.apply(this, [Rule.FAILURE, className])));
     }
 };
Пример #3
0
	sprintf.parse( formatString ).forEach( ( match, idx ) => {
		if ( _.isString( match ) ) {
			rv.push( match );
		} else {
			let arg = null;
			if ( match[2] ) {
				arg = args[0][match[2][0]];
			} else if ( match[1] ) {
				arg = args[parseInt( match[1], 10 ) - 1];
			} else {
				arg = args[cursor++];
			}

			// this points to a react element!
			if ( React.isValidElement( arg ) ) {
				rv.push( React.cloneElement( arg, { key: idx } ) );
				// not a react element, f**k around with it so that sprintf.format
				// can format it for us.  We make sure match[2] is null so that we
				// do not go down the object path, and we set match[1] to the first
				// index and then pass an array with two items in.
			} else {
				match[2] = null;
				match[1] = 1;
				rv.push( <span key={idx++}>
          {sprintf.format( [match], [null, arg] )}
        </span> );
			}
		}
	} );
Пример #4
0
 return function(var_args) {
   var message = format.apply(this, arguments);
   if (strict) {
     throw new gutil.PluginError('i18n_replace', message);
   } else {
     gutil.log('WARNING[i18n_replace]:', message);
   }
 }
Пример #5
0
 parseMessages: function(messages) {
   if (messages.length == 1) {
     return messages[0];
   }
   if (typeof messages[0] === 'string' && messages[0].indexOf('%') >= 0) {
     return sprintf.apply(this, messages);
   }
   return messages.join('');
 }
Пример #6
0
module.exports = function (options) {
  if (!Array.isArray(options.message)) {
    options.message = [options.message]
  }

  window.$.growl('<h4>' + options.header + '</h4>' + sprintf.apply(null, options.message), {
    type: options.type ? options.type : 'info',
    offset: 15
  })
}
Пример #7
0
thr.make = function (ErrorClass, msg) {
  var offset = 1;

  if (typeof ErrorClass !== 'function') {
    offset = 0;
    ErrorClass = Error;
  }

  return new ErrorClass(format.apply(null, slice.call(arguments, offset)));
};
Пример #8
0
Processor.prototype.process = function (entry) {
    var extracted = this._extractors.length == 0
        ? [ entry.json ]
        : this._extractors.map(function (extractor) {
            return extractor(entry.json)
        })

    entry.formatted.push(sprintf.apply(null, [ this._format ].concat(extracted)))

    this._next.process(entry)
}
Пример #9
0
 InputWalker.prototype.visitNgInput = function (property, input, args) {
     var className = property.parent.name.text;
     var memberName = property.name.text;
     var options = this.getOptions();
     var prefixLength;
     if (memberName) {
         var foundInvalid = options.find(function (x) { return memberName.startsWith(x); });
         prefixLength = foundInvalid ? foundInvalid.length : 0;
     }
     if (prefixLength > 0 &&
         !(memberName.length >= prefixLength + 1 && memberName[prefixLength] !== memberName[prefixLength].toUpperCase())) {
         var failureConfig = [Rule.FAILURE_STRING, className, memberName, options.join(', ')];
         var errorMessage = sprintf_js_1.sprintf.apply(null, failureConfig);
         this.addFailure(this.createFailure(property.getStart(), property.getWidth(), errorMessage));
     }
 };
 ClassMetadataWalker.prototype.visitClassDeclaration = function (node) {
     var syntaxKind = SyntaxKind.current();
     var className = node.name.text;
     var interfaces = [];
     if (node.heritageClauses) {
         var interfacesClause = node.heritageClauses.filter(function (h) { return h.token === syntaxKind.ImplementsKeyword; });
         if (interfacesClause.length !== 0) {
             interfaces = interfacesClause[0].types.map(function (t) { return t.expression.text; });
         }
     }
     var missing = this.extractMissing(node.members, syntaxKind, interfaces);
     if (missing.length !== 0) {
         this.addFailure(this.createFailure(node.getStart(), node.getWidth(), sprintf_js_1.sprintf.apply(this, this.formatFailure(className, missing))));
     }
     _super.prototype.visitClassDeclaration.call(this, node);
 };
 ClassMetadataWalker.prototype.visitNgDirective = function (meta) {
     var name = meta.controller.name;
     var className = name.text;
     var options = this.getOptions();
     var suffixes = options.length ? options : ['Directive'];
     var heritageClauses = meta.controller.heritageClauses;
     if (heritageClauses) {
         var i = heritageClauses.filter(function (h) { return h.token === ts.SyntaxKind.ImplementsKeyword; });
         if (i.length !== 0 &&
             i[0].types.map(getInterfaceName)
                 .filter(function (name) { return !!name; })
                 .some(function (name) { return name.endsWith(ValidatorSuffix); })) {
             suffixes.push(ValidatorSuffix);
         }
     }
     if (!Rule.validate(className, suffixes)) {
         this.addFailure(this.createFailure(name.getStart(), name.getWidth(), sprintf_js_1.sprintf.apply(this, [Rule.FAILURE, className, suffixes.join(', ')])));
     }
 };
Пример #12
0
Dictionary.prototype.format = function (language, path, key) {
    var vargs = slice.call(arguments, 3), args, keys
    var string = this.getString(language, path, key)
    if (!string) {
        return null
    }
    if (typeof vargs[0] === 'object') {
        vargs = vargs[0]
    }
    if (Array.isArray(vargs)) {
        args = vargs.map(function (_, index) {
            var order = string.order[index] || ''
            return vargs[/^\d+$/.test(order) ? order - 1 : index]
        })
    } else {
        keys = Object.keys(vargs)
        args = keys.map(function (_, index) {
            var order = string.order[index]
            return vargs[order ? order : keys[index]]
        })
    }
    return sprintf.apply(null, [ string.text].concat(args))
}
Пример #13
0
printf = function () {
	var s = sprintf.apply(sprintf
		, [].slice.call(arguments))
	;
	console.log(s);
};
 TemplateConditionalComplexityVisitor.prototype.visitDirectiveProperty = function (prop, context) {
     if (prop.sourceSpan) {
         var directive = prop.sourceSpan.toString();
         if (directive.startsWith('*ngFor') || directive.startsWith('*ngIf') ||
             directive.startsWith('*ngSwitchCase') || directive.startsWith('*ngSwitchDefault')) {
             this.complexity++;
         }
     }
     var options = this.getOptions();
     var complexityMax = options.length ? options[0] : Rule.COMPLEXITY_MAX;
     if (this.complexity > complexityMax) {
         var span = prop.sourceSpan;
         var failureConfig = [String(Rule.COMPLEXITY_MAX)];
         failureConfig.unshift(Rule.COMPLEXITY_FAILURE_STRING);
         this.addFailure(this.createFailure(span.start.offset, span.end.offset - span.start.offset, sprintf_js_1.sprintf.apply(this, failureConfig)));
     }
     _super.prototype.visitDirectiveProperty.call(this, prop, context);
 };
 ClassMetadataWalker.prototype.visitClassDeclaration = function (node) {
     var decorators = node.decorators;
     if (decorators) {
         var pipes = decorators.map(function (d) {
             return d.expression.text ||
                 (d.expression.expression || {}).text;
         }).filter(function (t) { return t === 'Pipe'; });
         if (pipes.length !== 0) {
             var className = node.name.text;
             if (!this.hasIPipeTransform(node)) {
                 this.addFailure(this.createFailure(node.getStart(), node.getWidth(), sprintf_js_1.sprintf.apply(this, [Rule.FAILURE, className])));
             }
         }
     }
     _super.prototype.visitClassDeclaration.call(this, node);
 };
Пример #16
0
			obj.error = function()
			{
				logger.error('%s[%s]: %s', type, obj.name, sprintf.apply(this, arguments));
			};
Пример #17
0
			obj.info = function()
			{
				logger.info('%s[%s]: %s', type, obj.name, sprintf.apply(this, arguments));
			};
Пример #18
0
 ClassMetadataWalker.prototype.validateProperty = function (className, property) {
     var propName = property.initializer.text;
     var isValidName = this.rule.validateName(propName);
     var isValidPrefix = (this.rule.hasPrefix ? this.rule.validatePrefix(propName) : true);
     if (!isValidName || !isValidPrefix) {
         this.addFailure(this.createFailure(property.getStart(), property.getWidth(), sprintf_js_1.sprintf.apply(this, this.createFailureArray(className, propName))));
     }
 };
Пример #19
0
String.prototype.sprintf = function(){
	return sprintf.sprintf.apply( null, [ this ].concat( [].slice.apply( arguments ) ) );
};
Пример #20
0
function error(var_args) {
  var message = format.apply(this, arguments);
  throw new gutil.PluginError('i18n_replace', message);
}
 ClassMetadataWalker.prototype.generateFailure = function (start, width, failureConfig) {
     this.addFailure(this.createFailure(start, width, sprintf_js_1.sprintf.apply(this, failureConfig)));
 };
Пример #22
0
 EnforceComponentSelectorValidatorWalker.prototype.generateFailure = function (start, width, failureConfig) {
     this.addFailure(this.createFailure(start, width, sprintf_js_1.sprintf.apply(this, failureConfig)));
 };
Пример #23
0
 InputMetadataWalker.prototype.visitNgInput = function (property, input, args) {
     var className = property.parent.name.text;
     var memberName = property.name.text;
     if (args.length !== 0 && memberName !== args[0]) {
         var failureConfig = [className, memberName, memberName];
         failureConfig.unshift(Rule.FAILURE_STRING);
         this.addFailure(this.createFailure(property.getStart(), property.getWidth(), sprintf_js_1.sprintf.apply(this, failureConfig)));
     }
 };
 SymbolAccessValidator.prototype.doCheck = function (ast, type, context) {
     var symbolType;
     var available;
     if (type === DeclarationType.Method) {
         symbolType = 'method';
     }
     else {
         symbolType = 'property';
     }
     available = classDeclarationUtils_1.getDeclaredMethodNames(this.context.controller)
         .concat(classDeclarationUtils_1.getDeclaredPropertyNames(this.context.controller))
         .concat(this.preDefinedVariables);
     var tmp = ast;
     while (tmp && !expressionTypes_1.ExpTypes.ImplicitReceiver(tmp)) {
         ast = tmp;
         if (expressionTypes_1.ExpTypes.KeyedRead(tmp)) {
             tmp = tmp.obj;
         }
         else if (expressionTypes_1.ExpTypes.KeyedWrite(tmp)) {
             tmp = tmp.obj;
         }
         else if (expressionTypes_1.ExpTypes.PropertyRead(tmp)) {
             tmp = tmp.receiver;
         }
         else if (expressionTypes_1.ExpTypes.PropertyWrite(tmp)) {
             tmp = tmp.receiver;
         }
         else if (expressionTypes_1.ExpTypes.SafeMethodCall(tmp)) {
             tmp = tmp.receiver;
         }
         else if (expressionTypes_1.ExpTypes.SafePropertyRead(tmp)) {
             tmp = tmp.receiver;
         }
         else if (expressionTypes_1.ExpTypes.MethodCall(tmp)) {
             tmp = tmp.receiver;
         }
         else {
             break;
         }
     }
     if (available.indexOf(ast.name) < 0) {
         var failureString = sprintf_js_1.sprintf.apply(this, [Rule.FAILURE, symbolType, ast.name]);
         if (ast.name) {
             var top_1 = this.getTopSuggestion(available, ast.name);
             var getSuggestion = function (list) {
                 if (list.length === 1) {
                     return "\"" + list[0] + "\"";
                 }
                 var result = "\"" + list.shift() + "\"";
                 while (list.length > 1) {
                     result += ", \"" + list.shift() + "\"";
                 }
                 result += " or \"" + list.shift() + "\"";
                 return result;
             };
             if (top_1.length && top_1[0].distance <= 2) {
                 failureString += " Probably you mean: " + getSuggestion(top_1.map(function (s) { return s.element; })) + ".";
             }
         }
         var width = ast.name.length;
         this.addFailure(this.createFailure(ast.span.start, width, failureString));
     }
     return null;
 };
Пример #25
0
var printf = function () { console.log(sprintf.apply(null, arguments)); };
 ExpressionCallMetadataWalker.prototype.validateCallExpression = function (callExpression) {
     if (callExpression.expression.text === 'forwardRef') {
         var currentNode = callExpression;
         while (currentNode.parent.parent) {
             currentNode = currentNode.parent;
         }
         var failureConfig = [];
         if (currentNode.kind === SyntaxKind.current().VariableStatement) {
             failureConfig = [Rule.FAILURE_IN_VARIABLE, currentNode.declarationList.declarations[0].name.text];
         }
         else {
             failureConfig = [Rule.FAILURE_IN_CLASS, currentNode.name.text];
         }
         this.addFailure(this.createFailure(callExpression.getStart(), callExpression.getWidth(), sprintf_js_1.sprintf.apply(this, failureConfig)));
     }
 };
Пример #27
0
			obj.debug = function()
			{
				logger.debug('%s[%s]: %s', type, obj.name, sprintf.apply(this, arguments));
			};
Пример #28
0
 ClassMetadataWalker.prototype.validateProperty = function (className, property) {
     var propValue = property.initializer.getText();
     if (propValue === 'false') {
         this.addFailure(this.createFailure(property.getStart(), property.getWidth(), sprintf_js_1.sprintf.apply(this, this.createFailureArray(className))));
     }
 };
 methods.forEach(function (m) {
     var n = m.name.text;
     if (n && _this.isMethodValidHook(m, interfaces)) {
         var hookName = n.substr(2, n.lenght);
         _this.addFailure(_this.createFailure(m.name.getStart(), m.name.getWidth(), sprintf_js_1.sprintf.apply(_this, [Rule.FAILURE, hookName, Rule.HOOKS_PREFIX + hookName, className])));
     }
 });
 TemplateConditionalComplexityVisitor.prototype.visitDirectiveProperty = function (prop, context) {
     if (prop.sourceSpan) {
         var directive = prop.sourceSpan.toString();
         if (directive.startsWith('*ngIf')) {
             var expr = directive.split(/\*ngIf\s*=\s*/)[1].slice(1, -1).replace(/[\n\r]/g, '');
             var expressionParser = new compiler.Parser(new compiler.Lexer());
             var ast_1 = expressionParser.parseAction(expr, null);
             var complexity = 0;
             var conditions = [];
             var condition = ast_1.ast;
             if (condition.operation) {
                 complexity++;
                 conditions.push(condition);
             }
             while (conditions.length > 0) {
                 condition = conditions.pop();
                 if (condition.operation) {
                     if (condition.left instanceof compiler_1.Binary) {
                         complexity++;
                         conditions.push(condition.left);
                     }
                     if (condition.right instanceof compiler_1.Binary) {
                         conditions.push(condition.right);
                     }
                 }
             }
             var options = this.getOptions();
             var complexityMax = options.length ? options[0] : Rule.COMPLEXITY_MAX;
             if (complexity > complexityMax) {
                 var span = prop.sourceSpan;
                 var failureConfig = [String(complexity), String(Rule.COMPLEXITY_MAX)];
                 failureConfig.unshift(Rule.COMPLEXITY_FAILURE_STRING);
                 this.addFailure(this.createFailure(span.start.offset, span.end.offset - span.start.offset, sprintf_js_1.sprintf.apply(this, failureConfig)));
             }
         }
     }
     _super.prototype.visitDirectiveProperty.call(this, prop, context);
 };