def yacheck_create_struct_field(self): for offset, count, field_type, string_type, comment, repeatable in create_field: size = count * get_size(field_type, string_type) name = get_name(field_type, string_type, offset, size) sid = idc.GetStrucIdByName('struct_' + name) self.assertNotEqual(sid, idaapi.BADADDR) fname = 'field_' + name self.check_field(sid, field_type, string_type, offset, size, fname) if comment is not None: for k in range(offset, offset + size - 1): self.assertEqual(idc.GetMemberComment(sid, k, repeatable), comment)
def append_lvar_comment(fva, frame_offset, s, repeatable=False): ''' add the given string as a (possibly repeatable) stack variable comment to the given function. does not add the comment if it already exists. adds the comment on its own line. Args: fva (int): the address of the function with the stack variable. frame_offset (int): the offset into the stack frame at which the variable is found. s (str): the comment text. repeatable (bool): if True, set a repeatable comment. Raises: UnicodeEncodeError: if the given string is not ascii. ''' s = s.encode('ascii') stack = idc.GetFrame(fva) if not stack: raise RuntimeError('failed to find stack frame for function: ' + hex(fva)) lvar_offset = idc.GetFrameLvarSize(fva) - frame_offset if not lvar_offset: raise RuntimeError('failed to compute local variable offset') if lvar_offset <= 0: raise RuntimeError('failed to compute positive local variable offset') string = idc.GetMemberComment(stack, lvar_offset, repeatable) if not string: string = s else: if s in string: # ignore duplicates return string = string + "\\n" + s if not idc.SetMemberComment(stack, lvar_offset, string, repeatable): raise RuntimeError('failed to set comment')
def get_comment(self, repeteable=True): return idc.GetMemberComment(self.parent.sid, self.struct_offset, repeteable)