def tag_write(ea, key, value):
'''Set the tag ``key`` to ``value`` at the address ``ea``.'''
if value is None:
raise ValueError("{:s}.tag_write({:x}, {!r}, ...) : Tried to set tag {!r} to an invalid value. : {!r}".format(__name__, ea, key, key, value))
# if the user wants to change the '__name__' tag, then
# change the name fo' real.
if key == '__name__':
return set_name(ea, value, listed=True)
if key == '__extra_prefix__':
return extra.set_prefix(ea, value)
if key == '__extra_suffix__':
return extra.set_suffix(ea, value)
if key == '__color__':
return set_color(ea, value)
# if not within a function, then use a repeatable comment
# otherwise, use a non-repeatable one
try: func = function.by_address(ea)
except: func = None
repeatable = False if func else True
# grab the current value
ea = interface.address.inside(ea)
state = internal.comment.decode(comment(ea, repeatable=not repeatable))
state and comment(ea, '', repeatable=not repeatable) # clear the old one
state.update(internal.comment.decode(comment(ea, repeatable=repeatable)))
# update the tag's reference
if key not in state:
if func:
internal.comment.contents.inc(ea, key)
else:
internal.comment.globals.inc(ea, key)
# now we can actually update the tag
res,state[key] = state.get(key,None),value
comment(ea, internal.comment.encode(state), repeatable=repeatable)
return res
评论列表
文章目录