Skip to content

Commit

Permalink
Merge branch 'main' of github.com:xeonliu/PSPDevNote
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 28, 2024
2 parents 4da6da3 + 00e376f commit d5e0cba
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 14 deletions.
108 changes: 106 additions & 2 deletions docs/libs/font.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ Unicode 中的一个编码区段,编码从 U+0000 至 U+FFFF,也称基本多

Unicode 编码规定以下字符范围为控制字符,\U0000 - \U001F, \U007F, \U0080 - \U009F。

<<<<<<< HEAD

UCS-2 用 0x0000 - 0xFFFF 代表所有UTF-8的字符。 假设一个字符为16x16, 一个byte(8Bit)可以代表8个点, 32个byte就可以代表一个字, 2Mib刚好表示整个UCS-2字库。

PSP在使用的时候, 跟据UCS2编码可以直接算出偏移量, 并取出32个byte, 进行位运算, 打印出一个字符.
=======
# PGF

26.9 PGF
Expand Down Expand Up @@ -134,4 +133,109 @@ Module("sceLibFont",
new SCE(0x5dcf6858, "sceFontGetShadowGlyphImage_Clip", 'i', "xxxiiii"),
new SCE(0x02d7f94b, "sceFontFlush", 'i', "x")
)

font_fuck library 还不止一种,有许多变种,但是大体上应该是一致的。

29个
sceFontisElement?


23:25:362 user_main D[SCEFONT]: HLE\sceFont.cpp:1333 sceFontGetCharInfo(08c4c05c, 27700, 09ff72f0)
23:25:362 user_main D[SCEFONT]: HLE\sceFont.cpp:1434 sceFontGetCharGlyphImage(8c4c05c, 6c34, 9ff72d0)
23:25:362 user_main D[SCEFONT]: HLE\sceFont.cpp:1333 sceFontGetCharInfo(08c4c05c, 28304, 09ff72f0)
23:25:362 user_main D[SCEFONT]: HLE\sceFont.cpp:1434 sceFontGetCharGlyphImage(8c4c05c, 6e90, 9ff72d0)
23:25:362 user_main D[SCEFONT]: HLE\sceFont.cpp:1333 sceFontGetCharInfo(08c4c05c, 21551, 09ff72f0)
23:25:362 user_main D[SCEFONT]: HLE\sceFont.cpp:1434 sceFontGetCharGlyphImage(8c4c05c, 542f, 9ff72d0)
23:25:362 user_main D[SCEFONT]: HLE\sceFont.cpp:1333 sceFontGetCharInfo(08c4c05c, 21160, 09ff72f0)
23:25:362 user_main D[SCEFONT]: HLE\sceFont.cpp:1434 sceFontGetCharGlyphImage(8c4c05c, 52a8, 9ff72d0)

0x9480

