Beispiel #1
0
int          clsDump::DumpScope(clsScope * pScope, int onlyCalculateSize)
{
  int          iSize = 0;
  unsigned int iIndex;

  iSize += DumpLine("----- SCOPE BEG -----\n", onlyCalculateSize);
  iSize += DumpLine("\tUID %u\n", pScope->m_UID, onlyCalculateSize);
  iSize += DumpLocation(pScope->m_Location, onlyCalculateSize);
  _Assert(pScope->m_pParentScope && "Frontend Error: All scopes should have a parent.");
  iSize += DumpLine("\tParent Scope UID %u\n", pScope->m_pParentScope->m_UID, onlyCalculateSize);
  _Assert(pScope->m_pRootScope && "Frontend Error: All scopes should have a root.");
  iSize += DumpLine("\tRoot Scope UID %u\n", pScope->m_pRootScope->m_UID, onlyCalculateSize);
  iSize += DumpLine("\tNumber of Children Scopes %u\n", pScope->m_pChildrenScopes.size(), onlyCalculateSize);
  for (iIndex = 0; iIndex < pScope->m_pChildrenScopes.size(); ++iIndex)
  {
    iSize += DumpLine("\tChild Scope UID %u\n", pScope->m_pChildrenScopes[iIndex]->m_UID, onlyCalculateSize);
  }
  iSize += DumpLine("\tNumber of Signals %u\n", pScope->m_pSignals.size(), onlyCalculateSize);
  for (iIndex = 0; iIndex < pScope->m_pSignals.size(); ++iIndex)
  {
    iSize += DumpLine("\tSignal UID %u\n", pScope->m_pSignals[iIndex]->m_UID, onlyCalculateSize);
  }
  iSize += DumpLine("\tNumber of Arguments %u\n", pScope->m_pArguments.size(), onlyCalculateSize);
  for (iIndex = 0; iIndex < pScope->m_pArguments.size(); ++iIndex)
  {
    iSize += DumpLine("\tArgument UID %u\n", pScope->m_pArguments[iIndex]->m_UID, onlyCalculateSize);
  }
  iSize += DumpLine("\tNumber of Parameters %u\n", pScope->m_pParameters.size(), onlyCalculateSize);
  for (iIndex = 0; iIndex < pScope->m_pParameters.size(); ++iIndex)
  {
    iSize += DumpLine("\tParameter UID %u\n", pScope->m_pParameters[iIndex]->m_UID, onlyCalculateSize);
  }
  iSize += DumpLine("\tNumber of Conditions %u\n", pScope->m_pConditions.size(), onlyCalculateSize);
  for (iIndex = 0; iIndex < pScope->m_pConditions.size(); ++iIndex)
  {
    iSize += DumpLine("\tCondition UID %u\n", pScope->m_pConditions[iIndex]->m_UID, onlyCalculateSize);
  }
  iSize += DumpLine("\tNumber of Events %u\n", pScope->m_pEvents.size(), onlyCalculateSize);
  for (iIndex = 0; iIndex < pScope->m_pEvents.size(); ++iIndex)
  {
    iSize += DumpLine("\tEvent UID %u\n", pScope->m_pEvents[iIndex]->m_UID, onlyCalculateSize);
  }
  if (pScope->m_pBasicBlock)
  {
    iSize += DumpLine("\tHas Basicblock %u\n", true, onlyCalculateSize);
    iSize += DumpLine("\tBasicblock UID %u\n", pScope->m_pBasicBlock->m_UID, onlyCalculateSize);
  }
  else
  {
    iSize += DumpLine("\tHas No Basicblock %u\n", false, onlyCalculateSize);
  }
  iSize += DumpString("\tScope Name\n", pScope->m_sScopeName, onlyCalculateSize);
  iSize += DumpLine("\tScope Type UID %u\n", pScope->m_pScopeType->m_UID, onlyCalculateSize);
  iSize += DumpLine("\tScope is Root = %u\n", pScope->m_IsRoot, onlyCalculateSize);
  iSize += DumpLine("\tScope is Automatic = %u\n", pScope->m_IsAutomatic, onlyCalculateSize);
  iSize += DumpLine("----- SCOPE END -----\n", onlyCalculateSize);

  return iSize;
}
Beispiel #2
0
void	HandleQuery(Host Session_SN, uchar *Query, int Size)
{
    uchar		*Browser;
    SResponse	Response;
    CLocation	TesterLocation;
    Host		Tested;
    SessProp	*SessionProposal;
    uint Idx = 0;
    uint Rank = 0;

    Browser = Query;

    while (Size > 0)
    {
        Response.Objs = NULL;
        Response.NbObj = 0;
        TCPResponseManager(&Browser, (uint *)&Size, &Response);
        uint Idx = 0;

        switch (Response.Cmd / 8)
        {
        case CMD_QUERY_IPING:
            printf("Received Incoming Initial Ping..\n");
            for (Idx = 0; Idx < Response.NbObj; Idx++)
            {
                switch (Response.Objs[Idx].Id)
                {
                case OBJ_ID_PINGER:
                    printf("Ping Coming From : %s.. Let's Reply..\n", Response.Objs[Idx].Value.Memory.Memory);
                    PingReply(Session_SN, Response.Reply2ID);
                    break;
                default:
                    break;
                }
            }
            break;
        case CMD_QUERY_SESSION:
            printf("Received session proposal..\n");

            SessionProposal = (SessProp *)malloc(sizeof(SessProp));
            SessionProposal->Relays = new queue<Host>;
            SessionProposal->SessID = BytesRandomWord() % 0x7FFF;
            *(uint *)(SessionProposal->PeerChallenge) = BytesRandom();
            *(uint *)(SessionProposal->PeerChallenge + 4) = BytesRandom();

            printf("Challenge to propose to Peer : ");
            showmem((uchar *)SessionProposal->PeerChallenge, 0x08);

            SessionProposal->CreatedSID = 0x00;
            SessionProposal->LocalCreatedSID = 0x00;

            for (Idx = 0; Idx < Response.NbObj; Idx++)
            {
                if (Response.Objs[Idx].ObjListInfos.Id == -1)
                {
                    switch(Response.Objs[Idx].Id)
                    {
                    case OBJ_ID_SESPROPOSER:
                        LocationBlob2Location(Response.Objs[Idx].Value.Memory.Memory, &(SessionProposal->ProposerLocation), Response.Objs[Idx].Value.Memory.MsZ);
                        printf("Proposer Node : ");
                        DumpLocation(&(SessionProposal->ProposerLocation));
                        break;
                    case OBJ_ID_SESCHALLENG:
                        printf("Session Challenge : ");
                        showmem(Response.Objs[Idx].Value.Table, sizeof(Response.Objs[Idx].Value.Table));
                        memcpy_s(SessionProposal->Challenge, sizeof(SessionProposal->Challenge), Response.Objs[Idx].Value.Table, sizeof(SessionProposal->Challenge));
                        break;
                    case OBJ_ID_PEERSESSID:
                        printf("Peer Choosen Session ID : 0x%x\n", Response.Objs[Idx].Value.Nbr);
                        SessionProposal->PeerSessID = Response.Objs[Idx].Value.Nbr;
                    default:
                        break;
                    }
                }
            }

            uint		NbObjLists;
            Memory_U	RelaysInfos;

            RelaysInfos.Memory = (uchar *)malloc(0xFF);
            ZeroMemory(RelaysInfos.Memory, 0xFF);
            RelaysInfos.MsZ = 0xFF;
            Browser = RelaysInfos.Memory;

            NbObjLists = DefNbObjList(Response);
            for (Rank = 0; Rank < NbObjLists + 1; Rank++)
            {
                Host	Relay;
                uint	State, ObjOccur;

                State = ObjOccur = 0;
                for (uint Idx = 0; Idx < Response.NbObj; Idx++)
                {
                    if ((Response.Objs[Idx].ObjListInfos.Id == 0x07) && (Response.Objs[Idx].ObjListInfos.Rank == Rank))
                    {
                        if (!ObjOccur)
                        {
                            memcpy_s(Browser, 0xFF, "\x05\x07\x41\x03", 0x04);
                            Browser += 0x04;
                            ObjOccur = 1;
                        }
                        WriteObject(&Browser, Response.Objs[Idx]);
                        switch(Response.Objs[Idx].Id)
                        {
                        case OBJ_ID_RELAY:
                            printf("Proposed Relay : %s:%d\n", Response.Objs[Idx].Value.Addr.ip, Response.Objs[Idx].Value.Addr.port);
                            strcpy_s(Relay.ip, MAX_IP_LEN + 1, Response.Objs[Idx].Value.Addr.ip);
                            Relay.port = Response.Objs[Idx].Value.Addr.port;
                            State += 1;
                            break;
                        case OBJ_ID_SID2DEC:
                            printf("Session To Declare on this relay : 0x%x\n", Response.Objs[Idx].Value.Nbr);
                            Relay.SessionID2Declare = Response.Objs[Idx].Value.Nbr;
                            State += 1;
                        default:
                            break;
                        }
                    }
                }
                if (State == 2)
                    SessionProposal->Relays->push(Relay);
            }
            RelaysInfos.MsZ = (uint)(Browser - RelaysInfos.Memory);
            SessionProposal->RelaysInfos = RelaysInfos;

            printf("Accepted session.. Let's initialize..\n");

            uchar	RecvCopy[0xFFFF];
            int		RecvSzCopy;

            ZeroMemory(RecvCopy, 0xFFFF);
            memcpy_s(RecvCopy, 0xFFFF, Query, Size);
            RecvSzCopy = Size;

            SessionPropReply(Session_SN, Response.Reply2ID);
            InitSession(SessionProposal);

            ZeroMemory(RecvBuffer, 0xFFFF);
            memcpy_s(Query, 0xFFFF, RecvCopy, RecvSzCopy);
            Size = RecvSzCopy;
            break;
        case CMD_QUERY_UDPTEST:
            printf("Received UDP Test report..\n");
            Tested.port = 0;
            for (Idx = 0; Idx < Response.NbObj; Idx++)
            {
                switch(Response.Objs[Idx].Id)
                {
                case OBJ_ID_TESTED:
                    printf("Peer Tested my UDP Address : %s:%d\n", Response.Objs[Idx].Value.Addr.ip, Response.Objs[Idx].Value.Addr.port);
                    if (Tested.port == 0)
                        Tested = Response.Objs[Idx].Value.Addr;
                    break;
                case OBJ_ID_TESTER:
                    LocationBlob2Location(Response.Objs[Idx].Value.Memory.Memory, &TesterLocation, Response.Objs[Idx].Value.Memory.MsZ);
                    printf("Tester Node : ");
                    DumpLocation(&TesterLocation);
                    printf("Should UDP Test %s:%d\n", TesterLocation.PVAddr.ip, TesterLocation.PVAddr.port);
                    break;
                default:
                    break;
                }
            }
            UDPTestReply(Session_SN, Response.Reply2ID, Tested);
            break;
        default:
            printf("Unhandled Query.. Sending ACK..\n");
            SendACK(Response.PacketID, Session_SN.socket, Session_SN, HTTPS_PORT, &(Session_SN.Connected), &Keys);
            break;
        }
        printf("\n");
    }
}