Example #1
0
def main(gen_graph, method, analyze, out, debug, diameter, vertices, m):
    """ Main program """

    set_debug(debug)
    handleArgs(gen_graph, method, analyze, out, diameter, vertices, m)

    return 0
Example #2
0
    def set_debug(self, bool):
        '''
        Turn on/off debugging

        @bool: True for debug on
        '''
        set_debug(bool)
Example #3
0
    def set_debug(self, bool):
        '''
        Turn on/off debugging

        @bool: True for debug on
        '''
        set_debug(bool)
Example #4
0
def test_debug_info(capsys):
    """ Test printing of debug info
    """
    utils.set_debug()
    utils.print_debug_info('TEST')

    captured = capsys.readouterr()
    assert captured.out == '### DEBUG ### TEST\n'
Example #5
0
def main():
    optparser = OptionParser()
    optparser.add_option('-p', dest="port", type="int", default="5000")
    optparser.add_option('-d', dest="debug", action="store_true",
                         default=False)
    options, _ = optparser.parse_args()
    utils.set_debug(options.debug)
    app.run(debug=utils.do_debug, port=options.port)
Example #6
0
    def __init__(self,
                 plugins=None,
                 extra_dir=None,
                 memimg='',
                 profile='',
                 kdbg='0',
                 filterp=None,
                 filterp_type=None,
                 output=None,
                 db=None,
                 debug=False,
                 unique_id_fields=None,
                 diff=None):

        set_debug(debug)

        # Use the supplied db file
        self.db = db
        self.db_ops = db_ops.DBOps()
        self.diff = diff

        # Set up plugin system
        self.pluglib = plugin.PluginLibrary()
        self.pluglib.addPluginDir(
            os.path.join(os.path.dirname(__file__), 'plugins'))
        self.plugins = plugins
        self.plugins = self.pluglib.getPluginList() if (
            self.plugins
            and self.plugins[0].lower() == 'all') else self.plugins
        # Add user specified directory of plugins
        if extra_dir:
            self.extra_dir = extra_dir
            self.pluglib.addPluginDir(self.extra_dir)

        # Set up user defined output filter
        self.filterp = filterp
        self.filterp_name = filterp.split(":")[0] if filterp else None
        self.filterp_value = filterp.split(":")[1] if filterp else None
        self.filterp_type = filterp_type if filterp_type else 'exact'
        self.unique_id_fields = unique_id_fields

        # Settings for the volatility subsystem
        self.memimg = memimg
        self.profile = profile
        self.kdbg = kdbg
        self.vol = self.__vol_init()
        # In case we're guessing a profile and need to get the result. Kind of a hack.
        if self.profile == None:
            try:
                self.profile = self.vol.config.get_value('profile')
            except:
                pass
Example #7
0
def parse_args(argv):
    """ Parse command line arguments

    Args:
        argv: Arguments from the command line.
    """
    keystore_filename = 'keystore'
    port = 6666
    signing_key = None
    dns = False
    try:
        opts, _ = getopt.getopt(
            argv[1:], 'hdnp=k=s=',
            ['help', 'debug', 'dns', 'port=', 'key=', 'store='])
        for o, a in opts:
            if o in ('-h', '--help'):
                print('-d/--debug to enable debug prints')
                print('-n/--dns to start a dns chain')
                print('-p/--port to change default port')
                print('-k/--key to load a private key from a file')
                print('-s/--store to load a keystore from a file')
                sys.exit()
            if o in ('-d', '--debug'):
                set_debug()
            if o in ('-n', '--dns'):
                dns = True
            if o in ('-p', '--port'):
                try:
                    port = int(a)
                except ValueError:
                    print("Port was invalid (e.g. not an int)")
            elif o in ('-k', '--key'):
                try:
                    signing_key = load_key(filename=a)
                    print('Key successfully loaded')
                except Exception as e:
                    print('Could not load Key / Key is invalid')
                    print(e)
            elif o in ('-s', '--store'):
                keystore_filename = a
                print_debug_info(keystore_filename)

    except getopt.GetoptError as err:
        print('for help use --help')
        print(err)
        sys.exit()

    return keystore_filename, port, signing_key, dns
