shuai 的个人资料娱乐精神照片日志 工具 帮助
2007/12/14

强暴.Net程序集 之十二 (反汇编之IL指令集)

 
警告:本系列文章为本人原创,只作技术研究之用,您可以引用链接传播,禁止其它的转载方式,禁止用于商业或非法目的, 对于造成的一切后果本人概不负责
 
在方法头之后就是一字节形式存储的IL指令,  详细的IL取值请见: Partition III CIL, 比如有:
Opcode Instruction
0x00    nop
0x01    break
0x02    ldarg.0
....
0x26    pop
0x27    jmp
0x28    call
0x29    calli
0x2A    ret
0x2B    br.s
...
0xFE 0x00    arglist
0xFE 0x01    ceq
0xFE 0x02    cgt
0xFE 0x03    cgt.un
0xFE 0x04    clt
 
如果按操作码的大小分类, 指令可以分为两组, 一组的操作码只占一个字节,  一组占两个字节, 并高位字节为0xFE
如果按是否含有操作数(参数), 可以分为无操作数, 和有操作数, 有操作数又可以细分为:

    1) 操作数是一个Token, 比如 callvirt 指令
    2) 操作数是一个跳转的目标Label, 比如br指令
    3) 操作数是一个具体的值, 比如ldc.i4指令
    4) 操作数是一个方法形参的索引指, 比如ldarg.s指令
    5) 操作数是switch指令
 
    按操作数占用大小又分为:
    1) 1个字节, 比如br.s指令 ldc.i4.s指令
    2) 2个字节, 比如ldarg指令
    3) 4个字节, 比如br指令 ldc.i4指令
    4) 8个字节, 比如ldc.i8指令,
 
程序需要针对不同的操作数类型, 以及大小进行不同的反汇编处理
 
因为操作数类型, 以及大小是可以确定的, 所以程序中我用一个结构类型保存这些确定的值(先下面的OperandType枚举, 和opcode结构)
然后以指令的字节形式为key保存在Map中

    操作码为一个字节的Map
    m[0x00] = opcode(L"nop");
    m[0x01] = opcode(L"break");
    m[0x02] = opcode(L"ldarg.0");
    ....
    m[0x26] = opcode(L"pop");
    m[0x27] = opcode(L"jmp", 4, Token);
    m[0x28] = opcode(L"call", 4, Token);
    m[0x29] = opcode(L"calli", 4, Token);
    m[0x2a] = opcode(L"ret");
    m[0x2b] = opcode(L"br.s", 1, Branch);
 
    操作码为两个字节的Map
    n[0x00] =  opcode(L"arglist");
    n[0x01] =  opcode(L"ceq");
    n[0x02] =  opcode(L"cgt");
    n[0x03] =  opcode(L"cgt.un");
    n[0x04] =  opcode(L"clt");
 
typedef enum
{
    Branch = 0,
    Token,
    Index,
    Value,
    Switch,
    None
} OperandType;
struct opcode
{
public:
    opcode()
    {
        operandSize = 0;
    }
    opcode(const std::wstring& instr) :
           instruction(instr),
           operandSize(0),
           operandType(None)
    {
    }
    opcode(const std::wstring& instr, int os, OperandType t) :
           instruction(instr),
           operandSize(os),
           operandType(t)
    {
    }
private:
    std::wstring instruction;
    int operandSize;
    OperandType operandType;
};
 

评论 (3)

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

没有名字发表:

Hi,Do you need digital signages, advertising displays, digital sign, advertisement displays and advertising players? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.

amberdigital Contact Us

website:www.amberdigital.com.hk
alibaba:amberdigital.en.alibaba.com[efbcidieidcjae]

10 月 24 日
没有名字发表:

Hi,Do you need ad players, advertisement player and LCD advertisings? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers. amberdigital Contact Us

E-mail:sstar@netvigator.com
website:www.amberdigital.com.hk
alibaba:amberdigital.en.alibaba.com[a

9 月 8 日
没有名字发表:
Welcome to enter (wow gold) and (wow power leveling) trading site, (Rolex) are cheap, (World of Warcraft gold) credibility Very good! Quickly into the next single! Key words directly to the website click on transactions! -6427580068801
8 月 4 日

引用通告

此日志的引用通告 URL 是:
http://iauhsgnay.spaces.live.com/blog/cns!C7C5DB6D46321CDD!451.trak
引用此项的网络日志