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

for loop throws Python TypeError for some Iterable objects #73

Open
colton-gabertan opened this issue Aug 23, 2023 · 0 comments
Open

for loop throws Python TypeError for some Iterable objects #73

colton-gabertan opened this issue Aug 23, 2023 · 0 comments

Comments

@colton-gabertan
Copy link
Contributor

Description

Most iterable objects returned by Ghidra API calls are iterable via classic for loops; however, there are some cases in which the iterable object is not compatible.

Steps to Re-create

def extract_function_loop(fh: FunctionHandle):
    f: ghidra.program.database.function.FunctionDB = fh.inner

    edges = []
    for block in SimpleBlockIterator(BasicBlockModel(currentProgram()), f.getBody(), monitor()):  # type: ignore [name-defined] # noqa: F821
        dests = block.getDestinations(monitor())  # type: ignore [name-defined] # noqa: F821
        s_addrs = block.getStartAddresses()

        while dests.hasNext():  # For loop throws Python TypeError
            for addr in s_addrs:
                edges.append((addr.getOffset(), dests.next().getDestinationAddress().getOffset()))

    if loops.has_loop(edges):
        yield Characteristic("loop"), AbsoluteVirtualAddress(f.getEntryPoint().getOffset())

https://github.com/mandiant/capa/blob/70d36ab6406a46b5bc9c2cac3866a80a8c8ea38d/capa/features/extractors/ghidra/function.py#L28C1-L42C1

Expected Behavior

dests should be compatible to use with a classic for loop i.e. for dest in dests:

Actual Behavior

Using a classic for loop throws a Python TypeError

image

Version Info

Ghidra v10.3.2
Ghidrathon v3.0.0
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

No branches or pull requests

1 participant