Skip to content

Commit 186a2e4

Browse files
committed
Adjust to ROSE API changes in 0.11.145.177 and 0.11.145.187.
1 parent 344be6e commit 186a2e4

File tree

5 files changed

+76
-10
lines changed

5 files changed

+76
-10
lines changed

libpharos/misc.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
2020
#endif
2121

22+
#if PHAROS_ROSE_DYNAMIC_PTR_HACK
23+
#include <Rose/As.h>
24+
#else
25+
#include <Sawyer/SharedPointer.h>
26+
#include <boost/shared_ptr.hpp>
27+
#include <memory>
28+
#endif
29+
2230
#include <numeric>
2331

2432
namespace pharos {
@@ -508,6 +516,31 @@ RegisterVector get_usual_registers(Rose::BinaryAnalysis::Architecture::BaseConst
508516

509517
std::string unparseX86Register(RegisterDescriptor, RegisterDictionaryPtr);
510518

519+
#if PHAROS_ROSE_DYNAMIC_PTR_HACK
520+
using Rose::as;
521+
#else
522+
template<class T, class U>
523+
std::shared_ptr<T> as(const std::shared_ptr<U> &p) {
524+
return std::dynamic_pointer_cast<T>(p);
525+
}
526+
527+
template<class T, class U>
528+
boost::shared_ptr<T> as(const boost::shared_ptr<U> &p) {
529+
return boost::dynamic_pointer_cast<T>(p);
530+
}
531+
532+
template<class T, class U>
533+
Sawyer::SharedPointer<T> as(const Sawyer::SharedPointer<U> &p) {
534+
return p.template dynamicCast<T>();
535+
}
536+
537+
template<class T, class U>
538+
T* as(U *p) {
539+
return dynamic_cast<T*>(p);
540+
}
541+
#endif
542+
543+
511544
} // namespace pharos
512545

513546
#endif // Pharos_Misc_H

libpharos/rose.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,16 @@
3434
# error "Rose versions 0.11.145.158 through 0.11.145.166 are broken. Please compile against a different version of Rose."
3535
#endif
3636

37+
#define PHAROS_ROSE_DYNAMIC_PTR_CHANGE 11'145'0177
38+
#if PHAROS_ROSE_DYNAMIC_PTR_CHANGE <= PHAROS_ROSE_MINIMUM_VERSION
39+
# error "This hack is now always true. Remove the hack and make it permanent."
40+
#endif
41+
#define PHAROS_ROSE_DYNAMIC_PTR_HACK (ROSE_VERSION >= PHAROS_ROSE_DYNAMIC_PTR_CHANGE)
42+
43+
#define PHAROS_ROSE_ADDRESS_SPACE_CHANGE 11'145'0187
44+
#if PHAROS_ROSE_ADDRESS_SPACE_CHANGE <= PHAROS_ROSE_MINIMUM_VERSION
45+
# error "This hack is now always true. Remove the hack and make it permanent."
46+
#endif
47+
#define PHAROS_ROSE_ADDRESS_SPACE_HACK (ROSE_VERSION >= PHAROS_ROSE_ADDRESS_SPACE_CHANGE)
48+
3749
#endif // Pharos_Rose_H

libpharos/semantics.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class SymbolicValue: public ParentSValue {
201201
// Promote from the standard ROSE "base" SValue to ours.
202202
static SymbolicValuePtr promote(const BaseSValuePtr &v) {
203203
//STRACE << "SymbolicValue::promote(" << *v << ")" << LEND;
204-
SymbolicValuePtr retval = Semantics2::BaseSemantics::dynamic_pointer_cast<SymbolicValue>(v);
204+
SymbolicValuePtr retval = as<SymbolicValue>(v);
205205
assert(retval!=NULL);
206206
return retval;
207207
}

libpharos/state.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2023 Carnegie Mellon University. See LICENSE file for terms.
1+
// Copyright 2015-2024 Carnegie Mellon University. See LICENSE file for terms.
22

33
#include "state.hpp"
44
#include "riscops.hpp"
@@ -307,7 +307,12 @@ void SymbolicRegisterState::print(std::ostream& stream, Formatter& fmt) const {
307307
}
308308
}
309309

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

328333
// Call the standard merge method.
334+
#if PHAROS_ROSE_ADDRESS_SPACE_HACK
335+
return BaseState::merge(other, ops, ops);
336+
#else
329337
return BaseState::merge(other, ops);
338+
#endif
330339
}
331340

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

417426
using InputOutputPropertySet = Semantics2::BaseSemantics::InputOutputPropertySet;
418427

