You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
13 KiB

  1. // Copyright (c) 2014 Daniel Grunwald
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4. // software and associated documentation files (the "Software"), to deal in the Software
  5. // without restriction, including without limitation the rights to use, copy, modify, merge,
  6. // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7. // to whom the Software is furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in all copies or
  10. // substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  13. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  14. // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  15. // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  16. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  17. // DEALINGS IN THE SOFTWARE.
  18. using System;
  19. namespace ICSharpCode.Decompiler.IL
  20. {
  21. enum ILOpCode : ushort
  22. {
  23. Nop = 0x00,
  24. Break = 0x01,
  25. Ldarg_0 = 0x02,
  26. Ldarg_1 = 0x03,
  27. Ldarg_2 = 0x04,
  28. Ldarg_3 = 0x05,
  29. Ldloc_0 = 0x06,
  30. Ldloc_1 = 0x07,
  31. Ldloc_2 = 0x08,
  32. Ldloc_3 = 0x09,
  33. Stloc_0 = 0x0a,
  34. Stloc_1 = 0x0b,
  35. Stloc_2 = 0x0c,
  36. Stloc_3 = 0x0d,
  37. Ldarg_S = 0x0e,
  38. Ldarga_S = 0x0f,
  39. Starg_S = 0x10,
  40. Ldloc_S = 0x11,
  41. Ldloca_S = 0x12,
  42. Stloc_S = 0x13,
  43. Ldnull = 0x14,
  44. Ldc_I4_M1 = 0x15,
  45. Ldc_I4_0 = 0x16,
  46. Ldc_I4_1 = 0x17,
  47. Ldc_I4_2 = 0x18,
  48. Ldc_I4_3 = 0x19,
  49. Ldc_I4_4 = 0x1a,
  50. Ldc_I4_5 = 0x1b,
  51. Ldc_I4_6 = 0x1c,
  52. Ldc_I4_7 = 0x1d,
  53. Ldc_I4_8 = 0x1e,
  54. Ldc_I4_S = 0x1f,
  55. Ldc_I4 = 0x20,
  56. Ldc_I8 = 0x21,
  57. Ldc_R4 = 0x22,
  58. Ldc_R8 = 0x23,
  59. Dup = 0x25,
  60. Pop = 0x26,
  61. Jmp = 0x27,
  62. Call = 0x28,
  63. Calli = 0x29,
  64. Ret = 0x2a,
  65. Br_S = 0x2b,
  66. Brfalse_S = 0x2c,
  67. Brtrue_S = 0x2d,
  68. Beq_S = 0x2e,
  69. Bge_S = 0x2f,
  70. Bgt_S = 0x30,
  71. Ble_S = 0x31,
  72. Blt_S = 0x32,
  73. Bne_Un_S = 0x33,
  74. Bge_Un_S = 0x34,
  75. Bgt_Un_S = 0x35,
  76. Ble_Un_S = 0x36,
  77. Blt_Un_S = 0x37,
  78. Br = 0x38,
  79. Brfalse = 0x39,
  80. Brtrue = 0x3a,
  81. Beq = 0x3b,
  82. Bge = 0x3c,
  83. Bgt = 0x3d,
  84. Ble = 0x3e,
  85. Blt = 0x3f,
  86. Bne_Un = 0x40,
  87. Bge_Un = 0x41,
  88. Bgt_Un = 0x42,
  89. Ble_Un = 0x43,
  90. Blt_Un = 0x44,
  91. Switch = 0x45,
  92. Ldind_I1 = 0x46,
  93. Ldind_U1 = 0x47,
  94. Ldind_I2 = 0x48,
  95. Ldind_U2 = 0x49,
  96. Ldind_I4 = 0x4a,
  97. Ldind_U4 = 0x4b,
  98. Ldind_I8 = 0x4c,
  99. Ldind_I = 0x4d,
  100. Ldind_R4 = 0x4e,
  101. Ldind_R8 = 0x4f,
  102. Ldind_Ref = 0x50,
  103. Stind_Ref = 0x51,
  104. Stind_I1 = 0x52,
  105. Stind_I2 = 0x53,
  106. Stind_I4 = 0x54,
  107. Stind_I8 = 0x55,
  108. Stind_R4 = 0x56,
  109. Stind_R8 = 0x57,
  110. Add = 0x58,
  111. Sub = 0x59,
  112. Mul = 0x5a,
  113. Div = 0x5b,
  114. Div_Un = 0x5c,
  115. Rem = 0x5d,
  116. Rem_Un = 0x5e,
  117. And = 0x5f,
  118. Or = 0x60,
  119. Xor = 0x61,
  120. Shl = 0x62,
  121. Shr = 0x63,
  122. Shr_Un = 0x64,
  123. Neg = 0x65,
  124. Not = 0x66,
  125. Conv_I1 = 0x67,
  126. Conv_I2 = 0x68,
  127. Conv_I4 = 0x69,
  128. Conv_I8 = 0x6a,
  129. Conv_R4 = 0x6b,
  130. Conv_R8 = 0x6c,
  131. Conv_U4 = 0x6d,
  132. Conv_U8 = 0x6e,
  133. Callvirt = 0x6f,
  134. Cpobj = 0x70,
  135. Ldobj = 0x71,
  136. Ldstr = 0x72,
  137. Newobj = 0x73,
  138. Castclass = 0x74,
  139. Isinst = 0x75,
  140. Conv_R_Un = 0x76,
  141. Unbox = 0x79,
  142. Throw = 0x7a,
  143. Ldfld = 0x7b,
  144. Ldflda = 0x7c,
  145. Stfld = 0x7d,
  146. Ldsfld = 0x7e,
  147. Ldsflda = 0x7f,
  148. Stsfld = 0x80,
  149. Stobj = 0x81,
  150. Conv_Ovf_I1_Un = 0x82,
  151. Conv_Ovf_I2_Un = 0x83,
  152. Conv_Ovf_I4_Un = 0x84,
  153. Conv_Ovf_I8_Un = 0x85,
  154. Conv_Ovf_U1_Un = 0x86,
  155. Conv_Ovf_U2_Un = 0x87,
  156. Conv_Ovf_U4_Un = 0x88,
  157. Conv_Ovf_U8_Un = 0x89,
  158. Conv_Ovf_I_Un = 0x8a,
  159. Conv_Ovf_U_Un = 0x8b,
  160. Box = 0x8c,
  161. Newarr = 0x8d,
  162. Ldlen = 0x8e,
  163. Ldelema = 0x8f,
  164. Ldelem_I1 = 0x90,
  165. Ldelem_U1 = 0x91,
  166. Ldelem_I2 = 0x92,
  167. Ldelem_U2 = 0x93,
  168. Ldelem_I4 = 0x94,
  169. Ldelem_U4 = 0x95,
  170. Ldelem_I8 = 0x96,
  171. Ldelem_I = 0x97,
  172. Ldelem_R4 = 0x98,
  173. Ldelem_R8 = 0x99,
  174. Ldelem_Ref = 0x9a,
  175. Stelem_I = 0x9b,
  176. Stelem_I1 = 0x9c,
  177. Stelem_I2 = 0x9d,
  178. Stelem_I4 = 0x9e,
  179. Stelem_I8 = 0x9f,
  180. Stelem_R4 = 0xa0,
  181. Stelem_R8 = 0xa1,
  182. Stelem_Ref = 0xa2,
  183. Ldelem = 0xa3,
  184. Stelem = 0xa4,
  185. Unbox_Any = 0xa5,
  186. Conv_Ovf_I1 = 0xb3,
  187. Conv_Ovf_U1 = 0xb4,
  188. Conv_Ovf_I2 = 0xb5,
  189. Conv_Ovf_U2 = 0xb6,
  190. Conv_Ovf_I4 = 0xb7,
  191. Conv_Ovf_U4 = 0xb8,
  192. Conv_Ovf_I8 = 0xb9,
  193. Conv_Ovf_U8 = 0xba,
  194. Refanyval = 0xc2,
  195. Ckfinite = 0xc3,
  196. Mkrefany = 0xc6,
  197. Ldtoken = 0xd0,
  198. Conv_U2 = 0xd1,
  199. Conv_U1 = 0xd2,
  200. Conv_I = 0xd3,
  201. Conv_Ovf_I = 0xd4,
  202. Conv_Ovf_U = 0xd5,
  203. Add_Ovf = 0xd6,
  204. Add_Ovf_Un = 0xd7,
  205. Mul_Ovf = 0xd8,
  206. Mul_Ovf_Un = 0xd9,
  207. Sub_Ovf = 0xda,
  208. Sub_Ovf_Un = 0xdb,
  209. Endfinally = 0xdc,
  210. Leave = 0xdd,
  211. Leave_S = 0xde,
  212. Stind_I = 0xdf,
  213. Conv_U = 0xe0,
  214. Prefix7 = 0xf8,
  215. Prefix6 = 0xf9,
  216. Prefix5 = 0xfa,
  217. Prefix4 = 0xfb,
  218. Prefix3 = 0xfc,
  219. Prefix2 = 0xfd,
  220. Prefix1 = 0xfe,
  221. Prefixref = 0xff,
  222. Arglist = 0x100,
  223. Ceq = 0x101,
  224. Cgt = 0x102,
  225. Cgt_Un = 0x103,
  226. Clt = 0x104,
  227. Clt_Un = 0x105,
  228. Ldftn = 0x106,
  229. Ldvirtftn = 0x107,
  230. Ldarg = 0x109,
  231. Ldarga = 0x10a,
  232. Starg = 0x10b,
  233. Ldloc = 0x10c,
  234. Ldloca = 0x10d,
  235. Stloc = 0x10e,
  236. Localloc = 0x10f,
  237. Endfilter = 0x111,
  238. Unaligned = 0x112,
  239. Volatile = 0x113,
  240. Tailcall = 0x114,
  241. Initobj = 0x115,
  242. Constrained = 0x116,
  243. Cpblk = 0x117,
  244. Initblk = 0x118,
  245. Rethrow = 0x11a,
  246. Sizeof = 0x11c,
  247. Refanytype = 0x11d,
  248. Readonly = 0x11e,
  249. }
  250. /*
  251. static class ILOpCodeExtensions
  252. {
  253. // We use a byte array instead of an enum array because it can be initialized more efficiently
  254. static readonly byte[] operandTypes = { (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.ShortVariable, (byte)OperandType.ShortVariable, (byte)OperandType.ShortVariable, (byte)OperandType.ShortVariable, (byte)OperandType.ShortVariable, (byte)OperandType.ShortVariable, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.ShortI, (byte)OperandType.I, (byte)OperandType.I8, (byte)OperandType.ShortR, (byte)OperandType.R, (byte)OperandType.BrTarget, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.Method, (byte)OperandType.Method, (byte)OperandType.Sig, (byte)OperandType.None, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.ShortBrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.Switch, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.Method, (byte)OperandType.Type, (byte)OperandType.Type, (byte)OperandType.String, (byte)OperandType.Method, (byte)OperandType.Type, (byte)OperandType.Type, (byte)OperandType.None, (byte)OperandType.BrTarget, (byte)OperandType.BrTarget, (byte)OperandType.Type, (byte)OperandType.None, (byte)OperandType.Field, (byte)OperandType.Field, (byte)OperandType.Field, (byte)OperandType.Field, (byte)OperandType.Field, (byte)OperandType.Field, (byte)OperandType.Type, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.Type, (byte)OperandType.Type, (byte)OperandType.None, (byte)OperandType.Type, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)OperandType.None, (byte)Operand
  255. public static OperandType GetOperandType(this ILOpCode opCode)
  256. {
  257. return (OperandType)operandTypes[(ushort)opCode];
  258. }
  259. }
  260. */
  261. }