├── .gitignore ├── CMakeLists.txt ├── IDA83_SDK ├── include │ ├── allins.hpp │ ├── allow_deprecated.hpp │ ├── auto.hpp │ ├── bitrange.hpp │ ├── bytes.hpp │ ├── compress.hpp │ ├── config.hpp │ ├── cvt64.hpp │ ├── dbg.hpp │ ├── demangle.hpp │ ├── dirtree.hpp │ ├── diskio.hpp │ ├── entry.hpp │ ├── enum.hpp │ ├── err.h │ ├── exehdr.h │ ├── expr.hpp │ ├── fixup.hpp │ ├── fpro.h │ ├── frame.hpp │ ├── funcs.hpp │ ├── gdl.hpp │ ├── graph.hpp │ ├── help.h │ ├── hexrays.hpp │ ├── ida.hpp │ ├── ida_highlighter.hpp │ ├── idacfg.hpp │ ├── idd.hpp │ ├── idp.hpp │ ├── ieee.h │ ├── intel.hpp │ ├── jumptable.hpp │ ├── kernwin.hpp │ ├── lex.hpp │ ├── lines.hpp │ ├── llong.hpp │ ├── loader.hpp │ ├── md5.h │ ├── moves.hpp │ ├── nalt.hpp │ ├── name.hpp │ ├── netnode.hpp │ ├── network.hpp │ ├── offset.hpp │ ├── parsejson.hpp │ ├── pro.h │ ├── problems.hpp │ ├── prodir.h │ ├── pronet.h │ ├── range.hpp │ ├── regex.h │ ├── registry.hpp │ ├── search.hpp │ ├── segment.hpp │ ├── segregs.hpp │ ├── srclang.hpp │ ├── strlist.hpp │ ├── struct.hpp │ ├── tryblks.hpp │ ├── typeinf.hpp │ ├── ua.hpp │ ├── workarounds.hpp │ └── xref.hpp └── lib │ ├── x64_win_vc_32_pro │ ├── ida.lib │ └── network.lib │ └── x64_win_vc_64_pro │ ├── ida.lib │ └── network.lib ├── README.md ├── cmake.toml ├── cmkr.cmake ├── graph.png ├── include └── cereal │ ├── access.hpp │ ├── archives │ ├── adapters.hpp │ ├── binary.hpp │ ├── json.hpp │ ├── portable_binary.hpp │ └── xml.hpp │ ├── cereal.hpp │ ├── details │ ├── helpers.hpp │ ├── polymorphic_impl.hpp │ ├── polymorphic_impl_fwd.hpp │ ├── static_object.hpp │ ├── traits.hpp │ └── util.hpp │ ├── external │ ├── LICENSE │ ├── base64.hpp │ ├── rapidjson │ │ ├── LICENSE │ │ ├── allocators.h │ │ ├── cursorstreamwrapper.h │ │ ├── document.h │ │ ├── encodedstream.h │ │ ├── encodings.h │ │ ├── error │ │ │ ├── en.h │ │ │ └── error.h │ │ ├── filereadstream.h │ │ ├── filewritestream.h │ │ ├── fwd.h │ │ ├── internal │ │ │ ├── biginteger.h │ │ │ ├── diyfp.h │ │ │ ├── dtoa.h │ │ │ ├── ieee754.h │ │ │ ├── itoa.h │ │ │ ├── meta.h │ │ │ ├── pow10.h │ │ │ ├── regex.h │ │ │ ├── stack.h │ │ │ ├── strfunc.h │ │ │ ├── strtod.h │ │ │ └── swap.h │ │ ├── istreamwrapper.h │ │ ├── memorybuffer.h │ │ ├── memorystream.h │ │ ├── msinttypes │ │ │ ├── LICENSE │ │ │ ├── inttypes.h │ │ │ └── stdint.h │ │ ├── ostreamwrapper.h │ │ ├── pointer.h │ │ ├── prettywriter.h │ │ ├── rapidjson.h │ │ ├── reader.h │ │ ├── schema.h │ │ ├── stream.h │ │ ├── stringbuffer.h │ │ └── writer.h │ └── rapidxml │ │ ├── license.txt │ │ ├── manual.html │ │ ├── rapidxml.hpp │ │ ├── rapidxml_iterators.hpp │ │ ├── rapidxml_print.hpp │ │ └── rapidxml_utils.hpp │ ├── macros.hpp │ ├── specialize.hpp │ ├── types │ ├── array.hpp │ ├── atomic.hpp │ ├── base_class.hpp │ ├── bitset.hpp │ ├── boost_variant.hpp │ ├── chrono.hpp │ ├── common.hpp │ ├── complex.hpp │ ├── concepts │ │ └── pair_associative_container.hpp │ ├── deque.hpp │ ├── forward_list.hpp │ ├── functional.hpp │ ├── list.hpp │ ├── map.hpp │ ├── memory.hpp │ ├── optional.hpp │ ├── polymorphic.hpp │ ├── queue.hpp │ ├── set.hpp │ ├── stack.hpp │ ├── string.hpp │ ├── tuple.hpp │ ├── unordered_map.hpp │ ├── unordered_set.hpp │ ├── utility.hpp │ ├── valarray.hpp │ ├── variant.hpp │ └── vector.hpp │ └── version.hpp ├── sponsor.png ├── src ├── Common │ ├── Public.cpp │ ├── Public.h │ ├── StringUtils.cpp │ ├── StringUtils.h │ ├── VmpCommon.cpp │ └── VmpCommon.h ├── Ghidra │ ├── .gitignore │ ├── Doxyfile │ ├── action.cc │ ├── action.hh │ ├── address.cc │ ├── address.hh │ ├── architecture.cc │ ├── architecture.hh │ ├── block.cc │ ├── block.hh │ ├── blockaction.cc │ ├── blockaction.hh │ ├── callgraph.cc │ ├── callgraph.hh │ ├── capability.cc │ ├── capability.hh │ ├── cast.cc │ ├── cast.hh │ ├── comment.cc │ ├── comment.hh │ ├── comment_ghidra.cc │ ├── comment_ghidra.hh │ ├── condexe.cc │ ├── condexe.hh │ ├── context.cc │ ├── context.hh │ ├── coreaction.cc │ ├── coreaction.hh │ ├── cover.cc │ ├── cover.hh │ ├── cpool.cc │ ├── cpool.hh │ ├── cpool_ghidra.cc │ ├── cpool_ghidra.hh │ ├── crc32.cc │ ├── crc32.hh │ ├── database.cc │ ├── database.hh │ ├── database_ghidra.cc │ ├── database_ghidra.hh │ ├── doccore.hh │ ├── docmain.hh │ ├── double.cc │ ├── double.hh │ ├── dynamic.cc │ ├── dynamic.hh │ ├── emulate.cc │ ├── emulate.hh │ ├── emulateutil.cc │ ├── emulateutil.hh │ ├── error.hh │ ├── filemanage.cc │ ├── filemanage.hh │ ├── float.cc │ ├── float.hh │ ├── flow.cc │ ├── flow.hh │ ├── fspec.cc │ ├── fspec.hh │ ├── funcdata.cc │ ├── funcdata.hh │ ├── funcdata_block.cc │ ├── funcdata_op.cc │ ├── funcdata_varnode.cc │ ├── ghidra_arch.cc │ ├── ghidra_arch.hh │ ├── ghidra_context.cc │ ├── ghidra_context.hh │ ├── ghidra_translate.cc │ ├── ghidra_translate.hh │ ├── globalcontext.cc │ ├── globalcontext.hh │ ├── grammar.cc │ ├── grammar.hh │ ├── grammar.y │ ├── graph.cc │ ├── graph.hh │ ├── heritage.cc │ ├── heritage.hh │ ├── inject_ghidra.cc │ ├── inject_ghidra.hh │ ├── inject_sleigh.cc │ ├── inject_sleigh.hh │ ├── interface.cc │ ├── interface.hh │ ├── jumptable.cc │ ├── jumptable.hh │ ├── libdecomp.cc │ ├── libdecomp.hh │ ├── loadimage.cc │ ├── loadimage.hh │ ├── loadimage_ghidra.cc │ ├── loadimage_ghidra.hh │ ├── loadimage_xml.cc │ ├── loadimage_xml.hh │ ├── marshal.cc │ ├── marshal.hh │ ├── memstate.cc │ ├── memstate.hh │ ├── merge.cc │ ├── merge.hh │ ├── modelrules.cc │ ├── modelrules.hh │ ├── op.cc │ ├── op.hh │ ├── opbehavior.cc │ ├── opbehavior.hh │ ├── opcodes.cc │ ├── opcodes.hh │ ├── options.cc │ ├── options.hh │ ├── override.cc │ ├── override.hh │ ├── paramid.cc │ ├── paramid.hh │ ├── partmap.hh │ ├── pcodecompile.cc │ ├── pcodecompile.hh │ ├── pcodeinject.cc │ ├── pcodeinject.hh │ ├── pcodeparse.cc │ ├── pcodeparse.hh │ ├── pcodeparse.y │ ├── pcoderaw.cc │ ├── pcoderaw.hh │ ├── prefersplit.cc │ ├── prefersplit.hh │ ├── prettyprint.cc │ ├── prettyprint.hh │ ├── printc.cc │ ├── printc.hh │ ├── printjava.cc │ ├── printjava.hh │ ├── printlanguage.cc │ ├── printlanguage.hh │ ├── rangemap.hh │ ├── rangeutil.cc │ ├── rangeutil.hh │ ├── raw_arch.cc │ ├── raw_arch.hh │ ├── ruleaction.cc │ ├── ruleaction.hh │ ├── rulecompile.cc │ ├── rulecompile.hh │ ├── ruleparse.y │ ├── semantics.cc │ ├── semantics.hh │ ├── signature.cc │ ├── signature.hh │ ├── sleigh.cc │ ├── sleigh.hh │ ├── sleigh_arch.cc │ ├── sleigh_arch.hh │ ├── sleighbase.cc │ ├── sleighbase.hh │ ├── slghparse.y │ ├── slghpatexpress.cc │ ├── slghpatexpress.hh │ ├── slghpattern.cc │ ├── slghpattern.hh │ ├── slghscan.l │ ├── slghsymbol.cc │ ├── slghsymbol.hh │ ├── space.cc │ ├── space.hh │ ├── string_ghidra.cc │ ├── string_ghidra.hh │ ├── stringmanage.cc │ ├── stringmanage.hh │ ├── subflow.cc │ ├── subflow.hh │ ├── transform.cc │ ├── transform.hh │ ├── translate.cc │ ├── translate.hh │ ├── type.cc │ ├── type.hh │ ├── typegrp_ghidra.cc │ ├── typegrp_ghidra.hh │ ├── typeop.cc │ ├── typeop.hh │ ├── types.h │ ├── unify.cc │ ├── unify.hh │ ├── unionresolve.cc │ ├── unionresolve.hh │ ├── userop.cc │ ├── userop.hh │ ├── variable.cc │ ├── variable.hh │ ├── varmap.cc │ ├── varmap.hh │ ├── varnode.cc │ ├── varnode.hh │ ├── xml.cc │ ├── xml.hh │ ├── xml.y │ ├── xml_arch.cc │ └── xml_arch.hh ├── GhidraExtension │ ├── FuncBuildHelper.cpp │ ├── FuncBuildHelper.h │ ├── IDALoadImage.cpp │ ├── IDALoadImage.h │ ├── PrintManager.cpp │ ├── PrintManager.h │ ├── VmpAction.cpp │ ├── VmpAction.h │ ├── VmpArch.cpp │ ├── VmpArch.h │ ├── VmpControlFlow.cpp │ ├── VmpControlFlow.h │ ├── VmpFunction.cpp │ ├── VmpFunction.h │ ├── VmpInstruction.cpp │ ├── VmpInstruction.h │ ├── VmpInstructionAsm.cpp │ ├── VmpInstructionBuilder.cpp │ ├── VmpInstructionMake.cpp │ ├── VmpNode.cpp │ ├── VmpNode.h │ ├── VmpRule.cpp │ └── VmpRule.h ├── Helper │ ├── AsmBuilder.cpp │ ├── AsmBuilder.h │ ├── GhidraHelper.cpp │ ├── GhidraHelper.h │ ├── IDAWrapper.cpp │ ├── IDAWrapper.h │ ├── UnicornHelper.cpp │ ├── UnicornHelper.h │ ├── VmpBlockAnalyzer.cpp │ └── VmpBlockAnalyzer.h ├── IDAPlugin.cpp ├── IDAPlugin.h ├── Manager │ ├── DisasmManager.cpp │ ├── DisasmManager.h │ ├── SectionManager.cpp │ ├── SectionManager.h │ ├── VmpVersionManager.cpp │ ├── VmpVersionManager.h │ ├── exceptions.cpp │ └── exceptions.h ├── VmpCore │ ├── VmpBlockBuilder.cpp │ ├── VmpBlockBuilder.h │ ├── VmpReEngine.cpp │ ├── VmpReEngine.h │ ├── VmpTraceFlowGraph.cpp │ ├── VmpTraceFlowGraph.h │ ├── VmpUnicorn.cpp │ └── VmpUnicorn.h └── main.cpp └── vcpkg.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | build/ -------------------------------------------------------------------------------- /IDA83_SDK/include/allow_deprecated.hpp: -------------------------------------------------------------------------------- 1 | // this file should be included before calling deprecated functions 2 | // it should be included at the point where the definitions of deprecated 3 | // functions begin in the source file. this way a deprecated function may call 4 | // another deprecated function without raising a warning. 5 | 6 | // deprecated functions may call each other 7 | #ifdef _MSC_VER 8 | #pragma warning(disable:4996) 9 | #endif 10 | #ifdef __GNUC__ 11 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 12 | #endif 13 | -------------------------------------------------------------------------------- /IDA83_SDK/include/err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Interactive disassembler (IDA). 3 | * Copyright (c) 1990-2023 Hex-Rays 4 | * ALL RIGHTS RESERVED. 5 | * 6 | */ 7 | 8 | #ifndef _ERR_H 9 | #define _ERR_H 10 | 11 | #include 12 | 13 | /*! \file err.h 14 | 15 | \brief Thread safe functions that deal with error codes 16 | 17 | */ 18 | 19 | /// Print error message to stderr (analog of perror) 20 | 21 | idaman THREAD_SAFE AS_PRINTF(1, 0) void ida_export vqperror(const char *format, va_list va); 22 | 23 | 24 | /// Get error description string. 25 | /// if _qerrno=-1, get_qerrno() will be used 26 | 27 | idaman THREAD_SAFE const char *ida_export qstrerror(error_t _qerrno); 28 | 29 | 30 | /// A convenience function to generate error messages (returns "header: error message") 31 | 32 | idaman THREAD_SAFE char *ida_export get_errdesc(const char *header, error_t _qerrno=-1); 33 | 34 | 35 | /// Get error message for MS Windows error codes 36 | /// \param code errno or GetLastError() depending on the system. 37 | 38 | idaman THREAD_SAFE char *ida_export winerr(int code); 39 | 40 | 41 | /// Get error string. 42 | /// if errno_code == -1, then errno will be used. 43 | 44 | idaman const char *ida_export qerrstr(int errno_code=-1); 45 | 46 | 47 | #ifdef __cplusplus 48 | 49 | /// See vqperror() 50 | 51 | THREAD_SAFE AS_PRINTF(1, 2) inline void qperror(const char *format, ...) 52 | { 53 | va_list va; 54 | va_start(va, format); 55 | vqperror(format, va); 56 | va_end(va); 57 | } 58 | 59 | 60 | /// See set_qerrno() 61 | 62 | THREAD_SAFE inline void set_errno(int code) 63 | { 64 | errno = code; 65 | set_qerrno(eOS); 66 | } 67 | #endif 68 | 69 | // Internal functions 70 | /// \cond 71 | 72 | // n=0..3 73 | idaman THREAD_SAFE void ida_export set_error_data(int n, size_t data); 74 | idaman THREAD_SAFE void ida_export set_error_string(int n, const char *str); 75 | idaman THREAD_SAFE size_t ida_export get_error_data(int n); 76 | idaman THREAD_SAFE const char *ida_export get_error_string(int n); 77 | 78 | #define QPRM_TYPE(t,n,x) set_error_data(n-1, t(x)) 79 | #define QPRM_CHAR(n,x) QPRM_TYPE(char,n,x) 80 | #define QPRM_SHORT(n,x) QPRM_TYPE(short,n,x) 81 | #define QPRM_INT(n,x) QPRM_TYPE(int,n,x) 82 | #define QPRM_INT32(n,x) QPRM_TYPE(int32,n,x) 83 | #define QPRM_UCHAR(n,x) QPRM_TYPE(uchar,n,x) 84 | #define QPRM_USHORT(n,x) QPRM_TYPE(ushort,n,x) 85 | #define QPRM_UINT(n,x) QPRM_TYPE(uint,n,x) 86 | #define QPRM_UINT32(n,x) QPRM_TYPE(uint32,n,x) 87 | #define QPRM(n,x) set_error_string(n-1, x) 88 | 89 | /// \endcond 90 | 91 | #ifndef NO_OBSOLETE_FUNCS 92 | 93 | /// Get errno and optionally set its new value. 94 | /// \param new_code if not -1, specifies the new value. The old value will be returned. 95 | 96 | idaman DEPRECATED THREAD_SAFE int ida_export qerrcode(int new_code=-1); 97 | 98 | #endif 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /IDA83_SDK/include/exehdr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Interactive disassembler (IDA). 3 | * Copyright (c) 1990-2023 Hex-Rays 4 | * ALL RIGHTS RESERVED. 5 | * 6 | * EXE-file header layout 7 | * 8 | */ 9 | 10 | #ifndef __EXEHDR_H 11 | #define __EXEHDR_H 12 | #pragma pack(push, 1) 13 | 14 | struct exehdr 15 | { 16 | uint16 exe_ident; 17 | #define EXE_ID 0x5A4D // 'MZ' 18 | #define EXE_ID2 0x4D5A // 'ZM' (DOS works with this also) 19 | uint16 PartPag; 20 | uint16 PageCnt; 21 | uint16 ReloCnt; 22 | uint16 HdrSize; 23 | uint16 MinMem; 24 | uint16 MaxMem; 25 | uint16 ReloSS; 26 | uint16 ExeSP; 27 | uint16 ChkSum; 28 | uint16 ExeIP; 29 | uint16 ReloCS; 30 | uint16 TablOff; 31 | uint16 Overlay; 32 | /* 33 | uint16 res[4]; // Reserved words 34 | uint16 oemid; // OEM identifier (for e_oeminfo) 35 | uint16 oeminfo; // OEM information; e_oemid specific 36 | uint16 res2[10]; // Reserved words 37 | uint32 lfanew; // File address of new exe header 38 | */ 39 | int32 CalcEXE_Length(void) 40 | { 41 | int32 len = PageCnt * 512L - HdrSize * 16; 42 | if ( PartPag != 0 ) 43 | len -= 512 - PartPag; 44 | return len; 45 | } 46 | void CalcEXE_Pages(int32 len) 47 | { 48 | PartPag = uint16(len % 512); 49 | PageCnt = uint16(len / 512); 50 | if ( PartPag != 0 ) 51 | PageCnt++; 52 | } 53 | }; 54 | 55 | struct exehdr_full: exehdr 56 | { 57 | uint16 res[4]; // Reserved words 58 | uint16 oemid; // OEM identifier (for e_oeminfo) 59 | uint16 oeminfo; // OEM information; e_oemid specific 60 | uint16 res2[10]; // Reserved words 61 | uint32 lfanew; // File address of new exe header 62 | }; 63 | 64 | #define PSPsize 0x100 65 | #define PE_PTROFF 0x3C 66 | #pragma pack(pop) 67 | #endif 68 | -------------------------------------------------------------------------------- /IDA83_SDK/include/help.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Interactive disassembler (IDA). 3 | * Copyright (c) 1990-2023 Hex-Rays 4 | * ALL RIGHTS RESERVED. 5 | * 6 | */ 7 | 8 | #ifndef _HELP_H 9 | #define _HELP_H 10 | 11 | typedef int help_t; /* Help messages are referred by ints */ 12 | 13 | // Get pointer to message text by its message id 14 | // The message texts are read from ida.hlp at the beginning 15 | // Returns: pointer to message text (nullptr is never returned by IDA) 16 | 17 | idaman THREAD_SAFE const char *ida_export itext(help_t msg_id); 18 | 19 | #ifdef __KERNWIN_HPP 20 | GCC_DIAG_OFF(format-nonliteral); 21 | NORETURN inline void Err(help_t format, ...) 22 | { 23 | va_list va; 24 | va_start(va, format); 25 | verror(itext(format), va); 26 | // NOTREACHED 27 | } 28 | 29 | inline void Warn(help_t format, ...) 30 | { 31 | va_list va; 32 | va_start(va, format); 33 | vwarning(itext(format), va); 34 | va_end(va); 35 | } 36 | 37 | inline void Info(help_t format, ...) 38 | { 39 | va_list va; 40 | va_start(va, format); 41 | vinfo(itext(format), va); 42 | va_end(va); 43 | } 44 | 45 | inline int Message(help_t format, ...) 46 | { 47 | va_list va; 48 | va_start(va, format); 49 | int nbytes = vmsg(itext(format), va); 50 | va_end(va); 51 | return nbytes; 52 | } 53 | 54 | inline int vask_yn(int deflt, help_t format, va_list va) 55 | { 56 | return vask_yn(deflt, itext(format), va); 57 | } 58 | 59 | inline int ask_yn(int deflt, help_t format, ...) 60 | { 61 | va_list va; 62 | va_start(va, format); 63 | int code = vask_yn(deflt, itext(format), va); 64 | va_end(va); 65 | return code; 66 | } 67 | GCC_DIAG_ON(format-nonliteral); 68 | #endif 69 | 70 | #ifndef NO_OBSOLETE_FUNCS 71 | #endif 72 | 73 | #endif /* _HELP_H */ 74 | -------------------------------------------------------------------------------- /IDA83_SDK/include/idacfg.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Interactive disassembler (IDA). 3 | * Copyright (c) 1990-2023 Hex-Rays 4 | * ALL RIGHTS RESERVED. 5 | * 6 | */ 7 | 8 | #ifndef IDACFG_HPP 9 | #define IDACFG_HPP 10 | 11 | /// Get one of config parameters defined by CC_PARMS in ida.cfg. 12 | /// All parameters for all compilers are stored in local map during last read 13 | /// of ida.cfg - this function just returns previously stored parameter value for 14 | /// given compiler (nullptr if no such parameter) 15 | idaman const char *ida_export cfg_get_cc_parm(comp_t compid, const char *name); 16 | 17 | 18 | /// Get header path config parameter from ida.cfg. 19 | /// Also see cfg_get_cc_parm() 20 | 21 | inline const char *cfg_get_cc_header_path(comp_t compid) 22 | { 23 | return cfg_get_cc_parm(compid, "HEADER_PATH"); 24 | } 25 | 26 | 27 | /// Get predefined macros config parameter from ida.cfg. 28 | /// Also see cfg_get_cc_parm() 29 | 30 | inline const char *cfg_get_cc_predefined_macros(comp_t compid) 31 | { 32 | return cfg_get_cc_parm(compid, "PREDEFINED_MACROS"); 33 | } 34 | 35 | /// Process one or more config directive(s). 36 | /// \param directive the directives to process 37 | /// \param priority priority \ref IDPOPT_RET 38 | /// In the case of errors this function displays a message and exits. 39 | 40 | idaman void ida_export process_config_directive( 41 | const char *directive, 42 | int priority=IDPOPT_PRI_HIGH); 43 | 44 | 45 | #endif // IDACFG_HPP 46 | -------------------------------------------------------------------------------- /IDA83_SDK/include/md5.h: -------------------------------------------------------------------------------- 1 | #ifndef MD5_H 2 | #define MD5_H 3 | 4 | struct MD5Context 5 | { 6 | uint32 buf[4]; 7 | uint32 bits[2]; 8 | unsigned char in[64]; 9 | 10 | MD5Context() { memset(this, 0, sizeof(*this)); } 11 | }; 12 | 13 | idaman THREAD_SAFE void ida_export MD5Init(MD5Context *context); 14 | idaman THREAD_SAFE void ida_export MD5Update(MD5Context *context, const void *buf, size_t len); 15 | idaman THREAD_SAFE void ida_export MD5Final(uchar digest[16], MD5Context *context); 16 | idaman THREAD_SAFE void ida_export MD5Transform(uint32 buf[4], uint32 const in[16]); 17 | 18 | //--------------------------------------------------------------------------- 19 | struct md5_t 20 | { 21 | uchar hash[16]; 22 | 23 | md5_t() { clear(); } 24 | md5_t(const md5_t &r) { assign(r); } 25 | 26 | const uchar &operator[](size_t i) const { return hash[i]; } 27 | uchar &operator[](size_t i) { return hash[i]; } 28 | 29 | void clear() { memset(hash, 0, sizeof(hash)); } 30 | void swap(md5_t &other) { std::swap(*this, other); } 31 | 32 | md5_t &operator=(const md5_t &r) 33 | { 34 | if ( this != &r ) 35 | assign(r); 36 | return *this; 37 | } 38 | 39 | DECLARE_COMPARISONS(md5_t) 40 | { 41 | return memcmp(hash, r.hash, sizeof(hash)); 42 | } 43 | 44 | 45 | protected: 46 | void assign(const md5_t &r) { memmove(hash, r.hash, sizeof(hash)); } 47 | }; 48 | DECLARE_TYPE_AS_MOVABLE(md5_t); 49 | typedef qvector md5_vec_t; 50 | 51 | #endif /* !MD5_H */ 52 | -------------------------------------------------------------------------------- /IDA83_SDK/include/srclang.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SRCLANG_H 2 | #define SRCLANG_H 3 | 4 | #include 5 | 6 | /*! \file srclang.hpp 7 | 8 | \brief Third-party compiler support 9 | */ 10 | 11 | /// \defgroup SRCLANG_ Source language IDs 12 | //@{ 13 | #define SRCLANG_C 0x01 ///< C 14 | #define SRCLANG_CPP 0x02 ///< C++ 15 | #define SRCLANG_OBJC 0x04 ///< Objective-C 16 | #define SRCLANG_SWIFT 0x08 ///< Swift (not supported yet) 17 | #define SRCLANG_GO 0x10 ///< Golang (not supported yet) 18 | //@} 19 | 20 | /// Bitmask that describes all source languages supported by a compiler. Combination of \ref SRCLANG_ values 21 | typedef int srclang_t; 22 | 23 | 24 | /// Set the parser with the given name as the current parser. 25 | /// Pass nullptr or an empty string to select the default parser. 26 | /// \return false if no parser was found with the given name 27 | 28 | idaman bool ida_export select_parser_by_name(const char *name); 29 | 30 | 31 | /// Set the parser that supports the given language(s) as the current parser. 32 | /// The selected parser must support all languages specified by the given ::srclang_t. 33 | /// \return false if no such parser was found 34 | 35 | idaman bool ida_export select_parser_by_srclang(srclang_t lang); 36 | 37 | 38 | /// Set the command-line args to use for invocations of the parser with the given name 39 | /// \param parser_name name of the target parser 40 | /// \param argv argument list 41 | /// \retval -1 no parser was found with the given name 42 | /// \retval -2 the operation is not supported by the given parser 43 | /// \retval 0 success 44 | 45 | idaman int ida_export set_parser_argv(const char *parser_name, const char *argv); 46 | 47 | 48 | /// Parse type declarations in the specified language 49 | /// \param lang the source language(s) expected in the input 50 | /// \param til type library to store the types 51 | /// \param input input source. can be a file path or decl string 52 | /// \param is_path true if input parameter is a path to a source file, false if the input is an in-memory source snippet 53 | /// \retval -1 no parser was found that supports the given source language(s) 54 | /// \retval else the number of errors encountered in the input source 55 | 56 | idaman int ida_export parse_decls_for_srclang( 57 | srclang_t lang, 58 | til_t *til, 59 | const char *input, 60 | bool is_path); 61 | 62 | 63 | /// Parse type declarations using the parser with the specified name 64 | /// \param parser_name name of the target parser 65 | /// \param til type library to store the types 66 | /// \param input input source. can be a file path or decl string 67 | /// \param is_path true if input parameter is a path to a source file, false if the input is an in-memory source snippet 68 | /// \retval -1 no parser was found with the given name 69 | /// \retval else the number of errors encountered in the input source 70 | 71 | idaman int ida_export parse_decls_with_parser( 72 | const char *parser_name, 73 | til_t *til, 74 | const char *input, 75 | bool is_path); 76 | 77 | 78 | 79 | #endif // !SRCLANG_H 80 | -------------------------------------------------------------------------------- /IDA83_SDK/include/strlist.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * The Interactive Disassembler (IDA). 3 | * Copyright (c) 1990-2023 Hex-Rays 4 | * ALL RIGHTS RESERVED. 5 | * 6 | */ 7 | 8 | #ifndef _STRLIST_HPP 9 | #define _STRLIST_HPP 10 | 11 | /*! \file strlist.hpp 12 | 13 | \brief Functions that deal with the string list 14 | 15 | While the kernel keeps the string list, it does not update it. 16 | The string list is not used by the kernel because 17 | keeping it up-to-date would slow down IDA without any benefit. 18 | If the string list is not cleared using clear_strlist(), the list will be 19 | saved to the database and restored on the next startup. 20 | 21 | The users of this list should call build_strlist() if they need an 22 | up-to-date version. 23 | */ 24 | 25 | /// Structure to keep string list parameters 26 | struct strwinsetup_t 27 | { 28 | bytevec_t strtypes; // set of allowed string types 29 | sval_t minlen = -1; 30 | uchar display_only_existing_strings = 0; 31 | uchar only_7bit = 1; 32 | uchar ignore_heads = 0; 33 | }; 34 | 35 | /// Information about one string from the string list 36 | struct string_info_t 37 | { 38 | ea_t ea; 39 | int length = 0; // in octets 40 | int type = 0; 41 | string_info_t(ea_t _ea=BADADDR) : ea(_ea) {} 42 | bool operator<(const string_info_t &r) const { return ea < r.ea; } 43 | }; 44 | DECLARE_TYPE_AS_MOVABLE(string_info_t); 45 | 46 | 47 | /// Get the static string list options 48 | 49 | idaman const strwinsetup_t *ida_export get_strlist_options(); 50 | 51 | 52 | /// Rebuild the string list. 53 | 54 | idaman void ida_export build_strlist(); 55 | 56 | 57 | /// Clear the string list. 58 | 59 | idaman void ida_export clear_strlist(); 60 | 61 | 62 | /// Get number of elements in the string list. 63 | /// The list will be loaded from the database (if saved) or 64 | /// built from scratch. 65 | 66 | idaman size_t ida_export get_strlist_qty(void); 67 | 68 | 69 | /// Get nth element of the string list (n=0..get_strlist_qty()-1) 70 | 71 | idaman bool ida_export get_strlist_item(string_info_t *si, size_t n); 72 | 73 | 74 | #endif // _STRLIST_HPP 75 | -------------------------------------------------------------------------------- /IDA83_SDK/include/workarounds.hpp: -------------------------------------------------------------------------------- 1 | // various workarounds/fixes for different compilers 2 | 3 | #ifndef _IDA_WORKAROUNDS_H 4 | #define _IDA_WORKAROUNDS_H 5 | 6 | // MS Visual C++: 7 | // this file should be included once in module (exe or dll) where std::stable_sort() is used 8 | #ifdef _MSC_VER 9 | #if (_MSC_VER < 1700) // before VS2012 10 | // the following fixes unneeded exports caused by use 11 | // of std::stable_sort, which uses new(std::nothrow) 12 | // reference: http://social.msdn.microsoft.com/Forums/vstudio/en-US/4692205a-0296-4f41-adbb-fa8339597f5c/unwanted-exports 13 | 14 | namespace std { extern const __declspec(selectany) nothrow_t nothrow = nothrow_t(); } 15 | 16 | // explanation by Javier Blazquez: 17 | 18 | /* 19 | The reason why this eliminates the _Init_locks export is because the linker 20 | no longer has to go find and use the nothrow.obj file (part of msvcprt.lib) 21 | during linking for the definition of std::nothrow, it can just use the 22 | definition you provided. That nothrow.obj file not only contains the 23 | definition of std::nothrow, it also contains a dllexport definition of 24 | std::_Init_locks::operator= (in fact, the only such definition of this 25 | function anywhere in the standard libraries), so preventing the linker from 26 | using the standard nothrow.obj at all has the effect of removing this ugly 27 | export altogether. 28 | */ 29 | #endif // (_MSC_VER < 1700) 30 | #endif // _MSC_VER 31 | 32 | #ifdef __LINUX__ 33 | // suppress dependency on __longjmp_chk 34 | // idea stolen from http://code.google.com/p/webm/issues/detail?id=166 35 | // this file should be included in modules where longjmp is used 36 | #if !defined(__ARM__) && defined(__GNUC_PREREQ) && __GNUC_PREREQ(2,11) 37 | #ifndef __X86__ 38 | __asm__(".symver __longjmp_chk,longjmp@GLIBC_2.2.5"); 39 | #else 40 | __asm__(".symver __longjmp_chk,longjmp@GLIBC_2.0"); 41 | #endif // !__X86__ 42 | #endif // __GNUC_PREREQ 43 | #endif // __LINUX__ 44 | 45 | #endif // _IDA_WORKAROUNDS_H 46 | 47 | -------------------------------------------------------------------------------- /IDA83_SDK/lib/x64_win_vc_32_pro/ida.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/IDA83_SDK/lib/x64_win_vc_32_pro/ida.lib -------------------------------------------------------------------------------- /IDA83_SDK/lib/x64_win_vc_32_pro/network.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/IDA83_SDK/lib/x64_win_vc_32_pro/network.lib -------------------------------------------------------------------------------- /IDA83_SDK/lib/x64_win_vc_64_pro/ida.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/IDA83_SDK/lib/x64_win_vc_64_pro/ida.lib -------------------------------------------------------------------------------- /IDA83_SDK/lib/x64_win_vc_64_pro/network.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/IDA83_SDK/lib/x64_win_vc_64_pro/network.lib -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VmpHelper 2 | 3 | a vmp-analysis ida plugin, currently under development... 4 | 5 | only supports Vmp3.5 x86 6 | 7 | ## How to use 8 | 9 | 1、Place the Ghidra directory and Revampire.dll into the IDA plugin directory 10 | 11 | 2、Use ida to load demo.exe. 12 | 13 | At 00401D7E,right click to pop up menu -> Revampire -> Mark as VmEntry 14 | 15 | 3、At 00401D70,right click to pop up menu -> Revampire -> Execute Vmp 3.5.0. 16 | 17 | Then you may get a flow chart like the following: 18 | 19 | ![graph](graph.png) 20 | 21 | ## Current Target 22 | 23 | 1、Identify all handlers of vmp 24 | 25 | 2、Print out the complete flow chart of vmp 26 | 27 | ## Reference 28 | 29 | ghidra:https://github.com/NationalSecurityAgency/ghidra 30 | 31 | unicorn:https://github.com/unicorn-engine/unicorn 32 | 33 | capstone:https://github.com/capstone-engine/capstone 34 | 35 | keystone:https://github.com/keystone-engine/keystone 36 | 37 | z3:https://github.com/Z3Prover/z3 38 | 39 | cereal:https://github.com/USCiLab/cereal 40 | 41 | 42 | 43 | ## Sponsor this project 44 | 45 | ![赞助](sponsor.png) 46 | 47 | -------------------------------------------------------------------------------- /cmake.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "Revampire" 3 | languages = ["C", "CXX"] 4 | 5 | cmake-after = """ 6 | if (MSVC) 7 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT") 8 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT") 9 | # Statically compile runtime 10 | string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 11 | string(REGEX REPLACE "/MD" "/MT" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") 12 | string(REGEX REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") 13 | string(REGEX REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") 14 | message(NOTICE "Building in MT mode") 15 | endif(MSVC) 16 | """ 17 | 18 | [fetch-content.capstone] 19 | git = "https://github.com/capstone-engine/capstone" 20 | tag = "5.0.1" 21 | 22 | [vcpkg] 23 | version = "2024.03.25" 24 | packages = ["keystone","unicorn","z3"] 25 | 26 | [find-package] 27 | z3 = {} 28 | 29 | [variables] 30 | CMAKE_CXX_COMPILER = "cl" 31 | CMAKE_C_COMPILER = "cl" 32 | 33 | VCPKG_TARGET_TRIPLET = "x64-windows-static" 34 | 35 | CMAKE_CONFIGURATION_TYPES = "Release;RelWithDebInfo" 36 | LLVM_USE_CRT_RELEASE = "MT" 37 | LLVM_USE_CRT_RELWITHDEBINFO = "MT" 38 | 39 | [target.Revampire] 40 | type = "shared" 41 | sources = [ 42 | "src/*.cpp", 43 | "src/Ghidra/*.cc", 44 | "src/GhidraExtension/*.cpp", 45 | "src/Common/*.cpp", 46 | "src/Helper/*.cpp", 47 | "src/Manager/*.cpp", 48 | "src/VmpCore/*.cpp", 49 | ] 50 | 51 | headers = [ 52 | "src/*.h", 53 | "src/Ghidra/*.h", 54 | "src/Ghidra/*.hh", 55 | "src/GhidraExtension/*.h", 56 | "src/Common/*.h", 57 | "src/Helper/*.h", 58 | "src/Manager/*.h", 59 | "src/VmpCore/*.h", 60 | ] 61 | 62 | compile-definitions = ["_WINDOWS","_CRT_SECURE_NO_WARNINGS","USE_STANDARD_FILE_FUNCTIONS"] 63 | include-directories = ["${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/include","IDA83_SDK/include","include"] 64 | link-directories = ["${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/lib","IDA83_SDK/lib/x64_win_vc_32_pro"] 65 | link-libraries = ["capstone::capstone" , "keystone" , "unicorn", "libz3","ida"] 66 | 67 | cmake-after = """ 68 | set_property(TARGET Revampire PROPERTY 69 | MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 70 | """ 71 | 72 | 73 | [options] 74 | CAPSTONE_BPF_SUPPORT = false 75 | CAPSTONE_EVM_SUPPORT = false 76 | CAPSTONE_MIPS_SUPPORT = false 77 | CAPSTONE_BUILD_STATIC_RUNTIME = true 78 | CAPSTONE_M680X_SUPPORT = false 79 | CAPSTONE_M68K_SUPPORT = false 80 | CAPSTONE_MOS65XX_SUPPORT = false 81 | CAPSTONE_PPC_SUPPORT = false 82 | CAPSTONE_RISCV_SUPPORT = false 83 | CAPSTONE_SH_SUPPORT = false 84 | CAPSTONE_SPARC_SUPPORT = false 85 | CAPSTONE_SYSZ_SUPPORT = false 86 | CAPSTONE_TMS320C64X_SUPPORT = false 87 | CAPSTONE_TRICORE_SUPPORT = false 88 | CAPSTONE_WASM_SUPPORT = false 89 | CAPSTONE_XCORE_SUPPORT = false -------------------------------------------------------------------------------- /graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/graph.png -------------------------------------------------------------------------------- /include/cereal/details/polymorphic_impl_fwd.hpp: -------------------------------------------------------------------------------- 1 | /*! \file polymorphic_impl_fwd.hpp 2 | \brief Internal polymorphism support forward declarations 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | /* This code is heavily inspired by the boost serialization implementation by the following authors 32 | 33 | (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 34 | Use, modification and distribution is subject to the Boost Software 35 | License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt) 36 | 37 | See http://www.boost.org for updates, documentation, and revision history. 38 | 39 | (C) Copyright 2006 David Abrahams - http://www.boost.org. 40 | 41 | See /boost/serialization/export.hpp and /boost/archive/detail/register_archive.hpp for their 42 | implementation. 43 | */ 44 | 45 | #ifndef CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 46 | #define CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 47 | 48 | namespace cereal 49 | { 50 | namespace detail 51 | { 52 | //! Forward declaration, see polymorphic_impl.hpp for more information 53 | template 54 | struct RegisterPolymorphicCaster; 55 | 56 | //! Forward declaration, see polymorphic_impl.hpp for more information 57 | struct PolymorphicCasters; 58 | 59 | //! Forward declaration, see polymorphic_impl.hpp for more information 60 | template 61 | struct PolymorphicRelation; 62 | } // namespace detail 63 | } // namespace cereal 64 | 65 | #endif // CEREAL_DETAILS_POLYMORPHIC_IMPL_FWD_HPP_ 66 | -------------------------------------------------------------------------------- /include/cereal/details/util.hpp: -------------------------------------------------------------------------------- 1 | /*! \file util.hpp 2 | \brief Internal misc utilities 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_DETAILS_UTIL_HPP_ 31 | #define CEREAL_DETAILS_UTIL_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | #ifdef _MSC_VER 37 | namespace cereal 38 | { 39 | namespace util 40 | { 41 | //! Demangles the type encoded in a string 42 | /*! @internal */ 43 | inline std::string demangle( std::string const & name ) 44 | { return name; } 45 | 46 | //! Gets the demangled name of a type 47 | /*! @internal */ 48 | template inline 49 | std::string demangledName() 50 | { return typeid( T ).name(); } 51 | } // namespace util 52 | } // namespace cereal 53 | #else // clang or gcc 54 | #include 55 | #include 56 | namespace cereal 57 | { 58 | namespace util 59 | { 60 | //! Demangles the type encoded in a string 61 | /*! @internal */ 62 | inline std::string demangle(std::string mangledName) 63 | { 64 | int status = 0; 65 | char *demangledName = nullptr; 66 | std::size_t len; 67 | 68 | demangledName = abi::__cxa_demangle(mangledName.c_str(), 0, &len, &status); 69 | 70 | std::string retName(demangledName); 71 | free(demangledName); 72 | 73 | return retName; 74 | } 75 | 76 | //! Gets the demangled name of a type 77 | /*! @internal */ 78 | template inline 79 | std::string demangledName() 80 | { return demangle(typeid(T).name()); } 81 | } 82 | } // namespace cereal 83 | #endif // clang or gcc branch of _MSC_VER 84 | #endif // CEREAL_DETAILS_UTIL_HPP_ 85 | -------------------------------------------------------------------------------- /include/cereal/external/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2004-2008 René Nyffenegger 2 | 3 | This source code is provided 'as-is', without any express or implied 4 | warranty. In no event will the author be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this source code must not be misrepresented; you must not 12 | claim that you wrote the original source code. If you use this source code 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must not be 17 | misrepresented as being the original source code. 18 | 19 | 3. This notice may not be removed or altered from any source distribution. 20 | 21 | René Nyffenegger rene.nyffenegger@adp-gmbh.ch 22 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/LICENSE: -------------------------------------------------------------------------------- 1 | Tencent is pleased to support the open source community by making RapidJSON available. 2 | 3 | Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | 5 | Licensed under the MIT License (the "License"); you may not use this file except 6 | in compliance with the License. You may obtain a copy of the License at 7 | 8 | http://opensource.org/licenses/MIT 9 | 10 | Unless required by applicable law or agreed to in writing, software distributed 11 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | specific language governing permissions and limitations under the License. 14 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/cursorstreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_CURSORSTREAMWRAPPER_H_ 16 | #define CEREAL_RAPIDJSON_CURSORSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | 20 | #if defined(__GNUC__) 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && _MSC_VER <= 1800 26 | CEREAL_RAPIDJSON_DIAG_PUSH 27 | CEREAL_RAPIDJSON_DIAG_OFF(4702) // unreachable code 28 | CEREAL_RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 29 | #endif 30 | 31 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | 34 | //! Cursor stream wrapper for counting line and column number if error exists. 35 | /*! 36 | \tparam InputStream Any stream that implements Stream Concept 37 | */ 38 | template > 39 | class CursorStreamWrapper : public GenericStreamWrapper { 40 | public: 41 | typedef typename Encoding::Ch Ch; 42 | 43 | CursorStreamWrapper(InputStream& is): 44 | GenericStreamWrapper(is), line_(1), col_(0) {} 45 | 46 | // counting line and column number 47 | Ch Take() { 48 | Ch ch = this->is_.Take(); 49 | if(ch == '\n') { 50 | line_ ++; 51 | col_ = 0; 52 | } else { 53 | col_ ++; 54 | } 55 | return ch; 56 | } 57 | 58 | //! Get the error line number, if error exists. 59 | size_t GetLine() const { return line_; } 60 | //! Get the error column number, if error exists. 61 | size_t GetColumn() const { return col_; } 62 | 63 | private: 64 | size_t line_; //!< Current Line 65 | size_t col_; //!< Current Column 66 | }; 67 | 68 | #if defined(_MSC_VER) && _MSC_VER <= 1800 69 | CEREAL_RAPIDJSON_DIAG_POP 70 | #endif 71 | 72 | #if defined(__GNUC__) 73 | CEREAL_RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | CEREAL_RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // CEREAL_RAPIDJSON_CURSORSTREAMWRAPPER_H_ 79 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_FILEREADSTREAM_H_ 16 | #define CEREAL_RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 24 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 25 | CEREAL_RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | CEREAL_RAPIDJSON_ASSERT(fp_ != 0); 46 | CEREAL_RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 56 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | CEREAL_RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | CEREAL_RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // CEREAL_RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/filewritestream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_FILEWRITESTREAM_H_ 16 | #define CEREAL_RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for output using fwrite(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | CEREAL_RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = std::fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | CEREAL_RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | CEREAL_RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // CEREAL_RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_IEEE754_ 16 | #define CEREAL_RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | CEREAL_RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static int EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return order + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = CEREAL_RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = CEREAL_RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = CEREAL_RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = CEREAL_RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | CEREAL_RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // CEREAL_RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/internal/pow10.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_POW10_ 16 | #define CEREAL_RAPIDJSON_POW10_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Computes integer powers of 10 in double (10.0^n). 24 | /*! This function uses lookup table for fast and accurate results. 25 | \param n non-negative exponent. Must <= 308. 26 | \return 10.0^n 27 | */ 28 | inline double Pow10(int n) { 29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes 30 | 1e+0, 31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 47 | }; 48 | CEREAL_RAPIDJSON_ASSERT(n >= 0 && n <= 308); 49 | return e[n]; 50 | } 51 | 52 | } // namespace internal 53 | CEREAL_RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // CEREAL_RAPIDJSON_POW10_ 56 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | CEREAL_RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Returns number of code points in a encoded string. 49 | template 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 51 | CEREAL_RAPIDJSON_ASSERT(s != 0); 52 | CEREAL_RAPIDJSON_ASSERT(outCount != 0); 53 | GenericStringStream is(s); 54 | const typename Encoding::Ch* end = s + length; 55 | SizeType count = 0; 56 | while (is.src_ < end) { 57 | unsigned codepoint; 58 | if (!Encoding::Decode(is, &codepoint)) 59 | return false; 60 | count++; 61 | } 62 | *outCount = count; 63 | return true; 64 | } 65 | 66 | } // namespace internal 67 | CEREAL_RAPIDJSON_NAMESPACE_END 68 | 69 | #endif // CEREAL_RAPIDJSON_INTERNAL_STRFUNC_H_ 70 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) CEREAL_RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | CEREAL_RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | CEREAL_RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // CEREAL_RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 16 | #define CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | CEREAL_RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_MEMORYSTREAM_H_ 16 | #define CEREAL_RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | CEREAL_RAPIDJSON_DIAG_PUSH 22 | CEREAL_RAPIDJSON_DIAG_OFF(unreachable-code) 23 | CEREAL_RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return CEREAL_RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return CEREAL_RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { CEREAL_RAPIDJSON_ASSERT(false); } 51 | void Flush() { CEREAL_RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | CEREAL_RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | CEREAL_RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // CEREAL_RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/msinttypes/LICENSE: -------------------------------------------------------------------------------- 1 | ISO C9x compliant stdint.h for Microsoft Visual Studio 2 | Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | 4 | Copyright (c) 2006-2013 Alexander Chemeris 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the product nor the names of its contributors may 17 | be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 23 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /include/cereal/external/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | CEREAL_RAPIDJSON_DIAG_PUSH 23 | CEREAL_RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | CEREAL_RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { CEREAL_RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | CEREAL_RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | CEREAL_RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // CEREAL_RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /include/cereal/external/rapidxml/license.txt: -------------------------------------------------------------------------------- 1 | Use of this software is granted under one of the following two licenses, 2 | to be chosen freely by the user. 3 | 4 | 1. Boost Software License - Version 1.0 - August 17th, 2003 5 | =============================================================================== 6 | 7 | Copyright (c) 2006, 2007 Marcin Kalicinski 8 | 9 | Permission is hereby granted, free of charge, to any person or organization 10 | obtaining a copy of the software and accompanying documentation covered by 11 | this license (the "Software") to use, reproduce, display, distribute, 12 | execute, and transmit the Software, and to prepare derivative works of the 13 | Software, and to permit third-parties to whom the Software is furnished to 14 | do so, all subject to the following: 15 | 16 | The copyright notices in the Software and this entire statement, including 17 | the above license grant, this restriction and the following disclaimer, 18 | must be included in all copies of the Software, in whole or in part, and 19 | all derivative works of the Software, unless such copies or derivative 20 | works are solely in the form of machine-executable object code generated by 21 | a source language processor. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | DEALINGS IN THE SOFTWARE. 30 | 31 | 2. The MIT License 32 | =============================================================================== 33 | 34 | Copyright (c) 2006, 2007 Marcin Kalicinski 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | of the Software, and to permit persons to whom the Software is furnished to do so, 41 | subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 52 | IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /include/cereal/external/rapidxml/rapidxml_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CEREAL_RAPIDXML_UTILS_HPP_INCLUDED 2 | #define CEREAL_RAPIDXML_UTILS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective. 8 | 9 | #include "rapidxml.hpp" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace cereal { 16 | namespace rapidxml 17 | { 18 | 19 | //! Represents data loaded from a file 20 | template 21 | class file 22 | { 23 | 24 | public: 25 | 26 | //! Loads file into the memory. Data will be automatically destroyed by the destructor. 27 | //! \param filename Filename to load. 28 | file(const char *filename) 29 | { 30 | using namespace std; 31 | 32 | // Open stream 33 | basic_ifstream stream(filename, ios::binary); 34 | if (!stream) 35 | throw runtime_error(string("cannot open file ") + filename); 36 | stream.unsetf(ios::skipws); 37 | 38 | // Determine stream size 39 | stream.seekg(0, ios::end); 40 | size_t size = stream.tellg(); 41 | stream.seekg(0); 42 | 43 | // Load data and add terminating 0 44 | m_data.resize(size + 1); 45 | stream.read(&m_data.front(), static_cast(size)); 46 | m_data[size] = 0; 47 | } 48 | 49 | //! Loads file into the memory. Data will be automatically destroyed by the destructor 50 | //! \param stream Stream to load from 51 | file(std::basic_istream &stream) 52 | { 53 | using namespace std; 54 | 55 | // Load data and add terminating 0 56 | stream.unsetf(ios::skipws); 57 | m_data.assign(istreambuf_iterator(stream), istreambuf_iterator()); 58 | if (stream.fail() || stream.bad()) 59 | throw runtime_error("error reading stream"); 60 | m_data.push_back(0); 61 | } 62 | 63 | //! Gets file data. 64 | //! \return Pointer to data of file. 65 | Ch *data() 66 | { 67 | return &m_data.front(); 68 | } 69 | 70 | //! Gets file data. 71 | //! \return Pointer to data of file. 72 | const Ch *data() const 73 | { 74 | return &m_data.front(); 75 | } 76 | 77 | //! Gets file data size. 78 | //! \return Size of file data, in characters. 79 | std::size_t size() const 80 | { 81 | return m_data.size(); 82 | } 83 | 84 | private: 85 | 86 | std::vector m_data; // File data 87 | 88 | }; 89 | 90 | //! Counts children of node. Time complexity is O(n). 91 | //! \return Number of children of node 92 | template 93 | inline std::size_t count_children(xml_node *node) 94 | { 95 | xml_node *child = node->first_node(); 96 | std::size_t count = 0; 97 | while (child) 98 | { 99 | ++count; 100 | child = child->next_sibling(); 101 | } 102 | return count; 103 | } 104 | 105 | //! Counts attributes of node. Time complexity is O(n). 106 | //! \return Number of attributes of node 107 | template 108 | inline std::size_t count_attributes(xml_node *node) 109 | { 110 | xml_attribute *attr = node->first_attribute(); 111 | std::size_t count = 0; 112 | while (attr) 113 | { 114 | ++count; 115 | attr = attr->next_attribute(); 116 | } 117 | return count; 118 | } 119 | 120 | } 121 | } // namespace cereal 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /include/cereal/types/array.hpp: -------------------------------------------------------------------------------- 1 | /*! \file array.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_ARRAY_HPP_ 31 | #define CEREAL_TYPES_ARRAY_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::array primitive types 39 | //! using binary serialization, if supported 40 | template inline 41 | typename std::enable_if, Archive>::value 42 | && std::is_arithmetic::value, void>::type 43 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 44 | { 45 | ar( binary_data( array.data(), sizeof(array) ) ); 46 | } 47 | 48 | //! Loading for std::array primitive types 49 | //! using binary serialization, if supported 50 | template inline 51 | typename std::enable_if, Archive>::value 52 | && std::is_arithmetic::value, void>::type 53 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 54 | { 55 | ar( binary_data( array.data(), sizeof(array) ) ); 56 | } 57 | 58 | //! Saving for std::array all other types 59 | template inline 60 | typename std::enable_if, Archive>::value 61 | || !std::is_arithmetic::value, void>::type 62 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 63 | { 64 | for( auto const & i : array ) 65 | ar( i ); 66 | } 67 | 68 | //! Loading for std::array all other types 69 | template inline 70 | typename std::enable_if, Archive>::value 71 | || !std::is_arithmetic::value, void>::type 72 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 73 | { 74 | for( auto & i : array ) 75 | ar( i ); 76 | } 77 | } // namespace cereal 78 | 79 | #endif // CEREAL_TYPES_ARRAY_HPP_ 80 | -------------------------------------------------------------------------------- /include/cereal/types/atomic.hpp: -------------------------------------------------------------------------------- 1 | /*! \file atomic.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_ATOMIC_HPP_ 31 | #define CEREAL_TYPES_ATOMIC_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serializing (save) for std::atomic 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::atomic const & a ) 41 | { 42 | ar( CEREAL_NVP_("atomic_data", a.load()) ); 43 | } 44 | 45 | //! Serializing (load) for std::atomic 46 | template inline 47 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::atomic & a ) 48 | { 49 | T tmp; 50 | ar( CEREAL_NVP_("atomic_data", tmp) ); 51 | a.store( tmp ); 52 | } 53 | } // namespace cereal 54 | 55 | #endif // CEREAL_TYPES_ATOMIC_HPP_ 56 | -------------------------------------------------------------------------------- /include/cereal/types/chrono.hpp: -------------------------------------------------------------------------------- 1 | /*! \file chrono.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_CHRONO_HPP_ 31 | #define CEREAL_TYPES_CHRONO_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Saving std::chrono::duration 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::duration const & dur ) 40 | { 41 | ar( CEREAL_NVP_("count", dur.count()) ); 42 | } 43 | 44 | //! Loading std::chrono::duration 45 | template inline 46 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::duration & dur ) 47 | { 48 | R count; 49 | ar( CEREAL_NVP_("count", count) ); 50 | 51 | dur = std::chrono::duration{count}; 52 | } 53 | 54 | //! Saving std::chrono::time_point 55 | template inline 56 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::time_point const & dur ) 57 | { 58 | ar( CEREAL_NVP_("time_since_epoch", dur.time_since_epoch()) ); 59 | } 60 | 61 | //! Loading std::chrono::time_point 62 | template inline 63 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::time_point & dur ) 64 | { 65 | D elapsed; 66 | ar( CEREAL_NVP_("time_since_epoch", elapsed) ); 67 | 68 | dur = std::chrono::time_point{elapsed}; 69 | } 70 | } // namespace cereal 71 | 72 | #endif // CEREAL_TYPES_CHRONO_HPP_ 73 | -------------------------------------------------------------------------------- /include/cereal/types/complex.hpp: -------------------------------------------------------------------------------- 1 | /*! \file complex.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_COMPLEX_HPP_ 31 | #define CEREAL_TYPES_COMPLEX_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Serializing (save) for std::complex 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::complex const & comp ) 40 | { 41 | ar( CEREAL_NVP_("real", comp.real()), 42 | CEREAL_NVP_("imag", comp.imag()) ); 43 | } 44 | 45 | //! Serializing (load) for std::complex 46 | template inline 47 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::complex & bits ) 48 | { 49 | T real, imag; 50 | ar( CEREAL_NVP_("real", real), 51 | CEREAL_NVP_("imag", imag) ); 52 | bits = {real, imag}; 53 | } 54 | } // namespace cereal 55 | 56 | #endif // CEREAL_TYPES_COMPLEX_HPP_ 57 | -------------------------------------------------------------------------------- /include/cereal/types/concepts/pair_associative_container.hpp: -------------------------------------------------------------------------------- 1 | /*! \file pair_associative_container.hpp 2 | \brief Support for the PairAssociativeContainer refinement of the 3 | AssociativeContainer concept. 4 | \ingroup TypeConcepts */ 5 | /* 6 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions are met: 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | * Neither the name of the copyright holder nor the 17 | names of its contributors may be used to endorse or promote products 18 | derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 24 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 32 | #define CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 33 | 34 | #include "cereal/cereal.hpp" 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std-like pair associative containers 39 | template class Map, typename... Args, typename = typename Map::mapped_type> inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, Map const & map ) 41 | { 42 | ar( make_size_tag( static_cast(map.size()) ) ); 43 | 44 | for( const auto & i : map ) 45 | ar( make_map_item(i.first, i.second) ); 46 | } 47 | 48 | //! Loading for std-like pair associative containers 49 | template class Map, typename... Args, typename = typename Map::mapped_type> inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, Map & map ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | map.clear(); 56 | 57 | auto hint = map.begin(); 58 | for( size_t i = 0; i < size; ++i ) 59 | { 60 | typename Map::key_type key; 61 | typename Map::mapped_type value; 62 | 63 | ar( make_map_item(key, value) ); 64 | #ifdef CEREAL_OLDER_GCC 65 | hint = map.insert( hint, std::make_pair(std::move(key), std::move(value)) ); 66 | #else // NOT CEREAL_OLDER_GCC 67 | hint = map.emplace_hint( hint, std::move( key ), std::move( value ) ); 68 | #endif // NOT CEREAL_OLDER_GCC 69 | } 70 | } 71 | } // namespace cereal 72 | 73 | #endif // CEREAL_CONCEPTS_PAIR_ASSOCIATIVE_CONTAINER_HPP_ 74 | -------------------------------------------------------------------------------- /include/cereal/types/deque.hpp: -------------------------------------------------------------------------------- 1 | /*! \file deque.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_DEQUE_HPP_ 31 | #define CEREAL_TYPES_DEQUE_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::deque 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::deque const & deque ) 41 | { 42 | ar( make_size_tag( static_cast(deque.size()) ) ); 43 | 44 | for( auto const & i : deque ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::deque 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::deque & deque ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | deque.resize( static_cast( size ) ); 56 | 57 | for( auto & i : deque ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_DEQUE_HPP_ 63 | -------------------------------------------------------------------------------- /include/cereal/types/forward_list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file forward_list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_FORWARD_LIST_HPP_ 31 | #define CEREAL_TYPES_FORWARD_LIST_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::forward_list all other types 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::forward_list const & forward_list ) 41 | { 42 | // write the size - note that this is slow because we need to traverse 43 | // the entire list. there are ways we could avoid this but this was chosen 44 | // since it works in the most general fashion with any archive type 45 | size_type const size = std::distance( forward_list.begin(), forward_list.end() ); 46 | 47 | ar( make_size_tag( size ) ); 48 | 49 | // write the list 50 | for( const auto & i : forward_list ) 51 | ar( i ); 52 | } 53 | 54 | //! Loading for std::forward_list all other types from 55 | template 56 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::forward_list & forward_list ) 57 | { 58 | size_type size; 59 | ar( make_size_tag( size ) ); 60 | 61 | forward_list.resize( static_cast( size ) ); 62 | 63 | for( auto & i : forward_list ) 64 | ar( i ); 65 | } 66 | } // namespace cereal 67 | 68 | #endif // CEREAL_TYPES_FORWARD_LIST_HPP_ 69 | -------------------------------------------------------------------------------- /include/cereal/types/functional.hpp: -------------------------------------------------------------------------------- 1 | /*! \file functional.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2016, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_FUNCTIONAL_HPP_ 31 | #define CEREAL_TYPES_FUNCTIONAL_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Saving for std::less 38 | template inline 39 | void serialize( Archive &, std::less & ) 40 | { } 41 | } // namespace cereal 42 | 43 | #endif // CEREAL_TYPES_FUNCTIONAL_HPP_ 44 | -------------------------------------------------------------------------------- /include/cereal/types/list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_LIST_HPP_ 31 | #define CEREAL_TYPES_LIST_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::list 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::list const & list ) 41 | { 42 | ar( make_size_tag( static_cast(list.size()) ) ); 43 | 44 | for( auto const & i : list ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::list 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::list & list ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | list.resize( static_cast( size ) ); 56 | 57 | for( auto & i : list ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_LIST_HPP_ 63 | -------------------------------------------------------------------------------- /include/cereal/types/map.hpp: -------------------------------------------------------------------------------- 1 | /*! \file map.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_MAP_HPP_ 31 | #define CEREAL_TYPES_MAP_HPP_ 32 | 33 | #include "cereal/types/concepts/pair_associative_container.hpp" 34 | #include 35 | 36 | #endif // CEREAL_TYPES_MAP_HPP_ 37 | -------------------------------------------------------------------------------- /include/cereal/types/optional.hpp: -------------------------------------------------------------------------------- 1 | /*! \file optional.hpp 2 | \brief Support for std::optional 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2017, Juan Pedro Bolivar Puente 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STD_OPTIONAL_ 31 | #define CEREAL_TYPES_STD_OPTIONAL_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal { 37 | //! Saving for std::optional 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME(Archive& ar, const std::optional& optional) 40 | { 41 | if(!optional) { 42 | ar(CEREAL_NVP_("nullopt", true)); 43 | } else { 44 | ar(CEREAL_NVP_("nullopt", false), 45 | CEREAL_NVP_("data", *optional)); 46 | } 47 | } 48 | 49 | //! Loading for std::optional 50 | template inline 51 | void CEREAL_LOAD_FUNCTION_NAME(Archive& ar, std::optional& optional) 52 | { 53 | bool nullopt; 54 | ar(CEREAL_NVP_("nullopt", nullopt)); 55 | 56 | if (nullopt) { 57 | optional = std::nullopt; 58 | } else { 59 | optional.emplace(); 60 | ar(CEREAL_NVP_("data", *optional)); 61 | } 62 | } 63 | } // namespace cereal 64 | 65 | #endif // CEREAL_TYPES_STD_OPTIONAL_ 66 | -------------------------------------------------------------------------------- /include/cereal/types/stack.hpp: -------------------------------------------------------------------------------- 1 | /*! \file stack.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STACK_HPP_ 31 | #define CEREAL_TYPES_STACK_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | // The default container for stack is deque, so let's include that too 37 | #include "cereal/types/deque.hpp" 38 | 39 | namespace cereal 40 | { 41 | namespace stack_detail 42 | { 43 | //! Allows access to the protected container in stack 44 | template inline 45 | C const & container( std::stack const & stack ) 46 | { 47 | struct H : public std::stack 48 | { 49 | static C const & get( std::stack const & s ) 50 | { 51 | return s.*(&H::c); 52 | } 53 | }; 54 | 55 | return H::get( stack ); 56 | } 57 | } 58 | 59 | //! Saving for std::stack 60 | template inline 61 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::stack const & stack ) 62 | { 63 | ar( CEREAL_NVP_("container", stack_detail::container( stack )) ); 64 | } 65 | 66 | //! Loading for std::stack 67 | template inline 68 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::stack & stack ) 69 | { 70 | C container; 71 | ar( CEREAL_NVP_("container", container) ); 72 | stack = std::stack( std::move( container ) ); 73 | } 74 | } // namespace cereal 75 | 76 | #endif // CEREAL_TYPES_STACK_HPP_ 77 | -------------------------------------------------------------------------------- /include/cereal/types/string.hpp: -------------------------------------------------------------------------------- 1 | /*! \file string.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STRING_HPP_ 31 | #define CEREAL_TYPES_STRING_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serialization for basic_string types, if binary data is supported 39 | template inline 40 | typename std::enable_if, Archive>::value, void>::type 41 | CEREAL_SAVE_FUNCTION_NAME(Archive & ar, std::basic_string const & str) 42 | { 43 | // Save number of chars + the data 44 | ar( make_size_tag( static_cast(str.size()) ) ); 45 | ar( binary_data( str.data(), str.size() * sizeof(CharT) ) ); 46 | } 47 | 48 | //! Serialization for basic_string types, if binary data is supported 49 | template inline 50 | typename std::enable_if, Archive>::value, void>::type 51 | CEREAL_LOAD_FUNCTION_NAME(Archive & ar, std::basic_string & str) 52 | { 53 | size_type size; 54 | ar( make_size_tag( size ) ); 55 | str.resize(static_cast(size)); 56 | ar( binary_data( const_cast( str.data() ), static_cast(size) * sizeof(CharT) ) ); 57 | } 58 | } // namespace cereal 59 | 60 | #endif // CEREAL_TYPES_STRING_HPP_ 61 | 62 | -------------------------------------------------------------------------------- /include/cereal/types/unordered_map.hpp: -------------------------------------------------------------------------------- 1 | /*! \file unordered_map.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UNORDERED_MAP_HPP_ 31 | #define CEREAL_TYPES_UNORDERED_MAP_HPP_ 32 | 33 | #include "cereal/types/concepts/pair_associative_container.hpp" 34 | #include 35 | 36 | #endif // CEREAL_TYPES_UNORDERED_MAP_HPP_ 37 | -------------------------------------------------------------------------------- /include/cereal/types/utility.hpp: -------------------------------------------------------------------------------- 1 | /*! \file utility.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the copyright holder nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UTILITY_HPP_ 31 | #define CEREAL_TYPES_UTILITY_HPP_ 32 | 33 | #include "cereal/cereal.hpp" 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serializing for std::pair 39 | template inline 40 | void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, std::pair & pair ) 41 | { 42 | ar( CEREAL_NVP_("first", pair.first), 43 | CEREAL_NVP_("second", pair.second) ); 44 | } 45 | } // namespace cereal 46 | 47 | #endif // CEREAL_TYPES_UTILITY_HPP_ 48 | -------------------------------------------------------------------------------- /include/cereal/version.hpp: -------------------------------------------------------------------------------- 1 | /*! \file version.hpp 2 | \brief Macros to detect cereal version 3 | 4 | These macros can assist in determining the version of cereal. Be 5 | warned that cereal is not guaranteed to be compatible across 6 | different versions. For more information on releases of cereal, 7 | see https://github.com/USCiLab/cereal/releases. 8 | 9 | \ingroup utility */ 10 | /* 11 | Copyright (c) 2018, Shane Grant 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are met: 16 | * Redistributions of source code must retain the above copyright 17 | notice, this list of conditions and the following disclaimer. 18 | * Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | * Neither the name of the copyright holder nor the 22 | names of its contributors may be used to endorse or promote products 23 | derived from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 26 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 29 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef CEREAL_VERSION_HPP_ 38 | #define CEREAL_VERSION_HPP_ 39 | 40 | //! The major version 41 | #define CEREAL_VERSION_MAJOR 1 42 | //! The minor version 43 | #define CEREAL_VERSION_MINOR 3 44 | //! The patch version 45 | #define CEREAL_VERSION_PATCH 2 46 | 47 | //! The full version as a single number 48 | #define CEREAL_VERSION (CEREAL_VERSION_MAJOR * 10000 \ 49 | + CEREAL_VERSION_MINOR * 100 \ 50 | + CEREAL_VERSION_PATCH) 51 | 52 | #endif // CEREAL_VERSION_HPP_ 53 | -------------------------------------------------------------------------------- /sponsor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/sponsor.png -------------------------------------------------------------------------------- /src/Common/Public.cpp: -------------------------------------------------------------------------------- 1 | #include "Public.h" 2 | 3 | size_t AlignByMemory(size_t originValue, size_t alignment) 4 | { 5 | size_t reminder = originValue / alignment; 6 | size_t mod = originValue % alignment; 7 | if (mod != 0) { 8 | reminder += 1; 9 | } 10 | return reminder * alignment; 11 | } -------------------------------------------------------------------------------- /src/Common/Public.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | template 5 | class Singleton { 6 | public: 7 | static T& Instance() { 8 | static T instance; 9 | return instance; 10 | } 11 | Singleton(const Singleton&) = delete; 12 | Singleton& operator=(const Singleton&) = delete; 13 | protected: 14 | Singleton() {} 15 | ~Singleton() {} 16 | }; 17 | 18 | size_t AlignByMemory(size_t originValue, size_t alignment); 19 | 20 | template 21 | T readFromMemory(unsigned char* buffer) { 22 | T result; 23 | std::memcpy(&result, buffer, sizeof(T)); 24 | return result; 25 | } -------------------------------------------------------------------------------- /src/Common/StringUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "StringUtils.h" 2 | #include 3 | #include 4 | 5 | std::wstring StringUtils::Utf8ToUnicode(const char* str) 6 | { 7 | std::wstring convertedString; 8 | if (!str || !*str) 9 | return convertedString; 10 | int requiredSize = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0); 11 | if (requiredSize > 0) 12 | { 13 | convertedString.resize(requiredSize - 1); 14 | if (!MultiByteToWideChar(CP_UTF8, 0, str, -1, (wchar_t*)convertedString.c_str(), requiredSize)) 15 | convertedString.clear(); 16 | } 17 | return convertedString; 18 | } 19 | 20 | std::wstring StringUtils::LocalCpToUtf16(const char* str) 21 | { 22 | std::wstring convertedString; 23 | if (!str || !*str) 24 | return convertedString; 25 | int requiredSize = MultiByteToWideChar(CP_ACP, 0, str, -1, nullptr, 0); 26 | if (requiredSize > 0) 27 | { 28 | convertedString.resize(requiredSize - 1); 29 | if (!MultiByteToWideChar(CP_ACP, 0, str, -1, (wchar_t*)convertedString.c_str(), requiredSize)) 30 | convertedString.clear(); 31 | } 32 | return convertedString; 33 | } 34 | 35 | std::string StringUtils::Utf16ToUtf8(const wchar_t* wstr) 36 | { 37 | std::string convertedString; 38 | if (!wstr || !*wstr) 39 | return convertedString; 40 | auto requiredSize = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr); 41 | if (requiredSize > 0) 42 | { 43 | convertedString.resize(requiredSize - 1); 44 | if (!WideCharToMultiByte(CP_UTF8, 0, wstr, -1, (char*)convertedString.c_str(), requiredSize, nullptr, nullptr)) 45 | convertedString.clear(); 46 | } 47 | return convertedString; 48 | } 49 | 50 | std::string StringUtils::LocalCpToUtf8(const char* str) 51 | { 52 | return Utf16ToUtf8(LocalCpToUtf16(str).c_str()); 53 | } 54 | 55 | std::string StringUtils::sprintf(_In_z_ _Printf_format_string_ const char* format, ...) 56 | { 57 | va_list args; 58 | va_start(args, format); 59 | auto result = vsprintf(format, args); 60 | va_end(args); 61 | return result; 62 | } 63 | 64 | std::string StringUtils::vsprintf(_In_z_ _Printf_format_string_ const char* format, va_list args) 65 | { 66 | char sbuffer[64] = ""; 67 | if (_vsnprintf_s(sbuffer, _TRUNCATE, format, args) != -1) 68 | return sbuffer; 69 | std::vector buffer(256, '\0'); 70 | while (true) 71 | { 72 | int res = _vsnprintf_s(buffer.data(), buffer.size(), _TRUNCATE, format, args); 73 | if (res == -1){ 74 | buffer.resize(buffer.size() * 2); 75 | continue; 76 | } 77 | else 78 | break; 79 | } 80 | return std::string(buffer.data()); 81 | } -------------------------------------------------------------------------------- /src/Common/StringUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | //copy from source code of x64Dbg 5 | 6 | class StringUtils 7 | { 8 | public: 9 | static std::wstring LocalCpToUtf16(const char* str); 10 | static std::wstring Utf8ToUnicode(const char* str); 11 | static std::string Utf16ToUtf8(const wchar_t* wstr); 12 | static std::string LocalCpToUtf8(const char* str); 13 | static std::string sprintf(_In_z_ _Printf_format_string_ const char* format, ...); 14 | static std::string vsprintf(_In_z_ _Printf_format_string_ const char* format, va_list args); 15 | }; -------------------------------------------------------------------------------- /src/Common/VmpCommon.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Common/VmpCommon.cpp -------------------------------------------------------------------------------- /src/Common/VmpCommon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | struct VmAddress 6 | { 7 | size_t raw; 8 | size_t vmdata; 9 | VmAddress() { 10 | raw = 0x0; 11 | vmdata = 0x0; 12 | } 13 | VmAddress(size_t ins, size_t vm) { 14 | raw = ins; 15 | vmdata = vm; 16 | } 17 | VmAddress(size_t ins) { 18 | raw = ins; 19 | vmdata = 0x0; 20 | } 21 | bool operator<(const VmAddress& other) const 22 | { 23 | return std::tie(raw, vmdata) < std::tie(other.raw, other.vmdata); 24 | } 25 | template 26 | void serialize(Archive& ar) 27 | { 28 | ar(raw, vmdata); 29 | } 30 | }; -------------------------------------------------------------------------------- /src/Ghidra/.gitignore: -------------------------------------------------------------------------------- 1 | coreext_* 2 | ghidraext_* 3 | consoleext_* 4 | libdecomp.a 5 | libdecomp_dbg.a 6 | decomp_dbg 7 | decomp_opt 8 | ghidra_dbg 9 | ghidra_opt 10 | ghidra_test_dbg 11 | sleigh_dbg 12 | com_dbg 13 | com_opt 14 | test_dbg 15 | ghi_dbg 16 | ghi_opt 17 | sla_dbg 18 | sla_opt 19 | 20 | -------------------------------------------------------------------------------- /src/Ghidra/action.hh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Ghidra/action.hh -------------------------------------------------------------------------------- /src/Ghidra/capability.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "capability.hh" 17 | 18 | namespace ghidra { 19 | 20 | /// Access static vector of CapabilityPoint objects that are registered during static initialization 21 | /// The list itself is created once on the first call to this method 22 | /// \e after all the static initializers have run 23 | /// \return the list of registered extensions 24 | vector &CapabilityPoint::getList(void) 25 | 26 | { 27 | static vector thelist; // This gets allocated exactly once on first call 28 | return thelist; 29 | } 30 | 31 | /// Constructing the object automatically registers it. 32 | /// For global instances, this happens during static initialization 33 | CapabilityPoint::CapabilityPoint(void) 34 | 35 | { 36 | getList().push_back(this); 37 | } 38 | 39 | /// Give all registered capabilities a chance to initialize (\e after all static initialization has happened) 40 | void CapabilityPoint::initializeAll(void) 41 | 42 | { 43 | vector &list( getList() ); 44 | for(int4 i=0;iinitialize(); 47 | } 48 | list.clear(); 49 | } 50 | 51 | } // End namespace ghidra 52 | -------------------------------------------------------------------------------- /src/Ghidra/capability.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file capability.hh 17 | /// \brief Infrastructure for discovering code extensions to the decompiler 18 | #ifndef __CAPABILITY_HH__ 19 | #define __CAPABILITY_HH__ 20 | 21 | #include "types.h" 22 | #include 23 | #include 24 | 25 | namespace ghidra { 26 | 27 | using std::vector; 28 | using std::string; 29 | 30 | /// \brief Class for automatically registering extension points to the decompiler 31 | /// 32 | /// This uses the C++ static initializer feature to automatically \e discover 33 | /// and register extension point. Code for an extension should provide 34 | /// a class that derives from CapabilityPoint and overrides the initialize() method. 35 | /// Additionally there should be a singleton static instantiation of this extension class. 36 | /// The extensions are accumulated in a list automatically, then the decompiler engine 37 | /// will ensure that the initialize() method is called on each extension, allowing it 38 | /// to complete its integration. 39 | class CapabilityPoint { 40 | static vector &getList(void); ///< Retrieve the list of extension point singletons 41 | protected: 42 | CapabilityPoint(void); ///< Construct extension capability exactly once 43 | public: 44 | virtual ~CapabilityPoint(void) {} ///< Destructor 45 | 46 | /// \brief Complete initialization of an extension point 47 | /// 48 | /// This method is implemented by each extension so it can do specialized integration 49 | virtual void initialize(void)=0; 50 | 51 | static void initializeAll(void); ///< Finish initialization for all extension points 52 | }; 53 | 54 | } // End namespace ghidra 55 | #endif 56 | -------------------------------------------------------------------------------- /src/Ghidra/comment_ghidra.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "comment_ghidra.hh" 17 | 18 | namespace ghidra { 19 | 20 | CommentDatabaseGhidra::CommentDatabaseGhidra(ArchitectureGhidra *g) 21 | : CommentDatabase() 22 | { 23 | ghidra = g; 24 | cachefilled = false; 25 | } 26 | 27 | /// Fetch all comments for the function in one chunk. Deserialize them and 28 | /// store the Comment objects in the cache 29 | /// \param fad is the address of the given function 30 | void CommentDatabaseGhidra::fillCache(const Address &fad) const 31 | 32 | { 33 | uint4 commentfilter; 34 | 35 | if (cachefilled) return; // Already queried ghidra 36 | cachefilled = true; 37 | // Gather which types of comments are being printed currently 38 | commentfilter = ghidra->print->getHeaderComment(); 39 | commentfilter |= ghidra->print->getInstructionComment(); 40 | if (commentfilter==0) return; 41 | CommentSet::const_iterator iter,iterend; 42 | iter = cache.beginComment(fad); 43 | iterend = cache.endComment(fad); 44 | 45 | PackedDecode decoder(ghidra); 46 | if (ghidra->getComments(fad,commentfilter,decoder)) { 47 | cache.decode(decoder); 48 | } 49 | } 50 | 51 | /// For the Ghidra implementation of CommentDatabase, addComment() is currently only 52 | /// called by the warning routines which generates the 53 | /// \e warning and \e warningheader comment types. Neither of 54 | /// these types is intended to be a permanent comment in the 55 | /// database, so we only add the comment to the cache 56 | void CommentDatabaseGhidra::addComment(uint4 tp, 57 | const Address &fad, 58 | const Address &ad, 59 | const string &txt) 60 | { 61 | cache.addComment(tp,fad,ad,txt); 62 | } 63 | 64 | bool CommentDatabaseGhidra::addCommentNoDuplicate(uint4 tp,const Address &fad,const Address &ad, 65 | const string &txt) 66 | { 67 | return cache.addCommentNoDuplicate(tp,fad,ad,txt); 68 | } 69 | 70 | CommentSet::const_iterator CommentDatabaseGhidra::beginComment(const Address &fad) const 71 | 72 | { 73 | fillCache(fad); 74 | return cache.beginComment(fad); 75 | } 76 | 77 | CommentSet::const_iterator CommentDatabaseGhidra::endComment(const Address &fad) const 78 | 79 | { 80 | return cache.endComment(fad); 81 | } 82 | 83 | } // End namespace ghidra 84 | -------------------------------------------------------------------------------- /src/Ghidra/comment_ghidra.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file comment_ghidra.hh 17 | /// \brief Obtain comments by talking to a Ghidra client 18 | #ifndef __COMMENT_GHIDRA_HH__ 19 | #define __COMMENT_GHIDRA_HH__ 20 | 21 | #include "comment.hh" 22 | #include "ghidra_arch.hh" 23 | 24 | namespace ghidra { 25 | 26 | /// \brief An implementation of CommentDatabase backed by a Ghidra client 27 | /// 28 | /// Comment information about particular functions is obtained by querying 29 | /// a Ghidra client. All comments for a single function are queried at once, and 30 | /// results are cached in this object. The cache needs to be cleared between 31 | /// functions using the clear() method. 32 | class CommentDatabaseGhidra : public CommentDatabase { 33 | ArchitectureGhidra *ghidra; ///< The Architecture and connection to the Ghidra client 34 | mutable CommentDatabaseInternal cache; ///< A cache of Comment objects received from the Ghidra client 35 | mutable bool cachefilled; ///< Set to \b true if comments for the current function have been fetched 36 | void fillCache(const Address &fad) const; ///< Fetch comments for the given function 37 | public: 38 | CommentDatabaseGhidra(ArchitectureGhidra *g); ///< Constructor 39 | virtual void clear(void) { cache.clear(); cachefilled=false; } 40 | virtual void clearType(const Address &fad,uint4 tp) { 41 | cache.clearType(fad,tp); 42 | } 43 | virtual void addComment(uint4 tp,const Address &fad, 44 | const Address &ad,const string &txt); 45 | virtual bool addCommentNoDuplicate(uint4 tp,const Address &fad,const Address &ad,const string &txt); 46 | virtual void deleteComment(Comment *com) { 47 | throw LowlevelError("deleteComment unimplemented"); } 48 | virtual CommentSet::const_iterator beginComment(const Address &fad) const; 49 | virtual CommentSet::const_iterator endComment(const Address &fad) const; 50 | virtual void encode(Encoder &encoder) const { 51 | throw LowlevelError("commentdb::encode unimplemented"); } 52 | virtual void decode(Decoder &decoder) { 53 | throw LowlevelError("CommentDatabaseGhidra::decode unimplemented"); } 54 | }; 55 | 56 | } // End namespace ghidra 57 | #endif 58 | -------------------------------------------------------------------------------- /src/Ghidra/coreaction.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Ghidra/coreaction.cc -------------------------------------------------------------------------------- /src/Ghidra/cpool_ghidra.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "cpool_ghidra.hh" 17 | 18 | namespace ghidra { 19 | 20 | ConstantPoolGhidra::ConstantPoolGhidra(ArchitectureGhidra *g) 21 | 22 | { 23 | ghidra = g; 24 | } 25 | 26 | CPoolRecord *ConstantPoolGhidra::createRecord(const vector &refs) 27 | 28 | { 29 | throw LowlevelError("Cannot access constant pool with this method"); 30 | } 31 | 32 | const CPoolRecord *ConstantPoolGhidra::getRecord(const vector &refs) const 33 | 34 | { 35 | const CPoolRecord *rec = cache.getRecord(refs); 36 | if (rec == (const CPoolRecord *)0) { 37 | bool success; 38 | PackedDecode decoder(ghidra); 39 | try { 40 | success = ghidra->getCPoolRef(refs,decoder); 41 | } 42 | catch(JavaError &err) { 43 | throw LowlevelError("Error fetching constant pool record: " + err.explain); 44 | } 45 | catch(DecoderError &err) { 46 | throw LowlevelError("Error in constant pool record encoding: "+err.explain); 47 | } 48 | if (!success) { 49 | ostringstream s; 50 | s << "Could not retrieve constant pool record for reference: 0x" << refs[0]; 51 | throw LowlevelError(s.str()); 52 | } 53 | rec = cache.decodeRecord(refs,decoder,*ghidra->types); 54 | } 55 | return rec; 56 | } 57 | 58 | void ConstantPoolGhidra::encode(Encoder &encoder) const 59 | 60 | { 61 | throw LowlevelError("Cannot access constant pool with this method"); 62 | } 63 | 64 | void ConstantPoolGhidra::decode(Decoder &decoder,TypeFactory &typegrp) 65 | 66 | { 67 | throw LowlevelError("Cannot access constant pool with this method"); 68 | } 69 | 70 | } // End namespace ghidra 71 | -------------------------------------------------------------------------------- /src/Ghidra/cpool_ghidra.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file cpool_ghidra.hh 17 | /// \brief Utility for implementing a \e constant \e pool backed by a Ghidra client 18 | 19 | #ifndef __CPOOL_GHIDRA_HH__ 20 | #define __CPOOL_GHIDRA_HH__ 21 | 22 | #include "ghidra_arch.hh" 23 | 24 | namespace ghidra { 25 | 26 | /// \brief An implementation of ConstantPool using a Ghidra client as the backing storage 27 | /// 28 | /// The actual CPoolRecord objects are cached locally, but new queries are placed 29 | /// with the Ghidra client hosting the program currently being decompiled. The 30 | /// queries and response records are sent via XML. The encode() and decode() 31 | /// methods are disabled. The clear() method only releases the local cache, 32 | /// no records on the Ghidra client are affected. 33 | class ConstantPoolGhidra : public ConstantPool { 34 | ArchitectureGhidra *ghidra; ///< The connection with the Ghidra client 35 | mutable ConstantPoolInternal cache; ///< The local cache of previouly queried CPoolRecord objects 36 | virtual CPoolRecord *createRecord(const vector &refs); 37 | public: 38 | ConstantPoolGhidra(ArchitectureGhidra *g); ///< Constructor 39 | virtual const CPoolRecord *getRecord(const vector &refs) const; 40 | virtual bool empty(void) const { return false; } 41 | virtual void clear(void) { cache.clear(); } 42 | virtual void encode(Encoder &encoder) const; 43 | virtual void decode(Decoder &decoder,TypeFactory &typegrp); 44 | }; 45 | 46 | } // End namespace ghidra 47 | #endif 48 | -------------------------------------------------------------------------------- /src/Ghidra/crc32.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "crc32.hh" 17 | 18 | namespace ghidra { 19 | 20 | // Table for bytewise calculation of a 32-bit Cyclic Redundancy Check 21 | uint4 crc32tab[] = { 22 | 0x0,0x77073096,0xee0e612c,0x990951ba,0x76dc419,0x706af48f, 23 | 0xe963a535,0x9e6495a3,0xedb8832,0x79dcb8a4,0xe0d5e91e, 24 | 0x97d2d988,0x9b64c2b,0x7eb17cbd,0xe7b82d07,0x90bf1d91, 25 | 0x1db71064,0x6ab020f2,0xf3b97148,0x84be41de,0x1adad47d, 26 | 0x6ddde4eb,0xf4d4b551,0x83d385c7,0x136c9856,0x646ba8c0, 27 | 0xfd62f97a,0x8a65c9ec,0x14015c4f,0x63066cd9,0xfa0f3d63, 28 | 0x8d080df5,0x3b6e20c8,0x4c69105e,0xd56041e4,0xa2677172, 29 | 0x3c03e4d1,0x4b04d447,0xd20d85fd,0xa50ab56b,0x35b5a8fa, 30 | 0x42b2986c,0xdbbbc9d6,0xacbcf940,0x32d86ce3,0x45df5c75, 31 | 0xdcd60dcf,0xabd13d59,0x26d930ac,0x51de003a,0xc8d75180, 32 | 0xbfd06116,0x21b4f4b5,0x56b3c423,0xcfba9599,0xb8bda50f, 33 | 0x2802b89e,0x5f058808,0xc60cd9b2,0xb10be924,0x2f6f7c87, 34 | 0x58684c11,0xc1611dab,0xb6662d3d,0x76dc4190,0x1db7106, 35 | 0x98d220bc,0xefd5102a,0x71b18589,0x6b6b51f,0x9fbfe4a5, 36 | 0xe8b8d433,0x7807c9a2,0xf00f934,0x9609a88e,0xe10e9818, 37 | 0x7f6a0dbb,0x86d3d2d,0x91646c97,0xe6635c01,0x6b6b51f4, 38 | 0x1c6c6162,0x856530d8,0xf262004e,0x6c0695ed,0x1b01a57b, 39 | 0x8208f4c1,0xf50fc457,0x65b0d9c6,0x12b7e950,0x8bbeb8ea, 40 | 0xfcb9887c,0x62dd1ddf,0x15da2d49,0x8cd37cf3,0xfbd44c65, 41 | 0x4db26158,0x3ab551ce,0xa3bc0074,0xd4bb30e2,0x4adfa541, 42 | 0x3dd895d7,0xa4d1c46d,0xd3d6f4fb,0x4369e96a,0x346ed9fc, 43 | 0xad678846,0xda60b8d0,0x44042d73,0x33031de5,0xaa0a4c5f, 44 | 0xdd0d7cc9,0x5005713c,0x270241aa,0xbe0b1010,0xc90c2086, 45 | 0x5768b525,0x206f85b3,0xb966d409,0xce61e49f,0x5edef90e, 46 | 0x29d9c998,0xb0d09822,0xc7d7a8b4,0x59b33d17,0x2eb40d81, 47 | 0xb7bd5c3b,0xc0ba6cad,0xedb88320,0x9abfb3b6,0x3b6e20c, 48 | 0x74b1d29a,0xead54739,0x9dd277af,0x4db2615,0x73dc1683, 49 | 0xe3630b12,0x94643b84,0xd6d6a3e,0x7a6a5aa8,0xe40ecf0b, 50 | 0x9309ff9d,0xa00ae27,0x7d079eb1,0xf00f9344,0x8708a3d2, 51 | 0x1e01f268,0x6906c2fe,0xf762575d,0x806567cb,0x196c3671, 52 | 0x6e6b06e7,0xfed41b76,0x89d32be0,0x10da7a5a,0x67dd4acc, 53 | 0xf9b9df6f,0x8ebeeff9,0x17b7be43,0x60b08ed5,0xd6d6a3e8, 54 | 0xa1d1937e,0x38d8c2c4,0x4fdff252,0xd1bb67f1,0xa6bc5767, 55 | 0x3fb506dd,0x48b2364b,0xd80d2bda,0xaf0a1b4c,0x36034af6, 56 | 0x41047a60,0xdf60efc3,0xa867df55,0x316e8eef,0x4669be79, 57 | 0xcb61b38c,0xbc66831a,0x256fd2a0,0x5268e236,0xcc0c7795, 58 | 0xbb0b4703,0x220216b9,0x5505262f,0xc5ba3bbe,0xb2bd0b28, 59 | 0x2bb45a92,0x5cb36a04,0xc2d7ffa7,0xb5d0cf31,0x2cd99e8b, 60 | 0x5bdeae1d,0x9b64c2b0,0xec63f226,0x756aa39c,0x26d930a, 61 | 0x9c0906a9,0xeb0e363f,0x72076785,0x5005713,0x95bf4a82, 62 | 0xe2b87a14,0x7bb12bae,0xcb61b38,0x92d28e9b,0xe5d5be0d, 63 | 0x7cdcefb7,0xbdbdf21,0x86d3d2d4,0xf1d4e242,0x68ddb3f8, 64 | 0x1fda836e,0x81be16cd,0xf6b9265b,0x6fb077e1,0x18b74777, 65 | 0x88085ae6,0xff0f6a70,0x66063bca,0x11010b5c,0x8f659eff, 66 | 0xf862ae69,0x616bffd3,0x166ccf45,0xa00ae278,0xd70dd2ee, 67 | 0x4e048354,0x3903b3c2,0xa7672661,0xd06016f7,0x4969474d, 68 | 0x3e6e77db,0xaed16a4a,0xd9d65adc,0x40df0b66,0x37d83bf0, 69 | 0xa9bcae53,0xdebb9ec5,0x47b2cf7f,0x30b5ffe9,0xbdbdf21c, 70 | 0xcabac28a,0x53b39330,0x24b4a3a6,0xbad03605,0xcdd70693, 71 | 0x54de5729,0x23d967bf,0xb3667a2e,0xc4614ab8,0x5d681b02, 72 | 0x2a6f2b94,0xb40bbe37,0xc30c8ea1,0x5a05df1b,0x2d02ef8d }; 73 | 74 | } // End namespace ghidra 75 | -------------------------------------------------------------------------------- /src/Ghidra/crc32.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file crc32.hh 17 | /// \brief Table and function for computing a CRC32 18 | 19 | #ifndef __CRC32_HH__ 20 | #define __CRC32_HH__ 21 | 22 | #include "types.h" 23 | 24 | namespace ghidra { 25 | 26 | extern uint4 crc32tab[]; ///< Table for quickly computing a 32-bit Cyclic Redundacy Check (CRC) 27 | 28 | /// \brief Feed 8 bits into a CRC register 29 | /// 30 | /// \param reg is the current state of the CRC register 31 | /// \param val holds 8 bits (least significant) to feed in 32 | /// \return the new value of the register 33 | inline uint4 crc_update(uint4 reg,uint4 val) { 34 | return crc32tab[(reg ^ val)&0xff] ^ (reg>>8); } 35 | 36 | } // End namespace ghidra 37 | #endif 38 | -------------------------------------------------------------------------------- /src/Ghidra/error.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file error.hh 17 | /// \brief Base class for error handling facilities 18 | /// 19 | /// This is also doubles as a place to list the common include files 20 | 21 | #ifndef __ERROR_HH__ 22 | #define __ERROR_HH__ 23 | 24 | #include "types.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace ghidra { 37 | 38 | using std::string; 39 | using std::map; 40 | using std::set; 41 | using std::list; 42 | using std::vector; 43 | using std::pair; 44 | using std::make_pair; 45 | using std::ostream; 46 | using std::istream; 47 | using std::ifstream; 48 | using std::ofstream; 49 | using std::istringstream; 50 | using std::ostringstream; 51 | using std::ios; 52 | using std::dec; 53 | using std::hex; 54 | using std::oct; 55 | using std::setfill; 56 | using std::fixed; 57 | using std::setprecision; 58 | using std::setw; 59 | using std::endl; 60 | using std::ws; 61 | using std::min; 62 | using std::max; 63 | using std::to_string; 64 | using std::piecewise_construct; 65 | using std::forward_as_tuple; 66 | 67 | 68 | /// \brief The lowest level error generated by the decompiler 69 | /// 70 | /// This is the base error for all exceptions thrown by the 71 | /// decompiler. This underived form is thrown for very low 72 | /// level errors that immediately abort decompilation (usually 73 | /// for just a single function). 74 | struct LowlevelError { 75 | string explain; ///< Explanatory string 76 | /// Initialize the error with an explanatory string 77 | LowlevelError(const string &s) { explain = s; } 78 | }; 79 | 80 | /// \brief A generic recoverable error 81 | /// 82 | /// This error is the most basic form of recoverable error, 83 | /// meaning there is some problem that the user did not take 84 | /// into account. 85 | struct RecovError : public LowlevelError { 86 | /// Initialize the error with an explanatory string 87 | RecovError(const string &s) : LowlevelError(s) {} 88 | }; 89 | 90 | /// \brief An error generated while parsing a command or language 91 | /// 92 | /// This error is generated when parsing character data of some 93 | /// form, as in a user command from the console or when parsing 94 | /// C syntax. 95 | struct ParseError : public LowlevelError { // Parsing error 96 | /// Initialize the error with an explanatory string 97 | ParseError(const string &s) : LowlevelError(s) {} 98 | }; 99 | 100 | } // End namespace ghidra 101 | #endif 102 | -------------------------------------------------------------------------------- /src/Ghidra/filemanage.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | // Generic (POSIX) class for searching files and managing paths 17 | 18 | #ifndef __FILEMANAGE_HH__ 19 | #define __FILEMANAGE_HH__ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace ghidra { 28 | 29 | using std::vector; 30 | using std::string; 31 | using std::ifstream; 32 | using std::ostringstream; 33 | 34 | class FileManage { 35 | vector pathlist; // List of paths to search for files 36 | static char separator; 37 | static string buildPath(const vector &pathels,int level); 38 | static bool testDevelopmentPath(const vector &pathels,int level,string &root); 39 | static bool testInstallPath(const vector &pathels,int level,string &root); 40 | public: 41 | void addDir2Path(const string &path); 42 | void addCurrentDir(void); 43 | void findFile(string &res,const string &name) const; // Resolve full pathname 44 | void matchList(vector &res,const string &match,bool isSuffix) const; // List of files with suffix 45 | static bool isDirectory(const string &path); 46 | static void matchListDir(vector &res,const string &match,bool isSuffix,const string &dir,bool allowdot); 47 | static void directoryList(vector &res,const string &dirname,bool allowdot=false); 48 | static void scanDirectoryRecursive(vector &res,const string &matchname,const string &rootpath,int maxdepth); 49 | static void splitPath(const string &full,string &path,string &base); 50 | static bool isAbsolutePath(const string &full) { if (full.empty()) return false; return (full[0] == separator); } 51 | static string discoverGhidraRoot(const char *argv0); 52 | }; 53 | 54 | } // End namespace ghidra 55 | #endif 56 | -------------------------------------------------------------------------------- /src/Ghidra/funcdata.hh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Ghidra/funcdata.hh -------------------------------------------------------------------------------- /src/Ghidra/ghidra_context.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "ghidra_context.hh" 17 | 18 | namespace ghidra { 19 | 20 | const TrackedSet &ContextGhidra::getTrackedSet(const Address &addr) const 21 | 22 | { 23 | cache.clear(); 24 | PackedDecode decoder(glb); 25 | glb->getTrackedRegisters(addr,decoder); 26 | 27 | uint4 elemId = decoder.openElement(ELEM_TRACKED_POINTSET); 28 | decodeTracked(decoder,cache); 29 | decoder.closeElement(elemId); 30 | return cache; 31 | } 32 | 33 | void ContextGhidra::decode(Decoder &decoder) 34 | 35 | { 36 | decoder.skipElement(); // Ignore details handled by ghidra 37 | } 38 | 39 | void ContextGhidra::decodeFromSpec(Decoder &decoder) 40 | 41 | { 42 | decoder.skipElement(); // Ignore details handled by ghidra 43 | } 44 | 45 | } // End namespace ghidra 46 | -------------------------------------------------------------------------------- /src/Ghidra/ghidra_translate.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file ghidra_translate.hh 17 | /// \brief Class for fetching p-code from a Ghidra client 18 | 19 | #ifndef __GHIDRA_TRANSLATE_HH__ 20 | #define __GHIDRA_TRANSLATE_HH__ 21 | 22 | #include "translate.hh" 23 | #include "ghidra_arch.hh" 24 | 25 | namespace ghidra { 26 | 27 | /// \brief An implementation of Translate that queries a Ghidra client for p-code information 28 | /// 29 | /// This class provides: 30 | /// - P-code for instructions and 31 | /// - Register names 32 | /// 33 | /// by sending a request to a Ghidra client and decoding the response. 34 | /// Messages are generally based on an XML format, but p-code responses in particular 35 | /// have a tight internal encoding. 36 | class GhidraTranslate : public Translate { 37 | ArchitectureGhidra *glb; ///< The Ghidra Architecture and connection to the client 38 | mutable map nm2addr; ///< Mapping from register name to Varnode 39 | mutable map addr2nm; ///< Mapping rom Varnode to register name 40 | const VarnodeData &cacheRegister(const string &nm,const VarnodeData &data) const; 41 | void decode(Decoder &decoder); ///< Initialize \b this Translate from a stream 42 | public: 43 | GhidraTranslate(ArchitectureGhidra *g) { glb = g; } ///< Constructor 44 | 45 | virtual void initialize(DocumentStorage &store); 46 | virtual const VarnodeData &getRegister(const string &nm) const; 47 | virtual string getRegisterName(AddrSpace *base,uintb off,int4 size) const; 48 | virtual void getAllRegisters(map ®list) const { 49 | throw LowlevelError("Cannot currently get all registers through this interface"); } 50 | virtual void getUserOpNames(vector &res) const; 51 | virtual int4 oneInstruction(PcodeEmit &emit,const Address &baseaddr) const; 52 | virtual int4 instructionLength(const Address &baseaddr) const { 53 | throw LowlevelError("Cannot currently get instruction length through this interface"); } 54 | virtual int4 printAssembly(AssemblyEmit &emit,const Address &baseaddr) const { 55 | throw LowlevelError("Cannot dump assembly through this interface"); } 56 | }; 57 | 58 | } // End namespace ghidra 59 | #endif 60 | -------------------------------------------------------------------------------- /src/Ghidra/graph.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __GRAPH_HH__ 17 | #define __GRAPH_HH__ 18 | 19 | #include "funcdata.hh" 20 | 21 | namespace ghidra { 22 | 23 | extern void dump_dataflow_graph(Funcdata &data,ostream &s); 24 | extern void dump_controlflow_graph(const string &name,const BlockGraph &graph,ostream &s); 25 | extern void dump_dom_graph(const string &name,const BlockGraph &graph,ostream &s); 26 | 27 | } // End namespace ghidra 28 | #endif 29 | -------------------------------------------------------------------------------- /src/Ghidra/libdecomp.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "libdecomp.hh" 17 | 18 | namespace ghidra { 19 | 20 | void startDecompilerLibrary(const char *sleighhome) 21 | 22 | { 23 | AttributeId::initialize(); 24 | ElementId::initialize(); 25 | CapabilityPoint::initializeAll(); 26 | ArchitectureCapability::sortCapabilities(); 27 | 28 | if (sleighhome != (const char *)0) 29 | SleighArchitecture::scanForSleighDirectories(sleighhome); 30 | } 31 | 32 | void startDecompilerLibrary(const vector &extrapaths) 33 | 34 | { 35 | AttributeId::initialize(); 36 | ElementId::initialize(); 37 | CapabilityPoint::initializeAll(); 38 | ArchitectureCapability::sortCapabilities(); 39 | 40 | for(uint4 i=0;i &extrapaths) 45 | 46 | { 47 | AttributeId::initialize(); 48 | ElementId::initialize(); 49 | CapabilityPoint::initializeAll(); 50 | ArchitectureCapability::sortCapabilities(); 51 | 52 | if (sleighhome != (const char *)0) 53 | SleighArchitecture::scanForSleighDirectories(sleighhome); 54 | 55 | for(uint4 i=0;i &extrapaths); 33 | extern void startDecompilerLibrary(const char *sleighhome,const vector &extrapaths); 34 | 35 | extern void shutdownDecompilerLibrary(void); 36 | 37 | } // End namespace ghidra 38 | #endif 39 | -------------------------------------------------------------------------------- /src/Ghidra/loadimage.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "loadimage.hh" 17 | 18 | namespace ghidra { 19 | 20 | /// This is a convenience method wrapped around the core 21 | /// loadFill() routine. It automatically allocates an array 22 | /// of the desired size, and then fills it with load image data. 23 | /// If the array cannot be allocated, an exception is thrown. 24 | /// The caller assumes the responsibility of freeing the 25 | /// array after it has been used. 26 | /// \param size is the number of bytes to read from the image 27 | /// \param addr is the address of the first byte being read 28 | /// \return a pointer to the desired bytes 29 | uint1 *LoadImage::load(int4 size,const Address &addr) 30 | 31 | { 32 | uint1 *buf = new uint1[ size ]; 33 | if (buf == (uint1 *)0) 34 | throw LowlevelError("Out of memory"); 35 | loadFill(buf,size,addr); 36 | return buf; 37 | } 38 | 39 | RawLoadImage::RawLoadImage(const string &f) : LoadImage(f) 40 | 41 | { 42 | vma = 0; 43 | thefile = (ifstream *)0; 44 | spaceid = (AddrSpace *)0; 45 | filesize = 0; 46 | } 47 | 48 | RawLoadImage::~RawLoadImage(void) 49 | 50 | { 51 | if (thefile != (ifstream *)0) { 52 | thefile->close(); 53 | delete thefile; 54 | } 55 | } 56 | 57 | /// The file is opened and its size immediately recovered. 58 | void RawLoadImage::open(void) 59 | 60 | { 61 | if (thefile != (ifstream *)0) throw LowlevelError("loadimage is already open"); 62 | thefile = new ifstream(filename.c_str()); 63 | if (!(*thefile)) { 64 | string errmsg = "Unable to open raw image file: "+filename; 65 | throw LowlevelError(errmsg); 66 | } 67 | thefile->seekg(0,ios::end); 68 | filesize = thefile->tellg(); 69 | } 70 | 71 | string RawLoadImage::getArchType(void) const 72 | 73 | { 74 | return "unknown"; 75 | } 76 | 77 | void RawLoadImage::adjustVma(long adjust) 78 | 79 | { 80 | adjust = AddrSpace::addressToByte(adjust,spaceid->getWordSize()); 81 | vma += adjust; 82 | } 83 | 84 | void RawLoadImage::loadFill(uint1 *ptr,int4 size,const Address &addr) 85 | 86 | { 87 | uintb curaddr = addr.getOffset(); 88 | uintb offset = 0; 89 | uintb readsize; 90 | 91 | curaddr -= vma; // Get relative offset of first byte 92 | while(size>0) { 93 | if (curaddr >= filesize) { 94 | if (offset == 0) // Initial address not within file 95 | break; 96 | memset(ptr+offset,0,size); // Fill out the rest of the buffer with 0 97 | return; 98 | } 99 | readsize = size; 100 | if (curaddr + readsize > filesize) // Adjust to biggest possible read 101 | readsize = filesize - curaddr; 102 | thefile->seekg(curaddr); 103 | thefile->read((char *)(ptr+offset),readsize); 104 | offset += readsize; 105 | size -= readsize; 106 | curaddr += readsize; 107 | } 108 | if (size > 0) { 109 | ostringstream errmsg; 110 | errmsg << "Unable to load " << dec << size << " bytes at " << addr.getShortcut(); 111 | addr.printRaw(errmsg); 112 | throw DataUnavailError(errmsg.str()); 113 | } 114 | } 115 | 116 | } // End namespace ghidra 117 | -------------------------------------------------------------------------------- /src/Ghidra/loadimage_ghidra.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "loadimage_ghidra.hh" 17 | 18 | namespace ghidra { 19 | 20 | LoadImageGhidra::LoadImageGhidra(ArchitectureGhidra *g) 21 | : LoadImage("ghidra_progam") 22 | 23 | { 24 | glb = g; 25 | } 26 | 27 | void LoadImageGhidra::open(void) 28 | 29 | { 30 | } 31 | 32 | void LoadImageGhidra::close(void) 33 | 34 | { 35 | } 36 | 37 | void LoadImageGhidra::loadFill(uint1 *ptr,int4 size,const Address &inaddr) 38 | 39 | { 40 | glb->getBytes(ptr,size,inaddr); 41 | } 42 | 43 | string LoadImageGhidra::getArchType(void) const 44 | 45 | { 46 | return "ghidra"; 47 | } 48 | 49 | void LoadImageGhidra::adjustVma(long adjust) 50 | 51 | { 52 | throw LowlevelError("Cannot adjust GHIDRA virtual memory"); 53 | } 54 | 55 | } // End namespace ghidra 56 | -------------------------------------------------------------------------------- /src/Ghidra/loadimage_ghidra.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file loadimage_ghidra.hh 17 | /// \brief Use the Ghidra client as a load image 18 | #ifndef __LOADIMAGE_GHIDRA_HH__ 19 | #define __LOADIMAGE_GHIDRA_HH__ 20 | 21 | #include "loadimage.hh" 22 | #include "ghidra_arch.hh" 23 | 24 | namespace ghidra { 25 | 26 | class ArchitectureGhidra; 27 | 28 | /// \brief An implementation of the LoadImage interface using a Ghidra client as the back-end 29 | /// 30 | /// Requests for program bytes are marshaled to a Ghidra client which sends back the data 31 | class LoadImageGhidra : public LoadImage { 32 | ArchitectureGhidra *glb; ///< The owning Architecture and connection to the client 33 | public: 34 | LoadImageGhidra(ArchitectureGhidra *g); ///< Constructor 35 | // virtual ~LoadImage(void) {} 36 | void open(void); ///< Open any descriptors 37 | void close(void); ///< Close any descriptor 38 | virtual void loadFill(uint1 *ptr,int4 size,const Address &addr); 39 | // Read only flags are all controlled through the database interface 40 | virtual string getArchType(void) const; 41 | virtual void adjustVma(long adjust); 42 | }; 43 | 44 | } // End namespace ghidra 45 | #endif 46 | -------------------------------------------------------------------------------- /src/Ghidra/loadimage_xml.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file loadimage_xml.hh 17 | /// \brief Support for programs stored using an XML schema 18 | 19 | #ifndef __LOADIMAGE_XML_HH__ 20 | #define __LOADIMAGE_XML_HH__ 21 | 22 | #include "loadimage.hh" 23 | 24 | namespace ghidra { 25 | 26 | extern AttributeId ATTRIB_ARCH; ///< Marshaling attribute "arch" 27 | 28 | extern ElementId ELEM_BINARYIMAGE; ///< Marshaling element \ 29 | extern ElementId ELEM_BYTECHUNK; ///< Marshaling element \ 30 | 31 | /// \brief Implementation of the LoadImage interface using underlying data stored in an XML format 32 | /// 33 | /// The image data is stored in an XML file in a \ file. 34 | /// The data is encoded in \ and potentially \ files. 35 | class LoadImageXml : public LoadImage { 36 | const Element *rootel; ///< The root XML element 37 | string archtype; ///< The architecture string 38 | const AddrSpaceManager *manage; ///< Manager of addresses 39 | set
readonlyset; ///< Starting address of read-only chunks 40 | map > chunk; ///< Chunks of image data, mapped by address 41 | map addrtosymbol; ///< Symbols sorted by address 42 | mutable map::const_iterator cursymbol; ///< Current symbol being reported 43 | void pad(void); ///< Make sure every chunk is followed by at least 512 bytes of pad 44 | public: 45 | LoadImageXml(const string &f,const Element *el); ///< Constructor 46 | void open(const AddrSpaceManager *m); ///< Read XML tags into the containers 47 | void clear(void); ///< Clear out all the caches 48 | void encode(Encoder &encoder) const; ///< Encode the image to a stream 49 | virtual ~LoadImageXml(void) { clear(); } 50 | virtual void loadFill(uint1 *ptr,int4 size,const Address &addr); 51 | virtual void openSymbols(void) const; 52 | virtual bool getNextSymbol(LoadImageFunc &record) const; 53 | virtual void getReadonly(RangeList &list) const; 54 | virtual string getArchType(void) const { return archtype; } 55 | virtual void adjustVma(long adjust); 56 | }; 57 | 58 | } // End namespace ghidra 59 | #endif 60 | -------------------------------------------------------------------------------- /src/Ghidra/paramid.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PARAMID_HH__ 17 | #define __PARAMID_HH__ 18 | 19 | #include "funcdata.hh" 20 | 21 | namespace ghidra { 22 | 23 | extern ElementId ELEM_PARAMMEASURES; ///< Marshaling element \ 24 | extern ElementId ELEM_PROTO; ///< Marshaling element \ 25 | extern ElementId ELEM_RANK; ///< Marshaling element \ 26 | 27 | class ParamMeasure { 28 | public: 29 | enum ParamIDIO { 30 | INPUT = 0, 31 | OUTPUT = 1 32 | }; 33 | enum ParamRank { 34 | BESTRANK = 1, 35 | DIRECTWRITEWITHOUTREAD = 1, //Output 36 | DIRECTREAD = 2, //Input. Must be same as DIRECTWRITEWITHREAD so that walkforward as part of walkbackward works 37 | // for detecting(not that DIRECTREAD is lower rank that DIRECTWRITEWITHOUTREAD) 38 | DIRECTWRITEWITHREAD = 2, //Output 39 | DIRECTWRITEUNKNOWNREAD = 3, //Output 40 | SUBFNPARAM = 4, //Input 41 | THISFNPARAM = 4, //Output 42 | SUBFNRETURN = 5, //Output 43 | THISFNRETURN = 5, //Input 44 | INDIRECT = 6, //Input or Output 45 | WORSTRANK = 7 46 | }; 47 | struct WalkState { 48 | bool best; 49 | int4 depth; 50 | ParamRank terminalrank; 51 | }; 52 | private: 53 | VarnodeData vndata; 54 | Datatype *vntype; 55 | ParamRank rank; 56 | ParamIDIO io; 57 | int4 numcalls; 58 | void walkforward( WalkState &state, PcodeOp *ignoreop, Varnode *vn ); 59 | void walkbackward( WalkState &state, PcodeOp *ignoreop,Varnode *vn ); 60 | void updaterank( ParamRank rank_in,bool best ) { rank = (best==true) ? min( rank, rank_in ) : max( rank, rank_in ); } 61 | public: 62 | ParamMeasure( const Address &addr, int4 sz, Datatype *dt, ParamIDIO io_in) { 63 | vndata.space=addr.getSpace(); vndata.offset=addr.getOffset(); vndata.size = sz; vntype=dt; io = io_in; rank=WORSTRANK; } 64 | void calculateRank(bool best,Varnode *basevn,PcodeOp *ignoreop); 65 | void encode( Encoder &encoder,ElementId &tag,bool moredetail ) const; 66 | void savePretty( ostream &s,bool moredetail ) const; 67 | int4 getMeasure(void) const { return (int4) rank; } 68 | }; 69 | 70 | class ParamIDAnalysis 71 | { 72 | Funcdata *fd; 73 | list InputParamMeasures; 74 | list OutputParamMeasures; 75 | public: 76 | ParamIDAnalysis( Funcdata *fd_in, bool justproto ); 77 | void encode( Encoder &encoder, bool moredetail ) const; 78 | void savePretty( ostream &s, bool moredetail ) const; 79 | }; 80 | 81 | } // End namespace ghidra 82 | #endif //ifndef __PARAMID_HH__ 83 | -------------------------------------------------------------------------------- /src/Ghidra/prefersplit.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef __PREFERSPLIT_HH__ 17 | #define __PREFERSPLIT_HH__ 18 | 19 | #include "varnode.hh" 20 | 21 | namespace ghidra { 22 | 23 | class Funcdata; // Forward declaration 24 | 25 | extern ElementId ELEM_PREFERSPLIT; ///< Marshaling element \ 26 | 27 | struct PreferSplitRecord { 28 | VarnodeData storage; 29 | int4 splitoffset; // Number of initial bytes (in address order) to split into first piece 30 | bool operator<(const PreferSplitRecord &op2) const; 31 | }; 32 | 33 | class PreferSplitManager { 34 | class SplitInstance { 35 | friend class PreferSplitManager; 36 | int4 splitoffset; 37 | Varnode *vn; 38 | Varnode *hi; // Most significant piece 39 | Varnode *lo; // Least significant piece 40 | public: 41 | SplitInstance(Varnode *v,int4 off) { vn = v; splitoffset = off; hi = (Varnode *)0; lo = (Varnode *)0; } 42 | }; 43 | Funcdata *data; 44 | const vector *records; 45 | vector tempsplits; // Copies of temporaries that need additional splitting 46 | void fillinInstance(SplitInstance *inst,bool bigendian,bool sethi,bool setlo); 47 | void createCopyOps(SplitInstance *ininst,SplitInstance *outinst,PcodeOp *op,bool istemp); 48 | bool testDefiningCopy(SplitInstance *inst,PcodeOp *def,bool &istemp); 49 | void splitDefiningCopy(SplitInstance *inst,PcodeOp *def,bool istemp); 50 | bool testReadingCopy(SplitInstance *inst,PcodeOp *readop,bool &istemp); 51 | void splitReadingCopy(SplitInstance *inst,PcodeOp *readop,bool istemp); 52 | bool testZext(SplitInstance *inst,PcodeOp *op); 53 | void splitZext(SplitInstance *inst,PcodeOp *op); 54 | bool testPiece(SplitInstance *inst,PcodeOp *op); 55 | void splitPiece(SplitInstance *inst,PcodeOp *op); 56 | bool testSubpiece(SplitInstance *inst,PcodeOp *op); 57 | void splitSubpiece(SplitInstance *inst,PcodeOp *op); 58 | bool testLoad(SplitInstance *inst,PcodeOp *op); 59 | void splitLoad(SplitInstance *inst,PcodeOp *op); 60 | bool testStore(SplitInstance *inst,PcodeOp *op); 61 | void splitStore(SplitInstance *inst,PcodeOp *op); 62 | bool splitVarnode(SplitInstance *inst); 63 | void splitRecord(const PreferSplitRecord &rec); 64 | bool testTemporary(SplitInstance *inst); 65 | void splitTemporary(SplitInstance *inst); 66 | public: 67 | void init(Funcdata *fd,const vector *rec); 68 | const PreferSplitRecord *findRecord(Varnode *vn) const; 69 | static void initialize(vector &records); 70 | void split(void); 71 | void splitAdditional(void); 72 | }; 73 | 74 | } // End namespace ghidra 75 | #endif 76 | -------------------------------------------------------------------------------- /src/Ghidra/printjava.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file printjava.hh 17 | /// \brief Classes supporting the java-language back-end to the decompiler 18 | 19 | #ifndef __PRINTJAVA_HH__ 20 | #define __PRINTJAVA_HH__ 21 | 22 | #include "printc.hh" 23 | 24 | namespace ghidra { 25 | 26 | /// \brief Factory and static initializer for the "java-language" back-end to the decompiler 27 | /// 28 | /// The singleton adds itself to the list of possible back-end languages for the decompiler 29 | /// and it acts as a factory for producing the PrintJava object for emitting java-language tokens. 30 | class PrintJavaCapability : public PrintLanguageCapability { 31 | static PrintJavaCapability printJavaCapability; ///< The singleton instance 32 | PrintJavaCapability(void); ///< Singleton constructor 33 | PrintJavaCapability(const PrintJavaCapability &op2); ///< Not implemented 34 | PrintJavaCapability &operator=(const PrintJavaCapability &op); ///< Not implemented 35 | public: 36 | virtual PrintLanguage *buildLanguage(Architecture *glb); 37 | }; 38 | 39 | /// \brief The java-language token emitter 40 | /// 41 | /// This builds heavily on the c-language PrintC emitter. Most operator tokens, the format of 42 | /// function prototypes, and code structuring are shared. Specifics of the java constant pool are handled 43 | /// through the overloaded opCpoolRefOp(). 44 | /// 45 | /// Java data-types are mapped into the decompiler's data-type system in a specific way. The primitives 46 | /// \b int, \b long, \b short, \b byte, \b boolean, \b float, and \b double all map directly. The 47 | /// \b char primitive is treated as a 2 byte unsigned integer. A TypeStruct object holds the field 48 | /// layout for a java class, then java objects get mapped as follows: 49 | /// - Class reference = pointer to TYPE_UINT 50 | /// - Array of \b int, \b long, \b short, or \b byte = pointer to TYPE_INT 51 | /// - Array of \b float or \b double = pointer to TYPE_FLOAT 52 | /// - Array of \b boolean = pointer to TYPE_BOOL 53 | /// - Array of class objects = pointer to TYPE_PTR 54 | /// 55 | /// There are some adjustments to the printing of data-types and LOAD/STORE expressions 56 | /// to account for this mapping. 57 | class PrintJava : public PrintC { 58 | static OpToken instanceof; ///< The \b instanceof keyword 59 | static bool isArrayType(const Datatype *ct); ///< Does the given data-type reference a java array 60 | static bool needZeroArray(const Varnode *vn); ///< Do we need '[0]' syntax. 61 | void resetDefaultsPrintJava(void); ///< Set options that are specific to Java 62 | virtual void printUnicode(ostream &s,int4 onechar) const; 63 | public: 64 | PrintJava(Architecture *g,const string &nm="java-language"); ///< Constructor 65 | virtual void resetDefaults(void); 66 | virtual void docFunction(const Funcdata *fd); 67 | virtual void pushTypeStart(const Datatype *ct,bool noident); 68 | virtual void pushTypeEnd(const Datatype *ct); 69 | virtual bool doEmitWideCharPrefix(void) const { return false; } 70 | virtual void adjustTypeOperators(void); 71 | virtual void opLoad(const PcodeOp *op); 72 | virtual void opStore(const PcodeOp *op); 73 | virtual void opCallind(const PcodeOp *op); 74 | virtual void opCpoolRefOp(const PcodeOp *op); 75 | }; 76 | 77 | } // End namespace ghidra 78 | #endif 79 | -------------------------------------------------------------------------------- /src/Ghidra/raw_arch.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file raw_arch.hh 17 | /// \brief Bare bones capability for treating a file as a raw executable image 18 | #ifndef __RAW_ARCH_HH__ 19 | #define __RAW_ARCH_HH__ 20 | 21 | #include "sleigh_arch.hh" 22 | #include "loadimage.hh" 23 | 24 | namespace ghidra { 25 | 26 | extern ElementId ELEM_RAW_SAVEFILE; ///< Marshaling element \ 27 | 28 | /// \brief Extension point for building an Architecture that reads in raw images 29 | class RawBinaryArchitectureCapability : public ArchitectureCapability { 30 | static RawBinaryArchitectureCapability rawBinaryArchitectureCapability; ///< The singleton instance 31 | RawBinaryArchitectureCapability(void); ///< Singleton 32 | RawBinaryArchitectureCapability(const RawBinaryArchitectureCapability &op2); ///< Not implemented 33 | RawBinaryArchitectureCapability &operator=(const RawBinaryArchitectureCapability &op2); ///< Not implemented 34 | public: 35 | virtual ~RawBinaryArchitectureCapability(void); 36 | virtual Architecture *buildArchitecture(const string &filename,const string &target,ostream *estream); 37 | virtual bool isFileMatch(const string &filename) const; 38 | virtual bool isXmlMatch(Document *doc) const; 39 | }; 40 | 41 | /// \brief Architecture that reads its binary as a raw file 42 | class RawBinaryArchitecture : public SleighArchitecture { 43 | long adjustvma; ///< What address byte 0 of the raw file gets treated as 44 | virtual void buildLoader(DocumentStorage &store); 45 | virtual void resolveArchitecture(void); 46 | virtual void postSpecFile(void); 47 | public: 48 | virtual void encode(Encoder &encoder) const; 49 | virtual void restoreXml(DocumentStorage &store); 50 | RawBinaryArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor 51 | virtual ~RawBinaryArchitecture(void) {} 52 | }; 53 | 54 | } // End namespace ghidra 55 | #endif 56 | -------------------------------------------------------------------------------- /src/Ghidra/string_ghidra.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "string_ghidra.hh" 17 | 18 | namespace ghidra { 19 | 20 | GhidraStringManager::GhidraStringManager(ArchitectureGhidra *g,int4 max) 21 | : StringManager(max) 22 | { 23 | glb = g; 24 | testBuffer = new uint1[max]; 25 | } 26 | 27 | GhidraStringManager::~GhidraStringManager(void) 28 | 29 | { 30 | delete [] testBuffer; 31 | } 32 | 33 | const vector &GhidraStringManager::getStringData(const Address &addr,Datatype *charType,bool &isTrunc) 34 | 35 | { 36 | map::iterator iter; 37 | iter = stringMap.find(addr); 38 | if (iter != stringMap.end()) { 39 | isTrunc = (*iter).second.isTruncated; 40 | return (*iter).second.byteData; 41 | } 42 | 43 | StringData &stringData(stringMap[addr]); 44 | stringData.isTruncated = false; 45 | glb->getStringData(stringData.byteData, addr, charType, maximumChars,stringData.isTruncated); 46 | isTrunc = stringData.isTruncated; 47 | return stringData.byteData; 48 | } 49 | 50 | } // End namespace ghidra 51 | -------------------------------------------------------------------------------- /src/Ghidra/string_ghidra.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file string_ghidra.hh 17 | /// \brief Implementation of the StringManager through the ghidra client 18 | 19 | #ifndef __STRING_GHIDRA_HH__ 20 | #define __STRING_GHIDRA_HH__ 21 | 22 | #include "ghidra_arch.hh" 23 | 24 | namespace ghidra { 25 | 26 | /// \brief Implementation of the StringManager that queries through the ghidra client 27 | /// 28 | /// This acts as a front end to Ghidra's string formats and encodings. 29 | /// The client translates any type of string into a UTF8 representation, and this 30 | /// class stores it for final presentation. Escaping the UTF8 string is left up 31 | /// to the PrintLanguage. 32 | class GhidraStringManager : public StringManager { 33 | ArchitectureGhidra *glb; ///< The ghidra client interface 34 | uint1 *testBuffer; ///< Temporary storage for storing bytes from client 35 | public: 36 | GhidraStringManager(ArchitectureGhidra *g,int4 max); ///< Constructor 37 | virtual ~GhidraStringManager(void); 38 | virtual const vector &getStringData(const Address &addr,Datatype *charType,bool &isTrunc); 39 | }; 40 | 41 | } // End namespace ghidra 42 | #endif 43 | -------------------------------------------------------------------------------- /src/Ghidra/typegrp_ghidra.cc: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "typegrp_ghidra.hh" 17 | 18 | namespace ghidra { 19 | 20 | Datatype *TypeFactoryGhidra::findById(const string &n,uint8 id,int4 sz) 21 | 22 | { 23 | Datatype *ct = TypeFactory::findById(n,id,sz); // Try internal find 24 | if (ct != (Datatype *)0) return ct; 25 | ArchitectureGhidra *ghidra = (ArchitectureGhidra *)glb; 26 | PackedDecode decoder(ghidra); 27 | try { 28 | if (!ghidra->getDataType(n,id,decoder)) // See if ghidra knows about type 29 | return (Datatype *)0; 30 | } 31 | catch(DecoderError &err) { 32 | throw LowlevelError("Decoder error: "+err.explain); 33 | } 34 | ct = decodeType(decoder); // Parse ghidra's type 35 | return ct; 36 | } 37 | 38 | } // End namespace ghidra 39 | -------------------------------------------------------------------------------- /src/Ghidra/typegrp_ghidra.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file typegrp_ghidra.hh 17 | /// \brief Interface for requesting data-type information from a Ghidra client 18 | 19 | #ifndef __TYPEGRP_GHIDRA_HH__ 20 | #define __TYPEGRP_GHIDRA_HH__ 21 | 22 | #include "type.hh" 23 | #include "ghidra_arch.hh" 24 | 25 | namespace ghidra { 26 | 27 | /// \brief An implementation of the TypeFactory interface, query a Ghidra client for data-type information 28 | /// 29 | /// Requests for a specific data-type name and id are marshaled to the Ghidra client, 30 | /// which sends back a description of the data-type. The description is parsed and 31 | /// converted into a Datatype object and cached in this object. 32 | class TypeFactoryGhidra : public TypeFactory { 33 | protected: 34 | virtual Datatype *findById(const string &n,uint8 id,int4 sz); 35 | public: 36 | TypeFactoryGhidra(ArchitectureGhidra *g) : TypeFactory(g) {} ///< Constructor 37 | virtual ~TypeFactoryGhidra(void) {} 38 | }; 39 | 40 | } // End namespace ghidra 41 | #endif 42 | -------------------------------------------------------------------------------- /src/Ghidra/types.h: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * NOTE: Decompiler specific flags, refers to sparc,linux,windows,i386,apple,alpha,powerpc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /* typedefs for getting specific word sizes */ 18 | 19 | #ifndef __TYPES_H__ 20 | #define __TYPES_H__ 21 | 22 | #include 23 | 24 | namespace ghidra { 25 | 26 | // Use of uintm and intm is deprecated. They must currently be set to be 32-bit. 27 | typedef uint32_t uintm; 28 | typedef int32_t intm; 29 | 30 | typedef uint64_t uint8; 31 | typedef int64_t int8; 32 | typedef uint32_t uint4; 33 | typedef int32_t int4; 34 | typedef uint16_t uint2; 35 | typedef int16_t int2; 36 | typedef uint8_t uint1; 37 | typedef int8_t int1; 38 | 39 | /* uintp is intended to be an unsigned integer that is the same size as a pointer */ 40 | typedef uintptr_t uintp; 41 | 42 | #if defined (__x86_64__) || defined (__i386__) 43 | #define HOST_ENDIAN 0 44 | 45 | #else // other platforms (not compatible with g++ 4.8.5) 46 | class Endian { 47 | public: 48 | static constexpr const union { int4 whole; int1 part[4]; } host = { 1 }; 49 | }; 50 | #define HOST_ENDIAN Endian::host.part[3] 51 | #endif 52 | 53 | #if defined(_WINDOWS) 54 | #pragma warning (disable:4312) 55 | #pragma warning (disable:4311) 56 | #pragma warning (disable:4267) 57 | #pragma warning (disable:4018) 58 | #pragma warning (disable:4244) 59 | 60 | /* 61 | The windows standard template library list implementation seems to have a philosophical difference with 62 | the standard regarding the validity of iterators pointing to objects that are moved between containers 63 | (via the splice method) These defines turn off the validity checks 64 | (These have been moved to the VC project spec) 65 | */ 66 | //#define _SECURE_SCL 0 67 | //#define _HAS_ITERATOR_DEBUGGING 0 68 | #endif 69 | 70 | /* 71 | Big integers: These are intended to be arbitrary precison integers. However 72 | for efficiency, these are currently implemented as fixed precision. 73 | So for coding purposes, these should be interpreted as fixed 74 | precision integers that store as big a number as you would ever need. 75 | */ 76 | 77 | typedef int8 intb; /* This is a signed big integer */ 78 | typedef uint8 uintb; /* This is an unsigned big integer */ 79 | 80 | /* 81 | 82 | Other compilation flags 83 | 84 | CPUI_DEBUG -- This is the ONE debug switch that should be passed in 85 | from the compiler, all others are controlled below 86 | */ 87 | 88 | #ifdef CPUI_DEBUG 89 | # define OPACTION_DEBUG 90 | # define PRETTY_DEBUG 91 | //# define __REMOTE_SOCKET__ 92 | //# define TYPEPROP_DEBUG 93 | //# define DFSVERIFY_DEBUG 94 | //# define BLOCKCONSISTENT_DEBUG 95 | //# define MERGEMULTI_DEBUG 96 | //# define VARBANK_DEBUG 97 | #endif 98 | 99 | } // End namespace ghidra 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /src/Ghidra/varnode.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Ghidra/varnode.cc -------------------------------------------------------------------------------- /src/Ghidra/xml_arch.hh: -------------------------------------------------------------------------------- 1 | /* ### 2 | * IP: GHIDRA 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /// \file xml_arch.hh 17 | /// \brief Extension to read executables based on an XML format 18 | #ifndef __XML_ARCH_HH__ 19 | #define __XML_ARCH_HH__ 20 | 21 | #include "sleigh_arch.hh" 22 | #include "loadimage_xml.hh" 23 | 24 | namespace ghidra { 25 | 26 | extern ElementId ELEM_XML_SAVEFILE; ///< Marshaling element \ 27 | 28 | /// \brief Extension for building an XML format capable Architecture 29 | class XmlArchitectureCapability : public ArchitectureCapability { 30 | static XmlArchitectureCapability xmlArchitectureCapability; ///< The singleton instance 31 | XmlArchitectureCapability(void); ///< Singleton 32 | XmlArchitectureCapability(const XmlArchitectureCapability &op2); ///< Not implemented 33 | XmlArchitectureCapability &operator=(const XmlArchitectureCapability &op2); ///< Not implemented 34 | public: 35 | virtual ~XmlArchitectureCapability(void); 36 | virtual Architecture *buildArchitecture(const string &filename,const string &target,ostream *estream); 37 | virtual bool isFileMatch(const string &filename) const; 38 | virtual bool isXmlMatch(Document *doc) const; 39 | }; 40 | 41 | /// \brief An Architecture that loads executables using an XML format 42 | class XmlArchitecture : public SleighArchitecture { 43 | long adjustvma; ///< The amount to adjust the virtual memory address 44 | virtual void buildLoader(DocumentStorage &store); 45 | // virtual void resolveArchitecture(void); ///< Inherit SleighArchitecture's version 46 | virtual void postSpecFile(void); 47 | public: 48 | virtual void encode(Encoder &encoder) const; 49 | virtual void restoreXml(DocumentStorage &store); 50 | XmlArchitecture(const string &fname,const string &targ,ostream *estream); ///< Constructor 51 | virtual ~XmlArchitecture(void) {} 52 | }; 53 | 54 | } // End namespace ghidra 55 | #endif 56 | -------------------------------------------------------------------------------- /src/GhidraExtension/FuncBuildHelper.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/FuncBuildHelper.cpp -------------------------------------------------------------------------------- /src/GhidraExtension/FuncBuildHelper.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/FuncBuildHelper.h -------------------------------------------------------------------------------- /src/GhidraExtension/IDALoadImage.cpp: -------------------------------------------------------------------------------- 1 | #include "IDALoadImage.h" 2 | #include "../Helper/IDAWrapper.h" 3 | #include "VmpArch.h" 4 | #include 5 | 6 | IDALoadImage::IDALoadImage(VmpArchitecture* glb) :ghidra::LoadImage("image") 7 | { 8 | arch = glb; 9 | } 10 | 11 | IDALoadImage::~IDALoadImage() 12 | { 13 | 14 | } 15 | 16 | void IDALoadImage::loadFill(ghidra::uint1* ptr, ghidra::int4 size, const ghidra::Address& addr) 17 | { 18 | IDAWrapper::get_bytes(ptr, size, addr.getOffset(), 0x1); 19 | } 20 | 21 | std::string IDALoadImage::getArchType(void)const 22 | { 23 | if (IDAWrapper::is64BitProgram()) { 24 | return "pei-x86-64"; 25 | } 26 | return "pe-i386"; 27 | } 28 | 29 | void IDALoadImage::adjustVma(long adjust) 30 | { 31 | 32 | } 33 | 34 | void IDALoadImage::getReadonly(ghidra::RangeList& list) const 35 | { 36 | int segCount = get_segm_qty(); 37 | for (int idx = 0; idx < segCount; ++idx) 38 | { 39 | segment_t* pSegment = getnseg(idx); 40 | if (pSegment->perm & SEGPERM_EXEC) { 41 | continue; 42 | } 43 | if (pSegment->perm & SEGPERM_WRITE) { 44 | continue; 45 | } 46 | if (pSegment->perm & SEGPERM_READ) { 47 | list.insertRange(arch->getSpaceByName("const"), pSegment->start_ea, pSegment->end_ea - 1); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/GhidraExtension/IDALoadImage.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Ghidra/loadimage.hh" 3 | 4 | class VmpArchitecture; 5 | 6 | class IDALoadImage:public ghidra::LoadImage 7 | { 8 | public: 9 | IDALoadImage(VmpArchitecture*); 10 | ~IDALoadImage(); 11 | private: 12 | void loadFill(ghidra::uint1* ptr, ghidra::int4 size, const ghidra::Address& addr) override; 13 | std::string getArchType(void) const override; 14 | void adjustVma(long adjust) override; 15 | void getReadonly(ghidra::RangeList& list) const override; 16 | private: 17 | VmpArchitecture* arch; 18 | }; -------------------------------------------------------------------------------- /src/GhidraExtension/PrintManager.cpp: -------------------------------------------------------------------------------- 1 | #include "PrintManager.h" 2 | #include "../Ghidra/printc.hh" 3 | 4 | PrintManager PrintManager::gPrintManager; 5 | 6 | ghidra::PrintLanguage* PrintManager::GetDefaultPrintLanguage(ghidra::Architecture* glb) 7 | { 8 | return new ghidra::PrintC(glb, "c-language"); 9 | } -------------------------------------------------------------------------------- /src/GhidraExtension/PrintManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Ghidra/printlanguage.hh" 3 | 4 | class PrintManager 5 | { 6 | public: 7 | static PrintManager gPrintManager; ///< The singleton instance 8 | ghidra::PrintLanguage* GetDefaultPrintLanguage(ghidra::Architecture* glb); 9 | }; -------------------------------------------------------------------------------- /src/GhidraExtension/VmpAction.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpAction.cpp -------------------------------------------------------------------------------- /src/GhidraExtension/VmpAction.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpAction.h -------------------------------------------------------------------------------- /src/GhidraExtension/VmpArch.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpArch.cpp -------------------------------------------------------------------------------- /src/GhidraExtension/VmpArch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Ghidra/sleigh_arch.hh" 3 | 4 | namespace ghidra 5 | { 6 | class Funcdata; 7 | } 8 | 9 | class VmpNode; 10 | class VmpBasicBlock; 11 | class VmpFunction; 12 | 13 | 14 | class VmpArchitecture :public ghidra::SleighArchitecture 15 | { 16 | public: 17 | enum architecture_e 18 | { 19 | ARCH_INVALID = 0x0, 20 | ARCH_X86, 21 | ARCH_X86_64, 22 | }; 23 | public: 24 | VmpArchitecture(); 25 | ~VmpArchitecture(); 26 | public: 27 | architecture_e ArchType(); 28 | ghidra::Funcdata* AnaVmpHandler(VmpNode* nodeInput); 29 | ghidra::Funcdata* AnaVmpBasicBlock(VmpBasicBlock* basicBlock); 30 | ghidra::Funcdata* AnaVmpFunction(VmpFunction* func); 31 | ghidra::Funcdata* OptimizeBlock(ghidra::Funcdata* fd); 32 | protected: 33 | void buildLoader(ghidra::DocumentStorage& store) override; 34 | void resolveArchitecture(void) override; 35 | private: 36 | bool initVmpArchitecture(); 37 | private: 38 | architecture_e arch_type; 39 | }; 40 | 41 | extern VmpArchitecture* gArch; 42 | -------------------------------------------------------------------------------- /src/GhidraExtension/VmpControlFlow.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpControlFlow.cpp -------------------------------------------------------------------------------- /src/GhidraExtension/VmpControlFlow.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpControlFlow.h -------------------------------------------------------------------------------- /src/GhidraExtension/VmpFunction.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpFunction.cpp -------------------------------------------------------------------------------- /src/GhidraExtension/VmpFunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "VmpControlFlow.h" 3 | 4 | class VmpArchitecture; 5 | class VmpReEngine; 6 | class Vmp3xHandlerFactory; 7 | 8 | class VmpFunction 9 | { 10 | public: 11 | VmpFunction(VmpArchitecture* arch, VmpReEngine* re); 12 | ~VmpFunction(); 13 | void FollowVmp(size_t startAddr); 14 | void CreateGraph(); 15 | VmpArchitecture* Arch(); 16 | VmpReEngine* VmpEngine(); 17 | public: 18 | size_t startAddr; 19 | VmpControlFlow cfg; 20 | private: 21 | VmpArchitecture* arch; 22 | VmpReEngine* reEngine; 23 | }; -------------------------------------------------------------------------------- /src/GhidraExtension/VmpInstruction.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpInstruction.h -------------------------------------------------------------------------------- /src/GhidraExtension/VmpInstructionBuilder.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpInstructionBuilder.cpp -------------------------------------------------------------------------------- /src/GhidraExtension/VmpNode.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpNode.cpp -------------------------------------------------------------------------------- /src/GhidraExtension/VmpNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Helper/UnicornHelper.h" 3 | #include "../Common/VmpCommon.h" 4 | 5 | namespace ghidra 6 | { 7 | class Funcdata; 8 | } 9 | 10 | class VmpNode 11 | { 12 | public: 13 | void append(VmpNode& other); 14 | void clear(); 15 | size_t findRegContext(size_t eip,const std::string& regName); 16 | VmAddress readVmAddress(const std::string& reg_code); 17 | public: 18 | std::vector addrList; 19 | std::vector contextList; 20 | }; -------------------------------------------------------------------------------- /src/GhidraExtension/VmpRule.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpRule.cpp -------------------------------------------------------------------------------- /src/GhidraExtension/VmpRule.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/GhidraExtension/VmpRule.h -------------------------------------------------------------------------------- /src/Helper/AsmBuilder.cpp: -------------------------------------------------------------------------------- 1 | #include "AsmBuilder.h" 2 | #include "../Manager/exceptions.h" 3 | 4 | #ifdef DeveloperMode 5 | #pragma optimize("", off) 6 | #endif 7 | 8 | AsmBuilder::AsmBuilder(ks_arch arch, int mode) 9 | { 10 | ks_err err = ks_open(arch, mode, &ks); 11 | if (err != KS_ERR_OK) { 12 | throw KeystoneException("ERROR: failed on ks_open()"); 13 | } 14 | } 15 | 16 | X86AsmBuilder::X86AsmBuilder():AsmBuilder(KS_ARCH_X86, KS_MODE_32) 17 | { 18 | 19 | } 20 | 21 | X86AsmBuilder::~X86AsmBuilder() 22 | { 23 | 24 | } 25 | 26 | AsmBuilder::~AsmBuilder() 27 | { 28 | if (ks) { 29 | ks_close(ks); 30 | } 31 | } 32 | 33 | std::unique_ptr AsmBuilder::EncodeAsm(size_t addr,const std::string& asmStr) 34 | { 35 | auto ret = std::make_unique(); 36 | size_t count; 37 | if (ks_asm(ks, asmStr.c_str(), addr, &ret->encode, &ret->encode_size, &count)) { 38 | throw AsmBuilderException("EncodeAsm error:" + asmStr); 39 | } 40 | return ret; 41 | } 42 | 43 | X86AsmBuilder& AsmBuilder::X86() 44 | { 45 | static X86AsmBuilder gX86Builder; 46 | return gX86Builder; 47 | } 48 | 49 | std::unique_ptr X86AsmBuilder::pop_reg(const std::string& regName) 50 | { 51 | auto ret = std::make_unique(); 52 | size_t count; 53 | std::string asmStr; 54 | if (regName == "eflags") { 55 | asmStr = "popfd"; 56 | } 57 | else { 58 | asmStr = "pop " + regName; 59 | } 60 | if (ks_asm(ks, asmStr.c_str(), 0, &ret->encode, &ret->encode_size, &count)) { 61 | throw AsmBuilderException("pop_reg error"); 62 | } 63 | return ret; 64 | } 65 | 66 | std::unique_ptr X86AsmBuilder::push_reg(const std::string& regName) 67 | { 68 | auto ret = std::make_unique(); 69 | size_t count; 70 | std::string asmStr; 71 | if (regName == "eflags") { 72 | asmStr = "PUSHFD"; 73 | } 74 | else { 75 | asmStr = "PUSH " + regName; 76 | } 77 | if (ks_asm(ks, asmStr.c_str(), 0, &ret->encode, &ret->encode_size, &count)) { 78 | throw AsmBuilderException("push_reg error"); 79 | } 80 | return ret; 81 | } 82 | 83 | std::unique_ptr X86AsmBuilder::push_const(size_t val) 84 | { 85 | auto ret = std::make_unique(); 86 | size_t count; 87 | std::string asmName = "PUSH " + std::to_string(val); 88 | if (ks_asm(ks, asmName.c_str(), 0, &ret->encode, &ret->encode_size, &count)) { 89 | throw AsmBuilderException("push_const error"); 90 | } 91 | return ret; 92 | } 93 | 94 | #ifdef DeveloperMode 95 | #pragma optimize("", on) 96 | #endif -------------------------------------------------------------------------------- /src/Helper/AsmBuilder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | class X86AsmBuilder; 7 | 8 | class AsmEncodeBuffer 9 | { 10 | public: 11 | AsmEncodeBuffer() 12 | { 13 | encode = nullptr; 14 | encode_size = 0x0; 15 | } 16 | ~AsmEncodeBuffer() { 17 | if (encode) { 18 | ks_free(encode); 19 | encode = nullptr; 20 | } 21 | } 22 | unsigned char* encode; 23 | size_t encode_size; 24 | }; 25 | 26 | class AsmBuilder 27 | { 28 | public: 29 | AsmBuilder(ks_arch arch, int mode); 30 | ~AsmBuilder(); 31 | static X86AsmBuilder& X86(); 32 | std::unique_ptr EncodeAsm(size_t addr, const std::string& asmStr); 33 | public: 34 | ks_engine* ks = nullptr; 35 | }; 36 | 37 | class X86AsmBuilder :public AsmBuilder 38 | { 39 | public: 40 | X86AsmBuilder(); 41 | ~X86AsmBuilder(); 42 | std::unique_ptr push_reg(const std::string& regName); 43 | std::unique_ptr pop_reg(const std::string& regName); 44 | std::unique_ptr push_const(size_t val); 45 | }; -------------------------------------------------------------------------------- /src/Helper/GhidraHelper.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Helper/GhidraHelper.h -------------------------------------------------------------------------------- /src/Helper/IDAWrapper.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Helper/IDAWrapper.cpp -------------------------------------------------------------------------------- /src/Helper/IDAWrapper.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Helper/IDAWrapper.h -------------------------------------------------------------------------------- /src/Helper/UnicornHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | enum x86_reg; 7 | struct cs_x86_op; 8 | 9 | struct reg_context 10 | { 11 | std::uint32_t EAX; 12 | std::uint32_t ECX; 13 | std::uint32_t EDX; 14 | std::uint32_t EBX; 15 | std::uint32_t ESP; 16 | std::uint32_t EBP; 17 | std::uint32_t ESI; 18 | std::uint32_t EDI; 19 | std::uint32_t EIP; 20 | std::uint32_t EFLAGS; 21 | public: 22 | std::uint32_t ReadReg(x86_reg reg); 23 | std::uint32_t ReadMemReg(cs_x86_op& op); 24 | std::uint32_t ReadReg(const std::string& regName); 25 | }; 26 | 27 | std::string GetX86RegName(x86_reg reg); 28 | 29 | class VmpUnicornContext 30 | { 31 | public: 32 | static std::unique_ptr DefaultContext(); 33 | static size_t DefaultEsp(); 34 | void SetVmJmpVal(const std::string& reg_stack, size_t newVal); 35 | void FixVmJmpVal(const std::string& reg_stack, size_t newVal); 36 | void SetVmCodeVal(const std::string& reg_code, size_t newVal); 37 | public: 38 | reg_context context; 39 | size_t stackCodeBase; 40 | std::vector stackBuffer; 41 | }; -------------------------------------------------------------------------------- /src/Helper/VmpBlockAnalyzer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Helper/VmpBlockAnalyzer.cpp -------------------------------------------------------------------------------- /src/Helper/VmpBlockAnalyzer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ghidra 7 | { 8 | class Funcdata; 9 | class Varnode; 10 | class PcodeOp; 11 | class BlockBasic; 12 | } 13 | 14 | struct VmpRotateContext; 15 | 16 | class DeepStackFix 17 | { 18 | public: 19 | int FixAllRam(ghidra::Funcdata* fd); 20 | private: 21 | bool FixStoreRam(ghidra::PcodeOp* curOp); 22 | bool FixLoadRam(ghidra::PcodeOp* curOp); 23 | z3::expr EvaluateVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 24 | z3::expr EvaluatePcodeOp(z3::context& ctx, ghidra::PcodeOp* defOp); 25 | z3::expr EvalutaeStackVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 26 | protected: 27 | ghidra::Funcdata* fd = nullptr; 28 | ghidra::BlockBasic* bb = nullptr; 29 | }; 30 | 31 | class RotateContextAnalyzer 32 | { 33 | public: 34 | RotateContextAnalyzer(ghidra::Funcdata* func) { 35 | fd = func; 36 | }; 37 | bool UpdateRotateContext(VmpRotateContext& old_ctx, VmpRotateContext& new_ctx); 38 | private: 39 | bool getEndStackOffset(int& outOffset); 40 | z3::expr EvaluateVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 41 | z3::expr EvaluatePcodeOp(z3::context& ctx, ghidra::PcodeOp* defOp); 42 | z3::expr EvalutaeStackVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 43 | private: 44 | VmpRotateContext* oldCtx = nullptr; 45 | ghidra::Funcdata* fd = nullptr; 46 | ghidra::BlockBasic* bb = nullptr; 47 | }; 48 | 49 | class VmpBranchAnalyzer 50 | { 51 | public: 52 | VmpBranchAnalyzer(ghidra::Funcdata* func) { 53 | fd = func; 54 | }; 55 | std::vector GuessVmpBranch(); 56 | private: 57 | std::vector guessConditionalBranch(z3::expr& expr); 58 | private: 59 | z3::expr EvaluatePcodeOp(z3::context& ctx, ghidra::PcodeOp* defOp); 60 | z3::expr EvaluateLoadVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 61 | z3::expr EvaluateVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 62 | z3::expr EvalutaeStackVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 63 | private: 64 | ghidra::Funcdata* fd = nullptr; 65 | ghidra::BlockBasic* bb = nullptr; 66 | public: 67 | bool bLoaded = false; 68 | }; 69 | 70 | class VmpExitCallAnalyzer 71 | { 72 | public: 73 | VmpExitCallAnalyzer() {}; 74 | size_t GuessExitCallAddr(ghidra::Funcdata* fd); 75 | private: 76 | bool getEndStackOffset(int& outOffset); 77 | z3::expr EvaluatePcodeOp(z3::context& ctx, ghidra::PcodeOp* defOp); 78 | z3::expr EvaluateVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 79 | z3::expr EvalutaeStackVarnode(z3::context& ctx, ghidra::PcodeOp* op, ghidra::Varnode* vn); 80 | private: 81 | ghidra::Funcdata* fd = nullptr; 82 | ghidra::BlockBasic* bb = nullptr; 83 | }; -------------------------------------------------------------------------------- /src/IDAPlugin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class IDAPlugin; 8 | class MenuRevampire :public action_handler_t 9 | { 10 | public: 11 | MenuRevampire(IDAPlugin* plugin); 12 | ~MenuRevampire(); 13 | void AttachMainMenu(TWidget* view, TPopupMenu* p); 14 | void AttachGraphMenu(TWidget* view, TPopupMenu* p); 15 | private: 16 | int activate(action_activation_ctx_t* ctx)override; 17 | action_state_t idaapi update(action_update_ctx_t* ctx) override; 18 | private: 19 | IDAPlugin* ida; 20 | }; 21 | 22 | class IDAPlugin :public plugmod_t 23 | { 24 | public: 25 | IDAPlugin(); 26 | ~IDAPlugin(); 27 | virtual bool idaapi run(size_t) override; 28 | public: 29 | MenuRevampire gMenu_Revampire; 30 | }; -------------------------------------------------------------------------------- /src/Manager/DisasmManager.cpp: -------------------------------------------------------------------------------- 1 | #include "DisasmManager.h" 2 | #include "SectionManager.h" 3 | #include "../Helper/IDAWrapper.h" 4 | #include "exceptions.h" 5 | #include 6 | 7 | csh DisasmManager::handle; 8 | 9 | RawInstruction::RawInstruction() 10 | { 11 | raw = cs_malloc(DisasmManager::handle); 12 | if (raw == nullptr) { 13 | throw DisasmException("cs_malloc error"); 14 | } 15 | } 16 | 17 | RawInstruction::~RawInstruction() 18 | { 19 | cs_free(raw, 1); 20 | } 21 | 22 | void RawInstruction::PrintRaw(std::ostream& ss) 23 | { 24 | ss << "0x" << std::hex << raw->address << "\t" << raw->mnemonic << " " << raw->op_str << "\n"; 25 | } 26 | 27 | DisasmManager::DisasmManager() 28 | { 29 | cs_err err; 30 | if (IDAWrapper::is64BitProgram()) { 31 | err = cs_open(CS_ARCH_X86, CS_MODE_64, &handle); 32 | } 33 | else { 34 | err = cs_open(CS_ARCH_X86, CS_MODE_32, &handle); 35 | } 36 | if (err != CS_ERR_OK) { 37 | throw DisasmException("cs_open error"); 38 | } 39 | cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON); 40 | } 41 | 42 | DisasmManager& DisasmManager::Main() 43 | { 44 | static DisasmManager gMainDisasm; 45 | return gMainDisasm; 46 | } 47 | 48 | DisasmManager::~DisasmManager() 49 | { 50 | cs_close(&handle); 51 | } 52 | 53 | 54 | 55 | std::unique_ptr DisasmManager::DecodeInstruction(size_t addr) 56 | { 57 | std::unique_ptr retIns = std::make_unique(); 58 | unsigned char tmpInsBuffer[16] = { 0 }; 59 | IDAWrapper::get_bytes(tmpInsBuffer, 16, addr, 0x1); 60 | size_t maxInsLen = 16; 61 | unsigned char* pInsBuf = tmpInsBuffer; 62 | if (cs_disasm_iter(DisasmManager::handle, (const uint8_t**)&pInsBuf, &maxInsLen, (uint64_t*)&addr, retIns->raw)) { 63 | return retIns; 64 | } 65 | return nullptr; 66 | } 67 | 68 | bool DisasmManager::IsBranchInstruction(cs_insn* ins) 69 | { 70 | if (ins->id >= X86_INS_JAE && ins->id <= X86_INS_JS) { 71 | return true; 72 | } 73 | return false; 74 | } 75 | 76 | bool DisasmManager::IsE8Call(cs_insn* ins) 77 | { 78 | if (ins->id != X86_INS_CALL) { 79 | return false; 80 | } 81 | if (ins->detail->x86.opcode[0] != 0xE8) { 82 | return false; 83 | } 84 | return true; 85 | } -------------------------------------------------------------------------------- /src/Manager/DisasmManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "../Common/VmpCommon.h" 5 | 6 | class vm_inst 7 | { 8 | public: 9 | vm_inst() {}; 10 | virtual ~vm_inst() {}; 11 | public: 12 | virtual VmAddress GetAddress() = 0; 13 | virtual bool IsRawInstruction() = 0; 14 | virtual void PrintRaw(std::ostream& ss) = 0; 15 | }; 16 | 17 | class RawInstruction :public vm_inst 18 | { 19 | public: 20 | RawInstruction(); 21 | ~RawInstruction(); 22 | VmAddress GetAddress() override { return raw->address; }; 23 | bool IsRawInstruction() override { return true; }; 24 | void PrintRaw(std::ostream& ss) override; 25 | public: 26 | cs_insn* raw; 27 | }; 28 | 29 | class DisasmManager 30 | { 31 | public: 32 | static DisasmManager& Main(); 33 | DisasmManager(); 34 | ~DisasmManager(); 35 | public: 36 | static bool IsBranchInstruction(cs_insn* ins); 37 | static bool IsE8Call(cs_insn* ins); 38 | std::unique_ptr DecodeInstruction(size_t addr); 39 | public: 40 | static csh handle; 41 | }; -------------------------------------------------------------------------------- /src/Manager/SectionManager.cpp: -------------------------------------------------------------------------------- 1 | #include "SectionManager.h" 2 | #include 3 | #include 4 | 5 | static size_t AlignByMemory(size_t originValue, size_t alignment) 6 | { 7 | size_t reminder = originValue / alignment; 8 | size_t mod = originValue % alignment; 9 | if (mod != 0) { 10 | reminder += 1; 11 | } 12 | return reminder * alignment; 13 | } 14 | 15 | SectionManager& SectionManager::Main() 16 | { 17 | static SectionManager gMainSection; 18 | return gMainSection; 19 | } 20 | 21 | SectionManager::SectionManager() 22 | { 23 | InitSectionManager(); 24 | } 25 | 26 | bool SectionManager::InitSectionManager() 27 | { 28 | segList.clear(); 29 | int segCount = get_segm_qty(); 30 | unsigned int bufSize = 0; 31 | for (int idx = 0; idx < segCount; ++idx) 32 | { 33 | SegmentInfomation tmpInfo; 34 | segment_t* pSegment = getnseg(idx); 35 | tmpInfo.segStart = pSegment->start_ea; 36 | tmpInfo.segSize = pSegment->size(); 37 | bufSize += tmpInfo.segSize; 38 | qstring tmpSectionName; 39 | get_segm_name(&tmpSectionName, pSegment); 40 | tmpInfo.segName = std::string(tmpSectionName.c_str(), tmpSectionName.length()); 41 | tmpInfo.segData.resize(pSegment->size()); 42 | get_bytes(&tmpInfo.segData[0], pSegment->size(), pSegment->start_ea, GMB_READALL); 43 | segList.push_back(tmpInfo); 44 | } 45 | return true; 46 | } 47 | 48 | unsigned char* SectionManager::LinearAddrToVirtualAddr(size_t LinerAddr) 49 | { 50 | unsigned int index = saveIndex; 51 | for (unsigned int n = 0; n < segList.size(); ++n) { 52 | unsigned int endAddr = segList[index].segStart + segList[index].segSize; 53 | if (LinerAddr >= segList[index].segStart && LinerAddr < endAddr) { 54 | unsigned int offset = LinerAddr - segList[index].segStart; 55 | saveIndex = index; 56 | return &segList[index].segData[offset]; 57 | } 58 | ++index; 59 | if (index == segList.size()) { 60 | index = 0; 61 | } 62 | } 63 | return 0; 64 | } 65 | 66 | int SectionManager::SectionIndex(size_t addr) 67 | { 68 | for (unsigned int n = 0; n < segList.size(); ++n) { 69 | if (addr >= segList[n].segStart && addr < segList[n].segStart + segList[n].segSize) { 70 | return n; 71 | } 72 | } 73 | return -1; 74 | } -------------------------------------------------------------------------------- /src/Manager/SectionManager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Manager/SectionManager.h -------------------------------------------------------------------------------- /src/Manager/VmpVersionManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Manager/VmpVersionManager.cpp -------------------------------------------------------------------------------- /src/Manager/VmpVersionManager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Manager/VmpVersionManager.h -------------------------------------------------------------------------------- /src/Manager/exceptions.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Manager/exceptions.cpp -------------------------------------------------------------------------------- /src/Manager/exceptions.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/Manager/exceptions.h -------------------------------------------------------------------------------- /src/VmpCore/VmpBlockBuilder.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/VmpCore/VmpBlockBuilder.cpp -------------------------------------------------------------------------------- /src/VmpCore/VmpBlockBuilder.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/VmpCore/VmpBlockBuilder.h -------------------------------------------------------------------------------- /src/VmpCore/VmpReEngine.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/VmpCore/VmpReEngine.cpp -------------------------------------------------------------------------------- /src/VmpCore/VmpReEngine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../GhidraExtension/VmpFunction.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class VmpArchitecture; 11 | 12 | class Vmp3xHandlerFactory 13 | { 14 | public: 15 | struct VmpHandlerRange 16 | { 17 | size_t startAddr; 18 | size_t endAddr; 19 | VmpHandlerRange() { 20 | startAddr = 0x0; 21 | endAddr = 0x0; 22 | } 23 | VmpHandlerRange(size_t from, size_t to) { 24 | startAddr = from; 25 | endAddr = to; 26 | } 27 | bool operator<(const VmpHandlerRange& other) const 28 | { 29 | return std::tie(startAddr, endAddr) < std::tie(other.startAddr, other.endAddr); 30 | } 31 | template 32 | void serialize(Archive& ar) 33 | { 34 | ar(startAddr, endAddr); 35 | } 36 | }; 37 | public: 38 | Vmp3xHandlerFactory(); 39 | ~Vmp3xHandlerFactory(); 40 | bool LoadHandlerPattern(); 41 | void SaveHandlerPattern(); 42 | private: 43 | void initWorkingDirectory(); 44 | public: 45 | std::map> handlerPatternMap; 46 | private: 47 | std::string workingDir; 48 | }; 49 | 50 | class VmpReEngine 51 | { 52 | public: 53 | VmpReEngine(); 54 | ~VmpReEngine(); 55 | static VmpReEngine& Instance(); 56 | public: 57 | void PrintGraph(size_t startAddr); 58 | void MarkVmpEntry(size_t startAddr); 59 | void Decompile(size_t startAddr); 60 | void Decompile_IDA(size_t startAddr); 61 | VmpArchitecture* Arch(); 62 | Vmp3xHandlerFactory& HandlerCache(); 63 | private: 64 | VmpFunction* makeFunction(size_t startAddr); 65 | void clearFunction(size_t startAddr); 66 | void clearAllFunction(); 67 | private: 68 | VmpArchitecture* arch = nullptr; 69 | Vmp3xHandlerFactory handlerFactory; 70 | std::list> funcCache; 71 | }; -------------------------------------------------------------------------------- /src/VmpCore/VmpTraceFlowGraph.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/VmpCore/VmpTraceFlowGraph.cpp -------------------------------------------------------------------------------- /src/VmpCore/VmpTraceFlowGraph.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/VmpCore/VmpTraceFlowGraph.h -------------------------------------------------------------------------------- /src/VmpCore/VmpUnicorn.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/VmpCore/VmpUnicorn.cpp -------------------------------------------------------------------------------- /src/VmpCore/VmpUnicorn.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fjqisba/VmpHelper/b45d19795f2969c6b50f5f1dee035c09a4009d52/src/VmpCore/VmpUnicorn.h -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "IDAPlugin.h" 6 | 7 | //-------------------------------------------------------------------------- 8 | static plugmod_t* idaapi init() 9 | { 10 | if (!is_idaq()) { 11 | return nullptr; 12 | } 13 | //only support x86 currently 14 | std::string procName = inf.procname; 15 | if (procName != "metapc") { 16 | return nullptr; 17 | } 18 | return new IDAPlugin(); 19 | } 20 | 21 | //-------------------------------------------------------------------------- 22 | static char comment[] = "It's a tool used to fuck vmp"; 23 | 24 | //-------------------------------------------------------------------------- 25 | // 26 | // PLUGIN DESCRIPTION BLOCK 27 | // 28 | //-------------------------------------------------------------------------- 29 | 30 | plugin_t PLUGIN = 31 | { 32 | IDP_INTERFACE_VERSION, 33 | PLUGIN_MULTI, // The plugin can work with multiple idbs in parallel 34 | init, // initialize 35 | nullptr, 36 | nullptr, 37 | comment, // long comment about the plugin 38 | nullptr, // multiline help about the plugin 39 | "Revampire", // the preferred short name of the plugin 40 | nullptr, // the preferred hotkey to run the plugin 41 | }; -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$cmkr": "This file is automatically generated from cmake.toml - DO NOT EDIT", 3 | "$cmkr-url": "https://github.com/build-cpp/cmkr", 4 | "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", 5 | "dependencies": [ 6 | "keystone", 7 | "unicorn", 8 | "z3" 9 | ], 10 | "description": "", 11 | "name": "revampire", 12 | "version-string": "" 13 | } 14 | --------------------------------------------------------------------------------