Skip to content
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

Zsz00/dev #2

Merged
merged 5 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: julia
os:
- linux
julia:
- 0.7
- 1.0
notifications:
email: false

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The StructIO.jl package is licensed under the MIT "Expat" License:
The HexIO.jl package is licensed under the MIT "Expat" License:

> Copyright (c) 2016: Keno Fischer.
>
Expand Down
2 changes: 1 addition & 1 deletion Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

julia_version = "1.8.0-beta3"
manifest_format = "2.0"
project_hash = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
project_hash = "f060a2e64e479ab6465690e0158022ef99ef3465"

[deps]
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
name = "StructIO"
name = "HexIO"
uuid = "53d494c1-5632-5724-8f4c-31dff12d585f"
repo = "https://github.com/zsz00/HexIO.git"
version = "0.0.1"

[compat]
julia = "1"
33 changes: 0 additions & 33 deletions appveyor.yml

This file was deleted.

2 changes: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
19 changes: 19 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Documenter, HexIO

makedocs(;
modules=[HexIO],
format=Documenter.HTML(edit_link="master"),
pages=[
"Introduction" => "index.md",
"Example" => "example.md",
"API" => "apis.md",
],
sitename="HexIO.jl",
authors="zsz00",
)

deploydocs(;
repo="github.com/zsz00/HexIO.jl.git",
devbranch = "master",
push_preview = true
)
17 changes: 17 additions & 0 deletions docs/src/apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# API Reference

## HexIO API

```@docs
HexIO.unpack
HexIO.pack
HexIO.fix_endian
HexIO.packed_sizeof
HexIO.@io

HexIO.Hex
HexIO.dump!
HexIO.edit!
HexIO.find!

```
101 changes: 101 additions & 0 deletions docs/src/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
## HexIO Example

### Example usage
```julia
julia> using HexIO

julia> @io struct TwoUInt64s
x::UInt64
y::UInt64
end

julia> buf = IOBuffer(collect(UInt8(1):UInt8(16)));

julia> seekstart(buf); unpack(buf, TwoUInt64s) # Default endianness depends on machine
TwoUInt64s(0x0807060504030201, 0x100f0e0d0c0b0a09)

julia> seekstart(buf); unpack(buf, TwoUInt64s, :BigEndian)
TwoUInt64s(0x0102030405060708, 0x090a0b0c0d0e0f10)

io = open("", "rb")
buffer = read(io, read_size)

```


Hex has same fuctions for editing and displaying data in binary files in
hexadecimal format.

### Synopsis

#### dump!(self::Hex, offset = 0, n::Int = -1)
Displays binary file data beginning at offset and ending at offset + n.
- offset defaults to 0
- n defaults to file size - n.

#### edit!(self::Hex, datastr::String, offset = 0)
Edits targeted binary file by overwriting data beginning at offset.
- offset defaults to 0
- datastr can be in ASCII or hexadecimal format (ie. "foobar" or "0x666f6f626172")

### Examples

### Complete File Hexdump

```julia
hex = Hex("test/test.bin")
dump!(hex, 0x00)
```
```
00000000 | 5D 00 00 80 66 6F 6F 62 61 72 FF FF FF 00 7F E1 |]...foobar......
00000010 | 90 E6 67 83 93 40 93 22 A0 1B AB 50 6E A1 93 54 |..g..@."...Pn..T
00000020 | 3A 7F FD A3 D9 C0 60 29 AF B6 94 96 3E AA 5C 38 |:.....`)....>.\8
00000030 | 1C 05 02 31 7D 74 72 0D 40 3C 22 DA EF FA CA 80 |...1}tr.@<".....
00000040 | DF F8 E2 7B CC 65 09 29 64 C3 15 DE E6 39 B7 7E |...{.e.)d....9.~
00000050 | D5 8C AA 91 F0 28 37 E1 5D AD C0 37 74 16 CE C1 |.....(7.]..7t...
00000060 | 75 94 1E EA DD 64 D6 B5 A1 2E 54 3D 62 4B 72 30 |u....d....T=bKr0
00000070 | 5A 35 B8 5D 42 A2 24 A1 C6 22 6A BE C6 58 07 E5 |Z5.]B.$.."j..X..
00000080 | 4F F1 E3 FC 53 14 70 AA AE 58 FA E3 D8 C4 3A DB |O...S.p..X....:.
00000090 | D2 81 CF 99 24 10 4C C1 53 76 98 BC 16 E9 C2 7E |....$.L.Sv.....~
000000A0 | 2C 6F 23 D6 F7 32 AB 81 7E 74 FD B6 FE B2 E7 15 |,o#..2..~t......
000000B0 | 83 7D 45 96 44 A8 D9 CF B2 B8 AD 37 73 0E 15 AD |.}E.D......7s...
and so on...
```
### Chunk Hexdump

Dump 16 bytes beginning at offset 0x04
```julia
hex = Hex("test.bin")
dump!(hex, 0x04, 16)

00000004 | 66 6F 6F 62 61 72 FF FF FF 00 7F E1 90 E6 67 83 |foobar........g.

dump!(hex.hex, 0x04, 16)

