Add specs for .encode_byte

bug/bundler_fix
jvazquez-r7 2014-09-08 14:24:03 -05:00
parent 3535a6a21d
commit 11ca383d4f
2 changed files with 79 additions and 7 deletions

View File

@ -7,7 +7,7 @@ module Encoder
class NonAlpha
def NonAlpha.gen_decoder()
def NonAlpha.gen_decoder
decoder =
"\x66\xB9\xFF\xFF" +
"\xEB\x19" + # Jmp to table
@ -28,13 +28,13 @@ class NonAlpha
end
def NonAlpha.encode_byte(block, table, tablelen)
if (tablelen > 255) or (block == 0x7B)
if tablelen > 255 || block == 0x7B
raise RuntimeError, "BadChar"
end
if (block >= 0x41 and block <= 0x5A) or (block >= 0x61 and block <= 0x7A)
if (block >= 0x41 && block <= 0x5A) || (block >= 0x61 && block <= 0x7A)
# gen offset, return magic
offset = 0x7b - block;
offset = 0x7b - block
table += offset.chr
tablelen = tablelen + 1
block = 0x7B

View File

@ -42,7 +42,6 @@ describe Rex::Encoder::NonAlpha do
subject { described_class.encode_byte(block, table, tablelen) }
context "when tablelen > 255" do
let(:badchars) { "" }
let(:block) { 0x20 }
let(:table) { "" }
let(:tablelen) { 256 }
@ -53,7 +52,6 @@ describe Rex::Encoder::NonAlpha do
end
context "when block == 0x7b" do
let(:badchars) { "" }
let(:block) { 0x7b }
let(:table) { "" }
let(:tablelen) { 0 }
@ -63,8 +61,82 @@ describe Rex::Encoder::NonAlpha do
end
end
context "when block == 0x40" do
context "when block is an upcase letter char code" do
let(:block) { 0x42 }
let(:table) { "" }
let(:tablelen) { 0 }
it "returns an Array" do
is_expected.to be_kind_of(Array)
end
it "returns a 3 fields Array" do
expect(subject.length).to eq(3)
end
it "returns '{' char as block" do
expect(subject[0]).to eq('{')
end
it "appends offset to table" do
expect(subject[1]).to eq((0x7b - block).chr)
end
it "increments tablelen" do
expect(subject[2]).to eq(tablelen + 1)
end
end
context "when block is a downcase letter char code" do
let(:block) { 0x62 }
let(:table) { "" }
let(:tablelen) { 0 }
it "returns an Array" do
is_expected.to be_kind_of(Array)
end
it "returns a 3 fields Array" do
expect(subject.length).to eq(3)
end
it "returns '{' char as block" do
expect(subject[0]).to eq('{')
end
it "appends offset to table" do
expect(subject[1]).to eq((0x7b - block).chr)
end
it "increments tablelen" do
expect(subject[2]).to eq(tablelen + 1)
end
end
context "when block is another char code" do
let(:block) { 0x7c }
let(:table) { "" }
let(:tablelen) { 0 }
it "returns an Array" do
is_expected.to be_kind_of(Array)
end
it "returns a 3 fields Array" do
expect(subject.length).to eq(3)
end
it "returns same block char code" do
expect(subject[0]).to eq(block.chr)
end
it "doesn't modify table" do
expect(subject[1]).to eq(table)
end
it "doesn't modify tablelen" do
expect(subject[2]).to eq(tablelen)
end
end
end