bool TryOptimize() { if (instrKind == InstrKind.Unchanged || instrKind == InstrKind.Short) { return(false); } var targetAddress = targetInstr.GetAddress(); var nextRip = IP + shortInstructionSize; long diff = (long)(targetAddress - nextRip); if (sbyte.MinValue <= diff && diff <= sbyte.MaxValue) { if (pointerData != null) { pointerData.IsValid = false; } instrKind = InstrKind.Short; Size = shortInstructionSize; return(true); } // If it's in the same block, we assume the target is at most 2GB away. bool useNear = bitness != 64 || targetInstr.IsInBlock(Block); if (!useNear) { targetAddress = targetInstr.GetAddress(); nextRip = IP + nearInstructionSize; diff = (long)(targetAddress - nextRip); useNear = int.MinValue <= diff && diff <= int.MaxValue; } if (useNear) { if (pointerData != null) { pointerData.IsValid = false; } instrKind = InstrKind.Near; Size = nearInstructionSize; return(true); } if (pointerData == null) { pointerData = Block.AllocPointerLocation(); } instrKind = InstrKind.Long; return(false); }
bool TryOptimize() { if (instrKind == InstrKind.Unchanged || instrKind == InstrKind.Rip || instrKind == InstrKind.Eip) { return(false); } // If it's in the same block, we assume the target is at most 2GB away. bool useRip = targetInstr.IsInBlock(Block); var targetAddress = targetInstr.GetAddress(); if (!useRip) { var nextRip = IP + ripInstructionSize; long diff = (long)(targetAddress - nextRip); useRip = int.MinValue <= diff && diff <= int.MaxValue; } if (useRip) { Size = ripInstructionSize; instrKind = InstrKind.Rip; return(true); } // If it's in the lower 4GB we can use EIP relative addressing if (targetAddress <= uint.MaxValue) { Size = eipInstructionSize; instrKind = InstrKind.Eip; return(true); } instrKind = InstrKind.Long; return(false); }
bool TryOptimize() { if (done) { return(false); } // If it's in the same block, we assume the target is at most 2GB away. bool useShort = bitness != 64 || targetInstr.IsInBlock(Block); if (!useShort) { var targetAddress = targetInstr.GetAddress(); var nextRip = IP + origInstructionSize; long diff = (long)(targetAddress - nextRip); useShort = int.MinValue <= diff && diff <= int.MaxValue; } if (useShort) { if (pointerData != null) { pointerData.IsValid = false; } Size = origInstructionSize; useOrigInstruction = true; done = true; return(true); } if (pointerData == null) { pointerData = Block.AllocPointerLocation(); } return(false); }