```cpp
undefined2 FUN_08884680(uint param_1)

{
undefined4 uVar1;
undefined4 uVar2;
uint uVar3;

param_1 = param_1 & 0xffff;
uVar1 = 0;
uVar2 = 0x2d;
if (DAT_08a33310 <= param_1) {
uVar1 = 0x2e;
uVar2 = 0x5a;
if (param_1 <= DAT_08a33310) {
uVar3 = 0x2d;
goto LAB_088846d0;
}
}
uVar3 = FUN_08884724(param_1,uVar1,uVar2);
uVar3 = uVar3 & 0xffff;
LAB_088846d0:
return *(undefined2 *)
(&DAT_08a2fb60 +
//(
//(param_1 - *(ushort *)(&DAT_08a3325c + uVar3 * 4))
//+
// Next one at 0x8a3325e
(uint)*(ushort *)(&DAT_08a3325e + uVar3 * 4)
)
* 2);
}


uint FUN_08884724(ushort param_1,uint param_2,uint param_3)

{
uint uVar1;
uint uVar2;
uint uVar3;

param_3 = param_3 & 0xffff;
param_2 = param_2 & 0xffff;
uVar3 = param_3 + param_2 >> 1;
uVar1 = param_3 - 1 & 0xffff;
if ((param_3 != param_2) &&
((uVar2 = uVar3, param_1 < *(ushort *)(&DAT_08a3325c + uVar3 * 4) ||
(param_2 = uVar3 + 1 & 0xffff, uVar2 = param_3, uVar1 = uVar3,
*(ushort *)(&DAT_08a3325c + uVar3 * 4) < param_1)))) {
uVar1 = FUN_08884724(param_1,param_2,uVar2);
}
// param1==*(ushort *)(&DAT_08a3325c + uVar3 * 4)
return uVar1;
}


```
08a3325c -> 0~0x5a
20 00 00 00 a1 00 5f 00 40 81 9e 00 80 81 dd 00 b8 81 0a 01 c8 81 12 01 da 81 19 01 f0 81 28 01 fc 81 30 01 4f 82 31 01 60 82 3b 01 81 82 55 01 9f 82 6f 01 40 83 c2 01 80 83 01 02 9f 83 18 02 bf 83 30 02 40 84 48 02 70 84 69 02 80 84 78 02 9f 84 8a 02 9f 88 aa 02 40 89 08 03 80 89 47 03 40 8a c4 03 80 8a 03 04 40 8b 80 04 80 8b bf 04 40 8c 3c 05 80 8c 7b 05 40 8d f8 05 80 8d 37 06 40 8e b4 06 80 8e f3 06 40 8f 70 07 80 8f af 07 40 90 2c 08 80 90 6b 08 40 91 e8 08 80 91 27 09 40 92 a4 09 80 92 e3 09 40 93 60 0a 80 93 9f 0a 40 94 1c 0b 80 94 5b 0b 40 95 d8 0b 80 95 17 0c 40 96 94 0c 80 96 d3 0c 40 97 50 0d 80 97 8f 0d 40 98 0c 0e 9f 98 3f 0e 40 99 9d 0e 80 99 dc 0e 40 9a 59 0f 80 9a 98 0f 40 9b 15 10 80 9b 54 10 40 9c d1 10 80 9c 10 11 40 9d 8d 11 80 9d cc 11 40 9e 49 12 80 9e 88 12 40 9f 05 13 80 9f 44 13 40 e0 c1 13 80 e0 00 14 40 e1 7d 14 80 e1 bc 14 40 e2 39 15 80 e2 78 15 40 e3 f5 15 80 e3 34 16 40 e4 b1 16 80 e4 f0 16 40 e5 6d 17 80 e5 ac 17 40 e6 29 18 80 e6 68 18 40 e7 e5 18 80 e7 24 19 40 e8 a1 19 80 e8 e0 19 40 e9 5d 1a 80 e9 9c 1a 40 ea 19 1b 80 ea 58 1b
00000020 005f00a1 009e8140 00dd8180 010a81b8 011281c8 011981da 012881f0 013081fc 0131824f 013b8260 01558281 016f829f 01c28340 02018380 0218839f 023083bf 02488440 02698470 02788480 028a849f 02aa889f 03088940 03478980 03c48a40 04038a80 04808b40 04bf8b80 053c8c40 057b8c80 05f88d40 06378d80 06b48e40 06f38e80 07708f40 07af8f80 082c9040 086b9080 08e89140 09279180 09a49240 09e39280 0a609340 0a9f9380 0b1c9440 0b5b9480 0bd89540 0c179580 0c949640 0cd39680 0d509740 0d8f9780 0e0c9840 0e3f989f 0e9d9940 0edc9980 0f599a40 0f989a80 10159b40 10549b80 10d19c40 11109c80 118d9d40 11cc9d80 12499e40 12889e80 13059f40 13449f80 13c1e040 1400e080 147de140 14bce180 1539e240 1578e280 15f5e340 1634e380 16b1e440 16f0e480 176de540 17ace580 1829e640 1868e680 18e5e740 1924e780 19a1e840 19e0e880 1a5de940 1a9ce980 1b19ea40 1b58ea80
第二位,
40-7E
80-FC
仅仅有编码的区域被列入。
ea80-eaa4
最末一位偏移量 1b58 + 25 = 1B7d = 7037
恰好为SHIFT-JIS编码总数
(7070?)有待查询,或许有些许删节。
GB2312有6763个汉字+682个全角字符。
字体替换:将对SceFontOpen的调用变为SceFontOpenUserFile的调用。
不知道Fontfuck Library的适用程度如何。
处于某些原因,PPSSPP无法正确解析PGF文件?可能是其SceFont实现有一些问题?
Jpcsp对于现成的字体没有什么问题。
CLANNED用的是微软雅黑,对字库进行了修改。
Jpcsp使用的是Resource Han Rounded CN,可以说是对于中文用户十分友好了。
MGSPW用的是微软雅黑Bold,没有对字库进行修改。Font='Microsoft YaHei UI' Type='Bold'
>>>>>>> 04bea76e94d934b878c995d594ce433b4f3be225
82 changes: 82 additions & 0 deletions docs/libs/reverse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @brief This file is a reversed version of TPU's libfont.prx (fontfunk) library
* Based on the libfont.prx binary, with reference to hz86/mgspw, a locolization plugin for Metal Gear Solid: Peace Walker
*/


