Skip to content

Commit

Permalink
basic pointer fix
Browse files Browse the repository at this point in the history
  • Loading branch information
2over12 committed Nov 13, 2023
1 parent 9cfd0d6 commit 47dd03c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions include/anvill/Passes/ConvertAddressesToEntityUses.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <anvill/CrossReferenceFolder.h>
#include <llvm/IR/PassManager.h>

#include <optional>
#include <vector>

Expand Down Expand Up @@ -44,29 +45,29 @@ using EntityUsages = std::vector<EntityUse>;
class ConvertAddressesToEntityUses final
: public llvm::PassInfoMixin<ConvertAddressesToEntityUses> {
private:

// Resolve addresses to entities and vice versa.
const CrossReferenceResolver &xref_resolver;

// The metadata ID to annotation recovered entities with.
const std::optional<unsigned> pc_metadata_id;

public:

// Function pass entry point
llvm::PreservedAnalyses run(llvm::Function &function,
llvm::FunctionAnalysisManager &fam);

// Returns the pass name
static llvm::StringRef name(void);

bool IsPointerLike(llvm::Use &use);

// Enumerates some of the possible entity usages that are isolated to
// specific instruction operand uses.
EntityUsages EnumeratePossibleEntityUsages(llvm::Function &function);

ConvertAddressesToEntityUses(
const CrossReferenceResolver &xref_resolver_,
std::optional<unsigned> pc_metadata_id_=std::nullopt);
std::optional<unsigned> pc_metadata_id_ = std::nullopt);
};

} // namespace anvill
18 changes: 17 additions & 1 deletion lib/Passes/ConvertAddressesToEntityUses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include <anvill/Utils.h>
#include <glog/logging.h>
#include <llvm/IR/Constant.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/Instruction.h>
#include <llvm/IR/Instructions.h>
#include <llvm/Support/Casting.h>
#include <remill/Arch/Arch.h>
#include <remill/BC/Util.h>

Expand All @@ -37,6 +41,16 @@ static llvm::MDNode *GetPCAnnotation(llvm::Module *module, uint64_t pc) {

} // namespace


bool ConvertAddressesToEntityUses::IsPointerLike(llvm::Use &use) {
if (auto cst = llvm::dyn_cast<llvm::ConstantExpr>(use.get())) {
return llvm::Instruction::IntToPtr == cst->getOpcode();
}
// TODO(Ian): Add use of type annotations here

return false;
}

llvm::PreservedAnalyses
ConvertAddressesToEntityUses::run(llvm::Function &function,
llvm::FunctionAnalysisManager &fam) {
Expand Down Expand Up @@ -150,9 +164,11 @@ EntityUsages ConvertAddressesToEntityUses::EnumeratePossibleEntityUsages(
ra.is_valid && !ra.references_return_address &&
!ra.references_stack_pointer) {


if (ra.references_entity || // Related to an existing lifted entity.
ra.references_global_value || // Related to a global var/func.
ra.references_program_counter) { // Related to `__anvill_pc`.
ra.references_program_counter ||
IsPointerLike(use)) { // Related to `__anvill_pc`.
output.emplace_back(&use, ra);
}
}
Expand Down

0 comments on commit 47dd03c

Please sign in to comment.