|
| 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 { 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 { subject }.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 { subject }.to raise_error |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + |
| 56 | + describe ".gen_decoder" do |
| 57 | + subject { 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 { subject }.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 { subject }.to raise_error |
| 84 | + end |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | +end |
0 commit comments