/** * Get the data byte count for the SMB packet * * @return Data byte count */ public final int getByteCount() { // Calculate the offset of the byte count int pos = PARAMWORDS + (2 * getParameterCount()); return (int) DataPacker.getIntelShort(m_smbbuf, pos); }
/** * Get a parameter word from the SMB packet. * * @param idx Parameter index (zero based). * @return Parameter word value. * @exception java.lang.IndexOutOfBoundsException If the parameter index is out of range. */ public final int getParameter(int idx) throws java.lang.IndexOutOfBoundsException { // Range check the parameter index if (idx > getParameterCount()) throw new java.lang.IndexOutOfBoundsException(); // Calculate the parameter word offset int pos = WORDCNT + (2 * idx) + 1; return (int) (DataPacker.getIntelShort(m_smbbuf, pos) & 0xFFFF); }
/** * Get the request operation id * * @return int */ public final int getOperationId() { return DataPacker.getIntelShort(getBuffer(), m_offset + OPERATIONID); }
/** * Get the request presentation identifier * * @return int */ public final int getPresentationIdentifier() { return DataPacker.getIntelShort(getBuffer(), m_offset + PRESENTIDENT); }
/** * Return the authentication length * * @return int */ public final int getAuthenticationLength() { return DataPacker.getIntelShort(getBuffer(), m_offset + AUTHLEN); }
/** * Return the fragment length * * @return int */ public final int getFragmentLength() { return DataPacker.getIntelShort(getBuffer(), m_offset + FRAGMENTLEN); }
/** * Get the user identifier (UID) * * @return User identifier (UID) */ public final int getUserId() { return DataPacker.getIntelShort(m_smbbuf, UID); }
/** * Get the tree identifier (TID) * * @return Tree identifier (TID) */ public final int getTreeId() { return DataPacker.getIntelShort(m_smbbuf, TID); }
/** * Get the session identifier (SID) * * @return Session identifier (SID) */ public final int getSID() { return DataPacker.getIntelShort(m_smbbuf, SID); }
/** * Get the process identifier (PID) high bytes, or zero if not used * * @return Process identifier value. */ public final int getProcessIdHigh() { return DataPacker.getIntelShort(m_smbbuf, PIDHIGH); }
/** * Get the multiplex identifier. * * @return Multiplex identifier. */ public final int getMultiplexId() { return DataPacker.getIntelShort(m_smbbuf, MID); }
/** * Return the NetBIOS header data length value. * * @return int */ public final int getHeaderLength() { return DataPacker.getIntelShort(m_smbbuf, 2) & 0xFFFF; }
/** * Get the SMB flags2 value. * * @return SMB flags2 value. */ public final int getFlags2() { return (int) DataPacker.getIntelShort(m_smbbuf, FLAGS2); }
/** * Unpack a word (16 bit) value from the byte area * * @return int */ public final int unpackWord() { int val = DataPacker.getIntelShort(m_smbbuf, m_pos); m_pos += 2; return val; }
/** * Decode a block of data according to the data descriptor string and return a vector of the * values converted to Java object types. * * @param buf Byte array containing the data to be unpacked * @param off Offset within the buffer that the data begins * @param desc Data descriptor string * @param objs Vector to store the decoded objects into * @param conv Converter used to locate strings within a data block. * @return Offset within the data buffer at the end of this data block */ protected static final int DecodeData(byte[] buf, int off, String desc, Vector objs, int conv) { // Scan the data descriptor string and convert each data item in the data // block int bufpos = off; int pos = 0; while (pos < desc.length()) { // Get the current data item type char dtype = desc.charAt(pos++); int dlen = 1; // Check if a data length has been specified if (pos < desc.length() && Character.isDigit(desc.charAt(pos))) { // Convert the data length string int numlen = 1; int numpos = pos + 1; while (numpos < desc.length() && Character.isDigit(desc.charAt(numpos++))) numlen++; // Set the data length dlen = Integer.parseInt(desc.substring(pos, pos + numlen)); // Update the descriptor string position pos = numpos - 1; } // Convert the current data item switch (dtype) { // Word (16 bit) data type case 'W': // Unpack words from the data block int sval; while (dlen-- > 0) { // Unpack the current word value sval = DataPacker.getIntelShort(buf, bufpos); objs.addElement(new Short((short) sval)); // Update the buffer pointer bufpos += 2; } break; // Integer (32 bit) data type case 'D': // Unpack integer values from the data block int ival; while (dlen-- > 0) { // Unpack the current integer value ival = DataPacker.getIntelInt(buf, bufpos); objs.addElement(new Integer(ival)); // Update the buffer pointer bufpos += 4; } break; // Byte data type case 'B': // For a single byte return a Byte else return the bytes as a String // object. if (dlen == 1) { objs.addElement(new Byte(buf[bufpos++])); } else { int endlen = 0; while (endlen < dlen && buf[bufpos + endlen] != 0x00) endlen++; String strval = new String(buf, bufpos, endlen); objs.addElement(strval); bufpos += dlen; } break; // Null terminated string data type case 'z': // Find the end of the null terminated string short spos = (short) DataPacker.getIntelInt(buf, bufpos); spos -= (short) conv; if (spos < buf.length && spos > 0) { int endpos = spos; while (buf[endpos] != 0) endpos++; // Add a string to the data vector String str = new String(buf, spos, endpos - spos); objs.addElement(str); } else objs.addElement(""); // Add 32-bit value size to buffer position bufpos += 4; break; // Skip 'n' bytes in the buffer case '.': bufpos += dlen; break; // Integer (32 bit) data type converted to a date/time value case 'T': // Unpack integer values from the data block int dval; while (dlen-- > 0) { // Unpack the current integer value dval = DataPacker.getIntelInt(buf, bufpos); // Build a Date object using the integer value as seconds since the // base date/time of 1-Jan-1970 00:00 Date datetime = new Date((long) dval * 1000); objs.addElement(datetime); // Update the buffer pointer bufpos += 4; } break; } // end switch data type } // end while descriptor string // Return the new buffer offset return bufpos; }