Skip to content

Commit

Permalink
Adjust to ROSE API changes in 0.11.145.177 and 0.11.145.187.
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-mwd committed Dec 16, 2024
1 parent 344be6e commit 186a2e4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
33 changes: 33 additions & 0 deletions libpharos/misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
#endif

#if PHAROS_ROSE_DYNAMIC_PTR_HACK
#include <Rose/As.h>
#else
#include <Sawyer/SharedPointer.h>
#include <boost/shared_ptr.hpp>
#include <memory>
#endif

#include <numeric>

namespace pharos {
Expand Down Expand Up @@ -508,6 +516,31 @@ RegisterVector get_usual_registers(Rose::BinaryAnalysis::Architecture::BaseConst

std::string unparseX86Register(RegisterDescriptor, RegisterDictionaryPtr);

#if PHAROS_ROSE_DYNAMIC_PTR_HACK
using Rose::as;
#else
template<class T, class U>
std::shared_ptr<T> as(const std::shared_ptr<U> &p) {
return std::dynamic_pointer_cast<T>(p);
}

template<class T, class U>
boost::shared_ptr<T> as(const boost::shared_ptr<U> &p) {
return boost::dynamic_pointer_cast<T>(p);
}

template<class T, class U>
Sawyer::SharedPointer<T> as(const Sawyer::SharedPointer<U> &p) {
return p.template dynamicCast<T>();
}

template<class T, class U>
T* as(U *p) {
return dynamic_cast<T*>(p);
}
#endif


} // namespace pharos

#endif // Pharos_Misc_H
Expand Down
12 changes: 12 additions & 0 deletions libpharos/rose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@
# error "Rose versions 0.11.145.158 through 0.11.145.166 are broken. Please compile against a different version of Rose."
#endif

#define PHAROS_ROSE_DYNAMIC_PTR_CHANGE 11'145'0177
#if PHAROS_ROSE_DYNAMIC_PTR_CHANGE <= PHAROS_ROSE_MINIMUM_VERSION
# error "This hack is now always true. Remove the hack and make it permanent."
#endif
#define PHAROS_ROSE_DYNAMIC_PTR_HACK (ROSE_VERSION >= PHAROS_ROSE_DYNAMIC_PTR_CHANGE)

#define PHAROS_ROSE_ADDRESS_SPACE_CHANGE 11'145'0187
#if PHAROS_ROSE_ADDRESS_SPACE_CHANGE <= PHAROS_ROSE_MINIMUM_VERSION
# error "This hack is now always true. Remove the hack and make it permanent."
#endif
#define PHAROS_ROSE_ADDRESS_SPACE_HACK (ROSE_VERSION >= PHAROS_ROSE_ADDRESS_SPACE_CHANGE)

#endif // Pharos_Rose_H
2 changes: 1 addition & 1 deletion libpharos/semantics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class SymbolicValue: public ParentSValue {
// Promote from the standard ROSE "base" SValue to ours.
static SymbolicValuePtr promote(const BaseSValuePtr &v) {
//STRACE << "SymbolicValue::promote(" << *v << ")" << LEND;
SymbolicValuePtr retval = Semantics2::BaseSemantics::dynamic_pointer_cast<SymbolicValue>(v);
SymbolicValuePtr retval = as<SymbolicValue>(v);
assert(retval!=NULL);
return retval;
}
Expand Down
15 changes: 12 additions & 3 deletions libpharos/state.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2023 Carnegie Mellon University. See LICENSE file for terms.
// Copyright 2015-2024 Carnegie Mellon University. See LICENSE file for terms.

#include "state.hpp"
#include "riscops.hpp"
Expand Down Expand Up @@ -307,7 +307,12 @@ void SymbolicRegisterState::print(std::ostream& stream, Formatter& fmt) const {
}
}

bool SymbolicState::merge(const BaseStatePtr &, BaseRiscOperators *) {
#if PHAROS_ROSE_ADDRESS_SPACE_HACK
bool SymbolicState::merge(const BaseStatePtr &, BaseRiscOperators *, BaseRiscOperators *)
#else
bool SymbolicState::merge(const BaseStatePtr &, BaseRiscOperators *)
#endif
{
// We do not want this class to be merged without a given condition (I.e., by the ROSE API
// internals.
abort();
Expand All @@ -326,7 +331,11 @@ bool SymbolicState::merge(const BaseStatePtr &other, BaseRiscOperators *ops,
cert_reg_merger->condition = condition;

// Call the standard merge method.
#if PHAROS_ROSE_ADDRESS_SPACE_HACK
return BaseState::merge(other, ops, ops);
#else
return BaseState::merge(other, ops);
#endif
}

// =========================================================================================
Expand Down Expand Up @@ -416,7 +425,7 @@ bool SymbolicMemoryMapState::equals(const SymbolicMemoryMapStatePtr& other) {

using InputOutputPropertySet = Semantics2::BaseSemantics::InputOutputPropertySet;

bool SymbolicMemoryMapState::merge(const BaseMemoryStatePtr& other_,
bool SymbolicMemoryMapState::merge(const BaseMemoryAddressSpacePtr& other_,
BaseRiscOperators* addrOps,
BaseRiscOperators* valOps) {

Expand Down
24 changes: 18 additions & 6 deletions libpharos/state.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2022 Carnegie Mellon University. See LICENSE file for terms.
// Copyright 2015-2024 Carnegie Mellon University. See LICENSE file for terms.

#ifndef Pharos_State_H
#define Pharos_State_H
Expand All @@ -7,16 +7,23 @@
#include "misc.hpp"

namespace pharos {
#if PHAROS_ROSE_ADDRESS_SPACE_HACK
#define PHAROS_ROSE_ADDRESSS_SPACE(name) Semantics2::BaseSemantics::AddressSpacePtr
#else
#define PHAROS_ROSE_ADDRESSS_SPACE(name) name
#endif

// Renames of standard ROSE typdefs.
using BaseRegisterState = Semantics2::BaseSemantics::RegisterState;
using BaseRegisterStatePtr = Semantics2::BaseSemantics::RegisterStatePtr;
using BaseRegisterAddressSpacePtr = PHAROS_ROSE_ADDRESSS_SPACE(BaseRegisterStatePtr);
using BaseState = Semantics2::BaseSemantics::State;
using BaseStatePtr = Semantics2::BaseSemantics::StatePtr;
using BaseRiscOperators = Semantics2::BaseSemantics::RiscOperators;
using BaseRiscOperatorsPtr = Semantics2::BaseSemantics::RiscOperatorsPtr;
using BaseMemoryState = Semantics2::BaseSemantics::MemoryState;
using BaseMemoryStatePtr = Semantics2::BaseSemantics::MemoryStatePtr;
using BaseMemoryAddressSpacePtr = PHAROS_ROSE_ADDRESSS_SPACE(BaseMemoryStatePtr);
using MemoryCell = Semantics2::BaseSemantics::MemoryCell;
using MemoryCellPtr = Semantics2::BaseSemantics::MemoryCellPtr;
using BaseMemoryCellMap = Semantics2::BaseSemantics::MemoryCellMap;
Expand Down Expand Up @@ -119,7 +126,7 @@ class SymbolicRegisterState: public RegisterStateGeneric {
return instance(SymbolicValue::promote(proto), rd);
}

virtual BaseRegisterStatePtr clone() const override {
virtual BaseRegisterAddressSpacePtr clone() const override {
STRACE << "SymbolicRegisterState::clone()" << LEND;
return SymbolicRegisterStatePtr(new SymbolicRegisterState(*this));
}
Expand Down Expand Up @@ -238,7 +245,7 @@ class SymbolicMemoryMapState: public BaseMemoryCellMap {
return saddr->get_hash();
}

virtual BaseMemoryStatePtr clone() const override {
virtual BaseMemoryAddressSpacePtr clone() const override {
STRACE << "SymbolicMemoryMapState::clone()" << LEND;
return BaseMemoryStatePtr(new SymbolicMemoryMapState(*this));
}
Expand All @@ -248,7 +255,7 @@ class SymbolicMemoryMapState: public BaseMemoryCellMap {
return SymbolicMemoryMapStatePtr(new SymbolicMemoryMapState(*this));
}

virtual bool merge(const BaseMemoryStatePtr& other_,
virtual bool merge(const BaseMemoryAddressSpacePtr& other_,
BaseRiscOperators* addrOps,
BaseRiscOperators* valOps) override;

Expand Down Expand Up @@ -334,7 +341,7 @@ class SymbolicMemoryListState: public BaseMemoryCellList {
return instance(addr_, val_);
}

virtual BaseMemoryStatePtr clone() const override {
virtual BaseMemoryAddressSpacePtr clone() const override {
STRACE << "SymbolicMemoryListState::clone()" << LEND;
return BaseMemoryStatePtr(new SymbolicMemoryListState(*this));
}
Expand Down Expand Up @@ -597,7 +604,12 @@ class SymbolicState: public BaseState {
}

private:
bool merge(const BaseStatePtr &other, BaseRiscOperators *ops) override;
#if PHAROS_ROSE_ADDRESS_SPACE_HACK
bool merge(const BaseStatePtr &other,
BaseRiscOperators *addrOps, BaseRiscOperators *valOps) override;
#else
bool merge(const BaseStatePtr &other, BaseRiscOperators *addrOps) override;
#endif

public:
bool merge(const BaseStatePtr &other, BaseRiscOperators *ops, const SymbolicValuePtr & cond);
Expand Down

0 comments on commit 186a2e4

Please sign in to comment.