[Python] Has anyone made a script to extract frame base addresses and active ranges for...

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am in need of a script for pyelftools to extract framebase address ranges for subprograms of interest. Here's an example excerpt from debug_frame information (taken from a simple executable binary for RV32 architecture). In this example, to the best of my understanding, the frame base is at the start the stack pointer (and offset is set to 32):

    00000034 00000024 00000000 FDE cie=00000000 pc=1000009c..100000bc
    DW_CFA_advance_loc: 2 to 1000009e
    DW_CFA_def_cfa_offset: 32 # sp + 32
    DW_CFA_advance_loc: 4 to 100000a2
    DW_CFA_offset: r1 (ra) at cfa-4
    DW_CFA_offset: r8 (s0) at cfa-8
    DW_CFA_advance_loc: 2 to 100000a4
    DW_CFA_def_cfa: r8 (s0) ofs 0 # fp + 0
    DW_CFA_advance_loc: 18 to 100000b6
    DW_CFA_restore: r1 (ra)
    DW_CFA_advance_loc: 2 to 100000b8
    DW_CFA_restore: r8 (s0)
    DW_CFA_def_cfa: r2 (sp) ofs 32 # sp + 32
    DW_CFA_advance_loc: 2 to 100000ba
    DW_CFA_def_cfa_offset: 0
    DW_CFA_nop
    DW_CFA_nop


    In this example I would like to get the address ranges for each CFA register value and possible offset. I'll write a script myself if none exists, but just thought I'd see if someone has an implementation done to save some time.

    In this case output I'm looking for would then be something like: [(1000009c, 'sp+32'), (100000a2, 's0'), (100000b8, 'sp+32')]

    Thanks!

    Continue reading...

Compartilhe esta Página