jsonpiler 0.10.2

a Json syntax programming language for Windows
Documentation
use crate::prelude::*;
impl Jsonpiler {
  pub(crate) fn get_msg_box(&mut self, caller: LabelId) -> ErrOR<LabelId> {
    const SIZE: i32 = 0x40;
    let id = symbol!(self, caller, MSG_BOX);
    let heap = Global(self.symbols[HEAP]);
    let u8_to_16 = self.get_u8_to_16(id)?;
    let heap_free = self.import(KERNEL32, "HeapFree");
    let message_box_w = self.import(USER32, "MessageBoxW");
    let title = Local(Tmp, -0x08);
    let text = Local(Tmp, -0x10);
    let type_and_ret = Local(Tmp, -0x18);
    let leak = Global(self.symbols[LEAK_CNT]);
    self.link_function(
      id,
      &[
        mov_q(text, Rdx),
        mov_q(type_and_ret, R8),
        mov_d(Rdx, 65001),
        Call(u8_to_16),
        mov_q(title, Rax),
        mov_q(Rcx, text),
        mov_d(Rdx, 65001),
        Call(u8_to_16),
        mov_q(text, Rax),
        Clear(Rcx),
        mov_q(Rdx, text),
        mov_q(R8, title),
        mov_q(R9, type_and_ret),
        CallApiCheck(message_box_w),
        mov_q(type_and_ret, Rax),
        mov_q(Rcx, heap),
        Clear(Rdx),
        mov_q(R8, title),
        CallApiCheck(heap_free),
        DecMd(leak),
        mov_q(Rcx, heap),
        Clear(Rdx),
        mov_q(R8, text),
        CallApiCheck(heap_free),
        DecMd(leak),
        mov_q(Rax, type_and_ret),
      ],
      SIZE,
    );
    Ok(id)
  }
  pub(crate) fn get_print(&mut self, caller: LabelId) -> ErrOR<LabelId> {
    const SIZE: i32 = 0x20;
    let id = symbol!(self, caller, PRINT);
    let print_n = self.get_print_n(id)?;
    let std_o = Global(self.symbols[STD_O]);
    self.link_function(id, &[mov_q(Rdx, std_o), Call(print_n)], SIZE);
    Ok(id)
  }
  pub(crate) fn get_print_e(&mut self, caller: LabelId) -> ErrOR<LabelId> {
    const SIZE: i32 = 0x20;
    let id = symbol!(self, caller, PRINT_E);
    let print_n = self.get_print_n(id)?;
    let std_e = Global(self.symbols[STD_E]);
    self.link_function(id, &[mov_q(Rdx, std_e), Call(print_n)], SIZE);
    Ok(id)
  }
  pub(crate) fn get_print_n(&mut self, caller: LabelId) -> ErrOR<LabelId> {
    const SIZE: i32 = 0x40;
    let id = symbol!(self, caller, PRINT_N);
    let write_file = self.import(KERNEL32, "WriteFile");
    let str_len = self.str_len(id)?;
    let std_n_and_tmp = Local(Tmp, -0x08);
    let string = Local(Tmp, -0x10);
    self.link_function(
      id,
      &[
        mov_q(string, Rcx),
        mov_q(std_n_and_tmp, Rdx),
        Call(str_len),
        mov_q(R8, Rax),
        mov_q(Rcx, std_n_and_tmp),
        mov_q(Rdx, string),
        LeaRM(R9, std_n_and_tmp),
        Clear(Rax),
        mov_q(Args(5), Rax),
        CallApiCheck(write_file),
      ],
      SIZE,
    );
    Ok(id)
  }
  pub(crate) fn get_u16_to_8(&mut self, caller: LabelId) -> ErrOR<LabelId> {
    const SIZE: i32 = 0x60;
    let id = symbol!(self, caller, U16TO8);
    let heap = Global(self.symbols[HEAP]);
    let to_multi_byte = self.import(KERNEL32, "WideCharToMultiByte");
    let heap_alloc = self.import(KERNEL32, "HeapAlloc");
    let cp = Local(Tmp, -0x04);
    let tmp_d = Local(Tmp, -0x10);
    let tmp_s = Local(Tmp, -0x18);
    let tmp_b = Local(Tmp, -0x20);
    let leak = Global(self.symbols[LEAK_CNT]);
    self.link_function(
      id,
      &[
        mov_q(tmp_d, Rdi),
        mov_q(tmp_s, Rsi),
        mov_q(tmp_b, Rbx),
        mov_q(Rdi, Rcx),
        mov_d(cp, Rdx),
        mov_d(Rcx, Rdx),
        Clear(Rdx),
        mov_q(R8, Rdi),
        mov_d(R9, u32::MAX),
        mov_q(Args(5), Rdx),
        mov_q(Args(6), Rdx),
        mov_q(Args(7), Rdx),
        mov_q(Args(8), Rdx),
        CallApiCheck(to_multi_byte),
        mov_q(Rsi, Rax),
        mov_q(Rcx, heap),
        mov_d(Rdx, 8),
        mov_q(R8, Rsi),
        CallApi(heap_alloc),
        IncMd(leak),
        mov_q(Rbx, Rax),
        mov_d(Rcx, cp),
        Clear(Rdx),
        mov_q(R8, Rdi),
        mov_d(R9, u32::MAX),
        mov_q(Rax, Rbx),
        mov_q(Args(5), Rax),
        mov_q(Rax, Rsi),
        mov_q(Args(6), Rax),
        mov_q(Args(7), Rdx),
        mov_q(Args(8), Rdx),
        CallApiCheck(to_multi_byte),
        AddRR(Rax, Rbx),
        DecR(Rax),
        Clear(Rcx),
        mov_b(Ref(Rax), Rcx),
        DecR(Rax),
        mov_b(Ref(Rax), Rcx),
        mov_q(Rax, Rbx),
        mov_q(Rdi, tmp_d),
        mov_q(Rsi, tmp_s),
        mov_q(Rbx, tmp_b),
      ],
      SIZE,
    );
    Ok(id)
  }
  pub(crate) fn get_u8_to_16(&mut self, caller: LabelId) -> ErrOR<LabelId> {
    const SIZE: i32 = 0x60;
    let id = symbol!(self, caller, U8TO16);
    let heap = Global(self.symbols[HEAP]);
    let to_wide_char = self.import(KERNEL32, "MultiByteToWideChar");
    let heap_alloc = self.import(KERNEL32, "HeapAlloc");
    let cp = Local(Tmp, -0x04);
    let tmp_d = Local(Tmp, -0x10);
    let tmp_s = Local(Tmp, -0x18);
    let tmp_b = Local(Tmp, -0x20);
    let leak = Global(self.symbols[LEAK_CNT]);
    self.link_function(
      id,
      &[
        mov_q(tmp_d, Rdi),
        mov_q(tmp_s, Rsi),
        mov_q(tmp_b, Rbx),
        mov_q(Rdi, Rcx),
        mov_d(cp, Rdx),
        mov_d(Rcx, Rdx),
        Clear(Rdx),
        mov_q(R8, Rdi),
        mov_d(R9, u32::MAX),
        mov_q(Args(5), Rdx),
        mov_q(Args(6), Rdx),
        CallApiCheck(to_wide_char),
        ShiftR(Shl, Rax, Shift::One),
        mov_q(Rsi, Rax),
        mov_q(Rcx, heap),
        Clear(Rdx),
        mov_q(R8, Rsi),
        CallApi(heap_alloc),
        IncMd(leak),
        mov_q(Rbx, Rax),
        mov_d(Rcx, cp),
        Clear(Rdx),
        mov_q(R8, Rdi),
        mov_d(R9, u32::MAX),
        mov_q(Args(5), Rbx),
        mov_q(Args(6), Rsi),
        CallApiCheck(to_wide_char),
        mov_q(Rax, Rbx),
        mov_q(Rdi, tmp_d),
        mov_q(Rsi, tmp_s),
        mov_q(Rbx, tmp_b),
      ],
      SIZE,
    );
    Ok(id)
  }
}