Skip to content

Commit

Permalink
Merge pull request #3 from zsz00/zsz00/dev
Browse files Browse the repository at this point in the history
fix Hex.__offset
  • Loading branch information
zsz00 authored Apr 29, 2022
2 parents 63e9cd7 + e526496 commit 65afefc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/hex_edit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,21 @@ end # type Hex
Hex(filename::AbstractString)
"""
function Hex(filename::AbstractString)
function Hex(filename::AbstractString, _offset::Int=0)
hex = open(filename, "r+")
_size = filename[1:4]=="\\\\.\\" ? 0 : filesize(filename)
println("_size:", _size)
_offset = 0x00
Hex(hex, _size, _offset)
end # constructor Hex

"""
Hex(io::IO)
"""
function Hex(io::IO)
function Hex(io::IO, _offset::Int=0)
hex = io
_size = stat(io).size
println("_size:", _size)
_offset = 0x00
Hex(hex, _size, _offset)
end # constructor Hex

Expand Down Expand Up @@ -87,7 +85,7 @@ function dump_buffer(s::Hex, buffer::Array{UInt8})
if idx + 16 > blen
llen = blen - idx + 1
end
dump_line(s, buffer[idx:idx + llen - 1])
dump_line(s, buffer[idx:(idx + llen - 1)])
idx = idx + llen
end
end # function dump_buffer
Expand Down Expand Up @@ -121,7 +119,7 @@ function dump!(s::Hex, start=nothing, n=nothing)
end
end # function dump!

dump!(buf::IO, start=nothing, n=nothing) = dump!(Hex(buf), start, n)
dump!(buf::IO, start=nothing, n=nothing) = dump!(Hex(buf, start), start, n)


"""
Expand Down
41 changes: 41 additions & 0 deletions test/test_2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using HexIO


struct MBR
# BHBBHBII 16B
id = 0 # 分区id号
type_1 = "" # 分区状态
type_2 = "" # 分区文件系统类型
off_1 = 0 # 起始偏移
p_size = 0 # 分区大小
end


function read_mbr()
buf = Hex("\\\\.\\PHYSICALDRIVE0") # within
buf = Hex("/dev/sda1") # linux
dump!(buf, 0x00, 512)
dump!(buf, 510, 2)

seek(buf.hex, 0x01f0)
flag = read(buf.hex, Int16)
println(flag)

return
if flag == 0
println(aa)

seekstart(buf)
seekstart(buf)

# p_type_1 = {128:'active',0:'normal'}
# p_type_2 = {15:'Extent',7:'NTFS',12:'FAT32',131:'Linux'}
end








0 comments on commit 65afefc

Please sign in to comment.