ida risc-V 增加几条指令

from ida_lines import COLOR_INSN, COLOR_MACRO 
from ida_idp import CUSTOM_INSN_ITYPE, IDP_Hooks, ph_get_regnames, ph_get_id, PLFM_XTENSA, PLFM_RISCV
from ida_bytes import get_bytes
from ida_idaapi import plugin_t, PLUGIN_PROC, PLUGIN_HIDE, PLUGIN_SKIP, PLUGIN_KEEP
from ida_ua import o_displ, o_reg, o_imm, dt_dword, OOF_ADDR
from struct import unpack


import sys
import idaapi
from idaapi import *
import ida_pro

DEBUG_PLUGIN = True

NEWINSN_COLOR = COLOR_MACRO if DEBUG_PLUGIN else COLOR_INSN

class NewInstructionsx:
    (NN_push,NN_pop,NN_jal16,NN_l_li,
    ) = range(CUSTOM_INSN_ITYPE, CUSTOM_INSN_ITYPE+4)
    
    lst = {NN_push:"push",NN_pop:"popret",NN_jal16:"jal16",NN_l_li:"l.li"
           }
#--------------------------------------------------------------------------
class xtensa_idp_hook_t(IDP_Hooks):
    def __init__(self):
        IDP_Hooks.__init__(self)

    def decode_instruction(self, insn):
        buf = get_bytes(insn.ea, 6)
        
        if ( (buf[0]&0xF)==0x08 or (buf[0]&0xF)==0x04 ) and (buf[1]&0xF0)==0x80:
            #print("0x%08X: %02X %02X" % (insn.ea, buf[0], buf[1],))
            #push    {ra,s0-s1},-64
            if (buf[0]&0xF)==0x08:
               insn.itype = NewInstructionsx.NN_push;
            elif (buf[0]&0xF)==0x04:
               insn.itype = NewInstructionsx.NN_pop; 
            insn.size = 2
            insn.Op1.type = o_imm;
            reg_num = (buf[0]>>4)&0xF;
            insn.Op1.addr = reg_num;
            if reg_num%4!=0x00:
               reg_num = reg_num//4 + 1;
            else:
               reg_num = reg_num//4;
            add_num = (buf[1]>>0)&0xF;  
            reg_num = (reg_num + add_num)*16;
            if (buf[0]&0xF)==0x08:
               insn.Op1.value = -reg_num;
            elif (buf[0]&0xF)==0x04:    
               insn.Op1.value =  reg_num;           
            print("insn.Op2.value = %X" % insn.Op1.value) 
            return True;
        elif (buf[0]&0xFF) == 0x7B:
            #06d05f7b 
            #6 3c 4 b 07b
            #104 B6 3C
            
            #16 3 0 8 f 7b
            #E0 8962
            insn.itype = NewInstructionsx.NN_jal16;
            
            set_bit = (buf[2]>>4)&0x01;
 
            reg = buf[1] & 0x0f;
            if reg > 0x00:
               reg_24_20 = reg -1;
            else:
               reg_24_20 = 0x10;
            reg_19_16 = buf[2] & 0x0f;
            reg_15_12 = (buf[1]>>0x04)&0x0f;
            
            if set_bit == 0x00:
               reg_11_08 = ((buf[3]>>0x04)&0x0f) & 0x07;
            else:
               reg_11_08 = ((buf[3]>>0x04)&0x0f) | 0x08; 
               
            reg_07_00 = buf[3]&0x0f;
            reg_07_00 = (reg_07_00<<4) | ((buf[2]>>4)&0x0e);
            reg = (reg_24_20<<20) | (reg_19_16<<16) | (reg_15_12<<12) | (reg_11_08<<8) | (reg_07_00<<0);
            
            insn.size = 4
            insn.Op1.type = o_imm;
            
            
            
            print("reg1 = %X" % reg) 
            print("insn.ea = %X" % insn.ea)    
            reg = reg + (insn.ea&0x0fffff) 
            insn.Op1.value =  reg;    
            print("reg2 = %X" % reg)             
            return True;
        elif (buf[0]&0x7F) == 0x1f and (buf[1]&0xf0)==0x00:
            #051f          l.li    a0
            #0000  01010   00 11111
            insn.itype = NewInstructionsx.NN_l_li;
            lowest_bit = buf[0]>>7;
            reg_4_1 = buf[1]&0x0f;
            reg = (reg_4_1<<1) | lowest_bit;
            insn.size = 6
            insn.Op1.type = o_reg;
            insn.Op1.value = reg;
            print("reg21 = %d" % reg) 
            
            insn.Op2.type = o_imm;
            reg = buf[5]<<24 | buf[4]<<16 | buf[3]<<8 | buf[2]<<0;
            insn.Op2.value = reg;
            print("reg22 = 0x%x" % reg)             
            return True;
        return False;

    def ev_ana_insn(self, insn):
        return self.decode_instruction(insn)

    def ev_out_mnem(self, outctx):
        insntype = outctx.insn.itype
        global NEWINSN_COLOR

        if (insntype >= CUSTOM_INSN_ITYPE) and (insntype in NewInstructionsx.lst):
            mnem = NewInstructionsx.lst[insntype]
            outctx.out_tagon(NEWINSN_COLOR)
            outctx.out_line(mnem)
            outctx.out_tagoff(NEWINSN_COLOR)
            #print("mnem = %s" % mnem)

            # TODO: how can MNEM_width be determined programmatically?
            MNEM_WIDTH = 12
            width = max(1, MNEM_WIDTH - len(mnem))
            outctx.out_line(' ' * width)

            return True
        return False


    def ev_out_operand(self, outctx, op):
        insn = outctx.insn
        
        
        #print("CUSTOM_INSN_ITYPE = %x" % CUSTOM_INSN_ITYPE) 
        #print("NewInstructionsx.NN_quou = %x" % NewInstructionsx.NN_quou) 
        #print("NewInstructionsx.NN_muluh = %x" % NewInstructionsx.NN_muluh) 
        #print("NewInstructionsx.NN_ld_hu = %x" % NewInstructionsx.NN_ld_hu) 
        
        #print("NewInstructionsx.NN_ld_hu = ", NewInstructionsx.NN_ld_hu) 
        #print("NewInstructions.NN_st_h = %X" % NewInstructionsx.NN_st_h) 
        if insn.itype in [NewInstructionsx.NN_push, NewInstructionsx.NN_pop]:
           #print("insn.itype = %X" % insn.itype)  
           #print("op.type = %X" % op.type) 
            
           #print("o_displ = %X" % o_displ) 
           #print("o_reg = %X" % o_reg) 
           #print("o_imm = %X" % o_imm)
           if op.type == o_imm:
              #print("o_displ = %X" % o_displ) 
              outctx.out_line("   {")
              outctx.out_register(ph_get_regnames()[1]) 
              reg_index = op.addr - 1;                 
              if reg_index > 0:
                 outctx.out_line(', ');   
                 outctx.out_register(ph_get_regnames()[8])
                 if reg_index > 2:
                    outctx.out_line('-'); 
                    outctx.out_register(ph_get_regnames()[18+reg_index-3])
                 elif reg_index==2:
                    outctx.out_line('-'); 
                    outctx.out_register(ph_get_regnames()[8+reg_index-1])
                             
              outctx.out_line('},    ');  
              outctx.out_value(op, OOFW_IMM |OOF_SIGNED |OOFS_NEEDSIGN|OOFW_32)
              print("op.addr = %X" % op.addr) 
              print("op.value = %d" % op.value) 
              return True
        if insn.itype in [NewInstructionsx.NN_jal16]:
           #print("insn.itype = %X" % insn.itype)  
           #print("op.type = %X" % op.type) 
            
           #print("o_displ = %X" % o_displ) 
           #print("o_reg = %X" % o_reg) 
           #print("o_imm = %X" % o_imm)
           if op.type == o_imm:
              #outctx.out_long(op.value, 16) 
              outctx.out_value(op, OOFW_IMM | OOFW_32)
              print("op.value = %X" % op.value) 
              print("op.addr = %X" % op.addr) 
              return True
        if insn.itype in [NewInstructionsx.NN_l_li]:
           #print("insn.itype = %X" % insn.itype)  
           #print("op.type = %X" % op.type) 
            
           #print("o_displ = %X" % o_displ) 
           #print("o_reg = %X" % o_reg) 
           #print("o_imm = %X" % o_imm)
           if op.type == o_reg:
              outctx.out_register(ph_get_regnames()[op.value]) 
              return True              
           if op.type == o_imm:
              #outctx.out_long(op.value, 16) 
              outctx.out_value(op, OOFW_IMM | OOFW_32)
              print("op.value = %X" % op.value) 
              print("op.addr = %X" % op.addr) 
              return True
        return False
        
        
