Skip to content

Commit 5ccb3cc

Browse files
committed
static_files: support for binary patching
1 parent bfae6f5 commit 5ccb3cc

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ARG CONSOLE_VERSION="1.0.5"
99
ARG PENGUIN_PLUGINS_VERSION="1.5.15"
1010
ARG VPN_VERSION="1.0.24"
1111
ARG HYPERFS_VERSION="0.0.38"
12-
ARG GUESTHOPPER_VERSION="1.0.15"
12+
ARG GUESTHOPPER_VERSION="1.0.16"
1313
ARG GLOW_VERSION="1.5.1"
1414
ARG GUM_VERSION="0.14.5"
1515
ARG LTRACE_PROTOTYPES_VERSION="0.7.91"

docs/schema_doc.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,41 @@ Copy a file from the host into the guest
11151115
|__Type__|string|
11161116

11171117

1118+
#### `static_files.<string>.<type=binary_patch>` Patch binary file
1119+
1120+
1121+
##### `static_files.<string>.<type=binary_patch>.type` Type of file action (patch binary file)
1122+
1123+
|||
1124+
|-|-|
1125+
|__Type__|`"binary_patch"`|
1126+
1127+
1128+
##### `static_files.<string>.<type=binary_patch>.file_offset` File offset (integer)
1129+
1130+
|||
1131+
|-|-|
1132+
|__Type__|integer|
1133+
|__Default__|`null`|
1134+
1135+
Offset in the file to patch, from the start of the file
1136+
1137+
##### `static_files.<string>.<type=binary_patch>.hex_bytes` Bytes to write (hex string)
1138+
1139+
|||
1140+
|-|-|
1141+
|__Type__|string|
1142+
1143+
Hex string of bytes to write at the offset
1144+
1145+
```yaml
1146+
DEADBEEF
1147+
```
1148+
1149+
```yaml
1150+
90 90
1151+
```
1152+
11181153
## `plugins` Plugins
11191154

11201155

src/penguin/gen_image.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@ def _modify_guestfs(g, file_path, file, project_dir):
386386
# Create a symlink to desired target
387387
symlink_file = {"type": "symlink", "target": file["target"]}
388388
_symlink_modify_guestfs(g, file_path, symlink_file)
389+
elif action == "binary_patch":
390+
file_offset = file.get("file_offset")
391+
bytes_hex = file.get("hex_bytes")
392+
393+
# Convert hex string to bytes
394+
patch_bytes = bytes.fromhex(bytes_hex.replace(" ", ""))
395+
target_path = file_path
396+
397+
# Open the file and patch it
398+
p = g.adjust_path(target_path)
399+
if not os.path.isfile(p):
400+
raise FileNotFoundError(f"Target file for binary_patch not found: {target_path}")
401+
402+
with open(p, "r+b") as f:
403+
f.seek(file_offset)
404+
f.write(patch_bytes)
389405

390406
else:
391407
raise RuntimeError(f"Unknown file system action {action}")

src/penguin/penguin_config/structure.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,31 @@ class LibInject(BaseModel):
708708
),
709709
),
710710
),
711+
dict(
712+
discrim_val="binary_patch",
713+
title="Patch binary file",
714+
description=None,
715+
fields=(
716+
(
717+
"file_offset",
718+
int,
719+
Field(
720+
default=None,
721+
title="File offset (integer)",
722+
description="Offset in the file to patch, from the start of the file"
723+
),
724+
),
725+
(
726+
"hex_bytes",
727+
str,
728+
Field(
729+
title="Bytes to write (hex string)",
730+
description="Hex string of bytes to write at the offset",
731+
examples=["DEADBEEF", "90 90"],
732+
),
733+
),
734+
),
735+
),
711736
),
712737
)
713738

0 commit comments

Comments
 (0)