Skip to content

Instantly share code, notes, and snippets.

@antiKk
Last active April 22, 2022 14:52
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save antiKk/279966c27fdfd9c7fe63b4ae410f89c4 to your computer and use it in GitHub Desktop.
$hactool = "$PSScriptRoot\hactool.exe"
$prodkeys = "$PSScriptRoot\prod.keys"
$firmware = "$PSScriptRoot\Firmware 10.1.0\"
$files = Get-ChildItem $firmware -Filter *.nca
$numfiles = 0
foreach ($file in $files) {
$hacout = & $hactool -k $prodkeys -i $firmware$file | Out-String
if($hacout -like '*Content Type: Meta*') {
Get-Item $firmware$file | Rename-Item -Path $firmware$file -NewName { $_.Name -replace '.nca','.cnmt.nca' }
$numfiles++
}
}
Write-Host "Renamed "$numfiles " ncas"
@Darthsternie
Copy link

Great Script!
You might want to replace the hardcoded Paths with this:
$hactool = "$PSScriptRoot\hactool.exe"
$prodkeys = "$PSScriptRoot\prod.keys"
$firmware = "$PSScriptRoot\Firmware"
That way the Script will use the hactool.exe, prod.keys and Firmware Folder from the same path/folder where the daybreak.ps1 is executed in :)

@antiKk
Copy link
Author

antiKk commented Jul 22, 2020

Thanks for the feedback!
Excellent suggestion.

@deejay87
Copy link

deejay87 commented Jul 22, 2020

Hello, i have test but got "Failed to match key" on every lines (only somes few files is renamed), tested with the prod.keys taken by lockpick , if you know what i do wrong :)
thanks

@Darthsternie
Copy link

Darthsternie commented Jul 22, 2020

Hello, i have test but got "Failed to match key" on every line, tested with the prod.keys taken by lockpick , if you know what i do wrong :)
thanks

Remove all the Keys from the prod.keys where hactool/daybreak.ps1 says "Failed to match key". hactool can't parse every key that lockpick dumps. After doing that it should work just fine.

@deejay87
Copy link

ok i try this after my coffee ^^ thanks, but however, not all files are renamed from what i see (same from your archives)

@antiKk
Copy link
Author

antiKk commented Jul 23, 2020

ok i try this after my coffee ^^ thanks, but however, not all files are renamed from what i see (same from your archives)

It should only rename the files with the meta content type.
I think on the latest firmware it's about 111 files.

@MrPerson0
Copy link

MrPerson0 commented Aug 4, 2020

I removed the offending keys from prod.keys where the program says "Failed to match key", but now I am getting "error section 0 is corrupted!" (or 1 instead), but 111 files are still being renamed. Should I worry about said error?

Edit: Redumped my keys and deleted the lines that were showing errors, seems to be working fine now.

@13xforever
Copy link

#!/bin/pwsh
<#
.SYNOPSIS
Script to rename firmware update files to be compatible with Daybreak updater homebrew.
.PARAMETER path
Path to firmware dump.
Default path is current directory from which the script was called.
.PARAMETER hactool
Path to hactool.exe (get it here: https://github.com/SciresM/hactool/releases/latest).
Default path is hactool.exe in the script folder.
.PARAMETER prodkeys
Path to your console prod.keys dump (instrucitons: https://yuzu-emu.org/help/quickstart/#dumping-prod-keys-and-title-keys).
Default path is prod.keys file in the script folder.
#>
param(
    [string]$path = ".\",
    [string]$hactool = "$PSScriptRoot\hactool.exe",
    [string]$prodkeys = "$PSScriptRoot\prod.keys"
)

if (-not (Test-Path $path))
{
    throw "Path to firmware does not exist: $path"
}
if (-not (Test-Path $hactool))
{
    throw "Can't find hactool.exe using path $hactool"
}
if (-not (Test-Path $prodkeys))
{
    throw "Can't find prod.keys file using path $prodkeys"
}

$files = @(Get-ChildItem $path -Filter *.nca)
$total = $files.Length
$c = 0
foreach ($file in $files)
{
    $c++
    Write-Progress -Activity 'Renaming NCAs' -Status "Checking file $c/$total" -PercentComplete ($c * 100.0 / $total)
    $hacout = & "$hactool" -k "$prodkeys" -i "$($file.FullName)" *>&1 | Out-String
    if ($hacout -match '\bContent Type:\s+Meta\b')
    {
        if (-not $file.Name.EndsWith('.cnmt.nca'))
        {
            Get-Item $file.FullName | Rename-Item -Path "$($file.FullName)" -NewName { $file.Name -replace '.nca', '.cnmt.nca' }
            Write-Host "Renamed $($file.Name)"
        }
        else
        {
            Write-Host "Skipped $($file.Name)"
        }
    }
}
Write-Progress -Activity 'Renaming NCAs' -Completed

@deejay87
Copy link

perfect 13xforever :)

@Pysis868
Copy link

Pysis868 commented Apr 22, 2022

For deejay87's "Failed to match key" issue: SciresM/hactool#79.

Also my own little script:

iterateFiles -iname '*.nca' ! -iname '*.cnmt.nca' | while read file;
  if hactool -i "$file" | grep -iP '\bContent Type:\s+Meta\b';
    echo "$file";
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment