Open tathanhdinh opened 5 years ago
Should probably have an auto &SS_BASE = IF_32BIT_ELSE(state.addr.ss_base.aword, zero1);
kind of thing. Would this work for you?
I don't recall if things like PUSH
and stuff have been properly implemented to bring in the segment.
Thanks @pgoodman.
auto &SS_BASE = IF_32BIT_ELSE(state.addr.ss_base.aword, zero1)
would work, but IMHO it's only a part of the story :(
I think the more serious problem is addr = ir.CreateAdd(addr, segment)
because in a segmented memory model, we cannot simply add add
and segment
to get the (logical) address, segment
should be used to go to the corresponding segment descriptor.
Is the issue something to do with segment permissions? What would an ideal or at least "complete" solution look like? For example, what if instead of addr = ir.CreateAdd(addr, segment)
where was something like: addr = ir.CreateCall(...)
and then call a function like TRANSLATE_ADDRESS_<seg name>(memory, state, addr)
?
Where this "address translation" function will, among other things, return addr + state.addr.XX_base.aword
.
And we can then have something like DEF_ADDR_TRANSLATE
macro that mirrors DEF_SEM
in some ways.
Yes, your proposition (of using addr = ir.CreateCall(...)
) is a perfect solution for this case.
Given instructions:
and
remill lifts to the same function:
so the segmentation (memory model) is ignored. But it's only true in Intel's 64-bit mode, in other mode (e.g. compatibility mode) the memory model has segments.
IMHO, there are several parts which can be modified to support segmented memory model. For example, the initialization of segment registers: https://github.com/trailofbits/remill/blob/9136eb565e4c3862093959b22da74ebc75e815a8/remill/Arch/X86/Runtime/BasicBlock.cpp#L162-L167
and the calculation of segmented address: https://github.com/trailofbits/remill/blob/9136eb565e4c3862093959b22da74ebc75e815a8/remill/BC/Lifter.cpp#L586-L589
and maybe others (?).
Many thanks for any response.