Skip to content

Commit

Permalink
Final Touchs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussacana committed Dec 20, 2022
1 parent e949db3 commit 82d4c08
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 21 deletions.
2 changes: 1 addition & 1 deletion PS4-OpenOrbis-Mono/main.c
Expand Up @@ -17,7 +17,7 @@ void* startMono()
#endif

#ifdef DEBUG
klog("Initializing Debugger...");
klog("Initializing Debugger at port 2222...");

mono_debugger_agent_parse_options("address=0.0.0.0:2222,transport=dt_socket,server=y");
mono_debug_init(1);
Expand Down
50 changes: 37 additions & 13 deletions PS4-OpenOrbis-Mono/trampoline.c
Expand Up @@ -26,15 +26,31 @@ void WriteJump(void* Address, void* Destination, char* OriInstructions)
memcpy(Address, JumpInstructions, sizeof(JumpInstructions));
}

//The KernelLoadStartModule export is just a check if you didn't set
//flags arguments, if not, it jump for the real function,
//we will use that to be able to keep the hook allways enabled,
//by calling the real LoadStartModule function directly
void* FindInternalFunction(void* Address){

//Since is just reading maybe this isn't required, but in any case, better be sure.
sceKernelMprotect((void*)Address, 0x20, PROT_READ | PROT_WRITE | PROT_EXEC);

for (int i = 0; i < 0x20; i++){
uint32_t* pDWORD = (uint32_t*)(Address+i);

//find the function end (end with NOPs)
if (*pDWORD == 0x90909090){

//The last instruction is a jmp to the real LoadStartModule function
uint8_t* pJmp = ((uint8_t*)pDWORD) - 5;

if (*pJmp != 0xE9)
return 0;
return 0;//Whatever if fails, we still can do the dirty way disabling the hook temporally

//Get the Jmp Offset
pDWORD = (uint32_t*)(pJmp+1);

//Calculate the jump offset
return pJmp + 5 + *pDWORD;
}
}
Expand Down Expand Up @@ -79,15 +95,23 @@ char* extract_extension(char* path)
return 0;
}

#ifdef DEBUG
#define LOG LOG
#define LOGF LOGf
#else
#define LOG(x)
#define LOGF(x,...)
#endif

void* hookLoadSprxAssembly(const char* AssemblyName, int* OpenStatus, int UnkBool, int RefOnly)
{
klogf("Loading Assembly: %s", AssemblyName);
LOGF("Loading Assembly: %s", AssemblyName);

char* finalPath = AssemblyName;

void* fp = fopen(AssemblyName, "r");
if (fp == 0) {
klog("Error opening file");
LOG("Error opening file");

char hintPath[0x300] = "\x0";
char* fname = extract_file_name(AssemblyName);
Expand Down Expand Up @@ -116,12 +140,12 @@ void* hookLoadSprxAssembly(const char* AssemblyName, int* OpenStatus, int UnkBoo
}

if (fp == 0) {
klog("No valid hints");
LOG("No valid hints");
return 0;
}

finalPath = hintPath;
klogf("Hint path matched: %s", hintPath);
LOGF("Hint path matched: %s", hintPath);
}

fseek(fp, 0, SEEK_END);
Expand All @@ -134,7 +158,7 @@ void* hookLoadSprxAssembly(const char* AssemblyName, int* OpenStatus, int UnkBoo
fclose(fp);

if (readed != size) {
klog("Error reading the file");
LOG("Error reading the file");
return 0;
}

Expand Down Expand Up @@ -163,14 +187,14 @@ void* hookLoadSprxAssembly(const char* AssemblyName, int* OpenStatus, int UnkBoo

mono_debug_open_image_from_memory(Image, pdb, size);

klogf("Debug symbols loaded: %s", pdbPath);
LOGF("Debug symbols loaded: %s", pdbPath);
}
}
#endif

if (OpenStatus != 0)* OpenStatus = status;

klogf("Assembly Image: %x", Image);
LOGF("Assembly Image: %x", Image);

return Image;
}
Expand All @@ -183,7 +207,7 @@ SceKernelLoadStartModuleInternal sceKernelLoadStartModuleMod;

