Skip to content

Commit

Permalink
Add identify recursively to the GUI (#435)
Browse files Browse the repository at this point in the history
* Add identify recursively to the GUI

* Add CHANGELOG entry

* Fix start page typo

* Add test
  • Loading branch information
rbs-jacob authored Feb 29, 2024
1 parent 9f8d8e6 commit b45c6b4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
19 changes: 19 additions & 0 deletions frontend/src/ofrak/remote_resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,25 @@ export class RemoteResource extends Resource {
await this.update_script();
}

async identify_recursively() {
const identify_recursively_results = await fetch(
`${this.uri}/identify_recursively`,
{
method: "POST",
}
).then(async (r) => {
if (!r.ok) {
throw Error(JSON.stringify(await r.json(), undefined, 2));
}
return r.json();
});
ingest_component_results(identify_recursively_results, this.resource_list);
this.flush_cache();
this.update();

await this.update_script();
}

async unpack_recursively() {
const unpack_recursively_results = await fetch(
`${this.uri}/unpack_recursively`,
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/ofrak/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export class Resource {
throw new NotImplementedError("identify");
}

async identify_recursively() {
throw new NotImplementedError("identify_recursively");
}

async pack() {
throw new NotImplementedError("pack");
}
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/resource/ResourceTreeToolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@
},
},
{
text: "Identify Recursively",
iconUrl: "/icons/identify.svg",
shortcut: "i+Shift",
onclick: async (e) => {
await rootResource.identify_recursively();
if (!resourceNodeDataMap[$selected]) {
resourceNodeDataMap[$selected] = {};
}
resourceNodeDataMap[$selected].childrenPromise =
rootResource.get_children();
refreshResource();
},
},
{
text: "Unpack Recursively",
iconUrl: "/icons/unpack_r.svg",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/StartView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@
{#if !dragging && !showProjectOptions}
<h1>Drag in a file to analyze</h1>
<p style:margin-bottom="0">
Click anwyhere to browse for a file to analyze
Click anywhere to browse for a file to analyze
</p>
{:else if dragging}
<h1>Drop the file!</h1>
Expand Down
1 change: 1 addition & 0 deletions ofrak_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Refactor HexView and related components to use mousewheel instead of scroll and compartmentalize all comonents to src/hex. ([#427](https://github.com/redballoonsecurity/ofrak/pull/427))
- Add an improved ISO9660 packer that leverages `mkisofs` instead of PyCdLib. ([#393](https://github.com/redballoonsecurity/ofrak/pull/393))
- Add UEFI binary unpacker. ([#399](https://github.com/redballoonsecurity/ofrak/pull/399))
- Add recursive identify functionality in the GUI. ([#435](https://github.com/redballoonsecurity/ofrak/pull/435))

### Fixed
- Improved flushing of filesystem entries (including symbolic links and other types) to disk. ([#373](https://github.com/redballoonsecurity/ofrak/pull/373))
Expand Down
15 changes: 15 additions & 0 deletions ofrak_core/ofrak/gui/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def __init__(
web.post("/{resource_id}/pack_recursively", self.pack_recursively),
web.post("/{resource_id}/analyze", self.analyze),
web.post("/{resource_id}/identify", self.identify),
web.post("/{resource_id}/identify_recursively", self.identify_recursively),
web.post("/{resource_id}/data_summary", self.data_summary),
web.get("/{resource_id}/get_parent", self.get_parent),
web.get("/{resource_id}/get_ancestors", self.get_ancestors),
Expand Down Expand Up @@ -538,6 +539,20 @@ async def identify(self, request: Request) -> Response:
raise e
return json_response(await self._serialize_component_result(result))

@exceptions_to_http(SerializedError)
async def identify_recursively(self, request: Request) -> Response:
resource = await self._get_resource_for_request(request)
script_str = """
await {resource}.identify_recursively()"""
await self.script_builder.add_action(resource, script_str, ActionType.MOD)
try:
result = await resource.auto_run_recursively(all_identifiers=True)
await self.script_builder.commit_to_script(resource)
except Exception as e:
await self.script_builder.clear_script_queue(resource)
raise e
return json_response(await self._serialize_component_result(result))

@exceptions_to_http(SerializedError)
async def data_summary(self, request: Request) -> Response:
resource = cast(Resource, await self._get_resource_for_request(request))
Expand Down
11 changes: 11 additions & 0 deletions ofrak_core/test_ofrak/unit/test_ofrak_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ async def test_identify(ofrak_client: TestClient, hello_world_elf):
assert resp_body["modified"][0]["id"] == create_body["id"]


async def test_identify_recursively(ofrak_client: TestClient, hello_world_elf):
create_resp = await ofrak_client.post(
"/create_root_resource", params={"name": "hello_world_elf"}, data=hello_world_elf
)
create_body = await create_resp.json()
resp = await ofrak_client.post(f"/{create_body['id']}/identify_recursively")
assert resp.status == 200
resp_body = await resp.json()
assert resp_body["modified"][0]["id"] == create_body["id"]


async def test_data_summary(ofrak_client: TestClient, ofrak_server, hello_world_elf, test_resource):
create_resp = await ofrak_client.post(
"/create_root_resource", params={"name": "hello_world_elf"}, data=hello_world_elf
Expand Down

0 comments on commit b45c6b4

Please sign in to comment.