コード例 #1
0
ファイル: chartype.py プロジェクト: loxygenK/blin-tool
def main():
    parser = ArgParser("chartype", arguments)
    char_type = parser.get_or("type", DEFAULT_CHAR_TYPE)
    char_form = (BOLD * parser["bold"]) | (ITALIC * parser["italic"])

    if char_type not in char_heads:
        print("No such char type: {}".format(char_type))
        print("Available types:\n  {}".format("\n  ".join(char_heads.keys())))
        return

    if char_form not in char_heads[char_type]:
        print("Unavailable form:{}".format(char_form_flag_to_str(char_form)))
        print("Available forms: \n{}".format("\n".join(
            [char_form_flag_to_str(x) for x in char_heads[char_type].keys()])))
        return

    content = " ".join(parser["content"])
    if content == "":
        content = "".join(sys.stdin.readlines())
        content = content.rstrip("\n")

    print("".join([
        chr(chartable.index(x) +
            char_heads[char_type][char_form]) if x in chartable else x
        for x in content
    ]))
コード例 #2
0
 def test_parse_all_flags(self):
     parser = ArgParser('test_parse_all_flags')
     parser.allow_label(True)
     args, libfuzzer_opts, libfuzzer_args, subprocess_args = parser.parse([
         '--debug',
         '--device',
         'device',
         '--foreground',
         '--monitor',
         '--no-cipd',
         '--output',
         'output',
         '--staging',
         'staging',
         'name',
         'label',
     ])
     self.assertArgsEqual(args,
                          debug=True,
                          device='device',
                          foreground=True,
                          monitor=True,
                          no_cipd=True,
                          output='output',
                          staging='staging',
                          name='name',
                          label='label')
     self.assertEqual(libfuzzer_opts, {})
     self.assertEqual(libfuzzer_args, [])
     self.assertEqual(subprocess_args, [])
コード例 #3
0
 def test_from_args(self):
     host = MockHost()
     parser = ArgParser('description')
     parser.require_name(False)
     # netaddr should get called with 'just-four-random-words', and fail
     with self.assertRaises(RuntimeError):
         args = parser.parse_args(['--device', 'just-four-random-words'])
         device = Device.from_args(host, args)
コード例 #4
0
def main():
    parser = ArgParser('Lists corpus instances in CIPD for the named fuzzer')
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    with Corpus.from_args(fuzzer, args) as corpus:
        cipd = Cipd(corpus)
        print(cipd.instances())
    return 0
コード例 #5
0
    def test_parse_args_missing_value(self):
        parser = ArgParser('test_parse_args_missing_value')
        parser.require_name(False)

        with self.assertRaises(SystemExit):
            parser.parse_args(['--device'])

        with self.assertRaises(SystemExit):
            parser.parse_args(['--output'])

        with self.assertRaises(SystemExit):
            parser.parse_args(['--staging'])
コード例 #6
0
    def test_pull(self):
        mock = MockDevice()
        fuzzer = Fuzzer(mock, u'mock-package1', u'mock-target3')
        parser = ArgParser('description')

        args = parser.parse_args(['1/3'])
        corpus = Corpus.from_args(fuzzer, args)
        corpus.pull()
        self.assertIn(
            ' '.join(
                mock.get_ssh_cmd([
                    'scp', '[::1]:' + fuzzer.data_path('corpus/*'), corpus.root
                ])), mock.host.history)
コード例 #7
0
    def test_push(self):
        mock = MockDevice()
        fuzzer = Fuzzer(mock, u'mock-package1', u'mock-target3')
        parser = ArgParser('description')

        args = parser.parse_args(['1/3'])
        corpus = Corpus.from_args(fuzzer, args)
        with tempfile.NamedTemporaryFile(dir=corpus.root) as f:
            corpus.push()
            self.assertIn(
                ' '.join(
                    mock.get_ssh_cmd([
                        'scp', f.name, '[::1]:' + fuzzer.data_path('corpus')
                    ])), mock.host.history)
コード例 #8
0
    def test_parse_args_unrecognized(self):
        parser = ArgParser('test_parse_args_unrecognized')
        parser.require_name(False)

        with self.assertRaises(SystemExit):
            parser.parse_args(['--unknown'])

        with self.assertRaises(SystemExit):
            parser.parse_args(['-help=1'])

        parser.require_name(True)
        parser.allow_label(True)
        with self.assertRaises(SystemExit):
            parser.parse_args(['one', 'two', 'three'])
