【原创】IDA中的中文解析插件

Python代码
文件名:set_chinese_comment.py
将其放在ida\plugins之下。
重新启动IDA,打开一个数据库文件
按alt+9,执行

在日志窗口中输出添加注释的信息,同时在.idata、.data段中添加了注释

import ida_idaapi
import idaapi
import idautils
import idc


def set_comment():
    for segment in idautils.Segments():
        seg_name = idc.get_segm_name(segment)
        segments = ['.data', '.idata', '.rdata']
        if seg_name in segments:
            print('add comment for segment ', seg_name)
            set_segment_cmt(segment)


def set_segment_cmt(segment):
    start_ea = segment
    end_ea = idc.get_segm_end(segment)
    temp_ea = start_ea
    comment_ea = start_ea
    comment = ''
    comment_gbk = ''
    comment_utf8 = ''
    comment_utf16 = ''

    byte_data = []
    while temp_ea < end_ea:
        byte_d = idc.get_db_byte(temp_ea)
        if byte_d != 0:
            if comment_ea == 0:
                comment_ea = temp_ea
            byte_data.append(byte_d)
        else:
            if len(byte_data) > 2:
                # 首先使用gbk解析
                try:
                    comment_gbk = bytes(byte_data).decode("GBK")
                    comment = comment_gbk
                except Exception:
                    pass
                # 再使用utf-8解析
                try:
                    comment_utf8 = bytes(byte_data).decode("utf-8")
                    if comment_utf8 != comment_gbk:
                        comment = comment + "\n" + comment_utf8
                except Exception:
                    pass
                # 再使用utf-16le 解析
                try:
                    comment_utf16 = bytes(byte_data).decode("utf-16le")
                    if comment_utf16 != comment_gbk and comment_utf16 != comment_utf8:
                        comment = comment + "\n" + comment_utf16
                except Exception:
                    pass
                idaapi.set_cmt(comment_ea, comment, True)
                print(hex(comment_ea), comment)
            byte_data = []
            comment_ea = 0
        temp_ea = idc.next_addr(temp_ea)


def PLUGIN_ENTRY():
    """
    Required plugin entry point for IDAPython plugins.
    """
    return SetChineseComment()


class SetChineseComment(ida_idaapi.plugin_t):
    """
    The IDA Patching plugin stub.
    """
    flags = ida_idaapi.PLUGIN_PROC | ida_idaapi.PLUGIN_UNL
    comment = "A plugin of ida of setting chinese comment"
    help = ""
    wanted_name = "Set Chinese Comment"
    wanted_hotkey = "alt+9"

    # --------------------------------------------------------------------------
    # IDA Plugin Overloads
    # --------------------------------------------------------------------------

    def __init__(self):
        pass

    def init(self):
        print('*' * 10, self.wanted_name, ' init...')
        return ida_idaapi.PLUGIN_KEEP

    def run(self, arg):
        print('*' * 10, self.wanted_name, ' runing...')
        set_comment()
        print('*' * 10, self.wanted_name, ' run finished...')

    def term(self):
        print('*' * 10, self.wanted_name, ' term...')

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赵庆明老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值