├── src ├── .dirstamp ├── .gitignore ├── libfcml.pc.in ├── fcml_dialect.c ├── fcml_gas_parser.h ├── fcml_intel_parser.h ├── fcml_assembler_int.h ├── fcml_trace.h ├── fcml_disp8_n.h ├── fcml_gas_rend.h ├── fcml_intel_rend.h ├── fcml_modrm.h ├── fcml_ceh.h ├── fcml_common_dialect.h ├── fcml_operand_decorators.h ├── fcml_renderer.c ├── fcml_parser_int.h ├── fcml_hints.h ├── fcml_parser_utils.h ├── fcml_mnemonic_parser.h ├── fcml_decoding_tree.h ├── fcml_operand_decorators.c ├── fcml_parser_utils.c ├── fcml_messages.h ├── fcml_choosers.c ├── Makefile.am ├── fcml_env_int.h ├── fcml_messages.c ├── fcml_parser.c ├── fcml_intel_parser.c ├── fcml_gas_parser.c └── fcml_hints.c ├── include ├── .gitignore ├── Makefile.am ├── fcml_dialect.h ├── fcml_gas_dialect.hpp ├── fcml_intel_dialect.h ├── fcml_intel_dialect.hpp ├── fcml_gas_dialect.h ├── fcml_lib_export.h ├── fcml_choosers.h └── fcml_dialect.hpp ├── m4 ├── .gitignore └── as-compiler-flag.m4 ├── NEWS ├── AUTHORS ├── example ├── .gitignore ├── fcml-asm │ ├── .gitignore │ └── Makefile.am ├── fcml-disasm │ ├── .gitignore │ └── Makefile.am ├── hsdis │ ├── .gitignore │ ├── Makefile.am │ └── hsdis.h └── Makefile.am ├── check ├── .gitignore ├── stf │ ├── .gitignore │ └── Makefile.am ├── cpp-tests │ ├── .gitignore │ ├── parser_t.hpp │ ├── Makefile.am │ ├── common_t.hpp │ ├── errors_t.hpp │ ├── dialect_t.hpp │ ├── assembler_t.hpp │ ├── disassembler_t.hpp │ ├── main.cpp │ ├── dialect_t.cpp │ └── parser_t.cpp ├── public-tests │ ├── .gitignore │ ├── general_usage_t.h │ ├── hints_t.h │ ├── render_t.h │ ├── instructions_i_t.h │ ├── instructions_a_t.h │ ├── instructions_b_t.h │ ├── instructions_c_t.h │ ├── instructions_d_t.h │ ├── instructions_e_t.h │ ├── instructions_f_t.h │ ├── instructions_g_t.h │ ├── instructions_h_t.h │ ├── instructions_j_t.h │ ├── instructions_k_t.h │ ├── instructions_l_t.h │ ├── instructions_m_t.h │ ├── instructions_n_t.h │ ├── instructions_o_t.h │ ├── instructions_p_t.h │ ├── instructions_r_t.h │ ├── instructions_s_t.h │ ├── instructions_t_t.h │ ├── instructions_u_t.h │ ├── instructions_v_t.h │ ├── instructions_w_t.h │ ├── instructions_x_t.h │ ├── prefixes_t.h │ ├── assembler_t.h │ ├── chooser_t.h │ ├── segment_reg_t.h │ ├── disassembler_t.h │ ├── error_handling_t.h │ ├── instructions_g_t.c │ ├── Makefile.am │ └── instructions_w_t.c ├── internal-tests │ ├── .gitignore │ ├── ceh_t.h │ ├── env_t.h │ ├── stream_t.h │ ├── coll_t.h │ ├── symbols_t.h │ ├── utils_t.h │ ├── common_utils_t.h │ ├── gas_parser_t.h │ ├── modrm_decoder_t.h │ ├── modrm_encoder_t.h │ ├── intel_parser_t.h │ ├── lag_assembler_t.h │ ├── mnemonic_parser_t.h │ ├── instruction_chooser_t.h │ ├── symbols_t.c │ ├── common_utils_t.c │ └── main.c └── Makefile.am ├── win32 ├── vs2017 │ └── fcml │ │ ├── examples │ │ └── hsdis │ │ │ ├── hsdis.def │ │ │ ├── resource.h │ │ │ ├── dllmain.cpp │ │ │ ├── targetver.h │ │ │ ├── hsdis.vcxproj.filters │ │ │ └── hsdis.rc │ │ ├── .gitignore │ │ ├── fcml │ │ ├── dllmain.c │ │ ├── resource.h │ │ ├── resource1.h │ │ └── fcml.rc │ │ └── fcml-check-cpp │ │ └── fcml-check-cpp.vcxproj.filters ├── vs2019 │ └── fcml │ │ ├── examples │ │ └── hsdis │ │ │ ├── hsdis.def │ │ │ ├── resource.h │ │ │ ├── dllmain.cpp │ │ │ ├── targetver.h │ │ │ ├── hsdis.vcxproj.filters │ │ │ └── hsdis.rc │ │ ├── .gitignore │ │ ├── fcml │ │ ├── dllmain.c │ │ ├── resource.h │ │ ├── resource1.h │ │ └── fcml.rc │ │ └── fcml-check-cpp │ │ └── fcml-check-cpp.vcxproj.filters └── Makefile.am ├── docs └── doxygen │ ├── .gitignore │ ├── doxyfile.in │ └── Makefile.am ├── Dockerfile ├── docker-compose.yml ├── .circleci └── config.yml ├── .gitignore ├── README ├── ChangeLog └── Makefile.am /src/.dirstamp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /include/.gitignore: -------------------------------------------------------------------------------- 1 | /Makefile 2 | /Makefile.in 3 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | *.m4 2 | !as-compiler-flag.m4 3 | 4 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | This is a first official release of the project. 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Slawomir Wojtasiak 2 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | *.Po 2 | *.o 3 | *.in 4 | Makefile 5 | 6 | 7 | -------------------------------------------------------------------------------- /check/.gitignore: -------------------------------------------------------------------------------- 1 | *.Po 2 | *.o 3 | *.in 4 | Makefile 5 | fcml_check 6 | -------------------------------------------------------------------------------- /example/fcml-asm/.gitignore: -------------------------------------------------------------------------------- 1 | *.Po 2 | *.o 3 | *.in 4 | Makefile 5 | fcml_asm 6 | -------------------------------------------------------------------------------- /example/fcml-disasm/.gitignore: -------------------------------------------------------------------------------- 1 | *.Po 2 | *.o 3 | *.in 4 | Makefile 5 | fcml_disasm 6 | 7 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lo 3 | *.la 4 | Makefile 5 | Makefile.in 6 | /.libs 7 | /.deps 8 | -------------------------------------------------------------------------------- /check/stf/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lo 3 | *.la 4 | Makefile 5 | Makefile.in 6 | /.libs 7 | /.deps 8 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/examples/hsdis/hsdis.def: -------------------------------------------------------------------------------- 1 | LIBRARY "hsdis" 2 | EXPORTS 3 | decode_instructions @1 4 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/examples/hsdis/hsdis.def: -------------------------------------------------------------------------------- 1 | LIBRARY "hsdis" 2 | EXPORTS 3 | decode_instructions @1 4 | -------------------------------------------------------------------------------- /docs/doxygen/.gitignore: -------------------------------------------------------------------------------- 1 | /doxyfile 2 | /doxygen.stamp 3 | /latex 4 | /html 5 | /Makefile 6 | /Makefile.in 7 | /*.tar.gz 8 | -------------------------------------------------------------------------------- /example/hsdis/.gitignore: -------------------------------------------------------------------------------- 1 | *.Po 2 | *.o 3 | *.in 4 | *.la 5 | *.lai 6 | *.so 7 | *.lo 8 | .libs 9 | .deps 10 | Makefile 11 | 12 | 13 | -------------------------------------------------------------------------------- /check/cpp-tests/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lo 3 | *.la 4 | Makefile 5 | Makefile.in 6 | /.libs 7 | /.deps 8 | /fcml_cpp_check 9 | /*.log 10 | /*.trs 11 | -------------------------------------------------------------------------------- /check/public-tests/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lo 3 | *.la 4 | Makefile 5 | Makefile.in 6 | /.libs 7 | /.deps 8 | /fcml_public_check 9 | /*.log 10 | /*.trs -------------------------------------------------------------------------------- /check/internal-tests/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.lo 3 | *.la 4 | Makefile 5 | Makefile.in 6 | /.libs 7 | /.deps 8 | /fcml_internal_check 9 | /*.log 10 | /*.trs -------------------------------------------------------------------------------- /example/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = fcml-asm fcml-disasm 2 | 3 | EXTRA_DIST = hsdis/hsdis.c \ 4 | hsdis/hsdis.h \ 5 | hsdis/Makefile.am \ 6 | hsdis/Makefile.in 7 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/.gitignore: -------------------------------------------------------------------------------- 1 | Release-lib 2 | Release-dll 3 | Debug-lib 4 | Debug-dll 5 | x64 6 | *.suo 7 | *.sdf 8 | *.ncb 9 | *.aps 10 | *.user 11 | *.VC.db -------------------------------------------------------------------------------- /win32/vs2019/fcml/.gitignore: -------------------------------------------------------------------------------- 1 | Release-lib 2 | Release-dll 3 | Debug-lib 4 | Debug-dll 5 | x64 6 | *.suo 7 | *.sdf 8 | *.ncb 9 | *.aps 10 | *.user 11 | *.VC.db -------------------------------------------------------------------------------- /check/stf/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libstf.la 2 | libstf_la_SOURCES = fcml_stf.h fcml_stf.c 3 | libstf_la_CPPFLAGS = -I$(top_srcdir)/include 4 | libstf_la_LDFLAGS = -no-undefined 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | RUN apt-get update -qq && \ 4 | apt-get install build-essential autoconf libtool-bin -y 5 | 6 | WORKDIR /usr/fcml-lib 7 | 8 | COPY . /usr/fcml-lib/ 9 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | tests: 4 | build: 5 | context: . 6 | dockerfile: Dockerfile 7 | command: bash -c 'autoreconf -i && ./configure && make && make check' 8 | 9 | -------------------------------------------------------------------------------- /example/fcml-asm/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = fcml_asm 2 | 3 | fcml_asm_SOURCES = main.c 4 | 5 | fcml_asm_CPPFLAGS = -I$(top_srcdir)/include @FCML_IMPORT_LIB@ 6 | 7 | fcml_asm_LDADD = $(top_srcdir)/src/libfcml.la 8 | -------------------------------------------------------------------------------- /check/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if CPP_WRAPPER 3 | CPPDIR = cpp-tests 4 | endif 5 | if ENABLE_INTERNAL_TESTS 6 | INTERNAL_TESTS_DIR = internal-tests 7 | endif 8 | 9 | SUBDIRS = stf $(INTERNAL_TESTS_DIR) public-tests $(CPPDIR) 10 | -------------------------------------------------------------------------------- /example/fcml-disasm/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = fcml_disasm 2 | 3 | fcml_disasm_SOURCES = main.c 4 | 5 | fcml_disasm_CPPFLAGS = -I$(top_srcdir)/include @FCML_IMPORT_LIB@ 6 | 7 | fcml_disasm_LDADD = $(top_srcdir)/src/libfcml.la 8 | 9 | -------------------------------------------------------------------------------- /example/hsdis/Makefile.am: -------------------------------------------------------------------------------- 1 | # Make sure that FCML is built. 2 | SUBDIRS = ../../src 3 | 4 | lib_LTLIBRARIES = libhsdis.la 5 | 6 | libhsdis_la_SOURCES = hsdis.c hsdis.h 7 | 8 | libhsdis_la_CPPFLAGS = -I$(top_srcdir)/include 9 | 10 | libhsdis_la_LIBADD = $(top_srcdir)/src/libfcml.la 11 | -------------------------------------------------------------------------------- /check/cpp-tests/parser_t.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * parser_t.hpp 3 | * 4 | * Created on: Aug 6, 2014 5 | * Author: tas 6 | */ 7 | 8 | #ifndef PARSER_T_HPP_ 9 | #define PARSER_T_HPP_ 10 | 11 | #include 12 | 13 | extern fcml_stf_test_suite fcml_si_cpp_parser; 14 | 15 | #endif /* PARSER_T_HPP_ */ 16 | -------------------------------------------------------------------------------- /check/public-tests/general_usage_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * general_usage_t.h 3 | * 4 | * Created on: May 25, 2014 5 | * Author: tas 6 | */ 7 | 8 | #ifndef GENERAL_USAGE_T_H_ 9 | #define GENERAL_USAGE_T_H_ 10 | 11 | #include 12 | 13 | extern fcml_stf_test_suite fcml_si_general_usage; 14 | 15 | #endif /* GENERAL_USAGE_T_H_ */ 16 | -------------------------------------------------------------------------------- /src/libfcml.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | includedir=@includedir@ 4 | libdir=@libdir@ 5 | 6 | Name: fcml 7 | Description: A machine code manipulation library for Intel 64 and IA-32. 8 | URL: https://github.com/swojtasiak/fcml-lib.git 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lfcml 12 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/fcml/dllmain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { 4 | switch (ul_reason_for_call) { 5 | case DLL_PROCESS_ATTACH: 6 | case DLL_THREAD_ATTACH: 7 | case DLL_THREAD_DETACH: 8 | case DLL_PROCESS_DETACH: 9 | break; 10 | } 11 | return TRUE; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/fcml/dllmain.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { 4 | switch (ul_reason_for_call) { 5 | case DLL_PROCESS_ATTACH: 6 | case DLL_THREAD_ATTACH: 7 | case DLL_THREAD_DETACH: 8 | case DLL_PROCESS_DETACH: 9 | break; 10 | } 11 | return TRUE; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | build: 3 | docker: 4 | - image: ubuntu:20.04 5 | steps: 6 | - run: | 7 | apt-get update -qq 8 | apt-get install build-essential autoconf libtool-bin flex bison git -y 9 | - checkout 10 | - run: | 11 | autoreconf -i 12 | ./configure 13 | make && make check 14 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/fcml/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by fcml.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/fcml/resource1.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by fcml.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/fcml/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by fcml.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/fcml/resource1.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by fcml.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/examples/hsdis/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by hsdis.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/examples/hsdis/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by hsdis.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /docs/doxygen/doxyfile.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = @PACKAGE_NAME@ 2 | PROJECT_NUMBER = @PACKAGE_VERSION@ 3 | STRIP_FROM_PATH = @top_srcdir@ 4 | INPUT = @top_srcdir@/include 5 | INCLUDE_PATH = @top_srcdir@/include 6 | EXCLUDE_PATTERNS = *_parser_def.c *_parser_def.h *_lexer.c *_lexer.h 7 | FILE_PATTERNS = *.c *.h *.cpp *.hpp 8 | RECURSIVE = NO 9 | GENERATE_LATEX = YES 10 | GENERATE_HTML = YES 11 | JAVADOC_AUTOBRIEF = YES 12 | ENUM_VALUES_PER_LINE = 1 13 | WARN_IF_UNDOCUMENTED = NO 14 | 15 | -------------------------------------------------------------------------------- /docs/doxygen/Makefile.am: -------------------------------------------------------------------------------- 1 | docpkg = $(PACKAGE_TARNAME)-doxy-$(PACKAGE_VERSION).tar.gz 2 | doc_DATA = $(docpkg) 3 | 4 | $(docpkg): doxygen.stamp 5 | tar chof - html | gzip -9 -c >$@ 6 | 7 | doxygen.stamp: doxyfile 8 | $(DOXYGEN) $(DOXYFLAGS) $< 9 | echo Timestamp > $@ 10 | 11 | install-data-hook: 12 | cd $(DESTDIR)$(docdir) && tar xf $(docpkg) 13 | 14 | uninstall-hook: 15 | cd $(DESTDIR)$(docdir) && rm -rf html 16 | cd $(DESTDIR)$(docdir) && rm -rf latex 17 | 18 | CLEANFILES = doxywarn.txt doxygen.stamp $(docpkg) 19 | 20 | clean-local: 21 | rm -rf html 22 | rm -rf latex -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /autom4te.cache 2 | /.settings 3 | /.cproject 4 | /.project 5 | /aclocal.m4 6 | /config.guess 7 | /config.h.in 8 | /config.log 9 | /config.status 10 | /config.sub 11 | /configure 12 | /depcomp 13 | /install-sh 14 | /libtool 15 | /ltmain.sh 16 | /Makefile 17 | /Makefile.in 18 | /missing 19 | /stamp-h1 20 | /ylwrap 21 | /config.h 22 | config.h.in~ 23 | compile 24 | /valgrind* 25 | /fcml-*.tar.gz 26 | /fcml-*.tar.xz 27 | autoscan-*.log 28 | configure.scan 29 | test-driver 30 | /misc 31 | *.exe 32 | .libs 33 | *.pc 34 | *.swp 35 | *.opendb 36 | *.db-shm 37 | *.db-wal 38 | .vscode 39 | configure~ 40 | dist/ 41 | -------------------------------------------------------------------------------- /check/cpp-tests/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = fcml_cpp_check 2 | 3 | # Include all tests. 4 | 5 | fcml_cpp_check_SOURCES = main.cpp \ 6 | dialect_t.cpp \ 7 | dialect_t.hpp \ 8 | common_t.cpp \ 9 | common_t.hpp \ 10 | assembler_t.cpp \ 11 | assembler_t.hpp \ 12 | disassembler_t.cpp \ 13 | disassembler_t.hpp \ 14 | errors_t.cpp \ 15 | errors_t.hpp \ 16 | parser_t.cpp \ 17 | parser_t.hpp 18 | 19 | fcml_cpp_check_CPPFLAGS = -Wall -Wno-write-strings -I$(top_srcdir)/include -I$(top_srcdir)/check/stf @FCML_IMPORT_LIB@ 20 | 21 | fcml_cpp_check_LDADD = $(top_srcdir)/src/libfcml.la $(top_srcdir)/check/stf/libstf.la 22 | 23 | check_SCRIPTS = fcml_cpp_check 24 | 25 | TESTS = $(check_SCRIPTS) 26 | 27 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is a general purpose machine code manipulation library for IA-32 and Intel 64 architectures. 2 | The library supports UNIX-like systems as well as Windows and is highly portable. The FCML library 3 | is free for commercial and non-commercial use as long as the terms of the LGPL license are met. 4 | Currently it supports such features as: 5 | 6 | * A one-line disassembler 7 | * A one-line assembler 8 | * An experimental multi-pass load-and-go assembler (Multi line!) 9 | * Support for the Intel and AT&T syntax 10 | * An instruction renderer 11 | * An instruction parser 12 | * Instructions represented as generic models 13 | * UNIX/GNU/Linux and Windows support 14 | * Portable - written entirely in C (no external dependencies) 15 | * Supported instruction sets: MMX, 3D-Now!, SSE, SSE2, SSE3, SSSE3, 16 | SSE4.1, SSE4.2, SSE4A, AVX, AVX2, AES, TBM, BMI1, BMI2, 17 | HLE, ADX, CLMUL, RDRAND, RDSEED, FMA, FMA4, LWP, SVM, XOP, VMX, SMX, AVX-512, XEON PHI 18 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | pkginclude_HEADERS = fcml_assembler.h \ 2 | fcml_assembler.hpp \ 3 | fcml_choosers.h \ 4 | fcml_common.h \ 5 | fcml_common.hpp \ 6 | fcml_common_utils.h \ 7 | fcml_dialect.h \ 8 | fcml_dialect.hpp \ 9 | fcml_disassembler.h \ 10 | fcml_disassembler.hpp \ 11 | fcml_env.h \ 12 | fcml_errors.h \ 13 | fcml_errors.hpp \ 14 | fcml_gas_dialect.h \ 15 | fcml_gas_dialect.hpp \ 16 | fcml_gas_mnemonics.h \ 17 | fcml_instructions.h \ 18 | fcml_intel_dialect.h \ 19 | fcml_intel_dialect.hpp \ 20 | fcml_intel_mnemonics.h \ 21 | fcml_lag_assembler.h \ 22 | fcml_lag_assembler.hpp \ 23 | fcml_lib_export.h \ 24 | fcml_optimizers.h \ 25 | fcml_parser.h \ 26 | fcml_parser.hpp \ 27 | fcml_registers.cpp \ 28 | fcml_registers.hpp \ 29 | fcml_renderer.h \ 30 | fcml_renderer.hpp \ 31 | fcml_stateful_assembler.hpp \ 32 | fcml_stateful_disassembler.hpp \ 33 | fcml_symbols.h \ 34 | fcml_symbols.hpp \ 35 | fcml_types.h \ 36 | fcml_gas_mnemonics.hpp \ 37 | fcml_gas_mnemonics.cpp \ 38 | fcml_intel_mnemonics.hpp \ 39 | fcml_intel_mnemonics.cpp -------------------------------------------------------------------------------- /check/internal-tests/ceh_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef CEH_T_H_ 21 | #define CEH_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_ceh; 26 | 27 | #endif /* CEH_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/hints_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef HINTS_T_H_ 21 | #define HINTS_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_hints; 26 | 27 | #endif /* HINTS_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/render_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef RENDER_T_H_ 21 | #define RENDER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_render; 26 | 27 | #endif /* RENDER_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/env_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_ENV_T_H_ 21 | #define FCML_ENV_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_env; 26 | 27 | #endif /* FCML_ENV_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/stream_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef STREAM_T_H_ 21 | #define STREAM_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_stream; 26 | 27 | #endif /* STREAM_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_i_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #ifndef INS_I_H_ 20 | #define INS_I_H_ 21 | 22 | #include 23 | 24 | extern fcml_stf_test_suite fctl_si_instructions_i; 25 | 26 | #endif /* INS_I_H_ */ 27 | -------------------------------------------------------------------------------- /check/cpp-tests/common_t.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef COMMON_T_HPP_ 21 | #define COMMON_T_HPP_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_cpp_common; 26 | 27 | #endif /* COMMON_T_HPP_ */ 28 | -------------------------------------------------------------------------------- /check/cpp-tests/errors_t.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef ERRORS_T_HPP_ 21 | #define ERRORS_T_HPP_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_cpp_errors; 26 | 27 | #endif /* ERRORS_T_HPP_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/coll_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_COLL_T_H_ 21 | #define FCML_COLL_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_coll; 26 | 27 | #endif /* FCML_COLL_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/symbols_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef SYMBOLS_T_H_ 21 | #define SYMBOLS_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_symbols; 26 | 27 | #endif /* SYMBOLS_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_a_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_A_H_ 21 | #define INS_A_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_a; 26 | 27 | #endif /* INS_A_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_b_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_B_H_ 21 | #define INS_B_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_b; 26 | 27 | #endif /* INS_B_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_c_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_C_H_ 21 | #define INS_C_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_c; 26 | 27 | #endif /* INS_C_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_d_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_D_H_ 21 | #define INS_D_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_d; 26 | 27 | #endif /* INS_D_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_e_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_E_H_ 21 | #define INS_E_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_e; 26 | 27 | #endif /* INS_E_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_f_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_F_H_ 21 | #define INS_F_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_f; 26 | 27 | #endif /* INS_F_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_g_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_G_H_ 21 | #define INS_G_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_g; 26 | 27 | #endif /* INS_G_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_h_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_H_H_ 21 | #define INS_H_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_h; 26 | 27 | #endif /* INS_H_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_j_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_J_H_ 21 | #define INS_J_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_j; 26 | 27 | #endif /* INS_J_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_k_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_K_H_ 21 | #define INS_K_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_k; 26 | 27 | #endif /* INS_K_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_l_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_L_H_ 21 | #define INS_L_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_l; 26 | 27 | #endif /* INS_L_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_m_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_M_H_ 21 | #define INS_M_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_m; 26 | 27 | #endif /* INS_M_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_n_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_N_H_ 21 | #define INS_N_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_n; 26 | 27 | #endif /* INS_N_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_o_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_O_H_ 21 | #define INS_O_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_o; 26 | 27 | #endif /* INS_O_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_p_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_P_H_ 21 | #define INS_P_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_p; 26 | 27 | #endif /* INS_P_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_r_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_R_H_ 21 | #define INS_R_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_r; 26 | 27 | #endif /* INS_R_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_s_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_S_H_ 21 | #define INS_S_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_s; 26 | 27 | #endif /* INS_S_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_t_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_T_H_ 21 | #define INS_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_t; 26 | 27 | #endif /* INS_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_u_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_U_H_ 21 | #define INS_U_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_u; 26 | 27 | #endif /* INS_U_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_v_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_V_H_ 21 | #define INS_v_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_v; 26 | 27 | #endif /* INS_V_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_w_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_W_H_ 21 | #define INS_W_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_w; 26 | 27 | #endif /* INS_W_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/instructions_x_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INS_X_H_ 21 | #define INS_X_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_instructions_x; 26 | 27 | #endif /* INS_X_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/prefixes_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef PREFIXES_T_H_ 21 | #define PREFIXES_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_prefixes; 26 | 27 | #endif /* PREFIXES_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/cpp-tests/dialect_t.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef DIALECT_T_HPP_ 21 | #define DIALECT_T_HPP_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_cpp_dialect; 26 | 27 | #endif /* DIALECT_T_HPP_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/utils_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_UTILS_T_H_ 21 | #define FCML_UTILS_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_utils; 26 | 27 | #endif /* FCML_UTILS_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/assembler_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef ASSEMBLER_T_H_ 21 | #define ASSEMBLER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_assembler; 26 | 27 | #endif /* ASSEMBLER_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/chooser_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_CHOOSER_T_H_ 21 | #define FCML_CHOOSER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_chooser; 26 | 27 | #endif /* FCML_CHOOSER_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/cpp-tests/assembler_t.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef ASSEMBLER_T_HPP_ 21 | #define ASSEMBLER_T_HPP_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_cpp_assembler; 26 | 27 | #endif /* ASSEMBLER_T_HPP_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/segment_reg_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef SEGMENT_REG_T_H_ 21 | #define SEGMENT_REG_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_segment_reg; 26 | 27 | #endif /* SEGMENT_REG_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/disassembler_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef DISASSEMBLER_T_H_ 21 | #define DISASSEMBLER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_disassembler; 26 | 27 | #endif /* DISASSEMBLER_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/common_utils_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef COMMON_UTILS_T_H_ 21 | #define COMMON_UTILS_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_common_utils; 26 | 27 | #endif /* COMMON_UTILS_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/public-tests/error_handling_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef ERROR_HANDLING_H_ 21 | #define ERROR_HANDLING_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_error_handling; 26 | 27 | #endif /* ERROR_HANDLING_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/gas_parser_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_GAS_PARSER_T_H_ 21 | #define FCML_GAS_PARSER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_gas_parser; 26 | 27 | #endif /* FCML_GAS_PARSER_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/modrm_decoder_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef MODRM_DECODER_T_H_ 21 | #define MODRM_DECODER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_modrm_decoder; 26 | 27 | #endif /* MODRM_DECODER_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/modrm_encoder_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef MODRM_ENCODER_T_H_ 21 | #define MODRM_ENCODER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fctl_si_modrm_encoder; 26 | 27 | #endif /* MODRM_ENCODER_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/cpp-tests/disassembler_t.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | 21 | #ifndef DISASSEMBLER_T_HPP_ 22 | #define DISASSEMBLER_T_HPP_ 23 | 24 | #include 25 | 26 | extern fcml_stf_test_suite fcml_si_cpp_disassembler; 27 | 28 | #endif /* DISASSEMBLER_T_HPP_ */ 29 | -------------------------------------------------------------------------------- /check/internal-tests/intel_parser_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_INTEL_PARSER_H_ 21 | #define FCML_INTEL_PARSER_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_intel_parser; 26 | 27 | #endif /* FCML_INTEL_PARSER_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/lag_assembler_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef LAG_ASSEMBLER_T_H_ 21 | #define LAG_ASSEMBLER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_lag_assembler; 26 | 27 | 28 | #endif /* LAG_ASSEMBLER_T_H_ */ 29 | -------------------------------------------------------------------------------- /check/internal-tests/mnemonic_parser_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_MNEMONIC_PARSER_T_H_ 21 | #define FCML_MNEMONIC_PARSER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_mnemonic_parser; 26 | 27 | #endif /* FCML_MNEMONIC_PARSER_T_H_ */ 28 | -------------------------------------------------------------------------------- /check/internal-tests/instruction_chooser_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2024 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef INSTRUCTION_CHOOSER_T_H_ 21 | #define INSTRUCTION_CHOOSER_T_H_ 22 | 23 | #include 24 | 25 | extern fcml_stf_test_suite fcml_si_instruction_chooser; 26 | 27 | #endif /* INSTRUCTION_CHOOSER_T_H_ */ 28 | -------------------------------------------------------------------------------- /src/fcml_dialect.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include "fcml_dialect_int.h" 22 | 23 | void LIB_CALL fcml_fn_dialect_free(fcml_st_dialect *dialect) { 24 | if (dialect) { 25 | ((fcml_st_dialect_context_int*) dialect)->free_dialect(dialect); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/fcml_gas_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_GAS_PARSER_H_ 21 | #define FCML_GAS_PARSER_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "fcml_parser_int.h" 28 | 29 | fcml_ceh_error fcml_fn_gas_parse_instruction_to_ast(fcml_ip ip, 30 | const fcml_string mnemonic, fcml_st_parser_ast *ast); 31 | 32 | #endif /* FCML_GAS_PARSER_H_ */ 33 | -------------------------------------------------------------------------------- /src/fcml_intel_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | * 19 | */ 20 | 21 | #ifndef FCML_INTEL_PARSER_H_ 22 | #define FCML_INTEL_PARSER_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "fcml_parser_int.h" 29 | 30 | fcml_ceh_error fcml_fn_intel_parse_instruction_to_ast(fcml_ip ip, 31 | const fcml_string mnemonic, fcml_st_parser_ast *ast); 32 | 33 | #endif /* FCML_INTEL_PARSER_H_ */ 34 | -------------------------------------------------------------------------------- /src/fcml_assembler_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_ASSEMBLER_INT_H_ 21 | #define FCML_ASSEMBLER_INT_H_ 22 | 23 | #include 24 | 25 | /** 26 | * Extracts dialect from assembler instance. 27 | * 28 | * @param assembler Assembler dialect should be extracted from. 29 | * @return Extracted dialect. 30 | */ 31 | fcml_st_dialect *fcml_fn_assembler_extract_dialect(fcml_st_assembler *assembler); 32 | 33 | #endif /* FCML_ASSEMBLER_INT_H_ */ 34 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/examples/hsdis/dllmain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "targetver.h" 21 | #include 22 | 23 | BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { 24 | 25 | switch (ul_reason_for_call) 26 | { 27 | case DLL_PROCESS_ATTACH: 28 | case DLL_THREAD_ATTACH: 29 | case DLL_THREAD_DETACH: 30 | case DLL_PROCESS_DETACH: 31 | break; 32 | } 33 | 34 | return TRUE; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/examples/hsdis/dllmain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "targetver.h" 21 | #include 22 | 23 | BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { 24 | 25 | switch (ul_reason_for_call) 26 | { 27 | case DLL_PROCESS_ATTACH: 28 | case DLL_THREAD_ATTACH: 29 | case DLL_THREAD_DETACH: 30 | case DLL_PROCESS_DETACH: 31 | break; 32 | } 33 | 34 | return TRUE; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/fcml_trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_TRACE_H_ 21 | #define FCML_TRACE_H_ 22 | 23 | #include "stdio.h" 24 | 25 | #ifdef FCML_DEBUG 26 | #define FCML_TRACE(pattern, ...) { printf("%s:%d ", __FILE__, __LINE__); printf(pattern, ##__VA_ARGS__); printf("\n");} 27 | #define FCML_TRACE_MSG(msg) { printf("%s:%d ", __FILE__, __LINE__); printf("%s\n", msg); } 28 | #else 29 | #define FCML_TRACE(pattern, ...) 30 | #define FCML_TRACE_MSG(msg) 31 | #endif 32 | 33 | #endif /* FCML_TRACE_H_ */ 34 | -------------------------------------------------------------------------------- /src/fcml_disp8_n.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2017 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 18 | * USA 19 | */ 20 | 21 | #ifndef SRC_FCML_DISP8_N_H_ 22 | #define SRC_FCML_DISP8_N_H_ 23 | 24 | #include "fcml_common.h" 25 | 26 | /** 27 | * Decodes N size for disp8 * N displacement. 28 | * 29 | * If "input_size" is equal to 0 it means that input size is not available. 30 | * 31 | * Returns 0 if N is unknown. 32 | */ 33 | fcml_uint32_t fcml_fn_d8n_calculate_n(fcml_uint32_t tuple_type, 34 | fcml_bool evex_b, fcml_uint32_t input_size, fcml_uint32_t vector_len); 35 | 36 | #endif /* SRC_FCML_DISP8_N_H_ */ 37 | -------------------------------------------------------------------------------- /src/fcml_gas_rend.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_GAS_REND_H_ 21 | #define FCML_GAS_REND_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "fcml_stream.h" 30 | 31 | fcml_ceh_error fcml_fn_rend_render_instruction_gas( 32 | const fcml_st_dialect *dialect_context, 33 | const fcml_st_render_config *config, 34 | fcml_st_memory_stream *output_stream, 35 | const fcml_st_disassembler_result *result); 36 | 37 | #endif /* FCML_GAS_REND_H_ */ 38 | -------------------------------------------------------------------------------- /src/fcml_intel_rend.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_INTEL_REND_H_ 21 | #define FCML_INTEL_REND_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "fcml_stream.h" 30 | 31 | fcml_ceh_error fcml_fn_rend_render_instruction_intel( 32 | const fcml_st_dialect *dialect_context, 33 | const fcml_st_render_config *config, 34 | fcml_st_memory_stream *output_stream, 35 | const fcml_st_disassembler_result *result); 36 | 37 | #endif /* FCML_INTEL_REND_H_ */ 38 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/examples/hsdis/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // The following macros define the minimum required platform. The minimum required platform 4 | // is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 5 | // your application. The macros work by enabling all features available on platform versions up to and 6 | // including the version specified. 7 | 8 | // Modify the following defines if you have to target a platform prior to the ones specified below. 9 | // Refer to MSDN for the latest info on corresponding values for different platforms. 10 | #ifndef WINVER // Specifies that the minimum required platform is Windows Vista. 11 | #define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. 12 | #endif 13 | 14 | #ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. 15 | #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. 16 | #endif 17 | 18 | #ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. 19 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 20 | #endif 21 | 22 | #ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. 23 | #define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. 24 | #endif 25 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/examples/hsdis/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // The following macros define the minimum required platform. The minimum required platform 4 | // is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 5 | // your application. The macros work by enabling all features available on platform versions up to and 6 | // including the version specified. 7 | 8 | // Modify the following defines if you have to target a platform prior to the ones specified below. 9 | // Refer to MSDN for the latest info on corresponding values for different platforms. 10 | #ifndef WINVER // Specifies that the minimum required platform is Windows Vista. 11 | #define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. 12 | #endif 13 | 14 | #ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. 15 | #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. 16 | #endif 17 | 18 | #ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. 19 | #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 20 | #endif 21 | 22 | #ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. 23 | #define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. 24 | #endif 25 | -------------------------------------------------------------------------------- /src/fcml_modrm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_MODRM_H_ 21 | #define FCML_MODRM_H_ 22 | 23 | #include 24 | #include 25 | 26 | typedef struct fcml_st_modrm { 27 | /* Register number specified by reg_opcode.*/ 28 | fcml_uint8_t reg_opcode; 29 | /* True if register needs REX prefix to be encoded.*/ 30 | fcml_bool reg_opcode_needs_rex; 31 | /* Register number specified by r/m when mod == 3.*/ 32 | fcml_nuint8_t reg; 33 | /* Effective address.*/ 34 | fcml_st_address address; 35 | /* True if RIP encoding is used.*/ 36 | fcml_bool is_rip; 37 | } fcml_st_modrm; 38 | 39 | #endif /* FCML_MODRM_H_ */ 40 | -------------------------------------------------------------------------------- /src/fcml_ceh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_CEH_H_ 21 | #define FCML_CEH_H_ 22 | 23 | #include 24 | #include 25 | 26 | void fcml_fn_ceh_move_errors(fcml_st_ceh_error_container *destination, 27 | fcml_st_ceh_error_container *source); 28 | 29 | void fcml_fn_ceh_free_errors_only(fcml_st_ceh_error_container *error_container); 30 | 31 | void fcml_fn_ceh_free_errors_only_with_level( 32 | fcml_st_ceh_error_container *error_container, 33 | fcml_en_ceh_error_level level); 34 | 35 | fcml_st_ceh_error_info *fcml_fn_ceh_add_error( 36 | fcml_st_ceh_error_container *error_container, 37 | const fcml_string message, fcml_ceh_error code, 38 | fcml_en_ceh_error_level level ); 39 | 40 | #endif /* FCML_CEH_H_ */ 41 | -------------------------------------------------------------------------------- /check/public-tests/instructions_g_t.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include "instructions_g_t.h" 22 | #include "instructions_base_t.h" 23 | 24 | fcml_bool fcml_tf_instructions_g_suite_init(void) { 25 | return FCML_TRUE; 26 | } 27 | 28 | fcml_bool fcml_tf_instructions_g_suite_cleanup(void) { 29 | return FCML_TRUE; 30 | } 31 | 32 | void fcml_tf_instruction_GETSEC(void) { 33 | FCML_I3264( "getsec", 0x0F, 0x37 ); 34 | FCML_A64( "getsec", 0x0f, 0x37 ); 35 | } 36 | 37 | fcml_stf_test_case fctl_ti_instructions_g[] = { 38 | { "fcml_tf_instruction_GETSEC", fcml_tf_instruction_GETSEC }, 39 | FCML_STF_NULL_TEST 40 | }; 41 | 42 | fcml_stf_test_suite fctl_si_instructions_g = { 43 | "suite-fctl_ti_instructions_g", fcml_tf_instructions_g_suite_init, fcml_tf_instructions_g_suite_cleanup, fctl_ti_instructions_g 44 | }; 45 | -------------------------------------------------------------------------------- /m4/as-compiler-flag.m4: -------------------------------------------------------------------------------- 1 | dnl as-compiler-flag.m4 0.1.0 2 | 3 | dnl autostars m4 macro for detection of compiler flags 4 | 5 | dnl David Schleef 6 | 7 | dnl $Id: as-compiler-flag.m4,v 1.1 2005/12/15 23:35:19 ds Exp $ 8 | 9 | dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED]) 10 | dnl Tries to compile with the given CFLAGS. 11 | dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags, 12 | dnl and ACTION-IF-NOT-ACCEPTED otherwise. 13 | 14 | AC_DEFUN([AS_COMPILER_FLAG], 15 | [ 16 | AC_MSG_CHECKING([to see if compiler understands $1]) 17 | 18 | save_CFLAGS="$CFLAGS" 19 | CFLAGS="$CFLAGS $1" 20 | 21 | AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) 22 | CFLAGS="$save_CFLAGS" 23 | 24 | if test "X$flag_ok" = Xyes ; then 25 | m4_ifvaln([$2],[$2]) 26 | true 27 | else 28 | m4_ifvaln([$3],[$3]) 29 | true 30 | fi 31 | AC_MSG_RESULT([$flag_ok]) 32 | ]) 33 | 34 | dnl AS_COMPILER_FLAGS(VAR, FLAGS) 35 | dnl Tries to compile with the given CFLAGS. 36 | 37 | AC_DEFUN([AS_COMPILER_FLAGS], 38 | [ 39 | list=$2 40 | flags_supported="" 41 | flags_unsupported="" 42 | AC_MSG_CHECKING([for supported compiler flags]) 43 | for each in $list 44 | do 45 | save_CFLAGS="$CFLAGS" 46 | CFLAGS="$CFLAGS $each" 47 | AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no]) 48 | CFLAGS="$save_CFLAGS" 49 | 50 | if test "X$flag_ok" = Xyes ; then 51 | flags_supported="$flags_supported $each" 52 | else 53 | flags_unsupported="$flags_unsupported $each" 54 | fi 55 | done 56 | AC_MSG_RESULT([$flags_supported]) 57 | if test "X$flags_unsupported" != X ; then 58 | AC_MSG_WARN([unsupported compiler flags: $flags_unsupported]) 59 | fi 60 | $1="$$1 $flags_supported" 61 | ]) 62 | 63 | -------------------------------------------------------------------------------- /src/fcml_common_dialect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_COMMON_DIALECT_H_ 21 | #define FCML_COMMON_DIALECT_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "fcml_ceh.h" 28 | #include "fcml_mnemonic_parser.h" 29 | 30 | fcml_ceh_error fcml_fn_cmn_dialect_get_mnemonic(const fcml_st_dialect *dialect, 31 | fcml_st_mp_mnemonic_set *mnemonic_set, fcml_st_mp_mnemonic **mnemonics, 32 | const fcml_st_condition *condition, int *mnemonics_counter); 33 | 34 | fcml_string fcml_fn_cmn_dialect_render_mnemonic(fcml_string mnemonic, 35 | fcml_st_condition *condition, fcml_uint8_t conditional_group, 36 | fcml_bool show_carry); 37 | 38 | fcml_ceh_error fcml_fn_cmn_dialect_get_register(const fcml_st_register *reg, 39 | fcml_string *printable_reg, fcml_bool is_rex); 40 | 41 | void fcml_fn_cmn_dialect_free(fcml_st_dialect *dialect); 42 | 43 | #endif /* FCML_COMMON_DIALECT_H_ */ 44 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/examples/hsdis/hsdis.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | 31 | 32 | Header Files 33 | 34 | 35 | Header Files 36 | 37 | 38 | Header Files 39 | 40 | 41 | 42 | 43 | Resource Files 44 | 45 | 46 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/examples/hsdis/hsdis.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | 31 | 32 | Header Files 33 | 34 | 35 | Header Files 36 | 37 | 38 | Header Files 39 | 40 | 41 | 42 | 43 | Resource Files 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/fcml_operand_decorators.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2017 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef SRC_FCML_OPERAND_DECORATORS_H_ 21 | #define SRC_FCML_OPERAND_DECORATORS_H_ 22 | 23 | #include "fcml_common.h" 24 | #include "fcml_def.h" 25 | 26 | typedef struct fcml_st_decorators_existence { 27 | fcml_bool bcast; 28 | fcml_bool z; 29 | fcml_bool er; 30 | fcml_bool opmask_reg; 31 | fcml_bool sae; 32 | } fcml_st_decorators_existence; 33 | 34 | typedef struct fcml_st_decorators_prefix_flags { 35 | fcml_bool b; 36 | fcml_bool z; 37 | fcml_uint8_t aaa; 38 | fcml_uint8_t ll; 39 | } fcml_st_decorators_prefix_flags; 40 | 41 | void fcml_fn_prepare_decorators_existence(fcml_operand_desc *operands, 42 | fcml_st_decorators_existence *dec_existence); 43 | 44 | /** 45 | * Decodes operand decorators for one operand. 46 | */ 47 | fcml_ceh_error fcml_fn_op_decor_decode( 48 | fcml_st_decorators_prefix_flags *prefix_flags, 49 | fcml_operand_decorators decorators_def, fcml_st_operand *operand); 50 | 51 | #endif /* SRC_FCML_OPERAND_DECODERS_H_ */ 52 | -------------------------------------------------------------------------------- /include/fcml_dialect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /** @file fcml_dialect.h 21 | * Structures and functions related to dialects. 22 | * Functions and structures used for developing new dialects are not exposed 23 | * as public API. If you are interested in implementing another dialect 24 | * you have to use internal headers. 25 | * 26 | * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. 27 | * This project is released under the GNU Lesser General Public License. 28 | */ 29 | 30 | #ifndef FCML_DIALECT_H_ 31 | #define FCML_DIALECT_H_ 32 | 33 | #include "fcml_lib_export.h" 34 | 35 | /** Assembler dialect.*/ 36 | typedef struct fcml_st_dialect fcml_st_dialect; 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * Frees dialect instance. 44 | * Frees all resources occupied by the dialect instance. 45 | * @param dialect Dialect to be freed. 46 | */ 47 | LIB_EXPORT void LIB_CALL fcml_fn_dialect_free( fcml_st_dialect *dialect ); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* FCML_DIALECT_H_ */ 54 | -------------------------------------------------------------------------------- /check/internal-tests/symbols_t.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include "symbols_t.h" 23 | 24 | #include 25 | 26 | fcml_bool fcml_tf_symbols_suite_init(void) { 27 | return FCML_TRUE; 28 | } 29 | 30 | fcml_bool fcml_tf_symbols_suite_cleanup(void) { 31 | return FCML_TRUE; 32 | } 33 | 34 | void fcml_tf_symbols_alloc() { 35 | fcml_st_symbol_table table = fcml_fn_symbol_table_alloc(); 36 | STF_ASSERT_PTR_NOT_NULL( table ); 37 | if( table ) { 38 | fcml_st_symbol *symbol = fcml_fn_symbol_alloc( "MAX_PATH", 256 ); 39 | STF_ASSERT_PTR_NOT_NULL( symbol ); 40 | if( symbol ) { 41 | STF_ASSERT_EQUAL( fcml_fn_symbol_add( table, symbol ), FCML_CEH_GEC_NO_ERROR ); 42 | } 43 | fcml_fn_symbol_table_free( table ); 44 | } 45 | } 46 | 47 | fcml_stf_test_case fctl_ti_symbols[] = { 48 | { "fcml_tf_symbols_alloc", fcml_tf_symbols_alloc }, 49 | FCML_STF_NULL_TEST 50 | }; 51 | 52 | fcml_stf_test_suite fctl_si_symbols = { 53 | "suite-symbols", fcml_tf_symbols_suite_init, fcml_tf_symbols_suite_cleanup, fctl_ti_symbols 54 | }; 55 | 56 | 57 | -------------------------------------------------------------------------------- /check/internal-tests/common_utils_t.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "common_utils_t.h" 21 | 22 | #include 23 | 24 | fcml_bool fcml_tf_common_utils_suite_init(void) { 25 | return FCML_TRUE; 26 | } 27 | 28 | fcml_bool fcml_tf_common_utils_suite_cleanup(void) { 29 | return FCML_TRUE; 30 | } 31 | 32 | void fcml_tf_common_utils_instruction_cloning(void) { 33 | 34 | fcml_st_instruction instruction = {0}; 35 | instruction.mnemonic = "adc"; 36 | 37 | fcml_st_instruction *cloned = (fcml_st_instruction*)fcml_fn_cu_clone_instruction( &instruction ); 38 | STF_ASSERT_PTR_NOT_NULL( cloned ); 39 | STF_ASSERT_STRING_EQUAL( "adc", cloned->mnemonic ); 40 | 41 | fcml_fn_cu_free_instruction( cloned ); 42 | } 43 | 44 | fcml_stf_test_case fcml_ti_common_utils[] = { 45 | { "fcml_tf_common_utils_instruction_cloning", fcml_tf_common_utils_instruction_cloning }, 46 | FCML_STF_NULL_TEST 47 | }; 48 | 49 | fcml_stf_test_suite fcml_si_common_utils = { 50 | "suite-fcml-common-utils", fcml_tf_common_utils_suite_init, fcml_tf_common_utils_suite_cleanup, fcml_ti_common_utils 51 | }; 52 | 53 | -------------------------------------------------------------------------------- /check/cpp-tests/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | // Include mnemonics and register definitions into the destination image file. 25 | #include 26 | #include 27 | #include 28 | 29 | #include "dialect_t.hpp" 30 | #include "common_t.hpp" 31 | #include "assembler_t.hpp" 32 | #include "disassembler_t.hpp" 33 | #include "errors_t.hpp" 34 | #include "parser_t.hpp" 35 | 36 | fcml_stf_test_suite *fcml_arr_cpp_suites[] = { 37 | &fcml_si_cpp_dialect, 38 | &fcml_si_cpp_common, 39 | &fcml_si_cpp_assembler, 40 | &fcml_si_cpp_disassembler, 41 | &fcml_si_cpp_errors, 42 | &fcml_si_cpp_parser, 43 | &fcml_si_cpp_assembler, 44 | FCML_STF_NULL_SUITE 45 | }; 46 | 47 | #include 48 | 49 | using namespace fcml; 50 | 51 | int main(int argc, char **argv) { 52 | 53 | /* Run tests.*/ 54 | 55 | fcml_bool result = fcml_stf_run_tests( FCML_TEXT("CPP wrappers tests"), fcml_arr_cpp_suites ); 56 | 57 | exit( result ? 0 : 1 ); 58 | } 59 | 60 | 61 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 10.06.2014 (1.0.0) 2 | - First official release 3 | 03.02.2015 (1.1.0) 4 | - Wrapper for C++ language 5 | - Some minor fixes in unit tests 6 | - Multi-pass assembler tests could have failed on some systems due to a bug 7 | - Several missing 'extern "C"' declarations added 8 | - 'dist' build targed has been fixed 9 | - pkg-config support 10 | - Lexer generated using newer version of flex 11 | 04.08.2015 (1.1.1) 12 | - Bug fix #1 - FCML-based HSDIS crashes when used with WinPerfAsmProfiler 13 | - Some minor build related changes 14 | - Internal unit tests have been disabled for MinGW and Cygwin builds 15 | - \DEBUG option has been added to hsdis (Debug) for VS2013 project 16 | 23.09.2016 (1.1.2) 17 | - hsdis - License changed to LGPL 2.1 18 | 18.10.2016 (1.1.3) 19 | - bug fix in tests (https://github.com/swojtasiak/fcml-lib/pull/3) 20 | - additional Apache 2.0 license added to hsdis 21 | 13.11.2019 (1.2.0) 22 | - bug fixes 23 | - AVX-512 support 24 | 24.04.2020 (1.2.1) 25 | - a new option (-all) added to fcml-asm 26 | - lots of refactoring and cleanup 27 | - important bug fixes: a bug in [ebp] encoding fixed (assembler) 28 | - important bug fixes: a bug in es segment register override fixed (assembler) 29 | 26.04.2020 (1.2.2) 30 | - some c99 features were removed in order to continue with VS support 31 | - support for vs2015 removed 32 | 11.04.2021 (1.2.3) 33 | - bug fix: https://github.com/swojtasiak/fcml-lib/issues/313 34 | - bug fix: https://github.com/swojtasiak/fcml-lib/issues/314 35 | - bug fix: https://github.com/swojtasiak/fcml-lib/issues/318 36 | - bison upgraded, deprecated directives removed 37 | - symbols are not exported by default anymore 38 | - the error handling refactored a bit 39 | - lots of code cleanups 40 | 26.01.2024 (1.3.0) 41 | - bug fix: https://github.com/swojtasiak/fcml-lib/issues/331 42 | - bug fix: https://github.com/swojtasiak/fcml-lib/issues/330 43 | - improvements in the default instruction chooser 44 | - bison upgraded 45 | - code cleanup 46 | - bug fix in vmovaps 47 | -------------------------------------------------------------------------------- /check/public-tests/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = fcml_public_check 2 | 3 | fcml_public_check_SOURCES = main.c \ 4 | error_handling_t.c \ 5 | error_handling_t.h \ 6 | hints_t.c \ 7 | hints_t.h \ 8 | instructions_a_t.c \ 9 | instructions_a_t.h \ 10 | instructions_base_t.c \ 11 | instructions_base_t.h \ 12 | instructions_b_t.c \ 13 | instructions_b_t.h \ 14 | instructions_c_t.c \ 15 | instructions_c_t.h \ 16 | instructions_d_t.c \ 17 | instructions_d_t.h \ 18 | instructions_e_t.c \ 19 | instructions_e_t.h \ 20 | instructions_f_t.c \ 21 | instructions_f_t.h \ 22 | instructions_g_t.c \ 23 | instructions_g_t.h \ 24 | instructions_h_t.c \ 25 | instructions_h_t.h \ 26 | instructions_i_t.c \ 27 | instructions_i_t.h \ 28 | instructions_j_t.c \ 29 | instructions_j_t.h \ 30 | instructions_l_t.c \ 31 | instructions_l_t.h \ 32 | instructions_k_t.c \ 33 | instructions_k_t.h \ 34 | instructions_m_t.c \ 35 | instructions_m_t.h \ 36 | instructions_n_t.c \ 37 | instructions_n_t.h \ 38 | instructions_o_t.c \ 39 | instructions_o_t.h \ 40 | instructions_p_t.c \ 41 | instructions_p_t.h \ 42 | instructions_r_t.c \ 43 | instructions_r_t.h \ 44 | instructions_s_t.c \ 45 | instructions_s_t.h \ 46 | instructions_t_t.c \ 47 | instructions_t_t.h \ 48 | instructions_u_t.c \ 49 | instructions_u_t.h \ 50 | instructions_v_t.c \ 51 | instructions_v_t.h \ 52 | instructions_w_t.c \ 53 | instructions_w_t.h \ 54 | instructions_x_t.c \ 55 | instructions_x_t.h \ 56 | prefixes_t.c \ 57 | prefixes_t.h \ 58 | segment_reg_t.c \ 59 | segment_reg_t.h \ 60 | chooser_t.c \ 61 | chooser_t.h \ 62 | render_t.h \ 63 | render_t.c \ 64 | disassembler_t.c \ 65 | disassembler_t.h \ 66 | assembler_t.c \ 67 | assembler_t.h \ 68 | general_usage_t.h \ 69 | general_usage_t.c 70 | 71 | fcml_public_check_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/check/stf @FCML_IMPORT_LIB@ 72 | 73 | fcml_public_check_LDADD = $(top_srcdir)/src/libfcml.la $(top_srcdir)/check/stf/libstf.la 74 | 75 | check_SCRIPTS = fcml_public_check 76 | 77 | TESTS = $(check_SCRIPTS) 78 | -------------------------------------------------------------------------------- /src/fcml_renderer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include "fcml_stream.h" 23 | #include "fcml_dialect_int.h" 24 | #include "fcml_trace.h" 25 | #include "fcml_env_int.h" 26 | 27 | fcml_ceh_error LIB_CALL fcml_fn_render(const fcml_st_dialect *dialect, 28 | const fcml_st_render_config *config, fcml_char *buffer, 29 | fcml_usize buffer_len, 30 | const fcml_st_disassembler_result *result) { 31 | 32 | fcml_st_memory_stream output_stream; 33 | output_stream.base_address = buffer; 34 | output_stream.offset = 0; 35 | output_stream.size = buffer_len; 36 | 37 | fcml_st_dialect_context_int *dialect_context_int = 38 | (fcml_st_dialect_context_int*)dialect; 39 | if (dialect_context_int->instruction_renderer) { 40 | fcml_fnp_render_instruction renderer = (fcml_fnp_render_instruction) 41 | dialect_context_int->instruction_renderer; 42 | return renderer( dialect, config, &output_stream, result ); 43 | } else { 44 | /* Dialect not initialized correctly.*/ 45 | FCML_TRACE_MSG("Rendering not supported by current dialect."); 46 | return FCML_CEH_GEC_FEATURE_NOT_SUPPORTED; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/fcml_parser_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_PARSER_INT_H_ 21 | #define FCML_PARSER_INT_H_ 22 | 23 | #include 24 | 25 | #include "fcml_apc_ast.h" 26 | #include "fcml_coll.h" 27 | #include "fcml_ceh.h" 28 | 29 | typedef struct fcml_st_parser_ast { 30 | /* Defined symbol. */ 31 | fcml_st_symbol *symbol; 32 | /* Abstract syntax tree of parsed instruction. */ 33 | fcml_st_ast_node *tree; 34 | /* All potential errors going here. */ 35 | fcml_st_ceh_error_container errors; 36 | } fcml_st_parser_ast; 37 | 38 | fcml_ceh_error fcml_fn_parse_to_cif(fcml_st_parser_context *context, 39 | const fcml_string instruction, fcml_st_parser_result *result_out); 40 | 41 | fcml_ceh_error fcml_fn_parse_to_ast(fcml_st_parser_context *context, 42 | const fcml_string instruction, fcml_st_parser_ast *ast_out); 43 | 44 | fcml_ceh_error fcml_fn_parser_add_symbol_to_symbol_table( 45 | fcml_st_ceh_error_container *errors, fcml_st_symbol_table symbol_table, 46 | fcml_st_symbol *symbol, fcml_bool allow_override); 47 | 48 | void fcml_fn_parser_free_ast(fcml_st_parser_ast *ast); 49 | 50 | void fcml_fn_parser_free_symbol(fcml_st_symbol *symbol); 51 | 52 | #endif /* FCML_PARSER_INT_H_ */ 53 | -------------------------------------------------------------------------------- /check/cpp-tests/dialect_t.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /* Test suite initialization. */ 21 | 22 | #include "dialect_t.hpp" 23 | 24 | #include 25 | #include 26 | 27 | using namespace fcml; 28 | 29 | class DialectExtractor: public DialectAware { 30 | }; 31 | 32 | fcml_bool fcml_tf_cpp_dialect_suite_init(void) { 33 | return FCML_TRUE; 34 | } 35 | 36 | fcml_bool fcml_tf_cpp_dialect_suite_cleanup(void) { 37 | return FCML_TRUE; 38 | } 39 | 40 | void fcml_tf_cpp_init_intel(void) { 41 | IntelDialect intel; 42 | DialectExtractor extractor; 43 | STF_ASSERT_PTR_NOT_NULL( extractor.extractDialect( intel ) ); 44 | IntelDialect *intelPTR = new IntelDialect(FCML_INTEL_DIALECT_CF_DEFAULT); 45 | STF_ASSERT_PTR_NOT_NULL( extractor.extractDialect( *intelPTR ) ); 46 | delete intelPTR; 47 | } 48 | 49 | void fcml_tf_cpp_init_gas(void) { 50 | } 51 | 52 | fcml_stf_test_case fcml_ti_cpp_dialect[] = { 53 | { "fcml_tf_cpp_init_intel", fcml_tf_cpp_init_intel }, 54 | { "fcml_tf_cpp_init_gas", fcml_tf_cpp_init_gas }, 55 | FCML_STF_NULL_TEST 56 | }; 57 | 58 | fcml_stf_test_suite fcml_si_cpp_dialect = { 59 | "suite-fcml-cpp-dialect", fcml_tf_cpp_dialect_suite_init, fcml_tf_cpp_dialect_suite_cleanup, fcml_ti_cpp_dialect 60 | }; 61 | -------------------------------------------------------------------------------- /check/internal-tests/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2024 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | /* Tests.*/ 26 | #include "modrm_encoder_t.h" 27 | #include "modrm_decoder_t.h" 28 | #include "stream_t.h" 29 | #include "coll_t.h" 30 | #include "utils_t.h" 31 | #include "intel_parser_t.h" 32 | #include "gas_parser_t.h" 33 | #include "mnemonic_parser_t.h" 34 | #include "lag_assembler_t.h" 35 | #include "env_t.h" 36 | #include "ceh_t.h" 37 | #include "common_utils_t.h" 38 | #include "instruction_chooser_t.h" 39 | #include "symbols_t.h" 40 | 41 | fcml_stf_test_suite *fcml_arr_suites[] = { 42 | &fctl_si_modrm_encoder, 43 | &fctl_si_modrm_decoder, 44 | &fctl_si_stream, 45 | &fcml_si_coll, 46 | &fcml_si_utils, 47 | &fcml_si_intel_parser, 48 | &fcml_si_gas_parser, 49 | &fcml_si_mnemonic_parser, 50 | &fcml_si_lag_assembler, 51 | &fcml_si_env, 52 | &fcml_si_ceh, 53 | &fcml_si_common_utils, 54 | &fcml_si_instruction_chooser, 55 | &fctl_si_symbols, 56 | FCML_STF_NULL_SUITE 57 | }; 58 | 59 | int main(int argc, char **argv) { 60 | 61 | /* Run tests.*/ 62 | fcml_bool result = fcml_stf_run_tests( FCML_TEXT( "Internal unit tests" ), 63 | fcml_arr_suites ); 64 | 65 | exit( result ? 0 : 1 ); 66 | } 67 | -------------------------------------------------------------------------------- /include/fcml_gas_dialect.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /** @file fcml_gas_dialect.hpp 21 | * C++ wrapper for the AT&T dialect. 22 | * 23 | * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. 24 | * This project is released under the GNU Lesser General Public License. 25 | */ 26 | 27 | #ifndef FCML_GAS_DIALECT_HPP_ 28 | #define FCML_GAS_DIALECT_HPP_ 29 | 30 | #include "fcml_dialect.hpp" 31 | 32 | #include "fcml_gas_dialect.h" 33 | 34 | namespace fcml { 35 | 36 | /** Wraps the AT&T dialect. 37 | * @since 1.1.0 38 | */ 39 | class GASDialect: public Dialect { 40 | public: 41 | /** 42 | * Creates AT&T dialect. 43 | * 44 | * @param flags Optional flags. 45 | * @since 1.1.0 46 | */ 47 | GASDialect(fcml_uint32_t flags = FCML_GAS_DIALECT_CF_DEFAULT) { 48 | fcml_st_dialect *dialect; 49 | fcml_ceh_error error = ::fcml_fn_dialect_init_gas(flags, &dialect); 50 | if (error) { 51 | throw InitException( 52 | FCML_TEXT("Can not initialize the AT&T dialect."), error); 53 | } 54 | setDialect(dialect); 55 | } 56 | /** 57 | * Virtual destructor. 58 | * @since 1.1.0 59 | */ 60 | virtual ~GASDialect() { 61 | } 62 | }; 63 | 64 | } 65 | 66 | #endif /* FCML_GAS_DIALECT_HPP_ */ 67 | -------------------------------------------------------------------------------- /include/fcml_intel_dialect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /** @file fcml_intel_dialect.h 21 | * Intel dialect implementation. 22 | * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. 23 | * This project is released under the GNU Lesser General Public License. 24 | */ 25 | 26 | #ifndef FCML_ASM_DIALECT_INTEL_H_ 27 | #define FCML_ASM_DIALECT_INTEL_H_ 28 | 29 | #include "fcml_lib_export.h" 30 | 31 | #include "fcml_errors.h" 32 | #include "fcml_dialect.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** Default combination of the configuration flags.*/ 39 | #define FCML_INTEL_DIALECT_CF_DEFAULT 0 40 | 41 | /** 42 | * Initializes Intel dialect. 43 | * Prepares new instance of Intel dialect for given set of configuration flags. 44 | * Every dialect has to be freed using fcml_fn_dialect_free() function. 45 | * 46 | * @param config_flags Configuration flags dedicated to the dialect. 47 | * @param[out] dialect Prepared dialect instance. 48 | * @return Error code or FCML_CEH_GEC_NO_ERROR. 49 | * @see fcml_fn_dialect_free 50 | */ 51 | LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_dialect_init_intel( 52 | fcml_uint32_t config_flags, fcml_st_dialect **dialect); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* FCML_ASM_DIALECT_INTEL_H_ */ 59 | -------------------------------------------------------------------------------- /src/fcml_hints.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_HINTS_H_ 21 | #define FCML_HINTS_H_ 22 | 23 | #include 24 | 25 | #include "fcml_def.h" 26 | 27 | typedef struct fcml_st_hts_calculated_hints { 28 | fcml_hints instruction_hints; 29 | fcml_hints operand_hints; 30 | } fcml_st_hts_calculated_hints; 31 | 32 | typedef fcml_st_hts_calculated_hints (*fcml_fp_hts_instruction_hints_calculator)( 33 | const fcml_st_def_addr_mode_desc *addr_mode, 34 | fcml_st_def_decoded_addr_mode *decoded_addr_mode); 35 | 36 | fcml_st_hts_calculated_hints fcml_fn_hts_ihc_far_pointer( 37 | const fcml_st_def_addr_mode_desc *addr_mode, 38 | fcml_st_def_decoded_addr_mode *decoded_addr_mode); 39 | 40 | fcml_st_hts_calculated_hints fcml_fn_hts_ihc_modrm_hints( 41 | const fcml_st_def_addr_mode_desc *addr_mode, 42 | fcml_st_def_decoded_addr_mode *decoded_addr_mode); 43 | 44 | fcml_st_hts_calculated_hints fcml_fn_hts_ihc_immediate_dis_relative( 45 | const fcml_st_def_addr_mode_desc *addr_mode, 46 | fcml_st_def_decoded_addr_mode *decoded_addr_mode); 47 | 48 | fcml_st_hts_calculated_hints fcml_fn_hts_ihc_pseudo_opcode( 49 | const fcml_st_def_addr_mode_desc *addr_mode, 50 | fcml_st_def_decoded_addr_mode *decoded_addr_mode); 51 | 52 | #endif /* FCML_HINTS_H_ */ 53 | -------------------------------------------------------------------------------- /include/fcml_intel_dialect.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /** @file fcml_intel_dialect.hpp 21 | * C++ wrapper for the Intel dialect. 22 | * 23 | * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. 24 | * This project is released under the GNU Lesser General Public License. 25 | */ 26 | 27 | #ifndef FCML_INTEL_DIALECT_HPP_ 28 | #define FCML_INTEL_DIALECT_HPP_ 29 | 30 | #include "fcml_dialect.hpp" 31 | 32 | #include "fcml_intel_dialect.h" 33 | 34 | namespace fcml { 35 | 36 | /** Wraps the Intel dialect. 37 | * @since 1.1.0 38 | */ 39 | class IntelDialect: public Dialect { 40 | public: 41 | /** 42 | * Creates the Intel dialect. 43 | * 44 | * @param flags Optional flags. 45 | * @since 1.1.0 46 | */ 47 | IntelDialect(fcml_uint32_t flags = FCML_INTEL_DIALECT_CF_DEFAULT) { 48 | fcml_st_dialect *dialect; 49 | fcml_ceh_error error = ::fcml_fn_dialect_init_intel(flags, &dialect); 50 | if (error) { 51 | throw InitException( 52 | FCML_TEXT("Can not initialize the Intel dialect."), error); 53 | } 54 | Dialect::setDialect(dialect); 55 | } 56 | /** 57 | * Virtual destructor. 58 | * @since 1.1.0 59 | */ 60 | virtual ~IntelDialect() { 61 | } 62 | }; 63 | 64 | } 65 | 66 | #endif /* FCML_INTEL_DIALECT_HPP_ */ 67 | -------------------------------------------------------------------------------- /src/fcml_parser_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_PUTILS_H_ 21 | #define FCML_PUTILS_H_ 22 | 23 | #include 24 | 25 | #include "fcml_env_int.h" 26 | #include "fcml_apc_ast.h" 27 | #include "fcml_ceh.h" 28 | #include "fcml_coll.h" 29 | 30 | /** Override default memory allocation function used by bison parser */ 31 | #define YYMALLOC fcml_fn_env_memory_alloc 32 | 33 | /** Override default memory deallocation function used by bison parser */ 34 | #define YYFREE fcml_fn_env_memory_free 35 | 36 | typedef struct fcml_st_parser_data { 37 | /* Lexer context. */ 38 | void *scannerInfo; 39 | /* Instruction pointer used to declare symbols. */ 40 | fcml_ip ip; 41 | /* Defined symbol. */ 42 | fcml_st_symbol *symbol; 43 | /* Abstract syntax tree of parsed isntruction. */ 44 | fcml_st_ast_node *tree; 45 | /* All potential errors going here. */ 46 | fcml_st_ceh_error_container errors; 47 | } fcml_st_parser_data; 48 | 49 | void fcml_fn_pu_parse_integer(const fcml_char *str, 50 | fcml_st_ast_val_integer *integer_value, int base); 51 | 52 | void fcml_fn_pu_parse_float(const fcml_char *str, 53 | fcml_st_ast_val_float *float_value); 54 | 55 | void fcml_fn_pu_parse_register(fcml_en_register type, fcml_usize size, 56 | fcml_uint8_t num, fcml_bool x64_exp, fcml_st_register *reg_dest); 57 | 58 | fcml_char* fcml_fn_pu_reg_type_to_string(fcml_en_register type); 59 | 60 | #endif /* FCML_PUTILS_H_ */ 61 | -------------------------------------------------------------------------------- /include/fcml_gas_dialect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /** @file fcml_gas_dialect.h 21 | * AT&T dialect implementation. 22 | * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. 23 | * This project is released under the GNU Lesser General Public License. 24 | */ 25 | 26 | #ifndef FCML_ASM_DIALECT_GAS_H_ 27 | #define FCML_ASM_DIALECT_GAS_H_ 28 | 29 | #include "fcml_lib_export.h" 30 | 31 | #include "fcml_errors.h" 32 | #include "fcml_dialect.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** Disables "SystemV/386 SVR3.2" compatibility for the non-commutative 39 | * arithmetic floating point operations with two register operands. */ 40 | #define FCML_GAS_DIALECT_CF_SYSV_SVR32_INCOMPATIBLE 0x00000001 41 | 42 | /** Default combination of configuration flags. */ 43 | #define FCML_GAS_DIALECT_CF_DEFAULT 0 44 | 45 | /** 46 | * Initializes AT&T dialect. 47 | * Prepares new instance of AT&T dialect for given set of configuration flags. 48 | * Every dialect has to be freed using fcml_fn_dialect_free() function. 49 | * 50 | * @param config_flags Configuration flags dedicated to the dialect. 51 | * @param[out] dialect Prepared dialect instance. 52 | * @return Error code or FCML_CEH_GEC_NO_ERROR. 53 | * @see fcml_fn_dialect_free 54 | */ 55 | LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_dialect_init_gas( 56 | fcml_uint32_t config_flags, fcml_st_dialect **dialect); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* FCML_ASM_DIALECT_GAS_H_ */ 63 | -------------------------------------------------------------------------------- /win32/Makefile.am: -------------------------------------------------------------------------------- 1 | WIN32_FINAL_DIST = vs2019 2 | 3 | define build_win32 4 | rm -Rf $(1)/dist 5 | 6 | mkdir -p $(1)/dist/x86 7 | mkdir -p $(1)/dist/x86/debug-dll 8 | mkdir -p $(1)/dist/x86/debug-lib 9 | mkdir -p $(1)/dist/x86/release-dll 10 | mkdir -p $(1)/dist/x86/release-lib 11 | mkdir -p $(1)/dist/x86_hsdis 12 | 13 | mkdir -p $(1)/dist/x64 14 | mkdir -p $(1)/dist/x64/debug-dll 15 | mkdir -p $(1)/dist/x64/debug-lib 16 | mkdir -p $(1)/dist/x64/release-dll 17 | mkdir -p $(1)/dist/x64/release-lib 18 | mkdir -p $(1)/dist/x64_hsdis 19 | 20 | cp $(1)/fcml/Debug-dll/fcml.dll $(1)/dist/x86/debug-dll 21 | cp $(1)/fcml/Debug-dll/fcml.lib $(1)/dist/x86/debug-dll 22 | cp $(1)/fcml/Release-dll/fcml.dll $(1)/dist/x86/release-dll 23 | cp $(1)/fcml/Release-dll/fcml.lib $(1)/dist/x86/release-dll 24 | cp $(1)/fcml/Debug-lib/fcml.lib $(1)/dist/x86/debug-lib 25 | cp $(1)/fcml/Release-lib/fcml.lib $(1)/dist/x86/release-lib 26 | 27 | cp $(1)/fcml/Release-lib/hsdis.dll $(1)/dist/x86_hsdis/hsdis.dll 28 | cp $(1)/fcml/Release-lib/hsdis.lib $(1)/dist/x86_hsdis/hsdis.lib 29 | cp ../example/hsdis/COPYING $(1)/dist/x86_hsdis/ 30 | 31 | cp $(1)/fcml/x64/Debug-dll/fcml.dll $(1)/dist/x64/debug-dll 32 | cp $(1)/fcml/x64/Debug-dll/fcml.lib $(1)/dist/x64/debug-dll 33 | cp $(1)/fcml/x64/Release-dll/fcml.dll $(1)/dist/x64/release-dll 34 | cp $(1)/fcml/x64/Release-dll/fcml.lib $(1)/dist/x64/release-dll 35 | cp $(1)/fcml/x64/Debug-lib/fcml.lib $(1)/dist/x64/debug-lib 36 | cp $(1)/fcml/x64/Release-lib/fcml.lib $(1)/dist/x64/release-lib 37 | 38 | cp $(1)/fcml/x64/Release-lib/hsdis.dll $(1)/dist/x64_hsdis/hsdis.dll 39 | cp $(1)/fcml/x64/Release-lib/hsdis.lib $(1)/dist/x64_hsdis/hsdis.lib 40 | cp ../example/hsdis/COPYING $(1)/dist/x64_hsdis/ 41 | 42 | cp -R ../include $(1)/dist/ 43 | rm -f $(1)/dist/include/.gitignore 44 | rm -f $(1)/dist/include/Makefile* 45 | 46 | zip $(1)/dist/hsdis-$(PACKAGE_VERSION)-win32-x86.zip -9 -j $(1)/dist/x86_hsdis/hsdis.dll $(1)/dist/x86_hsdis/hsdis.lib $(1)/dist/x86_hsdis/COPYING 47 | zip $(1)/dist/hsdis-$(PACKAGE_VERSION)-win32-amd64.zip -9 -j $(1)/dist/x64_hsdis/hsdis.dll $(1)/dist/x64_hsdis/hsdis.lib $(1)/dist/x64_hsdis/COPYING 48 | 49 | cd $(1)/dist/; zip fcml-$(PACKAGE_VERSION)-win32-VS.zip -9 -r x86/ x64/ include/ 50 | endef 51 | 52 | build-release: 53 | $(call build_win32,$(WIN32_FINAL_DIST)) 54 | rm -Rf dist/ 55 | mv $(WIN32_FINAL_DIST)/dist dist/ 56 | 57 | .PHONY: build-release 58 | -------------------------------------------------------------------------------- /include/fcml_lib_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2021 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /** @file fcml_lib_export.h 21 | * Handles Win32 DLL symbols importing/exporting. 22 | * The only interesting thing here is the LIBFCML_DLL_IMPORT symbol which has to 23 | * be always defined in order to use dynamic DLL under Windows. You can achieve it 24 | * by declaring the symbol before this header file is included. For example: 25 | * @code 26 | * #define LIBFCML_DLL_IMPORT 27 | * #include 28 | * @endcode 29 | * Take into account that this header file is included by every FCML public header, so 30 | * in fact you should define the symbol before including anything from the FCML library. 31 | * This declaration can be omitted as long as you use undecorated symbol names. 32 | * 33 | * @copyright Copyright (C) 2010-2021 Slawomir Wojtasiak. All rights reserved. 34 | * This project is released under the GNU Lesser General Public License. 35 | */ 36 | 37 | #ifndef FCML_LIB_EXPORT_H_ 38 | #define FCML_LIB_EXPORT_H_ 39 | 40 | #ifdef HAVE_CONFIG_H 41 | #include 42 | #endif 43 | 44 | #if _WIN32 || __CYGWIN__ 45 | #define LIB_CALL __stdcall 46 | #ifdef DLL_EXPORT 47 | #define LIB_EXPORT __declspec(dllexport) 48 | #else 49 | #ifdef LIBFCML_DLL_IMPORT 50 | #define LIB_EXPORT __declspec(dllimport) 51 | #endif 52 | #endif 53 | #endif 54 | 55 | #ifndef LIB_EXPORT 56 | #ifdef SUPPORT_VISIBILITY_HIDDEN 57 | #define LIB_EXPORT __attribute__((visibility("default"))) 58 | #else 59 | #define LIB_EXPORT 60 | #endif 61 | #endif 62 | 63 | #ifndef LIB_CALL 64 | #define LIB_CALL 65 | #endif 66 | 67 | #endif /* FCML_LIB_EXPORT_H_ */ 68 | -------------------------------------------------------------------------------- /src/fcml_mnemonic_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_MNEMONIC_PARSER_H_ 21 | #define FCML_MNEMONIC_PARSER_H_ 22 | 23 | #include "fcml_env_int.h" 24 | #include "fcml_ceh.h" 25 | #include "fcml_coll.h" 26 | 27 | typedef struct fcml_st_mp_mnemonic { 28 | fcml_string mnemonic; 29 | fcml_bool is_shortcut; 30 | fcml_bool is_classic; 31 | fcml_bool is_mode_mem_only; 32 | fcml_bool is_mode_reg_only; 33 | fcml_usize is_byte_ds; 34 | fcml_usize is_full_ds; 35 | fcml_usize supported_osa; 36 | fcml_usize supported_asa; 37 | fcml_nuint8_t suffix; 38 | fcml_nuint8_t pseudo_op; 39 | fcml_nuint8_t memory_data; 40 | fcml_bool is_default; 41 | fcml_nuint8_t l; 42 | fcml_uint32_t flags; 43 | } fcml_st_mp_mnemonic; 44 | 45 | typedef struct fcml_st_mp_mnemonic_set { 46 | fcml_st_coll_list *mnemonics; 47 | } fcml_st_mp_mnemonic_set; 48 | 49 | typedef struct fcml_st_mp_config { 50 | fcml_bool use_shortcut; 51 | fcml_nuint8_t pseudo_opcode; 52 | fcml_nuint8_t suffix; 53 | fcml_usize effective_osa; 54 | fcml_usize effective_asa; 55 | fcml_bool is_memory; 56 | fcml_usize memory_data_size; 57 | fcml_nuint8_t l; 58 | } fcml_st_mp_config; 59 | 60 | fcml_ceh_error fcml_fn_mp_parse_mnemonics(fcml_string mnemonics_pattern, 61 | fcml_st_mp_mnemonic_set **mnemonics); 62 | 63 | void fcml_fn_mp_free_mnemonics(fcml_st_mp_mnemonic_set *mnemonics); 64 | 65 | fcml_st_mp_mnemonic *fcml_fn_mp_choose_mnemonic( 66 | fcml_st_mp_mnemonic_set *mnemonics, fcml_st_mp_config *config); 67 | 68 | fcml_usize fcml_fn_mp_l_to_vector_length(fcml_uint8_t l); 69 | 70 | #endif /* FCML_MNEMONIC_PARSER_H_ */ 71 | -------------------------------------------------------------------------------- /src/fcml_decoding_tree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_ASM_DECODING_TREE_H_ 21 | #define FCML_ASM_DECODING_TREE_H_ 22 | 23 | #include "fcml_coll.h" 24 | #include "fcml_def.h" 25 | #include "fcml_dialect_int.h" 26 | 27 | #define FCML_DT_TREE_OPCODE_ARRAY_SIZE 256 28 | 29 | typedef struct fcml_st_dt_diss_tree_element { 30 | struct fcml_st_dt_diss_tree_element *opcodes[FCML_DT_TREE_OPCODE_ARRAY_SIZE]; 31 | fcml_st_coll_list *instruction_decoding_defs; 32 | } fcml_st_dt_diss_tree_element; 33 | 34 | typedef fcml_ceh_error (*fcml_fp_dt_prep_inst_def_callback)( 35 | fcml_st_dialect_context_int *dialect, 36 | fcml_st_dt_diss_tree_element *element, 37 | fcml_st_def_instruction_desc *instruction_desc, 38 | fcml_st_def_addr_mode_desc *opcode_desc); 39 | 40 | typedef void (*fcml_fp_dt_disp_inst_def_callback)( 41 | fcml_st_dialect_context_int *dialect, fcml_ptr instruction_decoding); 42 | 43 | typedef struct fcml_st_dt_decoding_tree { 44 | fcml_st_dt_diss_tree_element *opcode[FCML_DT_TREE_OPCODE_ARRAY_SIZE]; 45 | fcml_st_dialect_context_int *dialect_context; 46 | fcml_fp_dt_prep_inst_def_callback prep_callback; 47 | fcml_fp_dt_disp_inst_def_callback disp_callback; 48 | } fcml_st_dt_decoding_tree; 49 | 50 | fcml_ceh_error fcml_fn_dt_dts_tree_init( 51 | fcml_st_dialect_context_int *dialect_context, 52 | fcml_st_dt_decoding_tree **tree, 53 | fcml_fp_dt_prep_inst_def_callback prepare_callback, 54 | fcml_fp_dt_disp_inst_def_callback dispose_callback); 55 | 56 | void fcml_fn_dt_dts_tree_free(fcml_st_dialect_context_int *dialect_context, 57 | fcml_st_dt_decoding_tree *tree); 58 | 59 | #endif /* FCML_ASM_DECODING_TREE_H_ */ 60 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | EXTRA_DIST = win32/vs2017/fcml/examples/hsdis/dllmain.cpp \ 5 | win32/vs2017/fcml/examples/hsdis/hsdis.def \ 6 | win32/vs2017/fcml/examples/hsdis/hsdis.rc \ 7 | win32/vs2017/fcml/examples/hsdis/hsdis.vcxproj \ 8 | win32/vs2017/fcml/examples/hsdis/hsdis.vcxproj.filters \ 9 | win32/vs2017/fcml/examples/hsdis/resource.h \ 10 | win32/vs2017/fcml/examples/hsdis/targetver.h \ 11 | win32/vs2017/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj \ 12 | win32/vs2017/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj.filters \ 13 | win32/vs2017/fcml/fcml-check/fcml-check.vcxproj \ 14 | win32/vs2017/fcml/fcml-check/fcml-check.vcxproj.filters \ 15 | win32/vs2017/fcml/fcml.sln \ 16 | win32/vs2017/fcml/fcml/dllmain.c \ 17 | win32/vs2017/fcml/fcml/fcml.def \ 18 | win32/vs2017/fcml/fcml/fcml.rc \ 19 | win32/vs2017/fcml/fcml/fcml.vcxproj \ 20 | win32/vs2017/fcml/fcml/fcml.vcxproj.filters \ 21 | win32/vs2017/fcml/fcml/resource.h \ 22 | win32/vs2017/fcml/fcml/resource1.h \ 23 | win32/vs2019/fcml/examples/hsdis/dllmain.cpp \ 24 | win32/vs2019/fcml/examples/hsdis/hsdis.def \ 25 | win32/vs2019/fcml/examples/hsdis/hsdis.rc \ 26 | win32/vs2019/fcml/examples/hsdis/hsdis.vcxproj \ 27 | win32/vs2019/fcml/examples/hsdis/hsdis.vcxproj.filters \ 28 | win32/vs2019/fcml/examples/hsdis/resource.h \ 29 | win32/vs2019/fcml/examples/hsdis/targetver.h \ 30 | win32/vs2019/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj \ 31 | win32/vs2019/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj.filters \ 32 | win32/vs2019/fcml/fcml-check/fcml-check.vcxproj \ 33 | win32/vs2019/fcml/fcml-check/fcml-check.vcxproj.filters \ 34 | win32/vs2019/fcml/fcml.sln \ 35 | win32/vs2019/fcml/fcml/dllmain.c \ 36 | win32/vs2019/fcml/fcml/fcml.def \ 37 | win32/vs2019/fcml/fcml/fcml.rc \ 38 | win32/vs2019/fcml/fcml/fcml.vcxproj \ 39 | win32/vs2019/fcml/fcml/fcml.vcxproj.filters \ 40 | win32/vs2019/fcml/fcml/resource.h \ 41 | win32/vs2019/fcml/fcml/resource1.h 42 | 43 | if HAVE_DOXYGEN 44 | DOXYDIR = docs/doxygen 45 | endif 46 | 47 | SUBDIRS = include src check example win32 $(DOXYDIR) 48 | 49 | docker-build: 50 | @echo 'Building an image for dockerized unit tests.' 51 | docker-compose -f docker-compose.yml build 52 | 53 | docker-tests: docker-build 54 | @echo 'Running the dockerized unit tests.' 55 | docker-compose -f docker-compose.yml run --rm tests 56 | 57 | build-release: 58 | rm -Rf dist 59 | mkdir dist 60 | $(MAKE) $(AM_MAKEFLAGS) -C $(top_srcdir)/win32 build-release 61 | $(MAKE) $(AM_MAKEFLAGS) dist dist-xz 62 | mv fcml-*.tar.* dist/ 63 | cp win32/dist/*.zip dist/ 64 | 65 | .PHONY: build-release 66 | -------------------------------------------------------------------------------- /src/fcml_operand_decorators.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2017 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "fcml_operand_decorators.h" 21 | #include "fcml_def.h" 22 | 23 | void fcml_fn_prepare_decorators_existence(fcml_operand_desc *operands, 24 | fcml_st_decorators_existence *dec_existence) { 25 | int i; 26 | for(i = 0; i < FCML_OPERANDS_COUNT; i++) { 27 | fcml_operand_decorators decorators = FCML_DECORATORS(operands[i]); 28 | if (FCML_IS_DECOR_BCAST(decorators)) { 29 | dec_existence->bcast = FCML_TRUE; 30 | } 31 | if (FCML_IS_DECOR_OPMASK_REG(decorators)) { 32 | dec_existence->opmask_reg = FCML_TRUE; 33 | } 34 | if (FCML_IS_DECOR_Z(decorators)) { 35 | dec_existence->z = FCML_TRUE; 36 | } 37 | if (FCML_IS_DECOR_ER(decorators)) { 38 | dec_existence->er = FCML_TRUE; 39 | } 40 | if (FCML_IS_DECOR_SAE(decorators)) { 41 | dec_existence->sae = FCML_TRUE; 42 | } 43 | } 44 | } 45 | 46 | fcml_ceh_error fcml_fn_op_decor_decode( 47 | fcml_st_decorators_prefix_flags *prefix_flags, 48 | fcml_operand_decorators decorators_def, fcml_st_operand *operand) { 49 | 50 | fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR; 51 | 52 | fcml_st_operand_decorators *decorators = &(operand->decorators); 53 | 54 | /* Operand mask register. */ 55 | if (FCML_IS_DECOR_OPMASK_REG(decorators_def) && prefix_flags->aaa > 0) { 56 | decorators->operand_mask_reg.type = FCML_REG_OPMASK; 57 | decorators->operand_mask_reg.size = FCML_DS_64; 58 | decorators->operand_mask_reg.x64_exp = FCML_FALSE; 59 | decorators->operand_mask_reg.reg = prefix_flags->aaa; 60 | } 61 | 62 | /* Zeroying. */ 63 | if (FCML_IS_DECOR_Z(decorators_def) && prefix_flags->z) { 64 | decorators->z = FCML_TRUE; 65 | } 66 | 67 | return error; 68 | } 69 | -------------------------------------------------------------------------------- /src/fcml_parser_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "fcml_parser_utils.h" 21 | 22 | #include 23 | #include 24 | 25 | void fcml_fn_pu_parse_integer(const fcml_char *str, 26 | fcml_st_ast_val_integer *integer_value, int base) { 27 | #ifdef FCML_MSCC 28 | fcml_uint64_t value = _strtoui64( str, NULL, base ); 29 | #else 30 | fcml_uint64_t value = strtoull(str, NULL, base); 31 | #endif 32 | integer_value->overflow = ( errno == ERANGE); 33 | integer_value->value = value; 34 | integer_value->is_signed = FCML_FALSE; 35 | } 36 | 37 | void fcml_fn_pu_parse_float(const fcml_char *str, 38 | fcml_st_ast_val_float *float_value) { 39 | // Floats are not supported yet. 40 | #ifdef FCML_MSCC 41 | float_value->value = (float)strtod( str, NULL ); 42 | #else 43 | float_value->value = strtof(str, NULL); 44 | #endif 45 | float_value->overflow = ( errno == ERANGE) ? FCML_TRUE : FCML_FALSE; 46 | } 47 | 48 | void fcml_fn_pu_parse_register(fcml_en_register type, fcml_usize size, 49 | fcml_uint8_t reg, fcml_bool x64_exp, fcml_st_register *reg_dest) { 50 | reg_dest->type = type; 51 | reg_dest->size = size; 52 | reg_dest->reg = reg; 53 | reg_dest->x64_exp = x64_exp; 54 | } 55 | 56 | fcml_char* fcml_fn_pu_reg_type_to_string(fcml_en_register type) { 57 | fcml_char *desc; 58 | switch (type) { 59 | case FCML_REG_GPR: 60 | desc = "GPR"; 61 | break; 62 | case FCML_REG_SIMD: 63 | desc = "SIMD"; 64 | break; 65 | case FCML_REG_FPU: 66 | desc = "FPU"; 67 | break; 68 | case FCML_REG_SEG: 69 | desc = "SEG"; 70 | break; 71 | case FCML_REG_DR: 72 | desc = "DR"; 73 | break; 74 | case FCML_REG_CR: 75 | desc = "CR"; 76 | break; 77 | default: 78 | desc = "Unknown"; 79 | break; 80 | } 81 | return desc; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/examples/hsdis/hsdis.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""afxres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 1,3,0,0 55 | PRODUCTVERSION 1,3,0,0 56 | FILEFLAGSMASK 0x17L 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x4L 63 | FILETYPE 0x0L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "040904b0" 69 | BEGIN 70 | VALUE "FileDescription", "hsdis" 71 | VALUE "FileVersion", "1.3.0.0" 72 | VALUE "InternalName", "hsdis" 73 | VALUE "LegalCopyright", "Copyright (C) 2014-2024 Slawomir Wojtasiak" 74 | VALUE "OriginalFilename", "hsdis" 75 | VALUE "ProductName", "hsdis" 76 | VALUE "ProductVersion", "1.3.0.0" 77 | END 78 | END 79 | BLOCK "VarFileInfo" 80 | BEGIN 81 | VALUE "Translation", 0x409, 1200 82 | END 83 | END 84 | 85 | #endif // English (United States) resources 86 | ///////////////////////////////////////////////////////////////////////////// 87 | 88 | 89 | 90 | #ifndef APSTUDIO_INVOKED 91 | ///////////////////////////////////////////////////////////////////////////// 92 | // 93 | // Generated from the TEXTINCLUDE 3 resource. 94 | // 95 | 96 | 97 | ///////////////////////////////////////////////////////////////////////////// 98 | #endif // not APSTUDIO_INVOKED 99 | 100 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/examples/hsdis/hsdis.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""afxres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 1,3,0,0 55 | PRODUCTVERSION 1,3,0,0 56 | FILEFLAGSMASK 0x17L 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x4L 63 | FILETYPE 0x0L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "040904b0" 69 | BEGIN 70 | VALUE "FileDescription", "hsdis" 71 | VALUE "FileVersion", "1.3.0.0" 72 | VALUE "InternalName", "hsdis" 73 | VALUE "LegalCopyright", "Copyright (C) 2014-2024 Slawomir Wojtasiak" 74 | VALUE "OriginalFilename", "hsdis" 75 | VALUE "ProductName", "hsdis" 76 | VALUE "ProductVersion", "1.3.0.0" 77 | END 78 | END 79 | BLOCK "VarFileInfo" 80 | BEGIN 81 | VALUE "Translation", 0x409, 1200 82 | END 83 | END 84 | 85 | #endif // English (United States) resources 86 | ///////////////////////////////////////////////////////////////////////////// 87 | 88 | 89 | 90 | #ifndef APSTUDIO_INVOKED 91 | ///////////////////////////////////////////////////////////////////////////// 92 | // 93 | // Generated from the TEXTINCLUDE 3 resource. 94 | // 95 | 96 | 97 | ///////////////////////////////////////////////////////////////////////////// 98 | #endif // not APSTUDIO_INVOKED 99 | 100 | -------------------------------------------------------------------------------- /src/fcml_messages.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_MESSAGES_H_ 21 | #define FCML_MESSAGES_H_ 22 | 23 | #include 24 | #include 25 | 26 | #define FCML_MESSAGE_MAX 512 27 | 28 | typedef enum fcml_en_msg_message_code { 29 | /* Global error codes. */ 30 | FCML_MC_CEH_GEC_NO_ERROR = 0, 31 | FCML_MC_CEH_GEC_OUT_OF_MEMORY = 1, 32 | FCML_MC_CEH_GEC_INVALID_INPUT = 2, 33 | FCML_MC_CEH_GEC_INTERNAL_ERROR = 3, 34 | FCML_MC_CEH_GEC_NOT_INITIALIZED = 4, 35 | FCML_MC_CEH_GEC_EOF = 5, 36 | FCML_MC_CEH_GEC_VALUE_OUT_OF_RANGE = 6, 37 | FCML_MC_CEH_GEC_FEATURE_NOT_SUPPORTED = 7, 38 | FCML_MC_CEH_GEC_INVALID_ADDRESSING_MODE = 8, 39 | FCML_MC_CEH_GEC_INVALID_ADDRESSING_FORM = 9, 40 | FCML_MC_CEH_GEC_INVALID_INSTRUCTION_FORM = 10, 41 | FCML_MC_CEH_GEC_INVALID_OPPERAND = 11, 42 | FCML_MC_CEH_GEC_UNKNOWN_MNEMONIC = 12, 43 | FCML_MC_CEH_GEC_INVALID_OPPERAND_SIZE = 13, 44 | FCML_MC_CEH_GEC_INVALID_ADDRESS_SIZE = 14, 45 | FCML_MC_CEH_GEC_UNKNOWN_INSTRUCTION = 15, 46 | FCML_MC_CEH_GEC_INVALID_PREFIX = 16, 47 | FCML_MC_CEH_GEC_INVALID_REGISTER_TYPE = 17, 48 | FCML_MC_CEH_GEC_INVALID_REGISTER = 18, 49 | FCML_MC_CEH_GEC_UNDEFINED_SYMBOL = 19, 50 | /* Message error codes. */ 51 | FCML_MC_SEGMENT_REGISTER_CAN_NOT_BE_OVERRIDDEN, 52 | FCML_MC_SEGMENT_INVALID_PSEUDO_OPCODE_IMM, 53 | FCML_MC_SEGMENT_HLE_PREFIXES_NOT_ALLOWED, 54 | FCML_MC_SEGMENT_HLE_MORE_THAN_ONE_PREFIX, 55 | FCML_MC_SEGMENT_WRONG_REGISTER_TYPE_SEG, 56 | FCML_MC_SEGMENT_SYMBOL_ALREADY_DEFINED, 57 | FCML_MC_SEGMENT_UNDEFINED_SYMBOL, 58 | FCML_MC_SEGMENT_PARSED_LINE_TO_LONG 59 | } fcml_en_msg_message_code; 60 | 61 | fcml_string fcml_fn_msg_get_message(fcml_en_msg_message_code code); 62 | 63 | void fcml_fn_msg_add_error_message(fcml_st_ceh_error_container *errors, 64 | fcml_en_msg_message_code msg_code, fcml_ceh_error code, 65 | fcml_en_ceh_error_level level, ...); 66 | 67 | #endif /* FCML_MESSAGES_H_ */ 68 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/fcml/fcml.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource1.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource1.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""afxres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 1,3,0,0 55 | PRODUCTVERSION 1,3,0,0 56 | FILEFLAGSMASK 0x17L 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x4L 63 | FILETYPE 0x0L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "040904b0" 69 | BEGIN 70 | VALUE "FileDescription", "fcml" 71 | VALUE "FileVersion", "1.3.0.0" 72 | VALUE "InternalName", "fcml.dll" 73 | VALUE "LegalCopyright", "Copyright (C) 2010-2024 Slawomir Wojtasiak" 74 | VALUE "LegalTrademarks", "All Rights Reserved" 75 | VALUE "OriginalFilename", "fcml.dll" 76 | VALUE "ProductName", "Free Code Manipulation Library" 77 | VALUE "ProductVersion", "1.3.0.0" 78 | END 79 | END 80 | BLOCK "VarFileInfo" 81 | BEGIN 82 | VALUE "Translation", 0x409, 1200 83 | END 84 | END 85 | 86 | #endif // English (United States) resources 87 | ///////////////////////////////////////////////////////////////////////////// 88 | 89 | 90 | 91 | #ifndef APSTUDIO_INVOKED 92 | ///////////////////////////////////////////////////////////////////////////// 93 | // 94 | // Generated from the TEXTINCLUDE 3 resource. 95 | // 96 | 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | #endif // not APSTUDIO_INVOKED 100 | 101 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/fcml/fcml.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource1.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource1.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""afxres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 1,3,0,0 55 | PRODUCTVERSION 1,3,0,0 56 | FILEFLAGSMASK 0x17L 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x4L 63 | FILETYPE 0x0L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "040904b0" 69 | BEGIN 70 | VALUE "FileDescription", "fcml" 71 | VALUE "FileVersion", "1.3.0.0" 72 | VALUE "InternalName", "fcml.dll" 73 | VALUE "LegalCopyright", "Copyright (C) 2010-2024 Slawomir Wojtasiak" 74 | VALUE "LegalTrademarks", "All Rights Reserved" 75 | VALUE "OriginalFilename", "fcml.dll" 76 | VALUE "ProductName", "Free Code Manipulation Library" 77 | VALUE "ProductVersion", "1.3.0.0" 78 | END 79 | END 80 | BLOCK "VarFileInfo" 81 | BEGIN 82 | VALUE "Translation", 0x409, 1200 83 | END 84 | END 85 | 86 | #endif // English (United States) resources 87 | ///////////////////////////////////////////////////////////////////////////// 88 | 89 | 90 | 91 | #ifndef APSTUDIO_INVOKED 92 | ///////////////////////////////////////////////////////////////////////////// 93 | // 94 | // Generated from the TEXTINCLUDE 3 resource. 95 | // 96 | 97 | 98 | ///////////////////////////////////////////////////////////////////////////// 99 | #endif // not APSTUDIO_INVOKED 100 | 101 | -------------------------------------------------------------------------------- /src/fcml_choosers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | #include "fcml_coll.h" 26 | 27 | struct instruction_holder { 28 | fcml_ptr instruction; 29 | fcml_usize code_length; 30 | }; 31 | 32 | fcml_ptr LIB_CALL fcml_fn_asm_no_instruction_chooser( 33 | fcml_st_chooser_context *context) { 34 | return NULL; 35 | } 36 | 37 | static void fcml_ifn_replace_shortest(struct instruction_holder *shortest, 38 | fcml_ptr instruction, fcml_st_instruction_code *instruction_code) { 39 | if (!shortest->instruction || 40 | instruction_code->code_length < shortest->code_length) { 41 | shortest->instruction = instruction; 42 | shortest->code_length = instruction_code->code_length; 43 | } 44 | } 45 | 46 | fcml_ptr LIB_CALL fcml_fn_asm_default_instruction_chooser( 47 | fcml_st_chooser_context *context) { 48 | fcml_st_instruction_code instruction_code; 49 | fcml_ptr instruction = context->instruction; 50 | 51 | struct instruction_holder shortest = {0}; 52 | struct instruction_holder shortest_no_override = {0}; 53 | 54 | while (instruction) { 55 | context->extract(instruction, &instruction_code); 56 | 57 | /* Keep the shortest GPI instruction which doesn't override anything. */ 58 | if ((instruction_code.details.instruction_group & FCML_AMT_GPI) != 0 && 59 | !instruction_code.details.osa_override && 60 | !instruction_code.details.asa_override) { 61 | fcml_ifn_replace_shortest(&shortest_no_override, instruction, 62 | &instruction_code); 63 | } 64 | 65 | fcml_ifn_replace_shortest(&shortest, instruction, &instruction_code); 66 | 67 | instruction = context->next(instruction); 68 | } 69 | 70 | /* Return the shortest instruction which doesn't override ASA and OSA 71 | if there is any. */ 72 | if (shortest_no_override.instruction != NULL) { 73 | return shortest_no_override.instruction; 74 | } 75 | 76 | return shortest.instruction; 77 | } 78 | -------------------------------------------------------------------------------- /check/public-tests/instructions_w_t.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include "instructions_w_t.h" 22 | #include "instructions_base_t.h" 23 | 24 | fcml_bool fcml_tf_instructions_w_suite_init(void) { 25 | return FCML_TRUE; 26 | } 27 | 28 | fcml_bool fcml_tf_instructions_w_suite_cleanup(void) { 29 | return FCML_TRUE; 30 | } 31 | 32 | void fcml_tf_instruction_WAIT(void) { 33 | 34 | FCML_I3264( "wait", 0x9B ); 35 | 36 | FCML_A64( "wait", 0x9b ); 37 | FCML_A64_A( "fwait", 0x9b ); 38 | } 39 | 40 | void fcml_tf_instruction_WBINVD(void) { 41 | 42 | FCML_I3264( "wbinvd", 0x0F, 0x09 ); 43 | 44 | FCML_A3264( "wbinvd", 0x0f, 0x09 ); 45 | } 46 | 47 | void fcml_tf_instruction_WRFSBASE(void) { 48 | 49 | FCML_I64( "wrfsbase eax", 0xF3, 0x0F, 0xAE, 0xD0 ); 50 | FCML_I64( "wrfsbase eax", 0x66, 0xF3, 0x0F, 0xAE, 0xD0 ); 51 | FCML_I64( "wrfsbase rax", 0xF3, 0x48, 0x0F, 0xAE, 0xD0 ); 52 | 53 | FCML_I64( "wrgsbase eax", 0xF3, 0x0F, 0xAE, 0xD8 ); 54 | FCML_I64( "wrgsbase eax", 0x66, 0xF3, 0x0F, 0xAE, 0xD8 ); 55 | FCML_I64( "wrgsbase rax", 0xF3, 0x48, 0x0F, 0xAE, 0xD8 ); 56 | 57 | FCML_A64( "wrfsbase %eax", 0xf3, 0x0f, 0xae, 0xd0 ); 58 | FCML_A64( "wrfsbase %rax", 0xf3, 0x48, 0x0f, 0xae, 0xd0 ); 59 | FCML_A64( "wrgsbase %eax", 0xf3, 0x0f, 0xae, 0xd8 ); 60 | FCML_A64( "wrgsbase %rax", 0xf3, 0x48, 0x0f, 0xae, 0xd8 ); 61 | } 62 | 63 | void fcml_tf_instruction_WRMSR(void) { 64 | 65 | FCML_I32( "wrmsr", 0x0F, 0x30 ); 66 | FCML_I64( "wrmsr", 0x0F, 0x30 ); 67 | 68 | FCML_A64( "wrmsr", 0x0f, 0x30 ); 69 | FCML_A64( "wrmsr", 0x0f, 0x30 ); 70 | } 71 | 72 | fcml_stf_test_case fctl_ti_instructions_w[] = { 73 | { "fcml_tf_instruction_WAIT", fcml_tf_instruction_WAIT }, 74 | { "fcml_tf_instruction_WBINVD", fcml_tf_instruction_WBINVD }, 75 | { "fcml_tf_instruction_WRFSBASE", fcml_tf_instruction_WRFSBASE }, 76 | { "fcml_tf_instruction_WRMSR", fcml_tf_instruction_WRMSR }, 77 | FCML_STF_NULL_TEST 78 | }; 79 | 80 | fcml_stf_test_suite fctl_si_instructions_w = { 81 | "suite-fctl_ti_instructions_w", fcml_tf_instructions_w_suite_init, fcml_tf_instructions_w_suite_cleanup, fctl_ti_instructions_w 82 | }; 83 | 84 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | @SET_MAKE@ 2 | 3 | BUILT_SOURCES = fcml_intel_parser_def.h fcml_gas_parser_def.h fcml_intel_lexer.h fcml_gas_lexer.h 4 | 5 | AM_YFLAGS = -d -Wno-yacc 6 | 7 | lib_LTLIBRARIES = libfcml.la 8 | 9 | libfcml_la_SOURCES = fcml_intel_lexer.l \ 10 | fcml_intel_lexer.h \ 11 | fcml_gas_lexer.l \ 12 | fcml_gas_lexer.h \ 13 | fcml_intel_parser_def.y \ 14 | fcml_gas_parser_def.y \ 15 | fcml_apc_ast.c \ 16 | fcml_apc_ast.h \ 17 | fcml_assembler.c \ 18 | fcml_assembler_int.h \ 19 | fcml_ceh.c \ 20 | fcml_ceh.h \ 21 | fcml_choosers.c \ 22 | fcml_coll.c \ 23 | fcml_coll.h \ 24 | fcml_common_dialect.c \ 25 | fcml_common_dialect.h \ 26 | fcml_common_lex.h \ 27 | fcml_common_utils.c \ 28 | fcml_decoding_tree.c \ 29 | fcml_decoding_tree.h \ 30 | fcml_def.c \ 31 | fcml_def_enc.c \ 32 | fcml_def.h \ 33 | fcml_dialect.c \ 34 | fcml_dialect_int.c \ 35 | fcml_dialect_int.h \ 36 | fcml_disassembler.c \ 37 | fcml_encoding.c \ 38 | fcml_encoding.h \ 39 | fcml_env_int.c \ 40 | fcml_env_int.h \ 41 | fcml_gas_dialect.c \ 42 | fcml_gas_parser.c \ 43 | fcml_gas_parser.h \ 44 | fcml_gas_rend.c \ 45 | fcml_gas_rend.h \ 46 | fcml_hints.c \ 47 | fcml_hints.h \ 48 | fcml_intel_dialect.c \ 49 | fcml_intel_parser.c \ 50 | fcml_intel_parser.h \ 51 | fcml_intel_rend.c \ 52 | fcml_intel_rend.h \ 53 | fcml_messages.c \ 54 | fcml_messages.h \ 55 | fcml_mnemonic_parser.c \ 56 | fcml_mnemonic_parser.h \ 57 | fcml_modrm_decoder.c \ 58 | fcml_modrm_decoder.h \ 59 | fcml_modrm_encoder.c \ 60 | fcml_modrm_encoder.h \ 61 | fcml_modrm.h \ 62 | fcml_optimizers.c \ 63 | fcml_parser.c \ 64 | fcml_parser_int.c \ 65 | fcml_parser_int.h \ 66 | fcml_parser_utils.c \ 67 | fcml_parser_utils.h \ 68 | fcml_renderer.c \ 69 | fcml_rend_utils.c \ 70 | fcml_rend_utils.h \ 71 | fcml_stream.c \ 72 | fcml_trace.h \ 73 | fcml_utils.c \ 74 | fcml_utils.h \ 75 | fcml_stream.h \ 76 | fcml_lag_assembler.c \ 77 | fcml_symbols.c \ 78 | fcml_disp8_n.h \ 79 | fcml_disp8_n.c \ 80 | fcml_operand_decorators.h \ 81 | fcml_operand_decorators.c 82 | 83 | libfcml_la_CPPFLAGS = -I$(top_srcdir)/include 84 | libfcml_la_LDFLAGS = -no-undefined 85 | 86 | fcml_intel_lexer.h: fcml_intel_lexer.c 87 | @if test ! -f $@; then rm -f fcml_intel_lexer.c; else :; fi 88 | @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) fcml_gas_lexer.c; else :; fi 89 | 90 | fcml_gas_lexer.h: fcml_gas_lexer.c 91 | @if test ! -f $@; then rm -f fcml_gas_lexer.c; else :; fi 92 | @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) fcml_gas_lexer.c; else :; fi 93 | 94 | EXTRA_DIST = libfcml.pc.in 95 | 96 | pkgconfigdir = $(libdir)/pkgconfig 97 | nodist_pkgconfig_DATA = libfcml.pc 98 | 99 | libfcml.pc: libfcml.pc.in 100 | @sed -e 's![@]prefix[@]!$(prefix)!g' \ 101 | -e 's![@]exec_prefix[@]!$(exec_prefix)!g' \ 102 | -e 's![@]includedir[@]!$(includedir)!g' \ 103 | -e 's![@]libdir[@]!$(libdir)!g' \ 104 | -e 's![@]PACKAGE_VERSION[@]!$(PACKAGE_VERSION)!g' \ 105 | $(srcdir)/libfcml.pc.in > $@ 106 | 107 | CLEANFILES = *.pc 108 | -------------------------------------------------------------------------------- /src/fcml_env_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef FCML_ENVIRONMENT_H_ 21 | #define FCML_ENVIRONMENT_H_ 22 | 23 | #include 24 | #include 25 | 26 | #include "fcml_types.h" 27 | 28 | /* Memory. */ 29 | 30 | #define FCML_ENV_ALLOC_ST(str) (str*) \ 31 | fcml_fn_env_memory_alloc_clear(sizeof(str)); 32 | 33 | #define FCML_ENV_ALLOC_CLEAR(variable, type) type* variable = (type*) \ 34 | fcml_fn_env_memory_alloc_clear(sizeof(type)) 35 | 36 | /* Memory allocation. */ 37 | fcml_ptr fcml_fn_env_memory_alloc(fcml_usize size); 38 | 39 | fcml_ptr fcml_fn_env_memory_realloc(fcml_ptr ptr, fcml_usize size); 40 | 41 | fcml_ptr fcml_fn_env_memory_alloc_clear(fcml_usize size); 42 | 43 | void fcml_fn_env_memory_copy(fcml_ptr dest, const fcml_ptr src, fcml_usize len); 44 | 45 | void fcml_fn_env_memory_clear(fcml_ptr src, fcml_usize len); 46 | 47 | fcml_bool fcml_fn_env_memory_cmp(const fcml_ptr src1, const fcml_ptr src2, 48 | fcml_usize len); 49 | 50 | void fcml_fn_env_memory_free(fcml_ptr ptr); 51 | 52 | /* Strings. */ 53 | fcml_bool fcml_fn_env_str_strblank(const fcml_string str); 54 | 55 | fcml_usize fcml_fn_env_str_strlen(const fcml_string str); 56 | 57 | fcml_string fcml_fn_env_str_stralloc(fcml_usize len); 58 | 59 | fcml_string fcml_fn_env_str_strdup(const fcml_string str); 60 | 61 | void fcml_fn_env_str_strcpy( fcml_string src, const fcml_string dst); 62 | 63 | fcml_bool fcml_fn_env_str_strcmp(const fcml_string src1, 64 | const fcml_string src2); 65 | 66 | void fcml_fn_env_str_strncpy( fcml_string dst, const fcml_string src, 67 | fcml_usize len); 68 | 69 | void fcml_fn_env_str_strclr( fcml_string str); 70 | 71 | fcml_string fcml_fn_env_str_strldup(const fcml_string str, fcml_usize size); 72 | 73 | void fcml_fn_env_str_strfree( fcml_string str); 74 | 75 | void fcml_fn_env_str_vsnprintf( fcml_string buffer, fcml_usize maxlen, 76 | const fcml_string format, va_list args); 77 | 78 | void fcml_fn_env_str_snprintf( fcml_string buffer, fcml_usize maxlen, 79 | fcml_string format, ...); 80 | 81 | /* Characters. */ 82 | fcml_bool fcml_fn_env_is_alpha(fcml_char c); 83 | fcml_bool fcml_fn_env_is_digit(fcml_char c); 84 | 85 | #endif /* FCML_ENVIRONMENT_H_ */ 86 | -------------------------------------------------------------------------------- /src/fcml_messages.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | 22 | #include "fcml_messages.h" 23 | #include "fcml_ceh.h" 24 | #include "fcml_env_int.h" 25 | 26 | #define FCML_MAX_MESSAGE_LENGTH 512 27 | 28 | static fcml_string error_messages[] = { 29 | /* Messages for global error codes. */ 30 | FCML_TEXT("No error."), 31 | FCML_TEXT("Out of memory."), 32 | FCML_TEXT("Invalid input."), 33 | FCML_TEXT("Internal error."), 34 | FCML_TEXT("Not initialized."), 35 | FCML_TEXT("Unexpected end of data."), 36 | FCML_TEXT("Value out of range."), 37 | FCML_TEXT("Feature not supported."), 38 | FCML_TEXT("Invalid addressing mode."), 39 | FCML_TEXT("Invalid addressing form."), 40 | FCML_TEXT("Invalid instruction form."), 41 | FCML_TEXT("Invalid operand."), 42 | FCML_TEXT("Unknown mnemonic."), 43 | FCML_TEXT("Invalid operand size."), 44 | FCML_TEXT("Invalid address size."), 45 | FCML_TEXT("Unknown instruction."), 46 | FCML_TEXT("Invalid prefix."), 47 | FCML_TEXT("Invalid register type."), 48 | FCML_TEXT("Invalid register."), 49 | FCML_TEXT("Undefined symbol."), 50 | /* Messages for message error codes. */ 51 | FCML_TEXT("Segment register can not be overridden."), 52 | FCML_TEXT("Invalid pseudo opcode value."), 53 | FCML_TEXT("HLA prefixes are not allowed for instruction."), 54 | FCML_TEXT("More than one HLA prefix."), 55 | FCML_TEXT("Segment register expected."), 56 | FCML_TEXT("Symbol already defined: %s."), 57 | FCML_TEXT("Undefined symbol: %s."), 58 | FCML_TEXT("Parsed line exceed maximum allowed length."), 59 | /* Messages for warnings. */ 60 | }; 61 | 62 | fcml_string fcml_fn_msg_get_message(fcml_en_msg_message_code code) { 63 | return error_messages[code]; 64 | } 65 | 66 | void fcml_fn_msg_add_error_message(fcml_st_ceh_error_container *errors, 67 | fcml_en_msg_message_code msg_code, fcml_ceh_error code, 68 | fcml_en_ceh_error_level level, ...) { 69 | fcml_char buffer[FCML_MAX_MESSAGE_LENGTH]; 70 | va_list args; 71 | va_start(args, level); 72 | fcml_fn_env_str_vsnprintf(buffer, sizeof(buffer), 73 | fcml_fn_msg_get_message(msg_code), args); 74 | va_end(args); 75 | fcml_fn_ceh_add_error(errors, (const fcml_string) buffer, code, level); 76 | } 77 | -------------------------------------------------------------------------------- /win32/vs2017/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {842e0075-848c-4acf-a7aa-f66c6b23ee2f} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | stf 44 | 45 | 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | stf 67 | 68 | 69 | -------------------------------------------------------------------------------- /win32/vs2019/fcml/fcml-check-cpp/fcml-check-cpp.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav 15 | 16 | 17 | {842e0075-848c-4acf-a7aa-f66c6b23ee2f} 18 | 19 | 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | stf 44 | 45 | 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | stf 67 | 68 | 69 | -------------------------------------------------------------------------------- /example/hsdis/hsdis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2021 Slawomir Wojtasiak 4 | * 5 | * This piece of software is available under LGPL or Apache License. 6 | * 7 | * Linkage exception: 8 | * 9 | * You are permitted to build hsdis binaries and link them statically 10 | * with fcml-lib and still release these binaries under Apache License 11 | * without need to distribute the source code. 12 | * 13 | * LGPL: 14 | * 15 | * This library is free software; you can redistribute it and/or 16 | * modify it under the terms of the GNU Lesser General Public 17 | * License as published by the Free Software Foundation; either 18 | * version 2.1 of the License, or (at your option) any later version. 19 | * 20 | * This library is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * Lesser General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public 26 | * License along with this library; if not, write to the Free Software 27 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 28 | * USA 29 | * 30 | * Apache License: 31 | * 32 | * Copyright 2010-2021 Sławomir Wojtasiak 33 | * 34 | * Licensed under the Apache License, Version 2.0 (the "License"); 35 | * you may not use this file except in compliance with the License. 36 | * You may obtain a copy of the License at 37 | * 38 | * http://www.apache.org/licenses/LICENSE-2.0 39 | * 40 | * Unless required by applicable law or agreed to in writing, software 41 | * distributed under the License is distributed on an "AS IS" BASIS, 42 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 43 | * See the License for the specific language governing permissions and 44 | * limitations under the License. 45 | */ 46 | 47 | #ifndef FCML_HSDIS_H_ 48 | #define FCML_HSDIS_H_ 49 | 50 | #include 51 | 52 | #ifdef FCML_MSCC 53 | #ifdef HSDIS_EXPORT_DLL 54 | #define HSDIS_API __declspec(dllexport) 55 | #endif 56 | #ifdef HSDIS_IMPORT_DLL 57 | #define HSDIS_API __declspec(dllimport) 58 | #endif 59 | #endif 60 | 61 | /* If HSDIS_API is not defined here try to use the standard exporting 62 | * macro from fcml-lib. */ 63 | #ifndef HSDIS_API 64 | #ifdef LIB_EXPORT 65 | #define HSDIS_API LIB_EXPORT 66 | #else 67 | #define HSDIS_API 68 | #endif 69 | #endif 70 | 71 | #ifdef FCML_MSCC 72 | #define HSDIS_CALL __cdecl 73 | #else 74 | #define HSDIS_CALL 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | extern "C" { 79 | #endif 80 | 81 | typedef void* (*jvm_event_callback)(void *env_pv, const char *ev, void *arg); 82 | typedef int (*jvm_printf_callback)(void *env_pv, const char *format, ...); 83 | 84 | /* Called directly by jvm.so/jvm.dll. */ 85 | HSDIS_API void* HSDIS_CALL decode_instructions(void *start, void *end, 86 | jvm_event_callback, void *event_stream, jvm_printf_callback, 87 | void *printf_stream, const char *options); 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif /* FCML_HSDIS_H_ */ 94 | -------------------------------------------------------------------------------- /src/fcml_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "fcml_parser.h" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "fcml_dialect_int.h" 27 | #include "fcml_apc_ast.h" 28 | #include "fcml_env_int.h" 29 | #include "fcml_trace.h" 30 | #include "fcml_parser_int.h" 31 | #include "fcml_utils.h" 32 | 33 | fcml_ceh_error LIB_CALL fcml_fn_parse(fcml_st_parser_context *context, 34 | const fcml_string instruction, fcml_st_parser_result *result_out) { 35 | 36 | fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR; 37 | fcml_st_dialect_context_int *dialect_context_int = 38 | (fcml_st_dialect_context_int*) context->dialect; 39 | 40 | if (dialect_context_int->instruction_parser) { 41 | /* Call parser instance associated with given dialect. */ 42 | error = fcml_fn_parse_to_cif(context, instruction, result_out); 43 | } else { 44 | /* Dialect not initialized correctly.*/ 45 | FCML_TRACE_MSG("Parsing not supported by current dialect."); 46 | error = FCML_CEH_GEC_FEATURE_NOT_SUPPORTED; 47 | } 48 | if (error) { 49 | // Try to convert error code to error message if there is such need. 50 | fcml_fn_utils_conv_gec_to_error_info( 51 | context->configuration.enable_error_messages, 52 | &(result_out->errors), error); 53 | } 54 | return error; 55 | } 56 | 57 | void LIB_CALL fcml_fn_parser_result_free(fcml_st_parser_result *result) { 58 | if (result) { 59 | /* Frees parsed instruction, potential errors and warnings and result structure itself.*/ 60 | if (result->instruction) { 61 | fcml_fn_ast_free_converted_cif(result->instruction); 62 | result->instruction = NULL; 63 | } 64 | /* Symbol can not be free, because it is managed by symbols 65 | * table, but of course we have to zero it. 66 | */ 67 | result->symbol = NULL; 68 | fcml_fn_ceh_free_errors_only(&(result->errors)); 69 | } 70 | } 71 | 72 | void LIB_CALL fcml_fn_parser_result_prepare(fcml_st_parser_result *result) { 73 | if (result) { 74 | result->errors.errors = NULL; 75 | result->errors.last_error = NULL; 76 | result->instruction = NULL; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /check/cpp-tests/parser_t.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * parser_t.cpp 3 | * 4 | * Created on: Aug 6, 2014 5 | * Author: tas 6 | */ 7 | 8 | #include "parser_t.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace fcml; 15 | 16 | fcml_bool fcml_tf_cpp_parser_suite_init(void) { 17 | return FCML_TRUE; 18 | } 19 | 20 | fcml_bool fcml_tf_cpp_parser_suite_cleanup(void) { 21 | return FCML_TRUE; 22 | } 23 | 24 | void fcml_tf_cpp_parser(void) { 25 | 26 | try { 27 | 28 | IntelDialect dialect; 29 | 30 | ParserContext ctx(0x401000); 31 | 32 | Parser parser(dialect); 33 | 34 | ParserResult result; 35 | 36 | try { 37 | STF_ASSERT_EQUAL( parser.parse( ctx, _FT("mov eax, dword [0x0401000]"), result ), FCML_CEH_GEC_NO_ERROR ); 38 | STF_ASSERT_EQUAL( parser.parse( ctx, _FT("mov eax, dword [0x0401000]"), result ), FCML_CEH_GEC_NO_ERROR ); 39 | STF_ASSERT_EQUAL( parser.parse( ctx, _FT("mov eax, dword [0x0401000]"), result ), FCML_CEH_GEC_NO_ERROR ); 40 | STF_ASSERT_EQUAL( parser.parse( ctx, _FT("mov eax, dword [0x0401000]"), result ), FCML_CEH_GEC_NO_ERROR ); 41 | } catch( ParsingFailedException &exc ) { 42 | STF_FAIL("Parsing failed."); 43 | } 44 | 45 | const Instruction &instruction = result.getInstruction(); 46 | STF_ASSERT_EQUAL( instruction.isConditional(), false ); 47 | STF_ASSERT_EQUAL( instruction.getCondition().getConditionType(), Condition::CONDITION_O ); 48 | STF_ASSERT_EQUAL( instruction.getMnemonic(), fcml_cstring( _FT("mov") ) ); 49 | STF_ASSERT_EQUAL( instruction.getOperandsCount(), 2 ); 50 | STF_ASSERT_EQUAL( instruction.getPrefixes(), 0 ); 51 | 52 | } catch( std::exception &exc ) { 53 | STF_FAIL("Unexpected exception."); 54 | } catch( fcml::BaseException &exc ) { 55 | STF_FAIL("Unexpected exception."); 56 | } 57 | 58 | } 59 | 60 | 61 | void fcml_tf_cpp_parser_error(void) { 62 | 63 | try { 64 | 65 | IntelDialect dialect; 66 | 67 | ParserContext ctx(0x401000); 68 | 69 | Parser parser(dialect); 70 | 71 | ParserResult result; 72 | 73 | fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR; 74 | 75 | try { 76 | parser.parse( ctx, _FT("mov eax1, dword [0x0401000]"), result ); 77 | STF_FAIL("Parsing failed."); 78 | } catch( ParsingFailedException &exc ) { 79 | error = exc.getError(); 80 | STF_ASSERT_EQUAL( exc.getMsg(), FCML_TEXT( "Parsing failed: Undefined symbol: eax1." ) ); 81 | } 82 | 83 | STF_ASSERT_EQUAL( result.getErrors().getFirstErrorMessage(), FCML_TEXT( "Undefined symbol: eax1." ) ); 84 | STF_ASSERT_EQUAL( error, FCML_CEH_GEC_UNDEFINED_SYMBOL ); 85 | 86 | } catch( std::exception &exc ) { 87 | STF_FAIL("Unexpected exception."); 88 | } catch( fcml::BaseException &exc ) { 89 | STF_FAIL("Unexpected exception."); 90 | } 91 | 92 | } 93 | 94 | fcml_stf_test_case fcml_ti_cpp_parser[] = { 95 | { "fcml_tf_cpp_parser", fcml_tf_cpp_parser }, 96 | { "fcml_tf_cpp_parser_error", fcml_tf_cpp_parser_error }, 97 | FCML_STF_NULL_TEST 98 | }; 99 | 100 | fcml_stf_test_suite fcml_si_cpp_parser = { 101 | "suite-fcml-cpp-parser", fcml_tf_cpp_parser_suite_init, fcml_tf_cpp_parser_suite_cleanup, fcml_ti_cpp_parser 102 | }; 103 | -------------------------------------------------------------------------------- /src/fcml_intel_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "fcml_ceh.h" 25 | #include "fcml_env_int.h" 26 | #include "fcml_parser_utils.h" 27 | #include "fcml_intel_parser_def.h" 28 | #include "fcml_intel_lexer.h" 29 | #include "fcml_intel_parser.h" 30 | #include "fcml_parser_int.h" 31 | 32 | void intel_error(YYLTYPE *yylloc, struct fcml_st_parser_data *pd, 33 | const char *error) { 34 | /* Stores parser error into standard container. */ 35 | fcml_fn_ceh_add_error(&(pd->errors), (const fcml_string) error, 36 | FCML_CEH_MEC_ERROR_INVALID_SYNTAX, FCML_EN_CEH_EL_ERROR); 37 | } 38 | 39 | void* intel_alloc(yy_size_t size, yyscan_t yyscanner) { 40 | return fcml_fn_env_memory_alloc((fcml_usize) size); 41 | } 42 | 43 | void* intel_realloc(void *ptr, yy_size_t size, yyscan_t yyscanner) { 44 | return fcml_fn_env_memory_realloc(ptr, (fcml_usize) size); 45 | } 46 | 47 | void intel_free(void *ptr, yyscan_t yyscanner) { 48 | return fcml_fn_env_memory_free(ptr); 49 | } 50 | 51 | fcml_ceh_error fcml_fn_intel_parse_instruction_to_ast(fcml_ip ip, 52 | const fcml_string mnemonic, fcml_st_parser_ast *ast) { 53 | 54 | fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR; 55 | 56 | /* Instruction size is limited to prevent from parser's stack and buffer overflow. */ 57 | if (!mnemonic || !ast 58 | || fcml_fn_env_str_strlen(mnemonic) 59 | > FCML_PARSER_MAX_INSTRUCTION_LEN) { 60 | return FCML_CEH_GEC_INVALID_INPUT; 61 | } 62 | 63 | /* Fill instruction pointer. */ 64 | fcml_st_parser_data parser = { 0 }; 65 | parser.ip = ip; 66 | 67 | /* Set up scanner. */ 68 | if (intel_lex_init_extra(&parser, &(parser.scannerInfo))) { 69 | return FCML_CEH_GEC_OUT_OF_MEMORY; 70 | } 71 | 72 | intel__scan_string(mnemonic, parser.scannerInfo); 73 | 74 | int yyresult = intel_parse(&parser); 75 | 76 | intel_lex_destroy(parser.scannerInfo); 77 | 78 | ast->errors = parser.errors; 79 | ast->symbol = parser.symbol; 80 | ast->tree = parser.tree; 81 | 82 | if (yyresult) { 83 | switch (yyresult) { 84 | case 1: /*Syntax error.*/ 85 | error = FCML_CEH_GEC_INVALID_INPUT; 86 | break; 87 | case 2: /*Out of memory*/ 88 | error = FCML_CEH_GEC_OUT_OF_MEMORY; 89 | break; 90 | } 91 | } 92 | 93 | return error; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /src/fcml_gas_parser.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "fcml_gas_parser.h" 25 | #include "fcml_ceh.h" 26 | #include "fcml_env_int.h" 27 | #include "fcml_parser_utils.h" 28 | #include "fcml_gas_parser_def.h" 29 | #include "fcml_gas_lexer.h" 30 | #include "fcml_utils.h" 31 | #include "fcml_messages.h" 32 | #include "fcml_parser_int.h" 33 | 34 | void gas_error(YYLTYPE *yylloc, struct fcml_st_parser_data *pd, 35 | const char *error) { 36 | /* Stores parser error into standard container.*/ 37 | fcml_fn_ceh_add_error(&(pd->errors), (const fcml_string) error, 38 | FCML_CEH_MEC_ERROR_INVALID_SYNTAX, FCML_EN_CEH_EL_ERROR); 39 | } 40 | 41 | void* gas_alloc(yy_size_t size, yyscan_t yyscanner) { 42 | return fcml_fn_env_memory_alloc((fcml_usize) size); 43 | } 44 | 45 | void* gas_realloc(void *ptr, yy_size_t size, yyscan_t yyscanner) { 46 | return fcml_fn_env_memory_realloc(ptr, (fcml_usize) size); 47 | } 48 | 49 | void gas_free(void *ptr, yyscan_t yyscanner) { 50 | return fcml_fn_env_memory_free(ptr); 51 | } 52 | 53 | fcml_ceh_error fcml_fn_gas_parse_instruction_to_ast(fcml_ip ip, 54 | const fcml_string mnemonic, fcml_st_parser_ast *ast) { 55 | 56 | fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR; 57 | 58 | /* Instruction size is limited to prevent from parser's stack and buffer overflows. */ 59 | if (!mnemonic || !ast 60 | || fcml_fn_env_str_strlen(mnemonic) 61 | > FCML_PARSER_MAX_INSTRUCTION_LEN) { 62 | return FCML_CEH_GEC_INVALID_INPUT; 63 | } 64 | 65 | /* Fill instruction pointer. */ 66 | fcml_st_parser_data parser = { 0 }; 67 | parser.ip = ip; 68 | 69 | /* Set up scanner. */ 70 | if (gas_lex_init_extra(&parser, &(parser.scannerInfo))) { 71 | return FCML_CEH_GEC_OUT_OF_MEMORY; 72 | } 73 | 74 | gas__scan_string(mnemonic, parser.scannerInfo); 75 | 76 | int yyresult = gas_parse(&parser); 77 | 78 | gas_lex_destroy(parser.scannerInfo); 79 | 80 | ast->errors = parser.errors; 81 | ast->symbol = parser.symbol; 82 | ast->tree = parser.tree; 83 | 84 | if (yyresult) { 85 | switch (yyresult) { 86 | case 1: /*Syntax error.*/ 87 | error = FCML_CEH_GEC_INVALID_INPUT; 88 | break; 89 | case 2: /*Out of memory*/ 90 | error = FCML_CEH_GEC_OUT_OF_MEMORY; 91 | break; 92 | } 93 | } 94 | 95 | return error; 96 | } 97 | -------------------------------------------------------------------------------- /include/fcml_choosers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2024 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /** @file fcml_choosers.h 21 | * 22 | * API for instruction choosers. 23 | * 24 | * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. 25 | * This project is released under the GNU Lesser General Public License. 26 | */ 27 | 28 | #ifndef FCML_CHOOSER_H_ 29 | #define FCML_CHOOSER_H_ 30 | 31 | #include "fcml_lib_export.h" 32 | 33 | #include "fcml_types.h" 34 | #include "fcml_common.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** Returns next instructions from the iterator. 41 | * Instruction chooser uses this function to get next instruction from the chain. 42 | * @param instruction Current instruction. 43 | */ 44 | typedef fcml_ptr (*fcml_fnp_chooser_next)(fcml_ptr instruction); 45 | 46 | /** Gets instruction code from current abstract instruction pointer. 47 | * Gets instruction pointer and fills given instruction code 48 | * holder with the binary code of the instruction. 49 | * @param instruction Instruction pointer. 50 | * @param instruction_code Holder for the instruction code. 51 | */ 52 | typedef void (*fcml_fnp_chooser_extract)(fcml_ptr instruction, 53 | fcml_st_instruction_code *instruction_code); 54 | 55 | /** Instruction chooser context used to communicate with environment. */ 56 | typedef struct fcml_st_chooser_context { 57 | /** First instruction in the chain. */ 58 | fcml_ptr instruction; 59 | /** Gets next instruction code from iterator. */ 60 | fcml_fnp_chooser_next next; 61 | /** Extracts instruction code from the opaque instruction pointer.*/ 62 | fcml_fnp_chooser_extract extract; 63 | } fcml_st_chooser_context; 64 | 65 | /** Instruction chooser function pointer declaration. 66 | * @param chooser_context Instruction chooser context. 67 | */ 68 | typedef fcml_ptr (LIB_CALL *fcml_fnp_asm_instruction_chooser)( 69 | fcml_st_chooser_context *chooser_context); 70 | 71 | /** Default instruction chooser which chooses the shortest instruction available. 72 | * @param chooser_context Instruction chooser context. 73 | */ 74 | fcml_ptr LIB_EXPORT LIB_CALL fcml_fn_asm_default_instruction_chooser( 75 | fcml_st_chooser_context *chooser_context); 76 | 77 | /** NULL chooser which do not chose anything. 78 | * @param chooser_context Instruction chooser context. 79 | */ 80 | fcml_ptr LIB_EXPORT LIB_CALL fcml_fn_asm_no_instruction_chooser( 81 | fcml_st_chooser_context *chooser_context); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* FCML_CHOOSER_H_ */ 88 | -------------------------------------------------------------------------------- /src/fcml_hints.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #include "fcml_hints.h" 21 | 22 | fcml_st_hts_calculated_hints fcml_fn_hts_ihc_far_pointer( 23 | const fcml_st_def_addr_mode_desc *addr_mode, 24 | fcml_st_def_decoded_addr_mode *decoded_addr_mode) { 25 | fcml_st_hts_calculated_hints hints; 26 | hints.instruction_hints = FCML_HINT_FAR_POINTER; 27 | hints.operand_hints = 0; 28 | return hints; 29 | } 30 | 31 | fcml_st_hts_calculated_hints fcml_fn_hts_ihc_modrm_hints( 32 | const fcml_st_def_addr_mode_desc *addr_mode, 33 | fcml_st_def_decoded_addr_mode *decoded_addr_mode) { 34 | fcml_st_hts_calculated_hints hints = { 0 }; 35 | fcml_st_def_tma_rm *rm_args = 36 | (fcml_st_def_tma_rm*) decoded_addr_mode->addr_mode_args; 37 | if (rm_args->flags & FCML_RMF_M) { 38 | hints.operand_hints = 0; 39 | /* VSIB addressing mode is available for multimedia instructions only. */ 40 | if (rm_args->reg_type == FCML_REG_SIMD || rm_args->is_vsib) { 41 | /* SIMD media instruction. */ 42 | hints.operand_hints |= FCML_OP_HINT_MULTIMEDIA_INSTRUCTION; 43 | } 44 | if ( FCML_GET_OS( rm_args->encoded_memory_operand_size ) == FCML_EOS_FP) { 45 | /* Far pointer. */ 46 | hints.instruction_hints |= FCML_HINT_FAR_POINTER; 47 | } else if ( FCML_GET_OS( 48 | rm_args->encoded_memory_operand_size) != FCML_EOS_FPI) { 49 | /* If not far, then near :) */ 50 | hints.instruction_hints |= FCML_HINT_NEAR_POINTER; 51 | } 52 | if (rm_args->flags & FCML_RMF_I) { 53 | hints.instruction_hints |= FCML_HINT_INDIRECT_POINTER; 54 | } 55 | /* Every ModR/M encoded operand supports SIB hint. */ 56 | hints.operand_hints |= FCML_OP_HINT_SIB_ENCODING; 57 | } else { 58 | hints.operand_hints = 0; 59 | } 60 | return hints; 61 | } 62 | 63 | fcml_st_hts_calculated_hints fcml_fn_hts_ihc_immediate_dis_relative( 64 | const fcml_st_def_addr_mode_desc *addr_mode, 65 | fcml_st_def_decoded_addr_mode *decoded_addr_mode) { 66 | fcml_st_hts_calculated_hints hints; 67 | hints.instruction_hints = 0; 68 | hints.operand_hints = FCML_OP_HINT_DISPLACEMENT_RELATIVE_ADDRESS; 69 | return hints; 70 | } 71 | 72 | fcml_st_hts_calculated_hints fcml_fn_hts_ihc_pseudo_opcode( 73 | const fcml_st_def_addr_mode_desc *addr_mode, 74 | fcml_st_def_decoded_addr_mode *decoded_addr_mode) { 75 | fcml_st_hts_calculated_hints hints; 76 | hints.instruction_hints = 0; 77 | hints.operand_hints = FCML_OP_HINT_PSEUDO_OPCODE; 78 | return hints; 79 | } 80 | -------------------------------------------------------------------------------- /include/fcml_dialect.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * FCML - Free Code Manipulation Library. 3 | * Copyright (C) 2010-2020 Slawomir Wojtasiak 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /** @file fcml_dialect.hpp 21 | * C++ wrapper for the base dialect. 22 | * 23 | * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved. 24 | * This project is released under the GNU Lesser General Public License. 25 | */ 26 | 27 | #ifndef FCML_DIALECT_HPP_ 28 | #define FCML_DIALECT_HPP_ 29 | 30 | #include "fcml_common.hpp" 31 | 32 | #include "fcml_dialect.h" 33 | 34 | namespace fcml { 35 | 36 | /** 37 | * An abstract dialect. It's a base class for all supported dialects. 38 | * @since 1.1.0 39 | * @remarks This class is thread-safe. 40 | */ 41 | class Dialect: public NonCopyable { 42 | protected: 43 | 44 | /** 45 | * Default constructor. 46 | * @since 1.1.0 47 | */ 48 | Dialect() { 49 | _dialect = NULL; 50 | } 51 | 52 | /** 53 | * Virtual destructor. 54 | * @since 1.1.0 55 | */ 56 | virtual ~Dialect() { 57 | if (_dialect) { 58 | ::fcml_fn_dialect_free(_dialect); 59 | _dialect = NULL; 60 | } 61 | } 62 | 63 | protected: 64 | 65 | friend class DialectAware; 66 | 67 | /** 68 | * Gets the wrapped FCML dialect. 69 | * 70 | * @return The wrapped FCML dialect. 71 | * @since 1.1.0 72 | */ 73 | fcml_st_dialect* getDialect() const { 74 | return _dialect; 75 | } 76 | 77 | /** 78 | * Sets a new dialect for the wrapper. 79 | * 80 | * @param dialect The new dialect for the wrapper. 81 | * @since 1.1.0 82 | */ 83 | void setDialect(fcml_st_dialect *dialect) { 84 | this->_dialect = dialect; 85 | } 86 | 87 | private: 88 | 89 | /** Wrapped dialect */ 90 | fcml_st_dialect *_dialect; 91 | 92 | }; 93 | 94 | /** Inherit from this class in order to get access to the native FCML 95 | * dialect structure. 96 | * @since 1.1.0 97 | */ 98 | class DialectAware { 99 | public: 100 | 101 | /** 102 | * Default constructor. 103 | * @since 1.1.0 104 | */ 105 | DialectAware() { 106 | } 107 | 108 | /** 109 | * Virtual destructor. 110 | * @since 1.1.0 111 | */ 112 | virtual ~DialectAware() { 113 | } 114 | 115 | /** 116 | * Extracts the native FCML dialect from the dialect object. 117 | * 118 | * @param dialect The wrapper. 119 | * @return The wrapped FCML dialect. 120 | * @since 1.1.0 121 | */ 122 | fcml_st_dialect* extractDialect(const Dialect &dialect) const { 123 | return dialect.getDialect(); 124 | } 125 | }; 126 | 127 | } 128 | 129 | #endif /* FCML_DIALECT_HPP_ */ 130 | --------------------------------------------------------------------------------