Skip to main content

A tool to intercept calls to other tools and alter their arguments

Project description

cmd-interceptor

Maintainability PyPI PyPI version PyPI

A tool to intercept calls to your command line tools and alter their args.

Requires UNIX and working Python3 and whereis.

Installation

Since the interceptor PyPI package name is taken, you ought to install interceptor the following way:

pip install cmd-interceptor

Or, if you don't have pip:

git clone https://github.com/Dronehub/interceptor.git
cd interceptor
python setup.py install

Usage

Prepare the configuration

To override g++ put a JSON file at /etc/interceptor.d/g++

with the following contents:

{
  "args_to_disable": ["-quiet"],
  "args_to_append": ["-DDEBUG"]],
  "args_to_prepend": ["-v"],
  "args_to_replace": [["-march=native", "-mcpu=native"]],
  "display_before_start": true,
  "notify_about_actions": false
}

Configuring

If the intercepted command sees any arguments given in args_to_disable they will be removed before being passed to target command.

You give two-item lists in args_to_replace. If the first item occurs in arguments, it will be replaced by the second item.

If arguments in args_to_append are not in arguments, they will be appended to the arguments.

The arguments in args_to_append will be appended in the order they are listed.

If arguments in args_to_prepend are not in arguments, they will be prepended to arguments.

The arguments in args_to_prepend will be appended in the order they are listed.

If you don't prepare the configuration file in advance, an empty file will be created for you.

If display_before_start is set, then before the launch the application name and parameters actually passed to it will be displayed on stdout.

If notify_about_actions is set, then interceptor will print out each case an action is attempted.

The intercept command

The intercept command is the basic command used to interface with interceptor.

Intercepting tools

Say, to intercept the command foo invoke:

intercept foo

Note that foo's executable must be discoverable by whereis. There should be ideally a single executable file, otherwise interceptor will patch all of them. Interceptor should display the following:

Successfully intercepted foo

Note that you will be unable to proceed if foo is already an interceptor wrapper.

A Python wrapper will be found at previous location of foo, while it itself will be copied to the same directory but named foo-intercepted. The wrapper will hold the name of foo inside, so you can symlink it safely (eg. symlink of g++ to c++).

To cancel intercepting foo type:

intercept undo foo

To check whether foo is being intercepted type:

intercept status foo

This will additionally validate and reformat it's configuration file. This will return information about whether it's config is a symlink, or whether the tool is partially patched (ie. there are executables reachable within PATH that haven't been patched). To rectify this issue just type

intercept foo --force

Any call of intercept with a single argument (and optional switch) will be treated as order to intercept this command, so if you're trying to intercept, say show you just type:

intercept show

To provide configuration for foo type

intercept configure foo```

And type in the configuration in JSON format, followed by Ctrl+D.

To display current configuration for foo type:

intercept show foo

To have intercept display when the tool is called type:

intercept display foo

To hide the display type:

intercept hide foo

To have nano/vi run to edit your config file type:

intercept edit foo

To add an argument to be appended to the command type:

intercept append foo arg

To add an argument to be prepended to the command type:

intercept prepend foo arg

To add an argument to be eliminated if foo is called with it type:

intercept disable foo arg

To replace arg1 with arg2 each time foo is called type:

intercept replace foo arg1 arg2

To have intercept display when an action is taken type:

intercept notify foo

To hide the notifications type:

intercept unnotify foo

To symlink bar's configuration to that of foo type:

intercept link foo bar

To copy foo's configuration to that of bar type:

intercept copy foo bar

Note that intercept will refuse to link to foo if foo is already a symlink. To circumvent that type:

intercept link foo bar --force

To toggle argument deduplication (only unique arguments will be passed) type:

intercept enable-deduplication foo  # enable it
intercept disable-deduplication foo  # disable it

To append all calls to this instruction into /var/log/inteceptor.d/instruction_name:

intercept log foo # enable it
intercept unlog foo # disable it

To reset configuration of foo, type

intercept reset foo

This will tell you if foo's configuration was a symlink. Note that this will unlink foo is it is already a symlink.

Note that many of the aforementioned commands check first to see it foo is intercepted. You can pass --force to skip that check.

If you mean to pass --force as an argument, and not as a switch, interceptor will treat only the first --force found as a switch and remove it from further command processing. Rethink your naming of commands in that case.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmd-interceptor-2.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cmd_interceptor-2.1-py3.8.egg (21.2 kB view details)

Uploaded Egg

cmd_interceptor-2.1-py2.py3-none-any.whl (12.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file cmd-interceptor-2.1.tar.gz.

File metadata

  • Download URL: cmd-interceptor-2.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

File hashes

Hashes for cmd-interceptor-2.1.tar.gz
Algorithm Hash digest
SHA256 c633e653c9dc53f02030628be5b20d3dcb7eef8ba23efd80332dbd9668b08125
MD5 5125cc7007eaf639c02908979c16f13b
BLAKE2b-256 a79466b09d2a8404682cd3ac9ab6deed5936e4eea5b505fae88ee049be9d4c53

See more details on using hashes here.

File details

Details for the file cmd_interceptor-2.1-py3.8.egg.

File metadata

  • Download URL: cmd_interceptor-2.1-py3.8.egg
  • Upload date:
  • Size: 21.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

File hashes

Hashes for cmd_interceptor-2.1-py3.8.egg
Algorithm Hash digest
SHA256 ca41331cf65313434db28db22a07e6de77447e42a2f4cc4e8d9b5545f99ca0ec
MD5 5ba6e02c97652cc2f2fe872d721e8df0
BLAKE2b-256 957b9977d77b8f8422d31c5d1ec29a8d53db09e9d99715c004ce09ddcb2bd440

See more details on using hashes here.

File details

Details for the file cmd_interceptor-2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: cmd_interceptor-2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

File hashes

Hashes for cmd_interceptor-2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b1fb6a69a1fc257df106d09204d7f771b45ba1a804c1c35612d501d08e08fc4c
MD5 f5f834c2a4111618a8fcf660e0e2d0aa
BLAKE2b-256 5e84fda86fa99e725a63f1907fe8796647c0d60a95f3a95739ffb07ea20cf4e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page