def apply_enum_by_name(enum, member_name): member_value = enum.members[member_name].value for location in sark.locations(*sark.get_selection()): for operand in location.insn.operands: if operand.type.is_imm: if operand.imm == member_value: idc.OpEnumEx(location.ea, operand.n, enum.eid, enum.members[member_name].serial) elif operand.type.is_displ or operand.type.is_phrase: if operand.addr == member_value: idc.OpEnumEx(location.ea, operand.n, enum.eid, enum.members[member_name].serial)
def get_common_value(): values = defaultdict(int) for location in sark.locations(*sark.get_selection()): for operand in location.insn.operands: if operand.type.is_imm: values[operand.imm] += 1 elif operand.type.is_displ or operand.type.is_phrase: values[operand.addr] += 1 # Ignore 0 as it is usually not interesting values[0] = 0 # Get the most common value common_value = max(values.iteritems(), key=lambda x: x[1])[0] return common_value