Skip to content

Commit

Permalink
Remove State from Artifact API
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed Jan 6, 2024
1 parent 305d653 commit 7cddef9
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 771 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create_plugin(*args, **kwargs):
"""

from libbs.api import DecompilerInterface
from libbs.data import (
from libbs.artifacts import (
FunctionHeader, StackVariable, Enum, Struct, GlobalVariable, Comment
)

Expand Down
2 changes: 1 addition & 1 deletion libbs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.12.0"
__version__ = "0.13.0"
2 changes: 1 addition & 1 deletion libbs/api/artifact_dict.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Type
import logging

from libbs.data import (
from libbs.artifacts import (
Artifact, Comment, Enum, FunctionHeader, Function, FunctionArgument,
GlobalVariable, Patch, StackVariable, Struct, StructMember
)
Expand Down
2 changes: 1 addition & 1 deletion libbs/api/artifact_lifter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from libbs.data import StackVariable, Artifact
from libbs.artifacts import StackVariable, Artifact
from libbs.api.type_parser import CTypeParser

_l = logging.getLogger(name=__name__)
Expand Down
30 changes: 15 additions & 15 deletions libbs/api/decompiler_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from libbs.api.artifact_lifter import ArtifactLifter
from libbs.api.artifact_dict import ArtifactDict
from libbs.api.type_parser import CTypeParser, CType
from libbs.data import (
from libbs.artifacts import (
Artifact,
Function, FunctionHeader, StackVariable,
Comment, GlobalVariable, Patch,
Expand Down Expand Up @@ -163,7 +163,7 @@ def _init_ui_components(self, *args, **kwargs):
def _init_gui_plugin(self, *args, **kwargs):
return None

def active_context(self) -> libbs.data.Function:
def active_context(self) -> libbs.artifacts.Function:
"""
Returns an libbs Function. Currently only functions are supported as current contexts.
This function will be called very frequently, so its important that its implementation is fast
Expand Down Expand Up @@ -332,8 +332,8 @@ def _get_function(self, addr, **kwargs) -> Optional[Function]:
def _functions(self) -> Dict[int, Function]:
"""
Returns a dict of libbs.Functions that contain the addr, name, and size of each function in the decompiler.
Note: this does not contain the live data of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live data, use the singleton function of the same name.
Note: this does not contain the live artifacts of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live artifacts, use the singleton function of the same name.
@return:
"""
Expand Down Expand Up @@ -369,8 +369,8 @@ def _get_global_var(self, addr) -> Optional[GlobalVariable]:
def _global_vars(self) -> Dict[int, GlobalVariable]:
"""
Returns a dict of libbs.GlobalVariable that contain the addr and size of each global var.
Note: this does not contain the live data of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live data, use the singleton function of the same name.
Note: this does not contain the live artifacts of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live artifacts, use the singleton function of the same name.
@return:
"""
Expand All @@ -386,8 +386,8 @@ def _get_struct(self, name) -> Optional[Struct]:
def _structs(self) -> Dict[str, Struct]:
"""
Returns a dict of libbs.Structs that contain the name and size of each struct in the decompiler.
Note: this does not contain the live data of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live data, use the singleton function of the same name.
Note: this does not contain the live artifacts of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live artifacts, use the singleton function of the same name.
@return:
"""
Expand All @@ -403,8 +403,8 @@ def _get_enum(self, name) -> Optional[Enum]:
def _enums(self) -> Dict[str, Enum]:
"""
Returns a dict of libbs.Enum that contain the name of the enums in the decompiler.
Note: this does not contain the live data of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live data, use the singleton function of the same name.
Note: this does not contain the live artifacts of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live artifacts, use the singleton function of the same name.
@return:
"""
Expand All @@ -420,8 +420,8 @@ def _get_patch(self, addr) -> Optional[Patch]:
def _patches(self) -> Dict[int, Patch]:
"""
Returns a dict of libbs.Patch that contain the addr of each Patch and the bytes.
Note: this does not contain the live data of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live data, use the singleton function of the same name.
Note: this does not contain the live artifacts of the Artifact, only the minimum knowledge to that the Artifact
exists. To get live artifacts, use the singleton function of the same name.
@return:
"""
Expand Down Expand Up @@ -460,7 +460,7 @@ def global_artifacts(self):

def global_artifact(self, lookup_item: Union[str, int]):
"""
Returns a live libbs.data version of the Artifact located at the lookup_item location, which can
Returns a live libbs.artifacts version of the Artifact located at the lookup_item location, which can
lookup any artifact supported in `global_artifacts`
@param lookup_item:
Expand Down Expand Up @@ -557,7 +557,7 @@ def lower_artifact(self, artifact: Artifact) -> Artifact:

#
# Fillers:
# A filler function is generally responsible for pulling down data from a specific user state
# A filler function is generally responsible for pulling down artifacts from a specific user state
# and reflecting those changes in decompiler view (like the text on the screen). Normally, these changes
# will also be accompanied by a Git commit to the master users state to save the changes from pull and
# fill into their BS database. In special cases, a filler may only update the decompiler UI but not directly
Expand All @@ -571,7 +571,7 @@ def artifact_set_event_handler(
This function handles any event which tries to set an Artifact into the decompiler. This handler does two
important tasks:
1. Locks callback handlers, so you don't get infinite callbacks
2. "Lowers" the artifact, so it's data types match the decompilers
2. "Lowers" the artifact, so it's artifacts types match the decompilers
Because of this, it's recommended that when overriding this function you always call super() at the end of
your override so it's set correctly in the decompiler.
Expand Down
31 changes: 31 additions & 0 deletions libbs/api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import math

import tqdm


def progress_bar(items, gui=True, desc="Progressing..."):
if gui:
from libbs.ui.utils import QProgressBarDialog
pbar = QProgressBarDialog(label_text=desc)
pbar.show()
callback_stub = pbar.update_progress
else:
t = tqdm.tqdm(desc=desc)
callback_stub = t.update

bucket_size = len(items) / 100.0
if bucket_size < 1:
callback_amt = int(1 / (bucket_size))
bucket_size = 1
else:
callback_amt = 1
bucket_size = math.ceil(bucket_size)

for i, item in enumerate(items):
yield item
if i % bucket_size == 0:
callback_stub(callback_amt)

if gui:
# close the progress bar since it may not hit 100%
pbar.close()
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .artifact import Artifact
from .artifact import Artifact, TomlHexEncoder
from .comment import Comment
from .decompilation import Decompilation
from .enum import Enum
from .func import Function, FunctionArgument, FunctionHeader
from .func import Function, FunctionHeader, FunctionArgument
from .global_variable import GlobalVariable
from .patch import Patch
from .stack_variable import StackVariable
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions libbs/data/__init__.py

This file was deleted.

Loading

0 comments on commit 7cddef9

Please sign in to comment.