Skip to content

Commit

Permalink
Added Function.type property for setting function type.
Browse files Browse the repository at this point in the history
Closes tmr232#60.
  • Loading branch information
tmr232 committed Jun 9, 2017
1 parent 79061d3 commit 556743d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sark/code/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ def has_name(self):
def func_t(self):
return self._func

@property
def type(self):
return idc.GetType(self.startEA)

@type.setter
def type(self, c_signature):
success = idc.SetType(self.startEA, c_signature)
if not success:
raise exceptions.SetTypeFailed(self.startEA, c_signature)


def iter_function_lines(func_ea):
"""Iterate the lines of a function.
Expand Down
7 changes: 7 additions & 0 deletions sark/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class SarkNoSelection(SarkError):
class SarkNoFunction(SarkError):
pass


class SarkAddFunctionFailed(SarkError):
pass


class SarkFunctionExists(SarkError):
pass


class SarkStructError(SarkError):
pass

Expand Down Expand Up @@ -227,3 +229,8 @@ class PhraseNotSupported(PhraseError):
class PhraseProcessorNotSupported(PhraseNotSupported):
pass


class SetTypeFailed(SarkError):
def __init__(self, ea, c_signature):
message = 'idc.SetType(ea={ea:08X}, "{c_signature}") failed'.format(ea=ea, c_signature=c_signature)
super(SetTypeFailed, self).__init__(message)

0 comments on commit 556743d

Please sign in to comment.