-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an ability to install OFRAK from source #314
Open
ANogin
wants to merge
55
commits into
redballoonsecurity:master
Choose a base branch
from
ANogin:feature/install_from_source
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
c80ce01
Allow local installation from source tree without docker
ANogin 8e2fd54
Fix unused import
ANogin 2bbd207
Handle missing binja dependency
ANogin f8d6fa5
black formatting
ANogin f037711
Use OFRAK_INSTALL_PYTHON to run install.py
ANogin c71df7f
Ignore more files in .gitignore
ANogin b48474c
Pre-install pyyaml
ANogin 4b1c79a
Fix some of the typos Jacob found
ANogin 93b073a
Merge branch 'feature/install_from_source' of github.com:ANogin/ofrak…
ANogin bf465a8
Fix a typo noticed by Jacob
ANogin ce9cc7e
Use logging instead of raw priting, where appropriate
ANogin 93afc76
Correct the formatting
ANogin 08a828e
Merge remote-tracking branch 'origin/master' into feature/install_fro…
ANogin 1ec4b3f
Use "npm install" to install rollup
ANogin 3d50cf3
Make the black version requirement consistent
ANogin 17ed5e8
Add an option to run tests after install
ANogin 0d7ff95
Updated the instructions for installing from source
ANogin 9c9c856
Add more detailed instructions to documentation
ANogin 68c9bd6
Merge remote-tracking branch 'origin/master' into feature/install_fro…
ANogin 597db82
Use $(PYTHON) to run mypy
ANogin ba347a9
Use correct version of python executable
ANogin ed59084
Add apt/brew package info for binwalk
ANogin df3b3ac
Ignore files generated by "make test"
ANogin cc02334
Add apt/brew package info for mksquashfs/unsquashfs
ANogin aa89083
Quiet mypy errors in `ofrak_binary_ninja`
ANogin 0285823
Fix another `ofrak_binary_ninja` mypy issue
ANogin 60011dc
Fix a weird `ofrak_binary_ninja` coverage issue
ANogin d5f4b87
Install `python-lzo`, `bincopy`, `binwalk` in `make install`/`make de…
ANogin 2f85e98
`jupyter` is required for `ofrak_tutorial_test/ofrak_tutorial_test.py…
ANogin ad4561d
Revert "`jupyter` is required for `ofrak_tutorial_test/ofrak_tutorial…
ANogin 4e0bb0f
Add a script to test all modules across all python versions
ANogin 5d22975
Correct incomplete `ofrak_type` test requirements
ANogin fbb75a7
Force `legacy-editable` setuptools flag
ANogin 38dcbd5
Ignore a couple of files generated by `make test`
ANogin 76d5942
Use python3.8 in docker images (#416)
ANogin 25fcc41
Dropping the .altinstr_replacement section from the toolchain (#414)
rbs-alexr d4ff0fa
Set the fallback font to monospace (#422)
rbs-jacob 2880879
Display strings with numbers primarily as strings (#423)
rbs-jacob 5505696
Add typing support to ofrak_ghidra package (#421)
paulnoalhyt 0f513fe
Fix occasional spurious test failures. (#424)
ANogin b805ac1
Update to angr==9.2.77 (#417)
ANogin 4f80d75
Move away from "$OFRAK_DIR" argument to $PACKAGE_PATH for Docker buil…
whyitfor af5bf50
Refactor the GUI hex view and pane components (#427)
dannyp303 db3abb1
Revert using SUBALIGN(0) for .bss sections (#431)
rbs-afflitto 59c4387
move resourceTreeNode and dataLength to stores (#434)
dannyp303 57e4e8a
Add identify recursively to the GUI (#435)
rbs-jacob faea3d8
Feature/angr decompilation view (#436)
dannyp303 da36f79
Bump aiohttp to ~=3.9.3 (#440)
whyitfor cd89508
Update orjston to ~=3.9.15 to address security issue. (#442)
whyitfor a92cd61
add lief add/remove section modifier (#443)
dannyp303 bff6daa
change strings unpacker target to none (#438)
dannyp303 240686f
Fix Carve/Modify bug, handle an error in the server, vscode doesnt li…
dannyp303 091ebac
Support `make -k test` in docker root (#446)
ANogin 16552c7
reduce chunking min limit from 64mb to 1mb (#449)
dannyp303 c0eb500
Explicitly set the downloaded package file name (#451)
rbs-afflitto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ develop: | |
|
||
.PHONY: inspect | ||
inspect: | ||
mypy | ||
$(PYTHON) -m mypy | ||
|
||
.PHONY: test | ||
test: inspect | ||
|
73 changes: 73 additions & 0 deletions
73
disassemblers/ofrak_angr/ofrak_angr/components/angr_decompilation_analyzer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from dataclasses import dataclass | ||
import angr | ||
from angr.analyses.decompiler import Decompiler | ||
from ofrak.component.analyzer import Analyzer | ||
from ofrak.component.identifier import Identifier | ||
from ofrak.resource_view import ResourceView | ||
|
||
from ofrak.resource import Resource | ||
from ofrak.core.complex_block import ComplexBlock | ||
from ofrak.service.resource_service_i import ResourceFilter | ||
from ofrak_angr.model import AngrAnalysis, AngrAnalysisResource | ||
|
||
|
||
@dataclass | ||
class AngrDecompilationAnalysis(ResourceView): | ||
decompilation: str | ||
|
||
|
||
class AngrDecompilationAnalysisIdentifier(Identifier): | ||
id = b"AngrDecompilationAnalysisIdentifier" | ||
targets = (ComplexBlock,) | ||
|
||
async def identify(self, resource: Resource, config=None): | ||
resource.add_tag(AngrDecompilationAnalysis) | ||
|
||
|
||
class AngrDecompilatonAnalyzer(Analyzer[None, AngrDecompilationAnalysis]): | ||
id = b"AngrDecompilationAnalyzer" | ||
targets = (ComplexBlock,) | ||
outputs = (AngrDecompilationAnalysis,) | ||
|
||
async def analyze(self, resource: Resource, config: None) -> AngrDecompilationAnalysis: | ||
# Run / fetch angr analyzer | ||
try: | ||
root_resource = await resource.get_only_ancestor( | ||
ResourceFilter(tags=[AngrAnalysisResource], include_self=True) | ||
) | ||
complex_block = await resource.view_as(ComplexBlock) | ||
angr_analysis = await root_resource.analyze(AngrAnalysis) | ||
|
||
cfg = angr_analysis.project.analyses[angr.analyses.CFGFast].prep()( | ||
data_references=True, normalize=True | ||
) | ||
|
||
function_s = [ | ||
func | ||
for addr, func in angr_analysis.project.kb.functions.items() | ||
if func.addr == complex_block.virtual_address | ||
] | ||
if len(function_s) == 0: | ||
# Check for thumb | ||
function_s = [ | ||
func | ||
for addr, func in angr_analysis.project.kb.functions.items() | ||
if func.addr == complex_block.virtual_address + 1 | ||
] | ||
if len(function_s) != 1: | ||
raise ValueError( | ||
f"Could not find angr function for function at address {complex_block.virtual_address}" | ||
) | ||
function = function_s[0] | ||
dec: Decompiler = angr_analysis.project.analyses[angr.analyses.Decompiler].prep()( | ||
function, cfg=cfg.model, options=None | ||
) | ||
if dec.codegen is not None: | ||
decomp = dec.codegen.text | ||
else: | ||
decomp = "No Decompilation available" | ||
return AngrDecompilationAnalysis(decomp) | ||
except Exception as e: | ||
return AngrDecompilationAnalysis( | ||
f"The decompilation for this Complex Block has failed with the error {e}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
disassemblers/ofrak_angr/ofrak_angr_test/assets/hello.x64.elf
Git LFS file not shown
36 changes: 36 additions & 0 deletions
36
disassemblers/ofrak_angr/ofrak_angr_test/test_decompilation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import List | ||
import os | ||
from ofrak_angr.components.angr_decompilation_analyzer import AngrDecompilationAnalysis | ||
from ofrak.ofrak_context import OFRAKContext | ||
from ofrak.core.complex_block import ComplexBlock | ||
from ofrak.service.resource_service_i import ResourceFilter | ||
|
||
|
||
async def test_angr_decompilation(ofrak_context: OFRAKContext): | ||
root_resource = await ofrak_context.create_root_resource_from_file( | ||
os.path.join(os.path.dirname(__file__), "assets/hello.x64.elf") | ||
) | ||
await root_resource.unpack_recursively( | ||
do_not_unpack=[ | ||
ComplexBlock, | ||
] | ||
) | ||
complex_blocks: List[ComplexBlock] = await root_resource.get_descendants_as_view( | ||
ComplexBlock, | ||
r_filter=ResourceFilter( | ||
tags=[ | ||
ComplexBlock, | ||
] | ||
), | ||
) | ||
decomps = [] | ||
for complex_block in complex_blocks: | ||
await complex_block.resource.identify() | ||
angr_resource: AngrDecompilationAnalysis = await complex_block.resource.view_as( | ||
AngrDecompilationAnalysis | ||
) | ||
decomps.append(angr_resource.decompilation) | ||
assert len(decomps) == 11 | ||
assert "" not in decomps | ||
assert "main" in " ".join(decomps) | ||
assert "print" in " ".join(decomps) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
angr==9.2.6 | ||
angr==9.2.77 | ||
importlib-resources # A workaround for https://github.com/redballoonsecurity/ofrak/issues/398 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ develop: | |
|
||
.PHONY: inspect | ||
inspect: | ||
mypy | ||
$(PYTHON) -m mypy | ||
|
||
.PHONY: test | ||
test: inspect | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't yet had a chance to test, but I wonder if making Binary Ninja an "external tool" creates the possibility of a confusing situation for a user: they explicitly set the Binary Ninja back end by either discovering it or setting a command-line argument, they set
exclude_components_missing_dependencies=True
(also settable by a command-line argument), and there is an issue with their Binary Ninja installation. In this case, when they go to analyze their file, it won't unpack code regions with Binary Ninja, but also won't give the user any feedback as to why.This may not be an issue, whether because this situation is sufficiently unlikely, because we don't deem this to be a problem, or because this issue doesn't actually manifest this way, but it's worth considering this situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other concern I have about making Binary Ninja an external tool like this is that it's not consistent with the other analysis back ends. We only show information about when Binary Ninja is missing, but don't show any of the respective information about which components won't be loaded when we don't have Ghidra installed, , for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is here because the binja backend is the one that actually prevents OFRAK from working at all if binja is not installed. Other backends do not have the issue.