ilMetaWriter.ml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. (*
  2. * This file is part of ilLib
  3. * Copyright (c)2004-2013 Haxe Foundation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  18. *)
  19. open PeData;;
  20. open PeReader;;
  21. open IlMeta;;
  22. open IO;;
  23. (* encoding helpers *)
  24. let int_of_type_def_vis = function
  25. (* visibility flags - mask 0x7 *)
  26. | VPrivate -> 0x0 (* 0x0 *)
  27. | VPublic -> 0x1 (* 0x1 *)
  28. | VNestedPublic -> 0x2 (* 0x2 *)
  29. | VNestedPrivate -> 0x3 (* 0x3 *)
  30. | VNestedFamily -> 0x4 (* 0x4 *)
  31. | VNestedAssembly -> 0x5 (* 0x5 *)
  32. | VNestedFamAndAssem -> 0x6 (* 0x6 *)
  33. | VNestedFamOrAssem -> 0x7 (* 0x7 *)
  34. let int_of_type_def_layout = function
  35. (* layout flags - mask 0x18 *)
  36. | LAuto -> 0x0 (* 0x0 *)
  37. | LSequential -> 0x8 (* 0x8 *)
  38. | LExplicit -> 0x10 (* 0x10 *)
  39. let int_of_type_def_semantics props = List.fold_left (fun acc prop ->
  40. (match prop with
  41. (* semantics flags - mask 0x5A0 *)
  42. | SInterface -> 0x20 (* 0x20 *)
  43. | SAbstract -> 0x80 (* 0x80 *)
  44. | SSealed -> 0x100 (* 0x100 *)
  45. | SSpecialName -> 0x400 (* 0x400 *)
  46. ) lor acc
  47. ) 0 props
  48. let int_of_type_def_impl props = List.fold_left (fun acc prop ->
  49. (match prop with
  50. (* type implementation flags - mask 0x103000 *)
  51. | IImport -> 0x1000 (* 0x1000 *)
  52. | ISerializable -> 0x2000 (* 0x2000 *)
  53. | IBeforeFieldInit -> 0x00100000 (* 0x00100000 *)
  54. ) lor acc
  55. ) 0 props
  56. let int_of_type_def_string = function
  57. (* string formatting flags - mask 0x00030000 *)
  58. | SAnsi -> 0x0 (* 0x0 *)
  59. | SUnicode -> 0x00010000 (* 0x00010000 *)
  60. | SAutoChar -> 0x00020000 (* 0x00020000 *)
  61. let int_of_type_def_flags f =
  62. int_of_type_def_vis f.tdf_vis
  63. logor
  64. int_of_type_def_layout f.tdf_layout
  65. logor
  66. int_of_type_def_semantics f.tdf_semantics
  67. logor
  68. int_of_type_def_impl f.tdf_impl
  69. logor
  70. int_of_type_def_string f.tdf_string