Example #8
0
def test_process_incoming(capsys):
    """ Test to determine that messages expected to be given to the blockchain
    are added to the receive_queue.
    """
    with capsys.disabled():
        msg = ('to-blockchain', 'msg-data')
        receive_queue = Queue()
        address = ('0.0.0.0', 1)

        process_incoming_msg(pack_msg(msg), address, receive_queue)

        assert receive_queue.get() == (msg[0], msg[1], address)

        n_address = ('123.123.123.123', 1)

        msg = ('N_new_peer', n_address)
        process_incoming_msg(pack_msg(msg), address, receive_queue)

        assert n_address in PEERS._peer_list

        msg = ('N_pong', '')
        process_incoming_msg(pack_msg(msg), n_address, receive_queue)

        assert n_address in PEERS.get_active_peers()

        msg = ('N_get_peers', '')
        process_incoming_msg(pack_msg(msg), ('127.0.0.1', 6667), receive_queue)

        for p in PEERS.get_all_peers():

            received = RECEIVER.receive_msg()

            assert p == unpack_msg(received[0])[1]

        msg = ('N_ping', '')
        process_incoming_msg(pack_msg(msg), ('127.0.0.1', 6667), receive_queue)

        received = RECEIVER.receive_msg()

        assert 'N_pong' == unpack_msg(received[0])[0]

    utils.set_debug()

    process_incoming_msg(pack_msg(''), address, receive_queue)

    captured = capsys.readouterr()

    assert captured.out.startswith('### DEBUG ### Received invalid message\n')
Example #9
0
    def setup(self):
        """ Setup of the blockchain for the tests.
        """
        utils.set_debug()

        self.sends = Queue()

        self.gui_queue = Queue()
        self.blockchain = PoW_Blockchain(VERSION, self.sends, self.gui_queue)

        self.sender_sign = nacl.signing.SigningKey(seed=b'a' * 32)
        self.sender_verify = self.sender_sign.verify_key.encode(
            nacl.encoding.HexEncoder)
        self.receiver_sign = nacl.signing.SigningKey(seed=b'b' * 32)
        self.receiver_verify = self.receiver_sign.verify_key.encode(
            nacl.encoding.HexEncoder)
Example #10
0
    def __init__(self, plugins=None, extra_dir=None, memimg='', profile='', kdbg='0', filterp=None, filterp_type=None, output=None, db=None, debug=False, unique_id_fields=None, diff=None):

        set_debug(debug)

        # Use the supplied db file
        self.db = db
        self.db_ops = db_ops.DBOps()
        self.diff = diff

        # Set up plugin system
        self.pluglib = plugin.PluginLibrary()
        self.pluglib.addPluginDir(os.path.join(os.path.dirname(__file__), 'plugins'))
        self.plugins = plugins
        self.plugins = self.pluglib.getPluginList() if (self.plugins and self.plugins[0].lower() == 'all') else self.plugins
        # Add user specified directory of plugins
        if extra_dir:
            self.extra_dir = extra_dir
            self.pluglib.addPluginDir(self.extra_dir)
        
        # Set up user defined output filter
        self.filterp = filterp
        self.filterp_name = filterp.split(":")[0] if filterp else None
        self.filterp_value = filterp.split(":")[1] if filterp else None
        self.filterp_type = filterp_type if filterp_type else 'exact'
        self.unique_id_fields = unique_id_fields        

        # Settings for the volatility subsystem
        self.memimg = memimg
        self.profile = profile
        self.kdbg = kdbg
        self.vol = self.__vol_init()
        # In case we're guessing a profile and need to get the result. Kind of a hack.
        if self.profile == None:
            try:
                self.profile = self.vol.config.get_value('profile')
            except:
                pass
Example #11
0
def parse_args(argv):
    port = 6666

    try:
        opts, _ = getopt.getopt(argv[1:], 'hdp=', ['help', 'debug', 'port='])
        for o, a in opts:
            if o in ('-h', '--help'):
                print('-d/--debug to enable debug prints')
                print('-p/--port to change default port')
                sys.exit()
            if o in ('-d', '--debug'):
                set_debug()
            if o in ('-p', '--port'):
                try:
                    port = int(a)
                except ValueError:
                    print("Port was invalid (e.g. not an int)")

    except getopt.GetoptError as err:
        print('for help use --help')
        print(err)
        sys.exit()

    return port
