Esempio n. 1
0
def main(args: Namespace) -> None:
    if not (os.geteuid() == 0):
        fail_with('This script must be run with root privileges! Exiting.')

    if args.profiles:
        res = request_or_die(requests.get, '/profiles', 'Unable to get profiles')
        for p in sorted(res.json(), key=lambda p: p['exe']):
            print_profile_information(p)
    else:
        res = request_or_die(requests.get, '/processes', 'Unable to get processes')
        processes = res.json()
        if not args.threads:
            processes = [p for p in processes if p['pid'] == p['tid']]
        for p in sorted(processes, key=lambda p: (p['pid'], p['tid'])):
            print_process_information(p, args.threads)
Esempio n. 2
0
def load(args: Namespace) -> None:
    res = request_or_die(requests.put, f'/profiles/load',
                         'Unable to load profiles')
    body = res.json()
    loaded = body['loaded']
    err = body['error']
    print(f'Loaded {loaded} profiles, with {err} errors.')
Esempio n. 3
0
def save(args: Namespace) -> None:
    res = request_or_die(requests.put, f'/profiles/save',
                         'Unable to save profiles')
    body = res.json()
    saved = body['saved']
    err = body['error']
    print(f'Saved {saved} profiles, with {err} errors.')
Esempio n. 4
0
def tolerize(args: Namespace) -> None:
    if args.profile:
        res = request_or_die(
            requests.put, f'/profiles/exe/{args.profile}/tolerize',
            f'Unable to tolerize profile at exe {args.profile}')
    elif args.pid:
        res = request_or_die(requests.put,
                             f'/processes/pid/{args.pid}/tolerize',
                             f'Unable to tolerize profile at pid {args.pid}')
    else:
        raise NotImplementedError('No PID or profile supplied.')
    body = res.json()
    if args.profile:
        print(f'Tolerized profile {body["exe"]} successfully.')
    else:
        print(
            f'Tolerized PID {body["pid"]} ({body["profile"]["exe"]}) successfully.'
        )
Esempio n. 5
0
def status(args: Namespace) -> None:
    res = request_or_die(requests.get, f'/status', 'Unable to get status')
    body = res.json()
    for k, v in body.items():
        keystr = f'{k}:'
        print(f'{keystr:<16} {v}')
Esempio n. 6
0
def set(args: Namespace) -> None:
    setting = EBPH_SETTINGS(args.category)
    value = args.value
    res = request_or_die(requests.put, f'/settings/{setting}/{value}',
                         f'Failed to change {setting.name} to {value}')
    print(f'Changed {setting.name} to {value}.')