Module jcifs

Class SMBUtil

java.lang.Object
org.codelibs.jcifs.smb.internal.util.SMBUtil

public class SMBUtil extends Object
SMB protocol utility class providing low-level data encoding and decoding operations. Contains methods for reading and writing various data types (integers, strings, timestamps) in SMB protocol format, handling endianness and data type conversions.
Author:
mbechler
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte[]
    SMB1 protocol header template with magic number 0xFF 'SMB'
    static final byte[]
    SMB2 protocol header template with magic number 0xFE 'SMB'
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    readInt2(byte[] src, int srcIndex)
    Reads a 16-bit integer value from a byte array in little-endian format
    static int
    readInt4(byte[] src, int srcIndex)
    Reads a 32-bit integer value from a byte array in little-endian format
    static long
    readInt8(byte[] src, int srcIndex)
    Reads a 64-bit integer value from a byte array in little-endian format
    static long
    readTime(byte[] src, int srcIndex)
    Reads a Windows FILETIME value and converts it to Java time in milliseconds
    static long
    readUTime(byte[] buffer, int bufferIndex)
    Reads a Unix time value (32-bit seconds) and converts it to Java time in milliseconds
    static void
    writeInt2(long val, byte[] dst, int dstIndex)
    Writes a 16-bit integer value to a byte array in little-endian format
    static void
    writeInt4(long val, byte[] dst, int dstIndex)
    Writes a 32-bit integer value to a byte array in little-endian format
    static void
    writeInt8(long val, byte[] dst, int dstIndex)
    Writes a 64-bit integer value to a byte array in little-endian format
    static void
    writeTime(long t, byte[] dst, int dstIndex)
    Writes a Java time value as a Windows FILETIME
    static void
    writeUTime(long t, byte[] dst, int dstIndex)
    Writes a Java time value as a Unix time (32-bit seconds)

    Methods inherited from class java.lang.Object

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

    • SMB_HEADER

      public static final byte[] SMB_HEADER
      SMB1 protocol header template with magic number 0xFF 'SMB'
    • SMB2_HEADER

      public static final byte[] SMB2_HEADER
      SMB2 protocol header template with magic number 0xFE 'SMB'
  • Method Details

    • writeInt2

      public static void writeInt2(long val, byte[] dst, int dstIndex)
      Writes a 16-bit integer value to a byte array in little-endian format
      Parameters:
      val - the value to write
      dst - the destination byte array
      dstIndex - the starting index in the destination array
    • writeInt4

      public static void writeInt4(long val, byte[] dst, int dstIndex)
      Writes a 32-bit integer value to a byte array in little-endian format
      Parameters:
      val - the value to write
      dst - the destination byte array
      dstIndex - the starting index in the destination array
    • readInt2

      public static int readInt2(byte[] src, int srcIndex)
      Reads a 16-bit integer value from a byte array in little-endian format
      Parameters:
      src - the source byte array
      srcIndex - the starting index in the source array
      Returns:
      the 16-bit integer value
    • readInt4

      public static int readInt4(byte[] src, int srcIndex)
      Reads a 32-bit integer value from a byte array in little-endian format
      Parameters:
      src - the source byte array
      srcIndex - the starting index in the source array
      Returns:
      the 32-bit integer value
    • readInt8

      public static long readInt8(byte[] src, int srcIndex)
      Reads a 64-bit integer value from a byte array in little-endian format
      Parameters:
      src - the source byte array
      srcIndex - the starting index in the source array
      Returns:
      the 64-bit integer value
    • writeInt8

      public static void writeInt8(long val, byte[] dst, int dstIndex)
      Writes a 64-bit integer value to a byte array in little-endian format
      Parameters:
      val - the value to write
      dst - the destination byte array
      dstIndex - the starting index in the destination array
    • readTime

      public static long readTime(byte[] src, int srcIndex)
      Reads a Windows FILETIME value and converts it to Java time in milliseconds
      Parameters:
      src - the source byte array
      srcIndex - the starting index in the source array
      Returns:
      the time value in milliseconds since January 1, 1970 UTC
    • writeTime

      public static void writeTime(long t, byte[] dst, int dstIndex)
      Writes a Java time value as a Windows FILETIME
      Parameters:
      t - the time value in milliseconds since January 1, 1970 UTC
      dst - the destination byte array
      dstIndex - the starting index in the destination array
    • readUTime

      public static long readUTime(byte[] buffer, int bufferIndex)
      Reads a Unix time value (32-bit seconds) and converts it to Java time in milliseconds
      Parameters:
      buffer - the source byte array
      bufferIndex - the starting index in the source array
      Returns:
      the time value in milliseconds since January 1, 1970 UTC
    • writeUTime

      public static void writeUTime(long t, byte[] dst, int dstIndex)
      Writes a Java time value as a Unix time (32-bit seconds)
      Parameters:
      t - the time value in milliseconds since January 1, 1970 UTC
      dst - the destination byte array
      dstIndex - the starting index in the destination array