Using System.Collections.Generic.List`1 [System.Byte] in Python

I have a Python script that gets data from a .NET application. How can I use an incoming buffer like "System.Collections.Generic.List`1 [System.Byte]" in my script?

The script function would be to find and replace string tokens, reassemble the buffer back to System.Collections.Generic.List`1 [System.Byte], and then return the buffer back to the .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 greatly appreciated. Thank!

+3


source to share


1 answer


The problem is that List

Python side C # initialization ignores items specified in parentheses, which looks like an error, 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]

      

0


source







All Articles