uint32_t hookSceKernelLoadStartModule(const char* path, size_t args, const void* argp, uint32_t flags, void* option, void* status)
{
klogf("sceKernelLoadStartModule: %s", path);
LOGF("sceKernelLoadStartModule: %s", path);
uint32_t rst = sceKernelLoadStartModuleMod(path, args, argp, flags, option, status);

if (rst & 0x80000000) {
Expand Down Expand Up @@ -271,9 +295,9 @@ uint32_t hookSceKernelLoadStartModule(const char* path, size_t args, const void*
}

if (rst < 0x80000000)
klogf("Hint path matched: %s", hintPath);
LOGF("Hint path matched: %s", hintPath);
} else {
klog("Original Path Loaded");
LOG("Original Path Loaded");
}


Expand Down Expand Up @@ -319,9 +343,9 @@ void InstallHooks()
sceKernelLoadStartModuleMod = (SceKernelLoadStartModuleInternal)FindInternalFunction(sceKernelLoadStartModule);

if (sceKernelLoadStartModuleMod){
klogf("SceKernelLoadStartModuleInternal successfully loaded");
LOGF("SceKernelLoadStartModuleInternal successfully loaded");
} else {
klogf("SceKernelLoadStartModuleInternal failed");
LOGF("SceKernelLoadStartModuleInternal failed");
sceKernelLoadStartModuleMod = SceKernelLoadStartModuleAlt;
}

Expand Down
Binary file removed libSDL2/libSDL2/x64/Debug/libSDL2.o.stub
Binary file not shown.
Binary file removed main.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion main/main/Program.cs
Expand Up @@ -19,7 +19,7 @@ internal class Program

public static void Main()
{
User.Notify("Hello World from C#");
User.Notify(User.PlaystationButtons, "Hello World from C#");

Util.PrepareAsemblies();

Expand Down
153 changes: 147 additions & 6 deletions main/main/User.cs
@@ -1,16 +1,157 @@
using System;
using System.Runtime.InteropServices;
using Orbis.String;

namespace Orbis
{
public unsafe class User
{
public static void Notify(string Message)
public static void Notify(string Message) => Notify(PlaystationButtons, Message);
public static unsafe void Notify(string Icon, string Message)
{
sceSysUtilSendSystemNotificationWithText(222, Message);
NotifyBuffer Buffer = new NotifyBuffer();
Buffer.Message = Message;
Buffer.Uri = Icon;

const int BufferSize = 0xC30;

var pBuffer = Marshal.AllocHGlobal(BufferSize);
Marshal.StructureToPtr(Buffer, pBuffer, true);

sceKernelSendNotificationRequest(0, pBuffer, BufferSize, 0);

Marshal.FreeHGlobal(pBuffer);
}

//Notify Method By OSM-Made, https://github.com/OSM-Made/PS4-Notify/blob/main/Notify.cpp

#region Constants
public const string PlaystationButtons = "cxml://psnotification/tex_icon_system";
public const string CircleWithSlash = "cxml://psnotification/tex_icon_ban";
public const string IInChatBubble = "cxml://psnotification/tex_default_icon_notification";
public const string DefaultIconMessage = "cxml://psnotification/tex_default_icon_message";
public const string DefaultIconFriend = "cxml://psnotification/tex_default_icon_friend";
public const string DefaultIconTrophy = "cxml://psnotification/tex_default_icon_trophy";
public const string DefaultIconDownload = "cxml://psnotification/tex_default_icon_download";
public const string DefaultIconUpload16_9 = "cxml://psnotification/tex_default_icon_upload_16_9";
public const string DefaultIconCloudClient = "cxml://psnotification/tex_default_icon_cloud_client";
public const string DefaultIconActivity = "cxml://psnotification/tex_default_icon_activity";
public const string DefaultIconSmaps = "cxml://psnotification/tex_default_icon_smaps";
public const string DefaultIconShareplay = "cxml://psnotification/tex_default_icon_shareplay";
public const string DefaultIconTips = "cxml://psnotification/tex_default_icon_tips";
public const string DefaultIconEvents = "cxml://psnotification/tex_default_icon_events";
public const string DefaultIconShareScreen = "cxml://psnotification/tex_default_icon_share_screen";
public const string DefaultIconCommunity = "cxml://psnotification/tex_default_icon_community";
public const string DefaultIconLfps = "cxml://psnotification/tex_default_icon_lfps";
public const string DefaultIconTournament = "cxml://psnotification/tex_default_icon_tournament";
public const string DefaultIconTeam = "cxml://psnotification/tex_default_icon_team";
public const string DefaultAvatar = "cxml://psnotification/tex_default_avatar";
public const string IconCapture = "cxml://psnotification/tex_icon_capture";
public const string IconStartRec = "cxml://psnotification/tex_icon_start_rec";
public const string IconStopRec = "cxml://psnotification/tex_icon_stop_rec";
public const string IconLiveProhibited = "cxml://psnotification/tex_icon_live_prohibited";
public const string IconLiveStart = "cxml://psnotification/tex_icon_live_start";
public const string IconLoading = "cxml://psnotification/tex_icon_loading";
public const string IconLoading16_9 = "cxml://psnotification/tex_icon_loading_16_9";
public const string IconCountdown = "cxml://psnotification/tex_icon_countdown";
public const string IconParty = "cxml://psnotification/tex_icon_party";
public const string IconShareplay = "cxml://psnotification/tex_icon_shareplay";
public const string IconBroadcast = "cxml://psnotification/tex_icon_broadcast";
public const string IconPsnowToast = "cxml://psnotification/tex_icon_psnow_toast";
public const string AudioDeviceHeadphone = "cxml://psnotification/tex_audio_device_headphone";
public const string AudioDeviceHeadset = "cxml://psnotification/tex_audio_device_headset";
public const string AudioDeviceMic = "cxml://psnotification/tex_audio_device_mic";
public const string AudioDeviceMorpheus = "cxml://psnotification/tex_audio_device_morpheus";
public const string DeviceBattery0 = "cxml://psnotification/tex_device_battery_0";
public const string DeviceBattery1 = "cxml://psnotification/tex_device_battery_1";
public const string DeviceBattery2 = "cxml://psnotification/tex_device_battery_2";
public const string DeviceBattery3 = "cxml://psnotification/tex_device_battery_3";
public const string DeviceBatteryNocharge = "cxml://psnotification/tex_device_battery_nocharge";
public const string DeviceCompApp = "cxml://psnotification/tex_device_comp_app";
public const string DeviceController = "cxml://psnotification/tex_device_controller";
public const string DeviceJediUsb = "cxml://psnotification/tex_device_jedi_usb";
public const string DeviceBlaster = "cxml://psnotification/tex_device_blaster";
public const string DeviceHeadphone = "cxml://psnotification/tex_device_headphone";
public const string DeviceHeadset = "cxml://psnotification/tex_device_headset";
public const string DeviceKeyboard = "cxml://psnotification/tex_device_keyboard";
public const string DeviceMic = "cxml://psnotification/tex_device_mic";
public const string DeviceMorpheus = "cxml://psnotification/tex_device_morpheus";
public const string DeviceMouse = "cxml://psnotification/tex_device_mouse";
public const string DeviceMove = "cxml://psnotification/tex_device_move";
public const string DeviceRemote = "cxml://psnotification/tex_device_remote";
public const string DeviceOmit = "cxml://psnotification/tex_device_omit";
public const string IconConnect = "cxml://psnotification/tex_icon_connect";
public const string IconEventToast = "cxml://psnotification/tex_icon_event_toast";
public const string MorpheusTrophyBronze = "cxml://psnotification/tex_morpheus_trophy_bronze";
public const string MorpheusTrophyGold = "cxml://psnotification/tex_morpheus_trophy_gold";
public const string MorpheusTrophyPlatinum = "cxml://psnotification/tex_morpheus_trophy_platinum";
public const string IconChampionsLeague = "cxml://psnotification/tex_icon_champions_league";
#endregion

#region NotifyTypes
enum NotifyType
{
NotificationRequest = 0,
SystemNotification = 1,
SystemNotificationWithUserId = 2,
SystemNotificationWithDeviceId = 3,
SystemNotificationWithDeviceIdRelatedToUser = 4,
SystemNotificationWithText = 5,
SystemNotificationWithTextRelatedToUser = 6,
SystemNotificationWithErrorCode = 7,
SystemNotificationWithAppId = 8,
SystemNotificationWithAppName = 9,
SystemNotificationWithAppInfo = 9,
SystemNotificationWithAppNameRelatedToUser = 10,
SystemNotificationWithParams = 11,
SendSystemNotificationWithUserName = 12,
SystemNotificationWithUserNameInfo = 13,
SendAddressingSystemNotification = 14,
AddressingSystemNotificationWithDeviceId = 15,
AddressingSystemNotificationWithUserName = 16,
AddressingSystemNotificationWithUserId = 17,
UNK_1 = 100,
TrcCheckNotificationRequest = 101,
NpDebugNotificationRequest = 102,
UNK_2 = 102
}

[DllImport("libSceSysUtil.sprx", CharSet = CharSet.Ansi)]
static extern void sceSysUtilSendSystemNotificationWithText(int IconID, string Message);


[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Size = 0xC30)]
struct NotifyBuffer
{
public NotifyType Type;
public int ReqId;
public int Priority;
public int MsgId;
public int TargetId;
public int UserId;
public int unk1;
public int unk2;
public int AppId;
public int ErrorNum;
public int unk3;
public byte UseIconImageUri;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string Message;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string Uri;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string unkstr;


public NotifyBuffer()
{
Type = NotifyType.NotificationRequest;
UseIconImageUri = 1;
TargetId = -1;
unk3 = 0;
}
}

#endregion

[DllImport("libkernel")]
static extern void sceKernelSendNotificationRequest(long unk1, IntPtr Buffer, long size, long unk2);
}
}
Binary file removed mono/4.5/SDL2-CS.dll
Binary file not shown.
Binary file removed mono/4.5/SDL2-CS.pdb
Binary file not shown.
Binary file removed mono/4.5/SixLabors.ImageSharp.dll
Binary file not shown.
Binary file removed mono/4.5/SixLabors.ImageSharp.pdb
Binary file not shown.
Binary file removed mono/4.5/main.pdb
Binary file not shown.
Binary file removed sce_module/libSDL2.sprx
Binary file not shown.

0 comments on commit 82d4c08

Please sign in to comment.