// The Error Code definitions.

// https://github.com/uofw/uofw/blob/master/include/common/errors.h#L286
#define SCE_ERROR_KERNEL_LIBRARY_IS_NOT_LINKED 0x8002013A

// https://www.psdevwiki.com/vita/Error_Codes
#define SCE_FONT_ERROR_FILEOPEN 0x80460005
#define SCE_FONT_ERROR_FILECLOSE 0x80460006
#define SCE_FONT_ERROR_FILEREAD 0x80460007
#define SCE_FONT_ERROR_FILESEEK 0x80460008

PSP_MODULE_INFO("fontfuck", 0x0006, 1, 1);

int fuck_thread() {
printf("Fontfuck Start!\n")
int status;
SceUID modid = sceKernelLoadModule("disc0:/PSP_GAME/USRDIR/oldfont.prx", 0, NULL);
if(modid>0) {
sceKernelStartModule(modid,0,NULL,&status,0);
}
sceKernelExitDeleteThread(0);
return 0;
}

int module_start(int argc, char** argv)
{
SceUID thid;
thid = sceKernelCreateThread("fontfuck",fuck_thread,0x19,0x800,0,NULL);
if(thid>0){
sceKernelStartThread(thid, argc, argv);
}
return 0;
}

// strlen函数,乐
void sceFontNewLib(int param_1,undefined4 param_2)
{
int iVar1;

if (*(int *)(param_1 + 0x14) == 0) {
*(undefined4 *)(param_1 + 0x14) = 0x2d4;
*(undefined4 *)(param_1 + 0x18) = 0x2a0;
*(undefined4 *)(param_1 + 0x1c) = 0x21c;
*(undefined4 *)(param_1 + 0x20) = 0x1e0;
}
while ((iVar1 = sceFontNewLib(param_1,param_2)) == SCE_ERROR_KERNEL_LIBRARY_IS_NOT_LINKED) {
sceKernelDelayThread(200000);
}
return;
}

static void *my_open(void *pdata, char *filename, int *error)
{
SceUID fd = sceIoOpen(filename, PSP_O_RDONLY, 0);
if(fd < 0) {*error = SCE_FONT_ERROR_FILEOPEN; return 0;}
*error = 0; return (void *)fd;
}


static int my_close(void *pdata, void *fileid)
{
return sceIoClose((SceUID)fileid) < 0 ? SCE_FONT_ERROR_FILECLOSE : 0;
}

static int my_read(void *pdata, void *fileid, void *pbuf, int byte, int unit, int *error)
{
int count = byte * unit;
int retv = sceIoRead((SceUID)fileid, pbuf, count);
if(retv < count) {*error = SCE_FONT_ERROR_FILEREAD; return 0;}
*error = 0; return unit;
}

static int my_seek(void *pdata, void *fileid, int offset)
{
return sceIoLseek32((SceUID)fileid, offset, PSP_SEEK_SET) < 0 ? SCE_FONT_ERROR_FILESEEK : 0;
}
25 changes: 24 additions & 1 deletion docs/moduleload.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,27 @@ restart and open

