Example #1
0
 def __init__(self):
     if self.INSTANCE is not None:
         raise ValueError("Mapper is a Singleton. " \
             "Please use get_instance method.")
     debug(2, 'loading database from %s' % DB_URL)
     data = findall('{{{(.*)}}}', \
         urlopen("%s?action=raw" % DB_URL).read().replace('\n', ''))[0]
     self.json = parseJSON(data)
     self._warnings = {}
     self.reset_warnings()
Example #2
0
def query_hash_plain(hash):
    plain_text = ""

    print "Cracking hash %s..." % hash

    for vendor in QUERY_VENDOR:
        url = QUERY_API % (vendor, hash)
        res = get(url)

        if res.status_code == 200:
            result = parseJSON(res.content)

            if result["status"]:
                plain_text = result["result"]
                print "Hash Found!! Plain: %s" % plain_text
                break

    return plain_text
Example #3
0
def search_for_reverse_dependencies(module):
    if isinstance(module, Npm2Deb):
        module = module.name
    url = "http://registry.npmjs.org/-/_view/dependedUpon?startkey=" \
    + "[%%22%(name)s%%22]&endkey=[%%22%(name)s%%22,%%7B%%7D]&group_level=2"
    url = url % {'name': module}
    debug(1, "opening url %s" % url)
    data = urlopen(url).read()
    data = parseJSON(data)
    result = []
    if 'rows' in data and len(data['rows']) > 0:
        my_print("Reverse Depends:")
        for row in data['rows']:
            dependency = row['key'][1]
            result.append(dependency)
            my_print("  %s" % dependency)
    else:
        my_print("Module %s has no reverse dependencies" % module)
    return result
Example #4
0
def search_for_reverse_dependencies(module):
    if isinstance(module, Npm2Deb):
        module = module.name
    url = "http://registry.npmjs.org/-/_view/dependedUpon?startkey=" \
    + "[%%22%(name)s%%22]&endkey=[%%22%(name)s%%22,%%7B%%7D]&group_level=2"
    url = url % {'name': module}
    debug(1, "opening url %s" % url)
    data = urlopen(url).read()
    data = parseJSON(data)
    result = []
    if 'rows' in data and len(data['rows']) > 0:
        my_print("Reverse Depends:")
        for row in data['rows']:
            dependency = row['key'][1]
            result.append(dependency)
            my_print("  %s" % dependency)
    else:
        my_print("Module %s has no reverse dependencies" % module)
    return result
Example #5
0
    def read_package_info(self):
        utils.debug(1, "reading package info using npm view")
        info = getstatusoutput('npm view %s --json 2>/dev/null' % self.name)
        # if not status 0, raise expection
        if info[0] != 0:
            info = getstatusoutput('npm view %s --json' % self.name)
            exception = 'npm reports errors about %s module:\n' % self.name
            exception += info[1]
            raise ValueError(exception)
        if not info[1]:
            exception = 'npm returns empty json for %s module' % self.name
            raise ValueError(exception)

        try:
            self.json = parseJSON(info[1])
        except ValueError as value_error:
            # if error during parse, try to fail graceful
            if str(value_error) == 'No JSON object could be decoded':
                versions = []
                for line in info[1].split('\n'):
                    if re.match(r"^[a-z](.*)@[0-9]", line):
                        version = line.split('@')[1]
                        versions.append(version)
                if len(versions) > 0:
                    exception = "More than one version found. "\
                        "Please specify one of:\n %s" % '\n '.join(versions)
                    raise ValueError(exception)
                else:
                    raise value_error
            else:
                raise value_error

        self.name = self.json['name']
        self._get_json_author()
        self._get_json_repo_url()
        self._get_json_homepage()
        self._get_json_description()
        self._get_json_version()
        self._get_json_license()
Example #6
0
def search_for_builddep(module):
    try:
        if not isinstance(module, Npm2Deb):
            builddeb = parseJSON(getstatusoutput('npm view %s '
                'devDependencies --json 2>/dev/null' % module)[1])
        else:
            builddeb = module.json['devDependencies']
            module = module.name
    except ValueError:
        return None

    mapper = Mapper.get_instance()
    result = {}

    for dep in builddeb:
        result[dep] = {}
        result[dep]['version'] = builddeb[dep]
        result[dep]['debian'] = mapper.get_debian_package(dep)['repr']
        print_formatted_dependency("%s (%s)" % (dep, result[dep]['version']),
            result[dep]['debian'])

    return result
