Fix some specs

bug/bundler_fix
jvazquez-r7 2014-09-02 18:50:37 -05:00
parent a1823b6c1e
commit 3ad0542b2a
1 changed files with 70 additions and 57 deletions

View File

@ -6,7 +6,6 @@ require 'rex/arch/x86'
describe Rex::Arch::X86 do describe Rex::Arch::X86 do
describe ".reg_number" do describe ".reg_number" do
subject { described_class.reg_number(register) } subject { described_class.reg_number(register) }
context "when valid argument" do context "when valid argument" do
@ -30,42 +29,44 @@ describe Rex::Arch::X86 do
end end
describe ".pack_word" do describe ".pack_word" do
it "packs argument as 16-bit unsigned" do subject { described_class.pack_word(num) }
expect(described_class.pack_word(0x4141)).to eq("AA") let(:num) { 0x4142 }
it "packs as unsigned 16 little endian " do
is_expected.to eq("BA")
end end
it "truncates arguments longer than 16-bit unsigned" do context "when arguments longer than 16-bit unsigned" do
expect(described_class.pack_word(0x41414242)).to eq("BB") let(:num) { 0x41414242 }
end it "truncates" do
is_expected.to eq("BB")
it "packs as little endian" do end
expect(described_class.pack_word(0x4142)).to eq("BA")
end end
end end
describe ".pack_dword" do describe ".pack_dword" do
it "packs argument as 32-bit unsigned" do subject { described_class.pack_dword(num) }
expect(described_class.pack_dword(0x41414141)).to eq("AAAA") let(:num) { 0x41424344 }
it "packs as unsigned 32 little endian " do
is_expected.to eq("DCBA")
end end
it "truncates arguments longer than 16-bit unsigned" do context "when arguments longer than 32-bit unsigned" do
expect(described_class.pack_dword(0x4142424242)).to eq("BBBB") let(:num) { 0x4142424242 }
end it "truncates" do
is_expected.to eq("BBBB")
it "packs as little endian" do end
expect(described_class.pack_dword(0x41424344)).to eq("DCBA")
end end
end end
describe ".pack_lsb" do describe ".pack_lsb" do
it "returns the least significant byte of a packed dword" do subject { described_class.pack_lsb(num) }
expect(described_class.pack_lsb(0x41424344)).to eq("D") let(:num) { 0x41424344 }
end
end
describe ".pack_lsb" do
it "returns the least significant byte of a packed dword" do it "returns the least significant byte of a packed dword" do
expect(described_class.pack_lsb(0x41424344)).to eq("D") is_expected.to eq("D")
end end
end end
@ -694,84 +695,98 @@ describe Rex::Arch::X86 do
end end
end end
describe ".mov_byte" do describe ".clear" do
subject { described_class.mov_byte(reg, val) } subject { described_class.clear(reg, badchars) }
let(:reg) { Rex::Arch::X86::ECX }
let(:badchars) { '' }
it "returns a clear instruction" do
expect(subject).to be_an(String)
end
context "when reg is invalid" do
let(:reg) { 31337 }
it "raises an error" do
expect { subject }.to raise_error(ArgumentError)
end
end
context "when too many badchars" do
let(:badchars) { (0x00..0xff).to_a.pack("C*") }
it "raises an error" do
expect { subject }.to raise_error(RuntimeError)
end
end
end
describe ".mov_byte" do
subject { described_class.mov_byte(reg, val) }
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 3 }
it "generates a mov instruction" do
is_expected.to eq("\xb1\x03")
end
context "when reg is invalid" do context "when reg is invalid" do
let(:reg) { 31337 } let(:reg) { 31337 }
let(:val) { 3 }
it "raises an error" do it "raises an error" do
expect { subject }.to raise_error(ArgumentError) expect { subject }.to raise_error(ArgumentError)
end end
end end
context "when val is out of range" do context "when val is out of range" do
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 31337 } let(:val) { 31337 }
it "raises an error" do it "raises an error" do
expect { subject }.to raise_error(RangeError) expect { subject }.to raise_error(RangeError)
end end
end end
context "when reg and val are valid" do
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 3 }
it "generates a mov instruction" do
is_expected.to eq("\xb1\x03")
end
end
end end
describe ".mov_word" do describe ".mov_word" do
subject { described_class.mov_word(reg, val) } subject { described_class.mov_word(reg, val) }
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 0x4142 }
it "generates a mov instruction" do
is_expected.to eq("\x66\xb9\x42\x41")
end
context "when reg is invalid" do context "when reg is invalid" do
let(:reg) { 31337 } let(:reg) { 31337 }
let(:val) { 3 }
it "raises an error" do it "raises an error" do
expect { subject }.to raise_error(ArgumentError) expect { subject }.to raise_error(ArgumentError)
end end
end end
context "when val is out of range" do context "when val is out of range" do
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 0x41424344 } let(:val) { 0x41424344 }
it "raises an error" do it "raises an error" do
expect { subject }.to raise_error(RangeError) expect { subject }.to raise_error(RangeError)
end end
end end
context "when reg and val are valid" do
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 0x4142 }
it "generates a mov instruction" do
is_expected.to eq("\x66\xb9\x42\x41")
end
end
end end
describe ".mov_dword" do describe ".mov_dword" do
subject { described_class.mov_dword(reg, val) } subject { described_class.mov_dword(reg, val) }
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 0x41424344 }
it "generates a mov instruction" do
is_expected.to eq("\xb9\x44\x43\x42\x41")
end
context "when reg is invalid" do context "when reg is invalid" do
let(:reg) { 31337 } let(:reg) { 31337 }
let(:val) { 3 }
it "raises an error" do it "raises an error" do
expect { subject }.to raise_error(ArgumentError) expect { subject }.to raise_error(ArgumentError)
end end
end end
context "when reg and val are valid" do
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 0x41424344 }
it "generates a mov instruction" do
is_expected.to eq("\xb9\x44\x43\x42\x41")
end
end
context "when val is out of range" do context "when val is out of range" do
let(:reg) { Rex::Arch::X86::ECX }
let(:val) { 0x100000000 } let(:val) { 0x100000000 }
it "truncates value" do it "truncates value" do
is_expected.to eq("\xb9\x00\x00\x00\x00") is_expected.to eq("\xb9\x00\x00\x00\x00")
@ -1006,6 +1021,4 @@ describe Rex::Arch::X86 do
end end
end end
end end