Skip to content

Convert console type logic referencing incorrect replace length value #41

@rbh92

Description

@rbh92

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions