fix: make printed messages clearer
This commit is contained in:
28
src/main.c
28
src/main.c
@@ -13,7 +13,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define MESSAGE_UNAUTHORIZED "You are not authorized to use this software!\n"
|
||||
|
||||
#define MAX_STEPS 1024u
|
||||
|
||||
@@ -32,9 +32,9 @@ int main(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "HWINFO: %s\n", hw_info_flatten(hwinfo));
|
||||
// fprintf(stderr, "HWINFO: %s\n", hw_info_flatten(hwinfo));
|
||||
|
||||
fprintf(stderr, "Key: ");
|
||||
fprintf(stderr, "[Info] Unique hardware key: ");
|
||||
for (int i = 0; i < 16; i++)
|
||||
fprintf(stderr, "%02X", key[i]);
|
||||
fprintf(stderr, "\n");
|
||||
@@ -53,7 +53,7 @@ int main(){
|
||||
}
|
||||
|
||||
if (license == NULL) {
|
||||
fprintf(stderr, "Could not find license file\n");
|
||||
fprintf(stderr, "[Error] Could not find license file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -66,10 +66,6 @@ int main(){
|
||||
fread(buf, 1, license_size, license);
|
||||
|
||||
|
||||
// void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key);
|
||||
// void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv);
|
||||
// void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
|
||||
|
||||
AES_init_ctx(&ctx, key);
|
||||
AES_init_ctx_iv(&ctx, key, nonce);
|
||||
AES_CTR_xcrypt_buffer(&ctx, buf, license_size);
|
||||
@@ -83,12 +79,12 @@ int main(){
|
||||
fread(begin, 1, sizeof(begin), decrypted_license);
|
||||
if(memcmp(begin, expected, sizeof(begin)) != 0) {
|
||||
// This happens when decryption fails
|
||||
printf("You are not authorized to use this software!\n");
|
||||
printf(MESSAGE_UNAUTHORIZED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const int maxninput = 255;
|
||||
printf("Please enter the flag: ");
|
||||
printf("Please enter your authorization code: ");
|
||||
fflush(stdout);
|
||||
char userinput[maxninput];
|
||||
fgets(userinput, sizeof(userinput), stdin);
|
||||
@@ -110,9 +106,9 @@ int main(){
|
||||
// Load elf, keep 512 bytes as safe buffer
|
||||
int load_status = load_elf_object_sections(decrypted_license, memory, cpu.mem_size - SIZE_USERDATA);
|
||||
if (load_status != LOAD_OK) {
|
||||
fprintf(stderr, "ELF load failed with code %d for decrypted license\n", load_status);
|
||||
fprintf(stderr, "[Error] ELF load failed with code %d for decrypted license\n", load_status);
|
||||
fflush(stderr);
|
||||
printf("ELF load failed with code %d\n", load_status);
|
||||
printf("[Error] ELF load failed with code %d\n", load_status);
|
||||
fflush(stdout);
|
||||
return 1;
|
||||
}
|
||||
@@ -121,7 +117,7 @@ int main(){
|
||||
int symbol_status = resolve_elf_symbol_memory_offset(
|
||||
decrypted_license, EMU_ENTRY_SYMBOL, cpu.mem_size, &entry_offset);
|
||||
if (symbol_status != LOAD_OK) {
|
||||
fprintf(stderr, "Entry symbol '%s' resolve failed with code %d\n",
|
||||
fprintf(stderr, "[Error] Entry symbol '%s' resolve failed with code %d\n",
|
||||
EMU_ENTRY_SYMBOL, symbol_status);
|
||||
return 2;
|
||||
}
|
||||
@@ -139,16 +135,16 @@ int main(){
|
||||
}
|
||||
|
||||
if (steps == MAX_STEPS) {
|
||||
fprintf(stderr, "Execution did not halt within %u steps\n", MAX_STEPS);
|
||||
fprintf(stderr, "[Error] Execution did not halt within %u steps\n", MAX_STEPS);
|
||||
return 2;
|
||||
}
|
||||
|
||||
uint32_t result = (uint32_t)cpu.x[10];
|
||||
|
||||
if(result == 1) {
|
||||
printf("Congrats! That's the flag!\n");
|
||||
printf("License activated successfully!\n");
|
||||
} else {
|
||||
printf("Nope, sorry, that's incorrect!\n");
|
||||
printf(MESSAGE_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user