This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
generated from KOLANICH/python_project_boilerplate.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c15d95e
Showing
14 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = tab | ||
indent_size = 4 | ||
insert_final_newline = true | ||
end_of_line = lf | ||
|
||
[*.{yml,yaml,ksy}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
KOLANICH/python_project_boilerplate.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
allow: | ||
- dependency-type: "all" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: typical python workflow | ||
uses: KOLANICH-GHActions/typical-python-workflow@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/hcd2lime/kaitai | ||
/kaitai_struct_formats | ||
|
||
__pycache__ | ||
*.pyc | ||
*.pyo | ||
/*.egg-info | ||
/build | ||
/dist | ||
/.eggs | ||
/monkeytype.sqlite3 | ||
/.coverage | ||
*.py,cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No codes of conduct! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include UNLICENSE | ||
include *.md | ||
include tests | ||
include .editorconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
hcd2lime.py [![Unlicensed work](https://raw.githubusercontent.com/unlicense/unlicense.org/master/static/favicon.png)](https://unlicense.org/) | ||
=============== | ||
~~[wheel](https://gitlab.com/KOLANICH/hcd2lime.py/-/jobs/artifacts/master/raw/dist/lime-0.CI-py3-none-any.whl?job=build)~~ | ||
~~![GitLab Build Status](https://gitlab.com/KOLANICH/hcd2lime.py/badges/master/pipeline.svg)~~ | ||
~~![GitLab Coverage](https://gitlab.com/KOLANICH/hcd2lime.py/badges/master/coverage.svg)~~ | ||
~~[![GitHub Actions](https://github.com/KOLANICH/hcd2lime.py/workflows/CI/badge.svg)](https://github.com/KOLANICH/hcd2lime.py/actions/)~~ | ||
[![Coveralls Coverage](https://img.shields.io/coveralls/KOLANICH/hcd2lime.py.svg)](https://coveralls.io/r/KOLANICH/hcd2lime.py) | ||
[![Libraries.io Status](https://img.shields.io/librariesio/github/KOLANICH/hcd2lime.py.svg)](https://libraries.io/github/KOLANICH/hcd2lime.py) | ||
[![Code style: antiflash](https://img.shields.io/badge/code%20style-antiflash-FFF.svg)](https://codeberg.org/KOLANICH-tools/antiflash.py) | ||
|
||
Just a lib converting HCI communication dumps to Cypress chips into LiME memory dumps. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <https://unlicense.org/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def blobToWriteCommands(b, invalidCallback): | ||
from .kaitai import parse | ||
|
||
return parsedToWriteCommands(parse(b), invalidCallback) | ||
|
||
|
||
def parsedToWriteCommands(p, invalidCallback): | ||
for i, c in enumerate(p.commands): | ||
if c.opcode.group == c.Group.vendor_specific: | ||
vSC = c.parameters.payload | ||
if vSC.command == vSC.Command.write_ram: | ||
pld = vSC.payload | ||
yield (pld.address, pld.data) | ||
continue | ||
elif vSC.command == vSC.Command.launch_ram: | ||
yield None | ||
|
||
invalidCallback(i, c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from pathlib import Path | ||
from warnings import warn | ||
|
||
from lime import dump as limeDump | ||
from plumbum import cli | ||
|
||
from . import blobToWriteCommands | ||
|
||
|
||
class HCD2LiMECLI(cli.Application): | ||
"""Converts an *.hcd file for Cypress chips into LiME memory dump representing the writes found in the dump""" | ||
|
||
format = cli.switches.SwitchAttr(["-f", "--format"], help="Format of the dump") | ||
allowNonPatchram = cli.switches.Flag(["--allow-non-patchram"], help="Allow non-patchram HCI commands.") | ||
|
||
def main(self, dumpFile="./bcm4334.hcd"): | ||
hcdF = Path(dumpFile) | ||
|
||
if self.allowNonPatchram: | ||
|
||
def processInvalid(i, c): | ||
if c.opcode.group != c.Group.vendor_specific: | ||
warn("Command " + repr(i) + " is not vendor-specific: " + repr(c.opcode.group) + " " + repr(c.opcode.command)) | ||
else: | ||
vSC = c.parameters.payload | ||
warn("Command " + repr(i) + " is not used for patchram: " + repr(vSC.command)) | ||
|
||
else: | ||
|
||
def processInvalid(i, c): | ||
if c.opcode.group != c.Group.vendor_specific: | ||
raise ValueError("Command " + repr(i) + " is not vendor-specific: " + repr(c.opcode.group) + " " + repr(c.opcode.command), c) | ||
else: | ||
vSC = c.parameters.payload | ||
raise ValueError("Command " + repr(i) + " is not used for patchram: " + repr(vSC.command), c) | ||
|
||
data2up = list(blobToWriteCommands(hcdF.read_bytes(), processInvalid)) | ||
outFile = hcdF.parent / (hcdF.name + ".lime") | ||
with outFile.open("wb") as of: | ||
limeDump(data2up, of) | ||
|
||
|
||
if __name__ == "__main__": | ||
HCD2LiMECLI.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from io import BytesIO | ||
|
||
from kaitaistruct import KaitaiStream | ||
|
||
from .bluetooth_hcd import BluetoothHcd | ||
from .bluetooth_vendors_ids import BluetoothVendorsIds | ||
|
||
|
||
def parse(hcdBin): | ||
if isinstance(hcdBin, (bytes, bytearray)): | ||
iO = BytesIO(hcdBin) | ||
return BluetoothHcd(BluetoothVendorsIds.Vendor.cypress_semiconductor, KaitaiStream(iO)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[build-system] | ||
requires = ["setuptools>=61.2.0", "wheel", "setuptools_scm[toml]>=3.4.3", "kaitaiStructCompile.setuptools[toml]"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "hcd2lime" | ||
authors = [{name = "KOLANICH"}] | ||
description = "Converts an *.hcd file for Cypress chips into LiME memory dump representing the writes found in the dump" | ||
readme = "ReadMe.md" | ||
keywords = ["LiME", "Cypress", "Broadcom", "patchram", "internalblue", "bluetooth", "hci", "hcd"] | ||
license = {text = "Unlicense"} | ||
classifiers = [ | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Development Status :: 4 - Beta", | ||
"Environment :: Other Environment", | ||
"Intended Audience :: Developers", | ||
"License :: Public Domain", | ||
"Operating System :: OS Independent", | ||
"Topic :: Software Development :: Libraries :: Python Modules", | ||
] | ||
urls = {Homepage = "https://codeberg.org/KOLANICH-tools/hcd2lime.py"} | ||
requires-python = ">=3.4" | ||
dependencies = [ | ||
"kaitaistruct @ git+https://github.com/kaitai-io/kaitai_struct_python_runtime", | ||
"lime @ git+https://codeberg.org/KOLANICH-libs/lime.py.git", | ||
] | ||
dynamic = ["version"] | ||
|
||
[tool.setuptools] | ||
zip-safe = true | ||
packages = ["hcd2lime", "hcd2lime.kaitai"] | ||
|
||
[tool.setuptools_scm] | ||
|
||
[tool.kaitai] | ||
outputDir = "hcd2lime/kaitai" | ||
|
||
[tool.kaitai.repos."https://codeberg.org/KOLANICH/kaitai_struct_formats.git"."broadcom_patchram"] | ||
update = true | ||
localPath = "kaitai_struct_formats" | ||
|
||
[tool.kaitai.repos."https://codeberg.org/KOLANICH/kaitai_struct_formats.git"."broadcom_patchram".formats.bluetooth_hcd] | ||
path = "hardware/bluetooth/bluetooth_hcd.ksy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
import typing | ||
import itertools | ||
import os | ||
import sys | ||
import unittest | ||
from pathlib import Path | ||
from random import _urandom, randint | ||
|
||
from lime import * | ||
|
||
sys.path.insert(0, str(Path(__file__).absolute().parent.parent)) | ||
|
||
#from collections import OrderedDict | ||
#dict = OrderedDict | ||
|
||
|
||
def genRandRecord(minAddr=0, minSize=10, maxSize=20, maxAddr=(1 << 64)): | ||
start = randint(minAddr, maxAddr) | ||
stop = randint(start + minSize, min(start + maxSize, maxAddr)) | ||
len = stop - start | ||
payload = _urandom(len) | ||
return (start, payload) | ||
|
||
|
||
def genRandDump(): | ||
testStruct = [(0, b"")] | ||
for i in range(10): | ||
testStruct.append(genRandRecord(testStruct[-1][0] + len(testStruct[-1][1]))) | ||
del testStruct[0] | ||
return testStruct | ||
|
||
|
||
class Tests(unittest.TestCase): | ||
def test_roundtrip(self): | ||
d = genRandDump() | ||
f = dumps(d) | ||
d1 = loads(f) | ||
self.assertEqual(d, d1) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |