2019-01-01 11:53:32 +00:00
|
|
|
/*
|
2019-01-01 12:40:59 +00:00
|
|
|
Copyright (C) 2018-2019 de4dot@gmail.com
|
2018-09-06 00:02:48 +00:00
|
|
|
|
2019-01-01 12:40:59 +00:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
a copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
the following conditions:
|
2018-09-06 00:02:48 +00:00
|
|
|
|
2019-01-01 12:40:59 +00:00
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
2018-09-06 00:02:48 +00:00
|
|
|
|
2019-01-01 12:40:59 +00:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2018-09-06 00:02:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if !NO_ENCODER
|
|
|
|
using System;
|
|
|
|
using Iced.Intel;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Iced.UnitTests.Intel.EncoderTests {
|
|
|
|
public sealed class BlockEncoderTest16_call : BlockEncoderTest {
|
|
|
|
const int bitness = 16;
|
|
|
|
const ulong origRip = 0x8000;
|
|
|
|
const ulong newRip = 0xF000;
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
void Call_near_fwd() {
|
|
|
|
var originalData = new byte[] {
|
|
|
|
/*0000*/ 0xE8, 0x08, 0x00,// call 800Bh
|
|
|
|
/*0003*/ 0xB0, 0x00,// mov al,0
|
|
|
|
/*0005*/ 0x66, 0xB8, 0x78, 0x56, 0x34, 0x12,// mov eax,12345678h
|
|
|
|
/*000B*/ 0x90,// nop
|
|
|
|
};
|
|
|
|
var newData = new byte[] {
|
|
|
|
/*0000*/ 0xE8, 0x08, 0x00,// call 0F00Bh
|
|
|
|
/*0003*/ 0xB0, 0x00,// mov al,0
|
|
|
|
/*0005*/ 0x66, 0xB8, 0x78, 0x56, 0x34, 0x12,// mov eax,12345678h
|
|
|
|
/*000B*/ 0x90,// nop
|
|
|
|
};
|
|
|
|
var expectedInstructionOffsets = new uint[] {
|
|
|
|
0x0000,
|
|
|
|
0x0003,
|
|
|
|
0x0005,
|
|
|
|
0x000B,
|
|
|
|
};
|
|
|
|
var expectedRelocInfos = Array.Empty<RelocInfo>();
|
|
|
|
const BlockEncoderOptions options = BlockEncoderOptions.None;
|
2018-09-25 19:26:05 +00:00
|
|
|
EncodeBase(bitness, origRip, originalData, newRip, newData, options, decoderOptions, expectedInstructionOffsets, expectedRelocInfos);
|
2018-09-06 00:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
void Call_near_bwd() {
|
|
|
|
var originalData = new byte[] {
|
|
|
|
/*0000*/ 0x90,// nop
|
|
|
|
/*0001*/ 0xE8, 0xFC, 0xFF,// call 8000h
|
|
|
|
/*0004*/ 0xB0, 0x00,// mov al,0
|
|
|
|
/*0006*/ 0x66, 0xB8, 0x78, 0x56, 0x34, 0x12,// mov eax,12345678h
|
|
|
|
};
|
|
|
|
var newData = new byte[] {
|
|
|
|
/*0000*/ 0x90,// nop
|
|
|
|
/*0001*/ 0xE8, 0xFC, 0xFF,// call 0F000h
|
|
|
|
/*0004*/ 0xB0, 0x00,// mov al,0
|
|
|
|
/*0006*/ 0x66, 0xB8, 0x78, 0x56, 0x34, 0x12,// mov eax,12345678h
|
|
|
|
};
|
|
|
|
var expectedInstructionOffsets = new uint[] {
|
|
|
|
0x0000,
|
|
|
|
0x0001,
|
|
|
|
0x0004,
|
|
|
|
0x0006,
|
|
|
|
};
|
|
|
|
var expectedRelocInfos = Array.Empty<RelocInfo>();
|
|
|
|
const BlockEncoderOptions options = BlockEncoderOptions.None;
|
2018-09-25 19:26:05 +00:00
|
|
|
EncodeBase(bitness, origRip, originalData, newRip, newData, options, decoderOptions, expectedInstructionOffsets, expectedRelocInfos);
|
2018-09-06 00:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
void Call_near_other_near() {
|
|
|
|
var originalData = new byte[] {
|
|
|
|
/*0000*/ 0xE8, 0x08, 0x00,// call 800Bh
|
|
|
|
/*0003*/ 0xB0, 0x00,// mov al,0
|
|
|
|
/*0005*/ 0x66, 0xB8, 0x78, 0x56, 0x34, 0x12,// mov eax,12345678h
|
|
|
|
};
|
|
|
|
var newData = new byte[] {
|
|
|
|
/*0000*/ 0xE8, 0x09, 0x00,// call 800Bh
|
|
|
|
/*0003*/ 0xB0, 0x00,// mov al,0
|
|
|
|
/*0005*/ 0x66, 0xB8, 0x78, 0x56, 0x34, 0x12,// mov eax,12345678h
|
|
|
|
};
|
|
|
|
var expectedInstructionOffsets = new uint[] {
|
|
|
|
0x0000,
|
|
|
|
0x0003,
|
|
|
|
0x0005,
|
|
|
|
};
|
|
|
|
var expectedRelocInfos = Array.Empty<RelocInfo>();
|
|
|
|
const BlockEncoderOptions options = BlockEncoderOptions.None;
|
2018-09-25 19:26:05 +00:00
|
|
|
EncodeBase(bitness, origRip, originalData, origRip - 1, newData, options, decoderOptions, expectedInstructionOffsets, expectedRelocInfos);
|
2018-09-06 00:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
void Call_near_other_near_os() {
|
|
|
|
var originalData = new byte[] {
|
|
|
|
/*0000*/ 0x66, 0xE8, 0x08, 0x00, 0x00, 0x00,// call 0000800Eh
|
|
|
|
/*0006*/ 0xB0, 0x00,// mov al,0
|
|
|
|
/*0008*/ 0x66, 0xB8, 0x78, 0x56, 0x34, 0x12,// mov eax,12345678h
|
|
|
|
};
|
|
|
|
var newData = new byte[] {
|
|
|
|
/*0000*/ 0x66, 0xE8, 0x08, 0x90, 0xFF, 0xFF,// call 0000800Eh
|
|
|
|
/*0006*/ 0xB0, 0x00,// mov al,0
|
|
|
|
/*0008*/ 0x66, 0xB8, 0x78, 0x56, 0x34, 0x12,// mov eax,12345678h
|
|
|
|
};
|
|
|
|
var expectedInstructionOffsets = new uint[] {
|
|
|
|
0x0000,
|
|
|
|
0x0006,
|
|
|
|
0x0008,
|
|
|
|
};
|
|
|
|
var expectedRelocInfos = Array.Empty<RelocInfo>();
|
|
|
|
const BlockEncoderOptions options = BlockEncoderOptions.None;
|
2018-09-25 19:26:05 +00:00
|
|
|
EncodeBase(bitness, origRip, originalData, newRip, newData, options, decoderOptions, expectedInstructionOffsets, expectedRelocInfos);
|
2018-09-06 00:02:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|