Skip to content

Conversation

Tobiaqs
Copy link

@Tobiaqs Tobiaqs commented Feb 8, 2021

NKit does not properly find recovery data on *nix systems due to a Regex that only accepts Windows paths. This fixes that by accepting both types of slashes.

See #13 for more info.

@bcomnes
Copy link

bcomnes commented Mar 6, 2021

I think I'm running into this issue.

@bcomnes
Copy link

bcomnes commented Mar 6, 2021

@Tobiaqs any hints on how to build Nkit on nix with mono installed?

@Tobiaqs
Copy link
Author

Tobiaqs commented Mar 6, 2021

@bcomnes
This automates what I used to build NKit on Pop_OS! You'll need Docker though, or replace the Docker step by running dotnet build in the $PWD/NKit folder.

https://gist.github.com/Tobiaqs/34420144ade5f20609bb628779b3430f

public static string GetUpdatePartition(Settings settings, uint crc)
{
Regex m = new Regex(@"\\([A-Z0-9]{40})_([A-Z]+)_" + crc.ToString("X8") + "$", RegexOptions.IgnoreCase);
Regex m = new Regex(@"[/|\\]([A-Z0-9]{40})_([A-Z]+)_" + crc.ToString("X8") + "$", RegexOptions.IgnoreCase);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be wiser to use the Path.DirectorySeparatorChar character provided by the IO library. This will make sure that the regex is platform agnostic. I do not have visual studio installed at the moment but I think the code would look something like this

Suggested change
Regex m = new Regex(@"[/|\\]([A-Z0-9]{40})_([A-Z]+)_" + crc.ToString("X8") + "$", RegexOptions.IgnoreCase);
Regex m = new Regex(Path.DirectorySeparatorChar+@"([A-Z0-9]{40})_([A-Z]+)_" + crc.ToString("X8") + "$", RegexOptions.IgnoreCase);

Nonetheless, I am a bit skeptical on whether the Path.DirectorySeparatorChar would be properly parsed by the Regex builder if the Path.DirectorySeparatorChar is ""
We could propose a switch statement that properly builds the regexp.

The reason I want to avoid using [/|\] is because in extreme cases it could match wrongly

@pollev
Copy link

pollev commented Jan 16, 2022

Ran in to this issue. I would like to see this added as well!

@cgarz
Copy link

cgarz commented Feb 20, 2022

Does this fix the crc always being 00000000? Might help #5 if so.
Edit: After testing unfortunately it didn't help.

@ZLima12
Copy link

ZLima12 commented Feb 26, 2022

I've been hitting a wall for the last hour while trying to use this tool, I had a feeling there was something wrong with the detection. This fix would be appreciated!

@ZLima12
Copy link

ZLima12 commented Feb 27, 2022

FWIW, I was able to exploit the naive regex by renaming all the recovery files to include a backslash as the first character of their filename. After doing that, everything worked as expected.

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

Successfully merging this pull request may close these issues.

6 participants