MCPcopy Create free account
hub / github.com/D7EAD/mkPIVM / emit_fetch_byte_dec

Function emit_fetch_byte_dec

src/codec.cpp:111–238  ·  view source on GitHub ↗

fetch one byte from [ip], decrypt with current cipher state, update state, advance ip, leave result in low 8 of dst

Source from the content-addressed store, hash-verified

109 // fetch one byte from [ip], decrypt with current cipher state, update state,
110 // advance ip, leave result in low 8 of dst
111 void emit_fetch_byte_dec(X64Emitter& e, const VMConfig& vm, std::uint8_t dst) {
112 const auto& r = vm.dispatcher_regs();
113 const std::int32_t add_off = static_cast<std::int32_t>(vm.state_layout().cipher_extra) + kCipherAddOff;
114 const std::int32_t mult_off = static_cast<std::int32_t>(vm.state_layout().cipher_extra) + kCipherMultOff;
115 const std::int32_t sbox_off = static_cast<std::int32_t>(vm.state_layout().cipher_extra) + kSboxInvOff;
116
117 // movzx dst, byte [ip]
118 e.emit_rex(
119 false,
120 dst >= 8,
121 false,
122 r.ip >= 8
123 );
124 e.u8(0x0F); e.u8(0xB6);
125 e.emit_modrm_mem(
126 dst & 7,
127 r.ip,
128 rx::none,
129 0,
130 0
131 );
132
133 // inc ip
134 e.inc_reg(r.ip, true);
135
136 // mix byte with cipher_state low, then advance state
137 auto add_cs_mem = [&](std::int32_t disp) {
138 e.emit_rex(
139 true,
140 r.cipher_state >= 8,
141 false,
142 r.state_ptr >= 8
143 );
144 e.u8(0x03); // ADD r64, r/m64
145
146 e.emit_modrm_mem(
147 r.cipher_state & 7,
148 r.state_ptr,
149 rx::none,
150 0,
151 disp
152 );
153 };
154
155 auto imul_cs_mem = [&](std::int32_t disp) {
156 e.emit_rex(
157 true,
158 r.cipher_state >= 8,
159 false,
160 r.state_ptr >= 8
161 );
162 e.u8(0x0F); e.u8(0xAF); // IMUL r64, r/m64
163
164 e.emit_modrm_mem(
165 r.cipher_state & 7,
166 r.state_ptr,
167 rx::none,
168 0,

Callers 10

emit_state_initMethod · 0.70
emit_fetch_uN_decFunction · 0.70
emit_dispatch_tailFunction · 0.70
emit_handlerMethod · 0.70
emit_bin_handlerFunction · 0.70
emit_unary_arithFunction · 0.70
emit_shift_handlerFunction · 0.70
emit_cmp_test_handlerFunction · 0.70
emit_native_handlerFunction · 0.70
emit_state_initMethod · 0.70

Calls 10

cipher_kindMethod · 0.80
emit_rexMethod · 0.45
u8Method · 0.45
emit_modrm_memMethod · 0.45
inc_regMethod · 0.45
emit_modrmMethod · 0.45
rol_reg_imm8Method · 0.45
movzx_r64_r8Method · 0.45
emit_sibMethod · 0.45
u32Method · 0.45

Tested by

no test coverage detected