首页
社区
课程
招聘
ilasm 汇编小则 (高手勿进)(一)、(二)
发表于: 2005-9-9 15:45 13545

ilasm 汇编小则 (高手勿进)(一)、(二)

2005-9-9 15:45
13545

.net的一个很重要的特性就是跨语言的编程,任何语言都可以相互的调用,(比如C++,可以调用c#写的类),但前提相互调用的语言的约定只能规矩的遵守"CLS(公共语言规范)"的所有特性才可以,否则这中跨语言的编程将死悄悄拉...

net的汇编ilasm则继承了"CLS(公共语言规范)"所有特性.对于其他语言则也都集成了最小"CLS"规范,相关"GLS"规范可以看 .NET Frame 文档...
如果你想成为一个多语中编程的高手,想在.net平台下跨语言的编程,就必须熟悉 相关"CLS"的特性规范...

ilasm汇编不同与x86汇编,它的虚拟字节指令更抽象,更加想面向对象指令...

现在很多论坛对ilasm汇编很热,偶也初学.net,也对这中il汇编有兴趣.

下面 看看一个 输出"hello ilasm" 的Window Console 的ilasm结构:

.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                       
  .ver 1:0:5000:0
}
.assembly helloil1
{
  
}

.module helloil1.exe
.imagebase 0x00400000
.subsystem 0x00000003
.file alignment 4096
.corflags 0x00000001

.namespace helloil1   //定义名字空间helloil1
{
  .class private auto ansi beforefieldinit Class1 extends [mscorlib]System.Object
  {
    .method private hidebysig static void Main(string[] args) cil managed
    {
      .entrypoint //程序进入点标志
      .custom instance void [mscorlib]System.STAThreadAttribute::.ctor()  //单线城对象模型构造初始化
      .maxstack  1 //堆栈定义
        ldstr      "Hello ilasm" //压入字符串,堆栈压操作
        call       void [mscorlib]System.Console::WriteLine(string)
//这里输出"Hello ilasm" 调用
        call       string [mscorlib]System.Console::ReadLine()
//检测回车
        pop
        ret
    }

    .method public hidebysig specialname rtspecialname instance void  .ctor() cil managed //这是console类构造
    {
      
      .maxstack  1
        ldarg.0
        call       instance void [mscorlib]System.Object::.ctor()
        ret
    }

  }

}

ilasm汇编编译器在路径:C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\ilasm.exe

编译成功,,输出" hello  ilasm" ,它是个Window Console程序,至于生成一个
Window Form 程序的ilasm汇编结构,我会在下一遍给予介绍..

偶大略的说说.详细可以看看.NET Frame 文档...

static void Main(string[] args) cil managed

这是程序托管入口,static void Main(),

.assembly 特性定义一个程序集,可以模糊的认为程序集是.net环境中生成的EXE,或DLL,但只中EXE 或DLL,与.net之前的有又不同,它们更象组件相互封装,配属...具体看.NET Frame 文档...

.module 特性区别与.assembly,可以把.module理解为.net之前的exe或dll..

.imagebase 影象基地址..

.subsystem 连接系统类型

.file alignment 文件对齐数值

.corflags  指令设置运行库头文件标志.默认情况下,.corflags 指令指定值 1

.namespace 定义名字空间

由于初学.net有描述错误,大家请指点...


[培训]科锐逆向工程师培训第53期2025年7月8日开班!

收藏
免费 7
支持
分享
最新回复 (18)
雪    币: 258
活跃值: (230)
能力值: ( LV12,RANK:770 )
在线值:
发帖
回帖
粉丝
2
难免有误,,大家请批评,附件:a1.rar
2005-9-9 15:48
0
雪    币: 234
活跃值: (370)
能力值: ( LV9,RANK:530 )
在线值:
发帖
回帖
粉丝
3
学习
2005-9-9 16:02
0
雪    币: 258
活跃值: (230)
能力值: ( LV12,RANK:770 )
在线值:
发帖
回帖
粉丝
4
第二篇.IL汇编,,
在第一篇(是凑数的.. )有了对il汇编的了解,,

