[][src]Macro rofi_plugin::real_c_string

real_c_string!() { /* proc-macro */ }

Transforms passed string to same look as C strings at asm level Used in vmprotect crate, because vmprotect disassembles code, and finds usages like this

#![feature(proc_macro_hygiene)]

use real_c_string::real_c_string;
assert_eq!(0i8, unsafe{*real_c_string!("")});

let c_string = real_c_string!("Hello world!");
let same_as_array_of_bytes: [i8;13] = [72i8, 101i8, 108i8, 108i8, 111i8, 32i8, 119i8, 111i8, 114i8, 108i8, 100i8, 33i8, 0i8];
for i in 0..13 {
    assert_eq!(same_as_array_of_bytes[i], unsafe{*c_string.offset(i as isize)})
}

let c_string = real_c_string!("Привет world!");
// 63i8 == '?', russian characters are not fitting in 1 byte in utf-8 character set
let same_as_array_of_bytes: [i8;14] = [63i8, 63i8, 63i8, 63i8, 63i8, 63i8, 32i8, 119i8, 111i8, 114i8, 108i8, 100i8, 33i8, 0i8];
for i in 0..13 {
    assert_eq!(same_as_array_of_bytes[i], unsafe{*c_string.offset(i as isize)})
}