sdk-world
v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Toggle main menu visibility
Loading...
Searching...
No Matches
ioplib.c
1
2
/*
3
# _____ ___ ____ ___ ____
4
# ____| | ____| | | |____|
5
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
6
#-----------------------------------------------------------------------
7
# Copyright 2001-2009, ps2dev - http://www.ps2dev.org
8
# Licenced under Academic Free License version 2.0
9
# Review ps2sdk README & LICENSE files for further details.
10
#
11
# taken from MX4SIO driver for simplicity.
12
# all credits go to maximus32
13
*/
14
#include "
ioplib.h
"
15
#include <intrman.h>
16
17
iop_library_t *
ioplib_getByName
(
const
char
*name)
18
{
19
iop_library_t *libptr;
20
int
i;
21
22
// Get first loaded library
23
libptr = GetLoadcoreInternalData()->let_next;
24
// Loop through all loaded libraries
25
while
(libptr != NULL) {
26
// Compare library name only
27
for
(i = 0; i < 8; i++) {
28
if
(libptr->name[i] != name[i])
29
break
;
30
}
31
32
// Return if match
33
if
(i == 8)
34
return
libptr;
35
36
// Next library
37
libptr = libptr->prev;
38
}
39
40
return
NULL;
41
}
42
43
unsigned
int
ioplib_getTableSize(iop_library_t *lib)
44
{
45
void
**exp;
46
unsigned
int
size;
47
48
exp = NULL;
49
if
(lib != NULL) {
50
exp = lib->exports;
51
}
52
size = 0;
53
54
if
(exp != NULL)
55
while
(*exp++ != NULL)
56
size++;
57
58
return
size;
59
}
60
61
void
*
ioplib_hookExportEntry
(iop_library_t *lib,
unsigned
int
entry,
void
*func)
62
{
63
if
(entry < ioplib_getTableSize(lib)) {
64
int
oldstate;
65
void
**exp, *temp;
66
67
exp = &lib->exports[entry];
68
69
CpuSuspendIntr(&oldstate);
70
temp = *exp;
71
*exp = func;
72
func = temp;
73
CpuResumeIntr(oldstate);
74
75
return
func;
76
}
77
78
return
NULL;
79
}
80
81
void
ioplib_relinkExports(iop_library_t *lib)
82
{
83
struct
irx_import_table *table;
84
struct
irx_import_stub *stub;
85
86
// go through each table that imports the library
87
for
(table = lib->caller; table != NULL; table = table->next) {
88
// go through each import in the table
89
for
(stub = (
struct
irx_import_stub *)table->stubs; stub->jump != 0; stub++) {
90
// patch the stub to jump to the address specified in the library export table for "fno"
91
stub->jump = 0x08000000 | (((u32)lib->exports[stub->fno] << 4) >> 6);
92
}
93
}
94
}
ioplib.h
ioplib_getByName
iop_library_t * ioplib_getByName(const char *name)
get library object of any IRX Module
Definition
ioplib.c:17
ioplib_hookExportEntry
void * ioplib_hookExportEntry(iop_library_t *lib, unsigned int entry, void *func)
hook an IRX Module exported function
Definition
ioplib.c:61
mmceman
src
ioplib.c
Generated by
1.18.0