Commit 864e4020 authored by Stephen Kitt's avatar Stephen Kitt

Merge tag 'upstream/1.1.0'

Upstream version 1.1.0
parents ca1bd2c0 58202442
This diff is collapsed.
10.06.2014
10.06.2014 (1.0.0)
- First official release.
03.02.2015 (1.1.0)
- Wrapper for C++ language.
- Some minor fixes in unit tests.
- Multi-pass assembler tests could have failed on some systems due to a bug.
- Several missing 'extern "C"' declarations added.
- 'dist' build targed has been fixed.
- pkg-config support.
- Lexer generated using newer version of flex.
\ No newline at end of file
......@@ -3,6 +3,7 @@ ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = win32/dist.bat \
win32/vs2008/fcml/fcml-check/fcml-check.vcproj \
win32/vs2008/fcml/fcml-check-cpp/fcml-check-cpp.vcproj \
win32/vs2008/fcml/fcml.sln \
win32/vs2008/fcml/fcml/dllmain.c \
win32/vs2008/fcml/fcml/fcml.def \
......@@ -19,14 +20,14 @@ EXTRA_DIST = win32/dist.bat \
win32/vs2008/fcml/examples/hsdis/COPYING \
win32/vs2010/fcml/fcml-check/fcml-check.vcxproj \
win32/vs2010/fcml/fcml-check/fcml-check.vcxproj.filters \
win32/vs2010/fcml/fcml-check/fcml-check.vcxproj.user \
win32/vs2010/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj \
win32/vs2010/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj.filters \
win32/vs2010/fcml/fcml.sln \
win32/vs2010/fcml/fcml/dllmain.c \
win32/vs2010/fcml/fcml/fcml.def \
win32/vs2010/fcml/fcml/fcml.rc \
win32/vs2010/fcml/fcml/fcml.vcxproj \
win32/vs2010/fcml/fcml/fcml.vcxproj.filters \
win32/vs2010/fcml/fcml/fcml.vcxproj.user \
win32/vs2010/fcml/fcml/resource.h \
win32/vs2010/fcml/fcml/resource1.h \
win32/vs2010/fcml/examples/hsdis/dllmain.cpp \
......@@ -35,11 +36,12 @@ EXTRA_DIST = win32/dist.bat \
win32/vs2010/fcml/examples/hsdis/resource.h \
win32/vs2010/fcml/examples/hsdis/hsdis.vcxproj \
win32/vs2010/fcml/examples/hsdis/hsdis.vcxproj.filters \
win32/vs2010/fcml/examples/hsdis/hsdis.vcxproj.user \
win32/vs2010/fcml/examples/hsdis/targetver.h \
win32/vs2010/fcml/examples/hsdis/COPYING \
win32/vs2013/fcml/fcml-check/fcml-check.vcxproj \
win32/vs2013/fcml/fcml-check/fcml-check.vcxproj.filters \
win32/vs2013/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj \
win32/vs2013/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj.filters \
win32/vs2013/fcml/fcml.sln \
win32/vs2013/fcml/fcml/dllmain.c \
win32/vs2013/fcml/fcml/fcml.def \
......
This diff is collapsed.
This diff is collapsed.
SUBDIRS = stf internal-tests public-tests
if CPP_WRAPPER
CPPDIR = cpp-tests
endif
SUBDIRS = stf internal-tests public-tests $(CPPDIR)
This diff is collapsed.
noinst_PROGRAMS = fcml_cpp_check
# Include all tests.
fcml_cpp_check_SOURCES = main.cpp \
dialect_t.cpp \
dialect_t.hpp \
common_t.cpp \
common_t.hpp \
assembler_t.cpp \
assembler_t.hpp \
disassembler_t.cpp \
disassembler_t.hpp \
errors_t.cpp \
errors_t.hpp \
parser_t.cpp \
parser_t.hpp
fcml_cpp_check_CPPFLAGS = -Wall -Wno-write-strings -I$(top_srcdir)/include -I$(top_srcdir)/check/stf @FCML_IMPORT_LIB@
fcml_cpp_check_LDADD = $(top_srcdir)/src/libfcml.la $(top_srcdir)/check/stf/libstf.la
check_SCRIPTS = fcml_cpp_check
TESTS = $(check_SCRIPTS)
This diff is collapsed.
This diff is collapsed.
/*
* FCML - Free Code Manipulation Library.
* Copyright (C) 2010-2015 Slawomir Wojtasiak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ASSEMBLER_T_HPP_
#define ASSEMBLER_T_HPP_
#include <fcml_stf.h>
extern fcml_stf_test_suite fcml_si_cpp_assembler;
#endif /* ASSEMBLER_T_HPP_ */
This diff is collapsed.
/*
* FCML - Free Code Manipulation Library.
* Copyright (C) 2010-2015 Slawomir Wojtasiak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef STRUCT_WRAPPER_T_HPP_
#define STRUCT_WRAPPER_T_HPP_
#include <fcml_stf.h>
extern fcml_stf_test_suite fcml_si_cpp_common;
#endif /* STRUCT_WRAPPER_T_HPP_ */
/*
* FCML - Free Code Manipulation Library.
* Copyright (C) 2010-2015 Slawomir Wojtasiak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Test suite initialization. */
#include "dialect_t.hpp"
#include <fcml_common.hpp>
#include <fcml_intel_dialect.hpp>
using namespace fcml;
class DialectExtractor: public DialectAware {
};
fcml_bool fcml_tf_cpp_dialect_suite_init(void) {
return FCML_TRUE;
}
fcml_bool fcml_tf_cpp_dialect_suite_cleanup(void) {
return FCML_TRUE;
}
void fcml_tf_cpp_init_intel(void) {
IntelDialect intel;
DialectExtractor extractor;
STF_ASSERT_PTR_NOT_NULL( extractor.extractDialect( intel ) );
IntelDialect *intelPTR = new IntelDialect(FCML_INTEL_DIALECT_CF_DEFAULT);
STF_ASSERT_PTR_NOT_NULL( extractor.extractDialect( *intelPTR ) );
delete intelPTR;
}
void fcml_tf_cpp_init_gas(void) {
}
fcml_stf_test_case fcml_ti_cpp_dialect[] = {
{ "fcml_tf_cpp_init_intel", fcml_tf_cpp_init_intel },
{ "fcml_tf_cpp_init_gas", fcml_tf_cpp_init_gas },
FCML_STF_NULL_TEST
};
fcml_stf_test_suite fcml_si_cpp_dialect = {
"suite-fcml-cpp-dialect", fcml_tf_cpp_dialect_suite_init, fcml_tf_cpp_dialect_suite_cleanup, fcml_ti_cpp_dialect
};
/*
* FCML - Free Code Manipulation Library.
* Copyright (C) 2010-2015 Slawomir Wojtasiak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DIALECT_T_HPP_
#define DIALECT_T_HPP_
#include <fcml_stf.h>
extern fcml_stf_test_suite fcml_si_cpp_dialect;
#endif /* DIALECT_T_HPP_ */
/*
* FCML - Free Code Manipulation Library.
* Copyright (C) 2010-2015 Slawomir Wojtasiak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Test suite initialization. */
#include "disassembler_t.hpp"
#include <fcml_common.hpp>
#include <fcml_disassembler.hpp>
#include <fcml_renderer.hpp>
#include <fcml_registers.hpp>
#include <fcml_intel_dialect.hpp>
#include <fcml_gas_dialect.hpp>
#include <fcml_stateful_disassembler.hpp>
#include <fcml_gas_mnemonics.hpp>
using namespace fcml;
using namespace fcml::gas;
fcml_bool fcml_tf_cpp_disassembler_suite_init(void) {
return FCML_TRUE;
}
fcml_bool fcml_tf_cpp_disassembler_suite_cleanup(void) {
return FCML_TRUE;
}
void fcml_tf_cpp_disassemble(void) {
fcml_uint8_t code[] = {0x80, 0x54, 0x01, 0x02, 0x03};
try {
IntelDialect dialect;
Disassembler disassembler( dialect );
DisassemblerContext ctx( code , sizeof( code ) );
ctx.setIP(0x401000);
ctx.setOperatingMode(EntryPoint::OM_32_BIT);
DisassemblerResult result;
disassembler.disassemble( ctx, result );
const Instruction &instruction = result.getInstruction();
STF_ASSERT( instruction.getMnemonic() == M_ADC );
Renderer renderer( dialect );
RenderConfig config;
fcml_cstring instructionMnemonic;
renderer.render( config, result, instructionMnemonic );
STF_ASSERT_STRING_EQUAL( instructionMnemonic.c_str(), FCML_TEXT("adc byte ptr [ecx+eax+2],3") );
} catch( BaseException &exc ) {
STF_FAIL("Exception while disassembling the code.");
}
}
/* A 64-bit GDB dump used as an example.
Dump of assembler code for function main(int, char**):
0x0000000000404ddc <+0>: 55 push %rbp
0x0000000000404ddd <+1>: 48 89 e5 mov %rsp,%rbp
0x0000000000404de0 <+4>: 48 83 ec 20 sub $0x20,%rsp
0x0000000000404de4 <+8>: 89 7d ec mov %edi,-0x14(%rbp)
0x0000000000404de7 <+11>: 48 89 75 e0 mov %rsi,-0x20(%rbp)
0x0000000000404deb <+15>: be 60 d2 62 00 mov $0x62d260,%esi
0x0000000000404df0 <+20>: bf e8 db 41 00 mov $0x41dbe8,%edi
0x0000000000404df5 <+25>: e8 1f 89 01 00 callq 0x41d719
*/
fcml_uint8_t fcml_iarr_instruction_buffer_binary_code[] = {
0x55,
0x48, 0x89, 0xe5,
0x48, 0x83, 0xec, 0x20,
0x89, 0x7d, 0xec,
0x48, 0x89, 0x75, 0xe0,
0xbe, 0x60, 0xd2, 0x62, 0x00,
0xbf, 0xe8, 0xdb, 0x41, 0x00,
0xe8, 0x1f, 0x89, 0x01, 0x00
};
void fcml_tf_cpp_disassemble_instruction_buffer_disassemble_only(void) {
try {
GASDialect dialect;
Disassembler disassembler( dialect );
DisassemblerContext ctx( fcml_iarr_instruction_buffer_binary_code , sizeof( fcml_iarr_instruction_buffer_binary_code ) );
ctx.setIP(0x404ddc);
ctx.setOperatingMode(EntryPoint::OM_64_BIT);
StatefulDisassembler disas( disassembler, ctx, true );
Instruction instruction;
disas >> instruction;
STF_ASSERT( instruction.getMnemonic() == M_PUSH );
disas >> instruction;
STF_ASSERT( instruction.getMnemonic() == M_MOV );
} catch( BaseException &exc ) {
STF_FAIL("Exception while disassembling the code.");
}
}
void fcml_tf_cpp_disassemble_instruction_buffer_disassemble_render(void) {
try {
GASDialect dialect;
Disassembler disassembler( dialect );
DisassemblerContext ctx( fcml_iarr_instruction_buffer_binary_code , sizeof( fcml_iarr_instruction_buffer_binary_code ) );
ctx.setIP(0x404ddc);
ctx.setOperatingMode(EntryPoint::OM_64_BIT);
StatefulDisassembler disas( disassembler, ctx, true );
fcml_cstring instruction;
disas >> instruction;
STF_ASSERT( instruction == FCML_TEXT( "push %rbp" ) );
disas >> instruction;
STF_ASSERT( instruction == FCML_TEXT( "mov %rsp,%rbp" ) );
disas >> instruction;
STF_ASSERT( instruction == FCML_TEXT( "sub $32,%rsp" ) );
disas >> instruction;
STF_ASSERT( instruction == FCML_TEXT( "mov %edi,-20(%ebp)" ) );
disas >> instruction;
STF_ASSERT( instruction == FCML_TEXT( "mov %rsi,-32(%ebp)" ) );
disas >> instruction;
STF_ASSERT( instruction == FCML_TEXT( "mov $6476384,%esi" ) );
disas >> instruction;
STF_ASSERT( instruction == FCML_TEXT( "mov $4316136,%edi" ) );
disas >> instruction;
STF_ASSERT( instruction == FCML_TEXT( "callq 0x000000000041d719" ) );
} catch( BaseException &exc ) {
STF_FAIL("Exception while disassembling the code.");
}
}
void fcml_tf_cpp_disassemble_instruction_buffer_disassemble_only_stream(void) {
try {
GASDialect dialect;
Disassembler disassembler( dialect );
DisassemblerContext ctx( fcml_iarr_instruction_buffer_binary_code , sizeof( fcml_iarr_instruction_buffer_binary_code ) );
ctx.setIP(0x404ddc);
ctx.setOperatingMode(EntryPoint::OM_64_BIT);
StatefulDisassembler disas( disassembler, ctx, true );
fcml_costream ostream;
disas >> ostream;
disas >> ostream;
fcml_cstring src = ostream.str();
#if defined(_WIN32)
STF_ASSERT( src == _FT("push %rbp\r\nmov %rsp,%rbp\r\n") );
#else
STF_ASSERT( src == _FT("push %rbp\nmov %rsp,%rbp\n") );
#endif
} catch( BaseException &exc ) {
STF_FAIL("Exception while disassembling the code.");
}
}
fcml_stf_test_case fcml_ti_cpp_disassembler[] = {
{ "fcml_tf_cpp_disassemble", fcml_tf_cpp_disassemble },
{ "fcml_tf_cpp_disassemble_instruction_buffer_disassemble_only", fcml_tf_cpp_disassemble_instruction_buffer_disassemble_only },
{ "fcml_tf_cpp_disassemble_instruction_buffer_disassemble_render", fcml_tf_cpp_disassemble_instruction_buffer_disassemble_render },
{ "fcml_tf_cpp_disassemble_instruction_buffer_disassemble_only_stream", fcml_tf_cpp_disassemble_instruction_buffer_disassemble_only_stream },
FCML_STF_NULL_TEST
};
fcml_stf_test_suite fcml_si_cpp_disassembler = {
"suite-fcml-cpp-disassembler", fcml_tf_cpp_disassembler_suite_init, fcml_tf_cpp_disassembler_suite_cleanup, fcml_ti_cpp_disassembler
};
/*
* FCML - Free Code Manipulation Library.
* Copyright (C) 2010-2015 Slawomir Wojtasiak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DISASSEMBLER_T_HPP_
#define DISASSEMBLER_T_HPP_
#include <fcml_stf.h>
extern fcml_stf_test_suite fcml_si_cpp_disassembler;
#endif /* DISASSEMBLER_T_HPP_ */
/*
* FCML - Free Code Manipulation Library.
* Copyright (C) 2010-2015 Slawomir Wojtasiak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Test suite initialization. */
#include "errors_t.hpp"
#include <fcml_common.hpp>
#include <fcml_errors.hpp>
using namespace fcml;
fcml_bool fcml_tf_cpp_errors_suite_init(void) {
return FCML_TRUE;
}
fcml_bool fcml_tf_cpp_errors_suite_cleanup(void) {
return FCML_TRUE;
}
void fcml_tf_cpp_errors(void) {
fcml_st_ceh_error_info info1;
info1.code = FCML_CEH_GEC_FEATURE_NOT_SUPPORTED;
info1.level = FCML_EN_CEH_EL_WARN;
info1.message = FCML_TEXT("Some error1");
fcml_st_ceh_error_info info2;
info2.code = FCML_CEH_GEC_FEATURE_NOT_SUPPORTED;
info2.level = FCML_EN_CEH_EL_ERROR;
info2.message = FCML_TEXT("Some error2");
fcml_st_ceh_error_info info3;
info3.code = FCML_CEH_GEC_FEATURE_NOT_SUPPORTED;
info3.level = FCML_EN_CEH_EL_ERROR;
info3.message = FCML_TEXT("Some error3");
fcml_st_ceh_error_container errors;
errors.errors = &info1;
errors.last_error = &info3;
info3.next_error = NULL;
info2.next_error = &info3;
info1.next_error = &info2;
// Do not copy, just wrap.
ErrorContainer container;
ErrorTypeConverter::convert( errors, container );
if( !container.isEmpty() ) {
ErrorInfo &errorInfo = container.getFirstError();
STF_ASSERT_EQUAL( errorInfo.getMessage(), fcml_cstring( FCML_TEXT("Some error1") ) );
STF_ASSERT_EQUAL( errorInfo.getLevel(), ErrorInfo::EL_WARN );
STF_ASSERT_EQUAL( errorInfo.getCode(), FCML_CEH_GEC_FEATURE_NOT_SUPPORTED );
}
// Iterating over the errors.
if( !container.isEmpty() ) {
STF_ASSERT_EQUAL( container.getSize(), 3 );
for( fcml_usize i = 0; i < container.getSize(); i++ ) {
const ErrorInfo &info = container[i];
switch(i) {
case 0:
STF_ASSERT_EQUAL( info.getMessage(), FCML_TEXT("Some error1") );
break;
case 1:
STF_ASSERT_EQUAL( info.getMessage(), FCML_TEXT("Some error2") );
break;
case 2:
STF_ASSERT_EQUAL( info.getMessage(), FCML_TEXT("Some error3") );
break;
}
}
}
}
fcml_stf_test_case fcml_ti_cpp_errors[] = {
{ "fcml_tf_cpp_errors", fcml_tf_cpp_errors },
FCML_STF_NULL_TEST
};
fcml_stf_test_suite fcml_si_cpp_errors = {
"suite-fcml-cpp-errors", fcml_tf_cpp_errors_suite_init, fcml_tf_cpp_errors_suite_cleanup, fcml_ti_cpp_errors
};
/*
* FCML - Free Code Manipulation Library.
* Copyright (C) 2010-2015 Slawomir Wojtasiak
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ERRORS_T_HPP_
#define ERRORS_T_HPP_
#include <fcml_stf.h>