-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an option to decrypt title files
Hacky implementation, but should work
- Loading branch information
Showing
4 changed files
with
246 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
params := parseParams() | ||
|
||
if params == nil { | ||
return | ||
} | ||
|
||
rgl, err := LoadLauncher(params.rglPath) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
var err error | ||
|
||
logFunc := func(log string) { | ||
fmt.Println(log) | ||
switch params.cmdType { | ||
case cmdDecryptTitles: | ||
err = decryptTitles(params) | ||
case cmdExtractLauncher: | ||
err = extractLauncher(params) | ||
} | ||
|
||
for _, packFile := range rgl.Files { | ||
err = packFile.extractPackFile(params.outPath, logFunc) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("Done! Extracted into %s\n", params.outPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"crypto/aes" | ||
"crypto/cipher" | ||
"errors" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
var ( | ||
errInvalidMagic = errors.New("title: invalid file magic") | ||
errUnknownVersion = errors.New("title: unknown version") | ||
errSizeMismatch = errors.New("title: buffer size mismatch") | ||
) | ||
|
||
type rglTitle struct { | ||
Magic []byte | ||
Version uint32 | ||
Length uint32 | ||
Data []byte | ||
} | ||
|
||
func ReadTitleFromFile(filePath string) (*rglTitle, error) { | ||
file, err := os.Open(filePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer file.Close() | ||
|
||
content, err := ioutil.ReadAll(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return ReadTitleFromBuffer(content) | ||
} | ||
|
||
func ReadTitleFromBuffer(content []byte) (*rglTitle, error) { | ||
buffer := bytes.NewBuffer(content) | ||
reader := NewReader(buffer) | ||
|
||
magic := make([]byte, 4) | ||
_, err := reader.Read(magic) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if string(magic) != "RGLM" { | ||
return nil, errInvalidMagic | ||
} | ||
|
||
version, err := reader.ReadUint32() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
length, err := reader.ReadUint32() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if version != 1 || length > uint32(len(content)) { | ||
return nil, errUnknownVersion | ||
} | ||
|
||
// Hardcoded offset? | ||
reader.SetOffset(0x50) | ||
|
||
data := make([]byte, length) | ||
size, err := reader.Read(data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if size != int(length) { | ||
return nil, errSizeMismatch | ||
} | ||
|
||
return &rglTitle{ | ||
Magic: magic, | ||
Version: version, | ||
Length: length, | ||
Data: data, | ||
}, nil | ||
} | ||
|
||
func (title *rglTitle) decrypt() string { | ||
// Key and IV are both empty | ||
key := make([]byte, 32) | ||
iv := make([]byte, 16) | ||
|
||
block, err := aes.NewCipher(key) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
buffer := make([]byte, title.Length) | ||
mode := cipher.NewCBCDecrypter(block, iv) | ||
mode.CryptBlocks(buffer, title.Data) | ||
content := string(buffer) | ||
|
||
// FIXME: hacky trimming | ||
for i := 0; i < len(content); i += 1 { | ||
if content[i] == '{' { | ||
content = content[i : len(content)-1] | ||
break | ||
} | ||
} | ||
for i := len(content) - 1; i > 0; i -= 1 { | ||
if content[i] == '}' { | ||
content = content[:i+1] | ||
break | ||
} | ||
} | ||
|
||
return content | ||
} |