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

Disassemble in Extended not stopping at function boundary #1161

Open
palmerc opened this issue Jan 22, 2025 · 1 comment
Open

Disassemble in Extended not stopping at function boundary #1161

palmerc opened this issue Jan 22, 2025 · 1 comment
Assignees

Comments

@palmerc
Copy link

palmerc commented Jan 22, 2025

Describe the bug
When disassembling a function in LIEF extended the returned iterator does not stop at the function boundary

To Reproduce

def get_function_disassembly(binary_name: str, function_name: str) -> str:
    fat_macho = lief.MachO.parse(binary_name)
    thin_macho = fat_macho.take(lief.MachO.Header.CPU_TYPE.ARM64)
    instructions = thin_macho.disassemble(function_name)
    for instruction in instructions:
        print(instruction)

get_function_disassembly('/path/to/binary', 'function_somwhere_near_the_top')

Expected behavior
Ideally, some sort of block analysis that returns only the instructions pertinent to the named function not the entire subsequent disassembly.

Environment (please complete the following information):

  • System and Version : macOS Sequoia
  • Target format Mach-O
  • LIEF commit version: 0.17.0-
@palmerc
Copy link
Author

palmerc commented Jan 22, 2025

My workaround for this was to use lldb, but a pity you can't stay within LIEF

def get_function_disassembly(binary_name: str, function_name: str) -> str:
    cmds = ['lldb', '--arch', 'arm64', '--batch', '-o', f'disassemble -n {function_name}', '--file', binary_name]
    try:
        return subprocess.check_output(cmds).decode('utf-8')
    except subprocess.CalledProcessError:
        return ''

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

2 participants