全部博文(372)
2012年(372)
分类: 虚拟化
2012-03-06 19:23:25
可以看到,在Silverlight 5中受信应用的权限几乎获得了与桌面应用相当的权限,在这里,我将为大家介绍如何创建浏览器内的受信应用。以下示例将通过Silverlight来监视本地的网络流量。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 |
public static class WIN32API
{
[DllImport("kernel32.dll")]
public static extern bool GetComputerName(StringBuilder computerName, out Int32 nameLength);
[DllImport("Iphlpapi.dll")]
private static extern Int32 GetIfTable(Byte[] pIfTable, out long pdwSize, bool bOrder);
[DllImport("kernel32.dll")]
private static extern int MultiByteToWideChar(uint CodePage,Int32 dwFlags,byte[] lpMultiByteStr,Int32 cbMultiByte,byte[] lpWideCharStr, int cchWideChar);
public static MIB_IFTABLE GetIfTable()
{
MIB_IFTABLE table = new MIB_IFTABLE();
long size = 0;
GetIfTable(null, out size, false);
if (size != 0)
{
Byte[] data = new Byte[size];
long ret = GetIfTable(data, out size, false);
if (ret == 0)
{
MemoryStream ms = new MemoryStream(data);
ms.Position = 0;
BinaryReader br = new BinaryReader(ms, Encoding.Unicode);
table.dwNumEntries = br.ReadInt32();
table.table = new MIB_IFROW[table.dwNumEntries];
for (int i = 0; i < table.dwNumEntries; i++)
{
table.table[i] = new MIB_IFROW();
MIB_IFROW curRow = table.table[i];
FieldInfo[] fis = typeof(MIB_IFROW).GetFields();
foreach (FieldInfo fi in fis)
{
if (!fi.IsStatic)
{
MarshalAsAttribute[] attrs = fi.GetCustomAttributes(typeof(MarshalAsAttribute), true) as MarshalAsAttribute[];
if (attrs != null && attrs.Length > 0 && attrs[0].SizeConst != 0)
{
if (fi.FieldType == typeof(String))
{
Byte[] tmpChars = br.ReadBytes(attrs[0].SizeConst*2);
fi.SetValue(curRow, Encoding.Unicode.GetString(tmpChars, 0, tmpChars.Length).TrimEnd('\0'));
}
else if (fi.FieldType == typeof(Byte[]))
{
fi.SetValue(curRow, br.ReadBytes(attrs[0].SizeConst));
}
}
else
{
if (fi.FieldType == typeof(Int32))
{
Int32 tmpValue = br.ReadInt32();
fi.SetValue(curRow, tmpValue);
}
}
}
}
}
}
}
return table;
}
public static String AsciiToUTF8(Byte[] asciiBytes)
{
int mustBytes = MultiByteToWideChar(WIN32CONST.CP_ACP, WIN32CONST.MB_PRECOMPOSED, asciiBytes, -1, null, 0);
if (mustBytes > 0)
{
Byte[] tmpBytes = new Byte[mustBytes*2];
if (MultiByteToWideChar(WIN32CONST.CP_ACP, WIN32CONST.MB_PRECOMPOSED, asciiBytes, -1, tmpBytes, mustBytes) != 0)
{
return Encoding.Unicode.GetString(tmpBytes, 0, tmpBytes.Length);
}
}
return "";
}
} |