• IDA-IDC脚本编写语法


    1、IDA脚本编写基础

      IDC是IDA内置的脚本语言,其语法与C非常相似,它是一种解释性语言。

    • 执行方法
      • 在IDA中按SHIFT+F2键会弹出一个对话框,把语句直接写在对话框中,点击run就可被运行。
      • 在菜单栏中File | Script file载入idc文件。

    2、IDC语法

      IDC语言可参考C语言,语句以分号结束,注释为//或/**/,但也有很多不同。

    • 2.1 输出(类似C语言中的printf函数)
    • void Message(string format, …);
    • Message(“Hello world!”);
    • Message(“%s ”, “Hello world!”);

    2.2 变量

      IDC中所有变量都被定义成auto类型,会自动进行类型转换,一般类型有整数型、字符串类型、浮点型。

    • 局部变量:auto counter;
    • extern 引入全局变量的声明,extern outsideGlobal;
    • 字符串支持加好连接:auto str = "hello" + "world";
    • 字符串支持分片操作:str1 = str[7:9];

    2.3 操作符

    • 许多标准的C语言操作符(+、-、*、/、%、<<、>>、++、--)在IDC同样适用,但复合赋值运算符+=不支持、逗号操作符也不被支持。

    2.4 条件

    •  if、if else及三目运算符“?:”是支持的,但是switch语句是不支持的。
    auto currAddr;
    currAddr = ScreenEA();
    if (currAddr % 2)
        Message(“%x is odd
    ”, currAddr);
    else
        Message(“%x is even
    ”, currAddr);

    2.5 循环

    • 循环可以用for、while、do while实现。
    auto origEA, currEA, funStart, funEnd;
    origEA = ScreenEA();
    funStart = GetFunctionAttr(origEA, FUNCATTR_START);
    funEnd = GetFunctionAttr(origEA, FUNCATTR_END);
    if(funStart == -1)
        Message(“%x is not part of a functuion
    ”), origEA);
    for(currEA=funStart; currEA != BADADDR; currEA=NextHead(currEA, funEnd)){
        Message(“%8x
    ”, currEA);
    }

    2.6 函数

    • IDC所有函数必须被定义为静态。
    • 函数的声明与C语言不同,不需要指定类型。
    • 函数参数传递中,加上&表示传地址,不加表示传值。
    • return 返回函数输出。
    • 把自己的IDC函数库加入到ida.idc文件中,我们就可以全局使用自己的IDC函数了。
    // 例1:
    static outputCurrentAddress(){
        auto currAddress;
        currAddress = ScreeenEA();
        Message(“%x
    ”, currAddress);
        return currAddress;
    }
    // 例2:
    my_func(q, r, s)

    2.7 IDC对象

    class ExampleClass{
        ExampleClass(x, y){
            this.x = x;
            this.y = y;
        }
        ~ExampleClass(){
        }
        foo(x){
            this.a = this.a + x;
        }
    }
    
    static main(){
        ExampleClass ex;
        auto ex = ExampleClass(1, 2);
        ex.foo(10);
        ex.z = "string" //特点,可随时给对象添加成员
    }

    2.8 IDC程序

    •  将IDC脚本代码放到一个文件中可永久性保存。
    •   #include <文件> 将指定文件包含在当前文件中
    •   #define <宏名称> [可选值]
    •   #ifdef <名称> 测试宏是否存在
    •   #else 与#ifelse共同使用
    •   #endif #ifdef的终止符
    •   #undef <名称>删除宏定义
    #include <idc.idc>
    static main(){
        // 代码体
    }

    2.9 IDC错误处理

    •  try/catch

    2.10 数组

     

    3、有用的IDC函数

      

      

      

      

      

      

      

      

      

      

      

      

      

  • 相关阅读:
    sqlservr 命令行启动
    提高程序性能、何为缓存
    NoSQL和MemeryCache的出现意味着传统数据库使用方式的变革吗?
    jQuery UI Autocomplete是jQuery UI的自动完成组件
    MongoDB
    一步步 jQuery (一)概念,使用,$名称冲突4种解决方法,使用层次及次数问题
    淘宝API开发系列
    MongoDB学习笔记
    WF Workflow 状态机工作流 开发
    MongoDb与MVC3的增删改查采用官方驱动
  • 原文地址:https://www.cnblogs.com/gwind/p/8250842.html
Copyright © 2020-2023  润新知