【问题标题】:Changing compiler in IDAPython在 IDAPython 中更改编译器
【发布时间】:2020-06-06 19:26:38
【问题描述】:

我一直在尝试使用 IDAPython API 来调整脚本中的编译器设置,但我似乎无法让任何函数正常工作。我尝试过的一些事情:

1.

Python>SetLongPrm(INF_COMPILER, COMP_MS)

这让我将编译器 id 设置为正确的值,但由于某种原因,它将所有其他编译器相关值设置为 0 或类似的值。给我一个关于指针大小不正确且 int 大小不是有效值的错误。

2.

Python>idaapi.set_compiler_id(2)
False

这直接行不通,但这可能会与第一个命令相同。

3.

class compiler_info_t(object):
    id = COMP_MS
    cm = 0x3 | 0x00 | 0x30
    size_i = 4
    size_b = 1
    size_e = 4
    defalign = 0
    size_s = 2
    size_l = 4
    size_ll = 8
    def __init__(self, *args):
        """
        __init__(self) -> compiler_info_t
        """
        this = _idaapi.new_compiler_info_t(*args)
        try: self.this.append(this)
        except: self.this = this

我最后一次尝试是尝试制作我自己的 compiler_info_t 对象以传递给 idaapi.set_compiler(),但由于“_idaapi”不是我可以正常导入的模块,它不会让我调用 new_compiler_info_t()。

问题: 有没有办法单独设置/修复指针大小、内存模型和调用约定的编译器值? 如果没有,是否有其他方法可以完全调整编译器,类似于在编译器设置窗口中手动更改它的功能?

【问题讨论】:

    标签: python ida


    【解决方案1】:

    这是我的示例:“为 Visual C++ 设置编译器默认值”

    def print_compiler(id):
        print '-'*(80)
        abbr = ida_typeinf.get_compiler_abbr(id)
        name = ida_typeinf.get_compiler_name(id)
        print "id: %d (%s)" % (id,abbr)
        print "Compiler: '%s'" % name
        im = idc.get_inf_attr(INF_COMPILER)
        print "Calling model: %02X" % im.cm
        print "Defauil alignments: %d" % im.defalign
        print "sizeof(int): %d\tsizeof(short): %d" % (im.size_i,im.size_s)
        print "sizeof(bool): %d\tsizeof(long): %d" % (im.size_b,im.size_l)
        print "sizeof(enum): %d\tsizeof(longlong): %d" % (im.size_e,im.size_ll)
        print "sizeof(long double): %d" % (im.size_ldbl)
        print "Predefined macros: '%s'" % ida_idp.cfg_get_cc_predefined_macros(id)
        print "Included directories: '%s'" % ida_idp.cfg_get_cc_header_path(id)
        print '-'*(80)
    
    # Print Old Compiler settings by ID
    print_compiler(idc.get_inf_attr(INF_COMPILER).id)
    
    # Set Compiler defaults for Visual C++
    im = idc.get_inf_attr(INF_COMPILER) # Get current settings
    im.id = ida_typeinf.COMP_MS
    im.cm = 0x03 | 0x00 | 0x30
    im.defalign = 0
    im.size_i = 4
    im.size_b = 1
    im.size_e = 4
    im.size_s = 2
    im.size_l = 4
    im.size_ll = 8
    im.size_ldbl = 8
    # Replace predefined macros and included directories by id
    # from IDA.CFG (see 'CC_PARMS' in Built-in C parser parameters)
    ida_typeinf.set_c_macros(ida_idp.cfg_get_cc_predefined_macros(im.id))
    ida_typeinf.set_c_header_path(ida_idp.cfg_get_cc_header_path(im.id))
    # Resetting new settings :)
    idc.set_inf_attr(INF_COMPILER, im.id)
    
    # Print New Compiler settings by ID
    print_compiler(im.id)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 2011-10-10
      相关资源
      最近更新 更多