-
-
Notifications
You must be signed in to change notification settings - Fork 36
New MachOStructure DSL #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
68e502a
Preliminary work on the new MachOStructure dsl
apainintheneck b68a0af
Added new field types
apainintheneck b1e3739
Refactored MachOStructure class
apainintheneck 75acdfa
Updated headers.rb with new dsl
apainintheneck 19499a7
Updated section.rb to new dsl
apainintheneck c34f204
Started converting the load commands to new dsl
apainintheneck ab3b559
Updated dsl to handle updating inherited fields
apainintheneck 433755e
Changed fields to respect endianness
apainintheneck 1eb45ad
Finished updating load commands and more
apainintheneck 969833f
Add rubocop exception for self.inherited()
apainintheneck 0039b96
Moved logic out of the constructor
apainintheneck 7ef240f
Added way to generate #to_s
apainintheneck 8e7dd9d
Added :endian option to MachOStructure#field
apainintheneck d31379e
Added tests for MachOStructure dsl
apainintheneck 1bebc28
Added documentation for new structure dsl
apainintheneck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Internal MachOStructure DSL | ||
## Documentation | ||
The MachOStructure class makes it easy to describe binary chunks by using the #field method. This method generates the byte size and format strings necessary to parse a chunk of binary data. It also automatically generates the constructor and readers for all fields as well. | ||
|
||
The fields are created in order so you will be expected to pass those arguements to the constructor in the same order. Fields with no arguments should be defined last and fields with default arguments should be defined right before them. | ||
|
||
The type and options of inherited fields can be changed but their argument position and the number of arguments (used to calculate min_args) will also not change. | ||
|
||
Usually, endianness is handled by the Utils#specialize_format method but occasionally a field needs to specifiy that beforehand. That is what the :endian option is for. If not specified, a placeholder is used so that can be specified later. | ||
|
||
## Syntax | ||
```ruby | ||
field [field name], [field type], [option1 => value1], [option2 => value2], ... | ||
``` | ||
|
||
## Example | ||
```ruby | ||
class AllFields < MachO::MachOStructure | ||
field :name1, :string, :size => 16 | ||
field :name3, :int32 | ||
field :name4, :uint32 | ||
field :name5, :uint64 | ||
field :name6, :view | ||
field :name7, :lcstr | ||
field :name8, :two_level_hints_table | ||
field :name9, :tool_entries | ||
end | ||
``` | ||
|
||
## Field Types | ||
- `:string` [requires `:size` option] [optional `:padding` option] | ||
- a string | ||
- `:int32 ` | ||
- a signed 32 bit integer | ||
- `:uint32 ` | ||
- an unsigned 32 bit integer | ||
- `:uint64 ` | ||
- an unsigned 64 bit integer | ||
- `:view` [initalized] | ||
- an instance of the MachOView class (lib/macho/view.rb) | ||
- `:lcstr` [NOT initalized] | ||
- an instance of the LCStr class (lib/macho/load_commands.rb) | ||
- `:two_level_hints_table` [NOT initalized] [NO argument] | ||
- an instance of the TwoLevelHintsTable class (lib/macho/load_commands.rb) | ||
- `:tool_entries` [NOT initalized] | ||
- an instance of the ToolEntries class (lib/macho/load_commands.rb) | ||
|
||
## Option Types | ||
- Exclusive (only one can be used at a time) | ||
- `:mask` [Integer] bitmask to be applied to field | ||
- `:unpack` [String] binary unpack string used for further unpacking of :string | ||
- `:default` [Value] default field value | ||
- Inclusive (can be used with other options) | ||
- `:to_s` [Boolean] generate `#to_s` method based on field | ||
- Used with Integer field types | ||
- `:endian` [Symbol] optionally specify `:big` or `:little` endian | ||
- Used with `:string` field type | ||
- `:size` [Integer] size in bytes | ||
- `:padding` [Symbol] optionally specify `:null` padding | ||
|
||
## More Infomation | ||
Hop over to lib/macho/structure.rb to see the class itself. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.