#--------------------------------------------------------------------------
class XtensaESP(plugin_t):
    flags = PLUGIN_PROC | PLUGIN_HIDE
    comment = ""
    wanted_hotkey = ""
    help = "Adds support for additional Xtensa instructions"
    wanted_name = "XtensaESP"

    def __init__(self):
        self.prochook = None
        print ("%s initialized3." % XtensaESP.wanted_name)

    def init(self):
        #if ph_get_id() != PLFM_XTENSA:
        if ph_get_id() != PLFM_RISCV:
            print ("%s initialized1." % XtensaESP.wanted_name)
            print ("PLFM_XTENSA = %d." % PLFM_XTENSA)
            print ("ph_get_id() = %d." % ph_get_id())
            return PLUGIN_SKIP
        self.PTRSZ = 4 # Assume PTRSZ = 4 by default 
        self.prochook = xtensa_idp_hook_t()
        self.prochook.hook()
        print ("%s initialized2." % XtensaESP.wanted_name)
        return PLUGIN_KEEP

    def run(self, arg):
        pass

    def term(self):
        if self.prochook:
            self.prochook.unhook()
#--------------------------------------------------------------------------
def PLUGIN_ENTRY():
    return XtensaESP()

eqpid left top IDA547 -27.9 9.7 IDA532 -33 9.7 IDA012 -22.7 13.6 IDA204 -14.6 13.6 IDA353 -40.5 34.3 IDA047 -54.4 20.9 IDA543 -59.4 19.5 IDA014 -54.4 18.1 IDA344 -36.6 52.6 IDA337 -30.5 52.6 IDA338 -23.9 52.6 IDA345 -30.5 47.6 IDA346 -23.9 47.6 IDA347 -17.7 47.6 IDA348 -11.9 47.6 IDA323 7 51.8 IDA324 12.5 51.7 IDA325 18.2 51.8 IDA322 7 45.3 IDA321 12.5 45.3 IDA320 18.2 45.3 IDA317 7 40 IDA318 12.5 40 IDA319 18.2 40 IDA316 1.5 40 IDA307 1.5 32.9 IDA301 1.5 28.3 IDA302 7 28.3 IDA306 12.5 32.9 IDA303 12.5 28.3 IDA305 18.2 32.9 IDA518 18.2 28.3 IDA334 31.7 51.8 IDA330 31.7 45.3 IDA329 31.7 40 IDA315 31.7 32.9 IDA308 31.7 28.3 IDA335 37.7 51.8 IDA331 37.7 45.3 IDA328 37.7 40 IDA314 37.7 32.9 IDA309 37.7 28.3 IDA336 44.1 51.8 IDA332 44.1 45.3 IDA327 44.1 40 IDA313 44.1 32.9 IDA310 44.1 28.3 IDA342 50.2 51.8 IDA333 50.2 45.3 IDA326 50.2 40 IDA312 50.2 32.9 IDA311 50.2 28.3 IDA208 -8.6 24.5 IDA206 -13.4 24.6 IDA070 -9.6 3.8 IDA506 -36.6 47.6 IDA508 -63.3 9.6 IDA509 -57.6 9.6 IDA510 -51.9 9.6 IDA501 -63.3 4 IDA502 -57.6 4 IDA503 -51.9 4 IDA511 -46.3 9.6 IDA504 -46.3 4 IDA505 -30.7 -57 IDA355 -27.6 34.3 IDA354 -34 34.3 IDA349 -55.1 34 IDA529 -59.6 34 IDA071 -9.6 9.6 IDA205 -17.8 24.6 IDA530 -64.9 34 IDA513 -65.1 19.5 IDA516 -65.1 38.4 IDA515 -59.7 38.4 IDA519 -55.1 38.4 IDA520 -42 47.6 IDA521 -40.4 38.8 IDA523 -27.6 38.8 IDA522 -34.1 38.8 IDA304 24.8 32.9 IDA517 24.8 28.3 IDA507 -11.9 38.8 IDA339 -17.7 38.8 IDA512 -39.3 4 IDA207 -9.7 13.6 IDA340 -36 -57 IDA343 -41.6 -57 IDA069 -20.9 9.5 IDA527 -65.1 48.5 IDA528 -65.1 52.9 IDA526 -59.7 52.9 IDA525 -59.7 48.4 IDA350 -42.1 52.6 IDA351 -46.7 -57 IDA352 -52.2 -57 IDA531 -33.2 4 IDA548 -27.1 4 IDA533 -21 4 IDA534 -14.9 4 IDA535 -24.2 -57 IDA536 -17.5 -57 IDA537 0 -57 IDA539 -54.6 52.9 IDA540 -54.6 58 IDA541 -59.8 58 IDA542 -65.1 58 IDA546 -42 58 IDA545 -36.3 58 IDA202 -17.8 28.4 IDA201 -13.4 28.4 IDA203 -8.6 28.4 IDA549 -30.3 58 IDA550 -23.9 58 IDA538 -14.8 9.7 IDA551 -11.7 52.2 IDA552 -11.7 57.5 IDA553 -57.2 -56.9 IDA555 -61.7 -56.9 帮我列出来每条信息的update sql语句,就是显示全部,我再强调一遍,显示全部,不要给我下载附件或者省略号,我就要显示全部
最新发布
11-01
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值