예제 #1
0
파일: per.py 프로젝트: xianlimei/pyrdp
def writeObjectIdentifier(oid):
    """
    Pack a PER object identifier
    :param oid: object identifier (tuple of 6 integers)
    :type oid: (int, int, int, int, int, int)
    :return: str
    """
    return writeLength(5) + Uint8.pack((oid[0] << 4) & (oid[1] & 0x0f)) + b"".join(Uint8.pack(b) for b in oid[2 :])
예제 #2
0
파일: ber.py 프로젝트: yuraxdrumz/pyrdp
def writeLength(length: int) -> bytes:
    """
    Pack structure length as expected in BER specification
    :param length: structure length.
    """
    if length > 0x7f:
        return Uint8.pack(0x82) + Uint16BE.pack(length)
    else:
        return Uint8.pack(length)
예제 #3
0
파일: ber.py 프로젝트: xianlimei/pyrdp
def writeApplicationTag(tag, size):
    """
    Pack an application tag.
    :param tag: application tag.
    :type tag: Tag
    :param size: the size of the application packet.
    :type size: int
    """
    if tag > 30:
        return Uint8.pack((Class.BER_CLASS_APPL | PC.BER_CONSTRUCT) | Tag.BER_TAG_MASK) + Uint8.pack(tag) + writeLength(size)
    else:
        return Uint8.pack((Class.BER_CLASS_APPL | PC.BER_CONSTRUCT) | (Tag.BER_TAG_MASK & tag)) + writeLength(size)
예제 #4
0
파일: ber.py 프로젝트: yuraxdrumz/pyrdp
def writeBoolean(value: bool) -> bytes:
    """
    Pack a BER boolean
    """
    boolean = Uint8.pack(0xff if value else 0)
    return writeUniversalTag(Tag.BER_TAG_BOOLEAN,
                             False) + writeLength(1) + boolean
예제 #5
0
파일: ber.py 프로젝트: xianlimei/pyrdp
def writeEnumeration(value):
    """
    Pack a BER enumeration value
    :type value: int
    :return: str
    """
    return writeUniversalTag(Tag.BER_TAG_ENUMERATED, False) + writeLength(1) + Uint8.pack(value)
예제 #6
0
def writeNumericString(string: str, minValue: int) -> bytes:
    """
    Pack a PER numeric string
    :param string: numeric string
    :param minValue: minimum string length
    """
    length = len(string)
    mlength = minValue
    if length >= minValue:
        mlength = length - minValue
    
    result = b""
    
    for i in range(0, length, 2):
        c1 = ord(string[i : i + 1])
        if i + 1 < length:
            c2 = ord(string[i + 1 : i + 2])
        else:
            c2 = 0x30
        c1 = (c1 - 0x30) % 10
        c2 = (c2 - 0x30) % 10
        
        result += Uint8.pack((c1 << 4) | c2)
    
    return writeLength(mlength) + result
예제 #7
0
파일: per.py 프로젝트: xianlimei/pyrdp
def writeChoice(choice):
    """
    Pack a PER choice
    :param choice: choice value
    :type choice: int
    :return: str
    """
    return Uint8.pack(choice)
예제 #8
0
파일: per.py 프로젝트: xianlimei/pyrdp
def writeNumberOfSet(numberOfSet):
    """
    Pack a PER NumberOfSet
    :param numberOfSet: NumberOfSet value
    :type numberOfSet: int
    :return: str
    """
    return Uint8.pack(numberOfSet)
예제 #9
0
파일: per.py 프로젝트: xianlimei/pyrdp
def writeEnumeration(enum):
    """
    Pack a PER enumeration
    :param enum: enumeration value
    :type enum: int
    :return: str
    """
    return Uint8.pack(enum)
예제 #10
0
파일: ber.py 프로젝트: xianlimei/pyrdp
def writeBoolean(value):
    """
    Pack a BER boolean
    :type value: bool
    :return: str
    """
    boolean = Uint8.pack(0xff if value else 0)
    return writeUniversalTag(Tag.BER_TAG_BOOLEAN, False) + writeLength(1) + boolean
