Skip to content

Commit

Permalink
Store near branch target in mem_displ field
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Oct 5, 2021
1 parent d9b4161 commit 8a46c32
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
18 changes: 7 additions & 11 deletions src/csharp/Intel/Iced/Intel/Instruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ enum MvexInstrFlags : uint {
ulong nextRip;
ulong memDispl;
uint flags1;// InstrFlags1
// If it's a 64-bit immediate/offset/target, the high 32 bits is in memDispl
uint immediate;
ushort code;
byte memBaseReg;// Register
Expand Down Expand Up @@ -897,32 +896,29 @@ public long Immediate32to64 {
/// Gets the operand's branch target. Use this property if the operand has kind <see cref="OpKind.NearBranch16"/>
/// </summary>
public ushort NearBranch16 {
readonly get => (ushort)immediate;
set => immediate = value;
readonly get => (ushort)memDispl;
set => memDispl = value;
}
internal uint InternalNearBranch16 {
set => immediate = value;
set => memDispl = value;
}

/// <summary>
/// Gets the operand's branch target. Use this property if the operand has kind <see cref="OpKind.NearBranch32"/>
/// </summary>
public uint NearBranch32 {
readonly get => immediate;
set => immediate = value;
readonly get => (uint)memDispl;
set => memDispl = value;
}

/// <summary>
/// Gets the operand's branch target. Use this property if the operand has kind <see cref="OpKind.NearBranch64"/>
/// </summary>
public ulong NearBranch64 {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
readonly get => (memDispl << 32) | immediate;
readonly get => memDispl;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set {
immediate = (uint)value;
memDispl = (uint)(value >> 32);
}
set => memDispl = value;
}

/// <summary>
Expand Down
14 changes: 6 additions & 8 deletions src/rust/iced-x86/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub struct Instruction {
pub(crate) next_rip: u64,
pub(crate) mem_displ: u64,
pub(crate) flags1: u32, // InstrFlags1
// If it's a 64-bit immediate/offset/target, the high 32 bits is in mem_displ
pub(crate) immediate: u32,
pub(crate) code: Code,
pub(crate) mem_base_reg: Register,
Expand Down Expand Up @@ -1360,7 +1359,7 @@ impl Instruction {
#[must_use]
#[inline]
pub fn near_branch16(&self) -> u16 {
self.immediate as u16
self.mem_displ as u16
}

/// Sets the operand's branch target. Use this method if the operand has kind [`OpKind::NearBranch16`]
Expand All @@ -1372,7 +1371,7 @@ impl Instruction {
/// * `new_value`: New value
#[inline]
pub fn set_near_branch16(&mut self, new_value: u16) {
self.immediate = new_value as u32;
self.mem_displ = new_value as u64;
}

/// Gets the operand's branch target. Use this method if the operand has kind [`OpKind::NearBranch32`]
Expand All @@ -1381,7 +1380,7 @@ impl Instruction {
#[must_use]
#[inline]
pub fn near_branch32(&self) -> u32 {
self.immediate
self.mem_displ as u32
}

/// Sets the operand's branch target. Use this method if the operand has kind [`OpKind::NearBranch32`]
Expand All @@ -1393,7 +1392,7 @@ impl Instruction {
/// * `new_value`: New value
#[inline]
pub fn set_near_branch32(&mut self, new_value: u32) {
self.immediate = new_value;
self.mem_displ = new_value as u64;
}

/// Gets the operand's branch target. Use this method if the operand has kind [`OpKind::NearBranch64`]
Expand All @@ -1402,7 +1401,7 @@ impl Instruction {
#[must_use]
#[inline]
pub fn near_branch64(&self) -> u64 {
(self.mem_displ << 32) | self.immediate as u64
self.mem_displ
}

/// Sets the operand's branch target. Use this method if the operand has kind [`OpKind::NearBranch64`]
Expand All @@ -1414,8 +1413,7 @@ impl Instruction {
/// * `new_value`: New value
#[inline]
pub fn set_near_branch64(&mut self, new_value: u64) {
self.immediate = new_value as u32;
self.mem_displ = new_value >> 32;
self.mem_displ = new_value
}

/// Gets the near branch target if it's a `CALL`/`JMP`/`Jcc` near branch instruction
Expand Down
2 changes: 1 addition & 1 deletion src/rust/iced-x86/src/instruction_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub(crate) fn internal_set_immediate64_hi(this: &mut Instruction, new_value: u32
#[cfg(feature = "decoder")]
#[inline]
pub(crate) fn internal_set_near_branch16(this: &mut Instruction, new_value: u32) {
this.immediate = new_value;
this.mem_displ = new_value as u64;
}

#[cfg(feature = "decoder")]
Expand Down

0 comments on commit 8a46c32

Please sign in to comment.