Module jcifs

Class Encdec

java.lang.Object
org.codelibs.jcifs.smb1.util.Encdec

public class Encdec extends Object
Encoding and decoding utility class for SMB1 protocol. Provides methods for encoding/decoding various data types in different byte orders.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Milliseconds between January 1, 1970 and January 1, 1601 (Windows epoch).
    static final long
    Seconds between January 1, 1904 and January 1, 1970 (Mac epoch).
    static final int
    Time encoding type: 1601 epoch, 64-bit nanoseconds, big-endian.
    static final int
    Time encoding type: 1601 epoch, 64-bit nanoseconds, little-endian.
    static final int
    Time encoding type: 1904 epoch, 32-bit seconds, big-endian.
    static final int
    Time encoding type: 1904 epoch, 32-bit seconds, little-endian.
    static final int
    Time encoding type: 1970 epoch, 64-bit milliseconds, big-endian.
    static final int
    Time encoding type: 1970 epoch, 64-bit milliseconds, little-endian.
    static final int
    Time encoding type: 1970 epoch, 32-bit seconds, big-endian.
    static final int
    Time encoding type: 1970 epoch, 32-bit seconds, little-endian.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for Encdec.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    dec_doublebe(byte[] src, int si)
    Decodes a double value from big-endian byte order.
    static double
    dec_doublele(byte[] src, int si)
    Decodes a double value from little-endian byte order.
    static float
    dec_floatbe(byte[] src, int si)
    Decodes a float value from big-endian byte order.
    static float
    dec_floatle(byte[] src, int si)
    Decodes a float value from little-endian byte order.
    static Date
    dec_time(byte[] src, int si, int enc)
    Decodes a Date value according to the specified time encoding type.
    static String
    dec_ucs2le(byte[] src, int si, int slim, char[] buf)
    Decodes a UCS-2 little-endian encoded string from a byte array.
    static short
    dec_uint16be(byte[] src, int si)
    Decodes a 16-bit unsigned integer from big-endian byte order.
    static short
    dec_uint16le(byte[] src, int si)
    Decodes a 16-bit unsigned integer from little-endian byte order.
    static int
    dec_uint32be(byte[] src, int si)
    Decodes a 32-bit unsigned integer from big-endian byte order.
    static int
    dec_uint32le(byte[] src, int si)
    Decodes a 32-bit unsigned integer from little-endian byte order.
    static long
    dec_uint64be(byte[] src, int si)
    Decodes a 64-bit unsigned integer from big-endian byte order.
    static long
    dec_uint64le(byte[] src, int si)
    Decodes a 64-bit unsigned integer from little-endian byte order.
    static String
    dec_utf8(byte[] src, int si, int slim)
    Decodes a UTF-8 encoded string from a byte array.
    static int
    enc_doublebe(double d, byte[] dst, int di)
    Encodes a double value in big-endian byte order.
    static int
    enc_doublele(double d, byte[] dst, int di)
    Encodes a double value in little-endian byte order.
    static int
    enc_floatbe(float f, byte[] dst, int di)
    Encodes a float value in big-endian byte order.
    static int
    enc_floatle(float f, byte[] dst, int di)
    Encodes a float value in little-endian byte order.
    static int
    enc_time(Date date, byte[] dst, int di, int enc)
    Encodes a Date value according to the specified time encoding type.
    static int
    enc_uint16be(short s, byte[] dst, int di)
    Encodes a 16-bit unsigned integer in big-endian byte order.
    static int
    enc_uint16le(short s, byte[] dst, int di)
    Encodes a 16-bit unsigned integer in little-endian byte order.
    static int
    enc_uint32be(int i, byte[] dst, int di)
    Encodes a 32-bit unsigned integer in big-endian byte order.
    static int
    enc_uint32le(int i, byte[] dst, int di)
    Encodes a 32-bit unsigned integer in little-endian byte order.
    static int
    enc_uint64be(long l, byte[] dst, int di)
    Encodes a 64-bit unsigned integer in big-endian byte order.
    static int
    enc_uint64le(long l, byte[] dst, int di)
    Encodes a 64-bit unsigned integer in little-endian byte order.
    static int
    enc_utf8(String str, byte[] dst, int di, int dlim)
    Encodes a String as UTF-8 bytes.

    Methods inherited from class java.lang.Object

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

    • MILLISECONDS_BETWEEN_1970_AND_1601

      public static final long MILLISECONDS_BETWEEN_1970_AND_1601
      Milliseconds between January 1, 1970 and January 1, 1601 (Windows epoch).
      See Also:
    • SEC_BETWEEEN_1904_AND_1970

      public static final long SEC_BETWEEEN_1904_AND_1970
      Seconds between January 1, 1904 and January 1, 1970 (Mac epoch).
      See Also:
    • TIME_1970_SEC_32BE

      public static final int TIME_1970_SEC_32BE
      Time encoding type: 1970 epoch, 32-bit seconds, big-endian.
      See Also:
    • TIME_1970_SEC_32LE

      public static final int TIME_1970_SEC_32LE
      Time encoding type: 1970 epoch, 32-bit seconds, little-endian.
      See Also:
    • TIME_1904_SEC_32BE

      public static final int TIME_1904_SEC_32BE
      Time encoding type: 1904 epoch, 32-bit seconds, big-endian.
      See Also:
    • TIME_1904_SEC_32LE

      public static final int TIME_1904_SEC_32LE
      Time encoding type: 1904 epoch, 32-bit seconds, little-endian.
      See Also:
    • TIME_1601_NANOS_64LE

      public static final int TIME_1601_NANOS_64LE
      Time encoding type: 1601 epoch, 64-bit nanoseconds, little-endian.
      See Also:
    • TIME_1601_NANOS_64BE

      public static final int TIME_1601_NANOS_64BE
      Time encoding type: 1601 epoch, 64-bit nanoseconds, big-endian.
      See Also:
    • TIME_1970_MILLIS_64BE

      public static final int TIME_1970_MILLIS_64BE
      Time encoding type: 1970 epoch, 64-bit milliseconds, big-endian.
      See Also:
    • TIME_1970_MILLIS_64LE

      public static final int TIME_1970_MILLIS_64LE
      Time encoding type: 1970 epoch, 64-bit milliseconds, little-endian.
      See Also:
  • Constructor Details

    • Encdec

      public Encdec()
      Default constructor for Encdec. This is a utility class with static methods.
  • Method Details

    • enc_uint16be

      public static int enc_uint16be(short s, byte[] dst, int di)
      Encodes a 16-bit unsigned integer in big-endian byte order.
      Parameters:
      s - the short value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (2)
    • enc_uint32be

      public static int enc_uint32be(int i, byte[] dst, int di)
      Encodes a 32-bit unsigned integer in big-endian byte order.
      Parameters:
      i - the integer value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (4)
    • enc_uint16le

      public static int enc_uint16le(short s, byte[] dst, int di)
      Encodes a 16-bit unsigned integer in little-endian byte order.
      Parameters:
      s - the short value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (2)
    • enc_uint32le

      public static int enc_uint32le(int i, byte[] dst, int di)
      Encodes a 32-bit unsigned integer in little-endian byte order.
      Parameters:
      i - the integer value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (4)
    • dec_uint16be

      public static short dec_uint16be(byte[] src, int si)
      Decodes a 16-bit unsigned integer from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded short value
    • dec_uint32be

      public static int dec_uint32be(byte[] src, int si)
      Decodes a 32-bit unsigned integer from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded integer value
    • dec_uint16le

      public static short dec_uint16le(byte[] src, int si)
      Decodes a 16-bit unsigned integer from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded short value
    • dec_uint32le

      public static int dec_uint32le(byte[] src, int si)
      Decodes a 32-bit unsigned integer from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded integer value
    • enc_uint64be

      public static int enc_uint64be(long l, byte[] dst, int di)
      Encodes a 64-bit unsigned integer in big-endian byte order.
      Parameters:
      l - the long value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (8)
    • enc_uint64le

      public static int enc_uint64le(long l, byte[] dst, int di)
      Encodes a 64-bit unsigned integer in little-endian byte order.
      Parameters:
      l - the long value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (8)
    • dec_uint64be

      public static long dec_uint64be(byte[] src, int si)
      Decodes a 64-bit unsigned integer from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded long value
    • dec_uint64le

      public static long dec_uint64le(byte[] src, int si)
      Decodes a 64-bit unsigned integer from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded long value
    • enc_floatle

      public static int enc_floatle(float f, byte[] dst, int di)
      Encodes a float value in little-endian byte order.
      Parameters:
      f - the float value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (4)
    • enc_floatbe

      public static int enc_floatbe(float f, byte[] dst, int di)
      Encodes a float value in big-endian byte order.
      Parameters:
      f - the float value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (4)
    • dec_floatle

      public static float dec_floatle(byte[] src, int si)
      Decodes a float value from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded float value
    • dec_floatbe

      public static float dec_floatbe(byte[] src, int si)
      Decodes a float value from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded float value
    • enc_doublele

      public static int enc_doublele(double d, byte[] dst, int di)
      Encodes a double value in little-endian byte order.
      Parameters:
      d - the double value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (8)
    • enc_doublebe

      public static int enc_doublebe(double d, byte[] dst, int di)
      Encodes a double value in big-endian byte order.
      Parameters:
      d - the double value to encode
      dst - the destination byte array
      di - the starting index in the destination array
      Returns:
      the number of bytes written (8)
    • dec_doublele

      public static double dec_doublele(byte[] src, int si)
      Decodes a double value from little-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded double value
    • dec_doublebe

      public static double dec_doublebe(byte[] src, int si)
      Decodes a double value from big-endian byte order.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      Returns:
      the decoded double value
    • enc_time

      public static int enc_time(Date date, byte[] dst, int di, int enc)
      Encodes a Date value according to the specified time encoding type.
      Parameters:
      date - the Date to encode
      dst - the destination byte array
      di - the starting index in the destination array
      enc - the time encoding type (e.g., TIME_1970_SEC_32BE)
      Returns:
      the number of bytes written
    • dec_time

      public static Date dec_time(byte[] src, int si, int enc)
      Decodes a Date value according to the specified time encoding type.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      enc - the time encoding type (e.g., TIME_1970_SEC_32BE)
      Returns:
      the decoded Date value
    • enc_utf8

      public static int enc_utf8(String str, byte[] dst, int di, int dlim) throws IOException
      Encodes a String as UTF-8 bytes.
      Parameters:
      str - the String to encode
      dst - the destination byte array
      di - the starting index in the destination array
      dlim - the maximum index in the destination array
      Returns:
      the number of bytes written
      Throws:
      IOException - if an encoding error occurs
    • dec_utf8

      public static String dec_utf8(byte[] src, int si, int slim) throws IOException
      Decodes a UTF-8 encoded string from a byte array.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      slim - the limit index in the source array
      Returns:
      the decoded String
      Throws:
      IOException - if a decoding error occurs
    • dec_ucs2le

      public static String dec_ucs2le(byte[] src, int si, int slim, char[] buf) throws IOException
      Decodes a UCS-2 little-endian encoded string from a byte array.
      Parameters:
      src - the source byte array
      si - the starting index in the source array
      slim - the limit index in the source array
      buf - the character buffer for decoding
      Returns:
      the decoded String
      Throws:
      IOException - if a decoding error occurs