wim_parser 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 54b86032f25b6f4c9bc0a53f6e1f0f179a036ef38728711d631cebf34927e1d0
4
+ data.tar.gz: 600abfe4ee86a45018ade650bdb5fe4d3681bb54130da577bc04aae6bfdda324
5
+ SHA512:
6
+ metadata.gz: 1e25c49342ed1172329b2d977dbfa0809e196beb888c0b22366fd0abe9784f306f05fad627b31fcc0681d32665838438ecb9a3362121777b1446c3b24ab7aa7e
7
+ data.tar.gz: 4aea76f3599315219dd88695c7457e81cb977d4c45726778bf66fa6825af6381f072991eba6a205bea9e6f35f8925ee6cf3e0c5bb70a7195d9ae7f63d4344fdf
data/.codeclimate.yml ADDED
@@ -0,0 +1,16 @@
1
+ prepare:
2
+ fetch:
3
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_base.yml
4
+ path: ".rubocop_base.yml"
5
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
6
+ path: ".rubocop_cc_base.yml"
7
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
8
+ path: styles/base.yml
9
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
10
+ path: styles/cc_base.yml
11
+ plugins:
12
+ rubocop:
13
+ enabled: true
14
+ config: ".rubocop_cc.yml"
15
+ channel: rubocop-0-82
16
+ version: '2'
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_gem:
2
+ manageiq-style: ".rubocop_base.yml"
3
+ inherit_from:
4
+ - ".rubocop_local.yml"
data/.rubocop_cc.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from:
2
+ - ".rubocop_base.yml"
3
+ - ".rubocop_cc_base.yml"
4
+ - ".rubocop_local.yml"
File without changes
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at fryguy9@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wim_parser.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # WimParser
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/wim_parser.svg)](http://badge.fury.io/rb/wim_parser)
4
+ [![Build Status](https://travis-ci.com/ManageIQ/wim_parser.svg)](https://travis-ci.com/ManageIQ/wim_parser)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/85bd8d94d5799a9fe2f4/maintainability)](https://codeclimate.com/github/ManageIQ/wim_parser/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/85bd8d94d5799a9fe2f4/test_coverage)](https://codeclimate.com/github/ManageIQ/wim_parser/test_coverage)
7
+
8
+ Parser for the Windows Image Format (WIM)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'wim_parser'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install wim_parser
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ p = WimParser.new("path/to/file.wim")
30
+
31
+ p.header
32
+ # => {
33
+ # "image_tag" => "MSWIM\0\0\0",
34
+ # "size" => 208,
35
+ # "version" => 68864,
36
+ # "flags" => 0x00020082,
37
+ # "compression_size" => 32768,
38
+ # "wim_guid" => "N\x91-\xF7a'\x8D@\x9A0\xC5\xF1~\xD7X\x16", # real GUID is pending adding support for winnt.h GUID structure parsing
39
+ # "part_number" => 1,
40
+ # "total_parts" => 1,
41
+ # "image_count" => 2,
42
+ # "offset_table_size" => 150,
43
+ # "offset_table_flags" => 0x02000000,
44
+ # "offset_table_offset" => 2254,
45
+ # "offset_table_original_size" => 150,
46
+ # "xml_data_size" => 1644,
47
+ # "xml_data_flags" => 0x02000000,
48
+ # "xml_data_offset" => 2404,
49
+ # "xml_data_original_size" => 1644,
50
+ # "boot_metadata_size" => 0,
51
+ # "boot_metadata_flags" => 0x00000000,
52
+ # "boot_metadata_offset" => 0,
53
+ # "boot_metadata_original_size" => 0,
54
+ # "boot_index" => 0,
55
+ # "integrity_size" => 0,
56
+ # "integrity_flags" => 0x00000000,
57
+ # "integrity_offset" => 0,
58
+ # "integrity_original_size" => 0,
59
+ # "unused" => ("\0" * 60),
60
+ # }
61
+
62
+ p.xml_data
63
+ # => {
64
+ # "total_bytes" => 2404,
65
+ # "images" => [
66
+ # {
67
+ # "index" => 1,
68
+ # "name" => "Nothing",
69
+ # "description" => "Empty Windows Disk",
70
+ # "dir_count" => 3,
71
+ # "file_count" => 0,
72
+ # "total_bytes" => 0,
73
+ # "hard_link_bytes" => 0,
74
+ # "creation_time" => "2012-09-01 04:05:53 UTC",
75
+ # "last_modification_time" => "2012-09-01 04:05:53 UTC",
76
+ # },
77
+ # {
78
+ # "index" => 2,
79
+ # "name" => "appended image",
80
+ # "description" => "some files added",
81
+ # "dir_count" => 5,
82
+ # "file_count" => 1,
83
+ # "total_bytes" => 4,
84
+ # "hard_link_bytes" => 0,
85
+ # "creation_time" => "2012-09-01 04:08:59 UTC",
86
+ # "last_modification_time" => "2012-09-01 04:08:59 UTC",
87
+ # },
88
+ # ]
89
+ # }
90
+
91
+ ```
92
+
93
+ ## Development
94
+
95
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96
+
97
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
98
+
99
+ ## Contributing
100
+
101
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ManageIQ/wim_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ManageIQ/wim_parser/blob/master/CODE_OF_CONDUCT.md).
102
+
103
+ ## License
104
+
105
+ The gem is available as open source under the terms of the [Apache License 2.0](https://opensource.org/licenses/Apache-2.0).
106
+
107
+ ## Code of Conduct
108
+
109
+ Everyone interacting in the WimParser project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ManageIQ/wim_parser/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wim_parser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/wim_parser.rb ADDED
@@ -0,0 +1,131 @@
1
+ # encoding: US-ASCII
2
+
3
+ require_relative "wim_parser/version"
4
+ require "binary_struct"
5
+
6
+ # Parser for the Windows Image Format (WIM).
7
+ # Information found here:
8
+ # http://www.microsoft.com/en-us/download/details.aspx?id=13096
9
+ # http://technet.microsoft.com/en-us/library/cc749478%28WS.10%29.aspx?ITPID=win7dtp
10
+ # http://www.freepatentsonline.com/y2010/0211943.html
11
+ # http://nunobrito1981.blogspot.com/2010/12/inaccuracy-on-wim-documentation.html
12
+ #
13
+ # TODO: Add support for processing winnt.h GUID structures for wim_guid.
14
+ # http://msdn.microsoft.com/en-us/library/windows/desktop/aa373931%28v=vs.85%29.aspx
15
+ # http://stackoverflow.com/questions/679381/accessing-guid-members-in-c-sharp
16
+ class WimParser
17
+ autoload :Nokogiri, "nokogiri"
18
+
19
+ HEADER_V1_STRUCT = BinaryStruct.new([
20
+ 'a8', 'image_tag', # Signature that identifies the file as a .wim file. Value is set to "MSWIM\0\0".
21
+ 'L', 'size', # Size of the WIM header in bytes.
22
+ 'L', 'version', # The current version of the .wim file. This number will increase if the format of the .wim file changes.
23
+ 'L', 'flags', # Defines the custom flags (listed below).
24
+ 'L', 'compression_size', # Size of the compressed .wim file in bytes.
25
+ 'a16', 'wim_guid', # A unique identifier.
26
+ 'S', 'part_number', # The part number of the current .wim file in a spanned set. This value is 1, unless the data of the .wim file was split into multiple parts (.swm).
27
+ 'S', 'total_parts', # The total number of .wim file parts in a spanned set.
28
+ 'L', 'image_count', # The number of images contained in the .wim file.
29
+ 'L', 'offset_table_size', # The location of the resource lookup table.
30
+ 'L', 'offset_table_flags',
31
+ 'q', 'offset_table_offset',
32
+ 'q', 'offset_table_original_size',
33
+ 'L', 'xml_data_size', # The location of the XML data.
34
+ 'L', 'xml_data_flags',
35
+ 'q', 'xml_data_offset',
36
+ 'q', 'xml_data_original_size',
37
+ 'L', 'boot_metadata_size', # The location of the metadata resource.
38
+ 'L', 'boot_metadata_flags',
39
+ 'q', 'boot_metadata_offset',
40
+ 'q', 'boot_metadata_original_size',
41
+ 'L', 'boot_index', # The index of the bootable image in the .wim file. If this is zero, then there are no bootable images available.
42
+ 'L', 'integrity_size', # The location of integrity table used to verify files.
43
+ 'L', 'integrity_flags',
44
+ 'q', 'integrity_offset',
45
+ 'q', 'integrity_original_size',
46
+ 'a60', 'unused' # A reserved 60 bytes of additional space for future fields.
47
+ ])
48
+ SIZEOF_HEADER_V1_STRUCT = HEADER_V1_STRUCT.size
49
+
50
+ IMAGE_TAG = "MSWIM\0\0\0"
51
+
52
+ # Flags values for the header struct
53
+ FLAG_HEADER_RESERVED = 0x00000001
54
+ FLAG_HEADER_COMPRESSION = 0x00000002 # Resources within the WIM (both file and metadata) are compressed.
55
+ FLAG_HEADER_READONLY = 0x00000004 # The contents of this WIM should not be changed.
56
+ FLAG_HEADER_SPANNED = 0x00000008 # Resource data specified by the images within this WIM may be contained in another WIM.
57
+ FLAG_HEADER_RESOURCE_ONLY = 0x00000010 # This WIM contains file resources only. It does not contain any file metadata.
58
+ FLAG_HEADER_METADATA_ONLY = 0x00000020 # This WIM contains file metadata only.
59
+ FLAG_HEADER_WRITE_IN_PROGRESS = 0x00000040 # Limits one writer to the WIM file when opened with the WIM_FLAG_SHARE_WRITE mode, This flag is primarily used in the Windows Deployment Services (WDS) scenario.
60
+ FLAG_HEADER_RP_FIX = 0x00000080 # Reparse point fixup
61
+ # Additionally, if the FLAG_HEADER_COMPRESSION flag is set, the following flags are valid:
62
+ FLAG_HEADER_COMPRESS_RESERVED = 0x00010000
63
+ FLAG_HEADER_COMPRESS_XPRESS = 0x00020000 # Resources within the wim are compressed using XPRESS compression.
64
+ FLAG_HEADER_COMPRESS_LZX = 0x00040000 # Resources within the wim are compressed using LZX compression.
65
+
66
+ attr_reader :filename
67
+
68
+ def initialize(filename)
69
+ @filename = filename
70
+ end
71
+
72
+ def header
73
+ data = File.open(filename, "rb") do |f|
74
+ f.read(SIZEOF_HEADER_V1_STRUCT)
75
+ end
76
+ ret = HEADER_V1_STRUCT.decode(data)
77
+ raise "#{filename} is not a WIM file" if ret["image_tag"] != IMAGE_TAG
78
+ ret
79
+ end
80
+
81
+ def xml_data
82
+ header_data = header
83
+
84
+ xml = File.open(filename, "rb") do |f|
85
+ f.seek(header_data["xml_data_offset"])
86
+ f.read(header_data["xml_data_size"])
87
+ end
88
+ xml.force_encoding("UTF-16")
89
+
90
+ xml = Nokogiri::XML(xml).xpath("/WIM")
91
+
92
+ ret = {}
93
+ ret["total_bytes"] = xml.xpath("./TOTALBYTES").text.to_i
94
+ ret["images"] = xml.xpath("./IMAGE").collect do |i|
95
+ # Deal with hex time parts by removing the 0x prefix, padding with 0s to
96
+ # 8 characters, appending the low part to the high part, converting
97
+ # to an integer, and then converting that to a time object.
98
+ high_part = i.xpath("./CREATIONTIME/HIGHPART").text[2..-1].rjust(8, '0')
99
+ low_part = i.xpath("./CREATIONTIME/LOWPART").text[2..-1].rjust(8, '0')
100
+ creation_time = nt_filetime_to_ruby_time("#{high_part}#{low_part}".to_i(16))
101
+
102
+ high_part = i.xpath("./LASTMODIFICATIONTIME/HIGHPART").text[2..-1].rjust(8, '0')
103
+ low_part = i.xpath("./LASTMODIFICATIONTIME/LOWPART").text[2..-1].rjust(8, '0')
104
+ last_mod_time = nt_filetime_to_ruby_time("#{high_part}#{low_part}".to_i(16))
105
+
106
+ {
107
+ "index" => i["INDEX"].to_i,
108
+ "name" => i.xpath("./NAME").text,
109
+ "description" => i.xpath("./DESCRIPTION").text,
110
+ "dir_count" => i.xpath("./DIRCOUNT").text.to_i,
111
+ "file_count" => i.xpath("./FILECOUNT").text.to_i,
112
+ "total_bytes" => i.xpath("./TOTALBYTES").text.to_i,
113
+ "hard_link_bytes" => i.xpath("./HARDLINKBYTES").text.to_i,
114
+ "creation_time" => creation_time,
115
+ "last_modification_time" => last_mod_time,
116
+ }
117
+ end
118
+ ret
119
+ end
120
+
121
+ private
122
+
123
+ def nt_filetime_to_ruby_time(nt_time)
124
+ # Convert an NT FILETIME to a Ruby Time object.
125
+ nt_time = nt_time / 10_000_000 - 11_644_495_200
126
+ nt_time = 0 if nt_time < 0
127
+ Time.at(nt_time).gmtime
128
+ rescue RangeError
129
+ nt_time
130
+ end
131
+ end
@@ -0,0 +1,3 @@
1
+ class WimParser
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'lib/wim_parser/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "wim_parser"
5
+ spec.version = WimParser::VERSION
6
+ spec.authors = ["ManageIQ Authors"]
7
+
8
+ spec.summary = %q{Parser for the Windows Image Format (WIM)}
9
+ spec.description = spec.summary
10
+ spec.homepage = "https://github.com/ManageIQ/wim_parser"
11
+ spec.license = "Apache 2.0"
12
+
13
+ spec.metadata["homepage_uri"] = spec.homepage
14
+ spec.metadata["source_code_uri"] = spec.homepage
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "binary_struct", "~> 2.1"
26
+ spec.add_dependency "nokogiri", "~> 1.11"
27
+
28
+ spec.add_development_dependency "manageiq-style"
29
+ spec.add_development_dependency "rake", "~> 12.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wim_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ManageIQ Authors
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: binary_struct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: manageiq-style
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Parser for the Windows Image Format (WIM)
84
+ email:
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".codeclimate.yml"
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".rubocop_cc.yml"
94
+ - ".rubocop_local.yml"
95
+ - ".travis.yml"
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - lib/wim_parser.rb
104
+ - lib/wim_parser/version.rb
105
+ - wim_parser.gemspec
106
+ homepage: https://github.com/ManageIQ/wim_parser
107
+ licenses:
108
+ - Apache 2.0
109
+ metadata:
110
+ homepage_uri: https://github.com/ManageIQ/wim_parser
111
+ source_code_uri: https://github.com/ManageIQ/wim_parser
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.0.3
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Parser for the Windows Image Format (WIM)
131
+ test_files: []