diff --git a/src/backend_x64/block_of_code.cpp b/src/backend_x64/block_of_code.cpp index 1e0eaa16..d4a059b6 100644 --- a/src/backend_x64/block_of_code.cpp +++ b/src/backend_x64/block_of_code.cpp @@ -139,6 +139,45 @@ void BlockOfCode::CallFunction(const void* fn) { } } +void BlockOfCode::nop(size_t size) { + switch (size) { + case 0: + return; + case 1: + db(0x90); + return; + case 2: + db(0x66); db(0x90); + return; + case 3: + db(0x0f); db(0x1f); db(0x00); + return; + case 4: + db(0x0f); db(0x1f); db(0x40); db(0x00); + return; + case 5: + db(0x0f); db(0x1f); db(0x44); db(0x00); db(0x00); + return; + case 6: + db(0x66); db(0x0f); db(0x1f); db(0x44); db(0x00); db(0x00); + return; + case 7: + db(0x0f); db(0x1f); db(0x80); db(0x00); db(0x00); db(0x00); db(0x00); + return; + case 8: + db(0x0f); db(0x1f); db(0x84); db(0x00); db(0x00); db(0x00); db(0x00); db(0x00); + return; + case 9: + db(0x66); db(0x0f); db(0x1f); db(0x84); db(0x00); db(0x00); db(0x00); db(0x00); db(0x00); + return; + case 10: + default: + db(0x66); db(0x2e); db(0x0f); db(0x1f); db(0x84); db(0x00); db(0x00); db(0x00); db(0x00); db(0x00); + nop(size - 10); + return; + } +} + void BlockOfCode::SetCodePtr(CodePtr ptr) { // The "size" defines where top_, the insertion point, is. size_t required_size = reinterpret_cast(ptr) - getCode(); diff --git a/src/backend_x64/block_of_code.h b/src/backend_x64/block_of_code.h index f15df9bb..20f2ce2a 100644 --- a/src/backend_x64/block_of_code.h +++ b/src/backend_x64/block_of_code.h @@ -80,11 +80,7 @@ public: } void int3() { db(0xCC); } - void nop(size_t size = 0) { - for (size_t i = 0; i < size; i++) { - db(0x90); - } - } + void nop(size_t size = 0); void SetCodePtr(CodePtr ptr); void EnsurePatchLocationSize(CodePtr begin, size_t size);