# bbarchivist API Documentation

## Archivist module

`bbarchivist.archivist.``do_magic`(osversion, radioversion, softwareversion, localdir, radios=True, compressed=True, deleted=True, hashed=True, crc32=False, adler32=False, sha1=True, sha224=False, sha256=False, sha384=False, sha512=False, md5=True, md4=False, ripemd160=False, whirlpool=False, cappath='cap.exe', download=True, extract=True, loaders=True, signed=True, compmethod='7z')

  Wrap around multi-autoloader creation code. Some combination of creating, downloading, hashing, compressing and moving autoloaders.

  Parameters: | osversion (str) – OS version, 10.x.y.zzzz. radioversion (str) – Radio version, 10.x.y.zzzz. softwareversion (str) – Software release, 10.x.y.zzzz. localdir (str) – Working directory. Required. radios (bool) – Whether to create radio autoloaders. True by default. compressed (bool) – Whether to compress files. True by default. deleted (bool) – Whether to delete uncompressed files. True by default. hashed (bool) – Whether to hash files. True by default. crc32 (bool) – Whether to use CRC32. False by default. adler32 (bool) – Whether to use Adler-32. False by default. sha1 (bool) – Whether to use SHA-1. True by default. sha224 (bool) – Whether to use SHA-224. False by default. sha256 (bool) – Whether to use SHA-256. False by default. sha384 (bool) – Whether to use SHA-384. False by default. sha512 (bool) – Whether to use SHA-512. False by default. md5 (bool) – Whether to use MD5. True by default. md4 (bool) – Whether to use MD4. False by default. ripemd160 (bool) – Whether to use RIPEMD160. False by default. whirlpool (bool) – Whether to use Whirlpool. False by default. cappath (str) – Path to cap.exe. Default is local dir ‘cap.exe’. download (bool) – Whether to download bar files. True by default. extract (bool) – Whether to extract bar files. True by default. loaders (bool) – Whether to create autoloaders. True by default. signed (bool) – Whether to delete signed files. True by default. compmethod (str) – Compression method. Default is “7z” with fallback “zip”.

## Archivist wrapper

`bbarchivist.archivist_wrap.``main`()

  Parse arguments from argparse/questionnaire.

  Invoke `bbarchivist.archivist.doMagic()` with those arguments.

## Barutils module

`bbarchivist.barutils.``compress`(filepath, method='7z', szexe='7za.exe')

  Compress all autoloader files in a given folder, with a given method.

  Parameters: | filepath (str) – Working directory. Required. method (str) – Compression type. Default is “7z”. Defined in source. szexe (str) – Path to 7z executable, if needed.

`bbarchivist.barutils.``create_blitz`(a_folder, swver)

  Create a blitz file: a zipped archive of all app/core/radio bars.

  Parameters: | a_folder (str) – Target folder. swver (str) – Software version to title the blitz.

`bbarchivist.barutils.``extract_bars`(filepath)

  Extract .signed files from .bar files. Use system zlib.

  Parameters: | filepath (str) – Path to bar file directory.

`bbarchivist.barutils.``move_loaders`(localdir, exedir_os, exedir_rad, zipdir_os, zipdir_rad)

  Move autoloaders to zipped and loaders directories in localdir.

  Parameters: | localdir (str) – Local directory, containing files you wish to move. exedir_os (str) – Large autoloader .exe destination. exedir_rad (str) – Small autoloader .exe destination. zipdir_os (str) – Large autoloader archive destination. zipdir_rad (str) – Small autoloader archive destination.

`bbarchivist.barutils.``remove_empty_folders`(a_folder)

  Remove empty folders in a given folder using os.walk().

  Parameters: | a_folder (str) – Target folder.

`bbarchivist.barutils.``reset`(tarinfo)

  Filter for TAR compression.

  Parameters: | tarinfo (TarInfo) – TarInfo instance to use.

## Carrierchecker module

