Fix incorrectly handeling of unknown filetypes

This commit is contained in:
Joren Schipman 2024-05-01 22:59:59 +02:00
parent 1a8966cb1f
commit 323b6e1f82
Signed by untrusted user who does not match committer: Joren
GPG Key ID: 280E33DFBC0F1B55

View File

@ -180,40 +180,46 @@ func decryptKeyIV(ed string, privateKey *rsa.PrivateKey) ([]byte, error) {
return decodedKey, err return decodedKey, err
} }
func handleDecrypted(decryptedDataB []byte, uidB []byte){ func handleDecrypted(decryptedDataB []byte, uidB []byte) {
data, _ := base64.StdEncoding.DecodeString(strings.TrimSpace(string(decryptedDataB))) data, _ := base64.StdEncoding.DecodeString(strings.TrimSpace(string(decryptedDataB)))
fileType, err := magic.Lookup(data)
if err != nil {
if err == magic.ErrUnknown {
fmt.Println("File type is unknown")
} else {
panic(err)
}
}
fileType, err := magic.Lookup(data) var fileTDef string
if err != nil { if fileType != nil {
if err == magic.ErrUnknown { fileTDef = fileType.Extension
fmt.Println("File type is unknown") } else {
fileType.Extension = "unk" fileTDef = "unknown"
}else{ }
panic(err)
}
}
uid := strings.TrimSpace(string(uidB)) uid := strings.TrimSpace(string(uidB))
folderPath := fmt.Sprintf("Loot/%s", uid) folderPath := fmt.Sprintf("Loot/%s", uid)
err = createFolderIfNotExists(folderPath) err = createFolderIfNotExists(folderPath)
if err != nil { if err != nil {
panic(err) panic(err)
} }
timestamp := time.Now().Unix() timestamp := time.Now().Unix()
filename := fmt.Sprintf("%d.%s", timestamp, fileType.Extension) filename := fmt.Sprintf("%d.%s", timestamp, fileTDef)
filePath := fmt.Sprintf("%s/%s", folderPath, filename) filePath := fmt.Sprintf("%s/%s", folderPath, filename)
fmt.Println(filePath) fmt.Println(filePath)
err = saveFile(filePath, data) err = saveFile(filePath, data)
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Printf("Got a %s from %s, saving to %s\n",fileType.Extension,uid,filePath) fmt.Printf("Got a %s from %s, saving to %s\n", fileTDef, uid, filePath)
} }
func createFolderIfNotExists(folderPath string) error { func createFolderIfNotExists(folderPath string) error {
_, err := os.Stat(folderPath) _, err := os.Stat(folderPath)
if os.IsNotExist(err) { if os.IsNotExist(err) {