pkg module

Some console-friendly methods are exposed in pkg.*, and defined at pkg.commands.

pkg.commands.install(spec, repo=None, upgrade=False)

Download and install a package from specified repository. See install_from_repo().

Parameters:
  • spec (str) – name==version, or just name only.
  • repo (list(str) or None) – URL of the repository. Default: g['repos']
  • upgrade – Upgrade when already installed if True.
pkg.commands.remove(name)

Remove a package locally (LocalPackage.remove).

pkg.commands.local(name)

Find an installed package (LocalPackage.by_name).

Returns:None if package is not found, else LocalPackage instance.
Return type:LocalPackage
pkg.commands.remote(name, repo=None)

Find a remote package from given repos.

Parameters:
  • name – Name of the package
  • repo (list(str) or None) – URL of the repository. Default: g['repos']
Returns:

None if package is not found, else InstallablePackage instance.

Return type:

InstallablePackage

pkg.commands.refresh()

Rescan and load available plugins.

pkg.commands.upgrade(spec, repo=None)

Upgrade specified package. (pkg.install(spec, repo, upgrade=True))

Parameters:
  • spec (str) – name==version, or just name only.
  • repo – target repository to download.

pkg.package: Package-related classes

Package-related classes and methods are in pkg.package module. All constructing arguments are accessible via property.

class pkg.package.LocalPackage(id, path, version)

Bases: object

static all(disabled=False)

List all packages installed at g['path']['packages'].

Return type:list(LocalPackage)
static by_name(name, prefix=None)

Returns a package with specified name.

Return type:LocalPackage
info()

Loads info.json and returns a parsed JSON object.

Return type:dict
install(remove_on_fail=False)

Run python scripts specified by installers field in info.json.

Returns:None
load(force=False)

Actually does ida_loaders.load_plugin(paths), and updates IDAUSR variable.

loaders()
plugins()
populate_env()

A passive version of load; it only populates IDAUSR variable. It’s called at idapythonrc.py.

procs()
remove()

Removes a package.

class pkg.package.InstallablePackage(id, name, version, description, author, repo)

Bases: object

install(upgrade=False)

Just calls InstallablePackage.install_from_repo(self.repo, self.id, upgrade).

pkg.repo: Repository information

class pkg.repo.GitHubRepository(repo, timeout=8)

Bases: pkg.repo.Repository

GitHub-hosted repository. https://github.com/Jinmo/idapkg-repo

get(name)

Fetch metadata for single package from the repo.

Returns:None if package is not found, else a InstallablePackage object
Return type:pkg.package.InstallablePackage or None
list()

Fetch a list of all packages in the repo.

Returns:list of InstallablePackage in the repo.
Return type:list(pkg.package.InstallablePackage)
releases(name)

Fetch a list of releases of specified package.

class pkg.repo.OldRepository(url, timeout=8)

Bases: pkg.repo.Repository

S3-hosted repository. https://github.com/Jinmo/idapkg-api

get(name)

Fetch metadata for single package from the repo.

Returns:None if package is not found, else a InstallablePackage object
Return type:pkg.package.InstallablePackage or None
list()

Fetch a list of all packages in the repo.

Returns:list of InstallablePackage in the repo.
Return type:list(pkg.package.InstallablePackage)
releases(name)

Fetch a list of releases of specified package.

class pkg.repo.Repository

Bases: object

An instance of this class represents a single repository.

get(name)

Fetch metadata for single package from the repo.

Returns:None if package is not found, else a InstallablePackage object
Return type:pkg.package.InstallablePackage or None
list()

Fetch a list of all packages in the repo.

Returns:list of InstallablePackage in the repo.
Return type:list(pkg.package.InstallablePackage)
releases(name)

Fetch a list of releases of specified package.

pkg.repo.get_online_packages(repos=None)

Generates a list of packages from specified repositories.

Parameters:repos (list(str) or None) – Array of repository urls (string). Default: g[‘repos’]
Returns:list(InstallablePackage) from each repos.

pkg.config: config.json as g objects

This module generates and manages config data. Initial config is like this:

__initial_config = {
    'path': {
        'virtualenv': idapkg_dir('python'),
        'packages': idapkg_dir('packages')
    },
    'repos': [
        'https://api.idapkg.com'
    ],
    'idausr_native_bases': [None, None]
}
g:Config object extended from __initial_config. Loaded from and saved to ~/idapkg/config.json. g['path']['packages'] == idapkg_dir('python') initially.

pkg.env: IDA version, and EA

os:operating system. ‘win’ | ‘mac’ | ‘linux’
ea:current ea. 32 | 64
version:Decimal object for IDA Pro’s version (ex. Decimal(6.95))
version_info:namedtuple with version details (ex. VersionPair(major=7, minor=0, micro=171130))

pkg.process: process launchers with output redirected

Both method redirects stdout to IDA Pro’s console.

class pkg.process.Popen(*args, **kwargs)

Subclass of subprocess.Popen() that if stdout is not given, it’ll redirect stdout to messages window.

pkg.process.system(cmd)

Wrapper around os.system(), except that output will be redirected to messages window.

Parameters:cmd – Command to execute.
Returns:exit status.
Return type:int