Skip to content

Commit

Permalink
Run any OFRAK Component in the GUI (#287)
Browse files Browse the repository at this point in the history
* Revert sending script in primary response

* associate RID with tag/attribute, unable to find any attributes

* Add get_script method

* working resource selector generator

* Fetch script during certain frontend actions

* store scripts by session

* Move root getting into SB, begin adding var names

* Add var name replacement to action strings

* Add name generation

* Consoldiated ScriptBuilder code

* Update var naming code with marcs interface for sessions

* VSCode bad import paths :/

* Code runs, attempts to get non-existant var name

* Server runs without error

* Add root cache

* Some missing awaits and what not

* Trying to make things work

* added _add_action_to_session

* fixes

* Fix script spacing issues

* Clean up script, everything has 1 extra tab

* Exported script runs

* Working patches in gui script

* Add script gui pane

* dedent returns list not string

* Add initial syntax highlighting

* Fix highlighting, CSS, and lint

* Fix close button, minor lint things

* Script download button

* Black and remove resutl from some strings

* Added comments to script footer to guide users on backends

* Add to Changelog

* Changes based on feedback from PR

* Move script_builder to gui

* Changed json back to orjson and removed debug message in exception decorator

* Fix dimensions and minify new icon SVG

* get_all_components_for_resource works, get_config_for_component does not

* Update ofrak_core/ofrak/gui/server.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Get config working

* Add initial component + config support to frontend

* Run generic component

* oops forgot to save in vscode

* Forgot to save again

* Auto generate component fields and send request

* Reformat config from server

* Some stuff got reverted when i messed up my merge

* Send full name of config class

* Add orjson back, remove debug print

* Send config type the right way

* Component query

* Broke out fields to new component

* Add Dropdown to Component View

* Open Config view on Run

* Connect ComponentsView to ConfigView

* Add icon

* Fixes based on PR feedback

* Swap ordereddict for list, remote update_script

* Handle config=None, some boilerplate fresh componet after run code and check config field types

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Edward Larson <wasabiofip@gmail.com>

* Fix missed get_script call, remove old comment

* Updates from feedback, plus add json import back

* Slightly more sane ordering of methods

* Auto refresh after run component

* Updated selectable attributes exception

* Recursive component config fields, some issues

* Fix button bar CSS

* Add filtering to Run Components

* Mostly working config types

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Some html formatting

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/cli/command/gui.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/gui/server.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Apply changes to feedback

* Fix script sharing across sessions

* Update ofrak_core/ofrak/gui/script_builder.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Fill out comments on public methods

* Modify css on component filter

* Ensure actions update script, fix up doc strings

* Fix up comments, hex strings, update on delete

* Fix up find & replace and add tag doc strings

* Select on vaddr

* Make add_action last step in route handlers

* Revert backendurl/this.uri changes

* Added bytes to type checking

* Update ofrak_core/ofrak/gui/server.py

Co-authored-by: Edward Larson <wasabiofip@gmail.com>

* Handle SelectableAttrErr in add_variable

* Make MyPy happy

* Remove unused methods, add get_script test

* Remove local version of notebook file

* Revert notebook files

* Missing spaces

* Improve error message in script

* Revert helper_functions

* Revert helper functions part deux

* Script queue and commit wrapping actual ofrak calls

* Add test case for selectable attr err

* Add dtb selectable attributes and some formatting

* Add cmake back to Dockerstub

* Revert Dockerstub

* Make MyPy happy again

* Add missing commit script, always return script

* Remove unnecessary call to hex()

* Dequeue script on exception

* Minor formatting/accuracy changes

* Fix IDs in test case

* Add clear queue test - this is currently failing

* Index missing resource names

* removed backend url from new routes

* Some small fixes after merging

* Aesthetic changes to Component Config view

* Improve component visuals

* Highlight modified resources

* Add error message to component config view

* Disable shortscuts in views w text inputs

* Clear indicator when packed

* Fix up test

* Add styling to Add Element button

* Remove duplicate lines from merge conflict

* Change all CC type hints to ComponentConfig and beginings of serializer specific inputs from gui

* Optional and Enum working

* Make optional default to null

* Add targetable tag filter to run component view

* Added filter to components view and tests

* CHANGELOG for PR #287

* Add script to run component, remove NoneType refs

* Run pre-commit hook

* Remove EnumType

* Update ofrak_core/CHANGELOG.md

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Update frontend/src/stores.js

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Simple mods from PR

* add back orjson

* Make union type select a dropdown

* Better handle elipsis

* Support alternative checkbox alignment

* Adjust component filter CSS

* Lint

* Refactor componentsview code

* Refactor ComponentConfig into ComponentView

* Clean up Component View CSS

* Further improve component config style

Plus small quality of life improvements

* Make show all components button do what it says

* change typing.get_args to typing_inspect.get_args

* Add/Remove dict/list elements

* Make Optional behave like Union

* Fix enums

* Force SourceBundle to underlying dict type

* Add button bar to box with X to remove

* Fix button bar

* Change add button to a + icon

* Remove underscores and capitalize names

* Added typing.Iterable

* Minor fixes

* Some edits after merge

* frontend linter after update

* newline in svg file

* working toolchain selection in frontend

* SourceBundle file browser and etc.

* Make dicts work properly and remove calculator so remove button works for ints

* add SourceBundle serializer

* small cleanups

* Add color to var

* frontend linting

* Make mypy smile

* Update frontend/src/ComponentConfigNode.svelte

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Addressing comments by Jacob from PR

* Test fix ups

* Simplify modifier view hotkey conditional

* Re-Add Calculator to Int input

* Lint

* Hide run component behind experimental featues

* lint.. again

* Add missing test for ofrak server

* Test status only on get_tags_and_num_components test

* delete unused function, better test for SourceBundle serializer

* update changelog

* Update disassemblers/ofrak_capstone/ofrak_capstone/components.py

Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>

* Take wyatts suggestion on capstone typing.

---------

Co-authored-by: Marc Zalik <marc.zalik@gmail.com>
Co-authored-by: Dan Pesce <dan@redballoonsecurity.com>
Co-authored-by: Jacob Strieb <99368685+rbs-jacob@users.noreply.github.com>
Co-authored-by: Edward Larson <wasabiofip@gmail.com>
Co-authored-by: edward <edward@redballoonsecurity.com>
  • Loading branch information
6 people committed May 22, 2023
1 parent c06d8e1 commit d71059d
Show file tree
Hide file tree
Showing 44 changed files with 1,571 additions and 46 deletions.
2 changes: 1 addition & 1 deletion disassemblers/ofrak_capstone/ofrak_capstone/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(
super().__init__(resource_factory, data_service, resource_service)
self._disassembler_service = disassembler_service

async def analyze(self, resource: Resource, config: None) -> RegisterUsage:
async def analyze(self, resource: Resource, config=None) -> RegisterUsage:
program_attrs = await resource.analyze(ProgramAttributes)

instruction = await resource.view_as(Instruction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def __init__(
async def analyze(
self, resource: Resource, config: Optional[GhidraProjectConfig] = None
) -> GhidraProject:

# TODO: allow multiple headless server instances
os.system("pkill -if analyzeHeadless")
if config is not None:
Expand Down
1 change: 1 addition & 0 deletions frontend/public/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--main-fg-color: white;
--selected-bg-color: #86e3ed;
--comment-color: #eb8e5b;
--modified-color: #dc4e47;
--font: "cartograph";
--highlight-color: #fff259; /* Snake color */
--accent-text-color: #a9ed96; /* Caterpillar color */
Expand Down
1 change: 1 addition & 0 deletions frontend/public/icons/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions frontend/public/icons/run.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import AudioPlayer from "./AudioPlayer.svelte";
import ByteclassView from "./ByteclassView.svelte";
import CarouselSelector from "./CarouselSelector.svelte";
import ComponentsView from "./ComponentsView.svelte";
import EntropyView from "./EntropyView.svelte";
import FindReplaceView from "./FindReplaceView.svelte";
import HexView from "./HexView.svelte";
import JumpToOffset from "./JumpToOffset.svelte";
import LoadingAnimation from "./LoadingAnimation.svelte";
Expand Down Expand Up @@ -110,9 +112,12 @@
function handleShortcut(e) {
// Don't handle keypresses from within text inputs.
// Disable shortcuts in views with text inputs, otherwise misclicking outside of a text area may
// cause users to accidentally run shortcuts.
if (
["input", "textarea"].includes(e.target?.tagName.toLocaleLowerCase()) ||
e.target.isContentEditable
e.target.isContentEditable ||
modifierView
) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/BinaryModifyView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
import { selected, selectedResource as _selectedResource } from "./stores.js";
const selectedResource = $_selectedResource;
export let modifierView, dataPromise;
export let modifierView, dataPromise, resourceNodeDataMap;
let startInput,
endInput,
startOffset,
Expand Down Expand Up @@ -181,6 +181,7 @@
await selectedResource.queue_patch(patchData, startOffset, endOffset);
}
resourceNodeDataMap[$selected].modified = true;
modifierView = undefined;
refreshResource();
} catch (err) {
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/Checkbox.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<style>
label {
margin-left: 1em;
margin-right: 1em;
display: inline-flex;
flex-direction: row;
Expand All @@ -27,6 +26,11 @@
box-sizing: content-box;
}
label input[type="checkbox"].leftbox + span {
margin-left: 0;
margin-right: 2ch;
}
label input[type="checkbox"]:checked + span::after {
content: "";
display: block;
Expand Down
Loading

0 comments on commit d71059d

Please sign in to comment.