mirror of
https://github.com/shchmue/Lockpick.git
synced 2024-12-22 07:55:39 +00:00
Merge pull request #18 from HookedBehemoth/master
update for new ipc and libnx changes
This commit is contained in:
commit
9bbef1cc69
|
@ -592,7 +592,7 @@ void KeyCollection::get_titlekeys() {
|
|||
esInitialize();
|
||||
esCountCommonTicket(&common_count);
|
||||
esCountPersonalizedTicket(&personalized_count);
|
||||
NcmNcaId common_rights_ids[common_count], personalized_rights_ids[personalized_count];
|
||||
NcmRightsId common_rights_ids[common_count], personalized_rights_ids[personalized_count];
|
||||
esListCommonTicket(&ids_written, common_rights_ids, sizeof(common_rights_ids));
|
||||
esListPersonalizedTicket(&ids_written, personalized_rights_ids, sizeof(personalized_rights_ids));
|
||||
esExit();
|
||||
|
@ -608,13 +608,13 @@ void KeyCollection::get_titlekeys() {
|
|||
std::unordered_set<std::string> rights_ids;
|
||||
for (size_t i = 0; i < common_count; i++) {
|
||||
for (size_t j = 0; j < 0x10; j++) {
|
||||
sprintf(&rights_id_string[j*2], "%02x", common_rights_ids[i].c[j]);
|
||||
sprintf(&rights_id_string[j*2], "%02x", common_rights_ids[i].rights_id.c[j]);
|
||||
}
|
||||
rights_ids.insert(rights_id_string);
|
||||
}
|
||||
for (size_t i = 0; i < personalized_count; i++) {
|
||||
for (size_t j = 0; j < 0x10; j++) {
|
||||
sprintf(&rights_id_string[j*2], "%02x", personalized_rights_ids[i].c[j]);
|
||||
sprintf(&rights_id_string[j*2], "%02x", personalized_rights_ids[i].rights_id.c[j]);
|
||||
}
|
||||
rights_ids.insert(rights_id_string);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ void KeyLocation::get_from_memory(u64 tid, u8 seg_mask) {
|
|||
// if not a kernel process, get pid from pm:dmnt
|
||||
if ((tid > 0x0100000000000005) && (tid != 0x0100000000000028)) {
|
||||
u64 pid;
|
||||
pmdmntGetTitlePid(&pid, tid);
|
||||
pmdmntGetProcessId(&pid, tid);
|
||||
|
||||
if (R_FAILED(svcDebugActiveProcess(&debug_handle, pid)) ||
|
||||
R_FAILED(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), debug_handle)))
|
||||
|
|
162
source/nx/es.c
162
source/nx/es.c
|
@ -1,170 +1,72 @@
|
|||
#include "es.h"
|
||||
|
||||
#include <switch/arm/atomics.h>
|
||||
#include "../service_guard.h"
|
||||
|
||||
#include <switch/kernel/ipc.h>
|
||||
#include <switch/services/sm.h>
|
||||
|
||||
static Service g_esSrv;
|
||||
static u64 g_esRefCnt;
|
||||
|
||||
Result esInitialize() {
|
||||
atomicIncrement64(&g_esRefCnt);
|
||||
|
||||
if (serviceIsActive(&g_esSrv))
|
||||
return 0;
|
||||
NX_GENERATE_SERVICE_GUARD(es);
|
||||
|
||||
Result _esInitialize() {
|
||||
return smGetService(&g_esSrv, "es");
|
||||
}
|
||||
|
||||
void esExit()
|
||||
{
|
||||
if (atomicDecrement64(&g_esRefCnt) == 0) {
|
||||
serviceClose(&g_esSrv);
|
||||
}
|
||||
void _esCleanup() {
|
||||
serviceClose(&g_esSrv);
|
||||
}
|
||||
|
||||
Result esCountCommonTicket(u32 *num_tickets)
|
||||
{
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
u32 num_tickets;
|
||||
} out;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 9;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_esSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 num_tickets;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*num_tickets = resp->num_tickets;
|
||||
}
|
||||
}
|
||||
Result rc = serviceDispatchOut(&g_esSrv, 9, out);
|
||||
if (R_SUCCEEDED(rc) && num_tickets) *num_tickets = out.num_tickets;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result esCountPersonalizedTicket(u32 *num_tickets)
|
||||
{
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
u32 num_tickets;
|
||||
} out;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 10;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_esSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 num_tickets;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*num_tickets = resp->num_tickets;
|
||||
}
|
||||
}
|
||||
Result rc = serviceDispatchOut(&g_esSrv, 10, out);
|
||||
if (R_SUCCEEDED(rc) && num_tickets) *num_tickets = out.num_tickets;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result esListCommonTicket(u32 *numRightsIdsWritten, NcmNcaId *outBuf, size_t bufSize) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcAddRecvBuffer(&c, outBuf, bufSize, BufferType_Normal);
|
||||
|
||||
Result esListCommonTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize)
|
||||
{
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
u32 num_rights_ids_written;
|
||||
} out;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 11;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_esSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 num_rights_ids_written;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (numRightsIdsWritten) *numRightsIdsWritten = resp->num_rights_ids_written;
|
||||
}
|
||||
}
|
||||
Result rc = serviceDispatchInOut(&g_esSrv, 11, *numRightsIdsWritten, out,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
|
||||
.buffers = { { outBuf, bufSize } },
|
||||
);
|
||||
if (R_SUCCEEDED(rc) && numRightsIdsWritten) *numRightsIdsWritten = out.num_rights_ids_written;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result esListPersonalizedTicket(u32 *numRightsIdsWritten, NcmNcaId *outBuf, size_t bufSize) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcAddRecvBuffer(&c, outBuf, bufSize, BufferType_Normal);
|
||||
|
||||
Result esListPersonalizedTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize)
|
||||
{
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
u32 num_rights_ids_written;
|
||||
} out;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 12;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_esSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 num_rights_ids_written;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
if (numRightsIdsWritten) *numRightsIdsWritten = resp->num_rights_ids_written;
|
||||
}
|
||||
}
|
||||
Result rc = serviceDispatchInOut(&g_esSrv, 12, *numRightsIdsWritten, out,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
|
||||
.buffers = { { outBuf, bufSize } },
|
||||
);
|
||||
if (R_SUCCEEDED(rc) && numRightsIdsWritten) *numRightsIdsWritten = out.num_rights_ids_written;
|
||||
|
||||
return rc;
|
||||
}
|
|
@ -8,5 +8,5 @@ void esExit();
|
|||
|
||||
Result esCountCommonTicket(u32 *num_tickets); //9
|
||||
Result esCountPersonalizedTicket(u32 *num_tickets); // 10
|
||||
Result esListCommonTicket(u32 *numRightsIdsWritten, NcmNcaId *outBuf, size_t bufSize);
|
||||
Result esListPersonalizedTicket(u32 *numRightsIdsWritten, NcmNcaId *outBuf, size_t bufSize);
|
||||
Result esListCommonTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize);
|
||||
Result esListPersonalizedTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize);
|
|
@ -1,55 +1,26 @@
|
|||
#include "set_ext.h"
|
||||
|
||||
#include <switch/arm/atomics.h>
|
||||
#include "../service_guard.h"
|
||||
|
||||
#include <switch/services/sm.h>
|
||||
#include <switch/types.h>
|
||||
|
||||
static Service g_setcalSrv;
|
||||
static u64 g_refCntCal;
|
||||
|
||||
Result setcalInitialize(void) {
|
||||
atomicIncrement64(&g_refCntCal);
|
||||
|
||||
if (serviceIsActive(&g_setcalSrv))
|
||||
return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized);
|
||||
NX_GENERATE_SERVICE_GUARD(setcal);
|
||||
|
||||
Result _setcalInitialize() {
|
||||
return smGetService(&g_setcalSrv, "set:cal");
|
||||
}
|
||||
|
||||
void setcalExit(void) {
|
||||
if (atomicDecrement64(&g_refCntCal) == 0) {
|
||||
serviceClose(&g_setcalSrv);
|
||||
}
|
||||
void _setcalCleanup() {
|
||||
serviceClose(&g_setcalSrv);
|
||||
}
|
||||
|
||||
Result setcalGetEticketDeviceKey(void *key) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcAddRecvBuffer(&c, key, 0x244, 0);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 21;
|
||||
|
||||
Result rc = serviceIpcDispatch(&g_setcalSrv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
}
|
||||
|
||||
return rc;
|
||||
Result setcalGetEticketDeviceKey(void *key)
|
||||
{
|
||||
return serviceDispatch(&g_setcalSrv, 21,
|
||||
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
|
||||
.buffers = { { key, 0x244 } },
|
||||
);
|
||||
}
|
56
source/service_guard.h
Normal file
56
source/service_guard.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
#include <switch/types.h>
|
||||
#include <switch/result.h>
|
||||
#include <switch/kernel/mutex.h>
|
||||
#include <switch/sf/service.h>
|
||||
#include <switch/services/sm.h>
|
||||
|
||||
typedef struct ServiceGuard {
|
||||
Mutex mutex;
|
||||
u32 refCount;
|
||||
} ServiceGuard;
|
||||
|
||||
NX_INLINE bool serviceGuardBeginInit(ServiceGuard* g)
|
||||
{
|
||||
mutexLock(&g->mutex);
|
||||
return (g->refCount++) == 0;
|
||||
}
|
||||
|
||||
NX_INLINE Result serviceGuardEndInit(ServiceGuard* g, Result rc, void (*cleanupFunc)(void))
|
||||
{
|
||||
if (R_FAILED(rc)) {
|
||||
cleanupFunc();
|
||||
--g->refCount;
|
||||
}
|
||||
mutexUnlock(&g->mutex);
|
||||
return rc;
|
||||
}
|
||||
|
||||
NX_INLINE void serviceGuardExit(ServiceGuard* g, void (*cleanupFunc)(void))
|
||||
{
|
||||
mutexLock(&g->mutex);
|
||||
if (g->refCount && (--g->refCount) == 0)
|
||||
cleanupFunc();
|
||||
mutexUnlock(&g->mutex);
|
||||
}
|
||||
|
||||
#define NX_GENERATE_SERVICE_GUARD_PARAMS(name, _paramdecl, _parampass) \
|
||||
\
|
||||
static ServiceGuard g_##name##Guard; \
|
||||
NX_INLINE Result _##name##Initialize _paramdecl; \
|
||||
static void _##name##Cleanup(void); \
|
||||
\
|
||||
Result name##Initialize _paramdecl \
|
||||
{ \
|
||||
Result rc = 0; \
|
||||
if (serviceGuardBeginInit(&g_##name##Guard)) \
|
||||
rc = _##name##Initialize _parampass; \
|
||||
return serviceGuardEndInit(&g_##name##Guard, rc, _##name##Cleanup); \
|
||||
} \
|
||||
\
|
||||
void name##Exit(void) \
|
||||
{ \
|
||||
serviceGuardExit(&g_##name##Guard, _##name##Cleanup); \
|
||||
}
|
||||
|
||||
#define NX_GENERATE_SERVICE_GUARD(name) NX_GENERATE_SERVICE_GUARD_PARAMS(name, (void), ())
|
Loading…
Reference in a new issue