6

我有一个 Python 脚本,它从 .NET 应用程序接收数据。如何在我的脚本中使用类型为“System.Collections.Generic.List`1[System.Byte]”的传入缓冲区?

该脚本的功能是查找和替换字符串标记,将缓冲区重新组装回 System.Collections.Generic.List`1[System.Byte],然后将缓冲区返回给 .NET 服务器。

我对 Python很陌生。这是我到目前为止所拥有的:

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) 

任何帮助,将不胜感激。谢谢!

4

1 回答 1

1

问题是ListPython 端的 C# 初始化忽略了括号中给出的项目,这看起来像一个错误,现在改为使用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]
于 2015-09-07T06:27:54.557 回答