BaSs_HaXoR

Dis/Assembling CIL Code (w/ Mono tools)

Jan 28th, 2017
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 5.51 KB | None | 0 0
  1. /*
  2. |############################################################################################# !? # x # x # y ## y # z # z # ?! #############################################################################################|
  3. |#                                                                                               SOURCE: http://adf.ly/1iqzcc                                                                                               #|
  4. |############################################################################################# !? # x # x # y ## y # z # z # ?! #############################################################################################|
  5. |#                                                                                                            ##                                                                                                            #|
  6. |#                Dis/Assembling CIL Code                              Dis/Assembling CIL Code                ##             Dis/Assembling CIL Code                              Dis/Assembling CIL Code                   #|
  7. |#                                                                                                            ##                                                                                                            #|
  8. |############################################################################################# !? # x # x # y ## y # z # z # ?! #############################################################################################|
  9.  
  10. | ---------------------             ---------------------             ---------------------             ---------------------             --------------------- |
  11. [IL Code]
  12.  
  13. .NET compilers like mcs or mbas do not compile to native code, but to the Common Intermediate Language (CIL). IL code looks like this:
  14. | ---------------------             ---------------------             ---------------------             ---------------------             --------------------- |
  15.  
  16. */// hello world dissassembled with monodis
  17.  
  18. .assembly extern mscorlib
  19. {
  20.   .ver 0:0:0:0
  21. }
  22. .assembly 'hello'
  23. {
  24.   .hash algorithm 0x00008004
  25.   .ver  0:0:0:0
  26. }
  27.   .class private auto ansi beforefieldinit Hello
  28.         extends [mscorlib]System.Object
  29.   {
  30.  
  31.     // method line 1
  32.     .method public hidebysig  specialname  rtspecialname
  33.            instance default void .ctor()  cil managed
  34.     {
  35.         // Method begins at RVA 0x20ec
  36.         // Code size 7 (0x7)
  37.         .maxstack 8
  38.         IL_0000: ldarg.0
  39.         IL_0001: call instance void valuetype [corlib]System.Object::.ctor()
  40.         IL_0006: ret
  41.     } // end of method instance default void .ctor()
  42.  
  43.     // method line 2
  44.     .method public static
  45.            default void Main()  cil managed
  46.     {
  47.         // Method begins at RVA 0x20f4
  48.         .entrypoint
  49.         // Code size 11 (0xb)
  50.         .maxstack 8
  51.         IL_0000: ldstr "Hello Mono World!"
  52.         IL_0005: call void class [corlib]System.Console::WriteLine(string)
  53.         IL_000a: ret
  54.     } // end of method default void Main()
  55.  
  56.   } // end of type Hello
  57. There are two Mono tools for using IL code:
  58.  
  59. ilasm
  60. The Mono Assembler can be given disassembled text, and it creates an assembly file. This is very important, because many compilers don’t create the assembly themselves, and depend on this tool. Of course it can be also seen as a form of a compiler.
  61.  
  62. ############################################################################################# !? # x # x # y # y # z # z # ?! #############################################################################################
  63. monodis
  64. The Mono Disassembler extracts code like shown above from an assembly.
  65.  
  66. ############################################################################################# !? # x # x # y # y # z # z # ?! #############################################################################################
  67. The Mono Disassembler
  68. The monodis program is used to dump the contents of an ECMA CIL image. You can execute it by typing:
  69.  
  70. monodis FILE.exe
  71. The following options are supported:
  72.  
  73. --output=FILENAME
  74. Write output into FILENAME.
  75.  
  76. --mscorlib
  77. For non-corlib assemblies, use “mscorlib” as the assembly name. This is useful for round-tripping the IL with ilasm.
  78.  
  79. --assembly
  80. Dumps the contents of the assembly table
  81.  
  82. --assemblyref
  83. Dumps the contents of the assemblyref table
  84.  
  85. --classlayout
  86. Dumps the contents of the classlayout table
  87.  
  88. --constant
  89. Dumps the contents of the constant table
  90.  
  91. --event
  92. Dumps the contents of the event table
  93.  
  94. --exported
  95. Dumps the contents of the ExportedTypes table
  96.  
  97. --fields
  98. Dumps the contents of the fields table
  99.  
  100. --file
  101. Dumps the contents of the file table
  102.  
  103. --interface
  104. Dumps the contents of the interface table
  105.  
  106. --manifest
  107. Dumps the contents of the manifest table.
  108.  
  109. --memberref
  110. Dumps the contents of the memberref table
  111.  
  112. --method
  113. Dumps the contents of the method table
  114.  
  115. --methodsem
  116. Dumps the contents of the methodsem table
  117.  
  118. --module
  119. Dumps the contents of the module table
  120.  
  121. --moduleref
  122. Dumps the contents of the moduleref table
  123.  
  124. --mresources
  125. Dumps embedded managed resources
  126.  
  127. --param
  128. Dumps the contents of the param table
  129.  
  130. --property
  131. Dumps the contents of the property table
  132.  
  133. --propertymap
  134. Dumps the contents of the propertymap table
  135.  
  136. --typedef
  137. Dumps the contents of the typedef table
  138.  
  139. --typeref
  140. Dumps the contents of the typeref table If no flags are specified the program dumps the content of the image in a format that can be used to rountrip the code.
Add Comment
Please, Sign In to add comment