IT WORKS (again)

This commit is contained in:
Caleb Gardner
2022-06-19 00:32:33 -05:00
parent 8f5e1fef96
commit 214419b5c3
6 changed files with 32 additions and 11 deletions
+1
View File
@@ -28,6 +28,7 @@ func NewFullReader(r io.ReaderAt, start uint64, d decompress.Decompressor, block
func (r *FullReader) AddFragment(rdr func() (io.Reader, error)) {
r.fragRdr = rdr
r.sizes = append(r.sizes, 0)
}
type outDat struct {
+1
View File
@@ -27,6 +27,7 @@ func NewReader(r io.Reader, d decompress.Decompressor, blockSizes []uint32, bloc
func (r *Reader) AddFragment(rdr io.Reader) {
r.fragRdr = rdr
r.blockSizes = append(r.blockSizes, 0)
}
func realSize(siz uint32) uint32 {
+11 -5
View File
@@ -2,7 +2,6 @@ package inode
import (
"encoding/binary"
"fmt"
"io"
"math"
)
@@ -20,7 +19,7 @@ type File struct {
}
type eFileInit struct {
BlockStart uint32
BlockStart uint64
Size uint64
Sparse uint64
LinkCount uint32
@@ -37,10 +36,13 @@ type EFile struct {
func ReadFile(r io.Reader, blockSize uint32) (f File, err error) {
err = binary.Read(r, binary.LittleEndian, &f.fileInit)
if err != nil {
fmt.Println("Hi")
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)
return
}
@@ -50,7 +52,11 @@ func ReadEFile(r io.Reader, blockSize uint32) (f EFile, err error) {
if err != nil {
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)
return
}
+3
View File
@@ -61,6 +61,9 @@ func (r *Reader) Read(p []byte) (n int, err error) {
p[n+i] = tmp[i]
}
n += tmpN
}
if err != nil {
}
return
}
+2 -2
View File
@@ -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) {
var fragOffset uint64
var blockOffset uint32
var blockOffset uint64
var blockSizes []uint32
var fragInd uint32
var fragSize uint32
if i.Type == inode.Fil {
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
fragInd = i.Data.(inode.File).FragInd
fragSize = i.Data.(inode.File).Size % r.s.BlockSize
+14 -4
View File
@@ -3,7 +3,7 @@ package squashfs_test
//Actually proper tests go here.
import (
"fmt"
"errors"
"io"
"io/fs"
"net/http"
@@ -88,12 +88,22 @@ func TestExtractQuick(t *testing.T) {
//TODO: Add long test that checks contents.
squashFils := os.DirFS(unsquashPath)
err = fs.WalkDir(squashFils, "", func(path string, d fs.DirEntry, err error) error {
fmt.Println(path)
err = fs.WalkDir(squashFils, ".", func(path string, d fs.DirEntry, _ error) error {
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
})
if err != nil {
t.Fatal(err)
}
t.Fatal("This is a test")
}