Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompiler: Add printRaw implementation for ambiguous TypeOps #5063

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,16 @@ TypeOpIntSless::TypeOpIntSless(TypeFactory *t)
behave = new OpBehaviorIntSless();
}

void TypeOpIntSless::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " s< ";
Varnode::printRaw(s,op->getIn(1));
}

Datatype *TypeOpIntSless::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const

{
Expand All @@ -977,6 +987,16 @@ TypeOpIntSlessEqual::TypeOpIntSlessEqual(TypeFactory *t)
behave = new OpBehaviorIntSlessEqual();
}

void TypeOpIntSlessEqual::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " s<= ";
Varnode::printRaw(s,op->getIn(1));
}

Datatype *TypeOpIntSlessEqual::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const

{
Expand Down Expand Up @@ -1586,6 +1606,16 @@ Datatype *TypeOpIntSdiv::getInputCast(const PcodeOp *op,int4 slot,const CastStra
return castStrategy->castStandard(reqtype,curtype,true,true);
}

void TypeOpIntSdiv::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " s/ ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpIntRem::TypeOpIntRem(TypeFactory *t)
: TypeOpBinary(t,CPUI_INT_REM,"%",TYPE_UINT,TYPE_UINT)
{
Expand Down Expand Up @@ -1614,6 +1644,16 @@ TypeOpIntSrem::TypeOpIntSrem(TypeFactory *t)
behave = new OpBehaviorIntSrem();
}

void TypeOpIntSrem::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " s% ";
Varnode::printRaw(s,op->getIn(1));
}

Datatype *TypeOpIntSrem::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const

{
Expand Down Expand Up @@ -1661,27 +1701,67 @@ TypeOpFloatEqual::TypeOpFloatEqual(TypeFactory *t,const Translate *trans)
behave = new OpBehaviorFloatEqual(trans);
}

void TypeOpFloatEqual::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " f== ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpFloatNotEqual::TypeOpFloatNotEqual(TypeFactory *t,const Translate *trans)
: TypeOpBinary(t,CPUI_FLOAT_NOTEQUAL,"!=",TYPE_BOOL,TYPE_FLOAT)
{
opflags = PcodeOp::binary | PcodeOp::booloutput | PcodeOp::commutative;
behave = new OpBehaviorFloatNotEqual(trans);
}

void TypeOpFloatNotEqual::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " f!= ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpFloatLess::TypeOpFloatLess(TypeFactory *t,const Translate *trans)
: TypeOpBinary(t,CPUI_FLOAT_LESS,"<",TYPE_BOOL,TYPE_FLOAT)
{
opflags = PcodeOp::binary | PcodeOp::booloutput;
behave = new OpBehaviorFloatLess(trans);
}

void TypeOpFloatLess::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " f< ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpFloatLessEqual::TypeOpFloatLessEqual(TypeFactory *t,const Translate *trans)
: TypeOpBinary(t,CPUI_FLOAT_LESSEQUAL,"<=",TYPE_BOOL,TYPE_FLOAT)
{
opflags = PcodeOp::binary | PcodeOp::booloutput;
behave = new OpBehaviorFloatLessEqual(trans);
}

void TypeOpFloatLessEqual::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " f<= ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpFloatNan::TypeOpFloatNan(TypeFactory *t,const Translate *trans)
: TypeOpFunc(t,CPUI_FLOAT_NAN,"NAN",TYPE_BOOL,TYPE_FLOAT)
{
Expand All @@ -1696,34 +1776,82 @@ TypeOpFloatAdd::TypeOpFloatAdd(TypeFactory *t,const Translate *trans)
behave = new OpBehaviorFloatAdd(trans);
}

void TypeOpFloatAdd::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " f+ ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpFloatDiv::TypeOpFloatDiv(TypeFactory *t,const Translate *trans)
: TypeOpBinary(t,CPUI_FLOAT_DIV,"/",TYPE_FLOAT,TYPE_FLOAT)
{
opflags = PcodeOp::binary;
behave = new OpBehaviorFloatDiv(trans);
}

void TypeOpFloatDiv::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " f/ ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpFloatMult::TypeOpFloatMult(TypeFactory *t,const Translate *trans)
: TypeOpBinary(t,CPUI_FLOAT_MULT,"*",TYPE_FLOAT,TYPE_FLOAT)
{
opflags = PcodeOp::binary | PcodeOp::commutative;
behave = new OpBehaviorFloatMult(trans);
}