419-
bool SymbolicMemoryMapState::merge(const BaseMemoryStatePtr& other_,
428+
bool SymbolicMemoryMapState::merge(const BaseMemoryAddressSpacePtr& other_,
420429
BaseRiscOperators* addrOps,
421430
BaseRiscOperators* valOps) {
422431

libpharos/state.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015-2022 Carnegie Mellon University. See LICENSE file for terms.
1+
// Copyright 2015-2024 Carnegie Mellon University. See LICENSE file for terms.
22

33
#ifndef Pharos_State_H
44
#define Pharos_State_H
@@ -7,16 +7,23 @@
77
#include "misc.hpp"
88

99
namespace pharos {
10+
#if PHAROS_ROSE_ADDRESS_SPACE_HACK
11+
#define PHAROS_ROSE_ADDRESSS_SPACE(name) Semantics2::BaseSemantics::AddressSpacePtr
12+
#else
13+
#define PHAROS_ROSE_ADDRESSS_SPACE(name) name
14+
#endif
1015

1116
// Renames of standard ROSE typdefs.
1217
using BaseRegisterState = Semantics2::BaseSemantics::RegisterState;
1318
using BaseRegisterStatePtr = Semantics2::BaseSemantics::RegisterStatePtr;
19+
using BaseRegisterAddressSpacePtr = PHAROS_ROSE_ADDRESSS_SPACE(BaseRegisterStatePtr);
1420
using BaseState = Semantics2::BaseSemantics::State;
1521
using BaseStatePtr = Semantics2::BaseSemantics::StatePtr;
1622
using BaseRiscOperators = Semantics2::BaseSemantics::RiscOperators;
1723
using BaseRiscOperatorsPtr = Semantics2::BaseSemantics::RiscOperatorsPtr;
1824
using BaseMemoryState = Semantics2::BaseSemantics::MemoryState;
1925
using BaseMemoryStatePtr = Semantics2::BaseSemantics::MemoryStatePtr;
26+
using BaseMemoryAddressSpacePtr = PHAROS_ROSE_ADDRESSS_SPACE(BaseMemoryStatePtr);
2027
using MemoryCell = Semantics2::BaseSemantics::MemoryCell;
2128
using MemoryCellPtr = Semantics2::BaseSemantics::MemoryCellPtr;
2229
using BaseMemoryCellMap = Semantics2::BaseSemantics::MemoryCellMap;
@@ -119,7 +126,7 @@ class SymbolicRegisterState: public RegisterStateGeneric {
119126
return instance(SymbolicValue::promote(proto), rd);
120127
}
121128

122-
virtual BaseRegisterStatePtr clone() const override {
129+
virtual BaseRegisterAddressSpacePtr clone() const override {
123130
STRACE << "SymbolicRegisterState::clone()" << LEND;
124131
return SymbolicRegisterStatePtr(new SymbolicRegisterState(*this));
125132
}
@@ -238,7 +245,7 @@ class SymbolicMemoryMapState: public BaseMemoryCellMap {
238245
return saddr->get_hash();
239246
}
240247

241-
virtual BaseMemoryStatePtr clone() const override {
248+
virtual BaseMemoryAddressSpacePtr clone() const override {
242249
STRACE << "SymbolicMemoryMapState::clone()" << LEND;
243250
return BaseMemoryStatePtr(new SymbolicMemoryMapState(*this));
244251
}
@@ -248,7 +255,7 @@ class SymbolicMemoryMapState: public BaseMemoryCellMap {
248255
return SymbolicMemoryMapStatePtr(new SymbolicMemoryMapState(*this));
249256
}
250257

251-
virtual bool merge(const BaseMemoryStatePtr& other_,
258+
virtual bool merge(const BaseMemoryAddressSpacePtr& other_,
252259
BaseRiscOperators* addrOps,
253260
BaseRiscOperators* valOps) override;
254261

@@ -334,7 +341,7 @@ class SymbolicMemoryListState: public BaseMemoryCellList {
334341
return instance(addr_, val_);
335342
}
336343

337-
virtual BaseMemoryStatePtr clone() const override {
344+
virtual BaseMemoryAddressSpacePtr clone() const override {
338345
STRACE << "SymbolicMemoryListState::clone()" << LEND;
339346
return BaseMemoryStatePtr(new SymbolicMemoryListState(*this));
340347
}
@@ -597,7 +604,12 @@ class SymbolicState: public BaseState {
597604
}
598605

599606
private:
600-
bool merge(const BaseStatePtr &other, BaseRiscOperators *ops) override;
607+
#if PHAROS_ROSE_ADDRESS_SPACE_HACK
608+
bool merge(const BaseStatePtr &other,
609+
BaseRiscOperators *addrOps, BaseRiscOperators *valOps) override;
610+
#else
611+
bool merge(const BaseStatePtr &other, BaseRiscOperators *addrOps) override;
612+
#endif
601613

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

0 commit comments

Comments
 (0)