Skip to content

Instantly share code, notes, and snippets.

@hexkyz
Created February 11, 2017 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexkyz/06891b18d5225705b844b44786675bff to your computer and use it in GitHub Desktop.
Save hexkyz/06891b18d5225705b844b44786675bff to your computer and use it in GitHub Desktop.
sceSblSmSchedProxyGetStatus(u32 sm_handle, u32 *out_buf)
{
// Check global status var
u32 state = SMSCHED_STATUS;
// SmSched is not initialized
if (state != 0x01)
return 0x800F0426;
// NULL pointer
if (!out_buf)
return 0x800F0416;
// Check for negative handle
if ((sm_handle + 0x01) < 0x01)
return 0x800F042B;
u32 handle = (sm_handle >> 0x01);
u32 status_struct_addr = (handle << 0x02);
// Bad structure size field?
if (*status_struct_addr == 0xFFFFFFFF)
return 0x800F042B;
u32 *status0;
u32 *status1;
// Register pointers with Sysroot
u32 shared_mem_index = sub_45AC14(0x08, status0, status1);
// Bad index
if (shared_mem_index < 0)
return shared_mem_index;
// Flush shared memory block
u32 flush_result = sub_45AC80(shared_mem_index);
// Failed to flush shared memory
if (flush_result < 0)
{
// Flush back
sub_45AD8C(shared_mem_index);
return flush_result;
}
// Call SMC
u32 smc_result = sub_45A000(*(status_struct_addr + 0x04), shared_mem_index, 0, 0, 0x12F);
// Copy result from shared memory into pointers
u32 copy_result = sub_45ACFC(shared_mem_index, status0, status1);
// Failed to copy from shared memory
if (copy_result < 0)
{
// Flush back
sub_45AD8C(shared_mem_index);
return copy_result;
}
// Second pointer returns the reply size
u32 sm_reply_size = *status1;
// The reply is always 0x08 bytes
if (sm_reply_size < 0x07)
{
// Do kernel panic
SceDebugForDriver_391B5B74(0x27C1DBAE, 0, 0, 0xAD1439EB, 0, LR);
}
// First pointer is a pointer to the actual reply
u32 *sm_reply_addr = *status0;
// Return reply
*out_buf = *sm_reply_addr;
*(out_buf + 0x04) = *(sm_reply_addr + 0x04);
// Free shared memory block
u32 free_result = sub_45AD8C(shared_mem_index);
return smc_result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment