Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Intellij, pyCharm, etc.
.idea/
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ Features:
- undo/redo in HexEditor and in ConstructEditor
- extensible for custom adapters

## Installation
## Installation (for use in your own project)
The preferred way to installation is via PyPI:
```
pip install construct-editor
```

## Installation as standalone
The preferred way to installation is:
- Open a command line in the project folder (`construct-editor`)
- Create a new virtual environment via `virtualenv .venv`
- Activate it with `.venv\Scripts\activate.ps1` or `.venv\Scripts\activate.bat`
- Install via `pip install -e .` (remember the `.` at the end of the line)

## Getting started (Standalone)
To start the standalone version, just execute the following in the command line:
```
Expand Down Expand Up @@ -50,15 +57,14 @@ frame.Show(True)
app.MainLoop()
```

This snipped generate a gui like this:
This snipped generates a GUI like this:

[Screenshot of the example]

## Widgets
### ConstructHexEditor
This is the main widget ot this library. It offers a look at the raw binary data and also at the parsed structure.
It offers a way to modify the raw binary data, which is then automaticly converted to the structed view. And also it support to modify the structed data and build the binary data from it.

It offers a way to modify the raw binary data, which is then automaticly converted to the structed view. It also supports to modify the structed data and build the binary data from it.

### ConstructEditor
This is just the right side of the `ConstructHexEditor`, but can be used also used as standalone widget. It provides:
Expand Down
5 changes: 3 additions & 2 deletions construct_editor/gallery/test_greedyrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ class Entry(cst.DataclassMixin):
id: int = cst.csfield(cs.Int8sb)
width: int = cst.csfield(cs.Int8sb)
height: int = cst.csfield(cs.Int8sb)
_protected: int = cst.csfield(cs.Int8sb)


constr = cs.GreedyRange(cst.DataclassStruct(Entry))

gallery_item = GalleryItem(
construct=constr,
example_binarys={
"5": bytes([1, 10, 10, 2, 10, 10, 3, 18, 18, 4, 10, 10, 5, 20, 20]),
"1": bytes([1, 10, 10]),
"5": bytes([1, 10, 10, 1, 2, 10, 10, 2, 3, 18, 18, 3, 4, 10, 10, 4, 5, 20, 20, 5]),
"1": bytes([1, 10, 10, 1]),
"Zeros": bytes([]),
},
)
7 changes: 4 additions & 3 deletions construct_editor/helper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,14 +616,15 @@ def dvc_item_restore_expansion(self):
subentry.dvc_item_restore_expansion()

# default "add_nonstruct_subentries_to_list" ##############################
def create_flat_subentry_list(self, flat_subentry_list: List["EntryConstruct"]):
def create_flat_subentry_list(self, flat_subentry_list: List["EntryConstruct"], hide_protected: bool):
"""Create a flat list with all subentires, recursively"""
subentries = self.subentries
if subentries is not None:
for subentry in subentries:
subentry.create_flat_subentry_list(flat_subentry_list)
subentry.create_flat_subentry_list(flat_subentry_list, hide_protected)
else:
flat_subentry_list.append(self)
if not hide_protected or not self.name.startswith("_") and self.name != "":
flat_subentry_list.append(self)

# default "create_obj_panel" ##############################################
def create_obj_panel(self, parent) -> ObjEditorMixin:
Expand Down
8 changes: 4 additions & 4 deletions construct_editor/widgets/construct_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def get_column_name(self, selected_item, col):
raise ValueError(f"{repr(entry)} is no valid entry")

flat_subentry_list: List["EntryConstruct"] = []
entry.create_flat_subentry_list(flat_subentry_list)
entry.create_flat_subentry_list(flat_subentry_list, self.hide_protected)

return ".".join(flat_subentry_list[col].path)

Expand Down Expand Up @@ -353,7 +353,7 @@ def GetValue(self, item: dv.DataViewItem, col: int):
col = col - len(ConstructEditorColumn)

flat_subentry_list: List["EntryConstruct"] = []
entry.create_flat_subentry_list(flat_subentry_list)
entry.create_flat_subentry_list(flat_subentry_list, self.hide_protected)
if len(flat_subentry_list) > col:
return flat_subentry_list[col].obj_str
else:
Expand Down Expand Up @@ -663,7 +663,7 @@ def _reload_dvc_columns(self):
if list_viewed_entry.subentries is not None:
for subentry in list_viewed_entry.subentries:
flat_list = []
subentry.create_flat_subentry_list(flat_list)
subentry.create_flat_subentry_list(flat_list, self.hide_protected)
list_cols = max(list_cols, len(flat_list))

for list_col in range(list_cols):
Expand All @@ -678,7 +678,7 @@ def _rename_dvc_columns(self, entry: EntryConstruct):
if (entry.parent is not None) and (
entry.parent in self._model.list_viewed_entries
):
entry.create_flat_subentry_list(flat_list)
entry.create_flat_subentry_list(flat_list, self.hide_protected)

list_cols = self._dvc.GetColumnCount() - len(ConstructEditorColumn)
for list_col in range(list_cols):
Expand Down