Beispiel #1
0
    def exist_examine(self, addon_name):
        examine_url = '{}{}'.format(self.addon_path, addon_name)
        if self.verbose:
            print '[*] scan addon \'%s\' for exisitance... ' % addon_name
        try:    
            req = requests.get(examine_url, headers=HEADERS)
            self.reqs += 1
            if 'charset=gbk' in req.content:
                exist = examine(req.content.decode('gbk').encode('utf8'))
            else:
                exist = examine(req.content)

            if exist:
                self.outs.add(addon_name)
        except Exception as ex:
            print ex
Beispiel #2
0
    def exist_examine(self, addon_name):
        examine_url = '{}{}'.format(self.addon_path, addon_name)
        if self.verbose:
            print '[*] scan addon \'%s\' for exisitance... ' % addon_name
        try:    
            req = requests.get(examine_url, headers=HEADERS)
            self.reqs += 1
            if 'charset=gbk' in req.content:
                exist = examine(req.content.decode('gbk').encode('utf8'))
            else:
                exist = examine(req.content)

            if exist:
                self.outs.add(addon_name)
        except Exception as ex:
            print ex
def get_extension(id, url, _type, download=True):
    id = id.strip()
    if not id:
        return

    id = id.split('/')[-1]
    if (check_manifest_exists and os.path.exists(
            os.path.join(root, _type + '-manifests', id + '.json'))):
        print('Manifest %s already exists, skipping' % id)
        return

    if id in badURLs:
        return

    curdir = os.getcwd()
    dest = tempfile.mkdtemp(dir=myTmp)
    os.chmod(dest, stat.S_IWRITE)
    os.chdir(dest)
    destfile = os.path.join(dest, id + '.zip')

    print('Downloading...', id)
    try:
        download_file(destfile, url)
        try:
            if unzip:
                unzip_file(destfile)
        except:
            print(url)
            print('...unzip failed')
            badURLs.add(id)
            os.chdir(curdir)
            return dest

    except (UnicodeDecodeError, requests.exceptions.HTTPError) as exc:
        #        print(exc.message)
        print(url)
        print('...failed')
        badURLs.add(id)
        os.chdir(curdir)
        return dest

    if copy_manifest:
        manifest = os.path.join(dest, 'manifest.json')
        try:
            shutil.copy('manifest.json',
                        os.path.join(root, _type + '-manifests', id + '.json'))
            print('Got manifest for', id)
        except:
            print('No manifest found for', id)

    json_file = os.path.join(root, _type + '-apis', id + '.json')
    if parse:
        res = examine(dest)
        json.dump(res, open(json_file, 'w'))

    os.chdir(curdir)
    return dest
Beispiel #4
0
def get_extension(id, url, _type, download=True):
    id = id.strip()
    if not id:
        return

    dest = tempfile.mkdtemp()
    os.chdir(dest)

    id = id.split('/')[-1]
    if (check_manifest_exists
            and os.path.exists('%s/%s-apis/%s.json' % (root, _type, id))):
        print 'Manifest %s already exists, skipping' % id
        return

    destfile = os.path.join(dest, id + '.zip')

    print 'Downloading...', id
    try:
        download_file(destfile, url)
        if unzip:
            unzip_file(destfile)

    except (UnicodeDecodeError, requests.exceptions.HTTPError) as exc:
        print exc.message
        print url
        print '...failed'
        return

    if copy_manifest:
        manifest = os.path.join(dest, 'manifest.json')
        os.system('cp manifest.json %s/%s-manifests/%s.json' %
                  (root, _type, id))
        print 'Got manifest for', id

    json_file = '%s/%s-apis/%s.json' % (root, _type, id)
    if parse:
        res = examine(dest)
        json.dump(res, open(json_file, 'w'))

    return dest
    output = sys.argv[1].strip()
    assert output in ['text', 'html'], 'Format invalid: {}'.format(output)

    source = sys.argv[2]
    if source.startswith('https://chrome.google.com/webstore/detail'):
        # Its an add-on on the chrome store, let's get it.
        filename = get_chrome_addon(source)
    elif source.startswith('https://addons.mozilla.org/firefox/downloads/'):
        # Its an add-on on amo, let's get it.
        filename = get_addon(source)
    else:
        raise ValueError('Unknown file source.')

    assert os.path.exists(filename)

    filedir = unzip_file(filename)
    manifest_file = os.path.join(filedir, 'manifest.json')
    api_file = os.path.join(filedir, 'apis.json')
    json.dump(examine(filedir), open(api_file, 'w'))

    ext = Extension(manifest_file, api_file)
    ext.process()

    if output == 'text':
        format_text(ext)
    elif output == 'html':
        # This is just a quick prototype.
        format_html(ext, source)
    else:
        raise ValueError('Unknown format.')