bitcookies / winrar-keygen

Principle of WinRAR key generation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Format string causes undefined behavior

Sonic-The-Hedgehog-LNK1123 opened this issue · comments

The format string "60%060s%060s" at:

RegInfo.Items[1] = HelperStringFormat("60%060s%060s", LicenseTypeSignatureS.c_str(), LicenseTypeSignatureR.c_str());

and
RegInfo.Items[2] = HelperStringFormat("60%060s%060s", UserNameSignatureS.c_str(), UserNameSignatureR.c_str());

is not valid, the "0" flag cannot be combined with the "s" specifier.

The string should be replaced with "60%s%s" like this:

RegInfo.Items[1] = HelperStringFormat("60%060s%060s", LicenseTypeSignatureS.c_str(), LicenseTypeSignatureR.c_str());

should be replaced by:

RegInfo.Items[1] = HelperStringFormat("60%s%s", LicenseTypeSignatureS.c_str(), LicenseTypeSignatureR.c_str());

and

RegInfo.Items[2] = HelperStringFormat("60%060s%060s", UserNameSignatureS.c_str(), UserNameSignatureR.c_str());

should be replaced by:

RegInfo.Items[2] = HelperStringFormat("60%s%s", UserNameSignatureS.c_str(), UserNameSignatureR.c_str()); 

The changes introduced in #6 already ensure the strings to be formatted are exactly 60 chars.

Thanks, I'll take a look. 👍

I found a bug, the keys generated by Github Actions are all invalid. 😥

I can't find the reason, is it because of the cloud windows coding problem?

If you have a spare time, can you help to check it out?

I find that:

The key generated in this way is valid:

winrar-keygen.exe text1 text2"

but the key generated in this way is invalid:

winrar-keygen.exe text1 text2 > rarreg.key

Ohh. It's because powershell is outputting in UTF16-LE format by default, which is causing the error. I fixed.

Format string issues was also fixed using your suggestion. Thanks again! 😄