Skip to content
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

Feature/cached disasm #556

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
12f595e
add initial pyghidra, test fails to load
Dec 4, 2024
4fc4c66
working bb/cb unpacker
Dec 9, 2024
4a91519
Passes like 70% of tests
Dec 14, 2024
cb3c3c1
add gitattributes
Dec 14, 2024
b171a11
Update pyghidra code. CodeRegion, ComplexBlock, BasicBlock unpacking
Dec 15, 2024
11b1bf2
working tests with bb unapcker
Dec 17, 2024
d3a6133
oops, test lines included
Dec 18, 2024
e64f116
add cached disasmbler with simple json format
Dec 19, 2024
37fdfa8
added generation script for pyghidra and updated cached unapcker to n…
Dec 19, 2024
99a0881
keep analysis dict in memeory
Dec 20, 2024
5ad4d10
dependency inject cache store
Dec 20, 2024
a9df7ab
Fix indentation error
Dec 20, 2024
4e069c4
Update cache analysis store to store cache for all unpacked programs
Dec 20, 2024
8339413
get rid lookup to wokr
Dec 20, 2024
826f061
Update pyghidra generator to cli tool, create cached analysis tests u…
Jan 2, 2025
f084fb9
added some metadata with ghidra pie fix and hash checking, all tests …
Jan 2, 2025
2ba15dd
lint
Jan 2, 2025
6bbc9b5
update executable segment flag in cache file
Jan 3, 2025
381410f
Merge branch 'master' of github.com:dannyp303/ofrak into feature/cach…
Jan 3, 2025
b4ce27c
lint
Jan 3, 2025
95dc9a7
fix lfs text file issues
Jan 6, 2025
a03cac3
add cached decompilation and tests, renamed ofrak_cached to ofrak_cac…
Jan 8, 2025
48d1b72
lint
Jan 8, 2025
6eb7230
somehow had extra whitespace line
Jan 8, 2025
940decc
changelog
Jan 8, 2025
ada9a02
Merge branch 'master' into feature/cached_disasm
dannyp303 Jan 8, 2025
4bc241e
change ofrak_cached_diassembly name in lfs attributes
Jan 8, 2025
ead41cd
add lfs files
Jan 8, 2025
679f844
Merge branch 'feature/cached_disasm' of github.com:dannyp303/ofrak in…
Jan 8, 2025
a6c1147
update the pyghidra component to use the cached impl under the hood
Jan 9, 2025
42a2819
Merge branch 'master' into feature/cached_disasm
dannyp303 Jan 9, 2025
afa2762
EOF lint
Jan 9, 2025
78b06d4
update pyghidra component decomp component
Jan 9, 2025
598f716
updates for gui with pyghidra
Feb 5, 2025
c04f513
Merge branch 'master' of github.com:dannyp303/ofrak into feature/cach…
Feb 5, 2025
ce11765
update to docker release with pyghidra included
Feb 7, 2025
a092b53
review changes
Feb 13, 2025
b227e4a
lint
Feb 13, 2025
fc7aa72
Merge branch 'redballoonsecurity:master' into feature/cached_disasm
dannyp303 Feb 24, 2025
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
Prev Previous commit
Next Next commit
lint
Dan Pesce committed Jan 2, 2025
commit 2ba15ddc2cd388b90f5472c4c23755644635d92b
Original file line number Diff line number Diff line change
@@ -66,7 +66,6 @@ def __init__(
self.analysis_store = analysis_store

async def analyze(self, resource: Resource, config: CachedAnalysisAnalyzerConfig):

await resource.identify()
if not resource.has_tag(Program) and not resource.has_attributes(ProgramAttributes):
raise AttributeError(
@@ -77,7 +76,9 @@ async def analyze(self, resource: Resource, config: CachedAnalysisAnalyzerConfig
self.analysis_store.store_analysis(resource.get_id(), config.filename)
if not config.force:
if not self.verify_cache_file(resource):
raise ValueError("MD5 recorded in cache file does not match the hash of the requested resource, use the force config option to use this cache file anyway.")
raise ValueError(
"MD5 recorded in cache file does not match the hash of the requested resource, use the force config option to use this cache file anyway."
)
self.analysis_store.store_program_attributes(resource.get_id(), program_attributes)
cached_analysis_view = CachedAnalysis()
resource.add_view(cached_analysis_view)
@@ -87,8 +88,13 @@ async def analyze(self, resource: Resource, config: CachedAnalysisAnalyzerConfig
async def verify_cache_file(self, resource: Resource):
data = await resource.get_data()
md5_hash = hashlib.md5(data)
import ipdb; ipdb.set_trace()
return md5_hash.digest().hex() == self.analysis_store.get_analysis(resource.get_id())["metadata"]["hash"]
import ipdb

ipdb.set_trace()
return (
md5_hash.digest().hex()
== self.analysis_store.get_analysis(resource.get_id())["metadata"]["hash"]
)


class CachedProgramUnpacker(Unpacker[None]):
@@ -110,13 +116,16 @@ async def unpack(self, resource: Resource, config: None):
analysis = self.analysis_store.get_analysis(resource.get_id())
for key, mem_region in analysis.items():
if key.startswith("seg"):
await resource.create_child_from_view(CodeRegion(
virtual_address=mem_region["virtual_address"], size=mem_region["size"]
))
await resource.create_child_from_view(
CodeRegion(
virtual_address=mem_region["virtual_address"], size=mem_region["size"]
)
)


class CachedCodeRegionModifier(Modifier[None]):
targets=(CodeRegion,)
targets = (CodeRegion,)

def __init__(
self,
resource_factory: ResourceFactory,
@@ -136,9 +145,11 @@ async def modify(self, resource: Resource, config: None):
backend_code_regions: List[CodeRegion] = []
for key, mem_region in analysis.items():
if key.startswith("seg"):
backend_code_regions.append(CodeRegion(
virtual_address=mem_region["virtual_address"], size=mem_region["size"]
))
backend_code_regions.append(
CodeRegion(
virtual_address=mem_region["virtual_address"], size=mem_region["size"]
)
)

ofrak_code_regions = sorted(ofrak_code_regions, key=lambda cr: cr.virtual_address)
backend_code_regions = sorted(backend_code_regions, key=lambda cr: cr.virtual_address)
@@ -152,7 +163,9 @@ async def modify(self, resource: Resource, config: None):
backend_cr.virtual_address - backend_code_regions[0].virtual_address
)
if backend_relative_va == relative_va and backend_cr.size == code_region.size:
code_region.resource.add_view(backend_cr) # TODO: https://github.com/redballoonsecurity/ofrak/issues/537
code_region.resource.add_view(
backend_cr
) # TODO: https://github.com/redballoonsecurity/ofrak/issues/537
await resource.save()