forked from rose-compiler/rose
-
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.
(Binary Analysis) Null instruction set architecture
* Added a new "Null" instruction set architecture that can be used when the actual ISA isn't known or isn't supported by ROSE. This allows most forms of analysis to work as-is without needing any extra checks for nullptr. * The SgAsmNullInstruction is an instruction of the Null ISA. It's only instruction is the "unknown" instruction that's always one byte long. * The Null decoder decodes each byte of a program into a the "unknown" SgAsmNullInstruction AST. * The Null RegisterDictionary contains two 8-bit registers named "pc" and "sp" that are the program counter and stack pointer. These are needed because various analysis assume they exist. * The Null unparser knows how to unparse the single "unknown" SgAsmNullInstruction that has no operands. RPM-88
- Loading branch information
Showing
22 changed files
with
367 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -962,3 +962,4 @@ SgAtExp | |
SgFinishExp | ||
SgHereExp | ||
SgDotDotExp | ||
SgAsmNullInstruction |
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,19 @@ | ||
#include <featureTests.h> | ||
#ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT | ||
#include <sage3basic.h> | ||
#include <BinaryUnparserNull.h> | ||
|
||
namespace Rose { | ||
namespace BinaryAnalysis { | ||
namespace Unparser { | ||
|
||
void | ||
Null::emitInstructionMnemonic(std::ostream &out, SgAsmInstruction *insn, State&) const { | ||
out <<insn->get_mnemonic(); | ||
} | ||
|
||
} // namespace | ||
} // namespace | ||
} // namespace | ||
|
||
#endif |
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,45 @@ | ||
#ifndef ROSE_BinaryAnalysis_UnparserNull_H | ||
#define ROSE_BinaryAnalysis_UnparserNull_H | ||
#include <featureTests.h> | ||
#ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT | ||
|
||
#include <BinaryUnparserBase.h> | ||
|
||
namespace Rose { | ||
namespace BinaryAnalysis { | ||
namespace Unparser { | ||
|
||
struct NullSettings: public Settings {}; | ||
|
||
/** Unparser for null architecture. */ | ||
class Null: public Base { | ||
NullSettings settings_; | ||
|
||
protected: | ||
explicit Null(const NullSettings &settings) | ||
: settings_(settings) {} | ||
|
||
public: | ||
~Null() {} | ||
|
||
static Ptr instance(const NullSettings &settings = NullSettings()) { | ||
return Ptr(new Null(settings)); | ||
} | ||
|
||
Ptr copy() const ROSE_OVERRIDE { | ||
return instance(settings()); | ||
} | ||
|
||
const NullSettings& settings() const ROSE_OVERRIDE { return settings_; } | ||
NullSettings& settings() ROSE_OVERRIDE { return settings_; } | ||
|
||
protected: | ||
void emitInstructionMnemonic(std::ostream&, SgAsmInstruction*, State&) const ROSE_OVERRIDE; | ||
}; | ||
|
||
} // namespace | ||
} // namespace | ||
} // namespace | ||
|
||
#endif | ||
#endif |
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
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,62 @@ | ||
#include <featureTests.h> | ||
#ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT | ||
#include <sage3basic.h> | ||
#include <DisassemblerNull.h> | ||
#include <BinaryUnparserNull.h> | ||
|
||
namespace Rose { | ||
namespace BinaryAnalysis { | ||
|
||
DisassemblerNull::DisassemblerNull() { | ||
name("null"); | ||
wordSizeBytes(1); | ||
byteOrder(ByteOrder::ORDER_LSB); | ||
registerDictionary(RegisterDictionary::dictionary_null()); | ||
|
||
REG_IP = registerDictionary()->findOrThrow("pc"); | ||
REG_SP = registerDictionary()->findOrThrow("sp"); | ||
} | ||
|
||
DisassemblerNull::~DisassemblerNull() {} | ||
|
||
Disassembler* | ||
DisassemblerNull::clone() const { | ||
return new DisassemblerNull; | ||
} | ||
|
||
bool | ||
DisassemblerNull::canDisassemble(SgAsmGenericHeader*) const { | ||
return false; | ||
} | ||
|
||
Unparser::BasePtr | ||
DisassemblerNull::unparser() const { | ||
return Unparser::Null::instance(); | ||
} | ||
|
||
SgAsmInstruction* | ||
DisassemblerNull::disassembleOne(const MemoryMap::Ptr &map, rose_addr_t va, AddressSet*) { | ||
uint8_t byte = 0; | ||
size_t nRead = map->at(va).limit(1).require(MemoryMap::EXECUTABLE).read(&byte).size(); | ||
if (0 == nRead) | ||
throw Exception("short read", va); | ||
|
||
return makeUnknownInstruction(Exception("unknown", va, | ||
SgUnsignedCharList((const unsigned char*)&byte, (const unsigned char*)&byte+1), | ||
0)); | ||
} | ||
|
||
SgAsmInstruction* | ||
DisassemblerNull::makeUnknownInstruction(const Exception &e) { | ||
SgAsmInstruction *insn = new SgAsmNullInstruction(e.ip, "unknown"); | ||
SgAsmOperandList *operands = new SgAsmOperandList; | ||
insn->set_operandList(operands); | ||
operands->set_parent(insn); | ||
insn->set_raw_bytes(e.bytes); | ||
return insn; | ||
} | ||
|
||
} // namespace | ||
} // namespace | ||
|
||
#endif |
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,44 @@ | ||
#ifndef ROSE_BinaryAnalysis_Disassembler_Null_H | ||
#define ROSE_BinaryAnalysis_Disassembler_Null_H | ||
|
||
#include <featureTests.h> | ||
#ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT | ||
|
||
#include <Disassembler.h> | ||
#include <boost/serialization/access.hpp> | ||
#include <boost/serialization/base_object.hpp> | ||
|
||
namespace Rose { | ||
namespace BinaryAnalysis { | ||
|
||
/** Disassembler for nothing. | ||
* | ||
* This disassembler is a stub that can be used when no ISA is specified. It's never chosen automatically. It has unknown | ||
* byte order. It always decodes to an unknown instruction that's one byte long. */ | ||
class DisassemblerNull: public Disassembler { | ||
|
||
#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB | ||
private: | ||
friend class boost::serialization::access; | ||
|
||
template<class S> | ||
void serialize(S &s, const unsigned /*version*/) { | ||
s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Disassembler); | ||
} | ||
#endif | ||
|
||
public: | ||
DisassemblerNull(); | ||
virtual ~DisassemblerNull(); | ||
virtual Disassembler* clone() const ROSE_OVERRIDE; | ||
virtual bool canDisassemble(SgAsmGenericHeader*) const ROSE_OVERRIDE; | ||
virtual Unparser::BasePtr unparser() const ROSE_OVERRIDE; | ||
virtual SgAsmInstruction* disassembleOne(const MemoryMap::Ptr&, rose_addr_t va, AddressSet *successors = NULL) ROSE_OVERRIDE; | ||
virtual SgAsmInstruction* makeUnknownInstruction(const Exception&) ROSE_OVERRIDE; | ||
}; | ||
|
||
} // namespace | ||
} // namespace | ||
|
||
#endif | ||
#endif |
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
Oops, something went wrong.