mirror of
https://github.com/rvtr/unlaunch-installer_dev.git
synced 2026-01-26 13:43:08 -05:00
Skip the first cluster when checking for valid unlaunch install
The first cluster now is properly used by unlaunch to save its configs, so it will never be the same across runs of the installer, to account for this, skip the first 0x4000 bytes when checking for its sha1, so that the user configurable part is ignored
This commit is contained in:
parent
f3b3b502bc
commit
773fe2b7a5
@ -176,9 +176,9 @@ bool writeToFile(FILE* fd, const char* buffer, size_t size)
|
|||||||
return toWrite == 0;
|
return toWrite == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool calculateFileSha1(FILE* f, void* digest)
|
bool calculateFileSha1Offset(FILE* f, void* digest, size_t offset)
|
||||||
{
|
{
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, offset, SEEK_SET);
|
||||||
|
|
||||||
swiSHA1context_t ctx;
|
swiSHA1context_t ctx;
|
||||||
ctx.sha_block = 0; //this is weird but it has to be done
|
ctx.sha_block = 0; //this is weird but it has to be done
|
||||||
@ -198,14 +198,14 @@ bool calculateFileSha1(FILE* f, void* digest)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool calculateFileSha1Path(const char* path, void* digest)
|
bool calculateFileSha1PathOffset(const char* path, void* digest, size_t offset)
|
||||||
{
|
{
|
||||||
FILE* targetFile = fopen(path, "rb");
|
FILE* targetFile = fopen(path, "rb");
|
||||||
if (!targetFile)
|
if (!targetFile)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool res = calculateFileSha1(targetFile, digest);
|
bool res = calculateFileSha1Offset(targetFile, digest, offset);
|
||||||
fclose(targetFile);
|
fclose(targetFile);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,15 @@ unsigned long long getFileSize(FILE* f);
|
|||||||
unsigned long long getFileSizePath(char const* path);
|
unsigned long long getFileSizePath(char const* path);
|
||||||
bool toggleFileReadOnly(const char* path, bool readOnly);
|
bool toggleFileReadOnly(const char* path, bool readOnly);
|
||||||
bool writeToFile(FILE* fd, const char* buffer, size_t size);
|
bool writeToFile(FILE* fd, const char* buffer, size_t size);
|
||||||
bool calculateFileSha1(FILE* f, void* digest);
|
bool calculateFileSha1Offset(FILE* f, void* digest, size_t offset);
|
||||||
bool calculateFileSha1Path(const char* path, void* digest);
|
bool calculateFileSha1PathOffset(const char* path, void* digest, size_t offset);
|
||||||
|
static inline bool calculateFileSha1(FILE* f, void* digest) {
|
||||||
|
return calculateFileSha1Offset(f, digest, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool calculateFileSha1Path(const char* path, void* digest) {
|
||||||
|
return calculateFileSha1PathOffset(path, digest, 0);
|
||||||
|
}
|
||||||
|
|
||||||
//Directories
|
//Directories
|
||||||
bool safeCreateDir(const char* path);
|
bool safeCreateDir(const char* path);
|
||||||
|
|||||||
@ -235,9 +235,11 @@ bool uninstallUnlaunch(const consoleInfo& info, bool removeHNAABackup)
|
|||||||
|
|
||||||
static bool writeUnlaunchTmd(const char* path)
|
static bool writeUnlaunchTmd(const char* path)
|
||||||
{
|
{
|
||||||
Sha1Digest expectedDigest, actualDigest;
|
static constexpr auto unlaunchShaOffset = 0x4000;
|
||||||
swiSHA1Calc(expectedDigest.data(), unlaunchInstallerBuffer, unlaunchInstallerSize + 520);
|
Sha1Digest expectedDigest, actualDigest;
|
||||||
if(calculateFileSha1Path(path, actualDigest.data()) && expectedDigest == actualDigest)
|
swiSHA1Calc(expectedDigest.data(), unlaunchInstallerBuffer + unlaunchShaOffset,
|
||||||
|
(unlaunchInstallerSize + 520) - unlaunchShaOffset);
|
||||||
|
if(calculateFileSha1PathOffset(path, actualDigest.data(), unlaunchShaOffset) && expectedDigest == actualDigest)
|
||||||
{
|
{
|
||||||
// the tmd hasn't changed, no need to do anything
|
// the tmd hasn't changed, no need to do anything
|
||||||
return true;
|
return true;
|
||||||
@ -260,7 +262,7 @@ static bool writeUnlaunchTmd(const char* path)
|
|||||||
|
|
||||||
fclose(targetTmd);
|
fclose(targetTmd);
|
||||||
|
|
||||||
if(!calculateFileSha1Path(path, actualDigest.data()) || expectedDigest != actualDigest)
|
if(!calculateFileSha1PathOffset(path, actualDigest.data(), unlaunchShaOffset) || expectedDigest != actualDigest)
|
||||||
{
|
{
|
||||||
removeIfExists(path);
|
removeIfExists(path);
|
||||||
messageBox("\x1B[31mError:\x1B[33m Unlaunch tmd was not properly written\n");
|
messageBox("\x1B[31mError:\x1B[33m Unlaunch tmd was not properly written\n");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user