Example #12
0
def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('-B',
                        '--base',
                        dest='idir',
                        help='Buildroot Source Directory')
    parser.add_argument('-o',
                        '--output',
                        dest='odir',
                        help='Buildroot Output Directory')
    parser.add_argument('-b',
                        '--build',
                        dest='bdir',
                        help='Buildroot Build Directory')
    parser.add_argument('-k',
                        '--kernel-config',
                        dest='kconfig',
                        help='Custom Kernel Config to Use')
    parser.add_argument('-u',
                        '--uboot-config',
                        dest='uconfig',
                        help='Custom U-Boot Config(s) to Use')

    parser.add_argument('-N',
                        '--name',
                        dest='manifest_name',
                        help='Custom Manifest/Report Name',
                        default='')
    parser.add_argument('-A',
                        '--additional-packages',
                        dest='addl',
                        help='File of Additional Packages to Include')
    parser.add_argument('-E',
                        '--exclude-packages',
                        dest='excld',
                        help='File of Packages to Exclude')
    parser.add_argument('-W',
                        '--whitelist-cves',
                        dest='whtlst',
                        help='File of CVEs to Ignore/Whitelist')

    parser.add_argument('-K',
                        '--keyfile',
                        dest='llkey',
                        help='Location of LinuxLink credentials file')
    parser.add_argument('-C',
                        '--dashboard-config',
                        dest='lldashboard',
                        help='Location of LinuxLink Dashboard Config file')

    parser.add_argument(
        '-U',
        '--upload-only',
        dest='upload_only',
        help='Upload the manifest only; do not wait for report.',
        action='store_true',
        default=False)

    parser.add_argument('-D',
                        '--enable-debug',
                        dest='debug',
                        help='Enable Debug Output',
                        action='store_true')
    parser.add_argument('-I',
                        '--write-intermediate',
                        dest='write_intm',
                        help='Save Intermediate JSON Dictionaries',
                        action='store_true')
    parser.add_argument('-M',
                        '--metadata-only',
                        dest='do_check',
                        help='Only collect metadata, don\'t run online Check',
                        action='store_false')
    args = parser.parse_args()

    set_debug(args.debug)

    vgls = {
        'write_intm': args.write_intm,
        'do_check': args.do_check,
        'topdir': args.idir.strip() \
            if args.idir else os.path.abspath(os.curdir),
        'odir': args.odir.strip() if args.odir else None,
        'bdir': args.bdir.strip() if args.bdir else None,
        'kconfig': args.kconfig.strip() \
            if args.kconfig \
            else 'auto',
        'uconfig': args.uconfig.strip() \
            if args.uconfig \
            else 'auto',
        'manifest_name': args.manifest_name.strip(),
        'addl': args.addl.strip() if args.addl else '',
        'excld': args.excld.strip() if args.excld else '',
        'whtlst': args.whtlst.strip() if args.whtlst else '',
        'llkey': args.llkey.strip() if args.llkey else '',
        'lldashboard': args.lldashboard.strip() if args.lldashboard else '',
        'upload_only': args.upload_only
    }

    if not vgls.get('odir', None):
        vgls['odir'] = os.path.join(vgls['topdir'], 'output')
    if not vgls.get('bdir', None):
        vgls['bdir'] = os.path.join(vgls['odir'], 'build')
    vgls['vdir'] = os.path.join(vgls['odir'], VIGILES_DIR)

    dbg("Vigiles Buildroot Config: %s" %
        json.dumps(vgls, indent=4, sort_keys=True))
    return vgls
Example #13
0
    def test_invalid_transaction(self, capsys):
        """ Test that the chain rejects invalid transaction
        """
        utils.set_debug()

        # Verify rejection of duplicate transaction

        self.process_transaction(
            capsys, self.receiver_verify, 'i',
            self.sender_sign, self.sender_verify)

        time.sleep(0.00000001)  # new timestamp

        self.process_transaction(
            capsys, self.receiver_verify, 'i',
            self.sender_sign, self.sender_verify, False)

        captured = capsys.readouterr()
        assert 'This operation is already in the pool' in captured.out

        self.fill_block(capsys, 4)

        # Verify rejection of invite for members of the blockchain

        self.process_transaction(
            capsys, self.receiver_verify, 'i',
            self.sender_sign, self.sender_verify, False)

        captured = capsys.readouterr()
        assert 'Client is already invited!' in captured.out

        # Verify rejection for uninvite of someone that is not a member

        self.process_transaction(
            capsys, 'Not a client', 'ui',
            self.sender_sign, self.sender_verify, False)

        captured = capsys.readouterr()
        assert 'Client could not be found!' in captured.out

        # Verify rejection of not-permissioned uninvites

        self.process_transaction(
            capsys, self.sender_verify, 'ui',
            self.receiver_sign, self.receiver_verify, False)

        captured = capsys.readouterr()
        assert 'No permission to delete this node!' in captured.out

        # Verify rejection of unblocking of not-blocked IPs

        self.process_transaction(
            capsys, '66.77.88.99', 'ub',
            self.receiver_sign, self.receiver_verify, False)

        captured = capsys.readouterr()
        assert 'Trying to unblock IP that was not blocked' in captured.out

        # Verify rejection of blocking of already blocked IPs

        self.process_transaction(
            capsys, '255.255.255.0', 'b',
            self.sender_sign, self.sender_verify, False)

        captured = capsys.readouterr()
        assert 'IP was already blocked' in captured.out
