PS5NorModifier icon indicating copy to clipboard operation
PS5NorModifier copied to clipboard

Convert console type logic referencing incorrect replace length value

Open rbh92 opened this issue 8 months ago • 0 comments

See lines 717 - 759, 850 - 892, 982 - 1024 of Program.cs

// Modify the values to set the file as "Slim Edition"
try
{
    byte[] find = ConvertHexStringToByteArray(Regex.Replace("22020101", "0x|[ ,]", string.Empty).Normalize().Trim());
    byte[] replace = ConvertHexStringToByteArray(Regex.Replace("22010101", "0x|[ ,]", string.Empty).Normalize().Trim());

    byte[] bytes = File.ReadAllBytes(pathToDump);
    foreach (int index in PatternAt(bytes, find))
    {
        for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++)
        {
            bytes[i] = replace[replaceIndex];
        }
        File.WriteAllBytes(pathToDump, bytes);
    }

    byte[] find2 = ConvertHexStringToByteArray(Regex.Replace("22030101", "0x|[ ,]", string.Empty).Normalize().Trim());
    byte[] replace2 = ConvertHexStringToByteArray(Regex.Replace("22010101", "0x|[ ,]", string.Empty).Normalize().Trim());

    foreach (int index in PatternAt(bytes, find2))
    {
        for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++)
        {
            bytes[i] = replace2[replaceIndex];
        }
        File.WriteAllBytes(pathToDump, bytes);
    }

    System.Console.WriteLine("Your BIOS file has been updated successfully. The new .bin file will now report to");
    System.Console.WriteLine("the PlayStation 5 as a 'slim edition' console.");
    System.Console.WriteLine("Press Enter to continue...");
    System.Console.ReadLine();
    confirmed = true;
    break;
}
catch (Exception ex)
{
    // Handle any exceptions that occur while writing to the file
    System.Console.WriteLine("Error updating the binary file: " + ex.Message);
    System.Console.WriteLine("Please try again! Press Enter to continue...");
    System.Console.ReadLine();
    confirmed = true;
    break;
}

The foreach loop for the find2/replace2 values:

foreach (int index in PatternAt(bytes, find2))
{
    for (int i = index, replaceIndex = 0; i < bytes.Length && replaceIndex < replace.Length; i++, replaceIndex++)
    {
        bytes[i] = replace2[replaceIndex];
    }
    File.WriteAllBytes(pathToDump, bytes);
}

we are referencing replace.Length in the for loop instead of replace2.Length

This isn't a massive issue, as the replace values are always the same length.

rbh92 avatar May 17 '25 07:05 rbh92