Skip to content

Commit

Permalink
cli: pyimg4 img4 extract: add support for extracting raw/extra im4p…
Browse files Browse the repository at this point in the history
… data
  • Loading branch information
m1stadev committed Mar 24, 2024
1 parent e16c6d0 commit 7d9d372
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pyimg4/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,18 @@ def img4_create(
help='Input Image4 file.',
required=True,
)
@click.option(
'-r',
'--raw',
'raw',
type=click.File('wb'),
help='File to output Image4 payload data to.',
)
@click.option(
'--extra',
type=click.File('wb'),
help='File to output extra Image4 payload data to.',
)
@click.option(
'-p',
'--im4p',
Expand All @@ -828,6 +840,8 @@ def img4_create(
)
def img4_extract(
input_: BinaryIO,
raw: Optional[BinaryIO],
extra: Optional[BinaryIO],
im4p: Optional[BinaryIO],
im4m: Optional[BinaryIO],
im4r: Optional[BinaryIO],
Expand All @@ -841,9 +855,20 @@ def img4_extract(
except:
raise click.BadParameter(f'Failed to parse Image4 file: {input_.name}')

if all(i is None for i in (im4p, im4m, im4r)):
if all(i is None for i in (raw, extra, im4p, im4m, im4r)):
raise click.BadParameter('You must specify at least one output file')

if raw is not None:
raw.write(img4.im4p.payload.data)
click.echo(f'Extracted Image4 payload data to: {raw.name}')

if extra is not None:
if img4.im4p.payload.extra is None:
raise click.BadParameter('No extra Image4 payload data found')

extra.write(img4.im4p.payload.extra)
click.echo(f'Extracted extra Image4 payload data to: {extra.name}')

if im4p is not None:
if img4.im4p is None:
raise click.BadParameter('Image4 payload not found in Image4 file')
Expand Down

0 comments on commit 7d9d372

Please sign in to comment.