Example #14
0
 def set_debug(self, bool):
     '''
     Tuen on/off debugging.
     '''
     set_debug(bool)
 def call_set_debug():
     set_debug(fake_object, debug)
Example #16
0
 def call_set_debug():
     set_debug(fake_object, debug)
Example #17
0
def main():
    workpath = os.getcwd()  # os.path.dirname(os.path.realpath(__file__))

    print("===>workpath:%s" % workpath)

    parser = ArgumentParser()
    parser.add_argument('-s',
                        '--src-project',
                        dest='src_project',
                        help="original project")

    parser.add_argument('-o',
                        '--out-dir',
                        dest='out_dir',
                        help="pack project output path")

    parser.add_argument('-r',
                        '--resource-dir',
                        dest='resource_dir',
                        help="resource dir contain pack pictures and defines")

    parser.add_argument('-c',
                        '--config-file',
                        dest='config_file',
                        help="config file about run pack")

    parser.add_argument('-d',
                        '--data-dir',
                        dest='data_dir',
                        help="global data files dir")

    parser.add_argument('--step-config',
                        dest='step_config',
                        help="step config contains actions")

    parser.add_argument('--action-config',
                        dest='action_config',
                        help="actions config")

    parser.add_argument('--words-file',
                        dest='words_file',
                        help="words data file")

    parser.add_argument('--class-words-file',
                        dest='class_words_file',
                        help="words data file")

    parser.add_argument('--filed-words-file',
                        dest='filed_words_file',
                        help="words data file")

    parser.add_argument('--function-words-file',
                        dest='function_words_file',
                        help="words data file")

    parser.add_argument('steps', nargs='*', help="steps to run")

    parser.add_argument('-i',
                        '--ignore-steps',
                        dest='ignore_steps',
                        help="actions not run")

    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true',
                        help="is debug")
    parser.set_defaults(debug=False)

    args = parser.parse_args()

    print("=======================================================")

    if 'debug' in args:
        utils.set_debug(args.debug)
    else:
        utils.set_debug(False)

    # 检查基本路径
    if not os.path.isabs(args.src_project):
        args.src_project = os.path.join(workpath, args.src_project)

    if not os.path.isabs(args.resource_dir):
        args.resource_dir = os.path.join(workpath, args.resource_dir)

    if not os.path.isabs(args.out_dir):
        args.out_dir = os.path.join(workpath, args.out_dir)

    if not args.data_dir:
        args.data_dir = args.resource_dir
    else:
        if not os.path.isabs(args.data_dir):
            args.data_dir = os.path.join(workpath, args.data_dir)

    # load config info
    fp = open(args.config_file)
    config_data = json.load(fp)
    fp.close()

    # check config format version
    config_version = 1
    if "version" in config_data:
        config_version = config_data["version"]

    # check step config
    if args.step_config:
        scfp = open(args.step_config)
        step_config = json.load(scfp)
        scfp.close()
        if "steps" in step_config:
            step_config = step_config["steps"]
        # check config format version
        if "version" in config_data:
            config_version = config_data["version"]
    elif "steps" in config_data:
        step_config = config_data["steps"]
    else:
        raise Exception("no step config")

    # load base words
    generater.WordsManager.init_words()
    # load ext words
    parse_words(args)

    if "projects" in config_data:
        for project_config in config_data["projects"]:
            repack_project(args.src_project, args.out_dir, args.resource_dir,
                           args.data_dir, project_config, step_config,
                           args.action_config, args.steps, args.ignore_steps,
                           config_version)
    elif "project" in config_data:
        repack_project(args.src_project, args.out_dir, args.resource_dir,
                       args.data_dir, config_data["project"], step_config,
                       args.action_config, args.steps, args.ignore_steps,
                       config_version)