diff --git a/ctrtool/cia.c b/ctrtool/cia.c
index 91333bd..c2ba55b 100644
--- a/ctrtool/cia.c
+++ b/ctrtool/cia.c
@@ -46,7 +46,7 @@ void cia_save(cia_context* ctx, u32 type, u32 flags)
filepath* path = 0;
ctr_tmd_body *body;
ctr_tmd_contentchunk *chunk;
- int i;
+ unsigned int i;
char tmpname[255];
switch(type)
@@ -151,7 +151,7 @@ void cia_save_blob(cia_context *ctx, char *out_path, u64 offset, u64 size, int d
{
u32 max = sizeof(buffer);
if (max > size)
- max = size;
+ max = (u32) size;
if (max != fread(buffer, 1, max, ctx->file))
{
@@ -195,9 +195,9 @@ void cia_process(cia_context* ctx, u32 actions)
ctx->sizemeta = getle32(ctx->header.metasize);
ctx->offsetcerts = align(ctx->sizeheader, 64);
- ctx->offsettik = align(ctx->offsetcerts + ctx->sizecert, 64);
- ctx->offsettmd = align(ctx->offsettik + ctx->sizetik, 64);
- ctx->offsetcontent = align(ctx->offsettmd + ctx->sizetmd, 64);
+ ctx->offsettik = align((u32) (ctx->offsetcerts + ctx->sizecert), 64);
+ ctx->offsettmd = align((u32) (ctx->offsettik + ctx->sizetik), 64);
+ ctx->offsetcontent = align((u32) (ctx->offsettmd + ctx->sizetmd), 64);
ctx->offsetmeta = align64(ctx->offsetcontent + ctx->sizecontent, 64);
if (actions & InfoFlag)
@@ -253,7 +253,7 @@ void cia_verify_contents(cia_context *ctx, u32 actions)
ctr_tmd_contentchunk *chunk;
u8 *verify_buf;
u32 content_size=0;
- int i;
+ unsigned i;
// verify TMD content hashes, requires decryption ..
body = tmd_get_body(&ctx->tmd);
diff --git a/ctrtool/ctr.c b/ctrtool/ctr.c
index 6948bf8..e5198f7 100644
--- a/ctrtool/ctr.c
+++ b/ctrtool/ctr.c
@@ -244,7 +244,7 @@ int ctr_rsa_verify_hash(const u8 signature[0x100], const u8 hash[0x20], rsakey20
{
ctr_rsa_context ctx;
u32 result;
- u8 output[0x100];
+// u8 output[0x100];
if (key->keytype == RSAKEY_INVALID)
return Fail;
diff --git a/ctrtool/ctrtool.vcxproj b/ctrtool/ctrtool.vcxproj
index d16bc57..71596d6 100644
--- a/ctrtool/ctrtool.vcxproj
+++ b/ctrtool/ctrtool.vcxproj
@@ -54,7 +54,7 @@
Disabled
windows;.;%(AdditionalIncludeDirectories)
- WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
true
EnableFastChecks
MultiThreadedDebugDLL
@@ -75,15 +75,14 @@
MaxSpeed
true
windows;.;%(AdditionalIncludeDirectories)
- WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- MultiThreadedDLL
+ WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ MultiThreaded
true
Level3
ProgramDatabase
- c:\dev\tools\bin\ctrtool.exe
true
Console
true
@@ -100,6 +99,7 @@
+
@@ -132,6 +132,7 @@
+
diff --git a/ctrtool/ctrtool.vcxproj.filters b/ctrtool/ctrtool.vcxproj.filters
index 075c29d..f7862f2 100644
--- a/ctrtool/ctrtool.vcxproj.filters
+++ b/ctrtool/ctrtool.vcxproj.filters
@@ -117,6 +117,9 @@
Source Files
+
+ Source Files
+
@@ -209,5 +212,8 @@
Header Files
+
+ Header Files
+
\ No newline at end of file
diff --git a/ctrtool/cwav.c b/ctrtool/cwav.c
index 4c1242d..cf9f59b 100644
--- a/ctrtool/cwav.c
+++ b/ctrtool/cwav.c
@@ -429,7 +429,7 @@ int cwav_dspadpcm_setup(cwav_dspadpcmstate* state, cwav_context* ctx, int isloop
}
state->channelstate[i].samplebuffer = state->samplebuffer + SAMPLECOUNT * i;
- state->channelstate[i].sampleoffset = ctx->offset + getle32(adpcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset;
+ state->channelstate[i].sampleoffset = (u32) (ctx->offset + getle32(adpcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset);
if (isloop)
{
state->channelstate[i].yn1 = getle16(adpcminfo->loopyn1);
@@ -627,7 +627,7 @@ int cwav_imaadpcm_setup(cwav_imaadpcmstate* state, cwav_context* ctx, int isloop
}
state->channelstate[i].samplebuffer = state->samplebuffer + SAMPLECOUNT * i;
- state->channelstate[i].sampleoffset = ctx->offset + getle32(adpcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset;
+ state->channelstate[i].sampleoffset = (u32) (ctx->offset + getle32(adpcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset);
if (isloop)
{
state->channelstate[i].data = getle16(adpcminfo->loopdata);
@@ -826,7 +826,7 @@ int cwav_pcm_setup(cwav_pcmstate* state, cwav_context* ctx, int isloop)
cwav_channel* pcmchannel = &ctx->channel[i];
state->channelstate[i].samplebuffer = state->samplebuffer + SAMPLECOUNT * i;
- state->channelstate[i].sampleoffset = ctx->offset + getle32(pcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset;
+ state->channelstate[i].sampleoffset = (u32) (ctx->offset + getle32(pcmchannel->info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8 + startoffset);
stream_in_allocate(&state->channelstate[i].instreamctx, BUFFERSIZE, ctx->file);
stream_in_seek(&state->channelstate[i].instreamctx, state->channelstate[i].sampleoffset);
}
@@ -932,7 +932,7 @@ void cwav_print(cwav_context* ctx)
cwav_header* header = &ctx->header;
cwav_infoheader* infoheader = &ctx->infoheader;
u32 i;
- u32 infoheaderoffset = ctx->offset + getle32(ctx->header.infoblockref.offset);
+ u32 infoheaderoffset = (u32) (ctx->offset + getle32(ctx->header.infoblockref.offset));
u32 channelcount = getle32(infoheader->channelcount);
fprintf(stdout, "Header: %c%c%c%c\n", header->magic[0], header->magic[1], header->magic[2], header->magic[3]);
@@ -962,7 +962,7 @@ void cwav_print(cwav_context* ctx)
{
u32 channeloffset = infoheaderoffset + 0x1C + getle32(ctx->channel[i].inforef.offset);
u32 codecoffset = channeloffset + getle32(ctx->channel[i].info.codecref.offset);
- u32 sampleoffset = ctx->offset + getle32(ctx->channel[i].info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8;
+ u32 sampleoffset = (u32) (ctx->offset + getle32(ctx->channel[i].info.sampleref.offset) + getle32(ctx->header.datablockref.offset) + 8);
fprintf(stdout, "Channel %d:\n", i);
fprintf(stdout, " > Channel ref idtype: 0x%04X\n", getle16(ctx->channel[i].inforef.idtype));
diff --git a/ctrtool/exheader.c b/ctrtool/exheader.c
index 9715616..e9a6af1 100644
--- a/ctrtool/exheader.c
+++ b/ctrtool/exheader.c
@@ -1,3 +1,4 @@
+#include
#include
#include
@@ -5,6 +6,7 @@
#include "exheader.h"
#include "utils.h"
#include "ncch.h"
+#include "syscalls.h"
#include
void exheader_init(exheader_context* ctx)
@@ -193,7 +195,7 @@ int exheader_process(exheader_context* ctx, u32 actions)
exheader_verify(ctx);
if (actions & InfoFlag)
- exheader_print(ctx);
+ exheader_print(ctx, actions);
return 1;
}
@@ -231,7 +233,7 @@ void exheader_print_arm9accesscontrol(exheader_context* ctx)
}
}
-void exheader_print_arm11kernelcapabilities(exheader_context* ctx)
+void exheader_print_arm11kernelcapabilities(exheader_context* ctx, u32 actions)
{
unsigned int i, j;
unsigned int systemcallmask[8];
@@ -294,42 +296,66 @@ void exheader_print_arm11kernelcapabilities(exheader_context* ctx)
}
fprintf(stdout, "Allowed systemcalls: ");
- for(i=0; i<8; i++)
+ if(!(actions & ShowSyscallsFlag))
{
- for(j=0; j<24; j++)
+ for(i=0; i<8; i++)
{
- svcmask = systemcallmask[i];
-
- if (svcmask & (1< 0x%02X %s\n", svcid, svcname);
}
}
}
}
- if (svccount & 7)
- fprintf(stdout, "\n");
- if (svccount == 0)
- fprintf(stdout, "none\n");
-
fprintf(stdout, "Allowed interrupts: ");
for(i=0; i<0x7F; i++)
@@ -618,7 +644,7 @@ const char* exheader_getsystemmodeextstring(u8 systemmodeext, u8 systemmode)
}
-void exheader_print(exheader_context* ctx)
+void exheader_print(exheader_context* ctx, u32 actions)
{
u32 i;
u64 savedatasize = getle64(ctx->header.systeminfo.savedatasize);
@@ -679,7 +705,7 @@ void exheader_print(exheader_context* ctx)
fprintf(stdout, "Main thread priority: %d %s\n", ctx->system_local_caps.priority, exheader_getvalidstring(ctx->validpriority));
// print resource limit descriptor too? currently mostly zeroes...
exheader_print_arm11storageinfo(ctx);
- exheader_print_arm11kernelcapabilities(ctx);
+ exheader_print_arm11kernelcapabilities(ctx, actions);
exheader_print_arm9accesscontrol(ctx);
fprintf(stdout, "Service access: %s\n", exheader_getvalidstring(ctx->validservicecontrol));
diff --git a/ctrtool/exheader.h b/ctrtool/exheader.h
index 9691e0f..9ac656f 100644
--- a/ctrtool/exheader.h
+++ b/ctrtool/exheader.h
@@ -194,7 +194,7 @@ int exheader_get_compressedflag(exheader_context* ctx);
void exheader_read(exheader_context* ctx, u32 actions);
int exheader_process(exheader_context* ctx, u32 actions);
const char* exheader_getvalidstring(int valid);
-void exheader_print(exheader_context* ctx);
+void exheader_print(exheader_context* ctx, u32 actions);
void exheader_verify(exheader_context* ctx);
int exheader_hash_valid(exheader_context* ctx);
int exheader_programid_valid(exheader_context* ctx);
diff --git a/ctrtool/filepath.c b/ctrtool/filepath.c
index 94321e2..366bb65 100644
--- a/ctrtool/filepath.c
+++ b/ctrtool/filepath.c
@@ -47,7 +47,7 @@ void filepath_append_utf16(filepath* fpath, const u8* name)
if (code > 0x7F)
code = '#';
- fpath->pathname[size++] = code;
+ fpath->pathname[size++] = (char) code;
}
fpath->pathname[size] = 0;
diff --git a/ctrtool/ivfc.c b/ctrtool/ivfc.c
index fb7a5f0..041afda 100644
--- a/ctrtool/ivfc.c
+++ b/ctrtool/ivfc.c
@@ -51,7 +51,7 @@ void ivfc_fseek(ivfc_context* ctx, u64 offset)
u64 data_pos = offset - ctx->offset;
fseeko64(ctx->file, offset, SEEK_SET);
ctr_init_counter(&ctx->aes, ctx->key, ctx->counter);
- ctr_add_counter(&ctx->aes, data_pos / 0x10);
+ ctr_add_counter(&ctx->aes, (u32) (data_pos / 0x10));
}
size_t ivfc_fread(ivfc_context* ctx, void* buffer, size_t size, size_t count)
@@ -128,7 +128,7 @@ void ivfc_verify(ivfc_context* ctx, u32 flags)
{
ivfc_level* level = ctx->level + i;
- blockcount = level->datasize / level->hashblocksize;
+ blockcount = (u32) (level->datasize / level->hashblocksize);
if (level->datasize % level->hashblocksize != 0)
{
fprintf(stderr, "Error, IVFC block size mismatch\n");
@@ -160,7 +160,7 @@ void ivfc_read(ivfc_context* ctx, u64 offset, u64 size, u8* buffer)
}
ivfc_fseek(ctx, ctx->offset + offset);
- if (size != ivfc_fread(ctx, buffer, 1, size))
+ if (size != ivfc_fread(ctx, buffer, 1, (size_t) size))
{
fprintf(stderr, "Error, IVFC could not read file\n");
return;
@@ -177,7 +177,7 @@ void ivfc_hash(ivfc_context* ctx, u64 offset, u64 size, u8* hash)
ivfc_read(ctx, offset, size, ctx->buffer);
- ctr_sha_256(ctx->buffer, size, hash);
+ ctr_sha_256(ctx->buffer, (u32) size, hash);
}
void ivfc_print(ivfc_context* ctx)
diff --git a/ctrtool/main.c b/ctrtool/main.c
index 4a7199b..8282c9b 100644
--- a/ctrtool/main.c
+++ b/ctrtool/main.c
@@ -58,6 +58,7 @@ static void usage(const char *argv0)
" --ncchkey=key Set ncch key.\n"
" --ncchsyskey=key Set ncch fixed system key.\n"
" --showkeys Show the keys being used.\n"
+ " --showsyscalls Show system call names instead of numbers.\n"
" -t, --intype=type Specify input file type [ncsd, ncch, exheader, cia, tmd, lzss,\n"
" firm, cwav, exefs, romfs]\n"
"LZSS options:\n"
@@ -66,7 +67,7 @@ static void usage(const char *argv0)
" -n, --ncch=index Specify NCCH partition index.\n"
" --exheader=file Specify Extended Header file path.\n"
" --logo=file Specify Logo file path.\n"
- " --plainrgn=file Specify Plain region file path"
+ " --plainrgn=file Specify Plain region file path\n"
" --exefs=file Specify ExeFS file path.\n"
" --exefsdir=dir Specify ExeFS directory path.\n"
" --romfs=file Specify RomFS file path.\n"
@@ -150,6 +151,7 @@ int main(int argc, char* argv[])
{"decompresscode", 0, NULL, 21},
{"titlekey", 1, NULL, 22},
{"plainrgn", 1, NULL, 23},
+ {"showsyscalls", 0, NULL, 24},
{NULL},
};
@@ -239,6 +241,7 @@ int main(int argc, char* argv[])
case 21: ctx.actions |= DecompressCodeFlag; break;
case 22: keyset_parse_titlekey(&tmpkeys, optarg, strlen(optarg)); break;
case 23: settings_set_plainrgn_path(&ctx.usersettings, optarg); break;
+ case 24: ctx.actions |= ShowSyscallsFlag; break;
default:
usage(argv[0]);
@@ -344,7 +347,7 @@ int main(int argc, char* argv[])
firm_init(&firmctx);
firm_set_file(&firmctx, ctx.infile);
- firm_set_size(&firmctx, ctx.infilesize);
+ firm_set_size(&firmctx, (u32) ctx.infilesize);
firm_set_usersettings(&firmctx, &ctx.usersettings);
firm_process(&firmctx, ctx.actions);
@@ -399,7 +402,7 @@ int main(int argc, char* argv[])
tmd_init(&tmdctx);
tmd_set_file(&tmdctx, ctx.infile);
- tmd_set_size(&tmdctx, ctx.infilesize);
+ tmd_set_size(&tmdctx, (u32) ctx.infilesize);
tmd_set_usersettings(&tmdctx, &ctx.usersettings);
tmd_process(&tmdctx, ctx.actions);
@@ -412,7 +415,7 @@ int main(int argc, char* argv[])
lzss_init(&lzssctx);
lzss_set_file(&lzssctx, ctx.infile);
- lzss_set_size(&lzssctx, ctx.infilesize);
+ lzss_set_size(&lzssctx, (u32) ctx.infilesize);
lzss_set_usersettings(&lzssctx, &ctx.usersettings);
lzss_process(&lzssctx, ctx.actions);
diff --git a/ctrtool/ncch.c b/ctrtool/ncch.c
index 7c06b23..8d2a9ff 100644
--- a/ctrtool/ncch.c
+++ b/ctrtool/ncch.c
@@ -48,7 +48,7 @@ void ncch_set_file(ncch_context* ctx, FILE* file)
void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type)
{
u32 version = getle16(ctx->header.version);
- u32 mediaunitsize = ncch_get_mediaunit_size(ctx);
+ u32 mediaunitsize = (u32) ncch_get_mediaunit_size(ctx);
u8* partitionid = ctx->header.partitionid;
u32 i;
u64 x = 0;
@@ -73,7 +73,7 @@ void ncch_get_counter(ncch_context* ctx, u8 counter[16], u8 type)
for(i=0; i<8; i++)
counter[i] = partitionid[i];
for(i=0; i<4; i++)
- counter[12+i] = x>>((3-i)*8);
+ counter[12+i] = (u8) (x>>((3-i)*8));
}
}
@@ -148,7 +148,7 @@ int ncch_extract_buffer(ncch_context* ctx, u8* buffer, u32 buffersize, u32* outs
u32 read_len = buffersize;
if (read_len > ctx->extractsize)
- read_len = ctx->extractsize;
+ read_len = (u32) ctx->extractsize;
*outsize = read_len;
@@ -234,7 +234,7 @@ clean:
void ncch_verify(ncch_context* ctx, u32 flags)
{
- u32 mediaunitsize = ncch_get_mediaunit_size(ctx);
+ u32 mediaunitsize = (u32) ncch_get_mediaunit_size(ctx);
u32 exefshashregionsize = getle32(ctx->header.exefshashregionsize) * mediaunitsize;
u32 romfshashregionsize = getle32(ctx->header.romfshashregionsize) * mediaunitsize;
u32 exheaderhashregionsize = getle32(ctx->header.extendedheadersize);
diff --git a/ctrtool/ncsd.c b/ctrtool/ncsd.c
index 384216a..4a7d928 100644
--- a/ctrtool/ncsd.c
+++ b/ctrtool/ncsd.c
@@ -120,7 +120,7 @@ void ncsd_print(ncsd_context* ctx)
char magic[5];
ctr_ncsdheader* header = &ctx->header;
unsigned int i;
- unsigned int mediaunitsize = ncsd_get_mediaunit_size(ctx);
+ unsigned int mediaunitsize = (unsigned int) ncsd_get_mediaunit_size(ctx);
memcpy(magic, header->magic, 4);
diff --git a/ctrtool/romfs.c b/ctrtool/romfs.c
index 5889bdc..f8c9ffb 100644
--- a/ctrtool/romfs.c
+++ b/ctrtool/romfs.c
@@ -50,7 +50,7 @@ void romfs_fseek(romfs_context* ctx, u64 offset)
u64 data_pos = offset - ctx->offset;
fseeko64(ctx->file, offset, SEEK_SET);
ctr_init_counter(&ctx->aes, ctx->key, ctx->counter);
- ctr_add_counter(&ctx->aes, data_pos / 0x10);
+ ctr_add_counter(&ctx->aes, (u32) (data_pos / 0x10));
}
size_t romfs_fread(romfs_context* ctx, void* buffer, size_t size, size_t count)
@@ -91,7 +91,7 @@ void romfs_process(romfs_context* ctx, u32 actions)
return;
}
- ctx->infoblockoffset = ctx->offset + 0x1000;
+ ctx->infoblockoffset = (u32) (ctx->offset + 0x1000);
romfs_fseek(ctx, ctx->infoblockoffset);
romfs_fread(ctx, &ctx->infoheader, 1, sizeof(romfs_infoheader));
@@ -363,7 +363,7 @@ void romfs_extract_datafile(romfs_context* ctx, u64 offset, u64 size, const osch
{
max = sizeof(buffer);
if (max > size)
- max = size;
+ max = (u32) size;
if (max != romfs_fread(ctx, buffer, 1, max))
{
diff --git a/ctrtool/syscalls.c b/ctrtool/syscalls.c
new file mode 100644
index 0000000..edf8e8c
--- /dev/null
+++ b/ctrtool/syscalls.c
@@ -0,0 +1,165 @@
+#include
+#include
+#include
+#include "syscalls.h"
+
+// List of 3DS system calls. NULL indicates unknown.
+static const char *const syscall_list[NUM_SYSCALLS] =
+{
+ NULL, // 00
+ "ControlMemory", // 01
+ "QueryMemory", // 02
+ "ExitProcess", // 03
+ "GetProcessAffinityMask", // 04
+ "SetProcessAffinityMask", // 05
+ "GetProcessIdealProcessor", // 06
+ "SetProcessIdealProcessor", // 07
+ "CreateThread", // 08
+ "ExitThread", // 09
+ "SleepThread", // 0A
+ "GetThreadPriority", // 0B
+ "SetThreadPriority", // 0C
+ "GetThreadAffinityMask", // 0D
+ "SetThreadAffinityMask", // 0E
+ "GetThreadIdealProcessor", // 0F
+ "SetThreadIdealProcessor", // 10
+ "GetCurrentProcessorNumber", // 11
+ "Run", // 12
+ "CreateMutex", // 13
+ "ReleaseMutex", // 14
+ "CreateSemaphore", // 15
+ "ReleaseSemaphore", // 16
+ "CreateEvent", // 17
+ "SignalEvent", // 18
+ "ClearEvent", // 19
+ "CreateTimer", // 1A
+ "SetTimer", // 1B
+ "CancelTimer", // 1C
+ "ClearTimer", // 1D
+ "CreateMemoryBlock", // 1E
+ "MapMemoryBlock", // 1F
+ "UnmapMemoryBlock", // 20
+ "CreateAddressArbiter", // 21
+ "ArbitrateAddress", // 22
+ "CloseHandle", // 23
+ "WaitSynchronization1", // 24
+ "WaitSynchronizationN", // 25
+ "SignalAndWait", // 26
+ "DuplicateHandle", // 27
+ "GetSystemTick", // 28
+ "GetHandleInfo", // 29
+ "GetSystemInfo", // 2A
+ "GetProcessInfo", // 2B
+ "GetThreadInfo", // 2C
+ "ConnectToPort", // 2D
+ "SendSyncRequest1", // 2E
+ "SendSyncRequest2", // 2F
+ "SendSyncRequest3", // 30
+ "SendSyncRequest4", // 31
+ "SendSyncRequest", // 32
+ "OpenProcess", // 33
+ "OpenThread", // 34
+ "GetProcessId", // 35
+ "GetProcessIdOfThread", // 36
+ "GetThreadId", // 37
+ "GetResourceLimit", // 38
+ "GetResourceLimitLimitValues", // 39
+ "GetResourceLimitCurrentValues", // 3A
+ "GetThreadContext", // 3B
+ "Break", // 3C
+ "OutputDebugString", // 3D
+ "ControlPerformanceCounter", // 3E
+ NULL, // 3F
+ NULL, // 40
+ NULL, // 41
+ NULL, // 42
+ NULL, // 43
+ NULL, // 44
+ NULL, // 45
+ NULL, // 46
+ "CreatePort", // 47
+ "CreateSessionToPort", // 48
+ "CreateSession", // 49
+ "AcceptSession", // 4A
+ "ReplyAndReceive1", // 4B
+ "ReplyAndReceive2", // 4C
+ "ReplyAndReceive3", // 4D
+ "ReplyAndReceive4", // 4E
+ "ReplyAndReceive", // 4F
+ "BindInterrupt", // 50
+ "UnbindInterrupt", // 51
+ "InvalidateProcessDataCache", // 52
+ "StoreProcessDataCache", // 53
+ "FlushProcessDataCache", // 54
+ "StartInterProcessDma", // 55
+ "StopDma", // 56
+ "GetDmaState", // 57
+ "RestartDma", // 58
+ NULL, // 59
+ NULL, // 5A
+ NULL, // 5B
+ NULL, // 5C
+ NULL, // 5D
+ NULL, // 5E
+ NULL, // 5F
+ "DebugActiveProcess", // 60
+ "BreakDebugProcess", // 61
+ "TerminateDebugProcess", // 62
+ "GetProcessDebugEvent", // 63
+ "ContinueDebugEvent", // 64
+ "GetProcessList", // 65
+ "GetThreadList", // 66
+ "GetDebugThreadContext", // 67
+ "SetDebugThreadContext", // 68
+ "QueryDebugProcessMemory", // 69
+ "ReadProcessMemory", // 6A
+ "WriteProcessMemory", // 6B
+ "SetHardwareBreakPoint", // 6C
+ "GetDebugThreadParam", // 6D
+ NULL, // 6E
+ NULL, // 6F
+ "ControlProcessMemory", // 70
+ "MapProcessMemory", // 71
+ "UnmapProcessMemory", // 72
+ "CreateCodeSet", // 73
+ NULL, // 74
+ "CreateProcess", // 75
+ "TerminateProcess", // 76
+ "SetProcessResourceLimits", // 77
+ "CreateResourceLimit", // 78
+ "SetResourceLimitValues", // 79
+ "AddCodeSegment", // 7A
+ "Backdoor", // 7B
+ "KernelSetState", // 7C
+ "QueryProcessMemory", // 7D
+ NULL, // 7E
+ NULL, // 7F
+};
+
+
+void syscall_get_name(char *output, size_t size, unsigned int call_num)
+{
+ typedef char StaticAssert[sizeof(syscall_list) / sizeof(syscall_list[0]) == NUM_SYSCALLS ? 1 : -1];
+
+ if (size == 0)
+ {
+ return;
+ }
+
+ const char *name = NULL;
+ if (call_num < (unsigned int) NUM_SYSCALLS)
+ {
+ name = syscall_list[call_num];
+ }
+
+ char name_buf[] = "UnknownXX";
+ sprintf(&name_buf[sizeof(name_buf) - 3], "%02X", call_num & 0xFFu);
+
+ name = name ? name : name_buf;
+
+ size_t length = strlen(name);
+ length = (length > (size - 1)) ? (size - 1) : length;
+
+ memcpy(output, name, length);
+ output[length] = '\0';
+}
diff --git a/ctrtool/syscalls.h b/ctrtool/syscalls.h
new file mode 100644
index 0000000..5afca89
--- /dev/null
+++ b/ctrtool/syscalls.h
@@ -0,0 +1,19 @@
+#ifndef _SYSCALLS_H_
+#define _SYSCALLS_H_
+
+#include
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+enum { NUM_SYSCALLS = 0x80 };
+
+void syscall_get_name(char *output, size_t size, unsigned int call_num);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif
diff --git a/ctrtool/types.h b/ctrtool/types.h
index 9234fe1..5904a08 100644
--- a/ctrtool/types.h
+++ b/ctrtool/types.h
@@ -23,7 +23,8 @@ enum flags
VerifyFlag = (1<<4),
RawFlag = (1<<5),
ShowKeysFlag = (1<<6),
- DecompressCodeFlag = (1<<7)
+ DecompressCodeFlag = (1<<7),
+ ShowSyscallsFlag = (1<<8),
};
enum validstate
diff --git a/ctrtool/utils.c b/ctrtool/utils.c
index 1f21f07..92125e5 100644
--- a/ctrtool/utils.c
+++ b/ctrtool/utils.c
@@ -73,59 +73,59 @@ u32 getbe16(const u8* p)
void putle16(u8* p, u16 n)
{
- p[0] = n;
- p[1] = n>>8;
+ p[0] = (u8) n;
+ p[1] = (u8) (n>>8);
}
void putle32(u8* p, u32 n)
{
- p[0] = n;
- p[1] = n>>8;
- p[2] = n>>16;
- p[3] = n>>24;
+ p[0] = (u8) n;
+ p[1] = (u8) (n>>8);
+ p[2] = (u8) (n>>16);
+ p[3] = (u8) (n>>24);
}
void putle64(u8* p, u64 n)
{
- p[0] = n;
- p[1] = n >> 8;
- p[2] = n >> 16;
- p[3] = n >> 24;
- p[4] = n >> 32;
- p[5] = n >> 40;
- p[6] = n >> 48;
- p[7] = n >> 56;
+ p[0] = (u8) n;
+ p[1] = (u8) (n >> 8);
+ p[2] = (u8) (n >> 16);
+ p[3] = (u8) (n >> 24);
+ p[4] = (u8) (n >> 32);
+ p[5] = (u8) (n >> 40);
+ p[6] = (u8) (n >> 48);
+ p[7] = (u8) (n >> 56);
}
void putbe16(u8* p, u16 n)
{
- p[1] = n;
- p[0] = n >> 8;
+ p[1] = (u8) n;
+ p[0] = (u8) (n >> 8);
}
void putbe32(u8* p, u32 n)
{
- p[3] = n;
- p[2] = n >> 8;
- p[1] = n >> 16;
- p[0] = n >> 24;
+ p[3] = (u8) n;
+ p[2] = (u8) (n >> 8);
+ p[1] = (u8) (n >> 16);
+ p[0] = (u8) (n >> 24);
}
void putbe64(u8* p, u64 n)
{
- p[7] = n;
- p[6] = n >> 8;
- p[5] = n >> 16;
- p[4] = n >> 24;
- p[3] = n >> 32;
- p[2] = n >> 40;
- p[1] = n >> 48;
- p[0] = n >> 56;
+ p[7] = (u8) n;
+ p[6] = (u8) (n >> 8);
+ p[5] = (u8) (n >> 16);
+ p[4] = (u8) (n >> 24);
+ p[3] = (u8) (n >> 32);
+ p[2] = (u8) (n >> 40);
+ p[1] = (u8) (n >> 48);
+ p[0] = (u8) (n >> 56);
}
void readkeyfile(u8* key, const char* keyfname)
{
- u32 keysize = _fsize(keyfname);
+ u64 keysize = _fsize(keyfname);
FILE* f = fopen(keyfname, "rb");
if (0 == f)
@@ -136,7 +136,7 @@ void readkeyfile(u8* key, const char* keyfname)
if (keysize != 16)
{
- fprintf(stdout, "Error key size mismatch, got %d, expected %d\n", keysize, 16);
+ fprintf(stdout, "Error key size mismatch, got %"PRIu64", expected %d\n", keysize, 16);
goto clean;
}
diff --git a/ctrtool/utils.h b/ctrtool/utils.h
index 4d766aa..1d5eac8 100644
--- a/ctrtool/utils.h
+++ b/ctrtool/utils.h
@@ -41,7 +41,12 @@ int makedir(const char* dir);
u64 _fsize(const char *filename);
-#ifndef _WIN32
+#ifdef _MSC_VER
+inline int fseeko64(FILE *__stream, long long __off, int __whence)
+{
+ return _fseeki64(__stream, __off, __whence);
+}
+#else
extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
#endif