Example #7
0
    def read_package_info(self):
        utils.debug(1, "reading package info using npm view")
        info = getstatusoutput("npm view %s --json 2>/dev/null" % self.name)
        # if not status 0, raise expection
        if info[0] != 0:
            info = getstatusoutput("npm view %s --json" % self.name)
            exception = "npm reports errors about %s module:\n" % self.name
            exception += info[1]
            raise ValueError(exception)
        if not info[1]:
            exception = "npm returns empty json for %s module" % self.name
            raise ValueError(exception)

        try:
            self.json = parseJSON(info[1])
        except ValueError as value_error:
            # if error during parse, try to fail graceful
            if str(value_error) == "No JSON object could be decoded":
                versions = []
                for line in info[1].split("\n"):
                    if re.match(r"^[a-z](.*)@[0-9]", line):
                        version = line.split("@")[1]
                        versions.append(version)
                if len(versions) > 0:
                    exception = "More than one version found. " "Please specify one of:\n %s" % "\n ".join(versions)
                    raise ValueError(exception)
                else:
                    raise value_error
            else:
                raise value_error

        self.name = self.json["name"]
        self._get_json_author()
        self._get_json_repo_url()
        self._get_json_homepage()
        self._get_json_description()
        self._get_json_version()
        self._get_json_license()
Example #8
0
def search_for_dependencies(module, recursive=False, force=False, prefix=u''):
    try:
        if not isinstance(module, Npm2Deb):
            dependencies = parseJSON(
                getstatusoutput('npm view %s '
                                'dependencies --json 2>/dev/null' % module)[1])
        else:
            dependencies = module.json['dependencies']
            module = module.name
    except ValueError:
        return None

    mapper = Mapper.get_instance()
    result = {}

    keys = dependencies.keys()
    last_dep = False
    for dep in keys:
        if dep == keys[-1]:
            last_dep = True
        result[dep] = {}
        result[dep]['version'] = dependencies[dep]
        result[dep]['debian'] = mapper.get_debian_package(dep)['repr']
        dep_prefix = u'└─' if last_dep else u'├─'
        print_formatted_dependency(
            u"%s %s (%s)" % (dep_prefix, dep, result[dep]['version']),
            result[dep]['debian'], prefix)
        if recursive:
            if (result[dep]['debian'] and force) or \
                    result[dep]['debian'] is None:
                new_prefix = "%s%s " % (prefix, u"  " if last_dep else u"│ ")
                result[dep]['dependencies'] = search_for_dependencies(dep, \
                    recursive, force, new_prefix)
        else:
            result[dep]['dependencies'] = None

    return result
Example #9
0
def search_for_dependencies(module, recursive=False,
        force=False, prefix=u''):
    try:
        if not isinstance(module, Npm2Deb):
            dependencies = parseJSON(getstatusoutput('npm view %s '
                'dependencies --json 2>/dev/null' % module)[1])
        else:
            dependencies = module.json['dependencies']
            module = module.name
    except ValueError:
        return None

    mapper = Mapper.get_instance()
    result = {}

    keys = dependencies.keys()
    last_dep = False
    for dep in keys:
        if dep == keys[-1]:
            last_dep = True
        result[dep] = {}
        result[dep]['version'] = dependencies[dep]
        result[dep]['debian'] = mapper.get_debian_package(dep)['repr']
        dep_prefix = u'└─' if last_dep else u'├─'
        print_formatted_dependency(u"%s %s (%s)" % (dep_prefix, dep,
            result[dep]['version']), result[dep]['debian'], prefix)
        if recursive:
            if (result[dep]['debian'] and force) or \
                    result[dep]['debian'] is None:
                new_prefix = "%s%s " % (prefix, u"  " if last_dep else u"│ ")
                result[dep]['dependencies'] = search_for_dependencies(dep, \
                    recursive, force, new_prefix)
        else:
            result[dep]['dependencies'] = None

    return result
Example #10
0
def search_for_builddep(module):
    try:
        if not isinstance(module, Npm2Deb):
            builddeb = parseJSON(
                getstatusoutput('npm view %s '
                                'devDependencies --json 2>/dev/null' %
                                module)[1])
        else:
            builddeb = module.json['devDependencies']
            module = module.name
    except ValueError:
        return None

    mapper = Mapper.get_instance()
    result = {}

    for dep in builddeb:
        result[dep] = {}
        result[dep]['version'] = builddeb[dep]
        result[dep]['debian'] = mapper.get_debian_package(dep)['repr']
        print_formatted_dependency("%s (%s)" % (dep, result[dep]['version']),
                                   result[dep]['debian'])

    return result