Skip to content

Commit 45c0c7d

Browse files
committed
add an isodump cmd
1 parent 30ab35f commit 45c0c7d

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

cmd/isodump/main.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"path"
8+
"strings"
9+
"time"
10+
11+
"github.com/kdomanski/iso9660"
12+
)
13+
14+
func main() {
15+
if len(os.Args) != 2 {
16+
log.Fatalf("usage: %s <filename.iso>", os.Args[0])
17+
}
18+
19+
f, err := os.Open(os.Args[1])
20+
if err != nil {
21+
log.Fatalf("failed to open %s: %s", os.Args[1], err)
22+
}
23+
defer f.Close()
24+
25+
iso, err := iso9660.OpenImage(f)
26+
if err != nil {
27+
log.Fatalf("failed to open image %s: %s", os.Args[1], err)
28+
}
29+
30+
root, err := iso.RootDir()
31+
if err != nil {
32+
log.Fatalf("failed to open iso root %s: %s", os.Args[1], err)
33+
}
34+
35+
if err := printEntries(root, []string{}); err != nil {
36+
log.Fatal(err)
37+
}
38+
}
39+
40+
func printEntries(file *iso9660.File, parents []string) error {
41+
if len(parents) > 1 && (file.Name() == "\x00" || file.Name() == "\x01") {
42+
return nil
43+
}
44+
45+
printEntry(file, parents)
46+
47+
if !file.IsDir() {
48+
return nil
49+
}
50+
51+
childs, err := file.GetChildren()
52+
if err != nil {
53+
return fmt.Errorf("getting children for %s: %w", file.Name(), err)
54+
}
55+
56+
for _, entry := range childs {
57+
if err := printEntries(entry, append(parents, file.Name())); err != nil {
58+
return err
59+
}
60+
}
61+
62+
return nil
63+
}
64+
65+
func printEntry(file *iso9660.File, parents []string) {
66+
path := path.Join(append(parents, file.Name())...)
67+
path = strings.ReplaceAll(path, "\x00", ".")
68+
path = strings.ReplaceAll(path, "\x01", "..")
69+
70+
fmt.Printf("%q age: %v bytes: %v, me: %v\n",
71+
path,
72+
time.Since(file.ModTime()).Round(time.Second),
73+
file.Size(), file.HasMultiExtent())
74+
}

image_reader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func (f *File) IsDir() bool {
8282
return f.de.FileFlags&dirFlagDir != 0
8383
}
8484

85+
// HasMultiExtent is for 'testing' ISO data.
86+
func (f *File) HasMultiExtent() bool {
87+
return f.de.FileFlags&dirFlagMultiExtent != 0
88+
}
89+
8590
// ModTime returns the entry's recording time
8691
func (f *File) ModTime() time.Time {
8792
return time.Time(f.de.RecordingDateTime)

iso9660.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"io"
10+
"log"
1011
"strconv"
1112
"strings"
1213
"time"
@@ -178,6 +179,7 @@ func (de *DirectoryEntry) UnmarshalBinary(data []byte) error {
178179
identifierLen := data[32]
179180
de.Identifier = string(data[33 : 33+identifierLen])
180181

182+
log.Printf("DEBUG: %b %q %q", de.FileFlags, de.Identifier, string(data))
181183
// add padding if identifier length was even]
182184
idPaddingLen := (identifierLen + 1) % 2
183185
de.SystemUse = data[33+identifierLen+idPaddingLen : length]

0 commit comments

Comments
 (0)