示例#1
0
  private int bufferLength() {
    int length = 0;
    Object[] inparams = inParams.toArray();
    for (int i = 0; i < inparams.length; i++) {
      if (inparams[i] == null) {
        length = length + 4;
        continue;
      }
      int length2 =
          JIMarshalUnMarshalHelper.getLengthInBytes(
              inparams[i].getClass(), inparams[i], JIFlags.FLAG_NULL);
      length = length + length2;
    }

    return length + 2048; // 2K extra for alignments, if any.
  }
示例#2
0
  private void readPacket(NetworkDataRepresentation ndr, boolean fromCallback) {

    if (session == null) {
      throw new IllegalStateException(
          "Programming Error ! Session not attached with this call ! ... Please rectify ! ");
    }

    int index = 0;

    outparams = outParams.toArray();

    if (JISystem.getLogger().isLoggable(Level.FINEST)) {
      String str = "";
      for (int i = 0; i < outparams.length; i++) {
        str = str + "Out Param:[" + i + "]" + outparams[i] + "\n";
      }

      JISystem.getLogger().finest(str);
    }

    ArrayList comObjects = new ArrayList();
    Map additionalData = new HashMap();
    additionalData.put(CURRENTSESSION, session);
    additionalData.put(COMOBJECTS, comObjects);
    ArrayList results = new ArrayList();
    // user has nothing to return.
    if (outparams != null && outparams.length > 0) {
      while (index < outparams.length) {
        List listOfDefferedPointers = new ArrayList();
        results.add(
            JIMarshalUnMarshalHelper.deSerialize(
                ndr,
                outparams[index],
                listOfDefferedPointers,
                ((Integer) outparamFlags.get(index)).intValue(),
                additionalData));
        int x = 0;

        while (x < listOfDefferedPointers.size()) {

          ArrayList newList = new ArrayList();
          JIPointer replacement =
              (JIPointer)
                  JIMarshalUnMarshalHelper.deSerialize(
                      ndr,
                      (JIPointer) listOfDefferedPointers.get(x),
                      newList,
                      ((Integer) outparamFlags.get(index)).intValue(),
                      additionalData);
          ((JIPointer) listOfDefferedPointers.get(x))
              .replaceSelfWithNewPointer(
                  replacement); // this should replace the value in the original place.
          x++;
          listOfDefferedPointers.addAll(x, newList);
        }
        index++;
      }

      // now create the right COM Objects, it is required here only and no place else.
      for (int i = 0; i < comObjects.size(); i++) {
        JIComObjectImpl comObjectImpl = (JIComObjectImpl) comObjects.get(i);
        try {
          IJIComObject comObject = null;
          if (fromCallback) {
            // this is a new IP , so make a new JIComServer for this.
            JISession newsession = JISession.createSession(session);
            newsession.setGlobalSocketTimeout(session.getGlobalSocketTimeout());
            newsession.useSessionSecurity(session.isSessionSecurityEnabled());
            newsession.useNTLMv2(session.isNTLMv2Enabled());
            JIComServer comServer =
                new JIComServer(newsession, comObjectImpl.internal_getInterfacePointer(), null);
            comObject = comServer.getInstance();
            JIFrameworkHelper.link2Sessions(session, newsession);
          } else {
            if (comObjectImpl.internal_getInterfacePointer().isCustomObjRef()) {
              continue;
            }
            comObject =
                JIFrameworkHelper.instantiateComObject2(
                    session, comObjectImpl.internal_getInterfacePointer());
          }

          comObjectImpl.replaceMembers(comObject);
          JIFrameworkHelper.addComObjectToSession(
              comObjectImpl.getAssociatedSession(), comObjectImpl);
          // Why did I put this here. We should do an addRef regardless of whether we give a pointer
          // to COM or it gives us one.
          //					if (!fromCallback)
          {
            comObjectImpl.addRef();
          }

        } catch (JIException e) {
          JISystem.getLogger().throwing("JICallBuilder", "readPacket", e);
          throw new JIRuntimeException(e.getErrorCode());
        }
        // replace the members of the original com objects by the completed ones.
      }

      comObjects.clear();
    }

    outparams = results.toArray();
    executed = true;
  }
示例#3
0
  private void writePacket(NetworkDataRepresentation ndr) {
    if (session == null) {
      throw new IllegalStateException(
          "Programming Error ! Session not attached with this call ! ... Please rectify ! ");
    }

    Object[] inparams = inParams.toArray();

    int index = 0;
    if (inparams != null) {
      //			if (JISystem.getLogger().isLoggable(Level.FINEST))
      //			{
      //				String str = "";
      //				for (int i = 0;i < inparams.length;i++)
      //				{
      //					str = str + "In Param:[" + i + "] " + inparams[i] + "\n";
      //				}
      //				JISystem.getLogger().finest(str);
      //			}
      while (index < inparams.length) {
        List listOfDefferedPointers = new ArrayList();
        if (inparams[index] == null) {
          JIMarshalUnMarshalHelper.serialize(
              ndr, Integer.class, new Integer(0), listOfDefferedPointers, JIFlags.FLAG_NULL);
        } else {
          JIMarshalUnMarshalHelper.serialize(
              ndr,
              inparams[index].getClass(),
              inparams[index],
              listOfDefferedPointers,
              ((Integer) inparamFlags.get(index)).intValue());
        }

        int x = 0;

        while (x < listOfDefferedPointers.size()) {
          //					thought of this today morning...change the logic here...the defeered pointers need
          // to be
          //					completely serialized here. If they are also having nested deffered pointers then
          // those pointers
          //					should be "inserted" just after the current pointer itself.
          //					change the logic below to send out a new list and insert that list after the
          // current x.
          //					consider the case when there is a Struct having a nested pointer to another struct
          // and this struct
          //					itself having a pointer.
          //
          //					Inparams order:- for 2 params.
          //					int f,Struct{int i;
          //								 Struct *ptr;
          //								 Struct *ptr2;
          //								 int j;
          //								}
          //
          //					while serializing this struct the pointer 1 will get deffered and so will pointer
          // 2. Now while writing
          //					the deffered pointers , we will find that the pointer 1 is pointing to a struct
          // which has another deffered pointer (pointer to another struct maybe)
          //					in such case, the current logic will add the deffered pointer to the end of the
          // listOfDefferedPointers list, effectively serializing it
          //					after the pointer 2 referent. But that is what is against the rules of DCERPC, in
          // this case the referent of pointer 1 (struct with the pointer to another struct)
          //					should be serialized in place (following th rules of the struct serialization
          // ofcourse) and should not go to the end of the list.

          // JIMarshalUnMarshalHelper.serialize(ndr,JIPointer.class,(JIPointer)listOfDefferedPointers.get(x),listOfDefferedPointers,inparamFlags);
          ArrayList newList = new ArrayList();
          JIMarshalUnMarshalHelper.serialize(
              ndr,
              JIPointer.class,
              (JIPointer) listOfDefferedPointers.get(x),
              newList,
              ((Integer) inparamFlags.get(index)).intValue());
          x++; // incrementing index
          listOfDefferedPointers.addAll(x, newList);
        }
        index++;
      }
    }
  }