-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b828166
commit 6940daf
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
# | ||
# ronin-asm - A Ruby DSL for crafting Assembly programs and shellcode. | ||
# | ||
# Copyright (c) 2007-2025 Hal Brodigan (postmodern.mod3 at gmail.com) | ||
# | ||
# ronin-asm is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# ronin-asm is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with ronin-asm. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
|
||
require_relative '../operand' | ||
|
||
module Ronin | ||
module ASM | ||
module X86 | ||
# | ||
# Represents a relative offset (`rel8` or `rel32`). | ||
# | ||
# @since 1.0.0 | ||
# | ||
class RelativeOffset < Operand | ||
|
||
# The relative offset value. | ||
# | ||
# @return [Integer] | ||
attr_reader :value | ||
|
||
# The size of the relative offset operand. | ||
# | ||
# @return [1, 4] | ||
attr_reader :width | ||
|
||
# The operand type. | ||
# | ||
# @return [:rel8, :rel32] | ||
attr_reader :type | ||
|
||
# | ||
# Initializes the relative offset. | ||
# | ||
# @param [Integer] value | ||
# The relative offset value. | ||
# | ||
def initialize(value) | ||
@value = value | ||
@width = if value.bit_length <= 8 then 1 | ||
else 4 | ||
end | ||
@type = :"rel#{@width * 8}" | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
require 'ronin/asm/x86/relative_offset' | ||
|
||
describe Ronin::ASM::X86::RelativeOffset do | ||
let(:value) { 0x1000 } | ||
|
||
subject { described_class.new(value) } | ||
|
||
describe "#initialize" do | ||
it "must set #value" do | ||
expect(subject.value).to eq(value) | ||
end | ||
|
||
context "when the value has a bit length less or equal to 8 bits" do | ||
let(:value) { 0x10 } | ||
|
||
it "must set #width to 1" do | ||
expect(subject.width).to eq(1) | ||
end | ||
|
||
it "must set #type to :rel8" do | ||
expect(subject.type).to eq(:rel8) | ||
end | ||
end | ||
|
||
context "when the value has a bit length less or equal to 32bits" do | ||
let(:value) { 0x11223344 } | ||
|
||
it "must set #width to 4" do | ||
expect(subject.width).to eq(4) | ||
end | ||
|
||
it "must set #type to :rel32" do | ||
expect(subject.type).to eq(:rel32) | ||
end | ||
end | ||
end | ||
end |