# Path: lib/Register.py
# def get_reg_class(reg):
#     """
#     @brief Determines the register class of a given reg.
#     All different register names that address the same register
#     belong to the same register class e.g.: 'ax' and 'eax'
#     @param reg name of register
#     @return register class
#     """
#     lreg = reg.lower()
#     ret_value = None
#     for pos, reg_list in enumerate(_registerClasses):
#         for reg in reg_list:
#             found = False
#             if reg == lreg:
#                 found = True
#                 ret_value = pos
#                 break
#         if found:
#             break
#     return ret_value
# 
# def get_reg_by_size(reg_class, reg_size):
#     """
#     @brief Determines the register by its size and class
#     @param reg_class The register class of the register
#     @param reg_size The size of the register
#     @return Name of the register
#     """
#     if reg_class >= len(_registerClasses):
#         return None
#     num_regs = len(_registerClasses[reg_class])
#     if num_regs < 4:
#         return None
#     reg_index = -1
#     if reg_size > 32: # 64-bit regs
#         reg_index = num_regs - 1
#     elif reg_size > 16: # 32-bit regs
#         reg_index = num_regs - 2
#     elif reg_size > 8: # 16-bit regs
#         reg_index = num_regs - 3
#     elif reg_size > 0: # 8-bit regs
#         reg_index = 0
#     else:
#         return None
#     return _registerClasses[reg_class][reg_index]


import idaapi
from idc import *
from idautils import *
from lib.Register import get_reg_class, get_reg_by_size
# coding=utf-8
__author__ = 'Anatoli Kalysch'



### ARCHITECTURE AND REGISTER FUNCTIONALITY ###
# IDA PRO execution context layouts 64
ctx_layout_64 = {'st':['ST0', 'ST1', 'ST2', 'ST3', 'ST4', 'ST5', 'ST6', 'ST7'],
              'ctrl':'CTRL',
              'segments':['CS', 'DS', 'ES', 'FS', 'GS', 'SS'],
              'registers':['RAX', 'RBX', 'RCX', 'RDX', 'RSI', 'RDI', 'RBP', 'RSP', 'R8', 'R9', 'R10', 'R11', 'R12', 'R13', 'R14', 'R15'],
              'flags':'EFL',
              'multimedia':['XMM0', 'XMM1', 'XMM2', 'XMM3', 'XMM4', 'XMM5', 'XMM6', 'XMM7', 'XMM8', 'XMM9', 'XMM10', 'XMM11', 'XMM12', 'XMM13', 'XMM14', 'XMM15', 'MXCSR', 'MM0', 'MM1', 'MM2', 'MM3', 'MM4', 'MM5', 'MM6', 'MM7']}

# IDA PRO execution context layouts 86
ctx_layout_86 = {'st':['ST0', 'ST1', 'ST2', 'ST3', 'ST4', 'ST5', 'ST6', 'ST7'],
                 'ctrl':'CTRL',

# Path: lib/Register.py
# def get_reg_class(reg):
#     """
#     @brief Determines the register class of a given reg.
#     All different register names that address the same register
#     belong to the same register class e.g.: 'ax' and 'eax'
#     @param reg name of register
#     @return register class
#     """
#     lreg = reg.lower()
#     ret_value = None
#     for pos, reg_list in enumerate(_registerClasses):
#         for reg in reg_list:
#             found = False
#             if reg == lreg:
#                 found = True
#                 ret_value = pos
#                 break
#         if found:
#             break
#     return ret_value
# 
# def get_reg_by_size(reg_class, reg_size):
#     """
#     @brief Determines the register by its size and class
#     @param reg_class The register class of the register
#     @param reg_size The size of the register
#     @return Name of the register
#     """
#     if reg_class >= len(_registerClasses):
#         return None
#     num_regs = len(_registerClasses[reg_class])
#     if num_regs < 4:
#         return None
#     reg_index = -1
#     if reg_size > 32: # 64-bit regs
#         reg_index = num_regs - 1
#     elif reg_size > 16: # 32-bit regs
#         reg_index = num_regs - 2
#     elif reg_size > 8: # 16-bit regs
#         reg_index = num_regs - 3
#     elif reg_size > 0: # 8-bit regs
#         reg_index = 0
#     else:
#         return None
#     return _registerClasses[reg_class][reg_index]


# Path: lib/Util.py
import idaapi
from idc import *
from idautils import *
from lib.Register import get_reg_class, get_reg_by_size

# coding=utf-8
__author__ = 'Anatoli Kalysch'



### ARCHITECTURE AND REGISTER FUNCTIONALITY ###
# IDA PRO execution context layouts 64
ctx_layout_64 = {'st':['ST0', 'ST1', 'ST2', 'ST3', 'ST4', 'ST5', 'ST6', 'ST7'],
              'ctrl':'CTRL',
              'segments':['CS', 'DS', 'ES', 'FS', 'GS', 'SS'],
              'registers':['RAX', 'RBX', 'RCX', 'RDX', 'RSI', 'RDI', 'RBP', 'RSP', 'R8', 'R9', 'R10', 'R11', 'R12', 'R13', 'R14', 'R15'],
              'flags':'EFL',
              'multimedia':['XMM0', 'XMM1', 'XMM2', 'XMM3', 'XMM4', 'XMM5', 'XMM6', 'XMM7', 'XMM8', 'XMM9', 'XMM10', 'XMM11', 'XMM12', 'XMM13', 'XMM14', 'XMM15', 'MXCSR', 'MM0', 'MM1', 'MM2', 'MM3', 'MM4', 'MM5', 'MM6', 'MM7']}

# IDA PRO execution context layouts 86
ctx_layout_86 = {'st':['ST0', 'ST1', 'ST2', 'ST3', 'ST4', 'ST5', 'ST6', 'ST7'],
                 'ctrl':'CTRL',

                 'segments':['CS', 'DS', 'ES', 'FS', 'GS', 'SS'],