Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.build/

.idea/
.vscode/
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PROJECT ?= $(notdir $(patsubst %/,%,$(CURDIR)))
PACKAGE ?= github.com/andlabs/$(PROJECT)

GO_SOURCES = $(shell find . -type f \( -iname '*.go' \) \
-not \( -path "./vendor/*" -path ".*" \) \
-not \( -path "./_notes/*" -path ".*" \) \
-not \( -path "./_pre/*" -path ".*" \) \
-not \( -path "./_sectors/*" -path ".*" \) \
-not \( -path "./_try/*" -path ".*" \))

export GO111MODULE = on

fmt: $(GO_SOURCES) # format go sources
gofmt -w -s -l $^

.build/$(PROJECT).%: $(GO_SOURCES) go.mod
mkdir -p $(@D)
CGO_ENABLED=0 GOOS=$(basename $*) GOARCH=$(patsubst .%,%,$(suffix $*)) go build -o $@ $(PACKAGE)

.BIN_LOCAL = $(PROJECT).$(shell go env GOOS).$(shell go env GOARCH)

build: .build/$(.BIN_LOCAL)
32 changes: 16 additions & 16 deletions ata/ata.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func DrivespecUsage() string {
}

type ATA struct {
s *sysATA
s *sysATA
}

func Open(drivespec string) (*ATA, error) {
Expand All @@ -23,30 +23,30 @@ func (a *ATA) Close() error {
}

type Command28 struct {
Features byte
Count byte
LBALow byte
LBAMid byte
LBAHigh byte
Device byte
Command byte
Features byte
Count byte
LBALow byte
LBAMid byte
LBAHigh byte
Device byte
Command byte
}

type Response28 struct {
Error byte
Count byte
LBALow byte
LBAMid byte
LBAHigh byte
Device byte
Status byte
Error byte
Count byte
LBALow byte
LBAMid byte
LBAHigh byte
Device byte
Status byte
}

func (a *ATA) Read28(c *Command28, b []byte) (resp *Response28, n int, err error) {
return a.s.Read28(c, b)
}

func (a *ATA) Write28(c *Command28, b []byte) (resp *Response28, err eror) {
func (a *ATA) Write28(c *Command28, b []byte) (resp *Response28, err error) {
return a.s.Write28(c, b)
}

Expand Down
2 changes: 1 addition & 1 deletion ata/ata_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func sysDrivespecUsage() string {
return "This OS does not support sending arbitrary ATA commands to a disk; consequently, there are no valid drivespecs and any command requiring a drivespec will fail."
}

type sysATA struct {}
type sysATA struct{}

func sysOpen(drivespec string) (*ATA, error) {
return nil, ErrUnsupportedOS
Expand Down
54 changes: 27 additions & 27 deletions ata/ata_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
package ata

import (
"regexp"
"bytes"
"encoding/binary"
"regexp"

"golang.org/x/sys/windows"
)
Expand Down Expand Up @@ -36,7 +36,7 @@ func validDrivespec(drivespec string) bool {
}

type sysATA struct {
handle windows.Handle
handle windows.Handle
}

func sysOpen(drivespec string) (*ATA, error) {
Expand All @@ -50,8 +50,8 @@ func sysOpen(drivespec string) (*ATA, error) {
}
a := new(sysATA)
a.handle, err = windows.CreateFile(wdrivespec,
windows.GENERIC_READ | windows.GENERIC_WRITE,
windows.FILE_SHARE_READ | windows.FILE_SHARE_WRITE,
windows.GENERIC_READ|windows.GENERIC_WRITE,
windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE,
nil,
windows.OPEN_EXISTING,
0, nil)
Expand All @@ -66,24 +66,24 @@ func (a *sysATA) Close() error {
}

type _ATA_PASS_THROUGH_EX struct {
Length uint16
AtaFlags uint16
PathId uint8
TargetId uint8
Lun uint8
ReservedAsUchar uint8
DataTransferLength uint32
TimeOutValue uint32
ReservedAsUlong uint32
DataBufferOffset _ULONG_PTR
PreviousTaskFile [8]uint8
CurrentTaskFile [8]uint8
Length uint16
AtaFlags uint16
PathId uint8
TargetId uint8
Lun uint8
ReservedAsUchar uint8
DataTransferLength uint32
TimeOutValue uint32
ReservedAsUlong uint32
DataBufferOffset _ULONG_PTR
PreviousTaskFile [8]uint8
CurrentTaskFile [8]uint8
}

const (
_ATA_FLAGS_DRDY_REQUIRED = 0x01
_ATA_FLAGS_DATA_IN =0x02
_ATA_FLAGS_DATA_OUT = 0x04
_ATA_FLAGS_DATA_IN = 0x02
_ATA_FLAGS_DATA_OUT = 0x04
_ATA_FLAGS_48BIT_COMMAND = 0x08

_IOCTL_ATA_PASS_THROUGH = 0x04D02C
Expand All @@ -98,7 +98,7 @@ func (c *Command28) toNT(flags uint16, buf []byte) (send []byte, err error) {
// TODO _ATA_FLAGS_DRDY_REQUIRED?
pte.AtaFlags = flags
pte.DataTransferLength = uint32(len(buf))
pte.TimeOutValue = ^uint32(0) // TODO
pte.TimeOutValue = ^uint32(0) // TODO
pte.DataBufferOffset = _ULONG_PTR(sizeofPTE)
pte.CurrentTaskFile[0] = c.Features
pte.CurrentTaskFile[1] = c.Count
Expand All @@ -121,7 +121,7 @@ func (c *Command28) toNTRead(outbuf []byte) (send []byte, recv []byte, err error
if err != nil {
return nil, nil, err
}
recv = make([]byte, sizeofPTE + len(outbuf))
recv = make([]byte, sizeofPTE+len(outbuf))
return send, recv, nil
}

Expand All @@ -130,17 +130,17 @@ func (c *Command28) toNTWrite(inbuf []byte) (send []byte, recv []byte, err error
if err != nil {
return nil, nil, err
}
send = make([]byte, len(s) + len(inbuf))
send = make([]byte, len(s)+len(inbuf))
copy(send[:len(s)], s)
copy(send[len(s):], inbuf)
recv = make([]byte, sizeofPTE)
return send, recv, nil
}

type out struct {
recv []byte
pte _ATA_PASS_THROUGH_EX
resp *Response28
recv []byte
pte _ATA_PASS_THROUGH_EX
resp *Response28
}

func (a *sysATA) perform(send []byte, recv []byte, err error) (o *out, err error) {
Expand Down Expand Up @@ -180,9 +180,9 @@ func (a *sysATA) perform(send []byte, recv []byte, err error) (o *out, err error
resp.Status = pte.CurrentTaskFile[6]

return &out{
recv: recv[pte.DataBufferOffset:],
pte: pte,
resp: resp,
recv: recv[pte.DataBufferOffset:],
pte: pte,
resp: resp,
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions bridge/initio.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (Initio) NeedsKEK() bool {
}

type InitioKeySector struct {
raw []byte
d struct { // d for "DEK block"
raw []byte
d struct { // d for "DEK block"
Magic [4]byte // 27 5D BA 35
Unknown [8]byte
Key [32]byte // stored as little-endian longs
Expand All @@ -55,7 +55,7 @@ func (Initio) DecryptKeySector(keySector []byte, kek []byte) (KeySector, error)
}

return &InitioKeySector{
raw: keySector,
raw: keySector,
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions bridge/jmicron.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ func (JMicron) NeedsKEK() bool {
}

type JMicronKeySector struct {
raw []byte
raw []byte

// The names Key3EE2, Key3EF2, and Key3F02 are from the
// paper. But I recognize the hex numbers as addresses in the
// JMicron chip's RAM. These RAM addresses followed me
// around throughout disassembly, and I *knew* they were
// suspicious, damnit!
d struct { // d for "DEK block"
d struct { // d for "DEK block"
Magic [4]byte // 'DEK1'
Checksum uint16 // TODO check this too?
Checksum uint16 // TODO check this too?
Unknown uint16
Random1 uint32
Key3EE2 [16]byte // This is the first half of the AES-256 key.
Expand Down Expand Up @@ -69,7 +69,7 @@ func (JMicron) DecryptKeySector(keySector []byte, kek []byte) (KeySector, error)
}

return &JMicronKeySector{
raw: keySector,
raw: keySector,
}, nil
}

Expand Down
14 changes: 7 additions & 7 deletions bridge/plx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package bridge

import (
"bytes"
"encoding/binary"
"crypto/aes"
"encoding/binary"

"github.com/andlabs/reallymine/byteops"
"github.com/andlabs/reallymine/decryptloop"
Expand All @@ -28,13 +28,13 @@ func (PLX) NeedsKEK() bool {
}

type PLXKeySector struct {
raw []byte
d struct {
Magic [4]byte
Unknown [0x10]byte
EncryptedDEK [32]byte
raw []byte
d struct {
Magic [4]byte
Unknown [0x10]byte
EncryptedDEK [32]byte
}
dek []byte
dek []byte
}

// MAJOR TODO
Expand Down
18 changes: 9 additions & 9 deletions bridge/symwave.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func (Symwave) NeedsKEK() bool {
}

type SymwaveKeySector struct {
raw []byte
raw []byte

// The DEK is stored as two separately-wrapped halves.
// The KEK is only stored as one.
d struct {
Magic [4]byte
Unknown [0xC]byte
WrappedDEK1 [0x28]byte
WrappedDEK2 [0x28]byte
WrappedKEK [0x28]byte
d struct {
Magic [4]byte
Unknown [0xC]byte
WrappedDEK1 [0x28]byte
WrappedDEK2 [0x28]byte
WrappedKEK [0x28]byte
}
}

Expand All @@ -56,7 +56,7 @@ var symwaveKEKWrappingKey = []byte{

func (Symwave) DecryptKeySector(keySector []byte, kek []byte) (KeySector, error) {
return &SymwaveKeySector{
raw: byteops.DupBytes(keySector),
raw: byteops.DupBytes(keySector),
}, nil
}

Expand Down Expand Up @@ -95,7 +95,7 @@ func (ks *SymwaveKeySector) DEK() (dek []byte, err error) {
}

dek = byteops.DupBytes(dek1)
_ = dek2 // doesn't seem to be used
_ = dek2 // doesn't seem to be used
// And finally we just need one last endian correction...
byteops.SwapLongs(dek)
return dek, nil
Expand Down
Loading