Skip to content

Commit 27fedb2

Browse files
committed
Added a function that writes a bl branch
1 parent ea7e448 commit 27fedb2

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

ttyd-tools/rel/include/patch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace mod::patch {
88

99
void writeBranch(void *ptr, void *destination);
10+
void writeBranchLR(void *ptr, void *destination);
11+
void writeBranchMain(void *ptr, void *destination, uint32_t branch);
1012

1113
template<typename Func, typename Dest>
1214
Func hookFunction(Func function, Dest destination)

ttyd-tools/rel/source/global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace mod {
88

9-
const char *VersionNumber = "v3.0.27";
9+
const char *VersionNumber = "v3.0.28";
1010

1111
const char *RootLines[] =
1212
{

ttyd-tools/rel/source/patch.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@
66
namespace mod::patch {
77

88
void writeBranch(void *ptr, void *destination)
9+
{
10+
uint32_t branch = 0x48000000; // b
11+
writeBranchMain(ptr, destination, branch);
12+
}
13+
14+
void writeBranchLR(void *ptr, void *destination)
15+
{
16+
uint32_t branch = 0x48000001; // bl
17+
writeBranchMain(ptr, destination, branch);
18+
}
19+
20+
void writeBranchMain(void *ptr, void *destination, uint32_t branch)
921
{
1022
uint32_t delta = reinterpret_cast<uint32_t>(destination) - reinterpret_cast<uint32_t>(ptr);
11-
uint32_t value = 0x48000000;
12-
value |= (delta & 0x03FFFFFC);
23+
24+
branch |= (delta & 0x03FFFFFC);
1325

1426
uint32_t *p = reinterpret_cast<uint32_t *>(ptr);
15-
*p = value;
27+
*p = branch;
1628

1729
clear_DC_IC_Cache(ptr, sizeof(uint32_t));
1830
}

0 commit comments

Comments
 (0)