Skip to content

Commit

Permalink
Remove Instruction.disassembly attribute (#540)
Browse files Browse the repository at this point in the history
* Remove `Instruction.disassembly` attribute
- Existing usages are replace its with `Instruction.get_assembly()`

* Instruction.get_assembly does not need to be async...

* Update more Instruction test instances

* Add ofrak-capstone to ofrak-ghidra.yml

* Try creating rc versions for ofrak, ofrak-capstone

* Fix rc version installation issues

* Revert unneeded changes
  • Loading branch information
whyitfor authored Jan 10, 2025
1 parent ddc2ce1 commit 03c0445
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 275 deletions.
3 changes: 3 additions & 0 deletions disassemblers/ofrak_binary_ninja/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def run(self):
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
install_requires=[
"ofrak[test]>=3.3.0rc0",
],
extras_require={
"test": [
"fun-coverage==0.2.0",
Expand Down
3 changes: 2 additions & 1 deletion disassemblers/ofrak_capstone/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ All notable changes to `ofrak-capstone` will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/redballoonsecurity/ofrak/tree/master)
## [Unreleased 1.1.0rc0](https://github.com/redballoonsecurity/ofrak/tree/master)

### Fixed
- Capstone tests fixed to use `run_instruction_unpacker_test_case` ([#503](https://github.com/redballoonsecurity/ofrak/pull/503))

### Changed
- Update to captione==5.0.0.post1.
- Minor update to OFRAK Community License, add OFRAK Pro License ([#478](https://github.com/redballoonsecurity/ofrak/pull/478))
- Updated library to support ofrak 3.3.0rc0. ([#539](https://github.com/redballoonsecurity/ofrak/issues/539))

## 1.0.0 - 2022-01-25
### Added
Expand Down
4 changes: 2 additions & 2 deletions disassemblers/ofrak_capstone/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ PIP=pip3

.PHONY: install
install:
$(PIP) install .
$(PIP) install --pre .

.PHONY: develop
develop:
$(PIP) install -e .[test] --config-settings editable_mode=compat
$(PIP) install --pre -e .[test] --config-settings editable_mode=compat

.PHONY: inspect
inspect:
Expand Down
2 changes: 0 additions & 2 deletions disassemblers/ofrak_capstone/ofrak_capstone/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ async def unpack(self, resource: Resource, config=None):
instruction_view = Instruction(
disassem_result.address,
disassem_result.size,
f"{disassem_result.mnemonic} {disassem_result.operands}",
disassem_result.mnemonic,
disassem_result.operands,
bb_view.mode,
Expand Down Expand Up @@ -125,7 +124,6 @@ async def analyze(self, resource: Resource, config=None) -> Instruction:
return Instruction(
disassem_result.address,
disassem_result.size,
f"{disassem_result.mnemonic} {disassem_result.operands}",
disassem_result.mnemonic,
disassem_result.operands,
mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,39 +158,34 @@ async def _initialize_basic_bloc_resource(self, ofrak) -> Resource:
Instruction(
0x100,
0x4,
"push {r4, r5, r6, r7, r8, lr}",
"push",
"{r4, r5, r6, r7, r8, lr}",
InstructionSetMode.NONE,
),
Instruction(
0x104,
0x4,
"mov r4, #0x0",
"mov",
"r4, #0x0",
InstructionSetMode.NONE,
),
Instruction(
0x108,
0x4,
"mov r5, r4",
"mov",
"r5, r4",
InstructionSetMode.NONE,
),
Instruction(
0x10C,
0x4,
"ldr r6, [pc, #0x50]",
"ldr",
"r6, [pc, #0x50]",
InstructionSetMode.NONE,
),
Instruction(
0x110,
0x4,
"ldr r7, [pc, #0x50]",
"ldr",
"r7, [pc, #0x50]",
InstructionSetMode.NONE,
Expand Down
4 changes: 2 additions & 2 deletions disassemblers/ofrak_capstone/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def read_requirements(requirements_path):
version="1.0.0",
packages=setuptools.find_packages(exclude=["ofrak_capstone_test", "ofrak_capstone_test.*"]),
package_data={"ofrak_capstone": ["py.typed"]},
install_requires=["ofrak"] + read_requirements("requirements.txt"),
install_requires=["ofrak>=3.3.0rc0"] + read_requirements("requirements.txt"),
extras_require={
"test": [
"fun-coverage==0.2.0",
"pytest",
"pytest-cov",
"pytest-asyncio==0.19.0",
"requests",
"ofrak[test]",
"ofrak[test]>=3.3.0rc0",
]
},
author="Red Balloon Security",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ async def unpack(self, resource: Resource, config=None):
for reg in instruction["regs_written"].lower().split(","):
if reg not in regs_written and reg != "":
regs_written.append(reg)
disasm = f"{mnem} {operands}"

mode_string = instruction.get("instr_mode", "NONE")
mode = InstructionSetMode[mode_string]
Expand All @@ -92,7 +91,6 @@ async def unpack(self, resource: Resource, config=None):
instruction = Instruction(
virtual_address=vaddr,
size=size,
disassembly=disasm,
mnemonic=mnem,
operands=operands,
mode=mode,
Expand Down
1 change: 1 addition & 0 deletions ofrak-ghidra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ packages_paths:
"ofrak_io",
"ofrak_patch_maker",
"ofrak_core",
"disassemblers/ofrak_capstone",
"disassemblers/ofrak_ghidra",
"frontend",
]
Expand Down
6 changes: 5 additions & 1 deletion ofrak_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ All notable changes to `ofrak` will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/redballoonsecurity/ofrak/tree/master)
## [Unreleased: 3.3.0rc0](https://github.com/redballoonsecurity/ofrak/tree/master)
### Added
- Add license check command to prompt users about community or pro licenses. ([#478](https://github.com/redballoonsecurity/ofrak/pull/478))
- Support `application/vnd.android.package-archive` mime type for APKs, which is returned by newer versions of libmagic ([#470](https://github.com/redballoonsecurity/ofrak/pull/470))
Expand Down Expand Up @@ -62,6 +62,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Rename `MagicDescriptionIdentifier` to `MagicDescriptionPattern`, as it is run by `MagicIdentifier`
- Add `RawMagicPattern` to efficiently run custom magic byte search logic within `MagicIdenfifier`
- Update registered identifiers to make use of new `MagicIdentifier` for following resource tags: `Apk`, `Bzip2Data`, `CpioFilesystem`, `DeviceTreeBlob`, `Elf`, `Ext2Filesystem`, `Ext3Filesystem`, `Ext4Filesystem`, `GzipData`, `ISO9660Image`, `Jffs2Filesystem`, `LzmaData`, `XzData`, `LzoData`, `OpenWrtTrx`, `Pe`, `RarArchive`, `SevenZFilesystem`, `SquashfsFilesystem`, `TarArchive`, `Ubi`, `Ubifs`, `Uf2File`, `UImage`, `ZipArchive`, `ZlibData`, `ZstdData`
- Update `Instruction.get_assembly` to by synchronous ([#539](https://github.com/redballoonsecurity/ofrak/issues/539))

### Removed
- Removed `Instruction.disassembly` from `Instruction` class: use `Instruction.get_assembly()` instead ([#539](https://github.com/redballoonsecurity/ofrak/issues/539))

### Security
- Update aiohttp to 3.10.11 ([#522](https://github.com/redballoonsecurity/ofrak/pull/522))
Expand Down
4 changes: 1 addition & 3 deletions ofrak_core/ofrak/core/basic_block.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Optional, Iterable
Expand Down Expand Up @@ -57,8 +56,7 @@ async def get_assembly(self) -> str:
:return: the basic block's assembly
"""
instructions = await self.get_instructions()
instruction_assemblies = [i.get_assembly() for i in instructions]
return "\n".join(await asyncio.gather(*instruction_assemblies))
return "\n".join([i.get_assembly() for i in instructions])


class BasicBlockUnpacker(Unpacker[None], ABC):
Expand Down
5 changes: 1 addition & 4 deletions ofrak_core/ofrak/core/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ class Instruction(MemoryRegion):
:ivar virtual_address: the virtual address of the start of the instruction
:ivar size: the size of the instruction
:ivar disassembly: the instruction's disassembly
:ivar mnemonic: the instruction's mnemonic
:ivar operands: the instruction's operands
:ivar mode: the instruction set mode of the instruction
"""

disassembly: str
mnemonic: str
operands: str
mode: InstructionSetMode
Expand All @@ -48,7 +46,7 @@ def caption(cls, all_attributes) -> str:
return super().caption(all_attributes)
return f"{instruction_attributes.mnemonic} {instruction_attributes.operands}"

async def get_assembly(self) -> str:
def get_assembly(self) -> str:
"""
Get the instruction as an assembly string.
Expand Down Expand Up @@ -178,7 +176,6 @@ async def modify(self, resource: Resource, config: InstructionModifierConfig):
), "The modified instruction length does not match the original instruction length"

new_attributes = AttributesType[Instruction](
disassembly=modified_assembly,
mnemonic=config.mnemonic,
operands=config.operands,
mode=config.mode,
Expand Down
Loading

0 comments on commit 03c0445

Please sign in to comment.