mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-28 00:35:47 +00:00
Merge pull request #9454 from cocoa55/fix/rewriter-branch-into-cut
fix(codegen): reject branches into a rewritten instruction
This commit is contained in:
2 files changed
+17
-1
No files matched your search
@@ -54,6 +54,12 @@ std::int64_t X64InstructionRewriter::AdjustedDelta(
|
||||
std::int64_t sliceSize,
|
||||
std::int64_t delta
|
||||
) {
|
||||
const bool targetInsideCut = targetPosition > cutStart && targetPosition < cutEnd;
|
||||
|
||||
if (targetInsideCut) {
|
||||
throw CodegenException("Branch target inside rewritten instruction", static_cast<Domain::FileByteOffset>(instrPosition));
|
||||
}
|
||||
|
||||
const bool instrShifts = instrPosition >= cutEnd && instrPosition < sliceSize;
|
||||
const bool targetShifts = targetPosition >= cutEnd && targetPosition < sliceSize;
|
||||
|
||||
|
||||
@@ -54,6 +54,16 @@ int main() {
|
||||
Require(result.Bytes == std::vector<std::uint8_t>{
|
||||
0x90, 0x90, 0x90, 0xC3});
|
||||
|
||||
bool targetInsideCutRejected = false;
|
||||
try {
|
||||
(void)rewriter.Rewrite(
|
||||
{0xEB, 0x01, 0xB8, 0x11, 0x22, 0x33, 0x44, 0xC3},
|
||||
{2, {0x90}});
|
||||
} catch (const std::exception&) {
|
||||
targetInsideCutRejected = true;
|
||||
}
|
||||
Require(targetInsideCutRejected);
|
||||
|
||||
for (const auto& code : {
|
||||
std::vector<std::uint8_t>{
|
||||
0x66, 0xEB, 0x01, 0x90, 0xC3},
|
||||
@@ -107,7 +117,7 @@ int main() {
|
||||
}
|
||||
RequireTruncatedBranchRejected(backwardWraparoundRejected);
|
||||
|
||||
std::cout << "21 rewrite boundary cases passed\n";
|
||||
std::cout << "22 rewrite boundary cases passed\n";
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
|
||||
Reference in new issue
Block a user