首页
社区
课程
招聘
[分享]IDA 搜索UNICODE中文字符串python脚本
发表于: 2007-11-30 01:04 19747

[分享]IDA 搜索UNICODE中文字符串python脚本

2007-11-30 01:04
19747
# -*- coding: utf-8 -*-
#使用方法:SearchUnicodeString() 或SearchUnicodeString(1) =》1为地址加上注释
#脚本有些乱,请多包含
#虽然搜索出一些其实不是字符串的字符,但它符合Unicode的范围,实则没办法
#脚本作者为:Steve QQ:344843150

szPattern=ur'''[
        #\u3040-\u318f| #日文平假名,及繁体注音符号
        \u3300-\u337f| #带圆括号象形字
        #\u3400-\u3d2d| #CJK扩展A
        \u4e00-\u9fff| #CJK统一表意符号
        #\uf900-\ufaff| #CJK兼容象形文字
        #\uac00-\ud7af] #未知字符
        {1,}[\u0000]
        '''
##        szPattern=szPattern.encode("utf-16")
##        szPattern="[\u4e00-\u9fa5]"
Pattern=re.compile(szPattern,re.UNICODE | re.VERBOSE)

def GetBytes(ea,size):
    bytes=""
    for byte_ea in range(ea,ea+size):
        bytes+=chr(get_byte(byte_ea))
    return bytes

def showUStr(ea,size,bCmt):
    if (ea!=BADADDR and size!=0):
        gbkstr=""

        sFind=GetBytes(ea,size)
        if isData(GetFlags(ea)):
            if Pattern.match(unicode(sFind,'utf-16','ignore')):
                #print "Find:0x%x" %ea
            
            #    if get_word(ea)>=0x4e00 and get_word(ea)<=0x9fa5 : # and get_word(ea+2)>=0x4e00 and get_word(ea+2)<=0x9fa5 :
                    #if get_word(get_item_end(ea)-2)==0:
                try:
                    gbkstr=unicode(GetBytes(ea,size),'utf-16').encode('gbk')
                except BaseException:
                    gbkstr=""
                else:
                    if bCmt: set_cmt(ea, gbkstr, 1)
    return gbkstr

def SearchUStr(ea_start,ea_end,bCmt=0):
    """Search Unicode String"""
    ea=ea_start
    while ea<ea_end:
##        print 'ea=0x%x'%(ea)

##        if isASCII(get_flags_novalue(ea)):
##            #stype=typeinfo_t()
##            #stype.strtype=0
##            #stype=get_typeinfo(ea,0,FF_DWRD,stype)
##            stype=GetStringType(ea)
##            code=stype
##            print 'stype=%s'%code

        size=get_item_size(ea)
        #print 'size:%d'%size
        if size>2:
            szUStr=showUStr(ea,size,bCmt)
            szUStr=szUStr.strip(' \n\0')
            #szUStr=szUStr.strip().strip('\n').strip(chr(0xA)).strip('\0')
            if szUStr<>'':
                print 'ea=0x%x:%s'%(ea,szUStr)
            
##            if code==ASCSTR_UNICODE or stype==ASCSTR_ULEN2 or stype==ASCSTR_ULEN4:
##                delta=0
##                if code==ASCSTR_ULEN2:
##                    delta=2
##                if code==ASCSTR_ULEN4:
##                    delta=4
##
##                size=get_item_size(ea)
##                print 'size:%d'%size
##                if size>delta:
##                    print showUStr(ea,size,0)
##            
        ea=NextHead(ea,ea_end)

#bCmt为地址加上注释
def SearchUnicodeString(bCmt=0):
    """Seach Unicode String"""
    SearchUStr(MinEA(),MaxEA(),bCmt)
   

附件(请把txt后辍名改为py附件(编码utf-8)):
unicode_gen.txt

[课程]FART 脱壳王!加量不加价!FART作者讲授!

上传的附件:
收藏
免费 7
支持
分享
最新回复 (7)
雪    币: 6075
活跃值: (2236)
能力值: (RANK:1060 )
在线值:
发帖
回帖
粉丝
2
学习python
2007-11-30 10:42
0
雪    币: 827
活跃值: (242)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
支持哈~~~~
2007-11-30 11:47
0
雪    币: 1919
活跃值: (901)
能力值: ( LV9,RANK:490 )
在线值:
发帖
回帖
粉丝
4
不懂python,先收藏~~
2007-11-30 17:28
0
雪    币: 233
活跃值: (202)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
正需要多谢版主
2007-12-12 13:57
0
雪    币: 219
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
能显示繁体字符?
2007-12-14 23:19
0
雪    币: 239
活跃值: (20)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
7
gbk码集包括繁体字,应该能显示。
2007-12-15 18:50
0
雪    币: 178
活跃值: (144)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
8
Ida pro 里的中文字串

// the following characters are allowed in ASCII strings, i.e.
// in order to find end of a string IDA looks for a character
// which doesn't belong to this array:
// (cp866 version)
AsciiStringChars =
        "\r\n\a\v\b\t\x1B"
        " !\"#$%&'()*+,-./0123456789:;<=>?"
        "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
        "`abcdefghijklmnopqrstuvwxyz{|}~"
        "€亗儎厗噲墛媽崕彁憭摂晼棙櫄洔潪?
        "牎ⅲぅΗī氨渤吹斗腹夯冀究"
        "懒旅呐魄壬仕掏蜗醒矣哉肿刭谯茌捱"
        "噌忏溴骁栝觌祉铒";

// (full version)
//AsciiStringChars =
//      "\r\n\a\v\b\t\x1B"
//      " !\"#$%&'()*+,-./0123456789:;<=>?"
//    "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
//      "`abcdefghijklmnopqrstuvwxyz{|}~"
//      "€亗儎厗噲墛媽崕彁憭摂晼棙櫄洔潪?
//      "牎ⅲぅΗī氨渤吹斗腹夯冀究"
//      "懒旅呐魄壬仕掏蜗醒矣哉肿刭谯茌捱"
//      "噌忏溴骁栝觌祉铒瘃蝮趱鲼?";

// the following characters are allowed in user-defined names:

.........................cut..............................

把// (cp866 version) 到// (full version)之间的行用 '//'注释掉
把// (full version)  // the following characters are allowed ..之间的行前面的 '//'去掉,保存,重新运行IdaPro,呵呵,汉字真好...
2007-12-17 16:18
0
游客
登录 | 注册 方可回帖
返回
//