Take bytes type and print a formated string
(bytes:bytes, start:int=0, group_size:int=4)
| 562 | |
| 563 | |
| 564 | def print_bytes(bytes:bytes, start:int=0, group_size:int=4) -> None: |
| 565 | """Take bytes type and print a formated string""" |
| 566 | # Initiate a list where each element is a string in formate of |
| 567 | # index_n+1 ... index_n+group_size | hex_n+1 ... hex_n+group_size |
| 568 | output = [] |
| 569 | # Loop through the bytes in groups of 'group_size' |
| 570 | for index in range(len(bytes[start:]) // group_size): |
| 571 | output.append("\t".join(str(index * group_size + i + start) for i in range(group_size)) + |
| 572 | "\t|\t" + |
| 573 | "\t".join( |
| 574 | bytes[index * group_size + i + start : |
| 575 | index * group_size + i + start + 1].hex().upper() |
| 576 | for i in range(group_size))) |
| 577 | if len(bytes[start:]) % group_size != 0: |
| 578 | # Create a line for the remaining bytes (if any) |
| 579 | index += 1 |
| 580 | output.append("\t".join(str(index * group_size + i + start) for i in range(group_size)) + |
| 581 | "\t|\t" + |
| 582 | "\t".join(bytes[index * group_size + i + start : |
| 583 | index * group_size + i + start + 1].hex().upper() |
| 584 | for i in range(len(bytes[start:]) % group_size))) |
| 585 | print("\n".join(output)) |
| 586 | |
| 587 | |
| 588 |
nothing calls this directly
no outgoing calls
no test coverage detected