`bbarchivist.carrierchecker.``doMagic`(mcc, mnc, device, download=False, upgrade=False, directory='X:\\bbndk\\workspace\\bbarchivist\\docs\\bbarchivist', export=False, blitz=False)

  Wrap around `bbarchivist.networkutils` carrier checking.

  Parameters: | mcc (int) – Country code. mnc (int) – Network code. device (str) – Device ID (SXX100-#) download (bool) – Whether or not to download. Default is false. upgrade (bool) – Whether or not to use upgrade files. Default is false. directory (str) – Where to store files. Default is local directory. export (bool) – Whether or not to write URLs to a file. Default is false. blitz (bool) – Whether or not to create a blitz package. Default is false.

## Carrierchecker wrapper

`bbarchivist.carrierchecker_wrap.``main`()

  Parse arguments from argparse/questionnaire.

  Invoke `bbarchivist.carrierchecker.doMagic()` with those arguments.

## Escreens module

`bbarchivist.escreens.``calculate_escreens`(pin, app, uptime, duration=30)

  Calculate key for the Engineering Screens based on input.

  Parameters: | pin (str) – PIN to check. 8 character hexadecimal, lowercase. app (str) – App version. 10.x.y.zzzz. uptime (str) – Uptime in ms. duration (str) – 1, 3, 6, 15, 30 (days).

## Escreens wrapper

`bbarchivist.escreens_wrap.``main`()

  Parse arguments from argparse/questionnaire.

  Invoke `bbarchivist.escreens.calculate_escreens()` with arguments.

## Hashwrapper wrapper

`bbarchivist.filehasher_wrap.``main`()

  Parse arguments from argparse/questionnaire.

  Invoke `bbarchivist.hashwrapper.verifier()` with those arguments.

## Filehashtools module

`bbarchivist.filehashtools.``adler32hash`(filepath, blocksize=16777216)

  Return Adler32 checksum of a file.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``crc32hash`(filepath, blocksize=16777216)

  Return CRC32 checksum of a file.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``md4hash`(filepath, blocksize=16777216)

  Return MD4 hash of a file; depends on system SSL library.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``md5hash`(filepath, blocksize=16777216)

  Return MD5 hash of a file.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``ripemd160hash`(filepath, blocksize=16777216)

  Return RIPEMD160 hash of a file; depends on system SSL library.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``sha1hash`(filepath, blocksize=16777216)

  Return SHA-1 hash of a file.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``sha224hash`(filepath, blocksize=16777216)

  Return SHA-224 hash of a file.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``sha256hash`(filepath, blocksize=16777216)

  Return SHA-256 hash of a file.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``sha384hash`(filepath, blocksize=16777216)

  Return SHA-384 hash of a file.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``sha512hash`(filepath, blocksize=16777216)

  Return SHA-512 hash of a file.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

`bbarchivist.filehashtools.``whirlpoolhash`(filepath, blocksize=16777216)

  Return Whirlpool hash of a file; depends on system SSL library.

  Parameters: | filepath (str) – File you wish to verify. blocksize (int) – How much of file to read at once.

## Hashwrapper module

`bbarchivist.hashwrapper.``verifier`(workingdir, blocksize=16777216, crc32=False, adler32=False, sha1=True, sha224=False, sha256=False, sha384=False, sha512=False, md5=True, md4=False, ripemd160=False, whirlpool=False)

  For all files in a directory, perform various hash/checksum functions. Functions based on boolean arguments, writing the output to a .cksum file.

  Parameters: | workingdir (str) – Path containing files you wish to verify. blocksize (int) – How much of file to read at once. crc32 (bool) – Use of CRC32. False by default. adler32 (bool) – Use of Adler-32. False by default. sha1 (bool) – Use of SHA-1. True by default. sha224 (bool) – Use of SHA-224. False by default. sha256 (bool) – Use of SHA-256. False by default. sha384 (bool) – Use of SHA-384. False by default. sha512 (bool) – Use of SHA-512. False by default. md5 (bool) – Use of MD5. True by default. md4 (bool) – Use of MD4. False by default. Depends on system. ripemd160 (bool) – Use of RIPEMD160. False by default. Depends on system. whirlpool (bool) – Use of Whirlpool. False by default. Depends on system.

## Lazyloader module

`bbarchivist.lazyloader.``doMagic`(osversion, radioversion, softwareversion, device, localdir, autoloader)

  Wrap the tools necessary to make one autoloader.

  Parameters: | osversion (str) – OS version, 10.x.y.zzzz. radioversion (str) – Radio version, 10.x.y.zzzz. softwareversion (str) – Software version, 10.x.y.zzzz. device (int) – Device family to create loader for. localdir (str) – Working path. Default is local dir. autoloader (bool) – Whether to run loaders. Default is false. Windows-only.

## Lazyloader wrapper

`bbarchivist.lazyloader_wrap.``main`()

  Parse arguments from argparse/questionnaire.

  Invoke `bbarchivist.lazyloader.doMagic()` with those arguments.

## Linkgen module

`bbarchivist.linkgen.``doMagic`(osversion, radioversion, softwareversion)

  Generate debrick/core/radio links for given OS, radio, software release.

  Parameters: | osversion (str) – OS version, 10.x.y.zzzz. radioversion (str) – Radio version, 10.x.y.zzzz. softwareversion (str) – Software version, 10.x.y.zzzz.

## Linkgen wrapper

`bbarchivist.linkgen_wrap.``main`()

  Parse arguments from argparse/questionnaire.

  Invoke `bbarchivist.linkgen.doMagic()` with those arguments.

## Loadergen module

`bbarchivist.loadergen.``generate_lazy_loader`(osversion, radioversion, device, cap='cap.exe', localdir='X:\\bbndk\\workspace\\bbarchivist\\docs\\bbarchivist')

  `generate_loaders()`, but for making one OS/radio loader.

  Parameters: | osversion (str) – OS version, 10.x.y.zzzz. radioversion (str) – Radio version, 10.x.y.zzzz. device (int) – Selected device, from cap (str) – Path to cap.exe. Default is local dircap.exe. localdir (str) – Working path. Default is local dir.

`bbarchivist.loadergen.``generate_loaders`(osversion, radioversion, radios=True, cap='cap.exe', localdir='X:\\bbndk\\workspace\\bbarchivist\\docs\\bbarchivist')

  Create and properly label autoloaders. Leverages Python implementation of cap.exe.

  Parameters: | osversion (str) – OS version, 10.x.y.zzzz. radioversion (str) – Radio version, 10.x.y.zzzz. radios (bool) – Whether to make radios or not. True by default. cap (str) – Path to cap.exe. Default is local dircap.exe. localdir (str) – Working path. Default is local dir.

## Networkutils module

class `bbarchivist.networkutils.``DownloadManager`(download_dict, output_directory, thread_count=5)

  Bases: `object`

  Class that handles queued downloads. Based on: http://pipe-devnull.com/2012/09/13/queued-threaded-http-downloader-in-python.html

  `begin_downloads`()

    Start `Downloader` threads for queued downloads.

class `bbarchivist.networkutils.``Downloader`(queue, output_directory)

  Bases: `threading.Thread`

  Downloads files attached to supplied threads from DownloadManager. Based on: http://pipe-devnull.com/2012/09/13/queued-threaded-http-downloader-in-python.html

  `download`(url)

    Download file from given URL.

    Parameters: | url (str) – URL to download from.

  `run`()

    Download files from queue.

`bbarchivist.networkutils.``availability`(url)

  Check HTTP status code of given URL. 200 or 301-308 is OK, else is not.

  Parameters: | url (str) – URL to check.

`bbarchivist.networkutils.``carrier_checker`(mcc, mnc)

  Query BlackBerry World to map a MCC and a MNC to a country and carrier.

  Parameters: | mcc (int) – Country code. mnc (int) – Network code.

`bbarchivist.networkutils.``carrier_update_request`(mcc, mnc, device, download=False, upgrade=False, blitz=False)

  Query BlackBerry servers, check which update is out for a carrier.

  Parameters: | mcc (int) – Country code. mnc (int) – Network code. device (str) – Hexadecimal hardware ID. download (bool) – Whether to download files. False by default. upgrade (bool) – Whether to use upgrade files. False by default. blitz (bool) – Whether or not to create a blitz package. False by default.

## Pseudocap module

`bbarchivist.pseudocap.``ghetto_convert`(intsize)

  Convert from decimal integer to little endian hexadecimal string, padded to 16 characters with zeros.

  Parameters: | intsize (integer) – Integer you wish to convert.

`bbarchivist.pseudocap.``make_autoloader`(filename, cap, firstfile, secondfile='', thirdfile='', fourthfile='', fifthfile='', sixthfile='', folder='X:\\bbndk\\workspace\\bbarchivist\\docs\\bbarchivist')

  Python implementation of cap.exe. Writes cap.exe, magic offset, signed files to a .exe file. `make_offset()` is used to create the offset.

  Parameters: | filename (str) – Name of autoloader. cap (str) – Location of cap.exe file. firstfile (str) – First signed file. Required. secondfile (str) – Second signed file. Optional. thirdfile (str) – Third signed file. Optional. fourthfile (str) – Fourth signed file. Optional. fifthfile (str) – Fifth signed file. Optional. sixthfile (str) – Sixth signed file. Optional. folder (str) – Working folder. Optional.

`bbarchivist.pseudocap.``make_offset`(cap, firstfile, secondfile='', thirdfile='', fourthfile='', fifthfile='', sixthfile='', folder='X:\\bbndk\\workspace\\bbarchivist\\docs\\bbarchivist')

  Create magic offset file for use in autoloader creation. Cap.exe MUST match separator version. Version defined in `bbarchivist.bbconstants._capversion`.

  Parameters: | cap (str) – Location of cap.exe file. firstfile (str) – First signed file. Required. secondfile (str) – Second signed file. Optional. thirdfile (str) – Third signed file. Optional. fourthfile (str) – Fourth signed file. Optional. fifthfile (str) – Fifth signed file. Optional. sixthfile (str) – Sixth signed file. Optional. folder (str) – Working folder. Optional.

## Utilities module

`bbarchivist.utilities.``escreens_duration`(duration)

  Check if escreens duration is valid.

  Parameters: | duration (int) – Duration to check.

`bbarchivist.utilities.``escreens_pin`(pin)

  Check if given PIN is valid (8 character hexadecimal)

  Parameters: | pin (str) – PIN to check.

`bbarchivist.utilities.``file_exists`(file)

  Check if file exists. Used for parsing file inputs from command line.

  Parameters: | file (str) – Path to a file, including extension.

`bbarchivist.utilities.``get_core_count`()

  Find out how many CPU cores this system has. Good for multicore compression.

`bbarchivist.utilities.``get_seven_zip`(talkative=False)

  Return name of 7-Zip executable. On POSIX, it MUST be 7za. On Windows, it can be installed or supplied with the script. `win_seven_zip()` is used to determine if it’s installed.

  Parameters: | talkative (bool) – Whether to output to screen. False by default.

`bbarchivist.utilities.``is_amd64`()

  Returns true if script is running on an AMD64 system

`bbarchivist.utilities.``is_linux`()

  Returns true if script is running on Linux.

`bbarchivist.utilities.``is_mac`()

  Returns true if script is running on OSX.

`bbarchivist.utilities.``is_windows`()

  Returns true if script is running on Windows.

`bbarchivist.utilities.``positive_integer`(inputint)

  Check if number > 0. Used for parsing integer inputs from command line.

  Parameters: | inputint (int) – Integer to check.

`bbarchivist.utilities.``prep_seven_zip`()

  Check for presence of 7-Zip. On POSIX, checks for p7zip. On Windows, checks for 7-Zip. Returns False if not found, True if found.

`bbarchivist.utilities.``return_family`(index)

  Return device family from selected HWID. Lists found in bbconstants module.

  Parameters: | index (int) – The index to look up.

`bbarchivist.utilities.``return_model`(index)

  Return device model from selected HWID/variant index. Lists found in bbconstants module.

  Parameters: | index (int) – The index to look up.

`bbarchivist.utilities.``str2bool`(v)

  Parse bool from string input.

  Parameters: | v (str) – String to check if it means True or False.

`bbarchivist.utilities.``win_seven_zip`(talkative=False)

  For Windows, checks where 7-Zip is. Consults registry first for any installed instances of 7-Zip. If it’s not there, it falls back onto the supplied executables. If those aren’t there, return “error”.

  Parameters: | talkative (bool) – Whether to output to screen. False by default.