# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: angr
#     language: python
#     name: angr
# ---

# +
import angr
import angrcli.plugins.context_view
import angrcli.plugins.watches
from angrcli.interaction.explore import ExploreInteractive

#import angr.sim_state
#angr.sim_state.SimState.__repr__ = lambda self: self.context_view.pprint()


proj = angr.Project("./memview.elf",
                    load_options={'auto_load_libs': False})
cfg = proj.analyses.CFGFast()

state = proj.factory.entry_state()
e = ExploreInteractive(proj, state)


# +
# Task 1
# Find the addr of the global struct
# angr has a knowledge base plugin to parse specific symbols into memory labels, 

struct_addr = proj.kb.labels.lookup('global_struct')
 
# -

angr.types.define_struct("""
struct example_struct {
   int f_integer;
   char f_string[4];
   char* f_pointer;
};
""")
state.watches.add_watch(lambda state: state.mem[struct_addr].example_struct, 'struct watch')

# +
#e.state.mem[proj.kb.labels.lookup('global_struct')].example_struct.f_pointer.deref.string.concrete
# -



StarcoderdataJupyterScriptsDedupFiltered