Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: A way to tell whether a file has been updated by the update NCA #55

Open
OatmealDome opened this issue May 2, 2019 · 1 comment

Comments

@OatmealDome
Copy link

OatmealDome commented May 2, 2019

Basically, the --onlyupdated flag from hactool and a way to access this information programatically through IFile. I have gotten this working, but unfortunately all the necessary information is private, so an "official" way would be nice.

// Get the file
IFile file = romfs.OpenFile("/file.txt", OpenMode.Read);

// Get the offset
long fileOffset = nca.Sections[1].Header.IvfcInfo.LevelHeaders[5].Offset + (long)file.GetType().GetProperty("Offset", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(file);

// Get the first RelocationEntry from the IndirectStorage
RelocationEntry relocationEntry = (RelocationEntry)indirectStorage.GetType().GetMethod("GetRelocationEntry", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(indirectStorage, new object[] { fileOffset });

long remaining = file.GetSize();
long inPos = fileOffset;

// "Read" the whole file and check every entry's source, kinda copied from IndirectStorage b/c laziness
while (remaining > 0)
{
    if (relocationEntry.SourceIndex != 0)
    {
        // This file has been updated, do whatever
        break;
    }

    int bytesToRead = (int)Math.Min(relocationEntry.OffsetEnd - inPos, remaining);

    remaining -= bytesToRead;
    inPos += bytesToRead;

    if (inPos >= relocationEntry.OffsetEnd)
    {
        relocationEntry = relocationEntry.Next;
    }
}
@Thealexbarney
Copy link
Owner

This sort of thing is planned, but I'm not sure how I'm going to do it yet.

Exposing the relocation table and the rom file table and letting the application figure it out is an option, although the bucket tree APIs will change in the near future.

Another option would be to have the library parse that stuff itself and return a list of offsets and sources for each file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants