This commit is contained in:
Pavel 2024-10-20 19:35:30 +03:00
parent 3063ccfb49
commit 7ef6b8b457
3 changed files with 94 additions and 62 deletions

View File

@ -1,20 +1,21 @@
unit ps4_libSceAppContent;
{$mode objfpc}{$H+}
{$CALLING SysV_ABI_CDecl}
interface
uses
ps4_program,
Classes,
SysUtils;
subr_dynlib;
implementation
{
uses
sys_path,
sys_signal,
param_sfo;
}
Const
SCE_APP_CONTENT_APPPARAM_ID_SKU_FLAG =0;
@ -87,16 +88,18 @@ begin
Result:=0;
end;
function ps4_sceAppContentAppParamGetInt(paramId:DWORD;value:PInteger):Integer; SysV_ABI_CDecl;
function ps4_sceAppContentAppParamGetInt(paramId:DWORD;value:PInteger):Integer;
begin
Result:=0;
if (value=nil) then Exit(SCE_APP_CONTENT_ERROR_PARAMETER);
Case SCE_APP_CONTENT_APPPARAM_ID_SKU_FLAG of
SCE_APP_CONTENT_APPPARAM_ID_SKU_FLAG :value^:=SCE_APP_CONTENT_APPPARAM_SKU_FLAG_FULL;
{
SCE_APP_CONTENT_APPPARAM_ID_USER_DEFINED_PARAM_1:value^:=ParamSfoGetInt('USER_DEFINED_PARAM_1');
SCE_APP_CONTENT_APPPARAM_ID_USER_DEFINED_PARAM_2:value^:=ParamSfoGetInt('USER_DEFINED_PARAM_2');
SCE_APP_CONTENT_APPPARAM_ID_USER_DEFINED_PARAM_3:value^:=ParamSfoGetInt('USER_DEFINED_PARAM_3');
SCE_APP_CONTENT_APPPARAM_ID_USER_DEFINED_PARAM_4:value^:=ParamSfoGetInt('USER_DEFINED_PARAM_4');
}
else
Result:=SCE_APP_CONTENT_ERROR_PARAMETER;
end;
@ -105,7 +108,7 @@ end;
function ps4_sceAppContentGetAddcontInfoList(serviceLabel:SceNpServiceLabel;
list:pSceAppContentAddcontInfo;
listNum:DWORD;
hitNum:PDWORD):Integer; SysV_ABI_CDecl;
hitNum:PDWORD):Integer;
begin
Result:=0;
Writeln('sceAppContentGetAddcontInfoList:0x',HexStr(serviceLabel,8));
@ -118,96 +121,111 @@ end;
function ps4_sceAppContentGetAddcontInfo(serviceLabel:SceNpServiceLabel;
entitlementLabel:pSceNpUnifiedEntitlementLabel;
info:pSceAppContentAddcontInfo
):Integer; SysV_ABI_CDecl;
):Integer;
begin
if (entitlementLabel=nil) or (info=nil) then Exit(SCE_APP_CONTENT_ERROR_PARAMETER);
Result:=SCE_APP_CONTENT_ERROR_DRM_NO_ENTITLEMENT;
end;
function ps4_sceAppContentTemporaryDataFormat(mountPoint:pSceAppContentMountPoint):Integer; SysV_ABI_CDecl;
function ps4_sceAppContentTemporaryDataFormat(mountPoint:pSceAppContentMountPoint):Integer;
begin
{
_sig_lock;
Result:=FormatTmpPath(PChar(mountPoint));
_sig_unlock;
}
end;
function ps4_sceAppContentTemporaryDataMount(mountPoint:pSceAppContentMountPoint):Integer; SysV_ABI_CDecl;
function ps4_sceAppContentTemporaryDataMount(mountPoint:pSceAppContentMountPoint):Integer;
begin
{
_sig_lock;
Result:=FetchTmpMount(PChar(mountPoint),SCE_APP_CONTENT_TEMPORARY_DATA_OPTION_FORMAT);
_sig_unlock;
}
end;
function ps4_sceAppContentTemporaryDataMount2(option:DWORD;mountPoint:pSceAppContentMountPoint):Integer; SysV_ABI_CDecl;
function ps4_sceAppContentTemporaryDataMount2(option:DWORD;mountPoint:pSceAppContentMountPoint):Integer;
begin
{
_sig_lock;
Result:=FetchTmpMount(PChar(mountPoint),option);
_sig_unlock;
}
end;
function ps4_sceAppContentTemporaryDataUnmount(mountPoint:pSceAppContentMountPoint):Integer; SysV_ABI_CDecl;
function ps4_sceAppContentTemporaryDataUnmount(mountPoint:pSceAppContentMountPoint):Integer;
begin
{
_sig_lock;
Result:=UnMountTmpPath(PChar(mountPoint));
_sig_unlock;
}
end;
function ps4_sceAppContentTemporaryDataGetAvailableSpaceKb(mountPoint:pSceAppContentMountPoint;availableSpaceKb:PQWORD):Integer; SysV_ABI_CDecl;
function ps4_sceAppContentTemporaryDataGetAvailableSpaceKb(mountPoint:pSceAppContentMountPoint;availableSpaceKb:PQWORD):Integer;
begin
{
_sig_lock;
Result:=GetTmpPathAvailableSpaceKb(PChar(mountPoint),availableSpaceKb);
_sig_unlock;
}
end;
function ps4_sceAppContentDownloadDataGetAvailableSpaceKb(mountPoint:pSceAppContentMountPoint;availableSpaceKb:PQWORD):Integer; SysV_ABI_CDecl;
function ps4_sceAppContentDownloadDataGetAvailableSpaceKb(mountPoint:pSceAppContentMountPoint;availableSpaceKb:PQWORD):Integer;
begin
{
_sig_lock;
Result:=GetDownloadAvailableSpaceKb(PChar(mountPoint),availableSpaceKb);
_sig_unlock;
}
end;
function ps4_sceAppContentGetEntitlementKey(serviceLabel:SceNpServiceLabel;
entitlementLabel:pSceNpUnifiedEntitlementLabel;
key:pSceAppContentEntitlementKey
):Integer; SysV_ABI_CDecl;
):Integer;
begin
if (entitlementLabel=nil) or (key=nil) then Exit(SCE_APP_CONTENT_ERROR_PARAMETER);
Result:=0;
end;
function ps4_sceAppContentAddcontUnmount(mountPoint:pSceAppContentMountPoint):Integer; SysV_ABI_CDecl;
function ps4_sceAppContentAddcontUnmount(mountPoint:pSceAppContentMountPoint):Integer;
begin
Result:=0;
end;
function Load_libSceAppContent(Const name:RawByteString):TElf_node;
function Load_libSceAppContent(name:pchar):p_lib_info;
var
lib:PLIBRARY;
lib:TLIBRARY;
begin
Result:=TElf_node.Create;
Result.pFileName:=name;
//export module is libSceAppContentUtil
Result:=obj_new_int('libSceAppContentUtil');
lib:=Result._add_lib('libSceAppContent');
//
lib^.set_proc($47D940F363AB68DB,@ps4_sceAppContentInitialize);
lib^.set_proc($F7D6FCD88297A47E,@ps4_sceAppContentAppParamGetInt);
lib^.set_proc($C6777C049CC0C669,@ps4_sceAppContentGetAddcontInfoList);
lib^.set_proc($9B8EE3B8E987D151,@ps4_sceAppContentGetAddcontInfo);
lib^.set_proc($6B937B9401B4CB64,@ps4_sceAppContentTemporaryDataFormat);
lib^.set_proc($EDB38B5FAE88CFF5,@ps4_sceAppContentTemporaryDataMount);
lib^.set_proc($6EE61B78B3865A60,@ps4_sceAppContentTemporaryDataMount2);
lib^.set_proc($6DCA255CC9A9EAA4,@ps4_sceAppContentTemporaryDataUnmount);
lib^.set_proc($49A2A26F6520D322,@ps4_sceAppContentTemporaryDataGetAvailableSpaceKb);
lib^.set_proc($1A5EB0E62D09A246,@ps4_sceAppContentDownloadDataGetAvailableSpaceKb);
lib^.set_proc($5D3591D145EF720B,@ps4_sceAppContentGetEntitlementKey);
lib^.set_proc($DEB1D6695FF5282E,@ps4_sceAppContentAddcontUnmount);
lib:=Result^.add_lib('libSceAppContent');
lib.set_proc($47D940F363AB68DB,@ps4_sceAppContentInitialize);
lib.set_proc($F7D6FCD88297A47E,@ps4_sceAppContentAppParamGetInt);
lib.set_proc($C6777C049CC0C669,@ps4_sceAppContentGetAddcontInfoList);
lib.set_proc($9B8EE3B8E987D151,@ps4_sceAppContentGetAddcontInfo);
lib.set_proc($6B937B9401B4CB64,@ps4_sceAppContentTemporaryDataFormat);
lib.set_proc($EDB38B5FAE88CFF5,@ps4_sceAppContentTemporaryDataMount);
lib.set_proc($6EE61B78B3865A60,@ps4_sceAppContentTemporaryDataMount2);
lib.set_proc($6DCA255CC9A9EAA4,@ps4_sceAppContentTemporaryDataUnmount);
lib.set_proc($49A2A26F6520D322,@ps4_sceAppContentTemporaryDataGetAvailableSpaceKb);
lib.set_proc($1A5EB0E62D09A246,@ps4_sceAppContentDownloadDataGetAvailableSpaceKb);
lib.set_proc($5D3591D145EF720B,@ps4_sceAppContentGetEntitlementKey);
lib.set_proc($DEB1D6695FF5282E,@ps4_sceAppContentAddcontUnmount);
end;
var
stub:t_int_file;
initialization
ps4_app.RegistredPreLoad('libSceAppContent.prx',@Load_libSceAppContent);
reg_int_file(stub,'libSceAppContent.prx',@Load_libSceAppContent);
end.

