Skip to content
This repository has been archived by the owner on Sep 5, 2021. It is now read-only.

Commit

Permalink
Improved UX, Closes #2. Fixed padding getting trimmed. Fixed #5
Browse files Browse the repository at this point in the history
Signed-off-by: Adubbz <[email protected]>
  • Loading branch information
Adubbz committed May 31, 2018
1 parent 4e135aa commit 773d3ce
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 157 deletions.
67 changes: 67 additions & 0 deletions source/diagnostics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "diagnostics.h"

#include "goipc.h"

void printDebugInfo()
{
Result rc;
u16 safeSystemVersion;

if (g_nsvmInitialized)
{
if (R_SUCCEEDED(rc = nsvmGetSafeSystemVersion(&safeSystemVersion)))
printf("nsvmGetSafeSystemVersion: %u\n", safeSystemVersion);
else
printf("Failed to get current value from nsvmGetSafeSystemVersion. Error code: 0x%08x\n", rc);
}
else
printf("Cannot get value of nsvmGetSafeSystemVersion as ns:vm hasn't been initialized.");
}

NagStatus checkNagStatus(void)
{
if (!g_nsvmInitialized)
{
// ns:vm is not essential to proceed, however users need to be warned that this means there is less verification
// in place.
return UNKNOWN;
}

Result rc;
u8 needsUpdate;

if (R_FAILED(rc = nsvmNeedsUpdateVulnerability(&needsUpdate)))
{
printf("Failed to get current value from nsvmNeedsUpdateVulnerability. Error code: 0x%08x\n", rc);
return FAILED;
}

if (!needsUpdate)
return UNNAGGED;

u64 needsUpdateSettingSize;
u64 needsUpdateSetting;

if (R_FAILED(rc = setsysGetSettingsItemValueSize("vulnerability", "needs_update_vulnerability_policy", &needsUpdateSettingSize)))
{
printf("Could not get vulnerability!needs_update_vulnerability_policy size! Error code: 0x%08x\n", rc);
return FAILED;
}

if (needsUpdateSettingSize != 4)
{
printf("Invalid needs_update_vulnerability_policy size %lu. This likely means you are on an unsupported firmware.", needsUpdateSettingSize);
return FAILED;
}

if (R_FAILED(rc = setsysGetSettingsItemValue("vulnerability", "needs_update_vulnerability_policy", &needsUpdateSetting)))
{
printf("Could not get the value of vulnerability!needs_update_vulnerability_policy! Error code: 0x%08x\n", rc);
return FAILED;
}

if (needsUpdateSetting)
return NAGGED_SETTING;

return NAGGED_NOSETTING;
}
16 changes: 16 additions & 0 deletions source/diagnostics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <stdbool.h>
#include <switch.h>

typedef enum
{
FAILED,
UNKNOWN,
NAGGED_NOSETTING,
NAGGED_SETTING,
UNNAGGED
} NagStatus;

void printDebugInfo();
NagStatus checkNagStatus(void);
6 changes: 3 additions & 3 deletions source/goipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Result goipcInitialize(void)

if (R_FAILED(rc = smGetService(&g_pmshellSrv, "pm:shell")))
{
printf("Could not obtain pm:shell service. Error code: 0x%02x\n", rc);
printf("Could not obtain pm:shell service. Error code: 0x%08x\n", rc);
return rc;
}

if (R_FAILED(rc = smGetService(&g_setsysSrv, "set:sys")))
{
printf("Could not obtain set:sys service. Error code: 0x%02x\n", rc);
printf("Could not obtain set:sys service. Error code: 0x%08x\n", rc);
return rc;
}

Expand All @@ -25,7 +25,7 @@ Result nsvmInitialize(void)

if (R_FAILED(rc = smGetService(&g_nsvmSrv, "ns:vm")))
{
printf("Could not obtain ns:vm service. Error code: 0x%02x\n", rc);
printf("Could not obtain ns:vm service. Error code: 0x%08x\n", rc);
return rc;
}

Expand Down
3 changes: 3 additions & 0 deletions source/goipc.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include <stdbool.h>
#include <stdio.h>
#include <switch.h>

#define SET_MAX_NAME_SIZE 0x30

bool g_nsvmInitialized;

Service g_nsvmSrv;
Service g_pmshellSrv;
Service g_setfdSrv;
Expand Down
57 changes: 0 additions & 57 deletions source/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,6 @@

#define BUF_SIZE 0x50000

u8 verifyNagBytes(const char *save_path, u32 bytes)
{
FILE *f = fopen(save_path, "rb");

if (f == NULL)
{
printf("Failed to open save file to check bytes!\n");
return 1;
}

fseek(f, 0x8, 0);

u32 nagBytes;
fread(&nagBytes, sizeof(u32), 1, f);
fclose(f);

if (nagBytes == bytes)
{
printf("Valid nag bytes detected: 0x%02x\n", nagBytes);
return 0;
}
else
{
printf("Invalid nag bytes detected: 0x%02x\nBailing out...\n", nagBytes);
return 1;
}
}

u8 patchNagBytes(const char *save_path)
{
FILE *f = fopen(save_path, "wb");

if (f == NULL)
{
printf("Failed to open save file to patch bytes!\n");
return 1;
}

fseek(f, 0x8, 0);
u32 unnagBytes = 0x100000C8;
printf("Patching nag bytes to 0x%02x\n", unnagBytes);
fwrite(&unnagBytes, sizeof(u32), 1, f);
fclose(f);

fsdevCommitDevice("ns_ssversion");

printf("Verifying patching...\n");
if (verifyNagBytes(save_path, unnagBytes) == 0)
{
return 0;
}
else
{
return 1;
}
}

void copyFile(const char *src_path, const char *dst_path)
{
FILE *src = fopen(src_path, "rb");
Expand Down
3 changes: 0 additions & 3 deletions source/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ typedef struct
u8 is_dir;
} dir_ent_t;

u8 verifyNagBytes(const char *save_path, u32 bytes);
u8 patchNagBytes(const char *save_path);

void copyFile(const char *src_path, const char *dst_path);
int listDir(const char *path, dir_ent_t **dir_entries_out);
Loading

0 comments on commit 773d3ce

Please sign in to comment.