00000004 | 66 6F 6F 62 61 72 FF FF FF 00 7F E1 90 E6 67 83 |foobar........g.
```


### Hexadecimal Editing (Hex String)

Write foobar to `test.bin` beginning at offset 0x04
```julia
hex = Hex("test.bin")
edit!(hex, "0x666f6f626172", 0x04)
```

### Hexadecimal Editing (ASCII string)

Write foobar to test.bin beginning at offset 0x04
```julia
hex = Hex("test.bin")
edit!(hex, "foobar", 0x04)
```

### Binary Singature Location

Return offset of the start of the hexadecimal signature "b77e"
```julia
hex = Hex("test.bin")
offset = find!(hex, "0xb77e")
```
108 changes: 108 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# HexIO

[![HexIO](http://pkg.julialang.org/badges/HexIO_0.6.svg)](http://pkg.julialang.org/?pkg=HexIO)
[![HexIO](http://pkg.julialang.org/badges/HexIO_0.7.svg)](http://pkg.julialang.org/?pkg=HexIO)
[![Build Status](https://travis-ci.org/zsz00/HexIO.jl.svg?branch=master)](https://travis-ci.org/zsz00/HexIO.jl)
[![Coverage](http://codecov.io/github/zsz00/HexIO.jl/coverage.svg?branch=master)](http://codecov.io/github/zsz00/HexIO.jl?branch=master)

Generates IO methods (`pack`, `unpack`) from structure definitions. Also defines `packed_sizeof` to give the on-disk size of a packed structure, which is smaller than `sizeof` would give, if the struct is marked as `align_packed`.

# Example usage
```julia
julia> using HexIO

julia> @io struct TwoUInt64s
x::UInt64
y::UInt64
end

julia> buf = IOBuffer(collect(UInt8(1):UInt8(16)));

julia> seekstart(buf); unpack(buf, TwoUInt64s) # Default endianness depends on machine
TwoUInt64s(0x0807060504030201, 0x100f0e0d0c0b0a09)

julia> seekstart(buf); unpack(buf, TwoUInt64s, :BigEndian)
TwoUInt64s(0x0102030405060708, 0x090a0b0c0d0e0f10)

io = open("", "rb")
buffer = read(io, read_size)

```


Hex has same fuctions for editing and displaying data in binary files in
hexadecimal format.

### Synopsis

#### dump!(self::Hex, offset = 0, n::Int = -1)
Displays binary file data beginning at offset and ending at offset + n.
- offset defaults to 0
- n defaults to file size - n.

#### edit!(self::Hex, datastr::String, offset = 0)
Edits targeted binary file by overwriting data beginning at offset.
- offset defaults to 0
- datastr can be in ASCII or hexadecimal format (ie. "foobar" or "0x666f6f626172")

### Examples

### Complete File Hexdump

```julia
hex = Hex("test/test.bin")
dump!(hex, 0x00)
```
```
00000000 | 5D 00 00 80 66 6F 6F 62 61 72 FF FF FF 00 7F E1 |]...foobar......
00000010 | 90 E6 67 83 93 40 93 22 A0 1B AB 50 6E A1 93 54 |..g..@."...Pn..T
00000020 | 3A 7F FD A3 D9 C0 60 29 AF B6 94 96 3E AA 5C 38 |:.....`)....>.\8
00000030 | 1C 05 02 31 7D 74 72 0D 40 3C 22 DA EF FA CA 80 |...1}tr.@<".....
00000040 | DF F8 E2 7B CC 65 09 29 64 C3 15 DE E6 39 B7 7E |...{.e.)d....9.~
00000050 | D5 8C AA 91 F0 28 37 E1 5D AD C0 37 74 16 CE C1 |.....(7.]..7t...
00000060 | 75 94 1E EA DD 64 D6 B5 A1 2E 54 3D 62 4B 72 30 |u....d....T=bKr0
00000070 | 5A 35 B8 5D 42 A2 24 A1 C6 22 6A BE C6 58 07 E5 |Z5.]B.$.."j..X..
00000080 | 4F F1 E3 FC 53 14 70 AA AE 58 FA E3 D8 C4 3A DB |O...S.p..X....:.
00000090 | D2 81 CF 99 24 10 4C C1 53 76 98 BC 16 E9 C2 7E |....$.L.Sv.....~
000000A0 | 2C 6F 23 D6 F7 32 AB 81 7E 74 FD B6 FE B2 E7 15 |,o#..2..~t......
000000B0 | 83 7D 45 96 44 A8 D9 CF B2 B8 AD 37 73 0E 15 AD |.}E.D......7s...
and so on...
```
### Chunk Hexdump

Dump 16 bytes beginning at offset 0x04
```julia
hex = Hex("test.bin")
dump!(hex, 0x04, 16)

00000004 | 66 6F 6F 62 61 72 FF FF FF 00 7F E1 90 E6 67 83 |foobar........g.

dump!(hex.hex, 0x04, 16)

00000004 | 66 6F 6F 62 61 72 FF FF FF 00 7F E1 90 E6 67 83 |foobar........g.
```


### Hexadecimal Editing (Hex String)

Write foobar to `test.bin` beginning at offset 0x04
```julia
hex = Hex("test.bin")
edit!(hex, "0x666f6f626172", 0x04)
```

### Hexadecimal Editing (ASCII string)

Write foobar to test.bin beginning at offset 0x04
```julia
hex = Hex("test.bin")
edit!(hex, "foobar", 0x04)
```

### Binary Singature Location

Return offset of the start of the hexadecimal signature "b77e"
```julia
hex = Hex("test.bin")
offset = find!(hex, "0xb77e")
```