Пример #1
0
 public TransStruct parse(Buffer b, SmbSession session) {
   fileSystemAttributes = ByteOrderConverter.swap(b.getInt());
   maxFileNameLengthInBytes = ByteOrderConverter.swap(b.getInt());
   lengthOfFileSystemName = ByteOrderConverter.swap(b.getInt());
   fileSystemName = NetBiosNameCodec.readSmbUnicodeName(b, lengthOfFileSystemName);
   return this;
 }
Пример #2
0
  @Override
  public SmbData parseRequest(SmbHeader h, Buffer b, SmbSession session) {
    Transaction2Request data = new Transaction2Request();
    Trans2SubcommandMapper mapper = new Trans2SubcommandMapper();
    byte[] setup;
    byte[] pad1;
    byte[] pad2;
    byte[] parameters;
    byte[] buff;
    data.setWordCount(b.get());
    if (data.getWordCount() >= 0x0E) {
      data.setTotalParameterCount(ByteOrderConverter.swap(b.getShort()));
      data.setTotalDataCount(ByteOrderConverter.swap(b.getShort()));
      data.setMaxParameterCount(ByteOrderConverter.swap(b.getShort()));
      data.setMaxDataCount(ByteOrderConverter.swap(b.getShort()));
      data.setMaxSetupCount(b.get());
      data.setReserved1(b.get());
      data.setFlags(ByteOrderConverter.swap(b.getShort()));
      data.setTimeout(ByteOrderConverter.swap(b.getInt()));
      data.setReserved2(ByteOrderConverter.swap(b.getShort()));
      data.setParameterCount(ByteOrderConverter.swap(b.getShort()));
      data.setParameterOffset(ByteOrderConverter.swap(b.getShort()));
      data.setDataCount(ByteOrderConverter.swap(b.getShort()));
      data.setDataOffset(ByteOrderConverter.swap(b.getShort()));
      data.setSetupCount(b.get());
      data.setReserved3(b.get());
      setup = new byte[data.getSetupCount() * 2];
      b.gets(setup);
      data.setSetup(setup);
    } else {
      data.setMalformed(true);
      b.skip(data.getWordCount() * 2);
    }
    data.setByteCount(ByteOrderConverter.swap(b.getShort()));
    if (b.readableBytes() != data.getByteCount()) {
      data.setMalformed(true);
      return data;
    } else if (data.isMalformed()) {
      return data;
    }
    data.setName(NetBiosNameCodec.readOemName(b));

    if (data.getParameterCount() != 0) {
      pad1 = new byte[data.getParameterOffset() - b.position()];
      if (pad1.length != 0) {
        b.gets(pad1);
        data.setPad1(pad1);
      }
      parameters = new byte[data.getParameterCount()];
      b.gets(parameters);
      data.setTrans2Parameters(parameters);
    }
    if (data.getDataCount() != 0) {
      pad2 = new byte[data.getDataOffset() - b.position()];
      if (pad2.length != 0) {
        b.gets(pad2);
        data.setPad2(pad2);
      }
      buff = new byte[data.getDataCount()];
      b.gets(buff);
      data.setTrans2Data(buff);
    }

    Buffer setupBuffer = new ChainBuffer();
    Buffer parameterBuffer = new ChainBuffer();
    Buffer dataBuffer = new ChainBuffer();
    setupBuffer.addLast(data.getSetup());
    parameterBuffer.addLast(data.getTrans2Parameters());
    dataBuffer.addLast(data.getTrans2Data());
    setupBuffer.mark();
    TransParser parser =
        mapper.getParser(
            Transaction2Command.parse(ByteOrderConverter.swap(setupBuffer.getShort())));
    setupBuffer.reset();
    data.setTransaction2Data(parser.parseRequest(setupBuffer, parameterBuffer, dataBuffer));
    return data;
  }