171 Commits

Author SHA1 Message Date
dependabot[bot] 577130de8a Bump protobuf from 3.2.0 to 3.15.0 in /tools (#778)
Bumps [protobuf](https://github.com/protocolbuffers/protobuf) from 3.2.0 to 3.15.0.
- [Release notes](https://github.com/protocolbuffers/protobuf/releases)
- [Changelog](https://github.com/protocolbuffers/protobuf/blob/master/generate_changelog.py)
- [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.2.0...v3.15.0)

---
updated-dependencies:
- dependency-name: protobuf
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-10 23:51:05 -05:00
burntfalafel 79e3f9180a Fixed "could not connect to display" error (#771)
This is a pertaining issue in Linux systems where the DISPLAY variable isn't forwarded.

The error which is fixed is; "QXcbConnection: Could not connect to display". Users before have raised issues on this [here](https://github.com/lifting-bits/mcsema/issues?q=QXcbConnection%3A+Could+not+connect+to+display)
2021-12-15 11:00:41 -05:00
Eric Kilmer e42f45ffff Remove most Python2 references (#742)
* Remove most Python2 references

Still left some references to python2 for helper scripts since they
aren't tested (afaik) in CI

* Fix CI
2021-03-05 16:11:23 -05:00
Eric Kilmer aa49fcc4fb Support LLVM 11 (#729)
* Add guards based on LLVM version for 11 compatibility

* Use remill LLVM 11 compat headers

* CI support for LLVM 11
2021-02-13 11:22:32 -05:00
Peter Goodman 21970a5cfd Fixes one egregious bug in how we alias registers. What would happen is that AL/AH, DL/DH, etc. would all map to the same alias because their containing register and types would be the same. Modified register aliases to have the form <name>_<offset>_<type>. Also fixed an issue in mcsema-disass where the main function wouldn't be recognized as a function, and thus not lifted. (#710) 2020-11-11 18:07:48 -05:00
Peter Goodman b0f7790f43 Sparc support (#709)
* Adds sparc support; formats files

* Update the readme and walkthrough

* Minor tweaks to readme/walkthrough

* Update ci.yml
2020-11-05 12:59:20 -05:00
Peter Goodman ecc8ba9289 Fixes Issue #704 (#705) 2020-10-19 14:35:51 -04:00
Aiethel fa2d4b39a9 Update dyninst frontend (#701)
* cmake: Set c++ standard to c++17.

* dyninst: Properly set is_referenced_by_data if bb is target of data reference.

* dyninst: Always set some value to is_reference_by_data field.

Co-authored-by: Peter Goodman <peter@trailofbits.com>
2020-10-16 15:00:09 -04:00
Peter Goodman d9bbd1ea7c Python 3 support for mcsema-disass. (#699)
* Python 3 support for mcsema-disass.

* Conditional Python3 installation libraries

* Add conditional check for Python2 also

* Update CMakeLists.txt

Make the install options for py2/3 always available.

* Fix CI tool name

* Update flow.py

Co-authored-by: Eric Kilmer <eric.d.kilmer@gmail.com>
2020-10-06 16:19:52 -04:00
Peter Goodman 31f267bd5f Cmake refactor (#693)
* Update to latest remill APIs and way of using CMake.

* Minor fixes

* Bug fixes for AArch64

* Tweaks

* Adds some nifty functionality useful for debugging some aarch64 bugs

* Fixes a subtle bug

* Bug fixes

* Make the test suite use explicit args

* Bug fix in xrefs

* Disable tests for now
2020-09-22 23:22:56 -04:00
Artem Dinaburg f5aa430e3a Detailed Version Information (#684)
Emit version information with git commit hash, commit date, message, and author.
2020-08-11 02:03:37 -04:00
Peter Goodman c002b8505c Formats the code with clang-format and my additional stylistic mojojojo (#682) 2020-08-05 16:14:01 -04:00
Peter Goodman 2d55d02cc3 API improvements. Must be used with the api_improvements branches of Remill and Anvill (#666)
* API improvements. Must be used with the api_improvements branch of both Remill and McSema

fixes for x86 and running the lifted code with klee

* Update dockerfile to clone anvill

* update remill commit id

* Add python3 to dockerfile

* update python3

* disable abi script

* Updated cmake to find anvill

* Update main.cpp

* update find_package for anvill

* WIP:updated prebuild cfg

* update prebuild cfg files

* enable abi build for testsuite

* Fix memory leak

* install missing package for testcases

* frontend: Reflect cfg file changes in dyninst frontend.

* frontend: Update local files copyrights to reflect overall change to agplv3.

* fix failing testcases

* update test cfgs

* Fix test failure with local state pointer

* set the flag to use local state_ptr in default mode

Co-authored-by: kumarak <iit.akshay@gmail.com>
Co-authored-by: Lukas Korencik <xkorenc1@fi.muni.cz>
2020-07-23 02:14:56 -04:00
Artem Dinaburg 28dd4a717d Set up Github Actions and use a new Dockerfile based on the remill image (#650)
* Set up Github Actions and use a new Dockerfile based on the remill image
2020-05-07 02:04:07 -04:00
meme 8386165641 Fix KeyError issue with AArch64 targets (#641)
The key look-up assumes proper string conversion to "cdecl" which appears to not be the case on the latest Binary Ninja development build, thus: `KeyError: <calling convention: aarch64 cdecl>` occurs. By coercing to a string, this issue is fixed.
2020-04-08 19:54:48 -04:00
Aiethel 797dbf152b lift: Fix bug with ABILoader options attribute lifetime. (#629) 2020-02-21 19:16:28 -05:00
Aiethel 8ecfe165ef Various improvements (#628)
* bc: Inline calls to semantic functions and wrappers manually.

* bc: Inline calls to semantics and wrappers only if some flags are set.

* Refactor code that is responsible for abi libs loading.

* Wrap global pointers in RAII.

* Update .remill_commit_id

Co-authored-by: Peter Goodman <peter.goodman@gmail.com>
2020-02-10 13:20:05 -05:00
Peter Goodman 39794fcaa6 Attempt at fixing Issue #623. (#626)
* Attempt at fixing Issue #623.

* Fixes

* Update refs.py
2020-01-15 00:23:00 -05:00
Auxy 44ff9c2d9b Migrate IDA7 backend to latest API (#625)
* migrate segment.py API to IDA 7+

* migrate table.py API to IDA7+ version

Co-authored-by: Peter Goodman <peter.goodman@gmail.com>
2020-01-14 18:56:33 -05:00
Peter Goodman 5278102cad Various useful fixes (#624) 2020-01-10 16:05:37 -05:00
Peter Goodman d04fc23dbd Fixes #558 and fixes #603 (#620) 2020-01-10 15:34:17 -05:00
kumarak 112ccdabd9 Fix the base/index register for memory operand (#622) 2020-01-10 14:08:17 -05:00
Auxy d4b7477272 remove deprecated function to support IDA7.4 (#621) 2020-01-09 02:09:41 -05:00
Peter Goodman 46362c1f69 Function annotations (#619)
* Annotate lifted functions

* Annotate and Tie entrypoints

* Annotate external functions

* Annote _attach_call

* Update comments

* Simplify code that generated VerifyRegState

Co-authored-by: Aiethel <korencikl@gmail.com>
2020-01-08 17:35:35 -05:00
Aiethel 0e11aa0a7d Refactor abi libs loading (#596)
* lift: Filter function from abi_libs based on other flags

* lift: C++11 compatibility

* lift: Change severity of logs when IR prototype of ext function is not used.
2019-10-27 23:29:48 +01:00
Peter Goodman 782bd1dcfa Update for new remill APIs (#595)
* Update for new remill APIs

* Update remill commit id

* Cleanups

* resolved one issue
2019-10-27 17:48:43 -04:00
Alessandro Gario 1a96bd3712 Update links and remotes to the new organization name (#598)
* Docs: Update links with the new organization name

* CI/Travis: Update remotes with the new organization name

* mcsema-disass: Update links with the new organization name

* Dockerfile: Update remotes with the new organization name
2019-10-27 12:56:23 -04:00
Aiethel d134f3ad44 Misc update (#592)
* Update .remill_commit_id

* Add referecnes to Dyninst frontend README in top-level README

* Expand dyninst frontend local README

* Add whitespace to separate lines

* Update README.md
2019-10-09 15:32:12 -04:00
Aiethel bb1cac3e52 Issue 583 (#587)
* Change required Dyninst version

* Function blocks are explicitly checked for successors if they end with jump

* Whitespace

* Fix compile warning about signedness

* Fix compile warning about signedness

* Remove redundant recursion check for outgoing edge from bb

* Adds Section default initialization

* Whitespaces

* Early return

* Displacement is considered only if operand cannot be statically calculated

* ControlFlowOperand at the end is not needed, it is included in succs of bb

* Soften OffsetTable::Match from FATAL to WARNING if targets are empty

* Rework resolution of outgoing edges of bb

* Use ParseAPI::Function::contains instead of manual search

* Remove log message that was too verbose

* Soften heuristic to calculate offset tables as it was too strict

* Fix typo in comment

* Offset tables are now brute-forced if there are no candidates

* Improve algorithm to recognize MemoryDisplacements

* Better error message if bb succ are not determined correctly
2019-09-05 11:06:57 -04:00
Aiethel 6626f18d95 Dyninst master (#551)
* Before refactor & change of code style

* Rename files to match the rest of McSema

* Remove ArgParser, add glog and gflags

* Remove old files

* Rename some flags to match ida frontend

* Small test improvements

* Abolish ExternalFunc, which is reborn as POD

* Big code style sweep

* Renaming of variables

* Add CHECKs in main

* Main can be foung in stripped binaries

* WIP: Jump has lea-like hanlding, xrefs are search according to ParseAPI instead of SymtabAPI

* WIP: Stripped binaries are now trying to name init, fini

* WIP segment xref

* WIP xrefs are found in data, rodata, needs bss + cleanup

* SymbolMap is now container for all possible targets of xrefs

* Xrefs in rodata, data should be resolved correctly

* Bss self xrefs

* WIP Smarter tryEval

* Cleanup with DataXrefs

* No more of .got.plt stubs

* WIP: Try to locate missing functions via xref

* WIP More passes are now run to parse new functions

* WIP Safe point

* WIP: Displacement

* WIP aligment when searching for xrefs is taken into account

* Addresses stored in all data section are now inspected as potential entries of functions

* Need to search for code refs and parse in .*_array as well

* Messy as hell but everything seems to work

* WIP search for main now works in pie code (lea 0x...(%rip),...)

* Forgot to parse newly found functions from _start

* Bunch of hotfixes, preparing for cleaning

* Small code style chnages, bunch of comments to not get lost after weekend

* Externals variables now have imaginary addr

* MagicSection is now separate class, ExternalFunctions write themselves

* WIP relocations are now working, needs cleanup

* Remove throw, preparing to clean up xref handling

* Update README

* Base of DisassContext structure

* Starting to remove things from CFGWriter

* SectionManager is now global

* Managers are now global, to make CFGWriter smaller

* Cleanup

* Segment variables and magic section are now from context

* External and global variables are part of context

* init/fini now renamed based on information from symtab.isStripped()

* External_funcs are now in context

* Fixing tryParse bug

TryParse of segment ended too soon as end was calculated horribly
wrong and I am amazed it actually worked

* Data sections now use only tryParse to get xrefs and vars

* Refactor mistake

* Correctly parsing xrefs on the end of segment

Off by one error fix

* Code style, replacing cerr with glog

* DisassContext now holds all metadata

Removed skip_functions
CFG now contains entry for each function, only meaningful ones have
implementation
gDisassContext now holds everything needed to resolve xrefs

* Code style, forgot to include file last commit

* WIP code_xrefs resolve mechanism cleanup

* Merge CrossXrefs

CFGWriter::CrossXref abolished in favor of implementation in Util.

* Fix bug, with external not being recognizes in Context

* Lifting .so is broken and I have no idea how to do it

* Immediate values, partial variables

Rework code around immediate values, it is finally not just blindly
adding xrefs from everything

Sometimes two variables can occupy the same space (if one is suffix of
other). There is no real way to resolve it, so if there is something
targeting .data, .rodata, .bss it is just added as xref.

* Simplify resolve of instructions

* Remove found_xref from CFGWriter

* Cleaner lookup of regions

* Clean main a bit

* Code style changes

* Better variable names

* File structure

* README todo & shell changes

* Another round of code style

* Syntax error

* Renaming to init/fini only in stripped binaries

* One less writeDataXref wrapper

* Displacement now tries to resolve itself correctly

* Removed another now useless wrapper function

* Basic skeleton for recognising jump tables

* Offset tables

Offset tables are now recognized based on simple heuristic.

Offset tables that are immediately followed look like single one,
when resolving references this is taken into account.

Minor code style improvements

* Skeleton for local variables

* Resolve compiler warnings

* Parameters from debug info are also treated as local vars

* Decouple section parsing out of CFGWriter

* Update README

* Edges to catch blocks are ignored

* cmake now uses cxx-common protobuf instead of system-wide

* SectionManager does not abort when section is found

* Compiler warnings fix

* Remove constexpr, simplify FishForXref using set of overloads

* Edges are now properly checked to exclude some types.

* README update required cpp standart and Dyninst version

* Copyright header

* Typo, pretty_dump is now hidden behind flag

* SectionParser is now properly implemented

* First entry of Offset table can target itself

* Reworked data parsing

Last instruction in the block gets xref if it's a branching.
Utilities around external symbols recovery.

* Multiple improvements

* Removed recovery of variables from data sections as it was not working
properly
* pie_mode is now required for position independent binaries
* part of ubuntu 18.04 coreutils/gnutils can be lifted
* externals are now extracted from .plt stubs if linkage() does
not provide information

* Only link dyninst libs that are needed

* Remove some of log messages

* Unresolved cross_xrefs into text are now properly removed if they are from a switch

* Replace std::experimental::optional with slightly worse own implementation

* Fixed uninitialized variable usage

* Remove ExternalFunctionManager as global object

* Remove incorrectly implemented functions from SectionManager

* Codestyle changes

* TryEval now uses Maybe instead of bool as return type

* Changing last code xref is now cleaner with sanity check

* CrossXref now requires non-pointer type in template

* GetLastXref can return DataReference as well as CodeRef

* Missing reference

* Changed DisassContext into local member of CFGWriter

* SectionManager::IsCode instead manual search for text section

* Add consts into SectionManager where appropriate

* Change SectionManager to be local under CFGWriter

* Build flag is now cmake, not env

* Lift script should work with dyninst

* Cleaner local README

* Top level README

* Update README.md

* Set proper RPATH when install

* README fixes

* Remove tests. They will be added in separate branch

* Typo

* Revert changes in README

* Remove test section from README
2019-08-01 15:17:22 -04:00
Kyle Martin 1879492bf6 Un-Truncate File (#562) 2019-05-07 19:46:45 -04:00
artemdinaburg 101940f5b2 Fix/remove size eq 1 check (#555)
* Fix issues with is_sane_reference_target falsely rejecting size 1 references
2019-04-25 17:52:08 -04:00
artemdinaburg c7e880603a Bugfix: Scan the whole section for references in pie mode (#553)
* Bugfix: Scan the whole section for references in pie mode

* Update ida6 code with scan fix
2019-04-25 17:18:27 -04:00
Peter Goodman 364ada1ddb Update linux.txt 2019-04-23 14:07:01 -04:00
Peter Goodman caa99f1f45 Update linux.txt 2019-04-23 13:55:32 -04:00
Peter Goodman b8146a30e4 Add a check for python2.7 binary. (#529) 2019-03-18 11:44:13 -04:00
Peter Goodman 7d2dfe6e94 Attempt to resolve Issue #521 (#522)
* Attempt to resolve Issue #521

* minor fix

* minor fix

* minor fix

* Simplifications and comments

* If it's a copy of shared data, then don't treat it as an xref

* Error log if there is segment variable with the same name as external var

* Added flag and checks if the variable needs initialization if already defined;

* fix noreturn for the functions throwing exceptions;

* review changes

* Update get_cfg.py

* Update get_cfg.py

* Fix the recovery of exception action table chain

* Update the prebuild cfg for testsuite

* Fix entrypoint function not getting recovered in ida7

* Change the order of idc.GetFunctionName and idc.GetTrueName while looking for function name
2019-03-02 20:59:08 -05:00
dvn0zzz 67f33de3a1 Parse --std-args according to (#496) (#504) 2019-01-24 16:00:42 -05:00
kumarak af64f7c99e Issue501 stack variable recovery (#508)
* Fix the unsigned to signed conversion for the frame offset;

* Use struct pack for the sign conversion
2019-01-17 15:43:04 -05:00
artemdinaburg ca442bf695 Treat large externals as byte arrays and not big integers (#505)
* Handle large sized externals as byte arrays

* Externals <= 128 bits are treated as an integer
* Externals > 128 bits are treated as a byte array aligned the same as the
original variable

* Output recovered external variable size in mcsema-disass debug info
2019-01-11 00:04:00 -05:00
artemdinaburg 4435068d9f Pass --std-args to downstream script instead of eating it (#496) 2018-12-18 21:16:50 -05:00
artemdinaburg 2cb051e9ff Use LLIL for Variable Recovery (#495)
* Change to llil processing; Improved handling of ssa variable across the function calls
* Values object compare to remove the duplicate entries
2018-12-13 17:38:21 -05:00
artemdinaburg b5a8683bf1 Fix CFG Recovery for IDA7 to work with C++ applications (#494)
* Ignore "LOAD" segments
* Comment out code that made the .init_array section not have references
2018-12-13 17:28:05 -05:00
Kyle Martin 7417604302 Added Dockerfile (#487)
* Added Dockerfile
* Add build information to README
* Remove `privileged` flag from `docker run`
2018-12-11 12:06:08 -05:00
Kyle Martin f68b000893 Fixes Change in API (#490) 2018-11-08 14:46:53 -05:00
kumarak 4a47d349a1 Variable recovery from debug-less binaries (#482)
* InlineAsm fails due to function type mismatch

* disable ada failing testcases;

* semi-naive approach to recover the global variables without debuginfo

* Recover the globals and generate the global proto file

* Traverse the mlil instruction and collects memory addresses read/written

* Collect the function arguments and resolve its possible values ahead of time

* Add function handler and Instruction handler; refactor the changes

* Guard amd64 specific function calls in ABI_libc

* Put a compile-time guard around amd64 specific function definitions

* extend the instructions handling

* variable recovery handle the external and internal function return values;

* remove the check for blacklist addresses

* Initial attempt at variable recovery tests. Still needs work

* Updating globals tests

* Fix up recover and test script

* added a README, easier to read output from comparisons

* Add state variable for function entry

* State initialization and update it with the function call

* Adding binary-only variable recovery tests

* C++ exception test to var recovery

* Fix argument register lookup

* mask the symbols recovered from .init/.fini sections

* impoved inter-function analysis; fix the size of variables due to wrong operand size

* fixed operand size; get segment end to fix the size of last variable

* Compare function set for memory access

* split the list to addr ref and memory refs for the variables

* Update alias set generation

* switch to llil for analysis
2018-10-15 10:21:21 -04:00
Peter Goodman 39a10d007c Minor fix to not recognizing gmon_start. (#480)
* Minor fix to not recognizing gmon_start.

* function wrapper name for native execution
2018-10-10 21:58:25 -04:00
Peter Goodman 69cb35cc16 Call early init lazy xrefs (#466)
* More broadly applies lazy xref initialization to all initializations where the xref size is less than teh value size of the xref itself (pointer size, usually). Moves initialization of lazy xrefs into a new function, __mcsema_early_init, which guards itself against multiple executions. Makes sure that __mcsema_constructor calls __mcsema_early_init first. Finally, makes sure that all native-to-lifted entrypoints call __mcsema_early_init as well, as we have observed cases where the lifted binary contains weak implementations of c++ standard library functions, and these functions are called by native libraries initialized before the call to __mcsema_constructor, thereby resulting in re-entrancy issues.

* Update Function.cpp

* Make sure the __mcsema_early_init guard is in the module.

* Make sure the __mcsema_early_init guard is in the module.

* Fixes for __gmon_start__ and stuff.

* Minor fix

* Adds some symbols

* Minor fix for ida7

* Try to resolve things like calls through PLT thunks via xref entry lookups when a flow cross-reference is missing.
2018-09-23 15:25:14 -07:00
Kyle Martin e252733415 Resolves 457 (#462)
* Resolves 457

Constants In IL Should Not Also Be Pointers

* Update .remill_commit_id
2018-09-23 10:26:59 -07:00
Alessandro Gario 940ccd5357 mcsema_disass: Add support for IDAPython 7.1 (#411)
* mcsema_disass: Add support for IDAPython 7.1

* Code review changes

* Fix elf thunk identification for IDA 7.0

* check if the ref addr falls into LOAD segment

* Resolved merge conflict

* Check the LOAD segment before resolving xrefs

* Changes idc.GetMnem to idc. print_insn_mnem

* Move CFG recovery scripts to ida7

* Handle addresses which are in the middle of struct and unable to make xrefs

* Update with the master

* ida import

* handle references of external vtable

* Fix string recovery for apache binary

* IDA 6.x not detecting the typeinfo symbol refs and considering it as string
2018-09-04 12:50:46 -04:00