コード例 #9
0
ファイル: stop_fuzzer.py プロジェクト: xyuan/fuchsia
def main():
    parser = ArgParser('Stops the named fuzzer.')
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if fuzzer.is_running():
        print('Stopping ' + str(fuzzer) + '.')
        fuzzer.stop()
    else:
        print(str(fuzzer) + ' is already stopped.')
    return 0
コード例 #10
0
ファイル: repro_units.py プロジェクト: xyuan/fuchsia
def main():
    parser = ArgParser(
        'Runs the named fuzzer on provided test units, or all current test ' +
        'units for the fuzzer. Use \'check-fuzzer\' to see current tests units.'
    )
    args, fuzzer_args = parser.parse_known_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if fuzzer.repro(fuzzer_args) == 0:
        print('No matching artifacts found.')
        return 1
    return 0
コード例 #11
0
    def test_from_args(self):
        fuzzer = Fuzzer(MockDevice(), u'mock-package1', u'mock-target3')
        parser = ArgParser('description')

        args = parser.parse_args(['1/3'])
        corpus = Corpus.from_args(fuzzer, args)
        self.assertTrue(os.path.exists(corpus.root))

        tmp_dir = tempfile.mkdtemp()
        try:
            args = parser.parse_args(['1/3', '--staging', tmp_dir])
            corpus = Corpus.from_args(fuzzer, args)
            self.assertEqual(tmp_dir, corpus.root)
        finally:
            shutil.rmtree(tmp_dir)
コード例 #12
0
ファイル: list_fuzzers.py プロジェクト: xyuan/fuchsia
def main():
    parser = ArgParser(
        'Lists fuzzers matching NAME if provided, or all fuzzers.')
    parser.require_name(False)
    args = parser.parse_args()

    host = Host.from_build()

    fuzzers = Fuzzer.filter(host.fuzzers, args.name)
    if len(fuzzers) == 0:
        print('No matching fuzzers.')
        return 1
    print('Found %d matching fuzzers:' % len(fuzzers))
    for fuzzer in fuzzers:
        print('  %s/%s' % fuzzer)
    return 0
コード例 #13
0
    def test_parse_args_label(self):
        parser = ArgParser('test_parse_args_label')

        # Error if label present when not allowed.
        with self.assertRaises(SystemExit):
            parser.parse_args(['name', 'label'])

        # label not allowed if name is optional.
        parser.require_name(False)
        with self.assertRaises(AssertionError):
            parser.allow_label(True)

        parser.require_name(True)
        parser.allow_label(True)
        args = parser.parse_args(['name', 'label'])
        self.assertArgsEqual(args, name='name', label='label')
コード例 #14
0
    def test_parse_args_name(self):
        parser = ArgParser('test_parse_args_name')

        # By default, 'name' is required
        parser.require_name(True)
        with self.assertRaises(SystemExit):
            parser.parse_args([])

        args = parser.parse_args(['name'])
        self.assertArgsEqual(args, name='name')

        # 'name' can be made optional.
        parser.require_name(False)
        args = parser.parse_args([])
        self.assertArgsEqual(args)

        args = parser.parse_args(['name'])
        self.assertArgsEqual(args, name='name')
コード例 #15
0
def main():
    parser = ArgParser(
        'Transfers a fuzzing corpus for a named fuzzer from a device to CIPD')
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if fuzzer.measure_corpus()[0] == 0:
        print('Ignoring ' + str(fuzzer) + '; corpus is empty.')
        return 0
    with Corpus.from_args(fuzzer, args) as corpus:
        corpus.pull()
        cipd = Cipd(corpus)
        if not args.no_cipd:
            cipd.create()
    return 0
コード例 #16
0
ファイル: start_fuzzer.py プロジェクト: xyuan/fuchsia
def main():
    parser = ArgParser(
        'Starts the named fuzzer.  Additional arguments are passed through.')
    args, fuzzer_args = parser.parse_known_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if not args.monitor:
        with Corpus.from_args(fuzzer, args) as corpus:
            cipd = Cipd(corpus)
            if not args.no_cipd:
                cipd.install('latest')
            corpus.push()

        print(
            '\n****************************************************************'
        )
        print(' Starting ' + str(fuzzer) + '.')
        print(' Outputs will be written to:')
        print('   ' + fuzzer.results())
        if not args.foreground:
            print(' You should be notified when the fuzzer stops.')
            print(' To check its progress, use `fx fuzz check ' + str(fuzzer) +
                  '`.')
            print(' To stop it manually, use `fx fuzz stop ' + str(fuzzer) +
                  '`.')
        print(
            '****************************************************************\n'
        )
        fuzzer.start(fuzzer_args)
        if not args.foreground:
            subprocess.Popen(['python', sys.argv[0], '--monitor', str(fuzzer)])
    else:
        fuzzer.monitor()
        title = str(fuzzer) + ' has stopped.'
        body = 'Output written to ' + fuzzer.results() + '.'
        print(title)
        print(body)
        host.notify_user(title, body)
    return 0
