no_reg assembles to edi

37 views
Skip to first unread message

zhaper

unread,
Apr 20, 2013, 9:20:25 PM4/20/13
to asmji...@googlegroups.com
Hi!

I have a problem: B->mov(AsmJit::eax, AsmJit::Mem(AsmJit::ebp, AsmJit::no_reg, 0, 0xC));
this code assembles to: mov eax, [ebp+edi+0xC]

what does work properly: B->mov(AsmJit::eax, AsmJit::Mem(AsmJit::ebp, 0xC));

is this a bug or am I supposed to use the latter? I am not using it in this specific way, I wrote the example which doesn't work only for demonstration here, normally in my project I use it based on the input arguments, e.g. if I have to generate a memory operand based on whatever comes into my function, if there's no index register specified, I use no_reg ... therefore, my question is if this is a bug or should I add code for each specific case of [mem] arguments?

zhaper

unread,
Apr 20, 2013, 9:25:17 PM4/20/13
to asmji...@googlegroups.com
AsmJit::Mem x86obf_mem_op_to_asmjit(x86obf_op_t *op)
{
AsmJit::Mem mem;
const AsmJit::GPReg *base, *index;

if (op->type != UD_OP_MEM) {
x86obf_error("x86obf_mem_op_to_asmjit(): not a memory operand");
}

if (op->val_mem_base) {
base = op->val_mem_base;
} else {
base = &AsmJit::no_reg;
}

if (op->val_mem_index) {
index = op->val_mem_index;
} else {
index = &AsmJit::no_reg;
}

if (op->val_mem_size == 8) {
mem = AsmJit::byte_ptr(*base, *index, op->val_mem_scale, op->val_mem_offset);
} else if (op->val_mem_size == 16) {
mem = AsmJit::word_ptr(*base, *index, op->val_mem_scale, op->val_mem_offset);
} else if (op->val_mem_size == 32) {
mem = AsmJit::dword_ptr(*base, *index, op->val_mem_scale, op->val_mem_offset);
} else {
mem = AsmJit::Mem(*base, *index, op->val_mem_scale, op->val_mem_offset);
}

return mem;
}

Petr Kobalíček

unread,
Apr 28, 2013, 8:24:08 AM4/28/13
to asmjit-dev
Hi!

your current way of solving this issue is correct. The no_reg is currently mainly internal and I didn't expect that somebody will use it this way :) I'm working on improved version of asmjit so I will see what I can do with it.

Best regards
Petr Kobalicek


--
 
---
You received this message because you are subscribed to the Google Groups "asmjit-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to asmjit-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

zhaper

unread,
Apr 29, 2013, 9:51:36 PM4/29/13
to asmji...@googlegroups.com
Hi,

the version I attached is not the correct one, it uses no_reg. Here's a version that works if someone else gets the same issue:

Mem obf_mem_op_to_asmjit(obf_op_t *op)
{
Mem mem;


if (op->type != UD_OP_MEM) {
obf_error("obf_mem_op_to_asmjit(): not a memory operand");
}

// [base_reg + index*scale + offset]
if (op->data.mem.base && op->data.mem.index) {
if (op->data.mem.size == 8) {
mem = byte_ptr(*op->data.mem.base, *op->data.mem.index, op->data.mem.scale, op->data.mem.offset);
} else if (op->data.mem.size == 16) {
mem = word_ptr(*op->data.mem.base, *op->data.mem.index, op->data.mem.scale, op->data.mem.offset);
} else if (op->data.mem.size == 32) {
mem = dword_ptr(*op->data.mem.base, *op->data.mem.index, op->data.mem.scale, op->data.mem.offset);
} else {
mem = Mem(*op->data.mem.base, *op->data.mem.index, op->data.mem.scale, op->data.mem.offset);
}
} else {
// [base_reg + offset]
if (!op->data.mem.index && op->data.mem.base) {
if (op->data.mem.size == 8) {
mem = byte_ptr(*op->data.mem.base, op->data.mem.offset);
} else if (op->data.mem.size == 16) {
mem = word_ptr(*op->data.mem.base, op->data.mem.offset);
} else if (op->data.mem.size == 32) {
mem = dword_ptr(*op->data.mem.base, op->data.mem.offset);
} else {
mem = Mem(*op->data.mem.base, op->data.mem.offset);
}
// [offset]
} else if (!op->data.mem.base && !op->data.mem.index) {
if (op->data.mem.size == 8) {
mem = byte_ptr_abs((void *) op->data.mem.offset);
} else if (op->data.mem.size == 16) {
mem = word_ptr_abs((void *) op->data.mem.offset);
} else if (op->data.mem.size == 32) {
mem = dword_ptr_abs((void *) op->data.mem.offset);
} else {
mem = ptr_abs((void *) op->data.mem.offset);
}
} else {
obf_error("obf_mem_op_to_asmjit(): unsupported memory operand");
}
}

return mem;
}

There's one more thing, I think I've asked you about this before. Please make Labels referencable in more instructions, e.g. mov, push, etc.It would be cool if you made it so conditional jumps can take in address instead of a Label only, too.
Reply all
Reply to author
Forward
0 new messages