Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x64 support #513

Merged
merged 159 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
eed349c
decoder: fix condition
Aug 16, 2018
47b3b0d
llvmir_tests: clean abi
Jul 12, 2018
1b8559d
abi: make method const
Aug 27, 2018
bea9c7c
abi: value can be parameter
Aug 27, 2018
88b9293
abi: provide method parameterRegisters()
Aug 27, 2018
3ef6002
abi: provide return info
Aug 27, 2018
b41862e
abi: provide value of return register
Aug 27, 2018
43efa15
abi: provide info about FPU parameter registers
Jul 25, 2018
624dcb1
abi: provide special info about usage of FP registers
Jul 25, 2018
fc19d34
abi: provide info about double registers
Aug 27, 2018
2be2dbb
abi: pic32: new class
Jul 26, 2018
2d38d79
abi: provide support for pic32 abi
Jul 26, 2018
2d6632d
abi: provide info about FP register for return
Aug 7, 2018
e08e58d
param_return: rafacor - use abi instead of config
Jul 2, 2018
dad21d2
param_return: get rid of redundant operations
Jun 29, 2018
a693d66
param_return: redundant code
Jul 17, 2018
d19f4e9
param_return: redundant code
Jul 16, 2018
4f8a1be
param_return_tests: get rid of unused register configuration
Jul 12, 2018
01c246c
param_return: remove unnecessary comments
Jul 27, 2018
9468cea
param_return_tests: remove misleading test
Jul 27, 2018
16d7795
param_return: rename method filterRegisters
Jul 27, 2018
5148b83
param_return: use remove_if instead of manually searching vector
Jul 27, 2018
a7091ed
param_return: remove redundant code
Aug 1, 2018
324b5ce
param_return: remove code based on bad assumption
Aug 1, 2018
8337e7b
param_return: refactor generation of params in variadic functions
Aug 27, 2018
4043c20
abi/x64: provide support for Intel x86-64
Oct 17, 2018
743934e
abi: provide support for Intel x64 architecutre
Aug 1, 2018
83c8fa8
param_return_tests: x64 unit tests
Aug 6, 2018
31696ed
retdec-decompiler: make x64 files go through
Aug 16, 2018
afb1e06
param_return: detect type of parameter
Aug 7, 2018
890ea38
param_return: correct filtering of stack offsets
Aug 7, 2018
4efb408
param_return: small refactor
Aug 8, 2018
12b8b4b
param_return: new arguments collection algorithm
Aug 27, 2018
1c03145
param_return: new filter
Aug 27, 2018
f2b0729
abi: parameter registers overlay
Aug 17, 2018
5d2aeb7
abi: ms_x64: new class
Aug 17, 2018
341f3c8
abi: provide support fo microsoft x64 ABI
Aug 17, 2018
0105fd2
param_return_tests: revert 47277eb93
Feb 11, 2019
bf058d4
param_return_tests: x64: microsoft: new tests
Aug 20, 2018
44cd1e0
param_return: fix sort algorithm
Aug 21, 2018
d678376
param_return: store values instead of whole instructions
Aug 21, 2018
ba7bbaf
param_return: get rid of redundant code
Aug 27, 2018
df9b96d
param_return: change name of method
Aug 27, 2018
08d8609
param_return: apply DRY principle
Aug 27, 2018
8e5bbac
param_return: get rid of unnecessary operations
Aug 21, 2018
77563f9
param_return: make remove more clear
Aug 21, 2018
4579c53
param_return: move to better place
Aug 21, 2018
c138127
param_return: new filter
Aug 21, 2018
51cdc34
param_return: use new filter
Aug 21, 2018
caeb804
ParamFilter: new class
Aug 27, 2018
231a2af
param_return: use ParamFilter
Aug 27, 2018
251a172
param_return: get rid of deprecated methods
Aug 27, 2018
b7268c4
param_return: get rid of magic constants
Jul 24, 2018
993eff6
llvm ir: data layout: provide size of pointer on 64 bit architecture
Sep 25, 2018
64ad9c6
scripts: retdec-decompiler: new error handle
Sep 13, 2018
4e54670
param_return: prefer params detected in definition
Oct 23, 2018
e503641
param_return: unify methods to modify IR
Oct 25, 2018
6432089
x86_fastcall: new abi
Jan 30, 2019
06b45ea
x86_fastcall: provide unit tests
Jan 30, 2019
75d16f3
arm64: new abi
Feb 10, 2019
61acd54
x86_watcom: new abi
Feb 10, 2019
0a12d2d
powerpc64: new abi
Feb 10, 2019
dcbbffa
mips64: new abi
Feb 10, 2019
324b034
x86_pascal: new abi
Feb 10, 2019
9f16ae2
abi: provide information about stack parameter order
Feb 10, 2019
35ef64e
param_return: use info about parameter stack order
Feb 10, 2019
4a0f407
param_return: get rid of unused methods
Feb 21, 2019
9d336f2
param_return: provides found arguments in definition if definition pr…
Nov 29, 2018
73bb576
abi/arm: new unit tests
Feb 10, 2019
0a7e30a
abi/arm: provide option to pass parameters in float registers
Feb 10, 2019
f234314
abi: use watcom abi
Feb 10, 2019
1348f52
abi: use pascal abi
Feb 10, 2019
3e30df2
param_return_tests: watcom unit tests
Feb 10, 2019
adb8ee5
pascal: new unit tests
Feb 10, 2019
1909aa5
abi/mips: new unit tests
Feb 10, 2019
7884faf
config/architecture: provide test for mips64
Feb 10, 2019
195f49a
config/architecture: provide test for arm64
Feb 10, 2019
fbe0810
config/architecture: provide test for ppc64
Feb 10, 2019
52eb101
ppc abi: new unit tests
Feb 11, 2019
a470ad8
abi/ppc: new unit tests
Feb 11, 2019
30f76b5
calling_convention: new interface
Feb 21, 2019
e6514c8
calling_convention/arm: arm cc definition
Feb 21, 2019
0490206
calling_convention/arm64: arm64 cc implementation
Feb 21, 2019
83f5d22
calling_convention/mips: implementation of mips cc
Feb 21, 2019
c42d15b
calling_convention/mips64: implementation of mips64 cc
Feb 21, 2019
480a113
calling_conventnion/x86: implementation of x86 ccs
Feb 21, 2019
f03f20b
calling_conventnon/x64: implementation of x64 ccs
Feb 21, 2019
5414792
calling_convention/pic32: implementation of pic32 cc
Feb 21, 2019
164c284
calling_convention/powerpc: implementation of powerpc cc
Feb 21, 2019
5918d44
calling_convention/powerpc64: implementation of powerpc64 cc
Feb 21, 2019
3933fbb
abi: provide architecture word size info
Feb 21, 2019
0a8afa8
abi: this commit shall revert not needed info
Feb 21, 2019
a19d2c6
abi: provide test for stack variables
Feb 21, 2019
c607377
abi: provide test for pic32
Feb 21, 2019
ac4427f
abi: provide calling convention info
Feb 21, 2019
95d73d2
abi/x86: restet added convention inf
Feb 21, 2019
f6e87a4
abi/x64: revert info providing
Feb 21, 2019
503d5ed
abi/arm: revert cc info providing
Feb 21, 2019
a524689
abi/arm: revert cc providing
Feb 21, 2019
dc9df6a
abi/arm64: revert providing cc info
Feb 21, 2019
0dfbd7d
abi/ms_x64: revert cc info providing
Feb 21, 2019
362a3eb
abi/mips64: revert cc info providing
Feb 21, 2019
9b17374
abi/powerpc: revert default c cproviding
Feb 21, 2019
95c63b7
abi/powerpc64: revert cc info
Feb 21, 2019
0445a35
abi/pic32: rever cc info providing
Feb 21, 2019
ed2b9fe
abi/x86: provide x86 specific calling conventnions
Feb 21, 2019
18f3b48
abi/x64: provide defualt calling convnention
Feb 21, 2019
abc0a97
abi/arm: provide default cc info
Feb 21, 2019
96b067d
abi/mips: provide default calling convention
Feb 21, 2019
343e395
abi/arm64: provide default ar64 cc
Feb 21, 2019
a568e18
abi/ms_x64: provide default microsoft x64 cc info
Feb 21, 2019
fce7750
abi/powerpc: provide default cc info
Feb 21, 2019
540415e
abi/powerpc64: provide default cc
Feb 21, 2019
b524b7b
abi/pic32: provide default cc
Feb 21, 2019
ea606fb
abi/misp64: provide default cc
Feb 21, 2019
63171b6
config/calling_conventnion: make enum pubic
Feb 21, 2019
fdac82b
calling_convention: support for pascal fastcal id
Mar 4, 2019
2c484d2
calling_convention: make cc id serialization public
Mar 4, 2019
c188ba9
abi: make methods const
Mar 4, 2019
61cbb40
abi: provide method for register size
Mar 4, 2019
b87f4e9
abi: let children override getTypeByteSize method
Mar 4, 2019
ac65a65
abi: provide config
Mar 4, 2019
bf1bada
abi: save calling conventions in map
Mar 4, 2019
c1fc119
abi: assure type is sized
Mar 4, 2019
20dbab9
abi: provide word size info from config
Mar 4, 2019
09bae70
abi: return compiler specific settings in calling convention
Mar 4, 2019
89e3e70
capstone2llvmir/arm: fix STRD instruction
Mar 4, 2019
13b345b
abi: archs: provide const methods squish
Mar 4, 2019
f49be24
abi: pic32: define special size for double arguments
Mar 4, 2019
ac3728b
collector: new class
Mar 5, 2019
d387034
data_entries: new class
Mar 5, 2019
cae1ee1
filter: new class
Mar 5, 2019
04eef0b
param_return: refactor design
Mar 5, 2019
f15ef96
calling_convention: refactor methods
Mar 5, 2019
8ee78d8
calling_convention: x86: provide larger stack offset
Mar 5, 2019
a8c6d28
calling_convention: arm: correct info about cc
Mar 5, 2019
bc26186
calling_convention: mips: correct info about cc
Mar 5, 2019
242bb26
pic32: correct info about cc
Mar 5, 2019
f96312b
calling_convention: fix pascal_fastcall id
Mar 5, 2019
bf2c54c
powerpc: correct cc info
Mar 5, 2019
e16715d
calling_convention: x64: x86: fix cc info
Mar 5, 2019
a86918e
param_return_tests: fix tests
Mar 5, 2019
200f1ce
watcom fix
Mar 4, 2019
b07272f
abi: provide shortcuts to test if abi is for 64 bit arch
Mar 5, 2019
0bd8d05
calling_convention: refactor repository structure
Mar 5, 2019
50f2655
collector/pic32: separate special collector
Mar 5, 2019
e42ed24
param_return: disabling find of arg loads
Mar 4, 2019
e4aa804
collector/pic32: update cmakelist
Mar 5, 2019
212e94f
param_return_tests: enable calling convention unit tests
Mar 5, 2019
a19aeee
calling_convention: fastcall: pascal: fix parameter registers
Mar 5, 2019
07e1b7e
param_return_tests: fix caling conventions tests
Mar 5, 2019
e02ae8d
param_return_tests: enable ms x64 unit tests
Mar 5, 2019
c76d1bd
param_return/filter: provide explanaiton
Mar 5, 2019
4ba8a37
param_return/collector: provide explanaion
Mar 5, 2019
eb62ec6
ms_x64: new filter for x64 ms conention
Mar 5, 2019
8e044b0
param_return/filter: fix condition on special ms filter
Mar 5, 2019
9cc98e3
parm_return: filter/ms_x64: fix filtering by known type
Mar 5, 2019
3f8db46
stacofin: x64: provide application of x64 YARA signatures
Sep 12, 2018
b546103
doxygen: fix warnings
Mar 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @file include/retdec/bin2llvmir/optimizations/param_return/collector/collector.h
* @brief Collects possible arguments and returns of functions.
* @copyright (c) 2019 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_BIN2LLVMIR_OPTIMIZATIONS_PARAM_RETURN_COLLECTOR_COLLECTOR_H
#define RETDEC_BIN2LLVMIR_OPTIMIZATIONS_PARAM_RETURN_COLLECTOR_COLLECTOR_H