View File

@ -424,7 +424,7 @@ const
libname :nil;
libfrom :nil);
procedure unresolve_symbol_print(nid:QWORD;libname,libfrom:PChar);
procedure unresolve_symbol_print(nid:QWORD;libname,modname,libfrom:PChar);
var
str:shortstring;
begin
@ -439,6 +439,7 @@ begin
' nid ='+EncodeValue64(nid)+#13#10+
' name ='+str+#13#10+
' libname='+libname+#13#10+
' modname='+modname+#13#10+
' libfrom='+libfrom+#13#10;
print_error_td(str);
@ -454,7 +455,7 @@ begin
td^.td_frame.tf_rip:=PQWORD(td^.td_frame.tf_rsp)^;
unresolve_symbol_print(data^.nid,data^.libname,data^.libfrom);
unresolve_symbol_print(data^.nid,data^.libname,nil,data^.libfrom);
end;
procedure _unresolve_symbol; assembler; nostackframe; public;
@ -588,7 +589,7 @@ begin
if Result then
begin
unresolve_symbol_print(req.nid,req.libname,dynlib_basename(obj^.lib_path));
unresolve_symbol_print(req.nid,req.libname,req.modname,dynlib_basename(obj^.lib_path));
end;
end;

View File

@ -18,10 +18,10 @@ uses
type
TLIBRARY=object
lib:Pointer;
function set_symb(nid:QWORD;info:Byte;value:Pointer):Boolean;
function set_proc(nid:QWORD;value:Pointer):Boolean;
function set_data(nid:QWORD;value:Pointer):Boolean;
function set_weak(nid:QWORD;value:Pointer):Boolean;
function set_symb (nid:QWORD;info:Byte;value:Pointer;mod_id:Word=0):Boolean;
function set_proc (nid:QWORD;value:Pointer;mod_id:Word=0):Boolean;
function set_data (nid:QWORD;value:Pointer;mod_id:Word=0):Boolean;
function set_weak (nid:QWORD;value:Pointer;mod_id:Word=0):Boolean;
function get_value(nid:QWORD):Pointer;
end;
@ -145,7 +145,7 @@ type
procedure init_rel_data;
function add_str(str:pchar):QWORD;
function add_lib(lib_name:pchar;import:Word=0):TLIBRARY;
procedure add_mod(mod_name:pchar;import:Word=0);
function add_mod(mod_name:pchar;import:Word=0):WORD;
end;
p_Objlist_Entry=^Objlist_Entry;
@ -479,7 +479,7 @@ begin
Result.lib:=lib_entry;
end;
procedure t_lib_info.add_mod(mod_name:pchar;import:Word=0);
function t_lib_info.add_mod(mod_name:pchar;import:Word=0):WORD;
label
rep;
var
@ -504,9 +504,11 @@ begin
mod_entry^.dval.name_offset:=add_str(mod_name);
TAILQ_INSERT_TAIL(@mod_table,mod_entry,@mod_entry^.link);
Result:=mod_entry^.dval.id;
end;
function TLIBRARY.set_symb(nid:QWORD;info:Byte;value:Pointer):Boolean;
function TLIBRARY.set_symb(nid:QWORD;info:Byte;value:Pointer;mod_id:Word=0):Boolean;
var
lib_entry:p_Lib_Entry;
h_entry:p_sym_hash_entry;
@ -517,7 +519,7 @@ begin
h_entry:=AllocMem(SizeOf(t_sym_hash_entry));
//
h_entry^.nid :=nid;
h_entry^.mod_id:=0; //export
h_entry^.mod_id:=mod_id; //export -> mod_id=0
h_entry^.lib_id:=lib_entry^.dval.id;
//
h_entry^.sym.st_info :=info;
@ -549,19 +551,19 @@ begin
end;
end;
function TLIBRARY.set_proc(nid:QWORD;value:Pointer):Boolean;
function TLIBRARY.set_proc(nid:QWORD;value:Pointer;mod_id:Word=0):Boolean;
begin
Result:=set_symb(nid,(STB_GLOBAL shl 4) or STT_FUN,value);
Result:=set_symb(nid,(STB_GLOBAL shl 4) or STT_FUN,value,mod_id);
end;
function TLIBRARY.set_data(nid:QWORD;value:Pointer):Boolean;
function TLIBRARY.set_data(nid:QWORD;value:Pointer;mod_id:Word=0):Boolean;
begin
Result:=set_symb(nid,(STB_GLOBAL shl 4) or STT_OBJECT,value);
Result:=set_symb(nid,(STB_GLOBAL shl 4) or STT_OBJECT,value,mod_id);
end;
function TLIBRARY.set_weak(nid:QWORD;value:Pointer):Boolean;
function TLIBRARY.set_weak(nid:QWORD;value:Pointer;mod_id:Word=0):Boolean;
begin
Result:=set_symb(nid,(STB_WEAK shl 4) or STT_FUN,value);
Result:=set_symb(nid,(STB_WEAK shl 4) or STT_FUN,value,mod_id);
end;
function TLIBRARY.get_value(nid:QWORD):Pointer;
@ -2428,13 +2430,14 @@ begin
if (obj^.rtld_flags.init_plt<>0) then Exit;
Result:=change_relro_protection(obj,VM_PROT_RW);
if (Result<>0) then Exit;
entry:=obj^.rel_data^.pltrela_addr;
count:=obj^.rel_data^.pltrela_size div SizeOf(elf64_rela);
if (entry<>nil) and (count<>0) then
begin
Result:=change_relro_protection(obj,VM_PROT_RW);
if (Result<>0) then Exit;
For i:=0 to count-1 do
begin
kaddr:=i or QWORD($effffffe00000000);
@ -2467,7 +2470,8 @@ begin
Inc(entry);
end;
err:=change_relro_protection(obj,VM_PROT_READ);
err:=change_relro_protection(obj,VM_PROT_READ);
end;
obj^.rtld_flags.init_plt:=1;
end;
@ -2907,10 +2911,12 @@ const
);
function preload_prx_internal(name:pchar;flag:ptruint):p_lib_info;
label
_error;
var
entry:p_int_file;
path:pchar;
error:Integer;
err:Integer;
begin
Result:=nil;
@ -2942,25 +2948,32 @@ begin
obj_set_lib_path(Result,path);
object_add_name(Result,dynlib_basename(Result^.lib_path));
///Result^.lib_dirname neded???
alloc_tls(Result);
error:=map_prx_internal(name,Result);
if (error<>0) then
//load fake code mem
err:=map_prx_internal(name,Result);
if (err<>0) then
begin
obj_free(Result);
Exit(nil);
_error:
obj_free(Result);
Exit(nil);
end;
//
err:=digest_dynamic(Result);
if (err<>0) then
begin
Writeln(StdErr,'preload_prx_internal:','digest_dynamic() failed rv=',err);
goto _error;
end;
//reg lib
dynlibs_add_obj(Result);
//
Result^.rtld_flags.init_plt :=1;
Result^.rtld_flags.is_system:=1;
Result^.rtld_flags.internal:=1;
Result^.rtld_flags.internal :=1;
Result^.loaded:=1;
Writeln(' preload_prx_internal:',path);