MCPcopy Create free account
hub / github.com/eigenform/perfect / pad_until

Method pad_until

perfect/src/asm.rs:259–295  ·  view source on GitHub ↗

Pad with NOP (up to the 8-byte encoding) until the requested address. Returns the number of emitted bytes.

(&mut self, addr: usize)

Source from the content-addressed store, hash-verified

257 /// Pad with NOP (up to the 8-byte encoding) until the requested address.
258 /// Returns the number of emitted bytes.
259 pub fn pad_until(&mut self, addr: usize) -> usize {
260 if self.cur_addr() == addr {
261 return 0;
262 }
263
264 assert!(addr > self.cur_addr(),
265 "Requested pad target {:016x} must be > cursor {:016x}",
266 addr, self.cur_addr(),
267 );
268 assert!(addr <= self.max_addr(),
269 "Requested {:016x} must be <= max addr {:016x}",
270 addr, self.max_addr(),
271 );
272
273 let mut count = 0;
274 let num_padding = addr - self.cur_addr();
275 let nop8_count = num_padding / 8;
276 let rem8 = num_padding % 8;
277 for _ in 0..nop8_count {
278 dynasm!(self ; .bytes NOP8);
279 count += 8;
280 }
281 match rem8 {
282 0 => {},
283 1 => dynasm!(self ; nop),
284 2 => dynasm!(self ; .bytes NOP2),
285 3 => dynasm!(self ; .bytes NOP3),
286 4 => dynasm!(self ; .bytes NOP4),
287 5 => dynasm!(self ; .bytes NOP5),
288 6 => dynasm!(self ; .bytes NOP6),
289 7 => dynasm!(self ; .bytes NOP7),
290 _ => unreachable!(),
291 }
292 count += rem8;
293 assert_eq!(self.cur_addr(), addr);
294 return count;
295 }
296
297 /// Write assembler to backing memory.
298 pub fn commit(&mut self) -> Result<(), &str> {

Callers 7

emit_indir_brnMethod · 0.80
emitMethod · 0.80
emitMethod · 0.80
emit_attackerMethod · 0.80
emit_jmp_directMethod · 0.80
emit_je_directMethod · 0.80
emit_je_nopadMethod · 0.80

Calls 1

cur_addrMethod · 0.80

Tested by

no test coverage detected