-
Notifications
You must be signed in to change notification settings - Fork 527
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
1 parent
167b973
commit a09e067
Showing
15 changed files
with
335 additions
and
27 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 was deleted.
Oops, something went wrong.
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,60 @@ | ||
|
||
#include <iostream> | ||
#include <triton/api.hpp> | ||
#include <triton/basicBlock.hpp> | ||
|
||
using namespace triton; | ||
using namespace triton::arch; | ||
|
||
|
||
int main(int ac, const char **av) { | ||
/* Init the triton context */ | ||
triton::API api; | ||
|
||
/* Set the arch */ | ||
api.setArchitecture(ARCH_X86_64); | ||
|
||
BasicBlock block = BasicBlock({ | ||
Instruction((unsigned char *)"\x89\xd0", 2), /* mov eax, edx */ | ||
Instruction((unsigned char *)"\x80\xf4\x99", 3), /* xor ah, 0x99 */ | ||
Instruction((unsigned char *)"\x85\xc0", 2), /* test eax, eax */ | ||
Instruction((unsigned char *)"\x74\x08", 2), /* jz 10 */ | ||
}); | ||
|
||
api.disassembly(block); | ||
|
||
std::cout << block << std::endl; | ||
std::cout << "----------" << std::endl; | ||
|
||
auto i = Instruction((unsigned char *)"\x90", 1); /* nop */ | ||
api.disassembly(i); | ||
|
||
block.add(i); | ||
block.add(i); | ||
block.add(i); | ||
|
||
std::cout << block << std::endl; | ||
std::cout << "----------" << std::endl; | ||
|
||
block.remove(0); | ||
|
||
std::cout << block << std::endl; | ||
std::cout << "----------" << std::endl; | ||
|
||
api.disassembly(block, 0x1000); | ||
|
||
std::cout << block << std::endl; | ||
|
||
std::cout << "First addr: 0x" << std::hex << block.getFirstAddress() << std::endl; | ||
std::cout << "Last addr: " << std::hex << block.getLastAddress() << std::endl; | ||
std::cout << "Number of instructions: " << std::hex << block.size() << std::endl; | ||
|
||
std::cout << "----------" << std::endl; | ||
|
||
block.remove(2); /* remove the jz */ | ||
api.processing(block); | ||
|
||
std::cout << block << std::endl; | ||
|
||
return 0; | ||
} |
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,99 @@ | ||
//! \file | ||
/* | ||
** Copyright (C) - Triton | ||
** | ||
** This program is under the terms of the Apache License 2.0. | ||
*/ | ||
|
||
#include <triton/exceptions.hpp> | ||
#include <triton/basicBlock.hpp> | ||
|
||
|
||
|
||
namespace triton { | ||
namespace arch { | ||
|
||
BasicBlock::BasicBlock() { | ||
} | ||
|
||
|
||
BasicBlock::BasicBlock(const std::vector<triton::arch::Instruction>& instructions) { | ||
this->instructions = instructions; | ||
} | ||
|
||
|
||
BasicBlock::BasicBlock(const BasicBlock& other) { | ||
this->instructions = other.instructions; | ||
} | ||
|
||
|
||
BasicBlock& BasicBlock::operator=(const BasicBlock& other) { | ||
this->instructions = other.instructions; | ||
return *this; | ||
} | ||
|
||
|
||
BasicBlock::~BasicBlock() { | ||
this->instructions.clear(); | ||
} | ||
|
||
|
||
void BasicBlock::add(Instruction& instruction) { | ||
if (this->instructions.size()) { | ||
instruction.setAddress(this->instructions.back().getNextAddress()); | ||
} | ||
this->instructions.push_back(instruction); | ||
} | ||
|
||
|
||
bool BasicBlock::remove(triton::uint32 position) { | ||
if (this->instructions.size() <= position) | ||
return false; | ||
this->instructions.erase(this->instructions.begin() + position); | ||
return true; | ||
} | ||
|
||
|
||
std::vector<triton::arch::Instruction>& BasicBlock::getInstructions(void) { | ||
return this->instructions; | ||
} | ||
|
||
|
||
triton::usize BasicBlock::size(void) const { | ||
return this->instructions.size(); | ||
} | ||
|
||
|
||
triton::uint64 BasicBlock::getFirstAddress(void) const { | ||
if (this->instructions.size() == 0) | ||
throw triton::exceptions::BasicBlock("BasicBlock::getFirstAddress(): No instruction in the block."); | ||
return this->instructions.front().getAddress(); | ||
} | ||
|
||
|
||
triton::uint64 BasicBlock::getLastAddress(void) const { | ||
if (this->instructions.size() == 0) | ||
throw triton::exceptions::BasicBlock("BasicBlock::getLastAddress(): No instruction in the block."); | ||
return this->instructions.back().getAddress(); | ||
} | ||
|
||
|
||
std::ostream& operator<<(std::ostream& stream, BasicBlock& block) { | ||
triton::usize size = block.size(); | ||
for (const auto& inst : block.getInstructions()) { | ||
stream << inst; | ||
if (--size) { | ||
stream << std::endl; | ||
} | ||
} | ||
return stream; | ||
} | ||
|
||
|
||
std::ostream& operator<<(std::ostream& stream, BasicBlock* block) { | ||
stream << *block; | ||
return stream; | ||
} | ||
|
||
}; | ||
}; |
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
Oops, something went wrong.