1yaml2obj
2========
3
4yaml2obj takes a YAML description of an object file and converts it to a binary
5file.
6
7    $ yaml2obj input-file
8
9.. program:: yaml2obj
10
11Outputs the binary to stdout.
12
13COFF Syntax
14-----------
15
16Here's a sample COFF file.
17
18.. code-block:: yaml
19
20  header:
21    Machine: IMAGE_FILE_MACHINE_I386 # (0x14C)
22
23  sections:
24    - Name: .text
25      Characteristics: [ IMAGE_SCN_CNT_CODE
26                       , IMAGE_SCN_ALIGN_16BYTES
27                       , IMAGE_SCN_MEM_EXECUTE
28                       , IMAGE_SCN_MEM_READ
29                       ] # 0x60500020
30      SectionData:
31        "\x83\xEC\x0C\xC7\x44\x24\x08\x00\x00\x00\x00\xC7\x04\x24\x00\x00\x00\x00\xE8\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x8B\x44\x24\x08\x83\xC4\x0C\xC3" # |....D$.......$...............D$.....|
32
33  symbols:
34    - Name: .text
35      Value: 0
36      SectionNumber: 1
37      SimpleType: IMAGE_SYM_TYPE_NULL # (0)
38      ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
39      StorageClass: IMAGE_SYM_CLASS_STATIC # (3)
40      NumberOfAuxSymbols: 1
41      AuxiliaryData:
42        "\x24\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00" # |$.................|
43
44    - Name: _main
45      Value: 0
46      SectionNumber: 1
47      SimpleType: IMAGE_SYM_TYPE_NULL # (0)
48      ComplexType: IMAGE_SYM_DTYPE_NULL # (0)
49      StorageClass: IMAGE_SYM_CLASS_EXTERNAL # (2)
50
51Here's a simplified Kwalify_ schema with an extension to allow alternate types.
52
53.. _Kwalify: http://www.kuwata-lab.com/kwalify/ruby/users-guide.html
54
55.. code-block:: yaml
56
57  type: map
58    mapping:
59      header:
60        type: map
61        mapping:
62          Machine: [ {type: str, enum:
63                                 [ IMAGE_FILE_MACHINE_UNKNOWN
64                                 , IMAGE_FILE_MACHINE_AM33
65                                 , IMAGE_FILE_MACHINE_AMD64
66                                 , IMAGE_FILE_MACHINE_ARM
67                                 , IMAGE_FILE_MACHINE_ARMNT
68                                 , IMAGE_FILE_MACHINE_ARM64
69                                 , IMAGE_FILE_MACHINE_EBC
70                                 , IMAGE_FILE_MACHINE_I386
71                                 , IMAGE_FILE_MACHINE_IA64
72                                 , IMAGE_FILE_MACHINE_M32R
73                                 , IMAGE_FILE_MACHINE_MIPS16
74                                 , IMAGE_FILE_MACHINE_MIPSFPU
75                                 , IMAGE_FILE_MACHINE_MIPSFPU16
76                                 , IMAGE_FILE_MACHINE_POWERPC
77                                 , IMAGE_FILE_MACHINE_POWERPCFP
78                                 , IMAGE_FILE_MACHINE_R4000
79                                 , IMAGE_FILE_MACHINE_SH3
80                                 , IMAGE_FILE_MACHINE_SH3DSP
81                                 , IMAGE_FILE_MACHINE_SH4
82                                 , IMAGE_FILE_MACHINE_SH5
83                                 , IMAGE_FILE_MACHINE_THUMB
84                                 , IMAGE_FILE_MACHINE_WCEMIPSV2
85                                 ]}
86                   , {type: int}
87                   ]
88          Characteristics:
89            - type: seq
90              sequence:
91                - type: str
92                  enum: [ IMAGE_FILE_RELOCS_STRIPPED
93                        , IMAGE_FILE_EXECUTABLE_IMAGE
94                        , IMAGE_FILE_LINE_NUMS_STRIPPED
95                        , IMAGE_FILE_LOCAL_SYMS_STRIPPED
96                        , IMAGE_FILE_AGGRESSIVE_WS_TRIM
97                        , IMAGE_FILE_LARGE_ADDRESS_AWARE
98                        , IMAGE_FILE_BYTES_REVERSED_LO
99                        , IMAGE_FILE_32BIT_MACHINE
100                        , IMAGE_FILE_DEBUG_STRIPPED
101                        , IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP
102                        , IMAGE_FILE_NET_RUN_FROM_SWAP
103                        , IMAGE_FILE_SYSTEM
104                        , IMAGE_FILE_DLL
105                        , IMAGE_FILE_UP_SYSTEM_ONLY
106                        , IMAGE_FILE_BYTES_REVERSED_HI
107                        ]
108            - type: int
109      sections:
110        type: seq
111        sequence:
112          - type: map
113            mapping:
114              Name: {type: str}
115              Characteristics:
116                - type: seq
117                  sequence:
118                    - type: str
119                      enum: [ IMAGE_SCN_TYPE_NO_PAD
120                            , IMAGE_SCN_CNT_CODE
121                            , IMAGE_SCN_CNT_INITIALIZED_DATA
122                            , IMAGE_SCN_CNT_UNINITIALIZED_DATA
123                            , IMAGE_SCN_LNK_OTHER
124                            , IMAGE_SCN_LNK_INFO
125                            , IMAGE_SCN_LNK_REMOVE
126                            , IMAGE_SCN_LNK_COMDAT
127                            , IMAGE_SCN_GPREL
128                            , IMAGE_SCN_MEM_PURGEABLE
129                            , IMAGE_SCN_MEM_16BIT
130                            , IMAGE_SCN_MEM_LOCKED
131                            , IMAGE_SCN_MEM_PRELOAD
132                            , IMAGE_SCN_ALIGN_1BYTES
133                            , IMAGE_SCN_ALIGN_2BYTES
134                            , IMAGE_SCN_ALIGN_4BYTES
135                            , IMAGE_SCN_ALIGN_8BYTES
136                            , IMAGE_SCN_ALIGN_16BYTES
137                            , IMAGE_SCN_ALIGN_32BYTES
138                            , IMAGE_SCN_ALIGN_64BYTES
139                            , IMAGE_SCN_ALIGN_128BYTES
140                            , IMAGE_SCN_ALIGN_256BYTES
141                            , IMAGE_SCN_ALIGN_512BYTES
142                            , IMAGE_SCN_ALIGN_1024BYTES
143                            , IMAGE_SCN_ALIGN_2048BYTES
144                            , IMAGE_SCN_ALIGN_4096BYTES
145                            , IMAGE_SCN_ALIGN_8192BYTES
146                            , IMAGE_SCN_LNK_NRELOC_OVFL
147                            , IMAGE_SCN_MEM_DISCARDABLE
148                            , IMAGE_SCN_MEM_NOT_CACHED
149                            , IMAGE_SCN_MEM_NOT_PAGED
150                            , IMAGE_SCN_MEM_SHARED
151                            , IMAGE_SCN_MEM_EXECUTE
152                            , IMAGE_SCN_MEM_READ
153                            , IMAGE_SCN_MEM_WRITE
154                            ]
155                - type: int
156              SectionData: {type: str}
157      symbols:
158        type: seq
159        sequence:
160          - type: map
161            mapping:
162              Name: {type: str}
163              Value: {type: int}
164              SectionNumber: {type: int}
165              SimpleType: [ {type: str, enum: [ IMAGE_SYM_TYPE_NULL
166                                              , IMAGE_SYM_TYPE_VOID
167                                              , IMAGE_SYM_TYPE_CHAR
168                                              , IMAGE_SYM_TYPE_SHORT
169                                              , IMAGE_SYM_TYPE_INT
170                                              , IMAGE_SYM_TYPE_LONG
171                                              , IMAGE_SYM_TYPE_FLOAT
172                                              , IMAGE_SYM_TYPE_DOUBLE
173                                              , IMAGE_SYM_TYPE_STRUCT
174                                              , IMAGE_SYM_TYPE_UNION
175                                              , IMAGE_SYM_TYPE_ENUM
176                                              , IMAGE_SYM_TYPE_MOE
177                                              , IMAGE_SYM_TYPE_BYTE
178                                              , IMAGE_SYM_TYPE_WORD
179                                              , IMAGE_SYM_TYPE_UINT
180                                              , IMAGE_SYM_TYPE_DWORD
181                                              ]}
182                          , {type: int}
183                          ]
184              ComplexType: [ {type: str, enum: [ IMAGE_SYM_DTYPE_NULL
185                                               , IMAGE_SYM_DTYPE_POINTER
186                                               , IMAGE_SYM_DTYPE_FUNCTION
187                                               , IMAGE_SYM_DTYPE_ARRAY
188                                               ]}
189                           , {type: int}
190                           ]
191              StorageClass: [ {type: str, enum:
192                                          [ IMAGE_SYM_CLASS_END_OF_FUNCTION
193                                          , IMAGE_SYM_CLASS_NULL
194                                          , IMAGE_SYM_CLASS_AUTOMATIC
195                                          , IMAGE_SYM_CLASS_EXTERNAL
196                                          , IMAGE_SYM_CLASS_STATIC
197                                          , IMAGE_SYM_CLASS_REGISTER
198                                          , IMAGE_SYM_CLASS_EXTERNAL_DEF
199                                          , IMAGE_SYM_CLASS_LABEL
200                                          , IMAGE_SYM_CLASS_UNDEFINED_LABEL
201                                          , IMAGE_SYM_CLASS_MEMBER_OF_STRUCT
202                                          , IMAGE_SYM_CLASS_ARGUMENT
203                                          , IMAGE_SYM_CLASS_STRUCT_TAG
204                                          , IMAGE_SYM_CLASS_MEMBER_OF_UNION
205                                          , IMAGE_SYM_CLASS_UNION_TAG
206                                          , IMAGE_SYM_CLASS_TYPE_DEFINITION
207                                          , IMAGE_SYM_CLASS_UNDEFINED_STATIC
208                                          , IMAGE_SYM_CLASS_ENUM_TAG
209                                          , IMAGE_SYM_CLASS_MEMBER_OF_ENUM
210                                          , IMAGE_SYM_CLASS_REGISTER_PARAM
211                                          , IMAGE_SYM_CLASS_BIT_FIELD
212                                          , IMAGE_SYM_CLASS_BLOCK
213                                          , IMAGE_SYM_CLASS_FUNCTION
214                                          , IMAGE_SYM_CLASS_END_OF_STRUCT
215                                          , IMAGE_SYM_CLASS_FILE
216                                          , IMAGE_SYM_CLASS_SECTION
217                                          , IMAGE_SYM_CLASS_WEAK_EXTERNAL
218                                          , IMAGE_SYM_CLASS_CLR_TOKEN
219                                          ]}
220                            , {type: int}
221                            ]
222