2727# Binary Ninja components
2828import _binaryninjacore as core
2929from enums import (AnalysisState , SymbolType , InstructionTextTokenType ,
30- Endianness , ModificationStatus , StringType , SegmentFlag )
30+ Endianness , ModificationStatus , StringType , SegmentFlag , SectionSemantics )
3131import function
3232import startup
3333import architecture
@@ -422,7 +422,7 @@ def __repr__(self):
422422
423423
424424class Section (object ):
425- def __init__ (self , name , section_type , start , length , linked_section , info_section , info_data , align , entry_size ):
425+ def __init__ (self , name , section_type , start , length , linked_section , info_section , info_data , align , entry_size , semantics ):
426426 self .name = name
427427 self .type = section_type
428428 self .start = start
@@ -432,6 +432,7 @@ def __init__(self, name, section_type, start, length, linked_section, info_secti
432432 self .info_data = info_data
433433 self .align = align
434434 self .entry_size = entry_size
435+ self .semantics = SectionSemantics (semantics )
435436
436437 @property
437438 def end (self ):
@@ -899,7 +900,8 @@ def sections(self):
899900 for i in xrange (0 , count .value ):
900901 result [section_list [i ].name ] = Section (section_list [i ].name , section_list [i ].type , section_list [i ].start ,
901902 section_list [i ].length , section_list [i ].linkedSection , section_list [i ].infoSection ,
902- section_list [i ].infoData , section_list [i ].align , section_list [i ].entrySize )
903+ section_list [i ].infoData , section_list [i ].align , section_list [i ].entrySize ,
904+ section_list [i ].semantics )
903905 core .BNFreeSectionList (section_list , count .value )
904906 return result
905907
@@ -1678,6 +1680,28 @@ def is_offset_executable(self, addr):
16781680 """
16791681 return core .BNIsOffsetExecutable (self .handle , addr )
16801682
1683+ def is_offset_code_semantics (self , addr ):
1684+ """
1685+ ``is_offset_code_semantics`` checks if an virtual address ``addr`` is semantically valid for code.
1686+
1687+ :param int addr: a virtual address to be checked
1688+ :return: true if the virtual address is valid for writing, false if the virtual address is invalid or error
1689+ :rtype: bool
1690+ """
1691+ return core .BNIsOffsetCodeSemantics (self .handle , addr )
1692+
1693+ def is_offset_writable_semantics (self , addr ):
1694+ """
1695+ ``is_offset_writable_semantics`` checks if an virtual address ``addr`` is semantically writable. Some sections
1696+ may have writable permissions for linking purposes but can be treated as read-only for the purposes of
1697+ analysis.
1698+
1699+ :param int addr: a virtual address to be checked
1700+ :return: true if the virtual address is valid for writing, false if the virtual address is invalid or error
1701+ :rtype: bool
1702+ """
1703+ return core .BNIsOffsetWritableSemantics (self .handle , addr )
1704+
16811705 def save (self , dest ):
16821706 """
16831707 ``save`` saves the original binary file to the provided destination ``dest`` along with any modifications.
@@ -3218,17 +3242,17 @@ def get_address_for_data_offset(self, offset):
32183242 return None
32193243 return address .value
32203244
3221- def add_auto_section (self , name , start , length , type = "" , align = 1 , entry_size = 1 , linked_section = "" ,
3222- info_section = "" , info_data = 0 ):
3223- core .BNAddAutoSection (self .handle , name , start , length , type , align , entry_size , linked_section ,
3245+ def add_auto_section (self , name , start , length , semantics = SectionSemantics . DefaultSectionSemantics ,
3246+ type = "" , align = 1 , entry_size = 1 , linked_section = "" , info_section = "" , info_data = 0 ):
3247+ core .BNAddAutoSection (self .handle , name , start , length , semantics , type , align , entry_size , linked_section ,
32243248 info_section , info_data )
32253249
32263250 def remove_auto_section (self , name ):
32273251 core .BNRemoveAutoSection (self .handle , name )
32283252
3229- def add_user_section (self , name , start , length , type = "" , align = 1 , entry_size = 1 , linked_section = "" ,
3230- info_section = "" , info_data = 0 ):
3231- core .BNAddUserSection (self .handle , name , start , length , type , align , entry_size , linked_section ,
3253+ def add_user_section (self , name , start , length , semantics = SectionSemantics . DefaultSectionSemantics ,
3254+ type = "" , align = 1 , entry_size = 1 , linked_section = "" , info_section = "" , info_data = 0 ):
3255+ core .BNAddUserSection (self .handle , name , start , length , semantics , type , align , entry_size , linked_section ,
32323256 info_section , info_data )
32333257
32343258 def remove_user_section (self , name ):
@@ -3241,7 +3265,8 @@ def get_sections_at(self, addr):
32413265 for i in xrange (0 , count .value ):
32423266 result .append (Section (section_list [i ].name , section_list [i ].type , section_list [i ].start ,
32433267 section_list [i ].length , section_list [i ].linkedSection , section_list [i ].infoSection ,
3244- section_list [i ].infoData , section_list [i ].align , section_list [i ].entrySize ))
3268+ section_list [i ].infoData , section_list [i ].align , section_list [i ].entrySize ,
3269+ section_list [i ].semantics ))
32453270 core .BNFreeSectionList (section_list , count .value )
32463271 return result
32473272
@@ -3250,7 +3275,7 @@ def get_section_by_name(self, name):
32503275 if not core .BNGetSectionByName (self .handle , name , section ):
32513276 return None
32523277 result = Section (section .name , section .type , section .start , section .length , section .linkedSection ,
3253- section .infoSection , section .infoData , section .align , section .entrySize )
3278+ section .infoSection , section .infoData , section .align , section .entrySize , section . semantics )
32543279 core .BNFreeSection (section )
32553280 return result
32563281
0 commit comments