Skip to content

Instantly share code, notes, and snippets.

@storycraft
Last active March 16, 2021 08:12
Show Gist options
  • Save storycraft/98fe8d6b4f122a82c44daa8a21f78f14 to your computer and use it in GitHub Desktop.
Save storycraft/98fe8d6b4f122a82c44daa8a21f78f14 to your computer and use it in GitHub Desktop.
HDD Sheriff 9 bootrom.bin password patch generator
#include <stdio.h>
#include <string.h>
long long int setPassword(char *password, int pwdLength) {
if (pwdLength <= 0) return 0xFFFFFFFFLL;
unsigned int result = -1;
unsigned short encryptShifter;
unsigned short encryptedChar;
char lastEncryptedChar;
char lowEncryptedCharBit;
int lastResult = -1;
int shiftedLastResult = -1;
int index, encryptCount;
for (index = 0; index < pwdLength; index++) {
encryptedChar = (password[index] ^ result) & 0xff;
shiftedLastResult = lastResult >> 8;
encryptShifter = 0;
for (encryptCount = 0; encryptCount < 8; encryptCount++) {
lastEncryptedChar = encryptedChar;
lowEncryptedCharBit = encryptShifter & 1;
encryptShifter >>= 1;
encryptedChar = (encryptedChar >> 1) | (lowEncryptedCharBit << 15);
if (lastEncryptedChar % 2 != 0) {
encryptedChar ^= 0x8320;
encryptShifter ^= 0xEDB8;
}
}
result = ((encryptedChar ^ shiftedLastResult) & 0xffff) | (((encryptShifter ^ (shiftedLastResult >> 16)) & 0xffff) << 16);
lastResult = result;
}
return result;
}
int main() {
char password[32];
printf("Input password (max length: 32): ");
scanf("%s", password);
long long int res = setPassword(password, strlen(password));
printf("result: %lld\n", res);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment