Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 461
AKK2015 Avatar asked Jun 02 '15 03:06

AKK2015


1 Answers

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]
like image 51
denfromufa Avatar answered Oct 05 '22 12:10

denfromufa