Last active
October 15, 2022 19:26
-
-
Save anthonyprintup/5bee486e952c1fef7f8843c8e63e5f35 to your computer and use it in GitHub Desktop.
Pass any C++ Kata by replacing the test listener's virtual functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[gnu::naked]] int mprotect_syscall(void *const, const size_t, const int) noexcept { | |
asm volatile(".intel_syntax;" | |
"mov rax, 10;" // syscall id | |
"syscall;" | |
"ret" ::: "memory", "cc"); | |
} | |
int mprotect(void *address, const size_t length, const int protection) noexcept { | |
constexpr auto page_size = 4096ul; | |
address = reinterpret_cast<void*>(reinterpret_cast<std::uintptr_t>(address) & -page_size); | |
return mprotect_syscall(address, length, protection); | |
} | |
struct Bypass { | |
Bypass() noexcept { | |
// patch le test memes | |
CodewarsTestListener listener {}; | |
const auto vftable = *reinterpret_cast<std::uintptr_t**>(&listener); | |
mprotect(vftable, 4096, 1 | 2 /* PROT_READ , PROT_WRITE */); | |
vftable[6] = vftable[5]; // CodewarsTestListener::SpecFailed = CodewarsTestListener::SpecSucceeded | |
} | |
} bypass {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment