-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathdumplast.go
51 lines (43 loc) · 927 Bytes
/
dumplast.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 22 october 2015
package main
import (
"fmt"
"io"
"bytes"
"github.com/andlabs/reallymine/command"
"github.com/andlabs/reallymine/disk"
)
var zeroSector [disk.SectorSize]byte
func cDumpLast(d *disk.Disk, out io.Writer) error {
var sector []byte
// TODO add -fakesize option of sorts
pos := d.Size()
iter, err := d.ReverseIter(pos)
if err != nil {
return err
}
found := false
for iter.Next() {
sector = iter.Sectors()
pos = iter.Pos()
if !bytes.Equal(sector, zeroSector[:]) {
found = true
break
}
}
if err = iter.Err(); err != nil {
return err
}
if !found {
return fmt.Errorf("non-empty sector not found")
}
fmt.Printf("sector at 0x%X\n", pos)
_, err = out.Write(sector)
return err
}
var dumplast = &command.Command{
Name: "dumplast",
Args: []command.Arg{command.ArgDisk, command.ArgOutFile},
Description: "Dumps the last non-zero sector on %s to %s.",
Do: cDumpLast,
}