VTIL-Core/VTIL-Architecture/arch/instruction_desc.cpp

81 lines
3.3 KiB
C++
Raw Permalink Normal View History

// Copyright (c) 2020 Can Boluk and contributors of the VTIL Project
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
2020-07-09 02:43:51 +02:00
// 3. Neither the name of VTIL Project nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "instruction_desc.hpp"
namespace vtil
{
// Generic data-assignment constructor with certain validity checks.
//
instruction_desc::instruction_desc( const std::string& name,
const std::vector<operand_type>& operand_types,
int access_size_index,
bool is_volatile,
math::operator_id symbolic_operator,
std::vector<int> branch_operands,
const std::pair<int, bool>& memory_operands ) :
name( name ), operand_types( operand_types ), vaccess_size_index( access_size_index ),
is_volatile( is_volatile ), symbolic_operator( symbolic_operator ),
memory_operand_index( memory_operands.first - 1 ), memory_write( memory_operands.second )
{
fassert( operand_count() <= VTIL_ARCH_MAX_OPERAND_COUNT );
// Validate all operand indices.
//
2021-08-17 23:24:32 +08:00
fassert( vaccess_size_index == 0 || (size_t) abs( vaccess_size_index ) <= operand_count() );
fassert( memory_operands.first == 0 || (size_t) abs( memory_operands.first ) <= operand_count() );
for ( int op : branch_operands )
2021-08-17 23:24:32 +08:00
fassert( op != 0 && (size_t) abs( op ) <= operand_count() );
// Validate variable access size.
//
if ( vaccess_size_index < 0 )
fassert( operand_types[ ( -vaccess_size_index ) - 1 ] == operand_type::read_imm );
// Process branch operands.
//
for ( int op : branch_operands )
{
if ( op > 0 )
branch_operands_vip.push_back( op - 1 );
else
branch_operands_rip.push_back( -op - 1 );
}
2020-05-19 05:22:06 +02:00
// Validate operand types.
//
bool written = false;
for ( operand_type type : operand_types )
{
if ( type >= operand_type::write )
{
fassert( !written );
written = true;
}
}
}
};