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

Delete structs in DB when deleted in State #320

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Pascal-0x90
Copy link
Collaborator

Fixing Issue 306

The Problem

As seen in #306 , renaming and deleting of structs does not actually get rid of the toml file which Binsync uses to track structs.

The Solution

In order to make this somewhat generic, I modified the following files;

  • binsync/core/client.py
  • binsync/data/state.py

In state.py, I introduce the deleted_artifacts struct to keep track of any artifact that we want to remove.

self.deleted_artifacts: List[Dict[str, str]] = []

An example of this being used is in the function set_struct which will add an entry like so:

if old_name is not None:
try:
del self.structs[old_name]
self.deleted_artifacts.append(
{
"type": ArtifactType.STRUCT,
"name": old_name
}
)
#remove_data(self.client.repo.index, os.path.join('structs', f'{old_name}.toml'))
except KeyError:
pass

This then allows us to iterate over the list later on and explicitly all _delete_data from the dump function:

for item in self.deleted_artifacts:
if item['type'] == ArtifactType.STRUCT:
old_name = item['name']
path = pathlib.Path('structs').joinpath(f"{old_name}.toml")
self._delete_data(dst, path)
elif item['type'] == ArtifactType.FUNCTION:
pass
elif item['type'] == ArtifactType.COMMENT:
pass
elif item['type'] == ArtifactType.GLOBAL_VAR:
pass
elif item['type'] == ArtifactType.ENUM:
pass

_delete_data follows the same method as _dump_data but instead will make use of the remove_data function in self.client.

The last thing added was in the client.py file:

self.repo.git.add(update=True)

This allows us to ignore trying to pass around deleted files or added files and can just update the current folder with add. Then when the commit is sent off this will make git also remove the reference so we don't need to manually do repo.index.remove.

Other Changes

I also updated binsync/decompilers/ida/hooks.py to properly pass old_name for the previous name of the changed struct.

TODO

The UI table in QT still has the reference for the previous struct for some reason. Despite it being deleted in the folder, it still is present in the table.

@mahaloz mahaloz changed the title DRAFT: Fix/issue 306 Delete structs in DB when deleted in State Aug 22, 2023
@mahaloz
Copy link
Member

mahaloz commented Aug 22, 2023

@Pascal-0x90 I'm only getting to reviewing this now. Is this ready for review? I.e. did you test it once and confirm it works as you think it would? Or does it still need dev?

@Pascal-0x90
Copy link
Collaborator Author

Pascal-0x90 commented Aug 24, 2023

Hey @mahaloz it WOMM for what I described so I would say this is ready for review / testing. On that one segment regarding the if-statement tree, feel free to remove that if desired. I had it there in-case extractions were ever desired to be taken for any of the other Artifact Types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants