Skip to content

Commit

Permalink
pyrdp: camelCase vars and lowercase number literals
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Jun 14, 2024
1 parent 9db8226 commit 3966035
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 57 deletions.
26 changes: 13 additions & 13 deletions format/pyrdp/pdu/client_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const (
RDP10_2 = 0x80007
RDP10_3 = 0x80008
RDP10_4 = 0x80009
RDP10_5 = 0x8000A
RDP10_6 = 0x8000B
RDP10_7 = 0x8000C
RDP10_5 = 0x8000a
RDP10_6 = 0x8000b
RDP10_7 = 0x8000c
RDP10_8 = 0x8000d
RDP10_9 = 0x8000e
RDP10_10 = 0x8000f
Expand All @@ -41,10 +41,10 @@ var RDPVersionMap = scalar.UintMapSymStr{
}

const (
CLIENT_CORE = 0xC001
CLIENT_SECURITY = 0xC002
CLIENT_NETWORK = 0xC003
CLIENT_CLUSTER = 0xC004
CLIENT_CORE = 0xc001
CLIENT_SECURITY = 0xc002
CLIENT_NETWORK = 0xc003
CLIENT_CLUSTER = 0xc004
)

var clientDataMap = scalar.UintMapSymStr{
Expand All @@ -57,20 +57,20 @@ var clientDataMap = scalar.UintMapSymStr{
func ParseClientData(d *decode.D, length int64) {
d.FieldStruct("client_data", func(d *decode.D) {
header := d.FieldU16("header", clientDataMap)
data_len := int64(d.FieldU16("length") - 4)
dataLen := int64(d.FieldU16("length") - 4)

switch header {
case CLIENT_CORE:
ParseClientDataCore(d, data_len)
ParseClientDataCore(d, dataLen)
case CLIENT_SECURITY:
ParseClientDataSecurity(d, data_len)
ParseClientDataSecurity(d, dataLen)
case CLIENT_NETWORK:
ParseClientDataNetwork(d, data_len)
ParseClientDataNetwork(d, dataLen)
case CLIENT_CLUSTER:
ParseClientDataCluster(d, data_len)
ParseClientDataCluster(d, dataLen)
default:
// Assert() once all functions are implemented and tested.
d.FieldRawLen("data", data_len*8)
d.FieldRawLen("data", dataLen*8)
return
}
})
Expand Down
54 changes: 27 additions & 27 deletions format/pyrdp/pdu/client_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,46 @@ func ParseClientInfo(d *decode.D, length int64) {
d.FieldStruct("client_info", func(d *decode.D) {
pos := d.Pos()
var (
is_unicode bool
has_null bool
null_n uint64 = 0
unicode_n uint64 = 0
isUnicode bool
hasNull bool
nullN uint64 = 0
unicodeN uint64 = 0
)
code_page := d.FieldU32("code_page")
codePage := d.FieldU32("code_page")
flags := d.U32()
d.SeekRel(-4 * 8)
d.FieldStruct("flags", decodeFlagsFn)

is_unicode = ((flags & INFO_UNICODE) != 0)
has_null = (code_page == 1252 || is_unicode)
isUnicode = ((flags & INFO_UNICODE) != 0)
hasNull = (codePage == 1252 || isUnicode)

if has_null {
null_n = 1
if hasNull {
nullN = 1
}
if is_unicode {
unicode_n = 2
if isUnicode {
unicodeN = 2
}

domain_length := int(d.FieldU16("domain_length") + null_n*unicode_n)
username_length := int(d.FieldU16("username_length") + null_n*unicode_n)
password_length := int(d.FieldU16("password_length") + null_n*unicode_n)
alternate_shell_length := int(d.FieldU16("alternate_shell_length") + null_n*unicode_n)
working_dir_length := int(d.FieldU16("working_dir_length") + null_n*unicode_n)
domainLength := int(d.FieldU16("domain_length") + nullN*unicodeN)
usernameLength := int(d.FieldU16("username_length") + nullN*unicodeN)
passwordLength := int(d.FieldU16("password_length") + nullN*unicodeN)
alternateShellLength := int(d.FieldU16("alternate_shell_length") + nullN*unicodeN)
workingDirLength := int(d.FieldU16("working_dir_length") + nullN*unicodeN)

d.FieldUTF16LE("domain", domain_length, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("username", username_length, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("password", password_length, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("alternate_shell", alternate_shell_length, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("working_dir", working_dir_length, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("domain", domainLength, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("username", usernameLength, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("password", passwordLength, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("alternate_shell", alternateShellLength, scalar.StrActualTrim("\x00"))
d.FieldUTF16LE("working_dir", workingDirLength, scalar.StrActualTrim("\x00"))

extra_length := length - ((d.Pos() - pos) / 8)
if extra_length > 0 {
extraLength := length - ((d.Pos() - pos) / 8)
if extraLength > 0 {
d.FieldStruct("extra_info", func(d *decode.D) {
d.FieldU16("address_family", scalar.UintHex)
address_length := int(d.FieldU16("address_length"))
d.FieldUTF16LE("address", address_length, scalar.StrActualTrim("\x00"))
client_dir_length := int(d.FieldU16("client_dir_length"))
d.FieldUTF16LE("client_dir", client_dir_length, scalar.StrActualTrim("\x00"))
addressLength := int(d.FieldU16("address_length"))
d.FieldUTF16LE("address", addressLength, scalar.StrActualTrim("\x00"))
clientDirLength := int(d.FieldU16("client_dir_length"))
d.FieldUTF16LE("client_dir", clientDirLength, scalar.StrActualTrim("\x00"))
// TS_TIME_ZONE_INFORMATION structure
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/526ed635-d7a9-4d3c-bbe1-4e3fb17585f4
d.FieldU32("timezone_bias")
Expand Down
10 changes: 5 additions & 5 deletions format/pyrdp/pdu/clipboard_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ var cbParseFnMap = map[uint16]interface{}{

func ParseClipboardData(d *decode.D, length int64) {
d.FieldStruct("clipboard_data", func(d *decode.D) {
msg_type := uint16(d.FieldU16("msg_type", cbTypesMap))
msgType := uint16(d.FieldU16("msg_type", cbTypesMap))
d.FieldU16("msg_flags", cbFlagsMap)
data_length := d.FieldU32("data_len")
dataLength := d.FieldU32("data_len")

cbParser, ok := cbParseFnMap[msg_type]
cbParser, ok := cbParseFnMap[msgType]
if ok {
parseFn, ok := cbParser.(func(d *decode.D, length uint64))
if ok {
parseFn(d, data_length)
parseFn(d, dataLength)
return
}
}
// Assert() once all functions are implemented.
d.FieldRawLen("data", int64(data_length*8))
d.FieldRawLen("data", int64(dataLength*8))
})
}

Expand Down
12 changes: 6 additions & 6 deletions format/pyrdp/pdu/fastpath_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func ParseFastPathInput(d *decode.D, length int64) {
}
})

input_length := d.FieldU8("input_length1", scalar.UintHex)
if input_length&0x80 != 0 {
input_length = ((input_length & 0x7f) << 8) | d.FieldU8("input_length2", scalar.UintHex)
inputLength := d.FieldU8("input_length1", scalar.UintHex)
if inputLength&0x80 != 0 {
inputLength = ((inputLength & 0x7f) << 8) | d.FieldU8("input_length2", scalar.UintHex)
}

// d.FieldU64("data_signature", scalar.Hex)
Expand All @@ -92,9 +92,9 @@ func ParseFastPathInput(d *decode.D, length int64) {
// }
// })

input_length -= uint64(d.Pos()-pos) / 8
if input_length > 0 {
d.FieldRawLen("data", int64(input_length*8))
inputLength -= uint64(d.Pos()-pos) / 8
if inputLength > 0 {
d.FieldRawLen("data", int64(inputLength*8))
}
})
}
Expand Down
12 changes: 6 additions & 6 deletions format/pyrdp/pyrdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ func decodePYRDP(d *decode.D) any {
pos := d.Pos()

size := d.FieldU64("size") // minus the length
pdu_type := uint16(d.FieldU16("pdu_type", pduTypesMap))
pduType := uint16(d.FieldU16("pdu_type", pduTypesMap))
d.FieldU64("timestamp", scalar.UintActualUnixTimeDescription(time.Millisecond, time.RFC3339Nano))
pdu_size := int64(size - 18)
pduSize := int64(size - 18)

pduParser, ok := pduParsersMap[pdu_type]
pduParser, ok := pduParsersMap[pduType]
if !ok { // catch undeclared parsers
if pdu_size > 0 {
d.FieldRawLen("data", pdu_size*8)
if pduSize > 0 {
d.FieldRawLen("data", pduSize*8)
}
return
}
parseFn, ok := pduParser.(func(d *decode.D, length int64))
if !ok {
return
}
parseFn(d, pdu_size)
parseFn(d, pduSize)

curr := d.Pos() - pos
if READ_EXTRA {
Expand Down

0 comments on commit 3966035

Please sign in to comment.