#include <map>
#include <vector>

#include <llvm/IR/Instructions.h>
#include <llvm/IR/Module.h>

#include "retdec/bin2llvmir/analyses/reaching_definitions.h"
#include "retdec/bin2llvmir/optimizations/param_return/data_entries.h"
#include "retdec/bin2llvmir/providers/abi/abi.h"

namespace retdec {
namespace bin2llvmir {

class Collector
{
public:
typedef std::unique_ptr<Collector> Ptr;

public:
Collector(
const Abi* abi,
llvm::Module* m,
const ReachingDefinitionsAnalysis* rda);

virtual ~Collector();

public:
virtual void collectCallArgs(CallEntry* ce) const;
virtual void collectCallRets(CallEntry* ce) const;

virtual void collectDefArgs(DataFlowEntry* de) const;
virtual void collectDefRets(DataFlowEntry* de) const;

virtual void collectCallSpecificTypes(CallEntry* ce) const;

protected:

void collectRetStores(ReturnEntry* re) const;

void collectStoresBeforeInstruction(
llvm::Instruction* i,
std::vector<llvm::StoreInst*>& stores) const;

void collectLoadsAfterInstruction(
llvm::Instruction* i,
std::vector<llvm::LoadInst*>& loads) const;

bool collectLoadsAfterInstruction(
llvm::Instruction* i,
std::vector<llvm::LoadInst*>& loads,
std::set<llvm::Value*>& excluded) const;

void collectStoresInSinglePredecessors(
llvm::Instruction* i,
std::vector<llvm::StoreInst*>& stores) const;

void collectStoresRecursively(
llvm::Instruction* i,
std::vector<llvm::StoreInst*>& stores,
std::map<llvm::BasicBlock*,
std::set<llvm::Value*>>& seen) const;

bool collectStoresInInstructionBlock(
llvm::Instruction* i,
std::set<llvm::Value*>& values,
std::vector<llvm::StoreInst*>& stores) const;

protected:
bool extractFormatString(CallEntry* ce) const;

bool storesString(llvm::StoreInst* si, std::string& str) const;
llvm::Value* getRoot(llvm::Value* i, bool first = true) const;

protected:
const Abi* _abi;
llvm::Module* _module;
const ReachingDefinitionsAnalysis* _rda;
};

class CollectorProvider
{
public:
static Collector::Ptr createCollector(
const Abi* abi,
llvm::Module* m,
const ReachingDefinitionsAnalysis* rda);
};

} // namespace bin2llvmir
} // namespace retdec

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file include/retdec/bin2llvmir/optimizations/param_return/collector/pic32.h
* @brief Pic32 specific collection algorithms.
* @copyright (c) 2019 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_BIN2LLVMIR_OPTIMIZATIONS_PARAM_RETURN_COLLECTOR_PIC32_H
#define RETDEC_BIN2LLVMIR_OPTIMIZATIONS_PARAM_RETURN_COLLECTOR_PIC32_H