コード例 #17
0
def main():
    parser = ArgParser(
        'Reports status for the fuzzer matching NAME if ' +
        'provided, or for all running fuzzers.  Status includes execution ' +
        'state, corpus size, and number of artifacts.')
    parser.require_name(False)
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzers = Fuzzer.filter(host.fuzzers, args.name)

    pids = device.getpids()
    silent = True
    for pkg, tgt in fuzzers:
        fuzzer = Fuzzer(device, pkg, tgt)
        if not args.name and tgt not in pids:
            continue
        silent = False
        if tgt in pids:
            print(str(fuzzer) + ': RUNNING')
        else:
            print(str(fuzzer) + ': STOPPED')
        print('    Output path:  ' + fuzzer.data_path())
        print('    Corpus size:  %d inputs / %d bytes' %
              fuzzer.measure_corpus())
        artifacts = fuzzer.list_artifacts()
        if len(artifacts) == 0:
            print('    Artifacts:    None')
        else:
            print('    Artifacts:    ' + artifacts[0])
            for artifact in artifacts[1:]:
                print('                  ' + artifact)
    if silent:
        print('No fuzzers are running.  Include \'name\' to check specific ' +
              'fuzzers.')
        return 1
    return 0
コード例 #18
0
def main():
    parser = ArgParser(
        'Minimizes the current corpus for the named fuzzer. This should be ' +
        'used after running the fuzzer for a while, or after incorporating a '
        + 'third-party corpus using \'fetch-corpus\'')
    args, fuzzer_args = parser.parse_known_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    with Corpus.from_args(fuzzer, args) as corpus:
        cipd = Cipd(corpus)
        if not args.no_cipd:
            cipd.install('latest')
        corpus.push()
        if fuzzer.merge(fuzzer_args) == (0, 0):
            print('Corpus for ' + str(fuzzer) + ' is empty.')
            return 1
        corpus.pull()
        if not args.no_cipd:
            cipd.create()
    return 0
コード例 #19
0
    def test_parse_args_each_flag(self):
        parser = ArgParser('test_parse_args_each_flag')

        args = parser.parse_args(['--debug', 'name'])
        self.assertArgsEqual(args, debug=True, name='name')

        args = parser.parse_args(['--device', 'device', 'name'])
        self.assertArgsEqual(args, device='device', name='name')

        args = parser.parse_args(['--foreground', 'name'])
        self.assertArgsEqual(args, foreground=True, name='name')

        args = parser.parse_args(['--monitor', 'name'])
        self.assertArgsEqual(args, monitor=True, name='name')

        args = parser.parse_args(['--no-cipd', 'name'])
        self.assertArgsEqual(args, name='name', no_cipd=True)

        args = parser.parse_args(['--output', 'output', 'name'])
        self.assertArgsEqual(args, name='name', output='output')

        args = parser.parse_args(['--staging', 'staging', 'name'])
        self.assertArgsEqual(args, name='name', staging='staging')
コード例 #20
0
 def test_parse(self):
     parser = ArgParser('test_parse')
     args, libfuzzer_opts, libfuzzer_args, subprocess_args = parser.parse([
         '--debug',
         '-foo=twas',
         '--device',
         'device',
         '-bar=bryllyg',
         'name',
         '-device="and the"',
         'corpus/',
         '--',
         '-foo=slythy',
         'toves',
         '--debug',
     ])
     self.assertArgsEqual(args, debug=True, device='device', name='name')
     self.assertEqual(libfuzzer_opts, {
         'foo': 'twas',
         'bar': 'bryllyg',
         'device': '"and the"',
     })
     self.assertEqual(libfuzzer_args, ['corpus/'])
     self.assertEqual(subprocess_args, ['-foo=slythy', 'toves', '--debug'])
コード例 #21
0
 def test_from_args(self):
     mock_device = MockDevice()
     parser = ArgParser('description')
     with self.assertRaises(SystemExit):
         args = parser.parse_args(['target4'])
         fuzzer = Fuzzer.from_args(mock_device, args)