2011-11-15 21:26:51 +08:00
|
|
|
|
/*
|
|
|
|
|
Copyright (C) 2011 de4dot@gmail.com
|
|
|
|
|
|
|
|
|
|
This file is part of de4dot.
|
|
|
|
|
|
|
|
|
|
de4dot is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
de4dot is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Mono.Cecil;
|
|
|
|
|
using de4dot.blocks;
|
|
|
|
|
|
2011-12-09 16:02:06 +08:00
|
|
|
|
namespace de4dot.code.renamer.asmmodules {
|
2011-11-15 21:26:51 +08:00
|
|
|
|
interface RefDict<TRef, TMRef> where TRef : Ref where TMRef : MemberReference {
|
2011-11-21 17:36:23 +08:00
|
|
|
|
int Count { get; }
|
2012-01-01 19:09:16 +08:00
|
|
|
|
IEnumerable<TRef> getValues();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
IEnumerable<TRef> getSorted();
|
|
|
|
|
TRef find(TMRef tmref);
|
2011-12-28 20:24:02 +08:00
|
|
|
|
TRef findAny(TMRef tmref);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
void add(TRef tref);
|
|
|
|
|
void onTypesRenamed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TypeDefDict : RefDict<TypeDef, TypeReference> {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
TypeDefinitionDict<TypeDef> typeToDef = new TypeDefinitionDict<TypeDef>();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
|
2011-11-21 17:36:23 +08:00
|
|
|
|
public int Count {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
get { return typeToDef.Count; }
|
2011-11-21 17:36:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-01 19:09:16 +08:00
|
|
|
|
public IEnumerable<TypeDef> getValues() {
|
|
|
|
|
return typeToDef.getValues();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<TypeDef> getSorted() {
|
2012-01-01 19:09:16 +08:00
|
|
|
|
var list = new List<TypeDef>(getValues());
|
2011-11-21 17:36:23 +08:00
|
|
|
|
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
2011-11-15 21:26:51 +08:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TypeDef find(TypeReference typeReference) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
return typeToDef.find(typeReference);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 20:24:02 +08:00
|
|
|
|
public TypeDef findAny(TypeReference typeReference) {
|
|
|
|
|
return typeToDef.findAny(typeReference);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 21:26:51 +08:00
|
|
|
|
public void add(TypeDef typeDef) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
typeToDef.add(typeDef.TypeDefinition, typeDef);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onTypesRenamed() {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
typeToDef.onTypesRenamed();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class FieldDefDict : RefDict<FieldDef, FieldReference> {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
FieldDefinitionDict<FieldDef> fieldToDef = new FieldDefinitionDict<FieldDef>();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
|
2011-11-21 17:36:23 +08:00
|
|
|
|
public int Count {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
get { return fieldToDef.Count; }
|
2011-11-21 17:36:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-01 19:09:16 +08:00
|
|
|
|
public IEnumerable<FieldDef> getValues() {
|
|
|
|
|
return fieldToDef.getValues();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<FieldDef> getSorted() {
|
2012-01-01 19:09:16 +08:00
|
|
|
|
var list = new List<FieldDef>(getValues());
|
2011-11-21 17:36:23 +08:00
|
|
|
|
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
2011-11-15 21:26:51 +08:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FieldDef find(FieldReference fieldReference) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
return fieldToDef.find(fieldReference);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 20:24:02 +08:00
|
|
|
|
public FieldDef findAny(FieldReference fieldReference) {
|
|
|
|
|
return fieldToDef.findAny(fieldReference);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 21:26:51 +08:00
|
|
|
|
public void add(FieldDef fieldDef) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
fieldToDef.add(fieldDef.FieldDefinition, fieldDef);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onTypesRenamed() {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
fieldToDef.onTypesRenamed();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MethodDefDict : RefDict<MethodDef, MethodReference> {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
MethodDefinitionDict<MethodDef> methodToDef = new MethodDefinitionDict<MethodDef>();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
|
2011-11-21 17:36:23 +08:00
|
|
|
|
public int Count {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
get { return methodToDef.Count; }
|
2011-11-21 17:36:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-01 19:09:16 +08:00
|
|
|
|
public IEnumerable<MethodDef> getValues() {
|
|
|
|
|
return methodToDef.getValues();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<MethodDef> getSorted() {
|
2012-01-01 19:09:16 +08:00
|
|
|
|
var list = new List<MethodDef>(getValues());
|
2011-11-21 17:36:23 +08:00
|
|
|
|
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
2011-11-15 21:26:51 +08:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MethodDef find(MethodReference methodReference) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
return methodToDef.find(methodReference);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 20:24:02 +08:00
|
|
|
|
public MethodDef findAny(MethodReference methodReference) {
|
|
|
|
|
return methodToDef.findAny(methodReference);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 21:26:51 +08:00
|
|
|
|
public void add(MethodDef methodDef) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
methodToDef.add(methodDef.MethodDefinition, methodDef);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onTypesRenamed() {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
methodToDef.onTypesRenamed();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PropertyDefDict : RefDict<PropertyDef, PropertyReference> {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
PropertyDefinitionDict<PropertyDef> propToDef = new PropertyDefinitionDict<PropertyDef>();
|
2011-11-21 17:36:23 +08:00
|
|
|
|
|
|
|
|
|
public int Count {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
get { return propToDef.Count; }
|
2011-11-21 17:36:23 +08:00
|
|
|
|
}
|
2011-11-15 21:26:51 +08:00
|
|
|
|
|
2012-01-01 19:09:16 +08:00
|
|
|
|
public IEnumerable<PropertyDef> getValues() {
|
|
|
|
|
return propToDef.getValues();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<PropertyDef> getSorted() {
|
2012-01-01 19:09:16 +08:00
|
|
|
|
var list = new List<PropertyDef>(getValues());
|
2011-11-21 17:36:23 +08:00
|
|
|
|
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
2011-11-15 21:26:51 +08:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PropertyDef find(PropertyReference propertyReference) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
return propToDef.find(propertyReference);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 20:24:02 +08:00
|
|
|
|
public PropertyDef findAny(PropertyReference propertyReference) {
|
|
|
|
|
return propToDef.findAny(propertyReference);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 21:26:51 +08:00
|
|
|
|
public void add(PropertyDef propDef) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
propToDef.add(propDef.PropertyDefinition, propDef);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onTypesRenamed() {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
propToDef.onTypesRenamed();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class EventDefDict : RefDict<EventDef, EventReference> {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
EventDefinitionDict<EventDef> eventToDef = new EventDefinitionDict<EventDef>();
|
2011-11-21 17:36:23 +08:00
|
|
|
|
|
|
|
|
|
public int Count {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
get { return eventToDef.Count; }
|
2011-11-21 17:36:23 +08:00
|
|
|
|
}
|
2011-11-15 21:26:51 +08:00
|
|
|
|
|
2012-01-01 19:09:16 +08:00
|
|
|
|
public IEnumerable<EventDef> getValues() {
|
|
|
|
|
return eventToDef.getValues();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<EventDef> getSorted() {
|
2012-01-01 19:09:16 +08:00
|
|
|
|
var list = new List<EventDef>(getValues());
|
2011-11-21 17:36:23 +08:00
|
|
|
|
list.Sort((a, b) => Utils.compareInt32(a.Index, b.Index));
|
2011-11-15 21:26:51 +08:00
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EventDef find(EventReference eventReference) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
return eventToDef.find(eventReference);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-28 20:24:02 +08:00
|
|
|
|
public EventDef findAny(EventReference eventReference) {
|
|
|
|
|
return eventToDef.findAny(eventReference);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 21:26:51 +08:00
|
|
|
|
public void add(EventDef eventDef) {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
eventToDef.add(eventDef.EventDefinition, eventDef);
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onTypesRenamed() {
|
2011-12-17 01:46:30 +08:00
|
|
|
|
eventToDef.onTypesRenamed();
|
2011-11-15 21:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|