EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyCallStream Class Reference

#include "PyPacket.h"

Collaboration diagram for PyCallStream:

Public Member Functions

 PyCallStream ()
 
 ~PyCallStream ()
 
void Dump (LogType type, PyVisitor &dumper)
 
bool Decode (const std::string &type, PyTuple *&payload)
 
PyTupleEncode ()
 
PyCallStreamClone () const
 

Public Attributes

uint32 remoteObject
 
std::string remoteObjectStr
 
std::string method
 
PyTuplearg_tuple
 
PyDictarg_dict
 

Detailed Description

Definition at line 144 of file PyPacket.h.

Constructor & Destructor Documentation

PyCallStream::PyCallStream ( )

Definition at line 553 of file PyPacket.cpp.

Referenced by Clone().

554 : remoteObject(0),
555  method(""),
556  arg_tuple(nullptr),
557  arg_dict(nullptr)
558 {
559 }
PyDict * arg_dict
Definition: PyPacket.h:159
uint32 remoteObject
Definition: PyPacket.h:154
std::string method
Definition: PyPacket.h:157
PyTuple * arg_tuple
Definition: PyPacket.h:158

Here is the caller graph for this function:

PyCallStream::~PyCallStream ( )

Definition at line 561 of file PyPacket.cpp.

References arg_dict, arg_tuple, and PySafeDecRef.

561  {
564 }
PyDict * arg_dict
Definition: PyPacket.h:159
PyTuple * arg_tuple
Definition: PyPacket.h:158
#define PySafeDecRef(op)
Definition: PyRep.h:61

Member Function Documentation

PyCallStream * PyCallStream::Clone ( ) const

Definition at line 566 of file PyPacket.cpp.

References arg_dict, arg_tuple, PyRep::AsDict(), PyRep::AsTuple(), PyTuple::Clone(), PyDict::Clone(), method, PyCallStream(), remoteObject, and remoteObjectStr.

566  {
567  PyCallStream *res = new PyCallStream();
568  res->remoteObject = remoteObject;
570  res->method = method;
571  res->arg_tuple = arg_tuple->Clone()->AsTuple();
572  if (arg_dict == nullptr)
573  res->arg_dict = nullptr;
574  else
575  res->arg_dict = arg_dict->Clone()->AsDict();
576 
577  return res;
578 }
PyDict * arg_dict
Definition: PyPacket.h:159
PyTuple * AsTuple()
Definition: PyRep.h:138
uint32 remoteObject
Definition: PyPacket.h:154
std::string method
Definition: PyPacket.h:157
PyRep * Clone() const
Clones object.
Definition: PyRep.cpp:548
PyTuple * arg_tuple
Definition: PyPacket.h:158
PyDict * AsDict()
Definition: PyRep.h:142
PyRep * Clone() const
Clones object.
Definition: PyRep.cpp:670
std::string remoteObjectStr
Definition: PyPacket.h:155

Here is the call graph for this function:

bool PyCallStream::Decode ( const std::string &  type,
PyTuple *&  payload 
)

Definition at line 598 of file PyPacket.cpp.

References arg_dict, arg_tuple, PyRep::AsTuple(), codelog, PySubStream::decoded(), PySubStream::DecodeData(), PyRep::Dump(), PyRep::IntegerValue(), PyRep::IsTuple(), PyTuple::items, method, PyDecRef, PySafeDecRef, remoteObject, remoteObjectStr, and PyRep::StringContent().

Referenced by EVEPacketDispatcher::DispatchPacket().

598  {
599  PyTuple *payload = in_payload; //copy
600  in_payload = nullptr; //consume
601 
604  arg_tuple = nullptr;
605  arg_dict = nullptr;
606 
607  if (payload == nullptr) {
608  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - payload is null.");
609  return false;
610  }
611 
612  if (type != "macho.CallReq") {
613  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - packet payload has unknown string type '%s'", type.c_str());
614  PyDecRef(payload);
615  return false;
616  }
617 
618  if (payload->items.size() != 1) {
619  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - invalid tuple length %lu", payload->items.size());
620  PyDecRef(payload);
621  return false;
622  }
623  if (!payload->items[0]->IsTuple()) {
624  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - non tuple payload[0]");
625  PyDecRef(payload);
626  return false;
627  }
628 
629  PyTuple *payload2 = payload->items[0]->AsTuple();
630  if (payload2 == nullptr) {
631  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - payload2 is null.");
632  PyDecRef(payload);
633  PySafeDecRef(payload2);
634  return false;
635  }
636 
637  if (payload2->items.size() != 2) {
638  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - invalid tuple2 length %lu", payload2->items.size());
639  PyDecRef(payload);
640  PySafeDecRef(payload2);
641  return false;
642  }
643 
644  //decode inner payload tuple
645  //ignore tuple 0, it should be an int, dont know what it is
646  if (!payload2->items[1]->IsSubStream()) {
647  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - non-substream type");
648  PyDecRef(payload);
649  PySafeDecRef(payload2);
650  return false;
651  }
652 
653  PySubStream *ss = payload2->items[1]->AsSubStream();
654  if (ss == nullptr) {
655  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - ss is null.");
656  PyDecRef(payload);
657  PySafeDecRef(payload2);
658  return false;
659  }
660 
661  ss->DecodeData();
662  if (ss->decoded() == nullptr) {
663  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - Unable to decode call stream");
664  PyDecRef(payload);
665  PySafeDecRef(ss);
666  PySafeDecRef(payload2);
667  return false;
668  }
669 
670  if (!ss->decoded()->IsTuple()) {
671  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - packet body does not contain a tuple");
672  PyDecRef(payload);
673  PySafeDecRef(ss);
674  PySafeDecRef(payload2);
675  return false;
676  }
677 
678  PyTuple *maint = ss->decoded()->AsTuple();
679  if (maint == nullptr) {
680  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - maint is null.");
681  return false;
682  }
683  if (maint->items.size() != 4) {
684  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - packet body has %lu elements, expected %d", maint->items.size(), 4);
685  PyDecRef(payload);
686  PySafeDecRef(ss);
687  PySafeDecRef(maint);
688  PySafeDecRef(payload2);
689  return false;
690  }
691 
692  //parse first tuple element, unknown
693  if (maint->items[0]->IsInt()) {
695  remoteObjectStr = "";
696  } else if (maint->items[0]->IsString()) {
697  remoteObject = 0;
699  } else {
700  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - maint->items[0] has invalid type %s", maint->items[0]->TypeString());
701  codelog(NET__PACKET_ERROR, " in:");
702  payload->Dump(NET__PACKET_ERROR, " ");
703  PyDecRef(payload);
704  PySafeDecRef(ss);
705  PySafeDecRef(maint);
706  PySafeDecRef(payload2);
707  return false;
708  }
709 
710  //parse tuple[1]: method name
711  if (maint->items[1]->IsString()) {
712  method = PyRep::StringContent(maint->items[1]);
713  } else {
714  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - maint->items[1] has non-string type");
715  maint->items[1]->Dump(NET__PACKET_ERROR, " --> ");
716  codelog(NET__PACKET_ERROR, " in:");
717  payload->Dump(NET__PACKET_ERROR, " ");
718  PyDecRef(payload);
719  PySafeDecRef(ss);
720  PySafeDecRef(maint);
721  PySafeDecRef(payload2);
722  return false;
723  }
724 
725  //grab argument list.
726  if (!maint->items[2]->IsTuple()) {
727  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - argument list has non-tuple type");
728  maint->items[2]->Dump(NET__PACKET_ERROR, " --> ");
729  codelog(NET__PACKET_ERROR, "in:");
730  payload->Dump(NET__PACKET_ERROR, " ");
731  PyDecRef(payload);
732  PySafeDecRef(ss);
733  PySafeDecRef(maint);
734  PySafeDecRef(payload2);
735  return false;
736  }
737  arg_tuple = maint->items[2]->AsTuple();
738 
739  //options dict
740  if (maint->items[3]->IsNone()) {
741  arg_dict = nullptr;
742  } else if (maint->items[3]->IsDict()) {
743  arg_dict = maint->items[3]->AsDict();
744  } else {
745  codelog(NET__PACKET_ERROR, "PyCallStream::Decode() - tuple[3] has non-dict type");
746  maint->items[3]->Dump(NET__PACKET_ERROR, " --> ");
747  codelog(NET__PACKET_ERROR, "in:");
748  payload->Dump(NET__PACKET_ERROR, " ");
749  PyDecRef(payload);
750  PySafeDecRef(ss);
751  PySafeDecRef(maint);
752  PySafeDecRef(payload2);
753  return false;
754  }
755 
756  PyDecRef(payload);
757  PySafeDecRef(ss);
758  PySafeDecRef(maint);
759  PySafeDecRef(payload2);
760  return true;
761 }
PyDict * arg_dict
Definition: PyPacket.h:159
PyTuple * AsTuple()
Definition: PyRep.h:138
uint32 remoteObject
Definition: PyPacket.h:154
static std::string StringContent(PyRep *pRep)
Definition: PyRep.cpp:103
bool IsTuple() const
Definition: PyRep.h:108
std::string method
Definition: PyPacket.h:157
Python tuple.
Definition: PyRep.h:567
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
PyRep * decoded() const
Definition: PyRep.h:1048
void DecodeData() const
Definition: PyRep.cpp:1125
#define codelog(type, fmt,...)
Definition: logsys.h:128
PyTuple * arg_tuple
Definition: PyPacket.h:158
#define PyDecRef(op)
Definition: PyRep.h:57
#define PySafeDecRef(op)
Definition: PyRep.h:61
storage_type items
Definition: PyRep.h:628
std::string remoteObjectStr
Definition: PyPacket.h:155
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118

