ScratchABit: action_goto: Update for picotui 1.1.
[ScratchABit.git] / idc.py
blobfbddb52691a2034ba363b295252884839cf852c3
1 # ScratchABit - interactive disassembler
3 # Copyright (c) 2015-2018 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/>.
17 import logging as log
19 from scratchabit import engine
20 import idaapi
23 SEGATTR_PERM = 1
26 def GetReg(ea, reg):
27 assert reg == "T"
28 if engine.ADDRESS_SPACE.get_flags(ea, engine.AddressSpace.ALT_CODE):
29 return 1
30 return 0
33 def GetSegmentAttr(ea, attr):
34 assert attr == SEGATTR_PERM
35 off, area = engine.ADDRESS_SPACE.addr2area(addr)
36 props = engine.area_props(area)
37 ret = 0
38 if "R" in props:
39 ret |= idaapi.SEGPERM_READ
40 if "W" in props:
41 ret |= idaapi.SEGPERM_WRITE
42 if "X" in props:
43 ret |= idaapi.SEGPERM_EXEC
46 # Make filler
47 def MakeAlign(ea, cnt, align):
48 engine.ADDRESS_SPACE.make_filler(ea, cnt)
51 def SetReg(ea, reg, val):
52 assert reg == "T"
53 try:
54 if val:
55 engine.ADDRESS_SPACE.update_flags(ea, 0xff, engine.AddressSpace.ALT_CODE)
56 else:
57 engine.ADDRESS_SPACE.update_flags(ea, ~engine.AddressSpace.ALT_CODE, 0)
58 except engine.InvalidAddrException:
59 log.exception("")
62 def SetRegEx(ea, reg, val, tag):
63 SetReg(ea, reg, val)
65 # tag == 2 seems to be set in IDC exports. Abuse that to have
66 # more code entrypoints.
67 if tag == 2:
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
77 if end == 0xffffffff:
78 end = idaapi.BADADDR
79 engine.add_entrypoint(ea, True)
80 if end != idaapi.BADADDR:
81 # TODO: Actually handle function bounds ea-end
82 assert False
85 def MakeNameEx(ea, name, flags):
86 # TODO: use the flags
87 # TODO: name "" deletes label
88 engine.ADDRESS_SPACE.set_label(ea, name)