1 # ScratchABit - interactive disassembler
3 # Copyright (c) 2015 Paul Sokolovsky
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from scratchabit
import engine
28 if engine
.ADDRESS_SPACE
.get_flags(ea
, engine
.AddressSpace
.ALT_CODE
):
33 def GetSegmentAttr(ea
, attr
):
34 assert attr
== SEGATTR_PERM
35 off
, area
= engine
.ADDRESS_SPACE
.addr2area(addr
)
36 props
= engine
.area_props(area
)
39 ret |
= idaapi
.SEGPERM_READ
41 ret |
= idaapi
.SEGPERM_WRITE
43 ret |
= idaapi
.SEGPERM_EXEC
47 def MakeAlign(ea
, cnt
, align
):
48 engine
.ADDRESS_SPACE
.make_filler(ea
, cnt
)
51 def SetReg(ea
, reg
, val
):
55 engine
.ADDRESS_SPACE
.update_flags(ea
, 0xff, engine
.AddressSpace
.ALT_CODE
)
57 engine
.ADDRESS_SPACE
.update_flags(ea
, ~engine
.AddressSpace
.ALT_CODE
, 0)
58 except engine
.InvalidAddrException
:
62 def SetRegEx(ea
, reg
, val
, tag
):
65 # tag == 2 seems to be set in IDC exports. Abuse that to have
66 # more code entrypoints.
68 engine
.add_entrypoint(ea
, False)
71 def MakeComm(ea
, comment
):
72 engine
.ADDRESS_SPACE
.set_comment(ea
, comment
)
75 def MakeFunction(ea
, end
=idaapi
.BADADDR
):
76 # Exported *.idc have 0xffffffff as apparent BADADDR
79 engine
.add_entrypoint(ea
, True)
80 if end
!= idaapi
.BADADDR
:
81 # TODO: Actually handle function bounds ea-end
85 def MakeNameEx(ea
, name
, flags
):
87 # TODO: name "" deletes label
88 engine
.ADDRESS_SPACE
.set_label(ea
, name
)