manage prx

# 地址空间
# 地址空间

sceModuleInfo
内核如何管理Moudule


TN-HEN 6.20

Total Noob Homebrew Enabler OF 6.20(Can not load ISO on XMB)

Prometheus ISO Loader (liquidzigong)
-> Load ISO on XMB.

You can find videos & screenshots.

https://gbatemp.net/threads/liquidzigong-has-quit-the-psp-scene.267699/

https://baike.baidu.com/item/liquidzigong/6154040

http://news.17173.com/content/12172020/102020086.shtml

https://gamergen.com/actualites/liquidzigong-prometheus-quitte-scene-psp-fake-48302-1/amp

http://zerofuga0613.blog65.fc2.com/blog-entry-76.html
39 changes: 28 additions & 11 deletions docs/prxfilestruct.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PRX是特殊的ELF文件,包含了一些PSP独有的段(Section)
> Dump information in `prx` file
## 反汇编PRX的工具
+ `psp-objdump`
<!-- + `psp-objdump` -->

+ [`prxtool`](https://github.com/pspdev/prxtool)

Expand All @@ -16,7 +16,7 @@ PRX是特殊的ELF文件,包含了一些PSP独有的段(Section)

## File section

`psp-objdump -x ./ULJS00064_USER_MAIN.BIN `
`psp-objdump -x ./ULJS00064_USER_MAIN.BIN`
```
psp@pspserver:~/code/test$ psp-objdump -x ./ULJS00064_USER_MAIN.BIN
Expand Down Expand Up @@ -106,23 +106,35 @@ no symbols
```

## 代码段(.text)
(.text, containing the module text, which is the executed machine code; .rodata, containing read-only data; .data, containing data which may be modified during the program execution.)
### PRX文件中的两种函数
> (.text, containing the module text, which is the executed machine code; .rodata, containing read-only data; .data, containing data which may be modified during the program execution.)
> uofw Wiki
>
> + `prxtool -w`: Disasm the executable sections of the file`
>
> + `prxtool -m`: inspect import & export
### PRX文件中存在实现的两种函数

+ `prxtool -m`: inspect import&export
+ `prxtool -w`: Disasm the executable sections of the file`
+ Exported Functions (Referenced in `.rodata.sceResident`)

+ exported functions (Shown in `.rodata`)
供外部模块使用的函数,也即导出的函数
+ Subroutine

供外部使用的函数
+ subroutine
供模块自身内部使用的函数

供内部使用的函数
## .sceStub.text
+ Imported Functinos

## 只读文件段(.rodata)
从外部模块导入的函数
```
jr ra
nop
```
包含的都是空实现。在加载时由PSP内核进行动态链接。
## 只读数据段(.rodata)

### .rodata.sceModuleInfo 段
包含了模块的基本信息。由PSP_MOUDULE_INFO宏定义。
```
psp@pspserver:~/code/test$ psp-objdump -s -j .rodata.sceModuleInfo ./ULJS00064_USER_MAIN.BIN
Expand All @@ -134,3 +146,8 @@ Contents of section .rodata.sceModuleInfo:
1aee8c f0130800 d4ec1a00 e4ec1a00 ecec1a00 ................
1aee9c 68ee1a00 h...
```
## 导出表相关
### .lib.ent
导出表的表项。
### .rodata.sceResident
导出的一个库中导出的NID、函数地址
1 change: 1 addition & 0 deletions docs/stublibs.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const struct _PspLibraryEntry __library_exports[2] __attribute__((section(".lib.
};
```
生成的C代码的作用实际上是在`.rodata.sceResident`段中以连续的结构体数组存入每个导出的Library中导出函数的NID和导出的函数的地址。然后在`.lib.ent`段使用模块名和`.rodata.sceResient`中对应项的地址创建相应的导出条目。

|Segment Name|Export Index|Export Entry|Data|Type|
|---|---|---|---|----|
|.rodata.sceResident|1|__syslib_exports|MagicNumber|uint32|
Expand Down

0 comments on commit d5e0cba

Please sign in to comment.