#include "retdec/bin2llvmir/optimizations/param_return/collector/collector.h"

namespace retdec {
namespace bin2llvmir {

class CollectorPic32 : public Collector
{
public:
CollectorPic32(
const Abi* abi,
llvm::Module* m,
const ReachingDefinitionsAnalysis* rda);

virtual ~CollectorPic32() override;

public:
virtual void collectCallSpecificTypes(CallEntry* ce) const override;
};

} // namespace bin2llvmir
} // namespace retdec

#endif
185 changes: 185 additions & 0 deletions include/retdec/bin2llvmir/optimizations/param_return/data_entries.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/**
* @file include/retdec/bin2llvmir/optimizations/param_return/data_entries.h
* @brief Data entries for parameter analysis.
* @copyright (c) 2019 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_BIN2LLVMIR_OPTIMIZATIONS_PARAM_RETURN_DATA_ENTRIES_H
#define RETDEC_BIN2LLVMIR_OPTIMIZATIONS_PARAM_RETURN_DATA_ENTRIES_H

#include <vector>

#include "retdec/bin2llvmir/providers/calling_convention/calling_convention.h"

#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>

namespace retdec {
namespace bin2llvmir {

class ReturnEntry
{
public:
ReturnEntry(llvm::ReturnInst* r);

public:
void addRetStore(llvm::StoreInst* st);

void setRetStores(std::vector<llvm::StoreInst*>&& stores);
void setRetStores(const std::vector<llvm::StoreInst*>& stores);
void setRetValues(std::vector<llvm::Value*>&& values);

void setRetValues(const std::vector<llvm::Value*>& values);

public:
llvm::ReturnInst* getRetInstruction() const;

const std::vector<llvm::StoreInst*>& retStores() const;
const std::vector<llvm::Value*>& retValues() const;


protected:
llvm::ReturnInst* _retInst = nullptr;

std::vector<llvm::StoreInst*> _retStores;
std::vector<llvm::Value*> _retValues;
};

class CallableEntry
{
public:
bool isVoidarg() const;

void addArg(llvm::Value* arg);

void setVoidarg(bool voidarg = true);
void setArgTypes(
std::vector<llvm::Type*>&& types,
std::vector<std::string>&& names = {});

public:
const std::vector<llvm::Value*>& args() const;
const std::vector<llvm::Type*>& argTypes() const;
const std::vector<std::string>& argNames() const;

protected:
std::vector<llvm::Value*> _args;
std::vector<llvm::Type*> _argTypes;
std::vector<std::string> _argNames;

protected:
bool _voidarg = false;
};

class FunctionEntry : public CallableEntry
{
public:
bool isVariadic() const;
bool isWrapper() const;

public:
void addRetEntry(const ReturnEntry& ret);
ReturnEntry* createRetEntry(llvm::ReturnInst* ret);

void setArgs(std::vector<llvm::Value*>&& args);
void setVariadic(bool variadic = true);
void setWrappedCall(llvm::CallInst* wrap);
void setRetType(llvm::Type* type);
void setRetValue(llvm::Value* val);
void setCallingConvention(const CallingConvention::ID& cc);

public:
llvm::Value* getRetValue() const;
llvm::Type* getRetType() const;
llvm::CallInst* getWrappedCall() const;
CallingConvention::ID getCallingConvention() const;

const std::vector<ReturnEntry>& retEntries() const;
std::vector<ReturnEntry>& retEntries();

private:
llvm::CallInst* _wrap = nullptr;
llvm::Type* _retType = nullptr;
llvm::Value* _retVal = nullptr;
bool _variadic = false;
CallingConvention::ID _callconv = CallingConvention::ID::CC_UNKNOWN;

std::vector<ReturnEntry> _retEntries;
};

class CallEntry : public CallableEntry
{
// Constructor.
//
public:
CallEntry(
llvm::CallInst* call,
const FunctionEntry* base = nullptr);

// Usage data.
//
public:
void addRetLoad(llvm::LoadInst* load);

void setFormatString(const std::string& fmt);
void setArgStores(std::vector<llvm::StoreInst*>&& stores);
void setArgs(std::vector<llvm::Value*>&& args);
void setRetLoads(std::vector<llvm::LoadInst*>&& loads);
void setRetValues(std::vector<llvm::Value*>&& values);

llvm::CallInst* getCallInstruction() const;
const FunctionEntry* getBaseFunction() const;
std::string getFormatString() const;

public:
const std::vector<llvm::StoreInst*>& argStores() const;
const std::vector<llvm::Value*>& retValues() const;
const std::vector<llvm::LoadInst*>& retLoads() const;

private:
const FunctionEntry* _baseFunction;

llvm::CallInst* _callInst = nullptr;
std::string _fmtStr = "";

std::vector<llvm::LoadInst*> _retLoads;
std::vector<llvm::Value*> _retValues;
std::vector<llvm::StoreInst*> _argStores;
};

class DataFlowEntry : public FunctionEntry
{
// Constructor
//
public:
DataFlowEntry(llvm::Value* called);

// Type information
//
public:
bool isFunction() const;
bool isValue() const;
bool hasDefinition() const;

llvm::Function* getFunction() const;
llvm::Value* getValue() const;

void setCalledValue(llvm::Value* called);

// Usage data.
//
public:
CallEntry* createCallEntry(llvm::CallInst *call);
const std::vector<CallEntry>& callEntries() const;
std::vector<CallEntry>& callEntries();

private:
llvm::Value* _calledValue = nullptr;

std::vector<CallEntry> _calls;
};

} // namespace bin2llvmir
} // namespace retdec

#endif
Loading