예제 #11
0
def writeLength(value: int) -> bytes:
    """
    Pack a PER length indicator
    """
    if value > 0x7f:
        return Uint16BE.pack(value | 0x8000)
    else:
        return Uint8.pack(value)
예제 #12
0
파일: per.py 프로젝트: xianlimei/pyrdp
def writeSelection(selection):
    """
    Pack a PER selection
    :param selection: selection value
    :type selection: int
    :return: str
    """
    return Uint8.pack(selection)
예제 #13
0
파일: ber.py 프로젝트: yuraxdrumz/pyrdp
def writeUniversalTag(tag: Tag, isConstruct: bool) -> bytes:
    """
    Pack universal tag.
    :param tag: BER tag
    :param isConstruct: True if the structure is a construct
    """
    return Uint8.pack((Class.BER_CLASS_UNIV | berPC(isConstruct))
                      | (Tag.BER_TAG_MASK & tag))
예제 #14
0
파일: per.py 프로젝트: xianlimei/pyrdp
def writeLength(value):
    """
    Pack a PER length indicator
    :type value: int
    :return: str
    """
    if value > 0x7f:
        return Uint16BE.pack(value | 0x8000)
    else:
        return Uint8.pack(value)
예제 #15
0
def writeInteger(value: int) -> bytes:
    """
    Pack a PER integer
    """
    if value <= 0xff:
        return writeLength(1) + Uint8.pack(value)
    elif value < 0xffff:
        return writeLength(2) + Uint16BE.pack(value)
    else:
        return writeLength(4) + Uint32BE.pack(value)
예제 #16
0
파일: ber.py 프로젝트: xianlimei/pyrdp
def writeInteger(value):
    """
    Pack a BER integer
    :type value: int
    :return: str
    """
    if value <= 0xff:
        return writeUniversalTag(Tag.BER_TAG_INTEGER, False) + writeLength(1) + Uint8.pack(value)
    elif value <= 0xffff:
        return writeUniversalTag(Tag.BER_TAG_INTEGER, False) + writeLength(2) + Uint16BE.pack(value)
    else:
        return writeUniversalTag(Tag.BER_TAG_INTEGER, False) + writeLength(4) + Uint32BE.pack(value)
예제 #17
0
파일: per.py 프로젝트: xianlimei/pyrdp
def writeInteger(value):
    """
    Pack a PER integer
    :type value: int
    :return: str
    """
    if value <= 0xff:
        return writeLength(1) + Uint8.pack(value)
    elif value < 0xffff:
        return writeLength(2) + Uint16BE.pack(value)
    else:
        return writeLength(4) + Uint32BE.pack(value)
예제 #18
0
def writeEnumeration(enum: int) -> bytes:
    """
    Pack a PER enumeration
    :param enum: enumeration value
    """
    return Uint8.pack(enum)
예제 #19
0
def writeNumberOfSet(numberOfSet: int) -> bytes:
    """
    Pack a PER NumberOfSet
    :param numberOfSet: NumberOfSet value
    """
    return Uint8.pack(numberOfSet)
예제 #20
0
def writeSelection(selection: int) -> bytes:
    """
    Pack a PER selection
    :param selection: selection value
    """
    return Uint8.pack(selection)
예제 #21
0
def writeChoice(choice: int) -> bytes:
    """
    Pack a PER choice
    :param choice: choice value
    """
    return Uint8.pack(choice)
예제 #22
0
파일: ber.py 프로젝트: yuraxdrumz/pyrdp
def writeEnumeration(value: int) -> bytes:
    """
    Pack a BER enumeration value
    """
    return writeUniversalTag(Tag.BER_TAG_ENUMERATED,
                             False) + writeLength(1) + Uint8.pack(value)
예제 #23
0
def writeObjectIdentifier(oid: Tuple[int, int, int, int, int, int]) -> bytes:
    """
    Pack a PER object identifier
    :param oid: object identifier (tuple of 6 integers)
    """
    return writeLength(5) + Uint8.pack((oid[0] << 4) & (oid[1] & 0x0f)) + b"".join(Uint8.pack(b) for b in oid[2 :])