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

Handle zlib compressed files #2

Merged
merged 4 commits into from
Jun 24, 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
20 changes: 2 additions & 18 deletions cmd/extract.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package cmd

import (
"os"
"io"
"fmt"
"os"

"github.com/sector-f/jh_extract/nvc"
)
Expand Down Expand Up @@ -33,24 +32,9 @@ func extractNVC(arcPath string, pathlist []string, outputDirectory string, extra
extractedCount := 0

for hash, nvcEntry := range entries {
switch nvcEntry.Flags {
case nvc.Uncompressed:
// Do nothing
case nvc.Compressed:
// TODO: Perform zlib decompression
default:
continue
}

_, exists := hashToPath[hash]
if extractUnknown || exists {
_, err = r.Seek(int64(nvcEntry.Offset), 0) // "0 means relative to the origin of the file"
if err != nil {
continue
}

data := make([]byte, nvcEntry.Length)
_, err = io.ReadFull(r, data)
data, err := nvcEntry.Data(r)
if err != nil {
continue
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ module github.com/sector-f/jh_extract

go 1.18

require github.com/spf13/cobra v1.5.0

require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
45 changes: 40 additions & 5 deletions nvc/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package nvc

import (
"compress/zlib"
"errors"
"io"
)

type EntryFlags uint32
type Hash uint64

Expand All @@ -12,9 +18,38 @@ const (
)

type TocEntry struct {
Hash Hash
Offset uint32
RawLength uint32 // Uncompressed length
Length uint32 // Actual length in file
Flags EntryFlags
Hash Hash
Offset uint32
RawLength uint32 // Uncompressed length
Length uint32 // Actual length in file
Flags EntryFlags
}

func (t TocEntry) Data(r io.ReadSeeker) ([]byte, error) {
_, err := r.Seek(int64(t.Offset), 0)
winny- marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return []byte{}, err
}

var reader io.Reader = r

switch t.Flags {
case Uncompressed:
// Do nothing
case Compressed:
reader, err = zlib.NewReader(r)
if err != nil {
return []byte{}, err
}
default:
return []byte{}, errors.New("unsupported")
}

data := make([]byte, t.Length)
_, err = io.ReadFull(reader, data)
if err != nil {
return []byte{}, err
}

return data, nil
}