forked from avast/retdec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
238 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef RETDEC_BORLAND_AST_CTYPES_PARSER_H | ||
#define RETDEC_BORLAND_AST_CTYPES_PARSER_H | ||
|
||
#include "llvm/Demangle/borland_ast.h" | ||
#include "llvm/Demangle/borland_ast_types.h" | ||
#include "retdec/ctypes/module.h" | ||
#include "retdec/ctypes/context.h" | ||
#include "retdec/ctypes/function.h" | ||
#include "retdec/ctypes/type.h" | ||
#include "retdec/ctypes/integral_type.h" | ||
|
||
class Parameters; | ||
class VarArgness; | ||
|
||
namespace retdec { | ||
namespace ctypesparser { | ||
namespace borland_ast { | ||
|
||
class BorlandToCtypesParser | ||
{ | ||
public: | ||
enum Status : u_char | ||
{ | ||
success = 0, | ||
init, | ||
invalid_ast, | ||
}; | ||
|
||
public: | ||
BorlandToCtypesParser(); | ||
|
||
Status status(); | ||
|
||
void parseInto( | ||
std::shared_ptr <demangler::borland::Node> ast, | ||
retdec::ctypes::Module &module); | ||
|
||
private: | ||
std::shared_ptr <ctypes::Function> parseFunction(std::shared_ptr <demangler::borland::FunctionNode> function); | ||
std::shared_ptr <ctypes::Type> parseType(std::shared_ptr <demangler::borland::TypeNode> typeNode); | ||
std::shared_ptr <ctypes::IntegralType> parseIntegralType(std::shared_ptr <demangler::borland::TypeNode> integralNode); | ||
Parameters parseFuncParameters(std::shared_ptr <demangler::borland::ArrayNode> ¶msNode); | ||
ctypes::CallConvention parseCallConvention(demangler::borland::CallConv &callConv); | ||
VarArgness parseVarArgness(bool isVarArg); | ||
|
||
private: | ||
Status _status; | ||
std::shared_ptr <ctypes::Context> _context; | ||
}; | ||
|
||
} // borland_ast | ||
} // ctypesparser | ||
} // retdec | ||
|
||
#endif //RETDEC_BORLAND_AST_CTYPES_PARSER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
set(CTYPESPARSER_SOURCES | ||
ctypes_parser.cpp | ||
json_ctypes_parser.cpp | ||
borland_ast_ctypes_parser.cpp | ||
) | ||
|
||
add_library(retdec-ctypesparser STATIC ${CTYPESPARSER_SOURCES}) | ||
target_link_libraries(retdec-ctypesparser retdec-ctypes retdec-utils rapidjson) | ||
target_link_libraries(retdec-ctypesparser retdec-ctypes retdec-utils rapidjson llvm-demangler) | ||
target_include_directories(retdec-ctypesparser PUBLIC ${PROJECT_SOURCE_DIR}/include/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <cassert> | ||
|
||
#include "retdec/ctypesparser/borland_ast_ctypes_parser.h" | ||
#include "llvm/Demangle/borland_ast.h" | ||
#include "retdec/ctypes/type.h" | ||
#include "retdec/ctypes/function.h" | ||
#include "retdec/ctypes/unknown_type.h" | ||
|
||
using Kind = retdec::demangler::borland::Node::Kind; | ||
|
||
namespace retdec { | ||
namespace ctypesparser { | ||
namespace borland_ast { | ||
|
||
BorlandToCtypesParser::BorlandToCtypesParser() : | ||
_status(init), _context(nullptr) {} | ||
|
||
BorlandToCtypesParser::Status BorlandToCtypesParser::status() | ||
{ | ||
return _status; | ||
} | ||
|
||
void BorlandToCtypesParser::parseInto( | ||
std::shared_ptr<retdec::demangler::borland::Node> ast, | ||
retdec::ctypes::Module &module) | ||
{ | ||
assert(ast && "Ast cannot be null"); | ||
|
||
_context = module.getContext(); | ||
|
||
switch (ast->kind()) { | ||
case Kind::KFunction: { | ||
auto func = parseFunction(std::static_pointer_cast<demangler::borland::FunctionNode>(ast)); | ||
if (func) { | ||
module.addFunction(func); | ||
_status = success; | ||
} | ||
break; | ||
} | ||
default: | ||
_status = invalid_ast; | ||
} | ||
} | ||
|
||
std::shared_ptr<retdec::ctypes::Function> BorlandToCtypesParser::parseFunction(std::shared_ptr<demangler::borland::FunctionNode> function) | ||
{ | ||
std::string name = function->name()->str(); // TODO null on name() | ||
|
||
auto funcType = function->funcType(); | ||
|
||
std::shared_ptr<ctypes::Type> returnType = parseType(funcType->retType()); | ||
// ctypes::Function::Parameters parameters = parseFuncParameters(funcType->params()); | ||
// ctypes::CallConvention callConvention = parseCallConvention(funcNode->callConv()); | ||
// ctypes::Function::VarArgness varArgness = parseVarArgness(funcNode->isVarArg()); | ||
// | ||
// // TODO check status | ||
// | ||
// return ctypes::Function::create(_context, name, returnType, Parameters, callConvention, varArgness); | ||
return nullptr; | ||
} | ||
|
||
std::shared_ptr<ctypes::Type> BorlandToCtypesParser::parseType(std::shared_ptr<retdec::demangler::borland::TypeNode> typeNode) | ||
{ | ||
if (typeNode == nullptr) { | ||
return std::static_pointer_cast<ctypes::Type>(ctypes::UnknownType::create()); | ||
} | ||
|
||
switch (typeNode->kind()) { | ||
case Kind::KIntegralType: | ||
|
||
default: | ||
return std::static_pointer_cast<ctypes::Type>(ctypes::UnknownType::create()); | ||
} | ||
|
||
} | ||
|
||
//std::shared_ptr<ctypes::IntegralType> BorlandToCtypesParser::parseIntegralType(std::shared_ptr<retdec::demangler::borland::TypeNode> integralNode) | ||
//{ | ||
// | ||
//} | ||
|
||
//Parameters BorlandToCtypesParser::parseFuncParameters(std::shared_ptr<retdec::demangler::borland::ArrayNode> ¶msNode) | ||
//{ | ||
// return nullptr; | ||
//// if (paramsNode == nullptr) { | ||
//// return | ||
//// } | ||
//} | ||
|
||
} // borland_ast | ||
} // ctypesparser | ||
} // retdec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @file tests/demangler/borland_demangler_tests.cpp | ||
* @brief Tests for the borland demangler. | ||
* @copyright (c) 2019 Avast Software, licensed under the MIT license | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "llvm/Demangle/demangler.h" | ||
#include "retdec/ctypes/module.h" | ||
#include "llvm/Demangle/context.h" | ||
#include "retdec/ctypes/context.h" | ||
|
||
using namespace ::testing; | ||
|
||
namespace retdec { | ||
namespace demangler { | ||
namespace tests { | ||
|
||
class BorlandCtypesTests : public Test | ||
{ | ||
public: | ||
using status = retdec::demangler::Demangler::Status; | ||
|
||
BorlandCtypesTests() : | ||
demangler(retdec::demangler::DemanglerFactory::getDemangler("borland")) {} | ||
protected: | ||
std::unique_ptr<retdec::demangler::Demangler> demangler; | ||
}; | ||
|
||
TEST_F(BorlandCtypesTests, basic) | ||
{ | ||
auto context = std::make_shared<retdec::ctypes::Context>(); | ||
ctypes::Module module(context); | ||
demangler->demangleToModule("@myFunc_int_$qi", module); | ||
} | ||
|
||
} | ||
} | ||
} |