Module jcifs

Class NdrBuffer

java.lang.Object
org.codelibs.jcifs.smb1.dcerpc.ndr.NdrBuffer

public class NdrBuffer extends Object
NDR (Network Data Representation) buffer for encoding and decoding DCE/RPC messages. This class provides methods for reading and writing primitive types and strings in NDR format for DCE/RPC communication.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    byte[]
    The underlying byte buffer containing the NDR data.
    Buffer for deferred data processing.
    int
    The current position in the buffer.
    int
    The length of data in the buffer.
    int
    The starting position in the buffer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NdrBuffer(byte[] buf, int start)
    Constructs an NdrBuffer with the specified byte array and starting position.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advance(int n)
    Advances the buffer index by the specified number of bytes.
    int
    align(int boundary)
    Aligns the buffer index to the specified boundary.
    int
    align(int boundary, byte value)
    Aligns the buffer index to the specified boundary with a fill value.
    long
    Decodes a hyper integer (8 bytes) from NDR format.
    int
    Decodes a long integer (4 bytes) from NDR format.
    int
    Decodes a short integer (2 bytes) from NDR format.
    int
    Decodes a small integer (1 byte) from NDR format.
    Decodes a string from NDR format.
    derive(int idx)
    Creates a derived NdrBuffer at the specified index position.
    void
    enc_ndr_hyper(long h)
    Encodes a hyper integer (8 bytes) in NDR format.
    void
    enc_ndr_long(int l)
    Encodes a long integer (4 bytes) in NDR format.
    void
    enc_ndr_referent(Object obj, int type)
    Encodes an NDR referent pointer.
    void
    Encodes a short integer (2 bytes) in NDR format.
    void
    Encodes a small integer (1 byte) in NDR format.
    void
    Encodes a string in NDR format.
    byte[]
    Returns the underlying byte buffer.
    int
    Returns the capacity of the buffer.
    int
    Returns the current index position in the buffer.
    int
    Returns the length of data in the buffer.
    int
    Returns the available space at the tail of the buffer.
    void
    readOctetArray(byte[] b, int i, int l)
    Reads an octet array from the buffer.
    void
    Resets the buffer position to the start.
    void
    setIndex(int index)
    Sets the current index position in the buffer.
    void
    setLength(int length)
    Sets the length of data in the buffer.
     
    void
    writeOctetArray(byte[] b, int i, int l)
    Writes an octet array to the buffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • buf

      public byte[] buf
      The underlying byte buffer containing the NDR data.
    • start

      public int start
      The starting position in the buffer.
    • index

      public int index
      The current position in the buffer.
    • length

      public int length
      The length of data in the buffer.
    • deferred

      public NdrBuffer deferred
      Buffer for deferred data processing.
  • Constructor Details

    • NdrBuffer

      public NdrBuffer(byte[] buf, int start)
      Constructs an NdrBuffer with the specified byte array and starting position.
      Parameters:
      buf - the byte array to use as the buffer
      start - the starting position in the buffer
  • Method Details

    • derive

      public NdrBuffer derive(int idx)
      Creates a derived NdrBuffer at the specified index position.
      Parameters:
      idx - the index position for the derived buffer
      Returns:
      the derived NdrBuffer
    • reset

      public void reset()
      Resets the buffer position to the start.
    • getIndex

      public int getIndex()
      Returns the current index position in the buffer.
      Returns:
      the current index
    • setIndex

      public void setIndex(int index)
      Sets the current index position in the buffer.
      Parameters:
      index - the new index position
    • getCapacity

      public int getCapacity()
      Returns the capacity of the buffer.
      Returns:
      the buffer capacity
    • getTailSpace

      public int getTailSpace()
      Returns the available space at the tail of the buffer.
      Returns:
      the available tail space
    • getBuffer

      public byte[] getBuffer()
      Returns the underlying byte buffer.
      Returns:
      the byte buffer
    • align

      public int align(int boundary, byte value)
      Aligns the buffer index to the specified boundary with a fill value.
      Parameters:
      boundary - the alignment boundary
      value - the fill value for padding
      Returns:
      the number of bytes added for alignment
    • writeOctetArray

      public void writeOctetArray(byte[] b, int i, int l)
      Writes an octet array to the buffer.
      Parameters:
      b - the byte array to write
      i - the starting index in the array
      l - the number of bytes to write
    • readOctetArray

      public void readOctetArray(byte[] b, int i, int l)
      Reads an octet array from the buffer.
      Parameters:
      b - the byte array to read into
      i - the starting index in the array
      l - the number of bytes to read
    • getLength

      public int getLength()
      Returns the length of data in the buffer.
      Returns:
      the data length
    • setLength

      public void setLength(int length)
      Sets the length of data in the buffer.
      Parameters:
      length - the new data length
    • advance

      public void advance(int n)
      Advances the buffer index by the specified number of bytes.
      Parameters:
      n - the number of bytes to advance
    • align

      public int align(int boundary)
      Aligns the buffer index to the specified boundary.
      Parameters:
      boundary - the alignment boundary
      Returns:
      the number of bytes added for alignment
    • enc_ndr_small

      public void enc_ndr_small(int s)
      Encodes a small integer (1 byte) in NDR format.
      Parameters:
      s - the small integer value to encode
    • dec_ndr_small

      public int dec_ndr_small()
      Decodes a small integer (1 byte) from NDR format.
      Returns:
      the decoded small integer value
    • enc_ndr_short

      public void enc_ndr_short(int s)
      Encodes a short integer (2 bytes) in NDR format.
      Parameters:
      s - the short integer value to encode
    • dec_ndr_short

      public int dec_ndr_short()
      Decodes a short integer (2 bytes) from NDR format.
      Returns:
      the decoded short integer value
    • enc_ndr_long

      public void enc_ndr_long(int l)
      Encodes a long integer (4 bytes) in NDR format.
      Parameters:
      l - the long integer value to encode
    • dec_ndr_long

      public int dec_ndr_long()
      Decodes a long integer (4 bytes) from NDR format.
      Returns:
      the decoded long integer value
    • enc_ndr_hyper

      public void enc_ndr_hyper(long h)
      Encodes a hyper integer (8 bytes) in NDR format.
      Parameters:
      h - the hyper integer value to encode
    • dec_ndr_hyper

      public long dec_ndr_hyper()
      Decodes a hyper integer (8 bytes) from NDR format.
      Returns:
      the decoded hyper integer value
    • enc_ndr_string

      public void enc_ndr_string(String s)
      Encodes a string in NDR format.
      Parameters:
      s - the string to encode
    • dec_ndr_string

      public String dec_ndr_string() throws NdrException
      Decodes a string from NDR format.
      Returns:
      the decoded string
      Throws:
      NdrException - if decoding fails
    • enc_ndr_referent

      public void enc_ndr_referent(Object obj, int type)
      Encodes an NDR referent pointer.
      Parameters:
      obj - the object to encode as a referent
      type - the referent type
    • toString

      public String toString()
      Overrides:
      toString in class Object