IT WORKS (again)
This commit is contained in:
@@ -28,6 +28,7 @@ func NewFullReader(r io.ReaderAt, start uint64, d decompress.Decompressor, block
|
|||||||
|
|
||||||
func (r *FullReader) AddFragment(rdr func() (io.Reader, error)) {
|
func (r *FullReader) AddFragment(rdr func() (io.Reader, error)) {
|
||||||
r.fragRdr = rdr
|
r.fragRdr = rdr
|
||||||
|
r.sizes = append(r.sizes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
type outDat struct {
|
type outDat struct {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func NewReader(r io.Reader, d decompress.Decompressor, blockSizes []uint32, bloc
|
|||||||
|
|
||||||
func (r *Reader) AddFragment(rdr io.Reader) {
|
func (r *Reader) AddFragment(rdr io.Reader) {
|
||||||
r.fragRdr = rdr
|
r.fragRdr = rdr
|
||||||
|
r.blockSizes = append(r.blockSizes, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func realSize(siz uint32) uint32 {
|
func realSize(siz uint32) uint32 {
|
||||||
|
|||||||
+11
-5
@@ -2,7 +2,6 @@ package inode
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
@@ -20,7 +19,7 @@ type File struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type eFileInit struct {
|
type eFileInit struct {
|
||||||
BlockStart uint32
|
BlockStart uint64
|
||||||
Size uint64
|
Size uint64
|
||||||
Sparse uint64
|
Sparse uint64
|
||||||
LinkCount uint32
|
LinkCount uint32
|
||||||
@@ -37,10 +36,13 @@ type EFile struct {
|
|||||||
func ReadFile(r io.Reader, blockSize uint32) (f File, err error) {
|
func ReadFile(r io.Reader, blockSize uint32) (f File, err error) {
|
||||||
err = binary.Read(r, binary.LittleEndian, &f.fileInit)
|
err = binary.Read(r, binary.LittleEndian, &f.fileInit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Hi")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f.BlockSizes = make([]uint32, int(math.Ceil(float64(f.Size)/float64(blockSize))))
|
toRead := int(math.Floor(float64(f.Size) / float64(blockSize)))
|
||||||
|
if f.FragInd == 0xFFFFFFFF && f.Size%blockSize > 0 {
|
||||||
|
toRead++
|
||||||
|
}
|
||||||
|
f.BlockSizes = make([]uint32, toRead)
|
||||||
err = binary.Read(r, binary.LittleEndian, &f.BlockSizes)
|
err = binary.Read(r, binary.LittleEndian, &f.BlockSizes)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -50,7 +52,11 @@ func ReadEFile(r io.Reader, blockSize uint32) (f EFile, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f.BlockSizes = make([]uint32, int(math.Ceil(float64(f.Size)/float64(blockSize))))
|
toRead := int(math.Floor(float64(f.Size) / float64(blockSize)))
|
||||||
|
if f.FragInd == 0xFFFFFFFF && f.Size%uint64(blockSize) > 0 {
|
||||||
|
toRead++
|
||||||
|
}
|
||||||
|
f.BlockSizes = make([]uint32, toRead)
|
||||||
err = binary.Read(r, binary.LittleEndian, &f.BlockSizes)
|
err = binary.Read(r, binary.LittleEndian, &f.BlockSizes)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ func (r *Reader) Read(p []byte) (n int, err error) {
|
|||||||
p[n+i] = tmp[i]
|
p[n+i] = tmp[i]
|
||||||
}
|
}
|
||||||
n += tmpN
|
n += tmpN
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -32,13 +32,13 @@ func (r Reader) inodeFromDir(e directory.Entry) (i inode.Inode, err error) {
|
|||||||
|
|
||||||
func (r Reader) getReaders(i inode.Inode) (full *data.FullReader, rdr *data.Reader, err error) {
|
func (r Reader) getReaders(i inode.Inode) (full *data.FullReader, rdr *data.Reader, err error) {
|
||||||
var fragOffset uint64
|
var fragOffset uint64
|
||||||
var blockOffset uint32
|
var blockOffset uint64
|
||||||
var blockSizes []uint32
|
var blockSizes []uint32
|
||||||
var fragInd uint32
|
var fragInd uint32
|
||||||
var fragSize uint32
|
var fragSize uint32
|
||||||
if i.Type == inode.Fil {
|
if i.Type == inode.Fil {
|
||||||
fragOffset = uint64(i.Data.(inode.File).Offset)
|
fragOffset = uint64(i.Data.(inode.File).Offset)
|
||||||
blockOffset = i.Data.(inode.File).BlockStart
|
blockOffset = uint64(i.Data.(inode.File).BlockStart)
|
||||||
blockSizes = i.Data.(inode.File).BlockSizes
|
blockSizes = i.Data.(inode.File).BlockSizes
|
||||||
fragInd = i.Data.(inode.File).FragInd
|
fragInd = i.Data.(inode.File).FragInd
|
||||||
fragSize = i.Data.(inode.File).Size % r.s.BlockSize
|
fragSize = i.Data.(inode.File).Size % r.s.BlockSize
|
||||||
|
|||||||
+14
-4
@@ -3,7 +3,7 @@ package squashfs_test
|
|||||||
//Actually proper tests go here.
|
//Actually proper tests go here.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -88,12 +88,22 @@ func TestExtractQuick(t *testing.T) {
|
|||||||
//TODO: Add long test that checks contents.
|
//TODO: Add long test that checks contents.
|
||||||
|
|
||||||
squashFils := os.DirFS(unsquashPath)
|
squashFils := os.DirFS(unsquashPath)
|
||||||
err = fs.WalkDir(squashFils, "", func(path string, d fs.DirEntry, err error) error {
|
err = fs.WalkDir(squashFils, ".", func(path string, d fs.DirEntry, _ error) error {
|
||||||
fmt.Println(path)
|
libFil, e := os.Open(filepath.Join(libPath, path))
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
stat, _ := d.Info()
|
||||||
|
libStat, _ := libFil.Stat()
|
||||||
|
if stat.Size() != libStat.Size() {
|
||||||
|
t.Log(path, "not the same size between library and unsquashfs")
|
||||||
|
t.Log("File is", libStat.Size())
|
||||||
|
t.Log("Should be", stat.Size())
|
||||||
|
return errors.New("file not the correct size")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Fatal("This is a test")
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user