void TypeOpFloatMult::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " f* ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpFloatSub::TypeOpFloatSub(TypeFactory *t,const Translate *trans)
: TypeOpBinary(t,CPUI_FLOAT_SUB,"-",TYPE_FLOAT,TYPE_FLOAT)
{
opflags = PcodeOp::binary;
behave = new OpBehaviorFloatSub(trans);
}

void TypeOpFloatSub::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = ";
Varnode::printRaw(s,op->getIn(0));
s << " f- ";
Varnode::printRaw(s,op->getIn(1));
}

TypeOpFloatNeg::TypeOpFloatNeg(TypeFactory *t,const Translate *trans)
: TypeOpUnary(t,CPUI_FLOAT_NEG,"-",TYPE_FLOAT,TYPE_FLOAT)
{
opflags = PcodeOp::unary;
behave = new OpBehaviorFloatNeg(trans);
}

void TypeOpFloatNeg::printRaw(ostream &s,const PcodeOp *op)

{
Varnode::printRaw(s,op->getOut());
s << " = f- ";
Varnode::printRaw(s,op->getIn(0));
}

TypeOpFloatAbs::TypeOpFloatAbs(TypeFactory *t,const Translate *trans)
: TypeOpFunc(t,CPUI_FLOAT_ABS,"ABS",TYPE_FLOAT,TYPE_FLOAT)
{
Expand Down
13 changes: 13 additions & 0 deletions Ghidra/Features/Decompiler/src/decompile/cpp/typeop.hh
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public:
class TypeOpIntSless : public TypeOpBinary {
public:
TypeOpIntSless(TypeFactory *t); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual Datatype *getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const;
virtual Datatype *propagateType(Datatype *alttype,PcodeOp *op,Varnode *invn,Varnode *outvn,
int4 inslot,int4 outslot);
Expand All @@ -350,6 +351,7 @@ public:
class TypeOpIntSlessEqual : public TypeOpBinary {
public:
TypeOpIntSlessEqual(TypeFactory *t); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual Datatype *getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const;
virtual Datatype *propagateType(Datatype *alttype,PcodeOp *op,Varnode *invn,Varnode *outvn,
int4 inslot,int4 outslot);
Expand Down Expand Up @@ -534,6 +536,7 @@ public:
class TypeOpIntSdiv : public TypeOpBinary {
public:
TypeOpIntSdiv(TypeFactory *t); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opIntSdiv(op); }
virtual Datatype *getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const;
};
Expand All @@ -550,6 +553,7 @@ public:
class TypeOpIntSrem : public TypeOpBinary {
public:
TypeOpIntSrem(TypeFactory *t); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opIntSrem(op); }
virtual Datatype *getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const;
};
Expand Down Expand Up @@ -586,27 +590,31 @@ public:
class TypeOpFloatEqual : public TypeOpBinary {
public:
TypeOpFloatEqual(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatEqual(op); }
};

/// \brief Information about the FLOAT_NOTEQUAL op-code
class TypeOpFloatNotEqual : public TypeOpBinary {
public:
TypeOpFloatNotEqual(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatNotEqual(op); }
};

/// \brief Information about the FLOAT_LESS op-code
class TypeOpFloatLess : public TypeOpBinary {
public:
TypeOpFloatLess(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatLess(op); }
};

/// \brief Information about the FLOAT_LESSEQUAL op-code
class TypeOpFloatLessEqual : public TypeOpBinary {
public:
TypeOpFloatLessEqual(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatLessEqual(op); }
};

Expand All @@ -621,34 +629,39 @@ public:
class TypeOpFloatAdd : public TypeOpBinary {
public:
TypeOpFloatAdd(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatAdd(op); }
};

/// \brief Information about the FLOAT_DIV op-code
class TypeOpFloatDiv : public TypeOpBinary {
public:
TypeOpFloatDiv(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatDiv(op); }
};

/// \brief Information about the FLOAT_MULT op-code
class TypeOpFloatMult : public TypeOpBinary {
public:
TypeOpFloatMult(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatMult(op); }
};

/// \brief Information about the FLOAT_SUB op-code
class TypeOpFloatSub : public TypeOpBinary {
public:
TypeOpFloatSub(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatSub(op); }
};

/// \brief Information about the FLOAT_NEG op-code
class TypeOpFloatNeg : public TypeOpUnary {
public:
TypeOpFloatNeg(TypeFactory *t,const Translate *trans); ///< Constructor
virtual void printRaw(ostream &s,const PcodeOp *op);
virtual void push(PrintLanguage *lng,const PcodeOp *op,const PcodeOp *readOp) const { lng->opFloatNeg(op); }
};

Expand Down