Skip to main content

A pure python implementation of the Android Fastboot protocols

Project description

pyfastboot

This is a modified version for specific project usage - for example, service permission granting program for all Nokia phones.

For ADB implementation, see adb_shell.

This repository contains a pure-python implementation of the Fastboot protocols, using libusb1 for USB communications.

This is a complete replacement and rearchitecture of the Android project's ADB and fastboot code

This code is mainly targeted to users that need to communicate with Android devices in an automated fashion, such as in automated testing.

Using as standalone tool

Once installed, one new binary should be available: pyfastboot.

Running ./make_tools.py creates one file: fastboot.zip. They can be run similar to native fastboot via the python interpreter:

python fastboot.zip oem device-info

Using as a Python Library

FIHSW model: See this file as reference

HMDSW model get permission code (note the dk_calculation module is unavailable yet).

from pyfastboot import fastboot
from io import StringIO
import dk_calculation
import sys

def _InfoCb(message):
    if not message.message:
        return
    print(message.message.decode('utf-8'))

def getsecver(device):
    tmp = sys.stdout
    result = StringIO()
    sys.stdout = result
    device.Oem('getsecurityversion', info_cb=_InfoCb)
    sys.stdout = tmp
    del tmp
    return result.getvalue().splitlines()

def getperm(device):
    tmp = sys.stdout
    result = StringIO()
    sys.stdout = result
    device.Oem('getpermissions', info_cb=_InfoCb)
    sys.stdout = tmp
    del tmp
    return result.getvalue().splitlines()

def authcode(device):
    return device.HmdAuthStart().decode('utf-8')

ThisDevice = fastboot.FastbootCommands()
ThisDevice.ConnectDevice()

# Essential Informations will be stored at these 3 variables.

product = ThisDevice.Getvar('product').decode('utf-8')
secver = getsecver(ThisDevice)[0]
psn = ThisDevice.Getvar('serialno').decode('utf-8')

# 1st permission type is flash
ThisDevice.HmdEnableAuth(1, dk_calculation.getresult(prjcode=product, serialnumber=psn, securityversion=secver, auth_code=authcode(ThisDevice))

# Check Enabled Permissions
print(getperm(ThisDevice))

# 3rd permission type is repair
ThisDevice.HmdEnableAuth(3, dk_calculation.getresult(prjcode=product, serialnumber=psn, securityversion=secver, auth_code=authcode(ThisDevice))

# Check Enabled Permissions
print(getperm(ThisDevice))

Pros

  • Simpler code due to use of libusb1 and Python.
  • API can be used by other Python code easily.
  • Errors are propagated with tracebacks, helping debug connectivity issues.
  • No daemon outliving the command.
  • Can be packaged as standalone zips that can be run independent of the CPU architecture (e.g. x86 vs ARM).

Cons

  • Technically slower due to Python, mitigated by no daemon.
  • Only one command per device at a time.

Dependencies

  • libusb1 (1.0.16+)
  • python-libusb1 (1.2.0+)
  • fastboot.zip (optional):
    • python-progressbar (2.3+)

History

1.3.11

  • Fixed the issue on device without Fastbootd mode cannot pass isFastbootdCheck.

1.3.10

  • Fixed dependencies issue.
  • Fixed the Getvar function issue.
  • Add new feature: logical-partition create, resize and delete under fastbootd. (CreateLogicalPartition, ResizeLogicalPartition, DeleteLogicalPartition)

1.3.8

  • Added support for Unisoc "flashing unlock_bootloader" function (UnisocUnlockBootloader())
  • Added support for vbmeta processing
  • Fixed issue of GetIdentifierToken function

1.3.6

  • Fixed dependencies bug
  • Added initial support of GetIdentifierToken function for HTC and Unisoc models (GetIdentifierToken())

1.3.5

  • Renaming it into pyfastboot
  • Add Nokia, Motorola and Xiaomi specific OEM command functions

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

pyfastboot-1.3.12.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

pyfastboot-1.3.12-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file pyfastboot-1.3.12.tar.gz.

File metadata

  • Download URL: pyfastboot-1.3.12.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.5

File hashes

Hashes for pyfastboot-1.3.12.tar.gz
Algorithm Hash digest
SHA256 154391e1a5954df41b4c7fd51afbbfa141424b1ec6481b6edaead870f9d4a2ec
MD5 43bfd0f334716a5039c076855bdea524
BLAKE2b-256 a70c4a222a01373d159bc085c9914ccc26d99a33aa0432b1588fbed539cb112f

See more details on using hashes here.

File details

Details for the file pyfastboot-1.3.12-py3-none-any.whl.

File metadata

  • Download URL: pyfastboot-1.3.12-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.5

File hashes

Hashes for pyfastboot-1.3.12-py3-none-any.whl
Algorithm Hash digest
SHA256 190ddc2da2d9b0466b90508714a43db4b7ad1f66a7a423429a2494892e81d0ed
MD5 489bdd261579977bdc7221f30909c4c1
BLAKE2b-256 9f8181b0eca9bd7d505214c3dc96c120730825df869401a1e97921a876521285

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