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

AttributeError: 'XRef' object has no attribute 'sort' #33

Closed
mz21g opened this issue Mar 1, 2022 · 5 comments
Closed

AttributeError: 'XRef' object has no attribute 'sort' #33

mz21g opened this issue Mar 1, 2022 · 5 comments

Comments

@mz21g
Copy link

mz21g commented Mar 1, 2022

python3.9
macOS Monterey 12.1
angr 9.1.11752
angr-utils 0.5.0
bingraphvis 0.3.0

import angr
from angrutils import *


def cfgfastpng(filename):
    proj = angr.Project(filename, auto_load_libs = False)
    cfg = proj.analyses.CFGFast()
    plot_cfg(cfg, "cfg", format='png', asminst=True, remove_imports=True)


if __name__ == '__main__':
    cfgfastpng('./01_angr_avoid')

WARNING | 2022-03-01 19:55:43,281 | angr.analyses.cfg.cfg_fast | _tidy_data_references() sees an address 0x80d6040 that does not belong to any section or segment.
Traceback (most recent call last):
File "/Users/chenyanzhi/Documents/angr/test.py", line 12, in
cfgfastpng('./01_angr_avoid')
File "/Users/chenyanzhi/Documents/angr/test.py", line 8, in cfgfastpng
plot_cfg(cfg, "cfg", format='png', asminst=True, remove_imports=True)
File "/Users/chenyanzhi/Desktop/angr-dev/angr-utils/angrutils/visualize.py", line 34, in plot_cfg
vis.process(cfg.graph)
File "/Users/chenyanzhi/Desktop/angr-dev/bingraphvis/bingraphvis/base.py", line 309, in process
graph = self.pipeline.process(filter=filter)
File "/Users/chenyanzhi/Desktop/angr-dev/bingraphvis/bingraphvis/base.py", line 286, in process
c.render(n)
File "/Users/chenyanzhi/Desktop/angr-dev/bingraphvis/bingraphvis/base.py", line 126, in render
an.annotate_content(n, n.content[self.name])
File "/Users/chenyanzhi/Desktop/angr-dev/bingraphvis/bingraphvis/angr/annotator.py", line 384, in annotate_content
if dr.sort == 'string':
AttributeError: 'XRef' object has no attribute 'sort'

@kaveenliyanage
Copy link

kaveenliyanage commented Mar 2, 2022

Update the following lines in the
annotator.py

line 384 : dr.sort 			->>			dr.memory_data.sort
line 385 : dr.insn_addr		->>			dr.memory_data.insn_addr
line 385 : dr.content		->>			str(dr.memory_data.content)

@mz21g
Copy link
Author

mz21g commented Mar 3, 2022

Update the following lines in the annotator.py

line 384 : dr.sort 			->>			dr.memory_data.sort
line 385 : dr.insn_addr		->>			dr.memory_data.insn_addr
line 385 : dr.content		->>			str(dr.memory_data.content)

Thank you very much, It works, But I found that the second line should be changed to this

> line 385 : dr.insn_addr		->>			dr.ins_addr

because if I change it like you, It will have the following problems

WARNING | 2022-03-03 22:14:43,965 | angr.analyses.cfg.cfg_fast | _tidy_data_references() sees an address 0x804a040 that does not belong to any section or segment.
Traceback (most recent call last):
  File "/Users/chenyanzhi/Documents/angr/test.py", line 21, in <module>
    cfgfastpng("./00_angr_find")
  File "/Users/chenyanzhi/Documents/angr/test.py", line 16, in cfgfastpng
    plot_cfg(cfg, "cfg", format='png', asminst=True, remove_imports=True)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/angrutils/visualize.py", line 34, in plot_cfg
    vis.process(cfg.graph) 
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bingraphvis/base.py", line 309, in process
    graph = self.pipeline.process(filter=filter)        
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bingraphvis/base.py", line 286, in process
    c.render(n)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bingraphvis/base.py", line 126, in render
    an.annotate_content(n, n.content[self.name])
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bingraphvis/angr/annotator.py", line 385, in annotate_content
    comments_by_addr[dr.memory_data.insn_addr] = str(dr.memory_data.content)
AttributeError: 'MemoryData' object has no attribute 'insn_addr'

@mz21g
Copy link
Author

mz21g commented Mar 3, 2022

In addition,when I run the sample code, I had the same problem as #32

def main(filename):
    proj = angr.Project(filename, load_options={'auto_load_libs': False})
    main = proj.loader.main_object.get_symbol("main")
    start_state = proj.factory.blank_state(addr=main.rebased_addr)
    cfg = proj.analyses.CFGEmulated(fail_fast=True, starts=[main.rebased_addr], initial_state=start_state)
    plot_cfg(cfg, "ais3_cfg", format='png', asminst=True, remove_imports=True)

ais3_cfg

but I run my code, it will output normally

def cfgfastpng(filename):
    proj = angr.Project(filename, auto_load_libs=False)
    cfg = proj.analyses.CFGFast()
    plot_cfg(cfg, "cfg", format='png', asminst=True, remove_imports=True)

cfg

@axt
Copy link
Owner

axt commented Mar 11, 2022

Sorry for my late reply. Thanks for the report and the solution, I will apply the fixes on the weekend.

@mz21g :
When #32 was reported, I've tried to check it, but it worked for me.

Could you maybe figure out what is causing the problem? I wrote some thoughts about how to debug it in the original ticket.

I will also try to retest that on the weekend.

@axt
Copy link
Owner

axt commented Mar 13, 2022

I've applied the fix and created a new PyPI version. Thanks for the report!

@mz21g Tried your code to test #32, but it creates the assembly listing for me.

@axt axt closed this as completed Mar 13, 2022
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

3 participants