Skip to content

Commit 32faa0b

Browse files
committed
Land 3796, specs for Rex::Encoder::Alpha2 encoders
2 parents 22f5347 + eb190a5 commit 32faa0b

File tree

6 files changed

+471
-0
lines changed

6 files changed

+471
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# -*- coding:binary -*-
2+
require 'spec_helper'
3+
4+
require 'rex/encoder/alpha2/alpha_mixed'
5+
6+
describe Rex::Encoder::Alpha2::AlphaMixed do
7+
8+
it_behaves_like 'Rex::Encoder::Alpha2::Generic'
9+
10+
let(:decoder_stub) do
11+
"jAXP0A0AkAAQ2AB2BB0BBABXP8ABuJI"
12+
end
13+
14+
let(:reg_signature) do
15+
{
16+
'EAX' => 'PY',
17+
'ECX' => 'I',
18+
'EDX' => '7RY',
19+
'EBX' => 'SY',
20+
'ESP' => 'TY',
21+
'EBP' => 'UY',
22+
'ESI' => 'VY',
23+
'EDI' => 'WY'
24+
}
25+
end
26+
27+
describe ".gen_decoder_prefix" do
28+
subject(:decoder_prefix) { described_class.gen_decoder_prefix(reg, offset) }
29+
let(:reg) { 'ECX' }
30+
let(:offset) { 5 }
31+
32+
it "returns decoder prefix" do
33+
is_expected.to include(reg_signature[reg])
34+
end
35+
36+
context "when invalid reg name" do
37+
let(:reg) { 'NON EXISTENT' }
38+
let(:offset) { 0 }
39+
40+
it "raises an error" do
41+
expect { decoder_prefix }.to raise_error(ArgumentError)
42+
end
43+
end
44+
45+
context "when offset is bigger than 32" do
46+
let(:reg) { 'ECX' }
47+
let(:offset) { 33 }
48+
49+
it "raises an error" do
50+
expect { decoder_prefix }.to raise_error
51+
end
52+
end
53+
end
54+
55+
56+
describe ".gen_decoder" do
57+
subject(:decoder) { described_class.gen_decoder(reg, offset) }
58+
let(:reg) { 'ECX' }
59+
let(:offset) { 5 }
60+
61+
it "returns the alpha upper decoder" do
62+
is_expected.to include(decoder_stub)
63+
end
64+
65+
it "uses the correct decoder prefix" do
66+
is_expected.to include(reg_signature[reg])
67+
end
68+
69+
context "when invalid reg name" do
70+
let(:reg) { 'NON EXISTENT' }
71+
let(:offset) { 0 }
72+
73+
it "raises an error" do
74+
expect { decoder }.to raise_error(ArgumentError)
75+
end
76+
end
77+
78+
context "when offset is bigger than 32" do
79+
let(:reg) { 'ECX' }
80+
let(:offset) { 33 }
81+
82+
it "raises an error" do
83+
expect { decoder }.to raise_error
84+
end
85+
end
86+
end
87+
88+
end
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- coding:binary -*-
2+
require 'spec_helper'
3+
4+
require 'rex/encoder/alpha2/alpha_upper'
5+
6+
describe Rex::Encoder::Alpha2::AlphaUpper do
7+
8+
it_behaves_like 'Rex::Encoder::Alpha2::Generic'
9+
10+
let(:decoder_stub) do
11+
"VTX30VX4AP0A3HH0A00ABAABTAAQ2AB2BB0BBXP8ACJJI"
12+
end
13+
14+
let(:reg_signature) do
15+
{
16+
'EAX' => 'PY',
17+
'ECX' => 'I',
18+
'EDX' => 'RY',
19+
'EBX' => 'SY',
20+
'ESP' => 'TY',
21+
'EBP' => 'UY',
22+
'ESI' => 'VY',
23+
'EDI' => 'WY'
24+
}
25+
end
26+
27+
describe ".default_accepted_chars" do
28+
subject { described_class.default_accepted_chars }
29+
30+
it { is_expected.to eq(('B' .. 'Z').to_a + ('0' .. '9').to_a) }
31+
end
32+
33+
describe ".gen_decoder_prefix" do
34+
subject(:decoder_prefix) { described_class.gen_decoder_prefix(reg, offset) }
35+
let(:reg) { 'ECX' }
36+
let(:offset) { 5 }
37+
38+
it "returns decoder prefix" do
39+
is_expected.to include(reg_signature[reg])
40+
end
41+
42+
context "when invalid reg name" do
43+
let(:reg) { 'NON EXISTENT' }
44+
let(:offset) { 0 }
45+
46+
it "raises an error" do
47+
expect { decoder_prefix }.to raise_error(ArgumentError)
48+
end
49+
end
50+
51+
context "when offset is bigger than 20" do
52+
let(:reg) { 'ECX' }
53+
let(:offset) { 25 }
54+
55+
it "raises an error" do
56+
expect { decoder_prefix }.to raise_error
57+
end
58+
end
59+
end
60+
61+
62+
describe ".gen_decoder" do
63+
subject(:decoder) { described_class.gen_decoder(reg, offset) }
64+
let(:reg) { 'ECX' }
65+
let(:offset) { 5 }
66+
67+
it "returns the alpha upper decoder" do
68+
is_expected.to include(decoder_stub)
69+
end
70+
71+
it "uses the correct decoder prefix" do
72+
is_expected.to include(reg_signature[reg])
73+
end
74+
75+
context "when invalid reg name" do
76+
let(:reg) { 'NON EXISTENT' }
77+
let(:offset) { 0 }
78+
79+
it "raises an error" do
80+
expect { decoder }.to raise_error(ArgumentError)
81+
end
82+
end
83+
84+
context "when offset is bigger than 20" do
85+
let(:reg) { 'ECX' }
86+
let(:offset) { 25 }
87+
88+
it "raises an error" do
89+
expect { decoder }.to raise_error
90+
end
91+
end
92+
end
93+
94+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding:binary -*-
2+
require 'spec_helper'
3+
4+
require 'rex/encoder/alpha2/generic'
5+
6+
describe Rex::Encoder::Alpha2::Generic do
7+
8+
it_behaves_like 'Rex::Encoder::Alpha2::Generic'
9+
10+
describe ".default_accepted_chars" do
11+
subject(:accepted_chars) { described_class.default_accepted_chars }
12+
13+
it { is_expected.to eq(('a' .. 'z').to_a + ('B' .. 'Z').to_a + ('0' .. '9').to_a) }
14+
end
15+
16+
describe ".gen_decoder_prefix" do
17+
subject(:decoder_prefix) { described_class.gen_decoder_prefix(reg, offset) }
18+
let(:reg) { 'ECX' }
19+
let(:offset) { 0 }
20+
21+
it { is_expected.to eq('') }
22+
end
23+
24+
describe ".gen_decoder" do
25+
subject(:decoder) { described_class.gen_decoder(reg, offset) }
26+
let(:reg) { 'ECX' }
27+
let(:offset) { 0 }
28+
29+
it { is_expected.to eq('') }
30+
end
31+
32+
describe ".gen_second" do
33+
subject(:second) { described_class.gen_second(block, base) }
34+
let(:block) { 0xaf }
35+
let(:base) { 0xfa }
36+
37+
it "returns block ^ base" do
38+
expect(second ^ base).to eq(block)
39+
end
40+
end
41+
42+
end
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# -*- coding:binary -*-
2+
require 'spec_helper'
3+
4+
require 'rex/encoder/alpha2/unicode_mixed'
5+
6+
describe Rex::Encoder::Alpha2::UnicodeMixed do
7+
8+
it_behaves_like 'Rex::Encoder::Alpha2::Generic'
9+
10+
let(:decoder_stub) do
11+
"jXAQADAZABARALAYAIAQAIAQAIAhAAAZ1AIAIAJ11AIAIABABABQI1AIQIAIQI111AIAJQYAZBABABABABkMAGB9u4JB"
12+
end
13+
14+
let(:reg_signature) do
15+
{
16+
'EAX' => 'PPYA',
17+
'ECX' => '4444',
18+
'EDX' => 'RRYA',
19+
'EBX' => 'SSYA',
20+
'ESP' => 'TUYA',
21+
'EBP' => 'UUYAs',
22+
'ESI' => 'VVYA',
23+
'EDI' => 'WWYA'
24+
}
25+
end
26+
27+
describe ".gen_decoder_prefix" do
28+
subject(:decoder_prefix) { described_class.gen_decoder_prefix(reg, offset) }
29+
let(:reg) { 'ECX' }
30+
let(:offset) { 5 }
31+
32+
it "returns decoder prefix" do
33+
is_expected.to include(reg_signature[reg])
34+
end
35+
36+
context "when invalid reg name" do
37+
let(:reg) { 'NON EXISTENT' }
38+
let(:offset) { 0 }
39+
40+
it "raises an error" do
41+
expect { decoder_prefix }.to raise_error(RuntimeError)
42+
end
43+
end
44+
45+
context "when offset is bigger than 21" do
46+
let(:reg) { 'ECX' }
47+
let(:offset) { 22 }
48+
49+
it "raises an error" do
50+
expect { decoder_prefix }.to raise_error
51+
end
52+
end
53+
end
54+
55+
56+
describe ".gen_decoder" do
57+
subject(:decoder) { described_class.gen_decoder(reg, offset) }
58+
let(:reg) { 'ECX' }
59+
let(:offset) { 5 }
60+
61+
it "returns the alpha upper decoder" do
62+
is_expected.to include(decoder_stub)
63+
end
64+
65+
it "uses the correct decoder prefix" do
66+
is_expected.to include(reg_signature[reg])
67+
end
68+
69+
context "when invalid reg name" do
70+
let(:reg) { 'NON EXISTENT' }
71+
let(:offset) { 0 }
72+
73+
it "raises an error" do
74+
expect { decoder }.to raise_error(RuntimeError)
75+
end
76+
end
77+
78+
context "when offset is bigger than 21" do
79+
let(:reg) { 'ECX' }
80+
let(:offset) { 22 }
81+
82+
it "raises an error" do
83+
expect { decoder }.to raise_error
84+
end
85+
end
86+
end
87+
88+
end

0 commit comments

Comments
 (0)