Here is the call graph for this function:

Here is the caller graph for this function:

void PyCallStream::Dump ( LogType  type,
PyVisitor dumper 
)

Definition at line 580 of file PyPacket.cpp.

References _log, arg_dict, arg_tuple, method, remoteObject, remoteObjectStr, PyTuple::visit(), and PyDict::visit().

Referenced by EVECollectDispatcher::Handle_CallReq().

581 {
582  _log(type, "Call Stream:");
583  if (remoteObject == 0)
584  _log(type, " Remote Object: '%s'", remoteObjectStr.c_str());
585  else
586  _log(type, " Remote Object: %u", remoteObject);
587  _log(type, " Method: %s", method.c_str());
588  _log(type, " Arguments:");
589  arg_tuple->visit( dumper );
590  if (arg_dict == nullptr) {
591  _log(type, " Named Arguments: None");
592  } else {
593  _log(type, " Named Arguments:");
594  arg_dict->visit( dumper );
595  }
596 }
PyDict * arg_dict
Definition: PyPacket.h:159
uint32 remoteObject
Definition: PyPacket.h:154
#define _log(type, fmt,...)
Definition: logsys.h:124
std::string method
Definition: PyPacket.h:157
bool visit(PyVisitor &v) const
Visits object.
Definition: PyRep.cpp:675
PyTuple * arg_tuple
Definition: PyPacket.h:158
bool visit(PyVisitor &v) const
Visits object.
Definition: PyRep.cpp:553
std::string remoteObjectStr
Definition: PyPacket.h:155

Here is the call graph for this function:

Here is the caller graph for this function:

PyTuple * PyCallStream::Encode ( )

Definition at line 763 of file PyPacket.cpp.

References arg_dict, arg_tuple, PyTuple::items, method, PyStatic, remoteObject, and remoteObjectStr.

763  {
764  PyTuple *res_tuple = new PyTuple(4);
765 
766  //remoteObject
767  if (remoteObject == 0)
768  res_tuple->items[0] = new PyString(remoteObjectStr.c_str());
769  else
770  res_tuple->items[0] = new PyInt(remoteObject);
771 
772  //method name
773  res_tuple->items[1] = new PyString(method.c_str());
774 
775  //args
776  res_tuple->items[2] = arg_tuple; // no need to clone here. set actual rep in item, and it will be cleaned up by d'tor later
777 
778  //options
779  if (arg_dict == nullptr)
780  res_tuple->items[3] = PyStatic.NewNone();
781  else
782  res_tuple->items[3] = arg_dict; // no need to clone here. set actual rep in item, and it will be cleaned up by d'tor later
783 
784  //now that we have the main arg tuple, build the unknown stuff around it...
785  PyTuple *it2 = new PyTuple(2);
786  it2->items[0] = new PyInt(remoteObject==0?1:0); /* some sort of flag, "process here or call UP"....*/
787  it2->items[1] = new PySubStream(res_tuple);
788  PyTuple *it1 = new PyTuple(2);
789  it1->items[0] = it2;
790  it1->items[1] = PyStatic.NewNone(); //this is the "channel" dict if populated.
791  return it1;
792 }
PyDict * arg_dict
Definition: PyPacket.h:159
uint32 remoteObject
Definition: PyPacket.h:154
Python string.
Definition: PyRep.h:430
std::string method
Definition: PyPacket.h:157
Python tuple.
Definition: PyRep.h:567
Python integer.
Definition: PyRep.h:231
PyTuple * arg_tuple
Definition: PyPacket.h:158
#define PyStatic
Definition: PyRep.h:1209
storage_type items
Definition: PyRep.h:628
std::string remoteObjectStr
Definition: PyPacket.h:155

Member Data Documentation

PyDict* PyCallStream::arg_dict

Definition at line 159 of file PyPacket.h.

Referenced by Clone(), Decode(), Dump(), Encode(), Client::Handle_CallReq(), and ~PyCallStream().

PyTuple* PyCallStream::arg_tuple
std::string PyCallStream::method
uint32 PyCallStream::remoteObject

Definition at line 154 of file PyPacket.h.

Referenced by Clone(), Decode(), Dump(), and Encode().

std::string PyCallStream::remoteObjectStr

Definition at line 155 of file PyPacket.h.

Referenced by Clone(), Decode(), Dump(), Encode(), and Client::Handle_CallReq().


The documentation for this class was generated from the following files: