Skip to content

Commit

Permalink
Add log
Browse files Browse the repository at this point in the history
  • Loading branch information
nowrep committed May 18, 2017
1 parent 233546d commit 6dbfae2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 10 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif()

add_executable(shellbat
main.c
log.c
)

target_link_libraries(shellbat
Expand Down
40 changes: 40 additions & 0 deletions log.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* ShellBat plugin
* Copyright (c) 2017 David Rosca
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "log.h"

#include <psp2/io/fcntl.h>

void _log(char *str, ...)
{
static SceUID logfd = -1;
if (logfd == -1) {
logfd = sceIoOpen("ux0:shellbat.log", SCE_O_APPEND | SCE_O_CREAT | SCE_O_WRONLY, 0666);
}
char buff[256];
va_list arglist;
va_start(arglist, str);
int len = sceClibVsnprintf(buff, 256, str, arglist);
va_end(arglist);
sceIoWrite(logfd, buff, len);
sceIoWrite(logfd, "\n", 1);
}
37 changes: 37 additions & 0 deletions log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ShellBat plugin
* Copyright (c) 2017 David Rosca
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef _LOG_H_
#define _LOG_H_

#include <psp2/kernel/clib.h>

#if 1
#define LOG(x, ...) _log(x, ##__VA_ARGS__)
#else
#define LOG(x, ...)
#endif

void _log(char *str, ...);

#endif // _LOG_H_
19 changes: 9 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "log.h"

#include <psp2/kernel/modulemgr.h>
#include <psp2/kernel/clib.h>
#include <psp2/io/fcntl.h>
#include <psp2/power.h>
#include <taihen.h>

static SceUID g_hooks[2];

// static SceUID logfd;
static int in_draw_time = 0;

#if 0
static tai_hook_ref_t ref_hook;
// offset 0x1844f0
Expand All @@ -40,6 +38,8 @@ static int status_draw_battery_patched(int a1, uint8_t a2)
}
#endif

static int in_draw_time = 0;

static tai_hook_ref_t ref_hook0;
static int status_draw_time_patched(int a1, int a2)
{
Expand Down Expand Up @@ -67,6 +67,8 @@ static uint16_t **some_strdup_patched(uint16_t **a1, uint16_t *a2, int a2_size)
void _start() __attribute__ ((weak, alias ("module_start")));
int module_start(SceSize argc, const void *args)
{
LOG("Starting module");

tai_module_info_t info;
info.size = sizeof(info);
if (taiGetModuleInfo("SceShell", &info) >= 0) {
Expand All @@ -78,7 +80,6 @@ int module_start(SceSize argc, const void *args)
0x183ea4, // offset
1, // thumb
status_draw_time_patched);

g_hooks[1] = taiHookFunctionOffset(&ref_hook1,
info.modid,
0, // segidx
Expand All @@ -88,22 +89,20 @@ int module_start(SceSize argc, const void *args)
break;
}
default:
// SceShell NID not recognized
LOG("SceShell %XNID not recognized", info.module_nid);
break;
}
}

// logfd = sceIoOpen("ux0:shellbat.log", SCE_O_APPEND | SCE_O_CREAT | SCE_O_WRONLY, 0666);

return SCE_KERNEL_START_SUCCESS;
}

int module_stop(SceSize argc, const void *args)
{
LOG("Stopping module");

if (g_hooks[0] >= 0) taiHookRelease(g_hooks[0], ref_hook0);
if (g_hooks[1] >= 0) taiHookRelease(g_hooks[1], ref_hook1);

// sceIoClose(logfd);

return SCE_KERNEL_STOP_SUCCESS;
}

0 comments on commit 6dbfae2

Please sign in to comment.