Created
October 4, 2022 22:10
-
-
Save afulsamet/39b8ae12549506f69aff0a3008a1ba43 to your computer and use it in GitHub Desktop.
Inline string with using bit_cast (std:c++20)
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
#include <bit> | |
#include <array> | |
int main() | |
{ | |
// Create raw array in stack: rsp+2C | |
volatile std::uint32_t stack[3]; | |
// mov dword ptr ss:[rsp+2C], 6C6C6548 | |
stack[0] = std::integral_constant<std::uint32_t, std::bit_cast<std::uint32_t>(std::array<char, sizeof(std::uint32_t)>{'H', 'e', 'l', 'l'})>::value; | |
// mov dword ptr ss:[rsp+30], 6F57206F | |
stack[1] = std::integral_constant<std::uint32_t, std::bit_cast<std::uint32_t>(std::array<char, sizeof(std::uint32_t)>{'o', ' ', 'W', 'o'})>::value; | |
// mov dword ptr ss:[rsp+34], 646C72 | |
stack[2] = std::integral_constant<std::uint32_t, std::bit_cast<std::uint32_t>(std::array<char, sizeof(std::uint32_t)>{'r', 'l', 'd', '\0'})>::value; | |
// lea rdx, qword ptr ss:[rsp+2C] | |
std::printf("%s", (const char *)(&stack)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
x64 disassembly
Output