Skip to content

Commit

Permalink
Merge pull request JonathanSalwan#1315 from Japrajah/disassembly_call…
Browse files Browse the repository at this point in the history
…back

Added disassembly by filterCallback
  • Loading branch information
JonathanSalwan authored Mar 27, 2024
2 parents 924bcbb + 537a0e8 commit f30e83e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/libtriton/arch/architecture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ namespace triton {
}


triton::arch::BasicBlock Architecture::disassembly(triton::uint64 addr) const {
triton::arch::BasicBlock Architecture::disassembly(triton::uint64 addr, bool(*filterCallback)(std::vector<triton::arch::Instruction>&)) const {
std::vector<triton::arch::Instruction> ret;

if (!filterCallback)
throw triton::exceptions::Exception("Architecture::disassembly(): Incorrect filterCallback.");
do {
if (!this->isConcreteMemoryValueDefined(addr)) {
break;
Expand All @@ -278,12 +279,17 @@ namespace triton {
this->disassembly(inst);
ret.push_back(inst);
addr += inst.getSize();
} while (!ret.back().isControlFlow());
} while (!filterCallback(ret));

return triton::arch::BasicBlock(ret);
}


triton::arch::BasicBlock Architecture::disassembly(triton::uint64 addr) const {
return this->disassembly(addr, ([](std::vector<triton::arch::Instruction>& ret) -> bool {return ret.back().isControlFlow(); }));
}


triton::uint8 Architecture::getConcreteMemoryValue(triton::uint64 addr, bool execCallbacks) const {
if (!this->cpu)
throw triton::exceptions::Architecture("Architecture::getConcreteMemoryValue(): You must define an architecture.");
Expand Down
6 changes: 6 additions & 0 deletions src/libtriton/context/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ namespace triton {
}


triton::arch::BasicBlock Context::disassembly(triton::uint64 addr, bool(*filterCallback)(std::vector<triton::arch::Instruction>&)) const {
this->checkArchitecture();
return this->arch.disassembly(addr, filterCallback);
}


triton::arch::BasicBlock Context::disassembly(triton::uint64 addr) const {
this->checkArchitecture();
return this->arch.disassembly(addr);
Expand Down
3 changes: 3 additions & 0 deletions src/libtriton/includes/triton/architecture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ namespace triton {
//! Disassembles a concrete memory area and returns a list of at most `count` disassembled instructions.
TRITON_EXPORT std::vector<triton::arch::Instruction> disassembly(triton::uint64 addr, triton::usize count) const;

//! Disassembles a concrete memory area from `addr` until 'filterCallback' returns false. The function returns a 'BasicBlock'
TRITON_EXPORT triton::arch::BasicBlock disassembly(triton::uint64 addr, bool(*filterCallback)(std::vector<triton::arch::Instruction>&)) const;

//! Disassembles a concrete memory area from `addr` to control flow instruction and returns a `BasicBlock`.
TRITON_EXPORT triton::arch::BasicBlock disassembly(triton::uint64 addr) const;

Expand Down
3 changes: 3 additions & 0 deletions src/libtriton/includes/triton/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ namespace triton {
//! [**architecture api**] - Disassembles a concrete memory area and returns a list of at most `count` disassembled instructions.
TRITON_EXPORT std::vector<triton::arch::Instruction> disassembly(triton::uint64 addr, triton::usize count) const;

//! [**architecture api**] - Disassembles a concrete memory area from `addr` until 'filterCallback' returns false. The function returns a 'BasicBlock'
TRITON_EXPORT triton::arch::BasicBlock disassembly(triton::uint64 addr, bool(*filterCallback)(std::vector<triton::arch::Instruction>&)) const;

//! [**architecture api**] - Disassembles a concrete memory area from `addr` to control flow instruction and returns a `BasicBlock`.
TRITON_EXPORT triton::arch::BasicBlock disassembly(triton::uint64 addr) const;

Expand Down

0 comments on commit f30e83e

Please sign in to comment.