偶只是简单的说一下il汇编结构,,不是讲解.net
大家记得.NET 反编译工具ildasm,,大家可以反编译,熟悉熟悉il汇编虚拟指令
详细的il汇编虚拟指令说明在:
9e6K9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8X3#2K6k6r3&6Q4x3X3g2E0K9h3y4J5L8%4y4G2k6Y4c8Q4x3X3g2U0L8$3#2Q4x3V1k6D9K9h3u0J5j5i4u0&6i4K6u0r3j5$3S2K6i4K6u0r3k6r3g2X3j5i4g2D9N6q4)9J5k6h3q4K6M7q4)9K6c8Y4g2J5L8q4)9K6c8q4)9J5c8X3I4A6j5Y4u0S2M7Y4W2Q4x3V1k6o6d9q4y4Q4x3V1k6U0M7s2u0W2k6W2)9J5c8X3S2@1L8h3I4Q4x3V1k6X3M7X3I4J5k6Y4y4&6M7%4c8W2L8i4u0W2k6X3I4W2j5%4c8A6L8$3&6W2L8h3W2@1L8%4m8U0L8$3c8W2M7$3y4D9j5i4y4K6j5Y4u0X3j5h3I4K6k6g2)9#2k6Y4y4@1L8%4m8A6j5#2)9J5k6h3q4K6M7l9`.`.

下面 Win Form il 汇编如下(有些特性,偶也是用ildasm反编译,加ilasm正向编译得到的):

.assembly extern System.Windows.Forms
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                        
  .ver 1:0:5000:0
}
.assembly extern System
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                        
  .ver 1:0:5000:0
}
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                        
  .ver 1:0:5000:0
}
.assembly extern System.Drawing
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                        
  .ver 1:0:5000:0
}
.assembly HelloIL
{
  .custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyKeyNameAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyKeyFileAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyDelaySignAttribute::.ctor(bool) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyTrademarkAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 00 00 00 )
  .hash algorithm 0x00008004
  .ver 1:0:2078:25277
}
.mresource public HelloIL.Form1.resources{}
.module HelloIL.exe
.imagebase 0x00400000
.subsystem 0x00000002
.file alignment 4096
.corflags 0x00000001

.namespace HelloIL
{
  .class public auto ansi beforefieldinit Form1 extends [System.Windows.Forms]System.Windows.Forms.Form
  {
    .field private class [System]System.ComponentModel.Container components
    .method public hidebysig specialname rtspecialname instance void  .ctor() cil managed
    {
      
      .maxstack  2
        ldarg.0
        ldnull
        stfld      class [System]System.ComponentModel.Container HelloIL.Form1::components
        ldarg.0
        call       instance void [System.Windows.Forms]System.Windows.Forms.Form::.ctor()
        ldarg.0
        call       instance void HelloIL.Form1::InitializeComponent()
        ret
    }

    .method family hidebysig virtual instance void Dispose(bool disposing) cil managed
    {
      
      .maxstack  2
          ldarg.1
          brfalse.s  IL_jmp1
          ldarg.0
          ldfld      class [System]System.ComponentModel.Container HelloIL.Form1::components
          brfalse.s  IL_jmp1
          ldarg.0
          ldfld      class [System]System.ComponentModel.Container HelloIL.Form1::components
          callvirt   instance void [System]System.ComponentModel.Container::Dispose()
IL_jmp1:  ldarg.0
          ldarg.1
          call       instance void [System.Windows.Forms]System.Windows.Forms.Form::Dispose(bool)
          ret
    }
    .method private hidebysig instance void InitializeComponent() cil managed
    {
      
      .maxstack  4
        ldarg.0
        ldc.i4.6
        ldc.i4.s   14
        newobj     instance void [System.Drawing]System.Drawing.Size::.ctor(int32,int32)
        callvirt   instance void [System.Windows.Forms]System.Windows.Forms.Form::set_AutoScaleBaseSize(valuetype [System.Drawing]System.Drawing.Size)
        ldarg.0
        ldc.i4     0x108
        ldc.i4     0xa6
        newobj     instance void [System.Drawing]System.Drawing.Size::.ctor(int32,int32)
        call       instance void [System.Windows.Forms]System.Windows.Forms.Form::set_ClientSize(valuetype [System.Drawing]System.Drawing.Size)
        ldarg.0
        ldstr      "Form1"
        call       instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Name(string)
        ldarg.0
        ldstr      "HelloIL"
        callvirt   instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
        ret
    }
    .method private hidebysig static void Main() cil managed
    {
      .entrypoint
      .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 )
      .maxstack  1
      newobj     instance void HelloIL.Form1::.ctor()
      call       void [System.Windows.Forms]System.Windows.Forms.Application::Run(class [System.Windows.Forms]System.Windows.Forms.Form)
      ret
    }

  }
}

