I have a Python script which receives data from a .NET application. How do I use an incoming buffer of type 'System.Collections.Generic.List`1[System.Byte]' in my script?
The function of the script would be to find and replace string tokens, reassemble the buffer back into System.Collections.Generic.List`1[System.Byte] and then return the buffer back to a .NET server.
I am very new to Python. This is what I have so far:
import array
import clr
from System.Collections.Generic import *
def SetRecvBuffer(buffer):
li = List[byte](buffer)
hookme.Debug(li)
for x in li:
hookme.Debug(x)
Any help would be appreciated. Thanks!
The problem is that C# List
initialization on Python side ignores the items given in brackets which looks like a bug, for now instead use List.Add()
:
import clr
clr.AddReference("System.Collections")
from System.Collections.Generic import List
from System import Int32
li = List[Int32](range(3))
list(li) #returns []
li.Add(5)
list(li) #returns [5]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With