il虚拟汇编指令偶不想注释了...大家可以到
dd6K9s2c8@1M7q4)9K6b7g2)9J5c8W2)9J5c8X3#2K6k6r3&6Q4x3X3g2E0K9h3y4J5L8%4y4G2k6Y4c8Q4x3X3g2U0L8$3#2Q4x3V1k6D9K9h3u0J5j5i4u0&6i4K6u0r3j5$3S2K6i4K6u0r3k6r3g2X3j5i4g2D9N6q4)9J5k6h3q4K6M7q4)9K6c8Y4g2J5L8q4)9K6c8q4)9J5c8X3I4A6j5Y4u0S2M7Y4W2Q4x3V1k6o6d9q4y4Q4x3V1k6U0M7s2u0W2k6W2)9J5c8X3S2@1L8h3I4Q4x3V1k6X3M7X3I4J5k6Y4y4&6M7%4c8W2L8i4u0W2k6X3I4W2j5%4c8A6L8$3&6W2L8h3W2@1L8%4m8U0L8$3c8W2M7$3y4D9j5i4y4K6j5Y4u0X3j5h3I4K6k6g2)9#2k6Y4y4@1L8%4m8A6j5#2)9J5k6h3q4K6M7l9`.`.

在msdn中 il opcode 说明很详细,,大家可以慢慢翻译....

用 ilasm 编译 它成功之后,,就出出现一个win form 窗口程序,,很幼稚,
错误很多,大家请指正哈..
2005-9-9 16:04
0
雪    币: 258
活跃值: (230)
能力值: ( LV12,RANK:770 )
在线值:
发帖
回帖
粉丝
5
其中资源是在vs.net编译的..附件:a2.rar
2005-9-9 16:07
0
雪    币: 124
活跃值: (122)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
6
支持wei哥 学习一下。
2005-9-9 16:21
0
雪    币: 234
活跃值: (370)
能力值: ( LV9,RANK:530 )
在线值:
发帖
回帖
粉丝
7
支持的说!
2005-9-9 16:24
0
雪    币: 58782
活跃值: (21961)
能力值: (RANK:350 )
在线值:
发帖
回帖
粉丝
8
最初由 qiweixue 发布
.net的一个很重要的特性就是跨语言的编程,任何语言都可以相互的调用,(比如C++,可以调用c#写的类),但前提相互调用的语言的约定只能规矩的遵守"CLS(公共语言规范)"的所有特性才可以,否则这中跨语言的编程将死悄悄拉...


........


文章不错,为了以后阅读方便,将2篇主题合并。这样也能提高这帖的人气。
2005-9-9 16:35
0
雪    币: 258
活跃值: (230)
能力值: ( LV12,RANK:770 )
在线值:
发帖
回帖
粉丝
9
学习...
2005-9-9 16:44
0
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
支持wei弟,学习一下!
2005-9-9 17:42
0
雪    币: 603
活跃值: (617)
能力值: ( LV12,RANK:660 )
在线值:
发帖
回帖
粉丝
11
学习学习~  
2005-9-9 17:44
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
呵呵支持一下我们山东的小精英。。。。。。。。
2005-9-9 19:17
0
雪    币: 389
活跃值: (912)
能力值: ( LV9,RANK:770 )
在线值:
发帖
回帖
粉丝
13
支持
2005-9-9 19:18
0
雪    币: 339
活跃值: (1510)
能力值: ( LV13,RANK:970 )
在线值:
发帖
回帖
粉丝
14
老7越来越猛烈了。

.net的IL早就出来了,不过用心研究的人不多阿。以后可以顺便研究反编译或者花指令之类。哈哈
2005-9-9 19:34
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
是的。希望小7越走越远。。。别象俺一样为了吃饭而奔波。。。。
2005-9-9 19:40
0
雪    币: 61
活跃值: (160)
能力值: ( LV9,RANK:170 )
在线值:
发帖
回帖
粉丝
16
支持NIA
2005-9-9 20:50
0
雪    币: 204
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
17
支持校友!!
2005-9-10 09:20
0
雪    币: 212
活跃值: (70)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
18
看不懂 但是支持7哥!!!!
2005-9-10 22:07
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
19
好东西,感谢分享
2005-9-11 08:05
0
游客
登录 | 注册 方可回帖
返回