diff options
author | Lluis Sanchez <lluis@novell.com> | 2008-02-06 19:24:42 +0300 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2008-02-06 19:24:42 +0300 |
commit | bafa8c24e832cdfbe74069d8ea7394aa7f874ea8 (patch) | |
tree | 1946f8140956573c001bf8e3260ba7cca9efc9bf | |
parent | f119bb581aaee02846cf81b8b2d45bb42ea3963f (diff) |
* Mono.Addins.mds, Mono.Addins.Gui/AssemblyInfo.cs,
Mono.Addins.CecilReflector,
Mono.Addins.CecilReflector/AssemblyInfo.cs,
Mono.Addins.CecilReflector/Mono.Cecil,
Mono.Addins.CecilReflector/Mono.Cecil/configure,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.dll.sources,
Mono.Addins.CecilReflector/Mono.Cecil/default.build,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.csproj,
Mono.Addins.CecilReflector/Mono.Cecil/AUTHORS,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/InterfaceCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleReferenceCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodSpecification.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeSpecification.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionHelper.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/OverrideCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CallSite.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayDimensionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclarationReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericInstanceType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionVisitable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventDefinitionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldDefinitionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyDefinitionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleDefinitionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IImporter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMethodSignature.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeReferenceCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayDimension.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameterCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyInfo.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/StructureWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CustomAttribute.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MemberReferenceCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionStructureVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseReflectionReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameReferenceCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasSecurity.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodReturnType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NativeType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMemberDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasConstant.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMemberReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/DefaultImporter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasMarshalSpec.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseStructureVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Constants.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/LinkedResource.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ImportContext.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyKind.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FileAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CompactFrameworkCompatibility.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReferenceType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ResourceCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyFactory.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionException.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IGenericInstance.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NullReferenceImporter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PinnedType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PointerType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ExternTypeCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionStructureVisitable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclarationCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TargetRuntime.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericArgumentCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IAnnotationProvider.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ConstraintCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EmbeddedResource.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseReflectionVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CustomAttributeCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SentinelType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/StructureReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionController.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MarshalSpec.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/VariantType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IAssemblyResolver.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IRequireResolving.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMetadataScope.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MemberReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Resource.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PInvokeInfo.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/HashCodeProvider.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AggressiveReflectionReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IDetailReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityAction.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodDefinitionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericContext.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Modifiers.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NestedTypeCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ConstructorCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TableComparers.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs,
Mono.Addins.CecilReflector/Mono.Cecil/ChangeLog,
Mono.Addins.CecilReflector/Mono.Cecil/mono-cecil.pc.in,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCodeType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Document.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Instruction.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodHeader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentHashAlgorithm.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/IScopeProvider.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CilWorker.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/FlowControl.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableDefinitionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Code.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/GuidAttribute.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguage.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/IVariableDefinitionProvider.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/SymbolStoreHelper.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolStoreFactory.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ScopeCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/BaseCodeVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OperandType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/InstructionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodDataSection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguageVendor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Scope.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/StackBehaviour.cs,
Mono.Addins.CecilReflector/Mono.Cecil/README,
Mono.Addins.CecilReflector/Mono.Cecil/standalone.make,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen.rb,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-tests.rb,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-update-rev,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-sources.rb,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-types.rb,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-mig.rb,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-attributes.rb,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil.xml,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataTableReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/BaseMetadataVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Utilities.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataRowReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/IndexedCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/OpCodes.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/NamedCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Tests.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataRowWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataTableWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/CodedIndex.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Table.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/IMetadataVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Code.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Assembly.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/PropertyMap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/InterfaceImpl.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataInitializer.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ParamPtr.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Constant.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/BaseMetadataVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodSpec.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/DeclSecurity.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeDef.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GenericParamConstraint.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodImpl.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/EventPtr.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/NestedClass.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefProcessor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRef.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefOS.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Method.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/RowCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/StringsHeap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRowReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ExportedType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CustomAttribute.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Param.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ClassLayout.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRowWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataFormatException.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/PropertyPtr.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyOS.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataRow.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ModuleRef.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRoot.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/UserStringsHeap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldMarshal.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GenericParam.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ImplMap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TableCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CultureUtils.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TablesHeap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataStreamCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldPtr.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeRef.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataHeap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ManifestResource.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyProcessor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/File.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/EventMap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Event.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldLayout.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Field.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Property.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Module.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodSemantics.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/StandAloneSig.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldRVA.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataStream.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeSpec.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataTable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MemberRef.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodPtr.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/TODO,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/ChangeLog,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/SecurityParser.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/SmallXmlParser.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/MiniParser.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/BaseSignatureVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodRefSig.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/CustomAttrib.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/FieldSig.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Var.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/FnPtr.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SzArray.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodSpec.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ArrayShape.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Ptr.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MVar.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericArg.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/LocalVarSig.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Array.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ValueType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodSig.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SigType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Constraint.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/PropertySig.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MarshalSig.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/RetType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericInstSignature.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/TypeSpec.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/InputOutputItem.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Param.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Signature.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodDefSig.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Class.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericInst.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/CustomMod.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/PEFileHeader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SectionCollection.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryTable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/RuntimeImage.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ExportTable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/BaseImageVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceNode.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Imports.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryEntry.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DOSHeader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DebugHeader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SectionCharacteristics.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryString.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDataEntry.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Section.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DebugStoreType.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageFormatException.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageCharacteristics.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/CLIHeader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Image.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/PEOptionalHeader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageInitializer.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/RVA.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/CopyImageVisitor.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DataDirectory.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SubSystem.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitable.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IHeader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/MemoryBinaryWriter.cs,
Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceReader.cs,
Mono.Addins.CecilReflector/Mono.Cecil/NEWS,
Mono.Addins.CecilReflector/Mono.Cecil/Makefile,
Mono.Addins.CecilReflector/Mono.Addins.CecilReflector.mdp,
Mono.Addins.CecilReflector/Mono.Addins.CecilReflector,
Mono.Addins.CecilReflector/Mono.Addins.CecilReflector/Reflector.cs,
configure.ac, Mono.Addins.Setup/AssemblyInfo.cs,
Mono.Addins/AssemblyInfo.cs, Mono.Addins/Mono.Addins.mdp,
Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs,
Mono.Addins/Mono.Addins/TypeExtensionPointAttribute.cs,
Mono.Addins/Mono.Addins/ExtensionPointAttribute.cs,
Mono.Addins/Mono.Addins/ExtensionNodeChildAttribute.cs,
Mono.Addins/Makefile.am,
Mono.Addins/Mono.Addins.Database/IAssemblyReflector.cs,
Mono.Addins/Mono.Addins.Database/AddinScanResult.cs,
Mono.Addins/Mono.Addins.Database/AddinDatabase.cs,
Mono.Addins/Mono.Addins.Database/AddinScanner.cs,
Mono.Addins/Mono.Addins.Database/DefaultAssemblyReflector.cs,
Makefile.am: Added support for pluggable add-in assembly
reflectors. Implemented an add-in assembly reflector based on
Cecil.
svn path=/trunk/mono-addins/; revision=95038
370 files changed, 48979 insertions, 84 deletions
@@ -1,3 +1,14 @@ +2008-02-06 Lluis Sanchez Gual <lluis@novell.com> + + * Mono.Addins.mds, Mono.Addins.CecilReflector, + Mono.Addins.CecilReflector/AssemblyInfo.cs, + Mono.Addins.CecilReflector/Mono.Cecil, + Mono.Addins.CecilReflector/Mono.Addins.CecilReflector.mdp, + Mono.Addins.CecilReflector/Mono.Addins.CecilReflector, + Mono.Addins.CecilReflector/Mono.Addins.CecilReflector/Reflector.cs, + configure.ac, Makefile.am: Added support for pluggable add-in assembly + reflectors. Implemented an add-in assembly reflector based on Cecil. + 2008-01-30 Michael Hutchinson <mhutchinson@novell.com> * configure.in: Bump release number to 0.3.1. diff --git a/Makefile.am b/Makefile.am index 6fdafa3..a1ed8f3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = Mono.Addins Mono.Addins.Setup Mono.Addins.Gui mautil Test Samples +SUBDIRS = Mono.Addins Mono.Addins.CecilReflector Mono.Addins.Setup Mono.Addins.Gui mautil Test Samples DOCFILES = \ $(top_builddir)/bin/Mono.Addins.dll \ diff --git a/Mono.Addins.CecilReflector/AssemblyInfo.cs b/Mono.Addins.CecilReflector/AssemblyInfo.cs new file mode 100644 index 0000000..fda4188 --- /dev/null +++ b/Mono.Addins.CecilReflector/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("Mono.Addins.CecilReflector")] +[assembly: AssemblyCopyright("Copyright (C) 2007 Novell, Inc (http://www.novell.com)")] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("0.4.0.0")] diff --git a/Mono.Addins.CecilReflector/Mono.Addins.CecilReflector.mdp b/Mono.Addins.CecilReflector/Mono.Addins.CecilReflector.mdp new file mode 100644 index 0000000..9260cbe --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Addins.CecilReflector.mdp @@ -0,0 +1,357 @@ +<Project name="Mono.Addins.CecilReflector" fileversion="2.0" language="C#" clr-version="Net_1_1" ctype="DotNetProject"> + <Configurations active="Debug"> + <Configuration name="Debug" ctype="DotNetProjectConfiguration"> + <Output directory="../bin" signAssembly="True" assemblyKeyFile="../mono-addins.snk" assembly="Mono.Addins.CecilReflector" /> + <Build debugmode="True" target="Library" /> + <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_1_1" /> + <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" /> + </Configuration> + <Configuration name="Release" ctype="DotNetProjectConfiguration"> + <Output directory="bin/Release" assembly="Mono.Addins.CecilReflector" /> + <Build debugmode="False" target="Library" /> + <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_1_1" /> + <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" /> + </Configuration> + </Configurations> + <Contents> + <File name="Mono.Cecil/Mono.Cecil/AggressiveReflectionReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ArrayDimension.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ArrayDimensionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ArrayType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyFactory.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyFlags.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyKind.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/AssemblyNameReferenceCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/BaseReflectionReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/BaseReflectionVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/BaseStructureVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/CallSite.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/CompactFrameworkCompatibility.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/Constants.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ConstraintCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ConstructorCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/CustomAttribute.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/CustomAttributeCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/DefaultImporter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/EmbeddedResource.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/EventAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/EventDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/EventDefinitionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/EventReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ExternTypeCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/FieldAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/FieldDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/FieldDefinitionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/FieldReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/FileAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/FunctionPointerType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/GenericArgumentCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/GenericContext.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/GenericInstanceType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/GenericParameter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/GenericParameterCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/HashCodeProvider.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IAnnotationProvider.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IAssemblyResolver.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IDetailReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IGenericInstance.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IHasConstant.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IHasMarshalSpec.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IHasSecurity.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IImporter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IMemberDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IMemberReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IMetadataScope.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IMethodSignature.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ImportContext.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/InterfaceCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IReflectionStructureVisitable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IReflectionStructureVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IReflectionVisitable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IReflectionVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/IRequireResolving.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/LinkedResource.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MarshalSpec.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MemberReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MemberReferenceCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodDefinitionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodReturnType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/MethodSpecification.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/Modifiers.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ModuleDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ModuleDefinitionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ModuleReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ModuleReferenceCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/NativeType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/NestedTypeCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/NullReferenceImporter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/OverrideCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ParameterAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ParameterDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ParameterReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/PinnedType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/PInvokeInfo.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/PointerType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/PropertyAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/PropertyDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/PropertyDefinitionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/PropertyReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ReferenceType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ReflectionController.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ReflectionException.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ReflectionHelper.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ReflectionReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ReflectionWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/Resource.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/ResourceCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/SecurityAction.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/SecurityDeclarationCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/SecurityDeclarationReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/SentinelType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/StructureReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/StructureWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/TableComparers.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/TargetRuntime.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/TypeAttributes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/TypeDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/TypeReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/TypeReferenceCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/TypeSpecification.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil/VariantType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/BaseImageVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/CLIHeader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/CopyImageVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/DataDirectory.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/DebugHeader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/DebugStoreType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/DOSHeader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ExportTable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/IHeader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/Image.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ImageCharacteristics.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ImageFormatException.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ImageInitializer.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ImageReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ImageWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/Imports.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/MemoryBinaryWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/PEFileHeader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/PEOptionalHeader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ResourceDataEntry.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryEntry.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryString.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryTable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ResourceNode.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ResourceReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/ResourceWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/RuntimeImage.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/RVA.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/Section.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/SectionCharacteristics.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/SectionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Binary/SubSystem.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/BaseCodeVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/CilWorker.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/Code.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/Document.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/DocumentHashAlgorithm.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/DocumentLanguage.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/DocumentLanguageVendor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/FlowControl.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/GuidAttribute.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ICodeVisitable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ICodeVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/Instruction.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/InstructionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/IScopeProvider.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ISymbolReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ISymbolStoreFactory.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ISymbolWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/IVariableDefinitionProvider.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/MethodDataSection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/MethodHeader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/OpCode.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/OpCodeType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/OperandType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/Scope.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/ScopeCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/StackBehaviour.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/SymbolStoreHelper.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/VariableDefinitionCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Assembly.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/AssemblyOS.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/AssemblyProcessor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/AssemblyRef.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefOS.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefProcessor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/BaseMetadataVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/ClassLayout.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Constant.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/CultureUtils.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/CustomAttribute.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/DeclSecurity.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Event.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/EventMap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/EventPtr.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/ExportedType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Field.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/FieldLayout.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/FieldMarshal.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/FieldPtr.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/FieldRVA.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/File.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/GenericParam.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/GenericParamConstraint.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/IMetadataRow.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/IMetadataTable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/ImplMap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/InterfaceImpl.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/ManifestResource.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MemberRef.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataFormatException.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataHeap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataInitializer.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataRoot.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataRowReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataRowWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataStream.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataStreamCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataTableReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataTableWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MetadataWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Method.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MethodImpl.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MethodPtr.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MethodSemantics.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/MethodSpec.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Module.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/ModuleRef.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/NestedClass.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Param.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/ParamPtr.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Property.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/PropertyMap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/PropertyPtr.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/RowCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/StandAloneSig.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/StringsHeap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/TableCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/TablesHeap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/TypeDef.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/TypeRef.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/TypeSpec.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/UserStringsHeap.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/Array.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/ArrayShape.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/BaseSignatureVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/Class.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/Constraint.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/CustomAttrib.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/CustomMod.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/FieldSig.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/FnPtr.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/GenericArg.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/GenericInst.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/GenericInstSignature.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/InputOutputItem.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitable.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitor.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/LocalVarSig.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/MarshalSig.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/MethodDefSig.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/MethodRefSig.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/MethodSig.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/MethodSpec.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/MVar.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/Param.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/PropertySig.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/Ptr.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/RetType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/Signature.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/SigType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/SzArray.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/TypeSpec.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/ValueType.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Cecil.Signatures/Var.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Xml/ChangeLog" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/Mono.Xml/MiniParser.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Xml/SecurityParser.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/Mono.Xml/SmallXmlParser.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Cecil/AUTHORS" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/ChangeLog" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/configure" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/default.build" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/Makefile" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/Mono.Cecil.csproj" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/Mono.Cecil.dll.sources" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/mono-cecil.pc.in" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/NEWS" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/README" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/standalone.make" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Cecil/TODO" subtype="Code" buildaction="Nothing" /> + <File name="Mono.Addins.CecilReflector" subtype="Directory" buildaction="Compile" /> + <File name="Mono.Addins.CecilReflector/Reflector.cs" subtype="Code" buildaction="Compile" /> + <File name="AssemblyInfo.cs" subtype="Code" buildaction="Compile" /> + </Contents> + <References> + <ProjectReference type="Gac" localcopy="True" refto="System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> + <ProjectReference type="Project" localcopy="True" refto="Mono.Addins" /> + </References> + <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="Makefile.am" BuildTargetName="" CleanTargetName="" SyncReferences="True" IsAutotoolsProject="True" RelativeConfigureInPath=".."> + <BuildFilesVar Sync="True" Name="FILES" /> + <DeployFilesVar /> + <ResourcesVar Sync="True" Name="RESOURCES" /> + <OthersVar /> + <GacRefVar Sync="True" Name="REFERENCES" Prefix="-r:" /> + <AsmRefVar Sync="True" Name="REFERENCES" Prefix="-r:" /> + <ProjectRefVar Sync="True" Name="REFERENCES" Prefix="-r:" /> + </MonoDevelop.Autotools.MakefileInfo> +</Project>
\ No newline at end of file diff --git a/Mono.Addins.CecilReflector/Mono.Addins.CecilReflector/Reflector.cs b/Mono.Addins.CecilReflector/Mono.Addins.CecilReflector/Reflector.cs new file mode 100644 index 0000000..78a2a0e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Addins.CecilReflector/Reflector.cs @@ -0,0 +1,285 @@ +// Reflector.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2007 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// + +using System; +using System.Collections; +using System.Reflection; +using Mono.Addins; +using Mono.Addins.Database; +using Mono.Cecil; + +namespace Mono.Addins.CecilReflector +{ + public class Reflector: IAssemblyReflector + { + IAssemblyLocator locator; + Hashtable cachedAssemblies = new Hashtable (); + + public void Initialize (IAssemblyLocator locator) + { + this.locator = locator; + } + + public object[] GetCustomAttributes (object obj, Type type, bool inherit) + { + Mono.Cecil.ICustomAttributeProvider aprov = obj as Mono.Cecil.ICustomAttributeProvider; + if (aprov == null) + return new object [0]; + + ArrayList atts = new ArrayList (); + foreach (CustomAttribute att in aprov.CustomAttributes) { + object catt = ConvertAttribute (att, type); + if (catt != null) + atts.Add (catt); + } + return atts.ToArray (); + } + + object ConvertAttribute (CustomAttribute att, Type t) + { + string aname = att.Constructor.DeclaringType.FullName; + if (aname != t.FullName) + return null; + + object ob; + + if (att.ConstructorParameters.Count > 0) { + object[] cargs = new object [att.ConstructorParameters.Count]; + att.ConstructorParameters.CopyTo (cargs, 0); + ArrayList typeParameters = null; + + // Constructor parameters of type System.Type can't be set because types from the assembly + // can't be loaded. The parameter value will be set later using a type name property. + for (int n=0; n<cargs.Length; n++) { + string atype = att.Constructor.Parameters[n].ParameterType.FullName; + if (atype == "System.Type") { + if (typeParameters == null) + typeParameters = new ArrayList (); + cargs [n] = typeof(object); + typeParameters.Add (n); + } + } + ob = Activator.CreateInstance (t, cargs); + + // If there are arguments of type System.Type, set them using the property + if (typeParameters != null) { + Type[] ptypes = new Type [cargs.Length]; + for (int n=0; n<cargs.Length; n++) { + ptypes [n] = cargs [n].GetType (); + } + ConstructorInfo ci = t.GetConstructor (ptypes); + ParameterInfo[] ciParams = ci.GetParameters (); + + for (int n=0; n<typeParameters.Count; n++) { + int ip = (int) typeParameters [n]; + string propName = ciParams[ip].Name; + propName = char.ToUpper (propName [0]) + propName.Substring (1) + "Name"; + PropertyInfo pi = t.GetProperty (propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + pi.SetValue (ob, (string) att.ConstructorParameters [ip], null); + if (pi == null) + throw new InvalidOperationException ("Property '" + propName + "' not found in type '" + t + "'."); + } + } + } else { + ob = Activator.CreateInstance (t); + } + + foreach (DictionaryEntry de in att.Properties) { + string pname = (string)de.Key; + PropertyInfo prop = t.GetProperty (pname); + if (prop != null) { + if (prop.PropertyType == typeof(System.Type)) { + // We can't load the type. We have to use the typeName property instead. + pname += "Name"; + prop = t.GetProperty (pname, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + } + if (prop == null) { + throw new InvalidOperationException ("Property '" + pname + "' not found in type '" + t + "'."); + } + prop.SetValue (ob, de.Value, null); + } + } + return ob; + } + + public object LoadAssembly (string file) + { + return LoadAssembly (file, false); + } + + public AssemblyDefinition LoadAssembly (string file, bool cache) + { + AssemblyDefinition adef = (AssemblyDefinition) cachedAssemblies [file]; + if (adef != null) + return adef; + adef = AssemblyFactory.GetAssembly (file); + if (adef != null && cache) + cachedAssemblies [file] = adef; + return adef; + } + + public object LoadAssemblyFromReference (object asmReference) + { + AssemblyNameReference aref = (AssemblyNameReference) asmReference; + string loc = locator.GetAssemblyLocation (aref.FullName); + if (loc != null) + return LoadAssembly (loc); + else + return null; + } + + public System.Collections.IEnumerable GetAssemblyTypes (object asm) + { + TypeDefinitionCollection types = ((AssemblyDefinition)asm).MainModule.Types; + foreach (IAnnotationProvider t in types) + t.Annotations [typeof(AssemblyDefinition)] = asm; + return types; + } + + public System.Collections.IEnumerable GetAssemblyReferences (object asm) + { + return ((AssemblyDefinition)asm).MainModule.AssemblyReferences; + } + + public object GetType (object asm, string typeName) + { + IAnnotationProvider t = ((AssemblyDefinition)asm).MainModule.Types [typeName]; + if (t != null) { + t.Annotations [typeof(AssemblyDefinition)] = asm; + return t; + } else + return null; + } + + public object GetCustomAttribute (object obj, Type type, bool inherit) + { + foreach (object att in GetCustomAttributes (obj, type, inherit)) + if (type.IsInstanceOfType (obj)) + return att; + return null; + } + + public string GetTypeName (object type) + { + return ((TypeDefinition)type).Name; + } + + public string GetTypeFullName (object type) + { + return ((TypeDefinition)type).FullName; + } + + public string GetTypeAssemblyQualifiedName (object type) + { + AssemblyDefinition asm = GetAssemblyDefinition ((TypeDefinition)type); + return ((TypeDefinition)type).FullName + ", " + asm.Name.FullName; + } + + AssemblyDefinition GetAssemblyDefinition (TypeDefinition t) + { + IAnnotationProvider aprov = (IAnnotationProvider) t; + return (AssemblyDefinition) aprov.Annotations [typeof(AssemblyDefinition)]; + } + + public System.Collections.IEnumerable GetBaseTypeFullNameList (object type) + { + TypeDefinition t = (TypeDefinition) type; + AssemblyDefinition asm = GetAssemblyDefinition (t); + + ArrayList list = new ArrayList (); + Hashtable visited = new Hashtable (); + GetBaseTypeFullNameList (visited, list, asm, t); + return list; + } + + void GetBaseTypeFullNameList (Hashtable visited, ArrayList list, AssemblyDefinition asm, TypeReference tr) + { + TypeDefinition type = FindTypeDefinition (asm, tr); + if (type == null) + return; + + asm = GetAssemblyDefinition (type); + + TypeReference btype = type.BaseType; + if (btype != null && btype.FullName != "System.Object" && !visited.Contains (btype.FullName)) { + list.Add (btype.FullName); + visited [btype.FullName] = btype; + GetBaseTypeFullNameList (visited, list, asm, btype); + } + foreach (TypeReference interf in type.Interfaces) { + GetBaseTypeFullNameList (visited, list, asm, interf); + } + } + + TypeDefinition FindTypeDefinition (AssemblyDefinition referencer, TypeReference rt) + { + if (rt is TypeDefinition) + return (TypeDefinition) rt; + + string name = rt.FullName; + TypeDefinition td = GetType (referencer, name) as TypeDefinition; + if (td != null) + return td; + + foreach (AssemblyNameReference aref in referencer.MainModule.AssemblyReferences) { + string loc = locator.GetAssemblyLocation (aref.FullName); + if (loc == null) + continue; + AssemblyDefinition asm = LoadAssembly (loc, true); + td = GetType (asm, name) as TypeDefinition; + if (td != null) + return td; + } + return null; + } + + public bool TypeIsAssignableFrom (object baseType, object type) + { + string baseName = ((TypeDefinition)baseType).FullName; + foreach (string bt in GetBaseTypeFullNameList (type)) + if (bt == baseName) + return true; + return false; + } + + public IEnumerable GetFields (object type) + { + return ((TypeDefinition)type).Fields; + } + + public string GetFieldName (object field) + { + return ((FieldDefinition)field).Name; + } + + public string GetFieldTypeFullName (object field) + { + return ((FieldDefinition)field).FieldType.FullName; + } + + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/AUTHORS b/Mono.Addins.CecilReflector/Mono.Cecil/AUTHORS new file mode 100644 index 0000000..c05a391 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/AUTHORS @@ -0,0 +1 @@ +Jb Evain (jbevain@gmail.com) diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/ChangeLog b/Mono.Addins.CecilReflector/Mono.Cecil/ChangeLog new file mode 100644 index 0000000..1cd2ca6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/ChangeLog @@ -0,0 +1,3920 @@ +2008-02-06 Lluis Sanchez Gual <lluis@novell.com> + + * configure, Mono.Cecil.dll.sources, default.build, Mono.Cecil.csproj, + AUTHORS, Mono.Cecil, Mono.Cecil/InterfaceCollection.cs, + Mono.Cecil/GenericParameter.cs, Mono.Cecil/AssemblyLinkedResource.cs, + Mono.Cecil/ModuleReferenceCollection.cs, Mono.Cecil/ArrayType.cs, + Mono.Cecil/MethodSpecification.cs, + Mono.Cecil/ICustomAttributeProvider.cs, Mono.Cecil/TypeSpecification.cs, + Mono.Cecil/IReflectionVisitor.cs, Mono.Cecil/ReflectionHelper.cs, + Mono.Cecil/OverrideCollection.cs, Mono.Cecil/BaseAssemblyResolver.cs, + Mono.Cecil/CallSite.cs, Mono.Cecil/ArrayDimensionCollection.cs, + Mono.Cecil/SecurityDeclarationReader.cs, + Mono.Cecil/GenericInstanceType.cs, Mono.Cecil/ModuleReference.cs, + Mono.Cecil/ParameterDefinitionCollection.cs, + Mono.Cecil/IReflectionVisitable.cs, + Mono.Cecil/EventDefinitionCollection.cs, + Mono.Cecil/FieldDefinitionCollection.cs, + Mono.Cecil/PropertyDefinitionCollection.cs, + Mono.Cecil/ModuleDefinitionCollection.cs, Mono.Cecil/IImporter.cs, + Mono.Cecil/IMethodSignature.cs, Mono.Cecil/TypeReferenceCollection.cs, + Mono.Cecil/PInvokeAttributes.cs, Mono.Cecil/ArrayDimension.cs, + Mono.Cecil/ParameterAttributes.cs, Mono.Cecil/FunctionPointerType.cs, + Mono.Cecil/GenericParameterCollection.cs, + Mono.Cecil/PropertyAttributes.cs, Mono.Cecil/AssemblyInfo.cs, + Mono.Cecil/FieldDefinition.cs, Mono.Cecil/StructureWriter.cs, + Mono.Cecil/CustomAttribute.cs, Mono.Cecil/TypeReference.cs, + Mono.Cecil/GenericInstanceMethod.cs, + Mono.Cecil/MemberReferenceCollection.cs, + Mono.Cecil/IReflectionStructureVisitor.cs, + Mono.Cecil/BaseReflectionReader.cs, + Mono.Cecil/AssemblyNameReferenceCollection.cs, + Mono.Cecil/IHasSecurity.cs, Mono.Cecil/MethodCallingConvention.cs, + Mono.Cecil/ReflectionReader.cs, Mono.Cecil/MethodReturnType.cs, + Mono.Cecil/NativeType.cs, Mono.Cecil/AssemblyDefinition.cs, + Mono.Cecil/IMemberDefinition.cs, Mono.Cecil/TypeDefinition.cs, + Mono.Cecil/IHasConstant.cs, Mono.Cecil/IMemberReference.cs, + Mono.Cecil/IMetadataTokenProvider.cs, Mono.Cecil/DefaultImporter.cs, + Mono.Cecil/IHasMarshalSpec.cs, Mono.Cecil/BaseStructureVisitor.cs, + Mono.Cecil/Constants.cs, Mono.Cecil/SecurityDeclaration.cs, + Mono.Cecil/LinkedResource.cs, Mono.Cecil/ImportContext.cs, + Mono.Cecil/AssemblyKind.cs, Mono.Cecil/FileAttributes.cs, + Mono.Cecil/FieldAttributes.cs, Mono.Cecil/AssemblyHashAlgorithm.cs, + Mono.Cecil/CompactFrameworkCompatibility.cs, + Mono.Cecil/ReferenceType.cs, Mono.Cecil/PropertyReference.cs, + Mono.Cecil/ResourceCollection.cs, Mono.Cecil/AssemblyFactory.cs, + Mono.Cecil/ReflectionException.cs, Mono.Cecil/IGenericInstance.cs, + Mono.Cecil/NullReferenceImporter.cs, Mono.Cecil/PinnedType.cs, + Mono.Cecil/PointerType.cs, Mono.Cecil/ExternTypeCollection.cs, + Mono.Cecil/GenericParameterAttributes.cs, + Mono.Cecil/IReflectionStructureVisitable.cs, + Mono.Cecil/TypeAttributes.cs, Mono.Cecil/AssemblyNameDefinition.cs, + Mono.Cecil/SecurityDeclarationCollection.cs, + Mono.Cecil/TargetRuntime.cs, Mono.Cecil/GenericArgumentCollection.cs, + Mono.Cecil/IAnnotationProvider.cs, Mono.Cecil/AssemblyNameReference.cs, + Mono.Cecil/ConstraintCollection.cs, Mono.Cecil/EventReference.cs, + Mono.Cecil/EmbeddedResource.cs, Mono.Cecil/BaseReflectionVisitor.cs, + Mono.Cecil/CustomAttributeCollection.cs, Mono.Cecil/SentinelType.cs, + Mono.Cecil/StructureReader.cs, Mono.Cecil/ManifestResourceAttributes.cs, + Mono.Cecil/MethodDefinition.cs, Mono.Cecil/EventDefinition.cs, + Mono.Cecil/ModuleDefinition.cs, Mono.Cecil/ReflectionController.cs, + Mono.Cecil/MethodReference.cs, Mono.Cecil/MarshalSpec.cs, + Mono.Cecil/TypeDefinitionCollection.cs, Mono.Cecil/VariantType.cs, + Mono.Cecil/IAssemblyResolver.cs, Mono.Cecil/IRequireResolving.cs, + Mono.Cecil/IMetadataScope.cs, Mono.Cecil/MemberReference.cs, + Mono.Cecil/Resource.cs, Mono.Cecil/PInvokeInfo.cs, + Mono.Cecil/ReflectionWriter.cs, Mono.Cecil/HashCodeProvider.cs, + Mono.Cecil/AggressiveReflectionReader.cs, Mono.Cecil/IDetailReader.cs, + Mono.Cecil/FieldReference.cs, Mono.Cecil/SecurityAction.cs, + Mono.Cecil/MethodDefinitionCollection.cs, + Mono.Cecil/MethodImplAttributes.cs, Mono.Cecil/GenericContext.cs, + Mono.Cecil/Modifiers.cs, Mono.Cecil/MethodAttributes.cs, + Mono.Cecil/EventAttributes.cs, Mono.Cecil/ParameterDefinition.cs, + Mono.Cecil/AssemblyFlags.cs, Mono.Cecil/PropertyDefinition.cs, + Mono.Cecil/MethodSemanticsAttributes.cs, + Mono.Cecil/ParameterReference.cs, Mono.Cecil/NestedTypeCollection.cs, + Mono.Cecil/IGenericParameterProvider.cs, + Mono.Cecil/ConstructorCollection.cs, Mono.Cecil/TableComparers.cs, + Mono.Cecil/DefaultAssemblyResolver.cs, ChangeLog, mono-cecil.pc.in, + Mono.Cecil.Cil, Mono.Cecil.Cil/OpCodeType.cs, + Mono.Cecil.Cil/Document.cs, Mono.Cecil.Cil/Instruction.cs, + Mono.Cecil.Cil/SequencePoint.cs, Mono.Cecil.Cil/MethodHeader.cs, + Mono.Cecil.Cil/DocumentHashAlgorithm.cs, + Mono.Cecil.Cil/ExceptionHandler.cs, Mono.Cecil.Cil/IScopeProvider.cs, + Mono.Cecil.Cil/CodeReader.cs, Mono.Cecil.Cil/CilWorker.cs, + Mono.Cecil.Cil/ISymbolReader.cs, Mono.Cecil.Cil/ICodeVisitor.cs, + Mono.Cecil.Cil/VariableReference.cs, Mono.Cecil.Cil/CodeWriter.cs, + Mono.Cecil.Cil/FlowControl.cs, Mono.Cecil.Cil/OpCode.cs, + Mono.Cecil.Cil/VariableDefinitionCollection.cs, Mono.Cecil.Cil/Code.cs, + Mono.Cecil.Cil/ISymbolWriter.cs, Mono.Cecil.Cil/GuidAttribute.cs, + Mono.Cecil.Cil/DocumentType.cs, Mono.Cecil.Cil/DocumentLanguage.cs, + Mono.Cecil.Cil/IVariableDefinitionProvider.cs, + Mono.Cecil.Cil/SymbolStoreHelper.cs, + Mono.Cecil.Cil/ISymbolStoreFactory.cs, + Mono.Cecil.Cil/ScopeCollection.cs, Mono.Cecil.Cil/BaseCodeVisitor.cs, + Mono.Cecil.Cil/ICodeVisitable.cs, Mono.Cecil.Cil/OperandType.cs, + Mono.Cecil.Cil/OpCodes.cs, Mono.Cecil.Cil/InstructionCollection.cs, + Mono.Cecil.Cil/MethodBody.cs, Mono.Cecil.Cil/ExceptionHandlerType.cs, + Mono.Cecil.Cil/VariableDefinition.cs, + Mono.Cecil.Cil/MethodDataSection.cs, + Mono.Cecil.Cil/DocumentLanguageVendor.cs, + Mono.Cecil.Cil/ExceptionHandlerCollection.cs, Mono.Cecil.Cil/Scope.cs, + Mono.Cecil.Cil/StackBehaviour.cs, README, standalone.make, CodeGen, + CodeGen/cecil-gen.rb, CodeGen/cecil-gen-tests.rb, + CodeGen/cecil-update-rev, CodeGen/cecil-gen-sources.rb, + CodeGen/cecil-gen-types.rb, CodeGen/cecil-mig.rb, + CodeGen/cecil-gen-attributes.rb, CodeGen/cecil.xml, CodeGen/templates, + CodeGen/templates/MetadataTableReader.cs, + CodeGen/templates/BaseMetadataVisitor.cs, + CodeGen/templates/Utilities.cs, CodeGen/templates/MetadataRowReader.cs, + CodeGen/templates/IndexedCollection.cs, CodeGen/templates/OpCodes.cs, + CodeGen/templates/NamedCollection.cs, CodeGen/templates/Tests.cs, + CodeGen/templates/MetadataRowWriter.cs, + CodeGen/templates/MetadataTableWriter.cs, + CodeGen/templates/CodedIndex.cs, CodeGen/templates/Table.cs, + CodeGen/templates/IMetadataVisitor.cs, CodeGen/templates/Code.cs, + Mono.Cecil.Metadata, Mono.Cecil.Metadata/Assembly.cs, + Mono.Cecil.Metadata/PropertyMap.cs, + Mono.Cecil.Metadata/InterfaceImpl.cs, + Mono.Cecil.Metadata/MetadataInitializer.cs, + Mono.Cecil.Metadata/ParamPtr.cs, Mono.Cecil.Metadata/Constant.cs, + Mono.Cecil.Metadata/BaseMetadataVisitor.cs, + Mono.Cecil.Metadata/MethodSpec.cs, + Mono.Cecil.Metadata/IMetadataVisitable.cs, + Mono.Cecil.Metadata/DeclSecurity.cs, Mono.Cecil.Metadata/TypeDef.cs, + Mono.Cecil.Metadata/GenericParamConstraint.cs, + Mono.Cecil.Metadata/MethodImpl.cs, Mono.Cecil.Metadata/EventPtr.cs, + Mono.Cecil.Metadata/NestedClass.cs, + Mono.Cecil.Metadata/MetadataTableReader.cs, + Mono.Cecil.Metadata/AssemblyRefProcessor.cs, + Mono.Cecil.Metadata/AssemblyRef.cs, + Mono.Cecil.Metadata/AssemblyRefOS.cs, Mono.Cecil.Metadata/Method.cs, + Mono.Cecil.Metadata/RowCollection.cs, + Mono.Cecil.Metadata/MetadataTableWriter.cs, + Mono.Cecil.Metadata/StringsHeap.cs, + Mono.Cecil.Metadata/MetadataRowReader.cs, + Mono.Cecil.Metadata/ElementType.cs, Mono.Cecil.Metadata/ExportedType.cs, + Mono.Cecil.Metadata/CustomAttribute.cs, Mono.Cecil.Metadata/Param.cs, + Mono.Cecil.Metadata/MetadataReader.cs, + Mono.Cecil.Metadata/ClassLayout.cs, + Mono.Cecil.Metadata/MetadataRowWriter.cs, + Mono.Cecil.Metadata/MetadataFormatException.cs, + Mono.Cecil.Metadata/PropertyPtr.cs, Mono.Cecil.Metadata/Utilities.cs, + Mono.Cecil.Metadata/BlobHeap.cs, Mono.Cecil.Metadata/MetadataWriter.cs, + Mono.Cecil.Metadata/AssemblyOS.cs, Mono.Cecil.Metadata/IMetadataRow.cs, + Mono.Cecil.Metadata/MetadataToken.cs, Mono.Cecil.Metadata/ModuleRef.cs, + Mono.Cecil.Metadata/MetadataRoot.cs, + Mono.Cecil.Metadata/UserStringsHeap.cs, + Mono.Cecil.Metadata/FieldMarshal.cs, + Mono.Cecil.Metadata/GenericParam.cs, Mono.Cecil.Metadata/ImplMap.cs, + Mono.Cecil.Metadata/TableCollection.cs, + Mono.Cecil.Metadata/CultureUtils.cs, Mono.Cecil.Metadata/CodedIndex.cs, + Mono.Cecil.Metadata/TablesHeap.cs, + Mono.Cecil.Metadata/MetadataStreamCollection.cs, + Mono.Cecil.Metadata/FieldPtr.cs, Mono.Cecil.Metadata/TypeRef.cs, + Mono.Cecil.Metadata/MetadataHeap.cs, + Mono.Cecil.Metadata/ManifestResource.cs, + Mono.Cecil.Metadata/AssemblyProcessor.cs, Mono.Cecil.Metadata/File.cs, + Mono.Cecil.Metadata/EventMap.cs, Mono.Cecil.Metadata/Event.cs, + Mono.Cecil.Metadata/FieldLayout.cs, Mono.Cecil.Metadata/TokenType.cs, + Mono.Cecil.Metadata/Field.cs, Mono.Cecil.Metadata/Property.cs, + Mono.Cecil.Metadata/Module.cs, Mono.Cecil.Metadata/GuidHeap.cs, + Mono.Cecil.Metadata/MethodSemantics.cs, + Mono.Cecil.Metadata/StandAloneSig.cs, Mono.Cecil.Metadata/FieldRVA.cs, + Mono.Cecil.Metadata/MetadataStream.cs, Mono.Cecil.Metadata/TypeSpec.cs, + Mono.Cecil.Metadata/IMetadataTable.cs, Mono.Cecil.Metadata/MemberRef.cs, + Mono.Cecil.Metadata/MethodPtr.cs, + Mono.Cecil.Metadata/IMetadataVisitor.cs, TODO, Mono.Xml, + Mono.Cecil.Signatures, Mono.Cecil.Signatures/BaseSignatureVisitor.cs, + Mono.Cecil.Signatures/ISignatureVisitable.cs, + Mono.Cecil.Signatures/MethodRefSig.cs, + Mono.Cecil.Signatures/CustomAttrib.cs, + Mono.Cecil.Signatures/FieldSig.cs, Mono.Cecil.Signatures/Var.cs, + Mono.Cecil.Signatures/FnPtr.cs, Mono.Cecil.Signatures/SzArray.cs, + Mono.Cecil.Signatures/MethodSpec.cs, + Mono.Cecil.Signatures/ArrayShape.cs, Mono.Cecil.Signatures/Ptr.cs, + Mono.Cecil.Signatures/MVar.cs, Mono.Cecil.Signatures/GenericArg.cs, + Mono.Cecil.Signatures/LocalVarSig.cs, Mono.Cecil.Signatures/Array.cs, + Mono.Cecil.Signatures/ValueType.cs, Mono.Cecil.Signatures/MethodSig.cs, + Mono.Cecil.Signatures/SigType.cs, + Mono.Cecil.Signatures/SignatureReader.cs, + Mono.Cecil.Signatures/Constraint.cs, + Mono.Cecil.Signatures/PropertySig.cs, + Mono.Cecil.Signatures/MarshalSig.cs, + Mono.Cecil.Signatures/ISignatureVisitor.cs, + Mono.Cecil.Signatures/RetType.cs, + Mono.Cecil.Signatures/GenericInstSignature.cs, + Mono.Cecil.Signatures/TypeSpec.cs, + Mono.Cecil.Signatures/SignatureWriter.cs, + Mono.Cecil.Signatures/InputOutputItem.cs, + Mono.Cecil.Signatures/Param.cs, Mono.Cecil.Signatures/Signature.cs, + Mono.Cecil.Signatures/MethodDefSig.cs, Mono.Cecil.Signatures/Class.cs, + Mono.Cecil.Signatures/GenericInst.cs, + Mono.Cecil.Signatures/CustomMod.cs, Mono.Cecil.Binary, + Mono.Cecil.Binary/PEFileHeader.cs, + Mono.Cecil.Binary/SectionCollection.cs, + Mono.Cecil.Binary/ResourceDirectoryTable.cs, + Mono.Cecil.Binary/ResourceWriter.cs, Mono.Cecil.Binary/RuntimeImage.cs, + Mono.Cecil.Binary/ExportTable.cs, Mono.Cecil.Binary/BaseImageVisitor.cs, + Mono.Cecil.Binary/ResourceNode.cs, Mono.Cecil.Binary/Imports.cs, + Mono.Cecil.Binary/ResourceDirectoryEntry.cs, + Mono.Cecil.Binary/DOSHeader.cs, Mono.Cecil.Binary/DebugHeader.cs, + Mono.Cecil.Binary/SectionCharacteristics.cs, + Mono.Cecil.Binary/ResourceDirectoryString.cs, + Mono.Cecil.Binary/ResourceDataEntry.cs, Mono.Cecil.Binary/Section.cs, + Mono.Cecil.Binary/DebugStoreType.cs, Mono.Cecil.Binary/ImageReader.cs, + Mono.Cecil.Binary/ImageFormatException.cs, + Mono.Cecil.Binary/IBinaryVisitor.cs, + Mono.Cecil.Binary/ImageCharacteristics.cs, + Mono.Cecil.Binary/ImageWriter.cs, Mono.Cecil.Binary/CLIHeader.cs, + Mono.Cecil.Binary/Image.cs, Mono.Cecil.Binary/PEOptionalHeader.cs, + Mono.Cecil.Binary/ImageInitializer.cs, Mono.Cecil.Binary/RVA.cs, + Mono.Cecil.Binary/CopyImageVisitor.cs, + Mono.Cecil.Binary/DataDirectory.cs, Mono.Cecil.Binary/SubSystem.cs, + Mono.Cecil.Binary/IBinaryVisitable.cs, Mono.Cecil.Binary/IHeader.cs, + Mono.Cecil.Binary/MemoryBinaryWriter.cs, + Mono.Cecil.Binary/ResourceReader.cs, NEWS, Makefile: Added support for + pluggable add-in assembly reflectors. Implemented an add-in assembly + reflector based on Cecil. + +2007-10-31 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Binary/ImageReader.cs: fix for the case where + the export table export zero functions. + +2007-10-18 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/MethodBody.cs: Add an Optimize method which + is the opposite of Simplify. Based on a patch by Carlo. + + * Mono.Cecil.Cil/CodeWriter.cs: don't care about reducing MaxStack. + +2007-10-11 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/TypeReference.cs: add a IsNested helper property. + + * Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Integrate patch for Carlo, start working on enum writing + in custom attribute. + +2007-10-09 Nestor Salceda <nestor.salceda@gmail.com> + + * mono-cecil.pc.in: Updated the version number. + +2007-10-09 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/Instruction.cs + Mono.Cecil.Cil/CodeWriter.cs: + Move CodeWriter.GetSize (Instruction) to Instruction. + + Integration of patches from Carlo Kok <ck@remobjects.com>: + + * Mono.Cecil.Cil/Document.cs + Mono.Cecil.Cil/DocumentType.cs + Mono.Cecil.Cil/DocumentLanguage.cs + Mono.Cecil.Cil/DocumentLanguageVendor.cs: + Use plain guids for Document properties so it's easy + for third party document providers to use their own. + + * Mono.Cecil/ParameterDefinition.cs: + Clean or set the HasFieldMarshal flag when setting + MarshalSpecs on parameters. + + * Mono.Cecil/AssemblyNameReference.cs: + Protect against null culture. + + * Mono.Cecil/FieldDefinition.cs: + Clean or set the HasFieldMarshal flag when setting + MarshalSpecs on fields. + + * Mono.Cecil/GenericInstanceType.cs: + Properly initialize the IsValueType from the element type. + +2007-10-09 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/ReflectionWriter.cs: check for duplicates + in the MemberRef row. + +2007-10-08 Sebastien Pouliot <sebastien@ximian.com> + + * standalone.make: Revert changes so standalone Cecil (in SVN) can + be built using this Makefile (required for Gendarme); + * README: Update build and bug instructions. + +2007-10-07 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/BaseAssemblyResolver.cs: first lookup assemblies + in the specified directories before trying the framework dir. + +2007-10-06 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/OpCode.cs: make that a struct again, it + make the 2.1 profile explode. Will investigate why. + +2007-10-06 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/MethodCallingConvention.cs: Not a [Flag] + +2007-10-05 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/OpCode.cs: Change OpCode from struct to class + to avoid copying everything everytime. + +2007-09-28 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/SecurityDeclarationReader.cs: + Adapt patch from Carlo Kok <ck@remobjects.com>. + Properly read unicode string constants. + + * Mono.Cecil/SecurityDeclarationReader.cs: + Adapt patch from Carlo Kok <ck@remobjects.com>. + For some MS assemblies, the security declaration contains + one zero byte. + +2007-09-24 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/ModuleDefinition.cs: after a FullLoad, the symbol + reader is not needed anymore. + +2007-09-18 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/MethodBody.cs: + Adapt a patch from Ivan <ivanjh@gmail.com>. + Fix cloning of the This parameter. + +2007-09-12 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/TypeSpec.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Deal with custom mods on typespecs. + +2007-09-12 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Binary/ImageReader.cs: some 64bits assemblies + have a strange header without import tables. + +2007-09-09 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/GenericContext.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/DefaultImporter.cs: + Better handling of generic instances of references, where + the number of generic parameters is not known. + +2007-09-06 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/MethodDefinition: add Is** methods for MethodImplAttributes. + +2007-09-04 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/ReflectionWriter.cs: + Adapt a patch by Ewout Prangsma <ewout@tallapplications.com>. + Cache the typespec tokens instead of the typespec themselves + because GenericParameters are somethimes considered as typespecs. + +2007-08-28 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Cil/SymbolStoreHelper.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Generate proper variables signatures for symbols + stores. + +2007-08-19 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/CodeReader.cs: + Deal with generic exceptions. + +2007-08-15 Jb Evain <jbevain@novell.com> + + * CodeGen/cecil.xml, + Mono.Cecil.Cil/OpCodes.cs: + Fix bug spotted by Jesse Jones, ldelem.any has a + stack behavior pop of popref, popi. + +2007-08-15 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/TypeReference.cs + Mono.Cecil/TypeSpecification.cs: + TypeSpecification.Module return the module of the elemen + type now. + +2007-08-13 Rodrigo B. de Oliveira <rodrigobamboo@gmail.com> + + * default.build + Mono.Cecil/AssemblyInfo.cs: + Ability to pass custom defines to the c# compiler through + the csc.defines property. KEYFILE can be used to force + an AssemblyKeyFile attribute on AssemblyInfo.cs so strongly + signed versions of Mono.Cecil can be produced on .net 1.1, + cf 1.0 and cf 2.0. + +2007-08-13 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/CilWorker.cs: + Fix InsertBefore. + +2007-08-06 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/CilWorker.cs: + Fix the linked list after an InsertBefore, InsertAfter. + +2007-08-02 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/GenericParameter.cs + Mono.Cecil/FieldDefinition.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/EventDefinition.cs + Mono.Cecil/PInvokeInfo.cs + Mono.Cecil/Resource.cs + Mono.Cecil/ParameterDefinition.cs + Mono.Cecil/PropertyDefinition.cs: + + Add Isxxx properties based on the xxxAttributes enums. + +2007-07-23 Raja R Harinath <rharinath@novell.com> + + Fix 'make warnings'. + * Makefile (LIBRARY_PACKAGE): Set to none. + (install-local): Remove. + +2007-07-21 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/TypeReference.cs + Mono.Cecil/TypeSpecification.cs: + Add a new GetOriginalType () method. + + * Mono.Cecil/MethodReference.cs + Mono.Cecil/MethodSpecification.cs: + Add a new GetOriginalMethod () method. + +2007-07-19 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/AssemblyFactory.cs + Mono.Cecil.Binary/Image.cs: + Update the fileinfo after writing an assembly + to a file. + +2007-07-19 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Signature/SignatureReader.cs: + Better handling of the sentil in the varargs methods. + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/SentinelType.cs + Mono.Cecil.Cil/CodeWriter.cs: + Mono.Cecil.Signatures/SignatureReader.cs: + Fix handling of varargs methods. + +2007-07-18 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/CodeWriter.cs: + Deal with non-sense instructions that some + obfuscators emit. + + * Mono.Cecil/AggressiveReflectionReader.cs: + Deal with out of range properties. + * Mono.Cecil.Metadata/StringsHeap.cs: + Deal with out of range string indexes. + +2007-07-17 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/AggressiveReflectionReader.cs: + Add some gards against zeroed tokens. + + * Mono.Cecil.Metadata/Utilities.cs: + Return zero instead of throwing on invalid tags. + Allow Cecil to read assemblies partially broken + by some obfuscators. + +2007-07-14 Gert Driesen <drieseng@users.sourceforge.net> + + * default.build: Fix relative path to key. Avoid use of ugly foreach + contruct. Spaces to tabs. + * Mono.Cecil.csproj: Fix relative path to key. + * standalone.make: Fix relative path to key and config.make. + +2007-07-03 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/BaseAssemblyResolver.cs: + Expose a way to add default directories + where the assemblies are first looked for. + +2007-06-20 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/IReferenceImporter.cs => IImporter.cs + Mono.Cecil/DefaultReferenceImporter.cs => DefaultImporter.cs + + * Mono.Cecil/ReflectionHelper.cs + Mono.Cecil/DefaultReferenceImporter.cs + Mono.Cecil/ModuleDefinition.cs: + Move Cecil types import logic into + the DefaultReferenceImporter. + + Needed by the merger and the extractor. + +2007-06-19 Jb Evain <jbevain@novell.com> + + * Mono.Cecil.Cil/MethodBody.cs: + Avoid invalid cast by properly simplifying + instructions. + + * Mono.Cecil.Cil/OpCodes.cs: + CodeGen/cecil.xml: + leave.s is a macro instruction. + + * Mono.Cecil/TypeDefinition.cs + Mono.Cecil/ParameterDefinition.cs: + Fix cloning. + +2007-06-18 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/ReflectionReader.cs: + Fix custom mods for fields ref. + +2007-06-13 Jb Evain <jbevain@novell.com> + + Integrated patches by: + Paul Apostolescu <papostolescu@fortifysoftware.com> + + * patch3: + Mono.Cecil/ReflectionReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + In named args, objects are encoded as boxed. + + * patch1: + Mono.Cecil/IMemberDefinition.cs + Mono.Cecil/Constants.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/AggressiveReflectionReader.cs: + Do not take into account special _Deleted + members. + + * patch6: + Mono.Cecil/StructureReader.cs: + Read the flags of the references as well. + + * patch5: + Mono.Cecil.Metadata/UserStringsHeap.cs: + Don't bother getting a string from the bytes + if the length is < 2 (0, or 0 + an encoding flag) + + * patch4: + Mono.Cecil/ReflectionHelper.cs: + Update the value type flags of types + when they are imported if the type + reference was first seen as a type reference. + + * patch2: + Mono.Cecil.Signature/SignatureWriter.cs: + Patch to handle nullref values for types in + custom attributes arguments. + +2007-06-13 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/StructureWriter.cs, + Mono.Cecil/ReflectionWriter.cs: + Revert the on demand creation of memberref. + +2007-06-12 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/CallSite.cs + Mono.Cecil/ModuleReference.cs + Mono.Cecil/CustomAttribute.cs + Mono.Cecil/AssemblyDefinition.cs + Mono.Cecil/SecurityDeclaration.cs + Mono.Cecil/AssemblyNameReference.cs + Mono.Cecil/MemberReference.cs + Mono.Cecil/Resource.cs + Mono.Cecil/ParameterReference.cs: + Implement explicitely IAnnotationProvider. + +2007-06-05 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/AssemblyNameReference.cs: + Cache the fullname when possible. + +2007-05-31 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/ModuleDefinition.cs: + Add types to the module and members to the context + on inject. + + * Mono.Cecil/BaseAssemblyResolver.cs: + Improve resolve, works for people requiring + .net 1.0 assemblies when they only have 1.1. + +2007-05-30 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/DefaultAssemblyResolver.cs: + Add a RegisterAssembly method to register an + assembly to the cache without having to resolve it. + + * Mono.Cecil/DefaultReferenceImporter.cs: + Make methods virtual. + + * Mono.Cecil.dll.sources + Mono.Cecil.csproj + Mono.Cecil/ReflectionHelper.cs + Mono.Cecil/IReferenceImporter.cs + Mono.Cecil/FieldDefinition.cs + Mono.Cecil/CustomAttribute.cs + Mono.Cecil/ImportContext.cs + Mono.Cecil/NullReferenceImporter.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/EventDefinition.cs + Mono.Cecil/ReflectionController.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/GenericContext.cs + Mono.Cecil/DefaultReferenceImporter.cs + Mono.Cecil/PropertyDefinition.cs: + Provide a IReferenceImporter to customize how + types are injected from an assembly to another. + +2007-05-28 Jb Evain <jbevain@novell.com> + + * Borrow annotations concept from boo ast node. + Should be useful for the linker. + +2007-05-23 Jb Evain <jbevain@novell.com> + + * Mono.Cecil/StructureWriter.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Cil/CodeWriter.cs: + Emit MemberReferences rows on demand. + +2007-05-16 Jb Evain <jb@nurv.fr> + + * Mono.Cecil.Binary/ImageReader.cs: + Fix reading of the debug header for + headers half way emitted by .net SRE. + + * Mono.Cecil/BaseAssemblyResolver: + try to resolve unversionned assemblies. + +2007-05-09 Jb Evain <jb@nurv.fr> + + * Mono.Cecil.Binary/Image.cs: + Throw when rva cannot be resolved. + + * Mono.Cecil.csproj + Mono.Cecil.Binary/ExportTable.cs + Mono.Cecil.Binary/BaseImageVisitor.cs + Mono.Cecil.Binary/ImageReader.cs + Mono.Cecil.Binary/IBinaryVisitor.cs + Mono.Cecil.Binary/Image.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil/StructureReader.cs + Mono.Cecil/ReflectionWriter.cs: + When present, read the export table, so that people + reading non managed assemblies can use the Mono.Cecil.Binary + stuff. + + Fix the bug when section name is 8 char long. + + Based on a patch by Pavel Savara <pavel.savara@gmail.com>. + +2007-04-27 Jb Evain <jb@nurv.fr> + + * Mono.Cecil/AssemblyNameReference.cs: + Allow the computation of pktoken on CF_2_0. + +2007-04-25 Jb Evain <jb@nurv.fr> + + * Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Cil/ISymbolWriter.cs + Mono.Cecil.Signatures/SignatureWriter.cs + Start working on local var debug infos emitting. + +2007-04-08 Jb Evain <jb@nurv.fr> + + * Mono.Cecil/ParameterAttributes.cs: + ParameterAttributes.None + +2007-03-30 Jb Evain <jb@nurv.fr> + + * Collections: + Remove uneeded tests as an optimizations. + Based on a suggestion by Carlo Kok <ck@remobjects.com>. + + * Mono.Cecil.Metadata/StringsHeap.cs: + Optimize GetStringAt, patch by: + Carlo Kok <ck@remobjects.com> + +2007-03-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyInfo.cs: + Bump to 0.5.0.0 for the sake of our packagers friends. + Re-Bump to 0.5.0.1. + + * Mono.Cecil/StructureWriter.cs: + Throw a NotSupportedException instead of a NIE + for mixed mode assemblies. + +2007-03-20 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/MetadataWriter.cs: + Correct epilog for unicode user strings heap. + +2007-03-16 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/MethodBody.cs: + Add a MethodBody.Simplify method to expand + macros. + + * Mono.Cecil.dll.sources + Mono.Cecil.csproj + Mono.Cecil.Cil/OpCode.cs + Mono.Cecil.Cil/OpCodes.cs + Mono.Cecil.Cil/Code.cs + CodeGen/cecil-gen.rb + CodeGen/templates/OpCodes.cs + CodeGen/templates/Code.cs: + Add a Code enumeration to simplify working with + OpCodes. + +2007-03-12 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/UserStringsHeap.cs: + Avoid trailing blank on some systems. + +2007-02-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Deal with sentinels on simple methodrefs. + +2007-02-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.dll.sources + Mono.Cecil.csproj + CodeGen/cecil.xml + Mono.Cecil.Metadata/ParamPtr.cs + Mono.Cecil.Metadata/MethodSpec.cs + Mono.Cecil.Metadata/BaseMetadataVisitor.cs + Mono.Cecil.Metadata/EventPtr.cs + Mono.Cecil.Metadata/MetadataTableReader.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataRowReader.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/PropertyPtr.cs + Mono.Cecil.Metadata/FieldPtr.cs + Mono.Cecil.Metadata/MethodPtr.cs + Mono.Cecil.Metadata/IMetadataVisitor.cs: + Add *Ptr table definitions. + + * Mono.Cecil.dll.sources + Mono.Cecil.csproj + Mono.Cecil/CallSite.cs + Mono.Cecil/IMethodSignature.cs + Mono.Cecil/SentinelType.cs + Mono.Cecil/FunctionPointerType.cs + Mono.Cecil/MethodReference.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/CodeWriter.cs: + Implement support for writing function pointers. + Based on a patch by Argiris Kirtzidis <akyrtzi@gmail.com> + + * Mono.Cecil/Constants.cs: + Make it public due to some demands. + +2007-02-21 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Signatures/SignatureReader.cs: + do not read enums if the resolution is not forced until + cecil knows how to write them. + + * Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Signatures/SzArray.cs + Mono.Cecil.Signatures/Array.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/TypeSpec.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + handle custom mods on arrays signatures. + + * Mono.Cecil/ReflectionReader.cs: + Handle fields TypeSpecs that have an initial value. + Based on a patch by Argiris Kirtzidis <akyrtzi@gmail.com> + +2007-01-29 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/MetadataWriter.cs: + Save a byte ! Yeah ! + +2006-12-18 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionReader.cs: + Fix a bug in reading MemberRef pointing to MethodDef. + +2006-12-16 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/StructureReader.cs: + Prevent a NRE if we're reading a multi module + assembly through a stream if a module is not find. + Fix #80273. + +2006-12-07 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Allow an AssemblyDefinition to be written + more than once. + +2006-12-05 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Deal with nullref default parameters. + +2006-12-03 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Handle constant where the parameter is object + and the signature is something else. + +2006-11-27 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/TypeDefinitionCollection.cs + CodeGen/templates/NamedCollection.cs: + Allow multiple typedefs with the same namespace+name + to be able to read unvalid assemblies. + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Signatures/PropertySig.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + - Deal with modifiers on properties. + - Deal with non standard signatures when the byref + flag is placed after the custom modifiers. + Mono.Cecil/StructureReader.cs: + - Properly detect wether an assembli is a dll or not. + + Based on a patch by Argiris Kirtzidis <akyrtzi@gmail.com>. + +2006-11-25 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Signatures/GenericArg.cs + Mono.Cecil.Signatures/GenericInstSignature.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Deal with modifiers for generic arguments. + Based on a patch by Argiris Kirtzidis <akyrtzi@gmail.com>. + + * Mono.Cecil.Binary/ImageWriter.cs: + Fix a bug in writing rsrc sections. + + * Mono.Cecil.Cil/CodeReader.cs: + Do some refactoring. + + * Mono.Cecil.Metadata/MetadataToken.cs: + Add a ctor to get a MetadataToken + from an integer token. + +2006-11-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/GuidAttribute.cs: + Fix for CF compilation. + +2006-11-16 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/StructureReader.cs: + If an assembly has no managed assembly defined, + consider it as a dll. + +2006-11-08 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/BaseAssemblyResolver.cs: + Handles different kind of GAC on Windows. + +2006-11-07 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionHelper.cs: + Don't import the flags of an assembly name reference. + +2006-11-03 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/PropertyDefinition.cs: + Fix property cloning. + Patch by Alex Prudkiy <prudkiy@mail.ru> + +2006-10-26 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionReader.cs: + Use the proper generic context when reading memberrefs. + +2006-10-11 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/Document.cs: + Complete a little bit. + + * Mono.Cecil/SecurityDeclarationReader.cs: + Get rid of a lot of exceptions when creating the security + attribute. + +2006-10-10 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionReader.cs: + Mono.Cecil/CustomAttribute.cs: + Mono.Cecil.Signatures/SignatureReader.cs: + Mono.Cecil/SecurityDeclarationReader.cs: + Patch from: Eyal Alaluf <eyala@mainsoft.com>. + Add support for resolving custom attributes that contain references + to enum in other assemblies. + +2006-10-09 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IRequireResolving.cs + Mono.Cecil/CustomAttribute.cs + Mono.Cecil/SecurityDeclaration.cs + Mono.Cecil/SecurityDeclarationReader.cs + Mono.Cecil/AggressiveReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/ModuleDefinition.cs: + Introduce the interface IRequireResolving implemented + by CustomAttribute and SecurityDeclaration for when they can't + be read without loading another assembly. + + * Mono.Cecil/SecurityDeclarationReader.cs: + Prevent Cecil to crash when it can not get the type + of the declaration. + +2006-10-04 Eyal Alaluf <eyala@mainsoft.com> + + * Mono.Cecil/StructureReader.cs: + Visit the module we load when a DLL has more then 1 module. + Mono.Cecil/AssemblyNameReference.cs: + Allow "PublicToken=null" when parsing an assembly full name. + +2006-10-03 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/BaseAssemblyResolver.cs + Mono.Cecil.Binary/ResourceReader.cs: + CompactFramework fix. + +2006-10-02 Jb Evain <jbevain@gmail.com> + + * implement IList on the named collections. + + * implement the first bits of Win32 resources handling. + + * Mono.Cecil/ReflectionHelper.cs: + It does not make sense to import the assembly flags. + +2006-09-28 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/MethodDefinitionCollection.cs + Mono.Cecil/ConstructorCollection.cs + Mono.Cecil.Cil/InstructionCollection.cs + CodeGen/templates/IndexedCollection.cs + Fix StackOverlow. + +2006-09-27 Jb Evain <jbevain@gmail.com> + + * *Collection.cs: use CollectionBase when possible. + +2006-09-24 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyFactory.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Cil/ISymbolStoreFactory.cs + Mono.Cecil.Cil/SymbolStoreHelper.cs: + Some more work on the debugging infos api. + + * Mono.Cecil/MethodDefinitionCollection.cs + Mono.Cecil/ConstructorCollection.cs + CodeGen/templates/IndexedCollection.cs: + Fix the GetConstructor/GetMethod methods. + Based on a patch by Jon Chambers. + +2006-09-20 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/StructureWriter.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/AssemblyFactory.cs + Mono.Cecil.Cil/ISymbolReader.cs + Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil.Cil/ISymbolWriter.cs + Mono.Cecil.Cil/SymbolStoreHelper.cs: + Working on the debug infos stuff. + + * Mono.Cecil.Signatures/SignatureReader.cs: + Ensure custom attributes are read when they can be. + Patch by Sebastien Pouliot. + +2006-09-19 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Cil/Document.cs + Mono.Cecil.Cil/Instruction.cs + Mono.Cecil.Cil/SequencePoint.cs + Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/IScopeProvider.cs + Mono.Cecil.Cil/ISymbolReader.cs + Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil.Cil/ISymbolWriter.cs + Mono.Cecil.Cil/IVariableDefinitionProvider.cs + Mono.Cecil.Cil/SymbolStoreHelper.cs + Mono.Cecil.Cil/ISymbolStoreFactory.cs + Mono.Cecil.Cil/ScopeCollection.cs + Mono.Cecil.Cil/Scope.cs: + Work on the architecture for debugging infos. + + * Mono.Cecil.dll.sources + Mono.Cecil.Cil/Document.cs + Mono.Cecil.Cil/IVariableDefinitionProvider.cs + Mono.Cecil.Cil/SequencePoint.cs + Mono.Cecil.Cil/ScopeCollection.cs + Mono.Cecil.Cil/BaseCodeVisitor.cs + Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/IScopeProvider.cs + Mono.Cecil.Cil/MethodBody.cs + Mono.Cecil.Cil/ICodeVisitor.cs + Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil.Cil/Scope.cs + Mono.Cecil.Cil/VariableDefinitionCollection.cs + CodeGen/cecil.xml: + First bits of the debug infos stuff. + + * Mono.Cecil.Cil/InstructionCollection.cs + CodeGen/templates/IndexedCollection.cs: + The outside instruction has an offset of -1. + + * Mono.Cecil.Cil/OpCodes.cs + Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/OpCode.cs + CodeGen/templates/OpCodes.cs: + Simpliest way of dealing with different opcodes. + +2006-09-07 Jb Evain <jbevain@gmail.com> + + * support PE32+ file format. + + * Add an Outside instruction to an InstructionCollection. + Cleaner than the old null instruction. + + * Mono.Cecil/MarshalSpec.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + CodeGen/cecil-mig.rb: + Refactor names from Desc to Spec. + + * *Collection.cs: + Remove the unused events stuff. + +2006-08-31 Jb Evain <jbevain@gmail.com> + + * /!\ Breaking changes: + On the way to Cecil 0.5. Remove meaningless interfaces. + GenericParamAttributes -> GenericParameterAttributes + ParamAttributes -> ParamAttributes + + I'll provide a migration path with a script. + + Please do not use this revision, other changes are on the way. + +2006-08-26 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionReader.cs: + Fix a bug when reading some parameters. + +2006-08-26 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/ReflectionWriter.cs: + Fix the computation of the size of the last opcode in case + of an exception handler is pointing outside the cil stream. + + * Mono.Cecil.Cil/ReflectionWriter.cs: + Don't use seh tiny headers when the size can't fit in a byte. + + * Mono.Cecil.Cil/ReflectionWriter.cs: + Fix a problem in the computation of the stack when the IL + is somewhat strange. + +2006-08-23 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyInfo.cs: + Cecil 0.4.3 release. + +2006-08-21 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/MetadataWriter.cs: + Fix a bug in field initial values writing. + + * Mono.Cecil/BaseAssemblyResolver.cs: + Look for assemblies in ./ first + +2006-08-17 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/BaseAssemblyResolver.cs: + Resolve the corlib depending on its version. + + * Mono.Cecil/AssemblyName.cs + Mono.Cecil/BaseAssemblyResolver.cs: + Implement a AssemblyNameReference.Parse(string) + + * Mono.Cecil/TypeReferenceCollection.cs + Mono.Cecil/ExternTypeCollection.cs + Mono.Cecil/TypeDefinitionCollection.cs + CodeGen/templates/NamedCollectionImplem.cs: + Avoid infinite recursion. + + * Mono.Cecil/BaseAssemblyResolver.sc: + Stay .net 1.1 compatible + +2006-08-16 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IAssemblyResolver.cs + Mono.Cecil/BaseAssemblyResolver.cs + Mono.Cecil/DefaultAssemblyResolver.cs + Mono.Cecil/AssemblyDefinition.cs + Implement an assembly resolver. + + * Mono.Cecil/ReflectionReader.cs: + Fix the initial value reading. + Based on a report and a patch of Roei Erez <roeie@mainsoft.com> + +2006-08-15 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/TypeReferenceCollection.cs + Mono.Cecil/ExternTypeCollection.cs + Mono.Cecil/TypeDefinitionCollection.cs + CodeGen/templates/NamedCollectionImplem.cs: + Fix the CopyTo method. + +2006-07-19 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/IIndexedCollection.cs + CodeGen/templates/IndexedCollectionImplem.cs + Mono.Cecil/IConstructorCollection.cs + Mono.Cecil/IMethodDefinitionCollection.cs + Mono.Cecil/MethodDefinitionCollection.cs + Mono.Cecil/ConstructorCollection.cs: + Add a GetConstructor(bool,ParameterDefinitionCollection) method + required by the linker. + + * Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/StringsHeap.cs: + Read the string on demand, based on the index. + Needed due to some obfuscators that create a string entry like + xClassName, and make the pointer points to after the x. + +2006-07-03 Rodrigo B. de Oliveira <rodrigobamboo@gmail.com> + * CodeGen/templates/ImageReader.cs + Mono.Cecil.Binary/ImageReader.cs: + CompactFramework compatibility. + +2006-07-02 Rodrigo B. de Oliveira <rodrigobamboo@gmail.com> + + * CodeGen/templates/ImageReader.cs + Mono.Cecil.Binary/ImageReader.cs: + Proper FileNotFoundException construction. + + * Mono.Cecil/MethodDefinition.cs + Mono.Cecil/IMethod.cs: + Helper properties IsInternalCall and IsRuntime. + +2006-06-21 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/CilWorker.cs: + Fix ldc.i4.s emitting. + +2006-06-13 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Fix for compiling on CF 1. + * Mono.Cecil/StructureReader.cs: + Fix for a "bug" when csc 7.1 emits an assembly + with an assembly row, but no blob heap. + Plus style fix. + +2006-06-08 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IMethod.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/ReflectionWriter.cs: + Add a public HasBody property. + +2006-06-07 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/MethodDefinition.cs + Mono.Cecil/ReflectionWriter.cs: + Read and write method bodies only when allowed. + +2006-05-29 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IMethodDefinition.cs + Mono.Cecil/MethodDefinition.cs: + Remove the useless CreateBody method. + +2006-05-27 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/StructureWriter.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil.Metadata/MetadataToken.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Play better with mixed mode assemblies. + + * Mono.Cecil/SecurityDeclarationReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Read/Write this awful load of crap that is sharepoint. + +2006-05-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/CilWorker.cs: + Fix #78479. Patch by David Emsellem. + +2006-05-20 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/ImageReader.cs + CodeGen/templates/ImageWriter.cs + Mono.Cecil/AssemblyFactory.cs + Mono.Cecil/StructureWriter.cs + Mono.Cecil/Binary/ImageReader.cs + Mono.Cecil/Binary/Image.cs + Mono.Cecil/Binary/ImageWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs: + Optimize assembly writing. + Add methods to read assemblies from byte arrays. + + * Mono.Cecil/StructureWriter.cs: + Throw an exception when the target is an exe + and no entry point have been setted. + * Mono.Cecil/AssemblyFactory.cs: + Add helpers method to defines assemblies. + * Mono.Cecil/MethodDefinition.cs: + Set the hasThis flag to the correct value. + * Mono.Cecil.Cil/CodeReader.cs: + Remove old comment. + * Mono.Xml/SmallXmlParser.cs: + Make private. + +2006-05-18 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/MetadataTableReader.cs + Mono.Cecil.Metadata/MetadataTableReader.cs + Mono.Cecil.Metadata/TableCollection.cs + Mono.Cecil.Metadata/TablesHeap.cs: + Optimize a little bit. + + * CodeGen/templates/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/TableCollection.cs: + Fix for last changeset. + + * Mono.Cecil.Metadata/RIdAttribute.cs: + deleted. + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/StructureReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/AggressiveReflectionReader.cs + Mono.Cecil.Cil/CodeReader.cs + CodeGen/templates/Utilities.cs + CodeGen/templates/MetadataTableReader.cs + CodeGen/templates/MetadataTableWriter.cs + CodeGen/templates/Table.cs + CodeGen/templates/MetadataRowReader.cs + CodeGen/templates/MetadataRowWriter.cs + Mono.Cecil.Metadata/Assembly.cs + Mono.Cecil.Metadata/InterfaceImpl.cs + Mono.Cecil.Metadata/PropertyMap.cs + Mono.Cecil.Metadata/Constant.cs + Mono.Cecil.Metadata/MethodSpec.cs + Mono.Cecil.Metadata/DeclSecurity.cs + Mono.Cecil.Metadata/TypeDef.cs + Mono.Cecil.Metadata/GenericParamConstraint.cs + Mono.Cecil.Metadata/MethodImpl.cs + Mono.Cecil.Metadata/NestedClass.cs + Mono.Cecil.Metadata/MetadataTableReader.cs + Mono.Cecil.Metadata/AssemblyRefProcessor.cs + Mono.Cecil.Metadata/AssemblyRef.cs + Mono.Cecil.Metadata/AssemblyRefOS.cs + Mono.Cecil.Metadata/Method.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataRowReader.cs + Mono.Cecil.Metadata/ExportedType.cs + Mono.Cecil.Metadata/CustomAttribute.cs + Mono.Cecil.Metadata/Param.cs + Mono.Cecil.Metadata/ClassLayout.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/Utilities.cs + Mono.Cecil.Metadata/AssemblyOS.cs + Mono.Cecil.Metadata/ModuleRef.cs + Mono.Cecil.Metadata/FieldMarshal.cs + Mono.Cecil.Metadata/GenericParam.cs + Mono.Cecil.Metadata/ImplMap.cs + Mono.Cecil.Metadata/TableCollection.cs + Mono.Cecil.Metadata/TablesHeap.cs + Mono.Cecil.Metadata/TypeRef.cs + Mono.Cecil.Metadata/ManifestResource.cs + Mono.Cecil.Metadata/File.cs + Mono.Cecil.Metadata/EventMap.cs + Mono.Cecil.Metadata/AssemblyProcessor.cs + Mono.Cecil.Metadata/FieldLayout.cs + Mono.Cecil.Metadata/Event.cs + Mono.Cecil.Metadata/Field.cs + Mono.Cecil.Metadata/Property.cs + Mono.Cecil.Metadata/Module.cs + Mono.Cecil.Metadata/MethodSemantics.cs + Mono.Cecil.Metadata/StandAloneSig.cs + Mono.Cecil.Metadata/FieldRVA.cs + Mono.Cecil.Metadata/TypeSpec.cs + Mono.Cecil.Metadata/IMetadataTable.cs + Mono.Cecil.Metadata/MemberRef.cs: + Fix the way the metadata tables are handled. + + * Mono.Cecil.Signatures/SignatureWriter.cs: + Fix bug in string writing. + +2006-05-12 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyInfo.cs: + Hide the info if Cecil is embedded. + +2006-05-09 Jb Evain <jbevain@gmail.com> + + * cecil.build: rename to default.build + +2006-05-08 Jb Evain <jbevain@gmail.com> + + * Makefile: + Sign the assembly. + + * cecil.csproj: + Add an msbuild file. + +2006-05-05 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyFactory.cs + Mono.Cecil/StructureReader.cs + Mono.Cecil/ModuleDefinition.cs: + Add an AssemblyFactory.GetAssemblyManifest method. + +2006-05-04 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/TableComparers.cs: + TypeDef.Compare: the name is enough against <Module>. + + * Mono.Cecil/ReflectionWriter.cs: + Fix writing of namedargs in custom attributes. + +2006-04-26 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Signatures/SignatureReader.cs: + Don't create tons of hashtables. + +2006-04-24 Jb Evain <jbveain@gmail.com> + + * Mono.Cecil.Cil/MethodBody.cs: + Fix cloning. + +2006-04-21 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyFactory.cs + Mono.Cecil.Binary/MemoryBinaryWriter.cs: + Use MemoryStream::WriteTo when it's possible. + +2006-04-21 Rodrigo B. de Oliveira <rodrigobamboo@gmail.com> + + * Mono.Cecil/SecurityDeclaration.cs + Mono.Cecil/ISecurityDeclaration.cs + Mono.Cecil/SecurityDeclarationCollection.cs + Mono.Cecil/ModuleDefinition.cs: + Patch by Almann T. Goo (almann.goo@gmail.com) conditionally + removing references to PermissionSet when compiling for the CompactFramework. + + * Mono.Cecil/CompactFrameworkCompatibility.cs: + System.Security.PermissionSet definition no longer needed. + +2006-04-21 Jb Evain <jbevain@gmail.com> + + * *Collection.cs: + Fix typo in RemoveAt. + +2006-04-20 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Fix writing of complex arrays. + Now we roundtrip SharpDevelop. + + * Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/TableComparers.cs: + Ensure <Module> will always be the first type. + Fix roundtrip of Nemerle. + +2006-04-19 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/CodeWriter.cs: + Handle the case where an handler points after the last + instruction. Now we roundtrip db4o. + + * Mono.Cecil/IIndexedCollection.cs: + *Collection.cs: + Make every collection implement an indexed collection. + +2006-04-15 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/CustomAttribute.cs: + Fix handling of types. + +2006-04-11 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/FieldDefinition.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/IField.cs + Mono.Cecil/ITypeDefinition.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/AggressiveReflectionReader.cs + Mono.Cecil.Cil/IVariable.cs + Mono.Cecil.Cil/MethodBody.cs + Mono.Cecil.Cil/VariableDefinition.cs + Mono.Cecil.Cil/CodeWriter.cs: + Don't use interfaces internally. + + * Mono.Cecil/TypeReference.cs: + Make TypeReference extend MemberReference. + + * Mono.Cecil/Modifiers.cs + Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil.Signatures/LocalVarSig.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Fix modifiers on localvar signatures. + Fix roundtrip of delphi assemblies. + + * Mono.Cecil/CustomAttribute.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Work on complex custom attributes encoding. + + * Mono.Cecil/TableComparers.cs: + Style. + +2006-04-09 Eyal Alaluf <eyala@mainsoft.com> + + * Mono.Cecil/ReflectionReader.cs + Cannot assume that TypeRefs are ordered is such a way that an outer + class index comes always before all its inner classes. + +2006-04-06 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Clean up things a little bit prior ending + custom attribute encoding. + + * Mono.Cecil/ReflectionWriter.cs: + Write custom attributes of parameters + onyl when all methods have their tokens. + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/AggressiveReflectionReader.cs: + Handle custom attributes on generic parameters. + +2006-04-05 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Ensure the param[0] is written when it should be. + +2006-04-04 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionHelper.cs: + Remove an unused hack. + + * Mono.Cecil/AssemblyInfo.cs: Go 0.4.1 + + * Mono.Cecil.Metadata/MetadataHeap.cs + Mono.Cecil.Metadata/MetadataStream.cs: + Read #- stream has well. + + * Mono.Cecil/ReflectionHelper.cs: + Implement Import stuff for System.Type and SR.* + +2006-04-03 Rodrigo B. de Oliveira <rodrigobamboo@gmail.com> + + * Mono.Cecil/SecurityDeclarationReader.cs + Mono.Cecil/TypeReferenceCollection.cs + Mono.Cecil/CompactFrameworkCompatibility.cs + Mono.Cecil/AssemblyFactory.cs + Mono.Cecil/AssemblyName.cs + Mono.Cecil/ExternTypeCollection.cs + Mono.Cecil/TypeDefinitionCollection.cs + CodeGen/templates/NamedCollectionImplem.cs + Mono.Cecil.Metadata/CultureUtils.cs + cecil.build: + CompactFramework 2.0 support through CF_2_0 compilation symbol. + +2006-04-03 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.dll.sources + Mono.Cecil/GenericParameter.cs + Mono.Cecil/ReflectionHelper.cs + Mono.Cecil/FieldDefinition.cs + Mono.Cecil/CustomAttribute.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/IModuleDefinition.cs + Mono.Cecil/ImportContext.cs + Mono.Cecil/AssemblyName.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/EventDefinition.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/GenericContext.cs + Mono.Cecil/ParameterDefinition.cs + Mono.Cecil/PropertyDefinition.cs + Mono.Cecil.Cil/MethodBody.cs: + Work on generic assemblies manipulation via + import stuff. + +2006-03-31 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyFlags.cs: + Add a Retargetable flag used on the CF. + +2006-03-30 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/SecurityDeclarationReader.cs: + Don't crash if the declaration is empty. + + * Mono.Cecil/ParamAttributes.cs: + Update the Optional flag. + Mono.Cecil/ReflectionWriter.cs: + Fix the encoding of nullref. + Fixes #77959. Based on a patch by + Armand Du Plessis < armand@dotnet.org.za> + +2006-03-29 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IHasSecurity.cs + Mono.Cecil/IHasConstant.cs + Mono.Cecil/IHasMarshalSpec.cs: + Mono.Cecil/MethodReturnType.cs + Mono.Cecil/AssemblyDefinition.cs: + Implement IMetadataTokenProvider. + + * Mono.Cecil/StructureReader.cs + Mono.Cecil/ReflectionWriter.cs: + Use more the token providers. + +2006-03-28 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/MarshalDesc.cs + Mono.Cecil/IMarshalSpec.cs + Mono.Cecil/ReflectionWriter.cs: + Fix round-tripping of assemblies using + COM stuff. + +2006-03-27 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/MetadataToken.cs: + Override GetHashCode as we override Equals. + + * Mono.Cecil/TableComparers.cs: + Fix the ordering of generic parameters. + This revision roundtrips C5. Yeah! + + * Mono.Cecil/ReflectionWriter.cs: + Fix method spec "caching" + Mono.Cecil.Cil/OpCode.cs: + Override ToString (); + Mono.Cecil.Metadata/MetadataToken.cs: + Implement operator == + + * Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/TableComparers.cs: + Better handling of generic tables sorting. + + * Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/TableComparers.cs: + Sort generic tables as well. + +2006-03-27 Rodrigo B. de Oliveira <rodrigobamboo@gmail.com> + * Mono.Cecil.Metadata/MetadataWriter.cs: + Use CompactFramework compatible version of + System.Convert.ToBase64String. + +2006-03-27 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.dll.sources + Mono.Cecil/GenericParameter.cs + Mono.Cecil/ConstraintCollection.cs + Mono.Cecil/IGenericParameter.cs + Mono.Cecil/IConstraintCollection.cs + CodeGen/cecil.xml: + Add a ConstraintCollection to be used within + generic parameters. + + * Mono.Cecil/GenericInstanceType.cs: + Correctly return if the instance is a value type + or not. + +2006-03-25 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ModuleDefinition.cs: + Support the unreadable security declarations + when converting one to byte []. + + * Mono.Cecil/IModuleDefinition.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/ReflectionWriter.cs: + Add a FullLoad method on a module. + + * Mono.Cecil/StructureWriter.cs + Mono.Cecil/ReflectionWriter.cs: + Fix a few bugs in generics type emitting. + + * Mono.Cecil.Cil/CodeWriter.cs: + Cache local sig as well. + +2006-03-24 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Cache method specs as well. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Binary/ImageWriter.cs: + Replace the foreach char pattern by + Encoding.GetBytes + +2006-03-23 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/TypeReferenceCollection.cs + Mono.Cecil/ExternTypeCollection.cs + Mono.Cecil/TypeDefinitionCollection.cs + CodeGen/templates/NamedCollectionImplem.cs + CodeGen/templates/ImageReader.cs: + Ensure type with the same name are added + to the collection. + + * Mono.Cecil.Metadata/MetadataWriter.cs: + Ensure every blob signature is unique. + + * Mono.Cecil/IModuleDefinition.cs + Mono.Cecil/ModuleDefinition.cs: + Rename method to avoid confusion. + +2006-03-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/CodeWriter.cs: + Precisely detect whether we emit fat seh or not. + + * Mono.Cecil/ReflectionWriter.cs: + Avoid duplicates in the typespec table. + +2006-03-21 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter.cs: + Correctly write generic parameters. + + * Mono.Cecil/SecurityDeclarationReader.cs + Mono.Cecil/SecurityDeclaration.cs + Mono.Cecil/ReflectionWriter.cs: + Fix for security declarations reading on .net 2.0. + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/GenericContext.cs: + Fix test case RoundtripTestFixture.boo. + +2006-03-20 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/MetadataReader.cs: + #Strings heap is utf8, fix #77820. + +2006-03-08 Jb Evain <jbevain@gmail.com> + + * CodeGen/cecil-gen-tests.rb + CodeGen/templates/Tests.cs: + Start of a very small infrastructure to use tests from + rotor/mono with Cecil. + + * Mono.Cecil/IMethod.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/CodeWriter.cs: + Add support for the very special case ldarg 0. + Patch idea by Vladislav Spivak <spivak@mainsoft.com> + +2006-03-07 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/ImageReader.cs + Mono.Cecil/AssemblyFactory.cs + Mono.Cecil/StructureReader.cs + Mono.Cecil.Binary/Image.cs + Mono.Cecil.Binary/ImageReader.cs: + Allow users to get a loaded image using + Image.GetImage as they have no access to + the ImageReader. + +2006-03-06 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Signatures/SignatureReader.cs: + Fix array reading in custom attributes. + +2006-03-06 Joshua Tauberer <tauberer@for.net> + + * Mono.Cecil/TypeAttributes.cs: Fixed typo + in value for Abstract. + +2006-02-27 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/IndexedCollectionImplem.cs + CodeGen/templates/IIndexedCollection.cs + Mono.Cecil.Cil/InstructionCollection.cs + Mono.Cecil.Cil/IInstructionCollection.cs: + Small API fix, prevent the user from not using + the CilWorker. + + * Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/Label.cs: + Remove Label. + + * Mono.Cecil/ReflectionReader.cs: + Fix typo. + +2006-02-20 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Signatures/SignatureWriter.cs: + Fix a bug when a value is null in a custom attribute. + +2006-02-20 Sebastien Pouliot <sebastien@ximian.com> + + * Mono.Cecil.Metadata/MetadataWriter.cs: + Fix GetStrongNameSignatureSize to handle the ECMA pseudo-key. + +2006-02-07 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyInfos.cs: + Tag this version 0.3, as users are happy with it. + +2006-01-26 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/CustomAttribute.cs: + Fix cloning of non readable attributes. + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Signatures/MethodRefSig.cs + Mono.Cecil.Signatures/SignatureWriter.cs + Mono.Cecil.Signatures/MethodDefSig.cs: + Work on generics. + + * Mono.Cecil/ArrayType.cs + Mono.Cecil/ReferenceType.cs + Mono.Cecil/PointerType.cs: + Fix names of typespecs. + + * Mono.Cecil/TypeReferenceCollection.cs + Mono.Cecil/ExternTypeCollection.cs + CodeGen/templates/NamedCollectionImplem.cs: + Allow multiple key by names in type references. + +2006-01-25 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyFactory.cs: + Don't trap exceptions. + + * Mono.Cecil/GenericParameter.cs + Mono.Cecil/IMethod.cs + Mono.Cecil/GenericInstanceType.cs + Mono.Cecil/TypeReference.cs + Mono.Cecil/GenericInstanceMethod.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/IGenericArgumentCollection.cs + Mono.Cecil/ITypeReference.cs + Mono.Cecil/IGenericInstance.cs + Mono.Cecil/GenericArgumentCollection.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/MethodReference.cs + Mono.Cecil/ITypeDefinition.cs + Mono.Cecil/IGenericArgumentProvider.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/GenericContext.cs + CodeGen/cecil.xml: + Clean the generic api. This is not stable yet. + +2006-01-24 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ArrayType.cs: + Bug reported by Vladislav Spivak (spivak@mainsoft.com). + Fix a bug in array handling. + * Mono.Cecil/ConstructorCollection.cs + CodeGen/templates/IndexedCollectionImplem.cs: + Bug reported by Oleg Varchovsky (olegv@mainsoft.com). + Fix the lookup of constructors. + +2006-01-19 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyName.cs: + Fix computation of public key token. + +2006-01-18 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil.Metadata/MetadataToken.cs: + Add an use an ToUInt method and use it. + CodeGen/templates/DebugHeader.cs + Mono.Cecil.Binary/DebugHeader.cs: + Fix the size of the debug header. + + * Mono.Cecil/ModuleReference.cs + Mono.Cecil/AssemblyName.cs + Mono.Cecil/StructureReader.cs + Mono.Cecil/IMetadataScope.cs: + Make IMetadataScope implement IMetadataTokenProvider. + * Mono.Cecil/ReflectionWriter.cs: + Fix a typo when saving nested type refs. + +2006-01-17 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ArrayType.cs + Mono.Cecil/ArrayDimension.cs + Mono.Cecil/ReflectionWriter.cs: + End arrays support. + +2006-01-03 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/GenericParameter.cs + Mono.Cecil/ReflectionHelper.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/GenericContext.cs: + Work on generics. + +2005-12-31 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionHelper.cs: + Fix import of type specs. + +2005-12-30 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/ImageReader.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Binary/Image.cs + Mono.Cecil.Binary/ImageReader.cs: + Add support to assemblies where the metadata is defined + outside of the text section. (c++/cli /safe for instance) + +2005-12-23 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyInfo.cs: + Version 0.2.2.2 devel. + + * Mono.Cecil/AssemblyInfo.cs: + Version 0.2 to be released. + + * Mono.Cecil/ReflectionWriter.cs: + IGenericInstance are typespecs as well. + + * Mono.Cecil/ArrayType.cs: + Add a single dimension in the default ctor. + * Mono.Cecil/ReflectionReader.cs: + Don't manually add the default dimension as it's done + int the array type ctor. + * Mono.Cecil/ReflectionHelper.cs: + Import type specs. + +2005-12-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionWriter: + Write pinvoke infos as well. + + * Mono.Cecil/ReflectionReader.cs: + Unsure that primitive value types are viewed as + value types. + + * CodeGen/templates/Section.cs + CodeGen/templates/ImageReader.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Binary/Image.cs + Mono.Cecil.Binary/Section.cs + Mono.Cecil.Binary/ImageReader.cs: + Simplify the way you read binary data whithin + high level layer. + + * Mono.Cecil.Cil/CodeReader.cs: + Make helper methods public static. + * Mono.Cecil/ReflectionReader.cs: + Don't try to get the entry point method + if it don't point on a valid method RID. + + * CodeGen/templates/NamedCollectionImplem.cs + Mono.Cecil/ExternTypeCollection.cs + Mono.Cecil/TypeDefinitionCollection.cs + Mono.Cecil/TypeReferenceCollection.cs: + Don't add existing values. + + * Mono.Cecil/ModuleDefinition.cs: + Protect import from null refs. + +2005-12-21 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/StructureWriter.cs: + Don't increment pdb age. Not Cecil's job. + + * Mono.Cecil.Cil/ICilWorker.cs + Mono.Cecil.Cil/CilWorker.cs: + Add a new replace method. + +2005-12-20 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/StructureWriter.cs: + Ensure every assembly reference is processed. + + * Mono.Cecil/ReflectionHelper.cs: + Don't assume the cache is magically loaded. + Aka: most stupid bug of the year. + +2005-12-19 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/DebugHeader.cs + Mono.Cecil.Binary/DebugHeader.cs + Mono.Cecil.Binary/DebugStoreType.cs: + New files to store debug header infos. + * Mono.Cecil.dll.sources: updated + * CodeGen/cecil.xml + CodeGen/cecil-gen.rb + Mono.Cecil/StructureWriter.cs + Mono.Cecil.Binary/IBinaryVisitor.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/Image.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil.Binary/BaseImageVisitor.cs + Mono.Cecil.Binary/ImageReader.cs + Mono.Cecil.Metadata/MetadataWriter.cs: + Read and write debug header. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Binary/ImageWriter.cs: + Revert revision 54409. + +2005-12-14 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/ICilWorker.cs + Mono.Cecil.Cil/CilWorker.cs: + Add a remove method. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Binary/ImageWriter.cs: + Don't allocate potential big arrays here. + +2005-12-13 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/MetadataWriter.cs: + Set the correct version for .net 2 assemblies. + Correctly write embedded resources. + Fix #76963. + +2005-12-03 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/MethodSpecification.cs: + Override the declaring type and the name property to + match the inner method. + * Mono.Cecil/GenericInstanceType.cs: + Correctly set the FullName. + * Mono.Cecil/GenericInstanceMethod.cs: + Style. + +2005-12-02 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/TypeDefinition.cs: + Fix interface import. Patch by Thomas Gil. + +2005-11-24 Jb Evain <jbevain@gmail.com> + + * CodeGen/cecil-gen.rb + CodeGen/templates/MetadataTableReader.cs + CodeGen/templates/PEFileHeader.cs + CodeGen/templates/CLIHeader.cs + CodeGen/templates/PEOptionalHeader.cs + CodeGen/templates/Table.cs + CodeGen/templates/MetadataRowReader.cs + CodeGen/templates/OpCodes.cs + CodeGen/templates/Section.cs + CodeGen/templates/ImageReader.cs: + Update the codegen engine so that everyone can run it + without having to install a dependency (eruby). + + * Mono.Cecil.Metadata/Utilities.cs: re-codegenerated. + +2005-11-23 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IGenericArgumentProvider.cs + Style. + * CodeGen/cecil.xml: + Mirror Martin's change in the codegen engine. + +2005-11-23 Martin Baulig <martin@ximian.com> + + Generics API changes: + TypeReference and MethodReference now contain a + `GenericArguments' property (of type `GenericArgumentCollection') + and `GenericParameters' is moved into TypeDefinition/MethodDefinition. + + * Mono.Cecil/IGenericArgumentProvider.cs: New file. + (IGenericArgumentProvider): New public interface. + + * Mono.Cecil/IGenericArgumentCollection.cs + (IGenericArgumentCollection.Container): Changed type from + `IGenericInstance' -> `IGenericArgumentProvider'. + + * Mono.Cecil/IGenericInstance.cs + (IGenericInstance.Arguments): Renamed to `GenericArguments'. + + * Mono.Cecil/ITypeReference.cs + (ITypeReference): Implement `IGenericArgumentProvider' instead of + `IGenericParameterProvider'. + + * Mono.Cecil/ITypeDefinition.cs + (ITypeDefinition): Implement `IGenericParameterProvider'. + + * Mono.Cecil/IMethod.cs + (IMethodReference): Implement `IGenericArgumentProvider' instead of + `IGenericParameterProvider'. + (IMethodDefinition): Implement `IGenericParameterProvider'. + + * Mono.Cecil/TypeReference.cs + (TypeReference.GenericParameters): Removed. + (TypeReference.GenericArguments): New public property. + + * Mono.Cecil/TypeDefinition.cs + (TypeDefinition.GenericParameters): New public property. + (TypeDefinition.OnGenericParameterAdded): If a generic parameter + is added, also add it to the `GenericArguments'. + + * Mono.Cecil/MethodReference.cs + (MethodReference.GenericParameters): Removed. + (MethodReference.GenericArguments): New public property. + + * Mono.Cecil/MethodDefinition.cs + (MethodDefinition.GenericParameters): New public property. + (MethodDefinition.OnGenericParameterAdded): If a generic parameter + is added, also add it to the `GenericArguments'. + + * Mono.Cecil/GenericInstanceType.cs + (GenericInstanceType): Removed the `m_arguments' field; we now + inherit the `GenericArguments' property from `TypeReference'. + + * Mono.Cecil/GenericInstanceMethod.cs + (GenericInstanceMethod): Removed the `m_arguments' field; we now + inherit the `GenericArguments' property from `MethodReference'. + + * Mono.Cecil/GenericContext.cs + (GenericContext): We now operate on type/method references and not + definitions. + (GenericContext.Type): Changed type to `TypeReference'. + (GenericContext.Method): Changed type to `MethodReference'. + +2005-11-23 Martin Baulig <martin@ximian.com> + + * Mono.Cecil.Metadata/TokenType.cs: Added `GenericParam'. + + * Mono.Cecil.Metadata/Utilities.cs + (GetMetadataToken): In `case CodedIndex.HasCustomAttribute', add + `TokenType.GenericParam'. + +2005-11-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IMethodDefinitionCollection.cs + Mono.Cecil/MethodDefinitionCollection.cs + CodeGen/templates/IndexedCollectionImplem.cs + CodeGen/templates/IIndexedCollection.cs: + Add a new search method. + * CodeGen/templates/NamedCollectionImplem.cs + Mono.Cecil/TypeReferenceCollection.cs + Mono.Cecil/ExternTypeCollection.cs + Mono.Cecil/TypeDefinitionCollection.cs: + Style. + +2005-11-13 Rodrigo B. de Oliveira <rodrigobamboo@gmail.com> + * Mono.Cecil/ReflectionReader.cs + Fix for NRE when reading assemblies with a field initializer + pointing to a data section + (TestCases/Regression/OddInt64Initializer.dll). + +2005-11-11 Sebastien Pouliot <sebastien@ximian.com> + + * Mono.Cecil.Metadata/MetadataWriter.cs + Add support for different strongname key size (between 384 + and 16384 bits) as now supported in fx 2.0. Default is still + 1024 bits. + +2005-11-10 Rodrigo B. de Oliveira <rodrigobamboo@gmail.com> + * Mono.Cecil/CompactFrameworkCompatibility.cs + Mono.Cecil/SecurityDeclarationReader.cs + Mono.Cecil/TypeReferenceCollection.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/AssemblyFactory.cs + Mono.Cecil/AssemblyName.cs + Mono.Cecil/ExternTypeCollection.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/TypeDefinitionCollection.cs + CodeGen/templates/NamedCollectionImplem.cs + CodeGen/templates/ImageReader.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/CultureUtils.cs + Mono.Xml/SecurityParser.cs + Mono.Xml/SmallXmlParser.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Binary/ImageReader.cs + cecil.build + Implement support for compiling on the CompactFramework + +2005-11-08 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/GenericInstanceType.cs + Mono.Cecil/TypeReference.cs: + Fix a regression with 2.0 assemblies. + +2005-11-03 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/CallSite.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/ICallSite.cs + Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.dll.sources: + Implement support for calli opcodes reading. + +2005-11-01 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/FunctionPointerType.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Work on function pointers. + + * Mono.Cecil/AssemblyInfo.cs: + Increase Cecil SVN version. + + * Mono.Cecil/ArrayType.cs + Mono.Cecil/MethodSpecification.cs + Mono.Cecil/TypeSpecification.cs + Mono.Cecil/IMethodSpecification.cs + Mono.Cecil/GenericInstanceType.cs + Mono.Cecil/IGenericInstanceType.cs + Mono.Cecil/GenericInstanceMethod.cs + Mono.Cecil/IModifierType.cs + Mono.Cecil/IPinnedType.cs + Mono.Cecil/ReferenceType.cs + Mono.Cecil/IGenericInstanceMethod.cs + Mono.Cecil/PinnedType.cs + Mono.Cecil/PointerType.cs + Mono.Cecil/IPointerType.cs + Mono.Cecil/IReferenceType.cs + Mono.Cecil/IArrayType.cs + Mono.Cecil/ITypeSpecification.cs + Mono.Cecil/Modifiers.cs + Mono.Cecil.dll.sources: + Uniformize the specification model. + +2005-10-31 Jb Evain <jbevain@gmail.com> + + * AUTHORS, + NEWS, + README, + TODO, + Mono.Cecil/AssemblyInfo.cs: + Cecil 0.1 release. + + * Mono.Cecil/ReflectionReader.cs: + Force value type property on known core types. + +2005-10-28 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/TypeReference.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/ReflectionWriter.cs: + Uniformize the API. + + * Mono.Cecil.Signatures/SignatureWriter.cs: + Correct a bug in strings encoding in custom attributes. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil/StructureWriter.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil.Binary/ImageWriter.cs: + Implement a big of public key management, + here we reserve space for the strong name + signature if needed. + + * Mono.Cecil/StructureWriter.cs + Mono.Cecil/StructureReader.cs: + Disable public key writing until + it is implemented. + + * Mono.Cecil/GenericParameter.cs + Mono.Cecil/TypeReference.cs + Mono.Cecil/MethodReference.cs: + Work on generics writing api. + * Mono.Cecil/ReflectionReader.cs: + Fix a bug when defining a fresh assembly. + + * Mono.Cecil/GenericInstanceType.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/IGenericParameterProvider.cs + Mono.Cecil.Signatures/Var.cs + Mono.Cecil.Signatures/MVar.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs + Mono.Cecil.Cil/CodeWriter.cs: + Work on generics writing. + +2005-10-27 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/CilWorker.cs + Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil.Cil/OpCode.cs: + Override op == and != on opcodes. + + * Mono.Cecil/FieldDefinition.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/EventDefinition.cs + Mono.Cecil/PropertyDefinition.cs: + Fix setters working on attributes. + + * Mono.Cecil.Cil/CodeWriter.cs: + Compute max stack before writing method. + + * Mono.Cecil/GenericContext.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Work on generics support. + + * CodeGen/cecil.xml + Mono.Cecil/ISecurityDeclarationCollection.cs + Mono.Cecil/SecurityDeclarationCollection.cs: + Remove the security declaration from the codegen. + +2005-10-27 Sebastien Pouliot <sebastien@ximian.com> + + * Mono.Cecil\SecurityDeclaration.cs + Copy the permission set when cloning. + * Mono.Cecil\SecurityDeclarationCollection.cs + Ajusted to use an Hashtable, to Union permission sets on + the same action and to set/unset HasSecurity when needed. + * Mono.Cecil\ModuleDefinition.cs: + Added TODO (remainder) for complete 2.0 format support. + * Mono.Cecil\ReflectionWriter.cs: + Move MetadataToken finding outside the loop. + * Mono.Cecil\ISecurityDeclarationCollection.cs: + Adjust interface. + +2005-10-27 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/TypeDefinition.cs + Mono.Cecil/MethodDefinition.cs: + Add generics parameters in visitor path. + + * Mono.Cecil/GenericParamAttributes.cs: + Add new constraints flags. + +2005-10-22 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/GenericParameter.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/IGenericParameter.cs + Mono.Cecil/AggressiveReflectionReader.cs + Mono.Cecil/GenericContext.cs: + Support generic parameters constraints. + +2005-10-21 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/FieldDefinition.cs + Mono.Cecil/CustomAttribute.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/SecurityDeclaration.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/EventDefinition.cs + Mono.Cecil/ParameterDefinition.cs + Mono.Cecil/PropertyDefinition.cs: + Implement ICloneable. + + * Mono.Cecil/IAssemblyDefinition.cs: + Mirror changes on asm kind. + * Mono.Cecil/StructureReader.cs: + Fix asm kind detection. + + * Mono.Cecil/StructureWriter.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/ReflectionWriter.cs: + Fix regressions. + * Mono.Cecil.Cil/MethodBody.cs: + Fix method cloning. + + * CodeGen/templates/MetadataTableReader.cs + Mono.Cecil.Metadata/MetadataTableReader.cs + Mono.Cecil.Metadata/MetadataReader.cs: + Add helpers for reading. + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/AggressiveReflectionReader.cs + Mono.Cecil/GenericContext.cs: + Working on generic parameters reading. + Still have troubles reading a 2.0 corlib. + + * Mono.Cecil/IHasMarshalSpec.cs: + API fix. + + * Mono.Cecil/ParameterDefinition.cs + Mono.Cecil.Cil/VariableDefinition.cs: + Override ToString. + +2005-10-20 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/CodeReader.cs + Mono.Cecil.Cil/CodeWriter.cs + Mono.Cecil.Cil/ICilWorker.cs + Mono.Cecil.Cil/CilWorker.cs: + ShortInlineI operands are signed. + Spotted by Rodrigo B. de Oliveira. + + * CodeGen/templates/OpCodes.cs + Mono.Cecil.Cil/OpCodes.cs: + Add 2.0 opcodes. + + * Mono.Cecil/StructureWriter.cs + Mono.Cecil/AssemblyDefinition.cs + Mono.Cecil/AssemblyFactory.cs + Mono.Cecil/StructureReader.cs + Mono.Cecil/ReflectionWriter.cs: + Handle the assembly kind in a smoothie way. + +2005-10-19 Sebastien Pouliot <sebastien@ximian.com> + + * Mono.Cecil/AssemblyDefinition.cs: Added an override for ToString to + ease debugging. + * Mono.Cecil/ModuleDefinition.cs: Make SecurityDeclaration works with + 2.0 assemblies. + * Mono.Cecil/ReflectionReader.cs: Modified BuildSecurityDeclaration + to use the new SecurityDeclarationReader (supporting both formats). + * Mono.Cecil/SecurityAction.cs: Removed actions that were "cutted" out + of 2.0 final. + * Mono.Cecil/SecurityDeclarationReader.cs: New. Handle both the 1.x + and 2.0 formats for reading declarative security. + +2005-10-18 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/GenericParameter.cs: + A little change before the fix. + + * Mono.Cecil/ReflectionHelper.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil.Cil/MethodBody.cs: + Implement method cloning. + + * Mono.Cecil/ModuleReference.cs + Mono.Cecil/FieldDefinition.cs + Mono.Cecil/TypeReference.cs + Mono.Cecil/ReflectionReader.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/EventDefinition.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/FieldReference.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/PropertyDefinition.cs + Mono.Cecil/AssemblyFactory.cs: + Small API change. + + * Mono.Cecil.Cil/CodeReader.cs: + Fix variables names. + + TODO before 0.1: + Fix generic parameters, + generic writing, + constructor changes (with S.Type and SR.*Info) + +2005-10-14 Jb Evain <jbevain@gmail.com> + + Work on generics support. + + * CodeGen/cecil.xml: new collections, coded indexes, opcodes. + + * Mono.Cecil/IGenericParameterCollection.cs + Mono.Cecil/GenericParameterCollection.cs + Mono.Cecil/IGenericArgumentCollection.cs + Mono.Cecil/GenericArgumentCollection.cs: + Added new collections. + + * Mono.Cecil.Metadata/Utilities.cs: updated. + * Mono.Cecil.Metadata/TokenType.cs: added MethodSpec. + + * Mono.Cecil/IGenericParameter.cs + Mono.Cecil/GenericParameter.cs + Mono.Cecil/IGenericParameterConstraints.cs + Mono.Cecil/GenericParameterConstraints.cs + Mono.Cecil/IGenericParameterProvider.cs + Mono.Cecil/IGenericInstance.cs + Mono.Cecil/IGenericInstanceType.cs + Mono.Cecil/GenericInstanceType.cs + Mono.Cecil/IGenericInstanceMethod.cs + Mono.Cecil/GenericInstanceMethod.cs: + Generics API elements. + + * Mono.Cecil/IMethod.cs + Mono.Cecil/MethodReference.cs + Mono.Cecil/ITypeReference.cs + Mono.Cecil/TypeReference.cs: + Implement IGenericParameterProvider + + * Mono.Cecil/ReflectionReader.cs + Mono.Cecil/IReflectionVisitor.cs + Mono.Cecil/BaseReflectionVisitor.cs + Mono.Cecil/StructureReader.cs + Mono.Cecil/AggressiveReflectionReader.cs + Mono.Cecil/MemberReference.cs: + Support for the new generics elements. + + * Mono.Cecil.Signatures/Var.cs + Mono.Cecil.Signatures/MVar.cs + Mono.Cecil.Signatures/GenericInstSignature.cs + Mono.Cecil.Signatures/GenericInst.cs: + Added file header. + + * Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/GenericInstSignature.cs + Mono.Cecil.Signatures/MethodDefSig.cs + Mono.Cecil.Signatures/GenericInst.cs + Mono.Cecil.Signatures/MethodSpec.cs + Mono.Cecil/MethodCallingConvention.cs + Mono.Cecil.Cil/CodeReader.cs: + Added support for generic signatures. + + * Mono.Cecil.Cil/OpCodes.cs: + Add consrained. opcode. + + * Mono.Cecil.dll.sources: + Updated. + + Known problems: !!parameters + +2005-10-13 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionHelper.cs + Mono.Cecil/FieldDefinition.cs + Mono.Cecil/CustomAttribute.cs + Mono.Cecil/MethodReturnType.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/SecurityDeclaration.cs + Mono.Cecil/MethodDefinition.cs + Mono.Cecil/EventDefinition.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/ParameterDefinition.cs + Mono.Cecil/IMethodReturnType.cs + Mono.Cecil/PropertyDefinition.cs + Mono.Cecil.Cil/MethodBody.cs: + Work on the import. + * Mono.Cecil/ITypeParameterType.cs + Mono.Cecil/TypeParameterType.cs: + Correct the interface. + +2005-10-12 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/EventDefinition.cs + Mono.Cecil/TypeDefinition.cs + Mono.Cecil/ModuleDefinition.cs + Mono.Cecil/ReflectionWriter.cs + Mono.Cecil/PropertyDefinition.cs: + Small fixes. + +2005-09-16 Martin Baulig <martin@ximian.com> + + Added generics support to Cecil. + + * Mono.Cecil/IGenericInstType.cs: New file. + * Mono.Cecil/ITypeParameterType.cs: New file. + * Mono.Cecil/IMethodTypeParameterType.cs: New file. + + * Mono.Cecil.Metadata/ElementType.cs + (ElementType): Added `Var', `MVar' and `GenericInst'. + + * Mono.Cecil.Metadata/Utilities.cs + (Utilities.GetMetadataToken): .NET 2.0 also uses TypeDef's in the + MemberRefParent. + + * Mono.Cecil/GenericInstType.cs: New file. + * Mono.Cecil/MethodTypeParameterType.cs: New file. + * Mono.Cecil/TypeParameterType.cs: New file. + + * Mono.Cecil.Signatures/Var.cs: New file. + * Mono.Cecil.Signatures/MVar.cs: New file. + * Mono.Cecil.Signatures/GenericInst.cs: New file. + * Mono.Cecil.Signatures/GenericInstSignature.cs: New file. + + * Mono.Cecil/ReflectionReader.cs + (ReflectionReader.GetTypeRefFromSig): Add the new types. + + * Mono.Cecil.Signatures/SignatureReader.cs + (SignatureReader.ReadType): Add the new types. + +2005-10-06 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ReflectionHelper.cs + Mono.Cecil/ModuleDefinition.cs: + Fix a bug in type importing. + +2005-10-06 Jb Evain <jbevain@gmail.com> + + * Hopefully, this is the last API change before the release of Cecil 0.1. + Mono.Cecil.Implem has been moved to Mono.Cecil. The interfaces where + very convenient for a reading API, it was far less convenient for a + modification and writing one. The modification API still needs some work, + but this should be easier this way. + +2005-09-27 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/MetadataReader.cs: + Fix resources reading. + + * Mono.Cecil.Implem/StructureWriter.cs: + Correctly set the offset of resources in the manifest. + * Mono.Cecil.Implem/StructureFactories.cs: + Use correct overrides when creating assembly references. + * Mono.Cecil.Implem/ReflectionFactories: + Correctly create type references. + +2005-09-06 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IReflectionFactories.cs + Mono.Cecil.Implem/ReflectionFactories.cs: + Allow the creation of reference types for methods + parameters and return types. + * Mono.Cecil.Cil/ICilWorker.cs + Mono.Cecil.Implem/CilWorker.cs + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/CodeWriter.cs: + Global fix on the handling of parameters in instructions. + * Mono.Cecil.Implem/AssemblyName.cs: + Correcty write the version of an assembly fullname. + Spotted by Bruno Cabral. + * Mono.Cecil.Implem/TypeDefinition.cs: + Set the declaring type of a nested type on add. + * Mono.Cecil.Implem/CustomAttribute.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Signatures/CustomAttrib.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Global fix on custom attribute handling. Some + custom attribute (containing enums) blobs can not be + decoded. + +2005-09-04 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/Instruction.cs: + Add the setter for IInstruction::OpCode. + +2005-09-02 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ICustomAttribute.cs + Mono.Cecil.Implem/ReflectionFactories.cs + Mono.Cecil.Implem/CustomAttribute.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Prepare the work on custom attributes. + * Mono.Cecil.Cil/IInstruction.cs: + Let users modify the content of an instruction. + * Mono.Cecil.Implem/StructureReader.cs: + Do not try to read 2.0 assemblies. + +2005-08-28 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Metadata/MetadataWriter.cs: + Write the fields initial value back. + As of this revision, a round tripped mcs + can compile Cecil. + + * Mono.Cecil.Implem/ReflectionWriter.cs: + Emit things in proper order. + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/CodeWriter.cs: + Correct bug with InlineVar opcodes. + Emit fat body if maxstack is set. + + * Mono.Cecil.Implem/CodeWriter.cs: + Handle null tokens. + Mono.Cecil.Metadata/MetadataWriter.cs: + Allow one empty string in the userstring heap. + + * Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs: + Strings constant are unicode. + + * Mono.Cecil/LoadingType.cs + Mono.Cecil/AssemblyFactory.cs + CodeGen/templates/IndexedCollectionImplem.cs + CodeGen/templates/LzIndexedCollectionImplem.cs + CodeGen/cecil.xml + Mono.Cecil.Implem/InterfaceCollection.cs + Mono.Cecil.Implem/ILazyLoadable.cs + Mono.Cecil.Implem/ExternTypeCollection.cs + Mono.Cecil.Implem/SecurityDeclarationCollection.cs + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/OverrideCollection.cs + Mono.Cecil.Implem/EventDefinitionCollection.cs + Mono.Cecil.Implem/FieldDefinitionCollection.cs + Mono.Cecil.Implem/PropertyDefinitionCollection.cs + Mono.Cecil.Implem/CustomAttributeCollection.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/EventDefinition.cs + Mono.Cecil.Implem/FieldDefinition.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/ReflectionController.cs + Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/AssemblyDefinition.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Implem/MethodDefinitionCollection.cs + Mono.Cecil.Implem/LazyReflectionReader.cs + Mono.Cecil.Implem/ParameterDefinition.cs + Mono.Cecil.Implem/PropertyDefinition.cs + Mono.Cecil.Implem/ConstructorCollection.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Get rid of the complexity introduced by the + internal lazy loading. + + * Mono.Cecil.Implem/EventDefinition.cs + Mono.Cecil.Implem/PropertyDefinition.cs: + Fix the behavior of .ToString (). + +2005-08-27 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/ReflectionWriter.cs: + Write back custom attributes of modules and assemblies + as well as their security declaration. + * Mono.Cecil.Implem/CodeWriter.cs: + Fix branches computation. + Mono.Cecil.Signatures/SignatureReader.cs: + Disable custom attribute reading cache. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Binary/ImageWriter.cs: + Compute relocations. + * Mono.Cecil.Implem/ReflectionFactories.cs: + Blah. + + * Mono.Cecil.Implem/TablesComparer.cs + Mono.Cecil.Implem/ReflectionWriter.cs: + Sort all tables that need to be sorted. + + * Mono.Cecil.Implem/CodeReader.cs: + Oops. Add fat exception handlers to the method body. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Binary/ImageWriter.cs: + Correct a few bugs: relocations now works. + Encode enums in custom attributes. + Compute memberrefs tokens before visitings types. + + * Mono.Cecil.Implem/FieldDefinition.cs: + Correct a bug that causes null ref due to + the new api. + * Mono.Cecil.Signatures/SignatureWriter.cs: + Implement a very little more custom attributes + writing. + +2005-08-26 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IMemberReferenceCollection.cs + Mono.Cecil/IReflectionVisitor.cs + Mono.Cecil/IReflectionFactories.cs + Mono.Cecil/BaseReflectionVisitor.cs + Mono.Cecil/IModuleDefinition.cs + CodeGen/cecil.xml + Mono.Cecil.Implem/ReflectionFactories.cs + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/MemberReferenceCollection.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/ParameterDefinition.cs: + Handle member references nicely. + + * Mono.Cecil/ICustomAttributeProvider.cs + Mono.Cecil/IModuleDefinitionCollection.cs + Mono.Cecil/IReflectionStructureFactories.cs + Mono.Cecil/IInterfaceCollection.cs + Mono.Cecil/IMethod.cs + Mono.Cecil/IReflectionFactories.cs + Mono.Cecil/INestedTypeCollection.cs + Mono.Cecil/ITypeReferenceCollection.cs + Mono.Cecil/IExternTypeCollection.cs + Mono.Cecil/IAssemblyDefinition.cs + Mono.Cecil/ITypeDefinition.cs + Mono.Cecil/ICustomAttribute.cs + Mono.Cecil/IArrayDimensionCollection.cs + Mono.Cecil/TypeFactory.cs + Mono.Cecil/IConstructorCollection.cs + Mono.Cecil/IHasSecurity.cs + Mono.Cecil/IMethodDefinitionCollection.cs + Mono.Cecil/IPropertyDefinitionCollection.cs + Mono.Cecil/IAssemblyNameReferenceCollection.cs + Mono.Cecil/IModuleReferenceCollection.cs + Mono.Cecil/IArrayType.cs + Mono.Cecil/ISecurityDeclarationCollection.cs + Mono.Cecil/IModuleDefinition.cs + Mono.Cecil/IResourceCollection.cs + Mono.Cecil/IParameterDefinitionCollection.cs + Mono.Cecil/IEventDefinitionCollection.cs + Mono.Cecil/ITypeDefinitionCollection.cs + Mono.Cecil/IFieldDefinitionCollection.cs + Mono.Cecil/ICustomAttributeCollection.cs + Mono.Cecil/ISecurityDeclaration.cs + Mono.Cecil/IOverrideCollection.cs + Mono.Cecil/ITypeReference.cs + Mono.Cecil.Cil/IExceptionHandlerCollection.cs + Mono.Cecil.Cil/IVariableDefinitionCollection.cs + Mono.Cecil.Cil/IInstructionCollection.cs + Mono.Cecil.Cil/IMethodBody.cs + CodeGen/cecil-gen-types.rb + CodeGen/templates/ImageWriter.cs + CodeGen/templates/IndexedCollectionImplem.cs + CodeGen/templates/NamedCollectionImplem.cs + CodeGen/templates/IIndexedCollection.cs + CodeGen/templates/LzIndexedCollectionImplem.cs + CodeGen/templates/INamedCollection.cs + CodeGen/templates/LzNamedCollectionImplem.cs + Mono.Cecil.Implem/InterfaceCollection.cs + Mono.Cecil.Implem/AssemblyLinkedResource.cs + Mono.Cecil.Implem/ModuleReferenceCollection.cs + Mono.Cecil.Implem/ExternTypeCollection.cs + Mono.Cecil.Implem/SecurityDeclarationCollection.cs + Mono.Cecil.Implem/ReflectionFactories.cs + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/OverrideCollection.cs + Mono.Cecil.Implem/ArrayDimensionCollection.cs + Mono.Cecil.Implem/EmbeddedResource.cs + Mono.Cecil.Implem/CilWorker.cs + Mono.Cecil.Implem/ParameterDefinitionCollection.cs + Mono.Cecil.Implem/EventDefinitionCollection.cs + Mono.Cecil.Implem/FieldDefinitionCollection.cs + Mono.Cecil.Implem/PropertyDefinitionCollection.cs + Mono.Cecil.Implem/ModuleDefinitionCollection.cs + Mono.Cecil.Implem/CustomAttributeCollection.cs + Mono.Cecil.Implem/VariableDefinitionCollection.cs + Mono.Cecil.Implem/TypeReferenceCollection.cs + Mono.Cecil.Implem/MemberDefinition.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/FunctionPointerType.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/EventDefinition.cs + Mono.Cecil.Implem/FieldDefinition.cs + Mono.Cecil.Implem/InstructionCollection.cs + Mono.Cecil.Implem/VariableDefinition.cs + Mono.Cecil.Implem/CustomAttribute.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/MethodReference.cs + Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/StructureFactories.cs + Mono.Cecil.Implem/TypeDefinitionCollection.cs + Mono.Cecil.Implem/AssemblyNameReferenceCollection.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/MethodReturnType.cs + Mono.Cecil.Implem/MemberReference.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/Resource.cs + Mono.Cecil.Implem/AssemblyDefinition.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/FieldReference.cs + Mono.Cecil.Implem/MethodDefinitionCollection.cs + Mono.Cecil.Implem/LazyReflectionReader.cs + Mono.Cecil.Implem/LinkedResource.cs + Mono.Cecil.Implem/ParameterDefinition.cs + Mono.Cecil.Implem/PropertyDefinition.cs + Mono.Cecil.Implem/MethodBody.cs + Mono.Cecil.Implem/NestedTypeCollection.cs + Mono.Cecil.Implem/ConstructorCollection.cs + Mono.Cecil.Implem/ResourceCollection.cs + Mono.Cecil.Implem/ExceptionHandlerCollection.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/ImageReader.cs: + Fix the writing API before the API freeze. Few things + are not implemented, see todos. + +2005-08-20 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ITypeDefinition.cs + Mono.Cecil/IModuleDefinition.cs + Mono.Cecil/ITypeReference.cs + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs: + Add way to know if a type reference is a + value type or not. This hack saved my life. + + * Mono.Cecil.Implem/CodeWriter.cs: + Fix typespec emitting. + + * Mono.Cecil/IReflectionVisitor.cs + Mono.Cecil/IMethod.cs + Mono.Cecil/BaseReflectionVisitor.cs + Mono.Cecil/ITypeDefinition.cs + Mono.Cecil/IConstructorCollection.cs + CodeGen/cecil.xml + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/ConstructorCollection.cs: + Support constructors decently. + + * CodeGen/templates/Utilities.cs + Mono.Cecil.Metadata/Utilities.cs: + Return a null token if the rid of a md token + is 0. Fix the crash when Mono try to read + assemblies emitted by Cecil. + +2005-08-19 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/ReflectionWriter.cs: + Set the RVA of a method only if it can + have a body. + * Mono.Cecil.Signatures/SignatureReader.cs: + Remove debugging stuff. + + * Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Fix custom marshaller reading. + + * CodeGen/templates/NamedCollectionImplem.cs + CodeGen/templates/LzNamedCollectionImplem.cs + Mono.Cecil.Implem/ExternTypeCollection.cs + Mono.Cecil.Implem/TypeReferenceCollection.cs + Mono.Cecil.Implem/TypeDefinitionCollection.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TablesComparer.cs + Mono.Cecil.Implem/Constants.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Correct bugs in type* tables generations. + + * Mono.Cecil/IModuleDefinitionCollection.cs + Mono.Cecil/IInterfaceCollection.cs + Mono.Cecil/INestedTypeCollection.cs + Mono.Cecil/ITypeReferenceCollection.cs + Mono.Cecil/IExternTypeCollection.cs + Mono.Cecil/IArrayDimensionCollection.cs + Mono.Cecil/IMethodDefinitionCollection.cs + Mono.Cecil/IPropertyDefinitionCollection.cs + Mono.Cecil/IAssemblyNameReferenceCollection.cs + Mono.Cecil/IModuleReferenceCollection.cs + Mono.Cecil/ISecurityDeclarationCollection.cs + Mono.Cecil/IResourceCollection.cs + Mono.Cecil/IParameterDefinitionCollection.cs + Mono.Cecil/IEventDefinitionCollection.cs + Mono.Cecil/ITypeDefinitionCollection.cs + Mono.Cecil/IFieldDefinitionCollection.cs + Mono.Cecil/ICustomAttributeCollection.cs + Mono.Cecil/IOverrideCollection.cs + Mono.Cecil.Cil/IExceptionHandlerCollection.cs + Mono.Cecil.Cil/IVariableDefinitionCollection.cs + Mono.Cecil.Cil/IInstructionCollection.cs + CodeGen/templates/IIndexedCollection.cs + CodeGen/templates/INamedCollection.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Binary/SubSystem.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + On going change to the writing api. Not setter allowed on + collections. Work on custom attribute encoding. Remove + the Flags on Subsystem. + + * Mono.Cecil.dll.sources + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/TablesComparer.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Fix the build. + Stop to prefix typeref by the scope. + Cecil will have buggy behaviour if it have to handle + two typeref with the same namespace+name, but for the + moment, let it like that. + + * Mono.Cecil/INestedTypeCollection.cs + Mono.Cecil/IModuleReference.cs + Mono.Cecil/ITypeReferenceCollection.cs + Mono.Cecil/IAssemblyName.cs + Mono.Cecil/IExternTypeCollection.cs + Mono.Cecil/IMetadataScope.cs + Mono.Cecil/IModuleDefinition.cs + Mono.Cecil/IResourceCollection.cs + Mono.Cecil/ITypeDefinitionCollection.cs + CodeGen/templates/NamedCollectionImplem.cs + CodeGen/templates/INamedCollection.cs + CodeGen/templates/LzNamedCollectionImplem.cs + CodeGen/cecil.xml + Mono.Cecil.Metadata/RowCollection.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/MetadataToken.cs + Mono.Cecil.Implem/TablesComparer.cs + Mono.Cecil.Implem/ExternTypeCollection.cs + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/TypeReferenceCollection.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/TypeDefinitionCollection.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Implem/Constants.cs + Mono.Cecil.Implem/NestedTypeCollection.cs + Mono.Cecil.Implem/ResourceCollection.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Correct some part of the API. + Correct tons of bugs in the writing layer. + +2005-08-17 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IField.cs + CodeGen/cecil.xml + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/FieldDefinition.cs + Mono.Cecil.Implem/BaseReflectionReader.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/IDetailReader.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Implem/LazyReflectionReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Work on the working layer. Implement field initial + data. Bugs. + +2005-08-16 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Signatures/SignatureReader.cs: + Implement local var sig writing. + + * Mono.Cecil.Implem/ArrayType.cs: + Style. + Mono.Cecil.Implem/ParameterDefinition.cs: + Correct a bug in module obtention. + Mono.Cecil.Signatures/SignatureReader.cs: + Correct a bug in arrays's signature reading. + + * Mono.Cecil.dll.sources + Mono.Cecil/IReflectionVisitor.cs + Mono.Cecil/IModuleDefinitionCollection.cs + Mono.Cecil/IInterfaceCollection.cs + Mono.Cecil/IProperty.cs + Mono.Cecil/BaseReflectionVisitor.cs + Mono.Cecil/INestedTypeCollection.cs + Mono.Cecil/ITypeReferenceCollection.cs + Mono.Cecil/IParameter.cs + Mono.Cecil/IExternTypeCollection.cs + Mono.Cecil/IField.cs + Mono.Cecil/IArrayDimensionCollection.cs + Mono.Cecil/IMethodDefinitionCollection.cs + Mono.Cecil/IPropertyDefinitionCollection.cs + Mono.Cecil/IAssemblyNameReferenceCollection.cs + Mono.Cecil/IModuleReferenceCollection.cs + Mono.Cecil/IHasConstant.cs + Mono.Cecil/ISecurityDeclarationCollection.cs + Mono.Cecil/IMetadataTokenProvider.cs + Mono.Cecil/IModuleDefinition.cs + Mono.Cecil/BaseStructureVisitor.cs + Mono.Cecil/IResourceCollection.cs + Mono.Cecil/IParameterDefinitionCollection.cs + Mono.Cecil/IEventDefinitionCollection.cs + Mono.Cecil/ITypeDefinitionCollection.cs + Mono.Cecil/IFieldDefinitionCollection.cs + Mono.Cecil/ICustomAttributeCollection.cs + Mono.Cecil/IOverrideCollection.cs + Mono.Cecil.Cil/IExceptionHandlerCollection.cs + Mono.Cecil.Cil/IVariableDefinitionCollection.cs + Mono.Cecil.Cil/IInstructionCollection.cs + CodeGen/cecil-gen.rb + CodeGen/cecil-gen-types.rb + CodeGen/templates/IndexedCollectionImplem.cs + CodeGen/templates/NamedCollectionImplem.cs + CodeGen/templates/IIndexedCollection.cs + CodeGen/templates/LzIndexedCollectionImplem.cs + CodeGen/templates/INamedCollection.cs + CodeGen/templates/LzNamedCollectionImplem.cs + CodeGen/cecil.xml + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Implem/InterfaceCollection.cs + Mono.Cecil.Implem/ModuleReferenceCollection.cs + Mono.Cecil.Implem/ExternTypeCollection.cs + Mono.Cecil.Implem/SecurityDeclarationCollection.cs + Mono.Cecil.Implem/OverrideCollection.cs + Mono.Cecil.Implem/ParameterDefinitionCollection.cs + Mono.Cecil.Implem/EventDefinitionCollection.cs + Mono.Cecil.Implem/FieldDefinitionCollection.cs + Mono.Cecil.Implem/PropertyDefinitionCollection.cs + Mono.Cecil.Implem/ModuleDefinitionCollection.cs + Mono.Cecil.Implem/CustomAttributeCollection.cs + Mono.Cecil.Implem/VariableDefinitionCollection.cs + Mono.Cecil.Implem/TypeReferenceCollection.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/EventDefinition.cs + Mono.Cecil.Implem/FieldDefinition.cs + Mono.Cecil.Implem/InstructionCollection.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/MethodReference.cs + Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/TypeDefinitionCollection.cs + Mono.Cecil.Implem/AssemblyNameReferenceCollection.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/MethodReturnType.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/AssemblyDefinition.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Implem/MethodDefinitionCollection.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Implem/LazyReflectionReader.cs + Mono.Cecil.Implem/ParameterDefinition.cs + Mono.Cecil.Implem/PropertyDefinition.cs + Mono.Cecil.Implem/NestedTypeCollection.cs + Mono.Cecil.Implem/ResourceCollection.cs + Mono.Cecil.Implem/ExceptionHandlerCollection.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Working on the writing layer. + Begin to fix brokens part of the API. + +2005-08-15 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/ITypeDefinition.cs + CodeGen/templates/MetadataTableReader.cs + CodeGen/templates/PEFileHeader.cs + CodeGen/templates/ImageWriter.cs + CodeGen/templates/CLIHeader.cs + CodeGen/templates/PEOptionalHeader.cs + CodeGen/templates/MetadataTableWriter.cs + CodeGen/templates/Table.cs + CodeGen/templates/MetadataRowReader.cs + CodeGen/templates/BaseMetadataVisitor.cs + CodeGen/templates/Section.cs + CodeGen/templates/MetadataRowWriter.cs + CodeGen/templates/ImageReader.cs + CodeGen/templates/IMetadataVisitor.cs + Mono.Cecil.Metadata/Assembly.cs + Mono.Cecil.Metadata/PropertyMap.cs + Mono.Cecil.Metadata/InterfaceImpl.cs + Mono.Cecil.Metadata/MetadataInitializer.cs + Mono.Cecil.Metadata/Constant.cs + Mono.Cecil.Metadata/MethodSpec.cs + Mono.Cecil.Metadata/BaseMetadataVisitor.cs + Mono.Cecil.Metadata/DeclSecurity.cs + Mono.Cecil.Metadata/TypeDef.cs + Mono.Cecil.Metadata/MethodImpl.cs + Mono.Cecil.Metadata/GenericParamConstraint.cs + Mono.Cecil.Metadata/NestedClass.cs + Mono.Cecil.Metadata/MetadataTableReader.cs + Mono.Cecil.Metadata/AssemblyRefProcessor.cs + Mono.Cecil.Metadata/AssemblyRef.cs + Mono.Cecil.Metadata/AssemblyRefOS.cs + Mono.Cecil.Metadata/Method.cs + Mono.Cecil.Metadata/RowCollection.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/StringsHeap.cs + Mono.Cecil.Metadata/MetadataRowReader.cs + Mono.Cecil.Metadata/ExportedType.cs + Mono.Cecil.Metadata/CustomAttribute.cs + Mono.Cecil.Metadata/Param.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/ClassLayout.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/BlobHeap.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/AssemblyOS.cs + Mono.Cecil.Metadata/ModuleRef.cs + Mono.Cecil.Metadata/MetadataRoot.cs + Mono.Cecil.Metadata/UserStringsHeap.cs + Mono.Cecil.Metadata/FieldMarshal.cs + Mono.Cecil.Metadata/GenericParam.cs + Mono.Cecil.Metadata/ImplMap.cs + Mono.Cecil.Metadata/TableCollection.cs + Mono.Cecil.Metadata/TablesHeap.cs + Mono.Cecil.Metadata/MetadataStreamCollection.cs + Mono.Cecil.Metadata/ManifestResource.cs + Mono.Cecil.Metadata/TypeRef.cs + Mono.Cecil.Metadata/AssemblyProcessor.cs + Mono.Cecil.Metadata/EventMap.cs + Mono.Cecil.Metadata/File.cs + Mono.Cecil.Metadata/Event.cs + Mono.Cecil.Metadata/FieldLayout.cs + Mono.Cecil.Metadata/Field.cs + Mono.Cecil.Metadata/Property.cs + Mono.Cecil.Metadata/Module.cs + Mono.Cecil.Metadata/GuidHeap.cs + Mono.Cecil.Metadata/MethodSemantics.cs + Mono.Cecil.Metadata/StandAloneSig.cs + Mono.Cecil.Metadata/MetadataStream.cs + Mono.Cecil.Metadata/FieldRVA.cs + Mono.Cecil.Metadata/TypeSpec.cs + Mono.Cecil.Metadata/MemberRef.cs + Mono.Cecil.Metadata/IMetadataVisitor.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Signatures/MethodRefSig.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/FieldSig.cs + Mono.Cecil.Signatures/PropertySig.cs + Mono.Cecil.Signatures/ISignatureVisitor.cs + Mono.Cecil.Signatures/SignatureWriter.cs + Mono.Cecil.Signatures/MethodDefSig.cs + Mono.Cecil.Signatures/LocalVarSig.cs + Mono.Cecil.Binary/PEFileHeader.cs + Mono.Cecil.Binary/IBinaryVisitor.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/CLIHeader.cs + Mono.Cecil.Binary/SectionCollection.cs + Mono.Cecil.Binary/Image.cs + Mono.Cecil.Binary/PEOptionalHeader.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil.Binary/Imports.cs + Mono.Cecil.Binary/BaseImageVisitor.cs + Mono.Cecil.Binary/DOSHeader.cs + Mono.Cecil.Binary/Section.cs + Mono.Cecil.Binary/ImageReader.cs: + Apply the new visitor model to the rest of Cecil. + + * Mono.Cecil/IReflectionVisitor.cs + Mono.Cecil/BaseReflectionVisitor.cs + Mono.Cecil/IReflectionStructureVisitor.cs + Mono.Cecil/BaseStructureVisitor.cs + Mono.Cecil.Cil/BaseCodeVisitor.cs + Mono.Cecil.Cil/ICodeVisitor.cs + CodeGen/cecil-gen.rb + CodeGen/cecil-gen-types.rb + CodeGen/templates/IndexedCollectionImplem.cs + CodeGen/templates/NamedCollectionImplem.cs + CodeGen/templates/LzIndexedCollectionImplem.cs + CodeGen/templates/LzNamedCollectionImplem.cs + CodeGen/cecil.xml + Mono.Cecil.Implem/InterfaceCollection.cs + Mono.Cecil.Implem/AssemblyLinkedResource.cs + Mono.Cecil.Implem/ModuleReferenceCollection.cs + Mono.Cecil.Implem/AssemblyName.cs + Mono.Cecil.Implem/Instruction.cs + Mono.Cecil.Implem/ExternTypeCollection.cs + Mono.Cecil.Implem/MarshalDesc.cs + Mono.Cecil.Implem/SecurityDeclarationCollection.cs + Mono.Cecil.Implem/OverrideCollection.cs + Mono.Cecil.Implem/ExceptionHandler.cs + Mono.Cecil.Implem/EmbeddedResource.cs + Mono.Cecil.Implem/ModuleReference.cs + Mono.Cecil.Implem/ParameterDefinitionCollection.cs + Mono.Cecil.Implem/EventDefinitionCollection.cs + Mono.Cecil.Implem/FieldDefinitionCollection.cs + Mono.Cecil.Implem/PropertyDefinitionCollection.cs + Mono.Cecil.Implem/ModuleDefinitionCollection.cs + Mono.Cecil.Implem/CustomAttributeCollection.cs + Mono.Cecil.Implem/VariableDefinitionCollection.cs + Mono.Cecil.Implem/TypeReferenceCollection.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/EventDefinition.cs + Mono.Cecil.Implem/FieldDefinition.cs + Mono.Cecil.Implem/InstructionCollection.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/CustomAttribute.cs + Mono.Cecil.Implem/VariableDefinition.cs + Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/TypeDefinitionCollection.cs + Mono.Cecil.Implem/AssemblyNameReferenceCollection.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/PInvokeInfo.cs + Mono.Cecil.Implem/AssemblyDefinition.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Implem/MethodDefinitionCollection.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Implem/SecurityDeclaration.cs + Mono.Cecil.Implem/LazyReflectionReader.cs + Mono.Cecil.Implem/LinkedResource.cs + Mono.Cecil.Implem/ParameterDefinition.cs + Mono.Cecil.Implem/PropertyDefinition.cs + Mono.Cecil.Implem/MethodBody.cs + Mono.Cecil.Implem/NestedTypeCollection.cs + Mono.Cecil.Implem/ResourceCollection.cs + Mono.Cecil.Implem/ExceptionHandlerCollection.cs: + BIG changes in the visitor object model. Last one + was causing ambiguous calls, and does not provides + differences between an interface and a typedef for + instance. This is corrected by suffixing the visit + method by the name of what it is visiting, and by + configuring some collection to stop the propagation + of the visitor. + + * Mono.Cecil/ITypeDefinition.cs + Mono.Cecil/IArrayType.cs + CodeGen/templates/Utilities.cs + Mono.Cecil.Metadata/Utilities.cs + Mono.Cecil.Implem/ArrayType.cs + Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Implem/Constants.cs + Mono.Cecil.Signatures/MarshalSig.cs: + Work on the writing layer goes on. + +2005-08-14 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/NativeType.cs + Mono.Cecil.Signatures/MarshalSig.cs + Mono.Cecil.Signatures/SignatureWriter.cs + Mono.Cecil.Signatures/Signature.cs: + Work on signature writing. + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/TypeDefinition.cs: + Correct bugs in setting the hasThis field. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Binary/templates/ImageWriter.cs + Mono.Cecil/AssemblyKind.cs: + Make assemblies executable on win32. + Mono.Cecil.Implem/TypeDefinition.cs: + Mark new fields as loaded. + Mono.Cecil.Implem/ReflectionWriter.cs: + Correct the style to patch provided by + Sebastien Ros <s.ros@evaluant.com> + +2005-08-13 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IMethod.cs + Mono.Cecil/ITypeDefinition.cs + Mono.Cecil/IModuleDefinition.cs + Mono.Cecil.Cil/OpCode.cs + Mono.Cecil.Cil/ICilWorker.cs + CodeGen/templates/ImageReader.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/MetadataRoot.cs + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/CilWorker.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/MethodReference.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Implem/Constants.cs + Mono.Cecil.Implem/ParameterDefinition.cs + Mono.Cecil.Implem/MethodBody.cs + Mono.Cecil.Binary/ImageReader.cs + Mono.Cecil.Binary/MemoryBinaryWriter.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + On going work on the writing layer. + + * Mono.Cecil.Signatures/SignatureReader.cs: + Fix a bug when reading chars inside a custom + attribute signature. + +2005-08-12 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyFactory.cs + CodeGen/templates/ImageWriter.cs + CodeGen/templates/MetadataTableWriter.cs + CodeGen/templates/MetadataRowWriter.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/MemoryBinaryWriter.cs: + Use a custom binary writer instead of the old one. + + * Mono.Cecil/IMethod.cs + Mono.Cecil.Cil/BaseCodeVisitor.cs + Mono.Cecil.Cil/MethodHeader.cs + Mono.Cecil.Cil/ICodeVisitor.cs + Mono.Cecil.Implem/Instruction.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/FieldDefinition.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Implem/MethodBody.cs: + Ongoing work on the writing layer. + + * CodeGen/templates/Utilities.cs + CodeGen/templates/NamedCollectionImplem.cs + CodeGen/templates/MetadataRowWriter.cs + CodeGen/templates/LzNamedCollectionImplem.cs + CodeGen/cecil.xml + Mono.Cecil/IMethod.cs + Mono.Cecil/IAssemblyName.cs + Mono.Cecil/IModuleDefinition.cs + Mono.Cecil/AssemblyFactory.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/Utilities.cs + Mono.Cecil.Implem/ReflectionHelper.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/EventDefinition.cs + Mono.Cecil.Implem/FieldDefinition.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/MethodReference.cs + Mono.Cecil.Implem/TypeDefinitionCollection.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/TypeDefinition.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Implem/Constants.cs + Mono.Cecil.Implem/ParameterDefinition.cs + Mono.Cecil.Implem/PropertyDefinition.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Ongoing work on the writing layer. + Some fixes to the reading layer as well. + +2005-08-11 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Signatures/SignatureReader.cs: + Read Array signatures correctly. + + * Mono.Cecil/IMethodSignature.cs: + Remove the setted for the return type. + * Mono.Cecil.Implem/CilWorker.cs: + Fix the build. Me idiot! + * Mono.Cecil.Implem/Constants.cs: + Remove unexisting type Variant. + * Mono.Cecil.Implem/ReflectionHelper.cs: + Complete the helper. + +2005-08-10 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Cil/IMethodBody.cs + Mono.Cecil.Cil/ICilEmitter.cs + Mono.Cecil.Cil/ICilWorker.cs + Mono.Cecil.Implem/CilWorker.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/MethodBody.cs + Mono.Cecil.Implem/CilEmitter.cs + Mono.Cecil.Signatures/SignatureReader.cs + Mono.Cecil.Signatures/SignatureWriter.cs: + Prepare the api for the cil emitting. + + * CodeGen/templates/Utilities.cs + CodeGen/templates/MetadataRowReader.cs + CodeGen/templates/MetadataRowWriter.cs + Mono.Cecil.Metadata/Utilities.cs + Mono.Cecil.Metadata/MetadataRowReader.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs: + Fix the build on .net, i was using a sugar + syntax for delegates that csc does not understand. + Remove the coded index cache from the static class + Utilities, and add one per row visitor. + + * Mono.Cecil/IMethodReturnType.cs + Mono.Cecil.Implem/MethodReturnType.cs + Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/ParameterDefinition.cs: + Make IMethodReturn type inherits IHasMarshalSpec so + that users can read marshaling info for return types, + and implement it. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Implem/ReflectionWriter.cs: + Cecil now emits assemblies understood by the .net clr. + +2005-08-09 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyKind.cs + CodeGen/templates/ImageWriter.cs + CodeGen/templates/ImageReader.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil.Binary/ImageReader.cs: + Lots of little fixes. Now dumpbin is coherent + compared with an assembly emitted with csc or mcs + but still not yet compatible with .net. + + * Mono.Cecil.Signatures/SignatureReader.cs: + Fix an array out of range while trying to read + fixed arrays signatures + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Implem/AssemblyName.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Binary/ImageCharacteristics.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/Image.cs: + Cecil now emits assemblies that are understood + by Mono and Cecil itself. Still have troubles + with Msft CLR. + +2005-08-08 Jb Evain <jbevain@gmail.com> + + * CodeGen/cecil-gen.rb + CodeGen/templates/MetadataTableReader.cs + CodeGen/templates/ImageWriter.cs + CodeGen/templates/MetadataTableWriter.cs + CodeGen/templates/BaseMetadataVisitor.cs + CodeGen/templates/MetadataRowReader.cs + CodeGen/templates/MetadataRowWriter.cs + CodeGen/cecil.xml + Mono.Cecil.Metadata/MetadataInitializer.cs + Mono.Cecil.Metadata/BaseMetadataVisitor.cs + Mono.Cecil.Metadata/MetadataTableReader.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataRowReader.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/CLIHeader.cs + Mono.Cecil.Binary/ImageInitializer.cs: + The writing layer almost works. + + * Mono.Cecil/AssemblyKind.cs + Mono.Cecil/TargetRuntime.cs + Mono.Cecil.dll.sources: + Add thoses enumes to control assembly writing. + * Mono.Cecil/AssemblyFactory.cs + Mono.Cecil/IReflectionVisitor.cs + Mono.Cecil/BaseReflectionVisitor.cs + Mono.Cecil/IAssemblyDefinition.cs + Mono.Cecil/IReflectionStructureVisitor.cs + Mono.Cecil/BaseStructureVisitor.cs + CodeGen/templates/ImageWriter.cs + CodeGen/templates/MetadataTableWriter.cs + CodeGen/templates/MetadataRowWriter.cs + CodeGen/templates/LzNamedCollectionImplem.cs + Mono.Cecil.Metadata/MetadataInitializer.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/MetadataStreamCollection.cs + Mono.Cecil.Implem/AssemblyName.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/TypeDefinitionCollection.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/AssemblyDefinition.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil.Binary/Imports.cs: + Things are now plugged. SaveAssembly will now emits + a binary file. A broken file, but heh, at least it does. + +2005-08-07 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/ImageReader.cs + CodeGen/templates/ImageWriter.cs + CodeGen/templates/IMetadataVisitor.cs + Mono.Cecil.Binary/ImageReader.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Metadata/IMetadataVisitor.cs + Mono.Cecil.Metadata/BaseMetadataVisitor.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/MetadataStreamCollection.cs: + Simplify IMetadataVisitor. + Work on the writing layer, closer to have something testable + than ever. + + * CodeGen/cecil.xml + CodeGen/templates/ImageWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Binary/PEOptionalHeader.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/Imports.cs: + don't stop don't stop come ON! + + * CodeGen/templates/ImageWriter.cs + CodeGen/templates/ImageReader.cs + CodeGen/templates/Section.cs + Mono.Cecil.Binary/Image.cs + Mono.Cecil.Binary/ImageReader.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/Section.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/CodeWriter.cs: + Some writing layer love. + + * CodeGen/templates/ImageWriter.cs + CodeGen/templates/ImageReader.cs + Mono.Cecil.Binary/Imports.cs + Mono.Cecil.Binary/ImageReader.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil.Binary/ImageWriter.cs: + Read an write correctly the Hint/Name table + at the end of the .text section. + + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/ImageInitializer.cs: + More writing layer stuff. + +2005-08-06 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/ImageWriter.cs + CodeGen/templates/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataInitializer.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/StringsHeap.cs + Mono.Cecil.Metadata/BlobHeap.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/UserStringsHeap.cs + Mono.Cecil.Metadata/TableCollection.cs + Mono.Cecil.Metadata/TablesHeap.cs + Mono.Cecil.Metadata/MetadataHeap.cs + Mono.Cecil.Metadata/GuidHeap.cs + Mono.Cecil.Metadata/MetadataStream.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/CodeWriter.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Binary/ImageInitializer.cs: + Playing lego with bricks from the writing layer. + + * Mono.Cecil.dll.sources: + Updated. + * CodeGen/templates/CLIHeader.cs + CodeGen/templates/PEOptionalHeader.cs + Blah. + * CodeGen/cecil.xml + Mono.Cecil.Binary/CLIHeader.cs + Mono.Cecil.Binary/PEOptionalHeader.cs: + Mono.Cecil.Binary/PEFileHeader.cs + On going work on the writing layer + + * CodeGen/templates/ImageWriter.cs + CodeGen/templates/ImageReader.cs + Mono.Cecil.Binary/BaseImageVisitor.cs + Mono.Cecil.Binary/ImageReader.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil.Binary/ImageWriter.cs + Mono.Cecil.Metadata/BaseMetadataVisitor.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/MetadataInitializer.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/MetadataStream.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/CodeWriter.cs: + Add helpers visitor. + On going work on the writing layer. + + * CodeGen/templates/Utilities.cs + CodeGen/templates/MetadataRowReader.cs + CodeGen/templates/MetadataRowWriter.cs + Mono.Cecil.Metadata/StringsHeap.cs + Mono.Cecil.Metadata/MetadataRowReader.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Metadata/MetadataReader.cs + Mono.Cecil.Metadata/Utilities.cs + Mono.Cecil.Metadata/BlobHeap.cs + Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/MetadataHeap.cd + Mono.Cecil.Metadata/GuidHeap.cs: + On going work on the writing layer. + + * CodeGen/templates/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataWriter.cs: + On going work on the writing layer. + * Mono.Cecil.Implem/StructureWriter.cs: + Correctly override methods + * CodeGen/templates/MetadataRowWriter.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Implem/ReflectionWriter.cs: + Fix build warnings. + + * Mono.Cecil/IResource.cs + Mono.Cecil.Implem/AssemblyLinkedResource.cs + Mono.Cecil.Implem/EmbeddedResource.cs + Mono.Cecil.Implem/LinkedResource.cs + Mono.Cecil.Implem/Resource.cs: + Rename field Attributes to Flags for the sake of consistency. + * Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Implem/ReflectionWriter.cs + Mono.Cecil.Implem/StructureWriter.cs: + On going work on the writing layer. + * Mono.Cecil.Implem/StructureReader.cs: + Style. + + * Mono.Cecil/IAssemblyName.cs + Mono.Cecil.Implem/AssemblyName.cs + Mono.Cecil.Implem/StructureReader.cs: + Add an AssemblyFlag property to an IAssemblyNameReference, + implement it, and read it. + +2005-08-04 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/ReflectionReader.cs: + set a correct name to nameless parameters + + * Mono.Cecil.Signatures/SignatureReader.cs: + don't crash on null custom attributes + +2005-08-03 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/OpCodes.cs + Mono.Cecil.Cil/OpCodes.cs + Mono.Cecil.Cil/OpCode.cs: + Revert modifications to reduce code. OpCodes::.ctors were + not called. + + * Mono.Cecil.Implem/ReflectionReader.cs: + Make sure parameters are read even if there is no + corresponding Param row. Thanks Cesar for the hint. + + * Mono.Cecil.Metadata/MetadataWriter.cs + Mono.Cecil.Metadata/UserStringsHeap.cs + Mono.Cecil.Metadata/GuidHeap.cs + Mono.Cecil.Implem/CodeReader.cs: + On going work on the writing layer + + * CodeGen/cecil-gen.rb + CodeGen/cecil-gen-sources.rb + make executable + * *.*: set svn:eol-style to native + + * Mono.Cecil/BaseStructureVisitor.cs + Mono.Cecil/BaseReflectionVisitor.cs + Mono.Cecil.Implem/BaseReflectionReader.cs: + Add empty visitors for the sake of simplicity + * Mono.Cecil.Implem/StructureReader.cs + Mono.Cecil.Implem/ReflectionReader.cs: + Inherit new visitors + +2005-08-03 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Implem/LazyReflectionReader.cs + Mono.Cecil.Implem/CodeReader.cs: + Modify and add helpers to avoid lots of casts. + Correct a bug in custom attributes attribution. + +2005-08-02 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Signatures/TypeSpec.cs: + Don't restrain the SigType + * Mono.Cecil.Implem/AggressiveReflectionReader.cs: + Set PInvokeInfos on the correct method + +2005-07-30 Jb Evain <jbevain@gmail.com> + + * CodeGen/cecil-gen.rb + CodeGen/cecil-gen-sources.rb: + make them executable + * CodeGen/cecil-gen-types: style + * CodeGen/templates/ImageWriter.cs + Mono.Cecil.Binary/ImageWriter.cs: + Prelimimary work on assembly writing + +2005-07-29 Jb Evain <jbevain@gmail.com> + + * CodeGen/cecil-gen-types.rb + CodeGen/templates/MetadataTableWriter.cs + CodeGen/templates/MetadataRowWriter.cs + Mono.Cecil/AssemblyFactory.cs + Mono.Cecil.Metadata/MetadataTableWriter.cs + Mono.Cecil.Metadata/MetadataRowWriter.cs + Mono.Cecil.Implem/StructureWriter.cs + Mono.Cecil.Implem/ReflectionWriter.cs: + Preliminary work on assembly writing + +2005-07-28 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/AssemblyFactory.cs + Mono.Cecil.Implem/StructureWriter.cs + Preliminary work on assembly writing + + * Mono.Cecil/IMetadataTokenProvider.cs + Mono.Cecil/IMember.cs + Mono.Cecil/IParameter.cs: + Add a MetadataToken property on searchable items + * Mono.Cecil.Metadata/MetadataToken.cs: + Add a factory method to create token from row number + * Mono.Cecil.Implem/TypeReference.cs + Mono.Cecil.Implem/MemberReference.cs + Mono.Cecil.Implem/ParameterDefinition.cs: + Implement the token property + * Mono.Cecil.Implem/ReflectionReader.cs + Mono.Cecil.Implem/AggressiveReflectionReader.cs + Mono.Cecil.Implem/LazyReflectionReader.cs: + Set the token property on reading + * Mono.Cecil/IModuleDefinition.cs + Mono.Cecil.Implem/ModuleDefinition.cs + Mono.Cecil.Implem/ReflectionReader.cs: + Add methods to lookup items from their tokens + +2005-07-27 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/OpCodes.cs + Mono.Cecil.Cil/OpCodes.cs + Mono.Cecil.Cil/OpCode.cs: + Changes to reduce the size of the cache ctor + +2005-07-22 Raja R Harinath <rharinath@novell.com> + + * Makefile (MCS): Allow compiler to be overriden. + +2005-07-21 Todd Berman <tberman@off.net> + + * configure: Add a small stub configure (stolen from mcs) to set the + prefix. + * mono-cecil.pc.in: Add a mono-cecil.pc.in to allow for installation + according to the new "Libraries with Unstable API" Wiki documentation. + * Makefile: Add an install an a mono-cecil.pc target to allow for + installation and creation of the pc file. + +2005-07-14 Jb Evain <jbevain@gmail.com> + + * CodeGen/templates/ImageReader.cs + Mono.Cecil.Binary/IBinaryVisitor.cs + Mono.Cecil.Binary/Image.cs + Mono.Cecil.Binary/ImageInitializer.cs + Mono.Cecil.Binary/Imports.cs + Mono.Cecil.Binary/ImageReader.cs: + Read Imports Tables + +2005-07-14 Jb Evain <jbevain@gmail.com> + + * CodeGen/cecil-gen.rb: + make codegen works on ruby 1.8.2 + * CodeGen/templates/*.cs + Mono.Cecil.Metadata/*.cs: + style + +2005-07-13 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/VariableDefinition.cs: + set the index field + +2005-07-13 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.dll.sources: regenerated + * Mono.Cecil.Signatures/SignatureReader.cs: + Fix compilation warnings + * Mono.Cecil/IArrayType.cs + Mono.Cecil.Implem/ArrayType.cs: + Add Rank helper property + * Mono.Cecil/ITypeDefinition.cs + Mono.Cecil.Implem/TypeDefinition.cs: + Add Constructors helper property + +2005-07-11 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IMethod.cs + Mono.Cecil.Implem/Instruction.cs + Mono.Cecil.Implem/ExceptionHandler.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/Label.cs + Mono.Cecil.Implem/CodeReader.cs + Mono.Cecil.Implem/MethodBody.cs + Mono.Cecil.Implem/CilEmitter.cs + Mono.Cecil.Cil/ILabel.cs + Mono.Cecil.Cil/IInstruction.cs + Mono.Cecil.Cil/IExceptionHandler.cs + Mono.Cecil.Cil/IMethodBody.cs + Mono.Cecil.Cil/ICilEmitter.cs: + Preliminary changes on the instruction model before + changing of latptop + +2005-07-08 Jb Evain <jbevain@gmail.com> + + * Every generated files: use \n instead of \r\n + +2005-07-07 Jb Evain <jbevain@gmail.com> + + * *.*: use Mono coding conventions + * Mono.Xml/*.*: update Mono.Xml from corlib + * Mono.Cecil.Metadata/CultureUtils.cs: + Ensure that Cecil works under Mono + +2005-07-02 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil/IMethod.cs + Mono.Cecil/IProperty.cs + Mono.Cecil/IEvent.cs + Mono.Cecil/IField.cs + Mono.Cecil/ITypeDefinition.cs + Mono.Cecil.Implem/MethodDefinition.cs + Mono.Cecil.Implem/PropertyDefinition.cs + Mono.Cecil.Implem/EventDefinition.cs + Mono.Cecil.Implem/FieldDefinition.cs + Mono.Cecil.Implem/TypeDefinition.cs: + Add some funky sugar attributes, + more to come + +2005-07-01 Jb Evain <jbevain@gmail.com> + + * CodeGen/cecil-gen.rb, + CodeGen/templates/MetadataTableWriter.cs, + CodeGen/templates/MetadataRowWriter.cs, + Mono.Cecil.Metadata/MetadataTableWriter.cs, + Mono.Cecil.Metadata/MetadataRowWriter.cs, + Mono.Cecil.Metadata/MetadataWriter.cs: + Add metadata writing visitors + * Mono.Cecil.Metadata/CultureUtils.cs: + Be sure to use every possible culture infos. + * Mono.Cecil.Cil/IVariable.cs, + Mono.Cecil.Implem/VariableDefinition.cs, + Mono.Cecil.Implem/CodeReader.cs, + Mono.Cecil.Implem/CilEmitter.cs: + Add an index property to local variables + * Mono.Cecil.Metadata/MetadataReader.cs, + Mono.Cecil.Metadata/MetadataRowReader.cs, + CodeGen/templates/MetadataRowReader.cs, + Mono.Cecil.Metadata/TablesHeap.cs: + Handles null heaps + * Mono.Cecil.Implem/StructureWriter.cs, + Mono.Cecil.Implem/ReflectionController.cs, + Mono.Cecil.Implem/ReflectionWriter.cs: + Assemble writing classes + +2005-06-28 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/ReflectionReader.cs: style + * Mono.Cecil.Implem/LazyReflectionReader.cs: + read the last property as well. + +2005-06-21 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/ReflectionReader.cs: Correct a bug that prevents + assemblies to be readed if they have an entrypoint. Suggestion by + Mario Sopena + * Mono.Cecil.Implem/CodeReader.cs: Use sbyte not to lose negatives + offsets. Suggestion by Vladislav Spivak + * CodeGen/cecil.xml, + Mono.Cecil.Cil/OpCodes.cs, + Mono.Cecil.Cil/StackBehaviour.cs: Add an PopAll enumeration value + for StackBehaviour, and set the StackBehaviourPop property for + leave and leave.s opcodes to it. Suggested by Vladislav Spivak + +2005-06-12 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.Implem/TypeDefinition.cs: Set the declaring type + to this when defining a nested type. + +2005-06-07 Jb Evain <jbevain@gmail.com> + + * Mono.Cecil.dll.sources, + * CodeGen/cecil.xml, + * Mono.Cecil/IReflectionVisitor.cs, + * Mono.Cecil/INestedTypeCollection.cs, + * Mono.Cecil/ITypeDefinition, + * Mono.Cecil.Implem/ReflectionReader.cs, + * Mono.Cecil.Implem/ReflectionWriter.cs, + * Mono.Cecil.Implem/TypeDefinition.cs, + * Mono.Cecil.Implem/NestedTypeCollection: + Add a collection of nested types for type definition + + * Mono.Cecil.Implem/ModuleDefinition.cs: simplify type creation + +2005-06-07 Jb Evain <jbevain@gmail.com> + + * ChangeLog: Cecil has now ChangeLogs. Let use them. diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-attributes.rb b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-attributes.rb new file mode 100755 index 0000000..4158155 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-attributes.rb @@ -0,0 +1,226 @@ +#!/usr/bin/env ruby + +$providers = [] + +$mapping = { + "Assem" => "IsAssembly", + "FamORAssem" => "IsFamilyOrAssembly", + "FamANDAssem" => "IsFamilyAndAssembly", + "NestedFamORAssem" => "IsNestedFamilyOrAssembly", + "NestedFamANDAssem" => "IsNestedFamilyAndAssembly", + "RTSpecialName" => "IsRuntimeSpecialName", + "Compilercontrolled" => "IsCompilerControlled", + "NotNullableValueTypeConstraint" => "HasNotNullableValueTypeConstraint", + "ReferenceTypeConstraint" => "HasReferenceTypeConstraint", + "DefaultConstructorConstraint" => "HasDefaultConstructorConstraint", + "SupportsLastError" => "SupportsLastError", + "NoInlining" => "NoInlining", +} + +$black_list = [ + "None", "Unused", "RequireSecObject", + "HasFieldMarshal", "HasFieldRVA", + "OPTIL", "MaxMethodImplVal" +] + +class Attribute + + attr_accessor(:name) + attr_accessor(:type) + + def initialize(name, type) + @name = name + @type = type + end + + def full_name + "#{@type}.#{@name}" + end + + def to_csharp +""" public bool #{get_name()} { +#{getter()}#{setter()} } +""" + end + + def to_s + "Attribute #{full_name}" + end + + protected + def getter +""" get { return (m_attributes & #{full_name()}) != 0; } +""" + end + + def setter +""" set { + if (value) + m_attributes |= #{full_name()}; + else + m_attributes &= ~#{full_name()}; + } +""" + end + + private + def get_name + name = @name + return $mapping[name] if $mapping.include?(name) + return name if name.rindex("Has") == 0 + "Is#{name}" + end +end + +class MaskedAttribute < Attribute + + attr_accessor(:mask) + + def initialize(name, type, mask) + super(name, type) + @mask = mask + end + + def mask_full_name + "#{@type}.#{@mask}" + end + + def to_s + "MaskedAttribute #{full_name()}, masked by #{mask_full_name()}" + end + + protected + def getter +""" get { return (m_attributes & #{mask_full_name()}) == #{full_name()}; } +""" + end + + def setter +""" set { + if (value) { + m_attributes &= ~#{mask_full_name()}; + m_attributes |= #{full_name()}; + } else + m_attributes &= ~(#{mask_full_name()} & #{full_name()}); + } +""" + end +end + +class Provider + + attr_accessor(:type) + attr_accessor(:attributes_file) + attr_accessor(:target_file) + attr_accessor(:attributes) + + def initialize(type, attributes_file, target_file) + @type = type + @attributes_file = attributes_file + @target_file = target_file + @attributes = [] + end + + def parse + f = File.open(@attributes_file, File::RDONLY) + have_mask = false + mask = "" + f.readlines.each { |line| + if line.chomp().length == 0 + have_mask = false + else + name = get_name(line) + if not name.nil? and name.index("Mask") + mask = name + have_mask = true + elsif not name.nil? + attr = nil + if (have_mask) + attr = MaskedAttribute.new(name, @type, mask) + else + attr = Attribute.new(name, @type) + end + @attributes << attr + end + end + } + f.close + end + + def patch + buffer = read_target_content() + buffer = patch_buffer(buffer) + if buffer != read_target_content() + puts("#{@target_file} patched") + write_target_content (buffer) + end + end + + private + def patch_buffer(buffer) + region = "#region " + @type + endregion = "#endregion" + + endpart = buffer[(buffer.index(endregion) - 3)..buffer.length] + + rep = buffer[0..(buffer.index(region) + region.length)] + + rep += "\n" + + @attributes.each { |attr| + rep += attr.to_csharp + rep += "\n" if attr != @attributes.last + } + + rep += endpart + + rep + end + + def read_target_content + f = File.new(@target_file, File::RDONLY) + content = f.readlines.join + f.close + content + end + + def write_target_content(content) + File.open(@target_file, File::WRONLY | File::TRUNC) { |f| + f.write(content) + } + end + + def get_name(line) + pos = line.index("=") + return nil if not pos + name = line[0..(pos - 1)].strip + + return nil if $black_list.include?(name) + name + end +end + +def to_cecil_file(file) + "../Mono.Cecil/#{file}.cs" +end + +[ "Event", "Field", "Method", "Parameter", "Property", "Type" ].each { |name| + attributes = "#{name}Attributes" + definition = "#{name}Definition" + $providers << Provider.new(attributes, to_cecil_file(attributes), to_cecil_file(definition)) +} + +{ "GenericParameter" => "GenericParameter", + "ManifestResource" => "Resource", + "PInvoke" => "PInvokeInfo", +# "MethodImpl" => "MethodDefinition", +# "MethodSemantics" => "MethodDefinition", +}.each { |k, v| + attributes = "#{k}Attributes" + $providers << Provider.new(attributes, to_cecil_file(attributes), to_cecil_file(v)) +} + +$providers.each { |p| + p.parse + p.patch +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-sources.rb b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-sources.rb new file mode 100755 index 0000000..e93b195 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-sources.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +f = File.new("../Mono.Cecil.dll.sources", File::CREAT | File::WRONLY | File::TRUNC) + +[ "Mono.Cecil", "Mono.Cecil.Binary", + "Mono.Cecil.Metadata", "Mono.Cecil.Cil", + "Mono.Cecil.Signatures", "Mono.Xml" ].each { |dir| + + Dir.foreach("../" + dir) { |file| + f.print("./#{dir}/#{file}\n") if file[(file.length - 3)..file.length] == ".cs" + } +} + +f.close diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-tests.rb b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-tests.rb new file mode 100755 index 0000000..b2ab8ef --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-tests.rb @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby + +require 'erb' + +class Language + + attr_reader(:name) + attr_reader(:compiler) + attr_reader(:ext) + attr_reader(:command) + + def initialize(name, compiler, ext, command) + @name = name + @compiler = compiler + @ext = ext + @command = command + end +end + +class TestCase + + attr_reader(:lang) + attr_reader(:file) + + def initialize(lang, file) + @lang = lang + @file = file + end + + def method() + meth = @file.gsub(/[^a-zA-Z1-9]/, "_") + return meth[1..meth.length] if (meth[0].chr == "_") + return meth + end +end + +$languages = [ + Language.new("cil", "ilasm", ".il", "{0} /exe /output:{2} {1}"), + Language.new("csharp", "mcs", ".cs", "{0} /t:exe /o:{2} {1}") +] + +$tests = [ +] + +def analyze(dir) + $languages.each { |l| + pattern = File.join(dir, "**", "*" + l.ext) + Dir[pattern].each { |file| + $tests.push(TestCase.new(l, File.expand_path(file))) + } + } +end + +ARGV.each { |dir| + analyze(dir) +} + +if $tests.length > 0 + erb = ERB.new(IO.read("./templates/Tests.cs")) + print(erb.result) +end diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-types.rb b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-types.rb new file mode 100644 index 0000000..2c0e629 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen-types.rb @@ -0,0 +1,262 @@ + +# types used in templates + +module Cecil + + class Evolutive # abstract + + attr_reader(:requ) + + def initialize(requ) + @requ = requ + end + end + + class FieldWorker # abstract + + attr_reader(:field_name) + attr_reader(:property_name) + attr_reader(:type) + attr_reader(:ns) + attr_reader(:size) + attr_reader(:target) + + def initialize(name, type, target) + @property_name = name + @target = target + @field_name = to_field(name) + + @objtype = type + + ar = type.name.split(".") + @type = ar.pop() + @ns = ar.join(".") + + @size = type.size + end + + def to_field(name) + name = String.new(name) + name[0] = name[0].chr.downcase + return "m_" + name + end + + def write_binary(inst, writer) + pre = writer + ".Write (" + prp = inst + "." + @property_name + suf = ")" + return case @type + when "byte", "ushort", "short", "uint", "int" + pre + prp + suf + when "RVA" + pre + prp + ".Value" + suf + when "DataDirectory" + pre + prp + ".VirtualAddress" + suf + ";\n\t\t\t" + pre + prp + ".Size" + suf + else + pre + "(" + @objtype.underlying + ") " + prp + suf + end + end + + def read_binary(inst) + return case @type + when "byte" + inst + ".ReadByte ()" + when "ushort" + inst + ".ReadUInt16 ()"; + when "short" + inst + ".ReadInt16 ()"; + when "uint" + inst + ".ReadUInt32 ()"; + when "int" + inst + ".ReadInt32 ()"; + when "RVA" + "new RVA (" + inst + ".ReadUInt32 ())" + when "DataDirectory" + "new DataDirectory (\n new RVA (" + inst + ".ReadUInt32 ()),\n " + inst + ".ReadUInt32 ())" + else + "(" + @objtype.name + ") " + case @objtype.underlying + when "int" + inst + ".ReadInt32 ()"; + when "short" + inst + ".ReadInt16 ()"; + when "ushort" + inst + ".ReadUInt16 ()"; + when "uint" + inst + ".ReadUInt32 ()"; + end + end + end + end + + class Type + + attr_reader(:name) + attr_reader(:size) + attr_reader(:underlying) + + def initialize(name, size, underlying = nil) + @name = name + @size = size + @underlying = underlying + end + end + + class Table < Evolutive + + attr_reader(:ref_ns) + attr_reader(:rid) + attr_reader(:name) + attr_reader(:table_name) + attr_reader(:row_name) + attr_reader(:columns) + + def initialize(name, rid, requ) + super(requ) + @name = name + @table_name = name + "Table" + @row_name = name + "Row" + @rid = rid + @ref_ns = Array.new + @columns = Array.new + end + + def add_column(col) + if (!@ref_ns.include?(col.ns) && col.ns.length != 0 && col.ns != "Mono.Cecil.Metadata") then + @ref_ns.push(col.ns) + @ref_ns.sort!() + end + @columns.push(col) + end + + def row_size() + size = 0 + @columns.each { |col| + size += col.size + } + return size + end + end + + class Column < FieldWorker + + def initialize(name, type, target) + super(name, type, target) + end + + end + + class Collection + + attr_reader(:type) + attr_reader(:intf) + attr_reader(:name) + attr_reader(:container) + attr_reader(:container_impl) + attr_reader(:item_name) + attr_reader(:visitable) + attr_reader(:visitor) + attr_reader(:visitThis) + attr_reader(:visitItem) + attr_reader(:lazyload) + attr_reader(:pathtoloader) + attr_reader(:target) + attr_reader(:indexed) + + def initialize(type, container, visit, name, lazyload, pathtoloader, target, indexed = false, usecntintf = false) + @type = type + basename = (name.nil? ? type : name) + @intf = "I" + basename + "Collection" + @name = @intf[1..@intf.length] + @item_name = basename[0..basename.length] + @container = container + @container_impl = usecntintf ? @container : @container[0..@container.length] + if (!visit.nil?) then + @visitable = visit + "Visitable" + @visitor = visit + "Visitor" + @visitThis = "Visit" + @name + @visitItem = "Visit" + @item_name + end + @lazyload = lazyload + @pathtoloader = pathtoloader + @target = target + @indexed = indexed + end + end + + class OpCode < Evolutive + + attr_reader(:name) + attr_reader(:field_name) + attr_reader(:op1) + attr_reader(:op2) + attr_reader(:size) + attr_reader(:flowcontrol) + attr_reader(:opcodetype) + attr_reader(:operandtype) + attr_reader(:stackbehaviourpop) + attr_reader(:stackbehaviourpush) + + def initialize(name, op1, op2, flowcontrol, opcodetype, operandtype, stackbehaviourpop, stackbehaviourpush, requ) + super(requ) + @name = name + @field_name = name_to_prop(name) + @op1 = op1 ; @op2 = op2 + @size = @op1 == "0xff" ? 1 : 2 + @flowcontrol = "FlowControl." + flowcontrol + @opcodetype = "OpCodeType." + opcodetype + @operandtype = "OperandType." + operandtype + @stackbehaviourpop = "StackBehaviour." + stackbehaviourpop + @stackbehaviourpush = "StackBehaviour." + stackbehaviourpush + end + + def name_to_prop(name) + field = "" + ar = name.split(".") + ar.each { |part| + field += part.capitalize() + field += "_" unless ar.last == part + } + return field + end + end + + class Field < FieldWorker + + attr_reader(:default) + + def initialize(name, type, default) + super(name, type, nil) + @default = default + end + end + + class CodedIndexTable + + attr_reader(:name) + attr_reader(:tag) + + def initialize(name, tag) + @name = name + @tag = tag + end + end + + class CodedIndex < Evolutive + + attr_reader(:name) + attr_reader(:size) + attr_reader(:tables) + + def initialize(name, size, requ) + super(requ) + @name = name + @size = size + @tables = Array.new + end + + def add_table(name, tag) + @tables.push(CodedIndexTable.new(name, tag)) + end + end + +end diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen.rb b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen.rb new file mode 100755 index 0000000..dec7a1f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-gen.rb @@ -0,0 +1,161 @@ +#!/usr/bin/env ruby +# extern libraries used by code generator + +require 'erb' +require 'rexml/document' + +# our library + +require 'cecil-gen-types' + +# time to generate code now + +$types = Hash.new +$tables = Array.new +$colls = Array.new +$coded_indexes = Array.new +$ops = Array.new + +doc = REXML::Document.new(File.open("cecil.xml")) + +doc.root.each_element("/cecil/types//type") { |node| + type = Cecil::Type.new( + node.attribute("name").value, + node.attribute("size").value.to_i, + (node.attribute("underlying").nil? ? nil : node.attribute("underlying").value)) + $types[type.name] = type +} + +doc.root.each_element("/cecil/metadata/tables//table") { |node| + table = Cecil::Table.new(node.attribute("name").value, + node.attribute("rid").value, + node.attribute("requires").nil? ? nil : node.attribute("requires").value) + node.each_element("column") { |col| + column = Cecil::Column.new(col.attribute("name").value, + $types[col.attribute("type").value], + col.attribute("target").nil? ? nil : col.attribute("target").value) + table.add_column(column) + } + $tables.push(table) +} + +$tables.sort!() { |a, b| + a.name <=> b.name +} + +$stables = $tables.sort { |a, b| + eval(a.rid) <=> eval(b.rid) +} + +doc.root.each_element("/cecil/metadata/codedindexes//codedindex") { |node| + ci = Cecil::CodedIndex.new(node.attribute("name").value, + node.attribute("size").value, + node.attribute("requires").nil? ? nil : node.attribute("requires").value) + node.each_element("table") { |table| + ci.add_table(table.attribute("name").value, table.attribute("tag").value) + } + $coded_indexes.push(ci) +} + +doc.root.each_element("/cecil/metadata/opcodes//opcode") { |node| + $ops.push(Cecil::OpCode.new(node.attribute("name").value, node.attribute("op1").value, + node.attribute("op2").value, node.attribute("flowcontrol").value, + node.attribute("opcodetype").value, node.attribute("operandtype").value, + node.attribute("stackbehaviourpop").value, node.attribute("stackbehaviourpush").value, + node.attribute("requires").nil? ? nil : node.attribute("requires").value)) +} + +$ops.sort!() { |a, b| + if a.op1 == b.op1 + eval(a.op2) <=> eval(b.op2) + elsif a.op1 == "0xff" + -1 + else + 1 + end +} + +doc.root.each_element("/cecil/collections//collection") { |node| + $colls.push(Cecil::Collection.new(node.attribute("type").value, node.attribute("container").value, + (node.attribute("visit").nil? ? nil : node.attribute("visit").value), + (node.attribute("name").nil? ? nil : node.attribute("name").value), + (node.attribute("lazyload").nil? ? false : node.attribute("lazyload").value == "true"), + (node.attribute("pathtoloader").nil? ? nil : node.attribute("pathtoloader").value), + node.attribute("target").value, + (node.attribute("indexed").nil? ? false : node.attribute("indexed").value == "true"), + (node.attribute("usecontainerinterface").nil? ? false : node.attribute("usecontainerinterface").value == "true"))) +} + +def cecil_compile(file, template) + + erb = ERB.new(IO.read(template)) + res = erb.result + + if (!File.exists?(file)) + + File.open(file, File::CREAT|File::WRONLY|File::TRUNC) { |cur_file| + cur_file.write(res) + } + + puts("#Created: #{file}") + + else + + ext = ".tmp" + + File.open(file + ext, File::CREAT|File::WRONLY|File::TRUNC) { |temp_file| + temp_file.write(res) + } + + save = Array.new + + [file, file + ext].each { |fileloc| + File.open(fileloc, File::RDONLY) { |f| + buf = f.readlines + buf.each { |line| + line.chomp!() + } + buf = buf.join + buf = buf[buf.index("SOFTWARE."), buf.length] + save.push(buf) + } + } + + if (save[0] != save[1]) then + File.delete(file) if File.exists?(file) + File.rename(file + ext, file) + puts("#Modified: #{file}") + else + File.delete(file + ext) + end + end +end + +$tables.each { |table| + $cur_table = table + filename = "../Mono.Cecil.Metadata/" + table.name + ".cs" + cecil_compile(filename, "./templates/Table.cs") +} +$cur_table = nil + +[ "MetadataTableReader.cs", "MetadataRowReader.cs", + "MetadataTableWriter.cs", "MetadataRowWriter.cs", "BaseMetadataVisitor.cs", + "CodedIndex.cs", "Utilities.cs" ].each { |file| + cecil_compile("../Mono.Cecil.Metadata/" + file, "./templates/" + file) +} + +cecil_compile("../Mono.Cecil.Metadata/IMetadataVisitor.cs", "./templates/IMetadataVisitor.cs") + +cecil_compile("../Mono.Cecil.Cil/OpCodes.cs", "./templates/OpCodes.cs") +cecil_compile("../Mono.Cecil.Cil/Code.cs", "./templates/Code.cs") + +$colls.each { |coll| + $cur_coll = coll + file = "../#{coll.target}/" + coll.name + ".cs" + type = coll.indexed ? "Indexed" : "Named" + template = "./templates/#{type}Collection.cs" + + cecil_compile(file, template) +} +$cur_coll = nil + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-mig.rb b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-mig.rb new file mode 100755 index 0000000..a5104fb --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-mig.rb @@ -0,0 +1,159 @@ +#!/usr/bin/env ruby + +# +# usage cecil-mig.rb directory +# + +dir = ARGV.length > 0 ? ARGV[0] : "." + +$replaces = { + "GenericParamAttributes" => "GenericParameterAttributes", + "ParamAttributes" => "ParameterAttributes", + "IParameterReference" => "ParameterDefinition", + "IPropertyReference" => "PropertyDefinition", + "IEventReference" => "EventDefinition", + "IVariableReference" => "VariableDefinition", + "IMarshalDesc" => "MarshalSpec", + "MarshalDesc" => "MarshalSpec", + "IArrayMarshalDesc" => "ArrayMarshalSpec", + "ArrayMarshalDesc" => "ArrayMarshalSpec", + "ICustomMarshalerDesc" => "CustomMarshalerSpec", + "CustomMarshalerDesc" => "CustomMarshalerSpec", + "ISafeArrayDesc" => "SafeArraySpec", + "SafeArrayDesc" => "SafeArraySpec", + "IFixedArrayDesc" => "FixedArraySpec", + "FixedArrayDesc" => "FixedArraySpec", + "IFixedSysStringDesc" => "FixedSysStringSpec", + "FixedSysStringDesc" => "FixedSysStringSpec", + "IModifierType" => "ModType" +} + +$collections = [ + "AssemblyNameReferenceCollection", + "ModuleReferenceCollection", + "ModuleDefinitionCollection", + "ResourceCollection", + "TypeDefinitionCollection", + "TypeReferenceCollection", + "InterfaceCollection", + "ParameterDefinitionCollection", + "OverrideCollection", + "MethodDefinitionCollection", + "ConstructorCollection", + "EventDefinitionCollection", + "FieldDefinitionCollection", + "PropertyDefinitionCollection", + "InstructionCollection", + "ExceptionHandlerCollection", + "VariableDefinitionCollection", + "ArrayDimensionCollection", + "CustomAttributeCollection", + "ExternTypeCollection", + "NestedTypeCollection", + "SecurityDeclarationCollection", + "MemberReferenceCollection", + "GenericParameterCollection", + "GenericArgumentCollection", + "ConstraintCollection" +] + +$types = [ + "AssemblyDefinition", + "ArrayDimension", + "ArrayType", + "AssemblyLinkedResource", + "AssemblyNameReference", + "AssemblyNameDefinition", + "CallSite", + "CustomAttribute", + "EmbeddedResource", + "EventDefinition", + "EventReference", + "FieldDefinition", + "FieldReference", + "FunctionPointerType", + "GenericInstanceMethod", + "GenericInstanceType", + "GenericParameter", + "LinkedResource", + "MethodDefinition", + "MethodReference", + "MethodReturnType", + "ModifierOptional", + "ModifierRequired", + "ModuleDefinition", + "ModuleReference", + "ParameterDefinition", + "ParameterReference", + "PinnedType", + "PInvokeInfo", + "PropertyDefinition", + "PropertyReference", + "ReferenceType", + "Resource", + "SecurityDeclaration", + "TypeDefinition", + "TypeReference", + "TypeSpecification", + + "Instruction", + "ExceptionHandler", + "MethodBody", + "VariableDefinition", + "VariableReference" +] + +def iface(name) + return "I" + name +end + +def bang(buffer, re, str) + nl = "([\\W])" + buffer.gsub!(Regexp.new("#{nl}(#{re})#{nl}"), "\\1" + str + "\\3") +end + +def process_replaces(buffer) + $replaces.each_key { |key| + bang(buffer, key, $replaces[key]) + } +end + +def process_collections(buffer) + $collections.each { |name| + bang(buffer, iface(name), name) + } +end + +def process_types(buffer) + $types.each { |name| + bang(buffer, iface(name), name) + } +end + +def process_unbreak(buffer) + $unbreak.each { |name| + bang(buffer, name, iface(name)) + } +end + +def process(file) + buffer = "" + original = "" + File.open(file, File::RDONLY) { |f| + original = f.read() + buffer = original.clone + process_replaces(buffer) + process_collections(buffer) + process_types(buffer) + } + + File.open(file, File::WRONLY | File::TRUNC) { |f| + f.write(buffer) + puts("#{file} processed") + } if (original != buffer) + +end + +Dir[File.join(dir, "**", "*.*")].each { |file| + process(file) if not File.directory?(file) +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-update-rev b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-update-rev new file mode 100755 index 0000000..c1c1f91 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil-update-rev @@ -0,0 +1,51 @@ +#!/usr/bin/env ruby + +svn = "svn+ssh://mono-cvs.ximian.com/source/" +info = "Mono.Cecil/AssemblyInfo.cs" + +$rev = 0 + +IO::popen("svn info #{svn}").each { |line| + $rev = $1.to_i if line =~ /^Revision: ([0-9]+)/ +} + +if $rev == 0 + puts "Cannot get last revision" + exit(1) +end + +def read_file(file) + content = "" + f = File.new(file, File::CREAT | File::RDONLY) + content << f.readlines.join + f.close + + return content +end + +def write_file(file, content) + File.open(file, File::CREAT | File::WRONLY) { |f| + f.write(content) + } +end + +def patch_info(content) + patched = "" + content.each_line { |line| + if not line =~ /AssemblyVersion/ + patched << line + else + patched << line.gsub(/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/) { + next_rev = $rev.next + cut = 10000 + build_rev = (next_rev / cut).ceil + revision = next_rev - (build_rev * cut) + build = (($3.to_i / 100).ceil * 100) + build_rev + "#{$1.to_s}.#{$2.to_s}.#{build.to_s}.#{(revision).to_s}" + } + end + } + return patched +end + +write_file(info, patch_info(read_file(info))) diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil.xml b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil.xml new file mode 100644 index 0000000..4f548ec --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/cecil.xml @@ -0,0 +1,608 @@ +<?xml version="1.0" encoding="utf-8"?> +<cecil> + + <types> + <type name="byte" size="1" /> + <type name="ushort" size="2" /> + <type name="short" size="2" /> + <type name="uint" size="4" /> + <type name="int" size="4" /> + <type name="Mono.Cecil.Binary.DataDirectory" size="8" /> + <type name="Mono.Cecil.Binary.ImageCharacteristics" underlying="ushort" size="2" /> + <type name="Mono.Cecil.Binary.DebugStoreType" underlying="uint" size="4" /> + <type name="Mono.Cecil.Binary.SubSystem" underlying="ushort" size="2" /> + <type name="Mono.Cecil.Binary.SectionCharacteristics" underlying="uint" size="4" /> + <type name="Mono.Cecil.Binary.RVA" size="4" /> + <type name="Mono.Cecil.Binary.RuntimeImage" underlying="uint" size="4" /> + <type name="Mono.Cecil.AssemblyHashAlgorithm" underlying="uint" size="4" /> + <type name="Mono.Cecil.AssemblyFlags" underlying="uint" size="4" /> + <type name="Mono.Cecil.EventAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.TypeAttributes" underlying="uint" size="4" /> + <type name="Mono.Cecil.FieldAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.FileAttributes" underlying="uint" size="4" /> + <type name="Mono.Cecil.GenericParameterAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.PInvokeAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.ParameterAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.PropertyAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.ManifestResourceAttributes" underlying="uint" size="4" /> + <type name="Mono.Cecil.MethodAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.MethodImplAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.MethodSemanticsAttributes" underlying="ushort" size="2" /> + <type name="Mono.Cecil.SecurityAction" underlying="short" size="2" /> + <type name="Mono.Cecil.Metadata.ElementType" underlying="ushort" size="2" /> + <type name="Mono.Cecil.Metadata.MetadataToken" underlying="uint" size="4" /> + </types> + + <!-- + All details about the Metadata + reader and writer of Cecil + --> + <metadata> + + <!-- + This part contains ECMA spec + about CIL tables and rows positions + in a valid CLI image + --> + <tables> + <table name="Assembly" rid="0x20"> + <column name="HashAlgId" type="Mono.Cecil.AssemblyHashAlgorithm" /> + <column name="MajorVersion" type="ushort" /> + <column name="MinorVersion" type="ushort" /> + <column name="BuildNumber" type="ushort" /> + <column name="RevisionNumber" type="ushort" /> + <column name="Flags" type="Mono.Cecil.AssemblyFlags" /> + <column name="PublicKey" type="uint" target="BlobHeap" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Culture" type="uint" target="StringsHeap" /> + </table> + <table name="AssemblyOS" rid="0x22"> + <column name="OSPlatformID" type="uint" /> + <column name="OSMajorVersion" type="uint" /> + <column name="OSMinorVersion" type="uint" /> + </table> + <table name="AssemblyProcessor" rid="0x21"> + <column name="Processor" type="uint" /> + </table> + <table name="AssemblyRef" rid="0x23"> + <column name="MajorVersion" type="ushort" /> + <column name="MinorVersion" type="ushort" /> + <column name="BuildNumber" type="ushort" /> + <column name="RevisionNumber" type="ushort" /> + <column name="Flags" type="Mono.Cecil.AssemblyFlags" /> + <column name="PublicKeyOrToken" type="uint" target="BlobHeap" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Culture" type="uint" target="StringsHeap" /> + <column name="HashValue" type="uint" target="BlobHeap" /> + </table> + <table name="AssemblyRefOS" rid="0x25"> + <column name="OSPlatformID" type="uint" /> + <column name="OSMajorVersion" type="uint" /> + <column name="OSMinorVersion" type="uint" /> + <column name="AssemblyRef" type="uint" target="AssemblyRef" /> + </table> + <table name="AssemblyRefProcessor" rid="0x24"> + <column name="Processor" type="uint" /> + <column name="AssemblyRef" type="uint" target="AssemblyRef" /> + </table> + <table name="ClassLayout" rid="0x0f"> + <column name="PackingSize" type="ushort" /> + <column name="ClassSize" type="uint" /> + <column name="Parent" type="uint" target="TypeDef" /> + </table> + <table name="Constant" rid="0x0b"> + <column name="Type" type="Mono.Cecil.Metadata.ElementType" /> + <column name="Parent" type="Mono.Cecil.Metadata.MetadataToken" target="HasConstant" /> + <column name="Value" type="uint" target="BlobHeap" /> + </table> + <table name="CustomAttribute" rid="0x0c"> + <column name="Parent" type="Mono.Cecil.Metadata.MetadataToken" target="HasCustomAttribute" /> + <column name="Type" type="Mono.Cecil.Metadata.MetadataToken" target="CustomAttributeType" /> + <column name="Value" type="uint" target="BlobHeap" /> + </table> + <table name="DeclSecurity" rid="0x0e"> + <column name="Action" type="Mono.Cecil.SecurityAction" /> + <column name="Parent" type="Mono.Cecil.Metadata.MetadataToken" target="HasDeclSecurity" /> + <column name="PermissionSet" type="uint" target="BlobHeap" /> + </table> + <table name="EventMap" rid="0x12"> + <column name="Parent" type="uint" target="TypeDef" /> + <column name="EventList" type="uint" target="Event" /> + </table> + <table name="Event" rid="0x14"> + <column name="EventFlags" type="Mono.Cecil.EventAttributes" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="EventType" type="Mono.Cecil.Metadata.MetadataToken" target="TypeDefOrRef" /> + </table> + <table name="EventPtr" rid="0x13"> + <column name="Event" type="uint" target="Event" /> + </table> + <table name="ExportedType" rid="0x27"> + <column name="Flags" type="Mono.Cecil.TypeAttributes" /> + <column name="TypeDefId" type="uint" /> + <column name="TypeName" type="uint" target="StringsHeap" /> + <column name="TypeNamespace" type="uint" target="StringsHeap" /> + <column name="Implementation" type="Mono.Cecil.Metadata.MetadataToken" target="Implementation" /> + </table> + <table name="Field" rid="0x04"> + <column name="Flags" type="Mono.Cecil.FieldAttributes" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Signature" type="uint" target="BlobHeap" /> + </table> + <table name="FieldLayout" rid="0x10"> + <column name="Offset" type="uint" /> + <column name="Field" type="uint" target="Field" /> + </table> + <table name="FieldMarshal" rid="0x0d"> + <column name="Parent" type="Mono.Cecil.Metadata.MetadataToken" target="HasFieldMarshal" /> + <column name="NativeType" type="uint" target="BlobHeap" /> + </table> + <table name="FieldPtr" rid="0x03"> + <column name="Field" type="uint" target="Field" /> + </table> + <table name="FieldRVA" rid="0x1d"> + <column name="RVA" type="Mono.Cecil.Binary.RVA" /> + <column name="Field" type="uint" target="Field" /> + </table> + <table name="File" rid="0x26"> + <column name="Flags" type="Mono.Cecil.FileAttributes" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="HashValue" type="uint" target="BlobHeap" /> + </table> + <table name="GenericParam" rid="0x2a" requires="NET_2_0"> + <column name="Number" type="ushort" /> + <column name="Flags" type="Mono.Cecil.GenericParameterAttributes" /> + <column name="Owner" type="Mono.Cecil.Metadata.MetadataToken" target="TypeOrMethodDef" /> + <column name="Name" type="uint" target="StringsHeap" /> + </table> + <table name="GenericParamConstraint" rid="0x2c" requires="NET_2_0"> + <column name="Owner" type="uint" target="GenericParam" /> + <column name="Constraint" type="Mono.Cecil.Metadata.MetadataToken" target="TypeDefOrRef" /> + </table> + <table name="ImplMap" rid="0x1c"> + <column name="MappingFlags" type="Mono.Cecil.PInvokeAttributes" /> + <column name="MemberForwarded" type="Mono.Cecil.Metadata.MetadataToken" target="MemberForwarded" /> + <column name="ImportName" type="uint" target="StringsHeap" /> + <column name="ImportScope" type="uint" target="ModuleRef" /> + </table> + <table name="InterfaceImpl" rid="0x09"> + <column name="Class" type="uint" target="TypeDef" /> + <column name="Interface" type="Mono.Cecil.Metadata.MetadataToken" target="TypeDefOrRef" /> + </table> + <table name="ManifestResource" rid="0x28"> + <column name="Offset" type="uint" /> + <column name="Flags" type="Mono.Cecil.ManifestResourceAttributes" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Implementation" type="Mono.Cecil.Metadata.MetadataToken" target="Implementation" /> + </table> + <table name="MemberRef" rid="0x0a"> + <column name="Class" type="Mono.Cecil.Metadata.MetadataToken" target="MemberRefParent" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Signature" type="uint" target="BlobHeap" /> + </table> + <table name="Method" rid="0x06"> + <column name="RVA" type="Mono.Cecil.Binary.RVA" /> + <column name="ImplFlags" type="Mono.Cecil.MethodImplAttributes" /> + <column name="Flags" type="Mono.Cecil.MethodAttributes" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Signature" type="uint" target="BlobHeap" /> + <column name="ParamList" type="uint" target="Param" /> + </table> + <table name="MethodImpl" rid="0x19"> + <column name="Class" type="uint" target="TypeDef" /> + <column name="MethodBody" type="Mono.Cecil.Metadata.MetadataToken" target="MethodDefOrRef" /> + <column name="MethodDeclaration" type="Mono.Cecil.Metadata.MetadataToken" target="MethodDefOrRef" /> + </table> + <table name="MethodPtr" rid="0x05"> + <column name="Method" type="uint" target="Method" /> + </table> + <table name="MethodSemantics" rid="0x18"> + <column name="Semantics" type="Mono.Cecil.MethodSemanticsAttributes" /> + <column name="Method" type="uint" target="Method" /> + <column name="Association" type="Mono.Cecil.Metadata.MetadataToken" target="HasSemantics" /> + </table> + <table name="MethodSpec" rid="0x2b" requires="NET_2_0"> + <column name="Method" type="Mono.Cecil.Metadata.MetadataToken" target="MethodDefOrRef" /> + <column name="Instantiation" type="uint" target="BlobHeap" /> + </table> + <table name="Module" rid="0x00"> + <column name="Generation" type="ushort" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Mvid" type="uint" target="GuidHeap" /> + <column name="EncId" type="uint" target="GuidHeap" /> + <column name="EncBaseId" type="uint" target="GuidHeap" /> + </table> + <table name="ModuleRef" rid="0x1a"> + <column name="Name" type="uint" target="StringsHeap" /> + </table> + <table name="NestedClass" rid="0x29"> + <column name="NestedClass" type="uint" target="TypeDef" /> + <column name="EnclosingClass" type="uint" target="TypeDef" /> + </table> + <table name="Param" rid="0x08"> + <column name="Flags" type="Mono.Cecil.ParameterAttributes" /> + <column name="Sequence" type="ushort" /> + <column name="Name" type="uint" target="StringsHeap" /> + </table> + <table name="ParamPtr" rid="0x07"> + <column name="Param" type="uint" target="Param" /> + </table> + <table name="Property" rid="0x17"> + <column name="Flags" type="Mono.Cecil.PropertyAttributes" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Type" type="uint" target="BlobHeap" /> + </table> + <table name="PropertyMap" rid="0x15"> + <column name="Parent" type="uint" target="TypeDef" /> + <column name="PropertyList" type="uint" target="Property" /> + </table> + <table name="PropertyPtr" rid="0x16"> + <column name="Property" type="uint" target="Property" /> + </table> + <table name="StandAloneSig" rid="0x11"> + <column name="Signature" type="uint" target="BlobHeap" /> + </table> + <table name="TypeDef" rid="0x02"> + <column name="Flags" type="Mono.Cecil.TypeAttributes" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Namespace" type="uint" target="StringsHeap" /> + <column name="Extends" type="Mono.Cecil.Metadata.MetadataToken" target="TypeDefOrRef" /> + <column name="FieldList" type="uint" target="Field" /> + <column name="MethodList" type="uint" target="Method" /> + </table> + <table name="TypeRef" rid="0x01"> + <column name="ResolutionScope" type="Mono.Cecil.Metadata.MetadataToken" target="ResolutionScope" /> + <column name="Name" type="uint" target="StringsHeap" /> + <column name="Namespace" type="uint" target="StringsHeap" /> + </table> + <table name="TypeSpec" rid="0x1b"> + <column name="Signature" type="uint" target="BlobHeap" /> + </table> + </tables> + + <codedindexes> + <codedindex name="TypeDefOrRef" size="2"> + <table name="TypeDef" tag="0" /> + <table name="TypeRef" tag="1" /> + <table name="TypeSpec" tag="2" /> + </codedindex> + <codedindex name="HasConstant" size="2"> + <table name="Field" tag="0" /> + <table name="Param" tag="1" /> + <table name="Property" tag="2" /> + </codedindex> + <codedindex name="HasCustomAttribute" size="5"> + <table name="Method" tag="0" /> + <table name="Field" tag="1" /> + <table name="TypeRef" tag="2" /> + <table name="TypeDef" tag="3" /> + <table name="Param" tag="4" /> + <table name="InterfaceImpl" tag="5" /> + <table name="MemberRef" tag="6" /> + <table name="Module" tag="7" /> + <table name="DeclSecurity" tag="8" /> + <table name="Property" tag="9" /> + <table name="Event" tag="10" /> + <table name="StandAloneSig" tag="11" /> + <table name="ModuleRef" tag="12" /> + <table name="TypeSpec" tag="13" /> + <table name="Assembly" tag="14" /> + <table name="AssemblyRef" tag="15" /> + <table name="File" tag="16" /> + <table name="ExportedType" tag="17" /> + <table name="ManifestResource" tag="18" /> + <table name="GenericParam" tag="19" /> + </codedindex> + <codedindex name="HasFieldMarshal" size="1"> + <table name="Field" tag="0" /> + <table name="Param" tag="1" /> + </codedindex> + <codedindex name="HasDeclSecurity" size="2"> + <table name="TypeDef" tag="0" /> + <table name="Method" tag="1" /> + <table name="Assembly" tag="2" /> + </codedindex> + <codedindex name="MemberRefParent" size="3"> + <table name="TypeDef" tag="0" /> + <table name="TypeRef" tag="1" /> + <table name="ModuleRef" tag="2" /> + <table name="Method" tag="3" /> + <table name="TypeSpec" tag="4" /> + </codedindex> + <codedindex name="HasSemantics" size="1"> + <table name="Event" tag="0" /> + <table name="Property" tag="1" /> + </codedindex> + <codedindex name="MethodDefOrRef" size="1"> + <table name="Method" tag="0" /> + <table name="MemberRef" tag="1" /> + </codedindex> + <codedindex name="MemberForwarded" size="1"> + <table name="Field" tag="0" /> + <table name="Method" tag="1" /> + </codedindex> + <codedindex name="Implementation" size="2"> + <table name="File" tag="0" /> + <table name="AssemblyRef" tag="1" /> + <table name="ExportedType" tag="2" /> + </codedindex> + <codedindex name="CustomAttributeType" size="3"> + <table name="Method" tag="2" /> + <table name="MemberRef" tag="3" /> + </codedindex> + <codedindex name="ResolutionScope" size="2"> + <table name="Module" tag="0" /> + <table name="ModuleRef" tag="1" /> + <table name="AssemblyRef" tag="2" /> + <table name="TypeRef" tag="3" /> + </codedindex> + <codedindex name="TypeOrMethodDef" size="1" requires="NET_2_0"> + <table name="TypeDef" tag="0" /> + <table name="Method" tag="1" /> + </codedindex> + </codedindexes> + + <!-- + This part contains all the standards opcodes + --> + <opcodes> + <opcode name="nop" op1="0xff" op2="0x00" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="break" op1="0xff" op2="0x01" flowcontrol="Break" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="ldarg.0" op1="0xff" op2="0x02" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldarg.1" op1="0xff" op2="0x03" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldarg.2" op1="0xff" op2="0x04" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldarg.3" op1="0xff" op2="0x05" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldloc.0" op1="0xff" op2="0x06" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldloc.1" op1="0xff" op2="0x07" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldloc.2" op1="0xff" op2="0x08" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldloc.3" op1="0xff" op2="0x09" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="stloc.0" op1="0xff" op2="0x0a" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="stloc.1" op1="0xff" op2="0x0b" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="stloc.2" op1="0xff" op2="0x0c" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="stloc.3" op1="0xff" op2="0x0d" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="ldarg.s" op1="0xff" op2="0x0e" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineParam" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldarga.s" op1="0xff" op2="0x0f" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineParam" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="starg.s" op1="0xff" op2="0x10" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineParam" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="ldloc.s" op1="0xff" op2="0x11" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineVar" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldloca.s" op1="0xff" op2="0x12" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineVar" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="stloc.s" op1="0xff" op2="0x13" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineVar" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="ldnull" op1="0xff" op2="0x14" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushref" /> + <opcode name="ldc.i4.m1" op1="0xff" op2="0x15" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.0" op1="0xff" op2="0x16" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.1" op1="0xff" op2="0x17" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.2" op1="0xff" op2="0x18" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.3" op1="0xff" op2="0x19" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.4" op1="0xff" op2="0x1a" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.5" op1="0xff" op2="0x1b" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.6" op1="0xff" op2="0x1c" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.7" op1="0xff" op2="0x1d" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.8" op1="0xff" op2="0x1e" flowcontrol="Next" opcodetype="Macro" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4.s" op1="0xff" op2="0x1f" flowcontrol="Next" opcodetype="Macro" operandtype="ShortInlineI" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i4" op1="0xff" op2="0x20" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineI" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldc.i8" op1="0xff" op2="0x21" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineI8" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi8" /> + <opcode name="ldc.r4" op1="0xff" op2="0x22" flowcontrol="Next" opcodetype="Primitive" operandtype="ShortInlineR" stackbehaviourpop="Pop0" stackbehaviourpush="Pushr4" /> + <opcode name="ldc.r8" op1="0xff" op2="0x23" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineR" stackbehaviourpop="Pop0" stackbehaviourpush="Pushr8" /> + <opcode name="dup" op1="0xff" op2="0x25" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push1_push1" /> + <opcode name="pop" op1="0xff" op2="0x26" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="jmp" op1="0xff" op2="0x27" flowcontrol="Call" opcodetype="Primitive" operandtype="InlineMethod" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="call" op1="0xff" op2="0x28" flowcontrol="Call" opcodetype="Primitive" operandtype="InlineMethod" stackbehaviourpop="Varpop" stackbehaviourpush="Varpush" /> + <opcode name="calli" op1="0xff" op2="0x29" flowcontrol="Call" opcodetype="Primitive" operandtype="InlineSig" stackbehaviourpop="Varpop" stackbehaviourpush="Varpush" /> + <opcode name="ret" op1="0xff" op2="0x2a" flowcontrol="Return" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Varpop" stackbehaviourpush="Push0" /> + <opcode name="br.s" op1="0xff" op2="0x2b" flowcontrol="Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="brfalse.s" op1="0xff" op2="0x2c" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Popi" stackbehaviourpush="Push0" /> + <opcode name="brtrue.s" op1="0xff" op2="0x2d" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Popi" stackbehaviourpush="Push0" /> + <opcode name="beq.s" op1="0xff" op2="0x2e" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bge.s" op1="0xff" op2="0x2f" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bgt.s" op1="0xff" op2="0x30" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="ble.s" op1="0xff" op2="0x31" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="blt.s" op1="0xff" op2="0x32" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bne.un.s" op1="0xff" op2="0x33" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bge.un.s" op1="0xff" op2="0x34" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bgt.un.s" op1="0xff" op2="0x35" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="ble.un.s" op1="0xff" op2="0x36" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="blt.un.s" op1="0xff" op2="0x37" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="br" op1="0xff" op2="0x38" flowcontrol="Branch" opcodetype="Primitive" operandtype="InlineBrTarget" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="brfalse" op1="0xff" op2="0x39" flowcontrol="Cond_Branch" opcodetype="Primitive" operandtype="InlineBrTarget" stackbehaviourpop="Popi" stackbehaviourpush="Push0" /> + <opcode name="brtrue" op1="0xff" op2="0x3a" flowcontrol="Cond_Branch" opcodetype="Primitive" operandtype="InlineBrTarget" stackbehaviourpop="Popi" stackbehaviourpush="Push0" /> + <opcode name="beq" op1="0xff" op2="0x3b" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bge" op1="0xff" op2="0x3c" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bgt" op1="0xff" op2="0x3d" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="ble" op1="0xff" op2="0x3e" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="blt" op1="0xff" op2="0x3f" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bne.un" op1="0xff" op2="0x40" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bge.un" op1="0xff" op2="0x41" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="bgt.un" op1="0xff" op2="0x42" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="ble.un" op1="0xff" op2="0x43" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="blt.un" op1="0xff" op2="0x44" flowcontrol="Cond_Branch" opcodetype="Macro" operandtype="InlineBrTarget" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push0" /> + <opcode name="switch" op1="0xff" op2="0x45" flowcontrol="Cond_Branch" opcodetype="Primitive" operandtype="InlineSwitch" stackbehaviourpop="Popi" stackbehaviourpush="Push0" /> + <opcode name="ldind.i1" op1="0xff" op2="0x46" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" /> + <opcode name="ldind.u1" op1="0xff" op2="0x47" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" /> + <opcode name="ldind.i2" op1="0xff" op2="0x48" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" /> + <opcode name="ldind.u2" op1="0xff" op2="0x49" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" /> + <opcode name="ldind.i4" op1="0xff" op2="0x4a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" /> + <opcode name="ldind.u4" op1="0xff" op2="0x4b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" /> + <opcode name="ldind.i8" op1="0xff" op2="0x4c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi8" /> + <opcode name="ldind.i" op1="0xff" op2="0x4d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" /> + <opcode name="ldind.r4" op1="0xff" op2="0x4e" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushr4" /> + <opcode name="ldind.r8" op1="0xff" op2="0x4f" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushr8" /> + <opcode name="ldind.ref" op1="0xff" op2="0x50" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushref" /> + <opcode name="stind.ref" op1="0xff" op2="0x51" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" /> + <opcode name="stind.i1" op1="0xff" op2="0x52" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" /> + <opcode name="stind.i2" op1="0xff" op2="0x53" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" /> + <opcode name="stind.i4" op1="0xff" op2="0x54" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" /> + <opcode name="stind.i8" op1="0xff" op2="0x55" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi8" stackbehaviourpush="Push0" /> + <opcode name="stind.r4" op1="0xff" op2="0x56" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popr4" stackbehaviourpush="Push0" /> + <opcode name="stind.r8" op1="0xff" op2="0x57" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popr8" stackbehaviourpush="Push0" /> + <opcode name="add" op1="0xff" op2="0x58" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="sub" op1="0xff" op2="0x59" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="mul" op1="0xff" op2="0x5a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="div" op1="0xff" op2="0x5b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="div.un" op1="0xff" op2="0x5c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="rem" op1="0xff" op2="0x5d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="rem.un" op1="0xff" op2="0x5e" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="and" op1="0xff" op2="0x5f" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="or" op1="0xff" op2="0x60" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="xor" op1="0xff" op2="0x61" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="shl" op1="0xff" op2="0x62" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="shr" op1="0xff" op2="0x63" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="shr.un" op1="0xff" op2="0x64" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="neg" op1="0xff" op2="0x65" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push1" /> + <opcode name="not" op1="0xff" op2="0x66" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Push1" /> + <opcode name="conv.i1" op1="0xff" op2="0x67" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.i2" op1="0xff" op2="0x68" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.i4" op1="0xff" op2="0x69" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.i8" op1="0xff" op2="0x6a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" /> + <opcode name="conv.r4" op1="0xff" op2="0x6b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushr4" /> + <opcode name="conv.r8" op1="0xff" op2="0x6c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushr8" /> + <opcode name="conv.u4" op1="0xff" op2="0x6d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.u8" op1="0xff" op2="0x6e" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" /> + <opcode name="callvirt" op1="0xff" op2="0x6f" flowcontrol="Call" opcodetype="Objmodel" operandtype="InlineMethod" stackbehaviourpop="Varpop" stackbehaviourpush="Varpush" /> + <opcode name="cpobj" op1="0xff" op2="0x70" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" /> + <opcode name="ldobj" op1="0xff" op2="0x71" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi" stackbehaviourpush="Push1" /> + <opcode name="ldstr" op1="0xff" op2="0x72" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineString" stackbehaviourpop="Pop0" stackbehaviourpush="Pushref" /> + <opcode name="newobj" op1="0xff" op2="0x73" flowcontrol="Call" opcodetype="Objmodel" operandtype="InlineMethod" stackbehaviourpop="Varpop" stackbehaviourpush="Pushref" /> + <opcode name="castclass" op1="0xff" op2="0x74" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref" stackbehaviourpush="Pushref" /> + <opcode name="isinst" op1="0xff" op2="0x75" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" /> + <opcode name="conv.r.un" op1="0xff" op2="0x76" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushr8" /> + <opcode name="unbox" op1="0xff" op2="0x79" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" /> + <opcode name="throw" op1="0xff" op2="0x7a" flowcontrol="Throw" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref" stackbehaviourpush="Push0" /> + <opcode name="ldfld" op1="0xff" op2="0x7b" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Popref" stackbehaviourpush="Push1" /> + <opcode name="ldflda" op1="0xff" op2="0x7c" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" /> + <opcode name="stfld" op1="0xff" op2="0x7d" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Popref_pop1" stackbehaviourpush="Push0" /> + <opcode name="ldsfld" op1="0xff" op2="0x7e" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldsflda" op1="0xff" op2="0x7f" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="stsfld" op1="0xff" op2="0x80" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineField" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="stobj" op1="0xff" op2="0x81" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi_pop1" stackbehaviourpush="Push0" /> + <opcode name="conv.ovf.i1.un" op1="0xff" op2="0x82" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.i2.un" op1="0xff" op2="0x83" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.i4.un" op1="0xff" op2="0x84" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.i8.un" op1="0xff" op2="0x85" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" /> + <opcode name="conv.ovf.u1.un" op1="0xff" op2="0x86" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.u2.un" op1="0xff" op2="0x87" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.u4.un" op1="0xff" op2="0x88" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.u8.un" op1="0xff" op2="0x89" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" /> + <opcode name="conv.ovf.i.un" op1="0xff" op2="0x8a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.u.un" op1="0xff" op2="0x8b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="box" op1="0xff" op2="0x8c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Pop1" stackbehaviourpush="Pushref" /> + <opcode name="newarr" op1="0xff" op2="0x8d" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi" stackbehaviourpush="Pushref" /> + <opcode name="ldlen" op1="0xff" op2="0x8e" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" /> + <opcode name="ldelema" op1="0xff" op2="0x8f" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" /> + <opcode name="ldelem.i1" op1="0xff" op2="0x90" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" /> + <opcode name="ldelem.u1" op1="0xff" op2="0x91" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" /> + <opcode name="ldelem.i2" op1="0xff" op2="0x92" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" /> + <opcode name="ldelem.u2" op1="0xff" op2="0x93" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" /> + <opcode name="ldelem.i4" op1="0xff" op2="0x94" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" /> + <opcode name="ldelem.u4" op1="0xff" op2="0x95" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" /> + <opcode name="ldelem.i8" op1="0xff" op2="0x96" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi8" /> + <opcode name="ldelem.i" op1="0xff" op2="0x97" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushi" /> + <opcode name="ldelem.r4" op1="0xff" op2="0x98" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushr4" /> + <opcode name="ldelem.r8" op1="0xff" op2="0x99" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushr8" /> + <opcode name="ldelem.ref" op1="0xff" op2="0x9a" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi" stackbehaviourpush="Pushref" /> + <opcode name="stelem.i" op1="0xff" op2="0x9b" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi" stackbehaviourpush="Push0" /> + <opcode name="stelem.i1" op1="0xff" op2="0x9c" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi" stackbehaviourpush="Push0" /> + <opcode name="stelem.i2" op1="0xff" op2="0x9d" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi" stackbehaviourpush="Push0" /> + <opcode name="stelem.i4" op1="0xff" op2="0x9e" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi" stackbehaviourpush="Push0" /> + <opcode name="stelem.i8" op1="0xff" op2="0x9f" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popi8" stackbehaviourpush="Push0" /> + <opcode name="stelem.r4" op1="0xff" op2="0xa0" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popr4" stackbehaviourpush="Push0" /> + <opcode name="stelem.r8" op1="0xff" op2="0xa1" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popr8" stackbehaviourpush="Push0" /> + <opcode name="stelem.ref" op1="0xff" op2="0xa2" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Popref_popi_popref" stackbehaviourpush="Push0" /> + <opcode name="ldelem.any" op1="0xff" op2="0xa3" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref_popi" stackbehaviourpush="Push1" requires="NET_2_0" /> + <opcode name="stelem.any" op1="0xff" op2="0xa4" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref_popi_popref" stackbehaviourpush="Push0" requires="NET_2_0" /> + <opcode name="unbox.any" op1="0xff" op2="0xa5" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popref" stackbehaviourpush="Push1" requires="NET_2_0" /> + <opcode name="conv.ovf.i1" op1="0xff" op2="0xb3" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.u1" op1="0xff" op2="0xb4" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.i2" op1="0xff" op2="0xb5" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.u2" op1="0xff" op2="0xb6" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.i4" op1="0xff" op2="0xb7" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.u4" op1="0xff" op2="0xb8" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.i8" op1="0xff" op2="0xb9" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" /> + <opcode name="conv.ovf.u8" op1="0xff" op2="0xba" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi8" /> + <opcode name="refanyval" op1="0xff" op2="0xc2" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="ckfinite" op1="0xff" op2="0xc3" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushr8" /> + <opcode name="mkrefany" op1="0xff" op2="0xc6" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Popi" stackbehaviourpush="Push1" /> + <opcode name="ldtoken" op1="0xff" op2="0xd0" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineTok" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="conv.u2" op1="0xff" op2="0xd1" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.u1" op1="0xff" op2="0xd2" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.i" op1="0xff" op2="0xd3" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.i" op1="0xff" op2="0xd4" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="conv.ovf.u" op1="0xff" op2="0xd5" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="add.ovf" op1="0xff" op2="0xd6" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="add.ovf.un" op1="0xff" op2="0xd7" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="mul.ovf" op1="0xff" op2="0xd8" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="mul.ovf.un" op1="0xff" op2="0xd9" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="sub.ovf" op1="0xff" op2="0xda" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="sub.ovf.un" op1="0xff" op2="0xdb" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Push1" /> + <opcode name="endfinally" op1="0xff" op2="0xdc" flowcontrol="Return" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="leave" op1="0xff" op2="0xdd" flowcontrol="Branch" opcodetype="Primitive" operandtype="InlineBrTarget" stackbehaviourpop="PopAll" stackbehaviourpush="Push0" /> + <opcode name="leave.s" op1="0xff" op2="0xde" flowcontrol="Branch" opcodetype="Macro" operandtype="ShortInlineBrTarget" stackbehaviourpop="PopAll" stackbehaviourpush="Push0" /> + <opcode name="stind.i" op1="0xff" op2="0xdf" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi" stackbehaviourpush="Push0" /> + <opcode name="conv.u" op1="0xff" op2="0xe0" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="arglist" op1="0xfe" op2="0x00" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ceq" op1="0xfe" op2="0x01" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" /> + <opcode name="cgt" op1="0xfe" op2="0x02" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" /> + <opcode name="cgt.un" op1="0xfe" op2="0x03" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" /> + <opcode name="clt" op1="0xfe" op2="0x04" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" /> + <opcode name="clt.un" op1="0xfe" op2="0x05" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1_pop1" stackbehaviourpush="Pushi" /> + <opcode name="ldftn" op1="0xfe" op2="0x06" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineMethod" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="ldvirtftn" op1="0xfe" op2="0x07" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineMethod" stackbehaviourpop="Popref" stackbehaviourpush="Pushi" /> + <opcode name="ldarg" op1="0xfe" op2="0x09" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineParam" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldarga" op1="0xfe" op2="0x0a" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineParam" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="starg" op1="0xfe" op2="0x0b" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineParam" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="ldloc" op1="0xfe" op2="0x0c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineVar" stackbehaviourpop="Pop0" stackbehaviourpush="Push1" /> + <opcode name="ldloca" op1="0xfe" op2="0x0d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineVar" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="stloc" op1="0xfe" op2="0x0e" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineVar" stackbehaviourpop="Pop1" stackbehaviourpush="Push0" /> + <opcode name="localloc" op1="0xfe" op2="0x0f" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Pushi" /> + <opcode name="endfilter" op1="0xfe" op2="0x11" flowcontrol="Return" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi" stackbehaviourpush="Push0" /> + <opcode name="unaligned." op1="0xfe" op2="0x12" flowcontrol="Meta" opcodetype="Prefix" operandtype="ShortInlineI" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="volatile." op1="0xfe" op2="0x13" flowcontrol="Meta" opcodetype="Prefix" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="tail." op1="0xfe" op2="0x14" flowcontrol="Meta" opcodetype="Prefix" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="initobj" op1="0xfe" op2="0x15" flowcontrol="Next" opcodetype="Objmodel" operandtype="InlineType" stackbehaviourpop="Popi" stackbehaviourpush="Push0" /> + <opcode name="constrained." op1="0xfe" op2="0x16" flowcontrol="Next" opcodetype="Prefix" operandtype="InlineTok" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="cpblk" op1="0xfe" op2="0x17" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi_popi" stackbehaviourpush="Push0" /> + <opcode name="initblk" op1="0xfe" op2="0x18" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Popi_popi_popi" stackbehaviourpush="Push0" /> + <opcode name="no." op1="0xfe" op2="0x19" flowcontrol="Next" opcodetype="Prefix" operandtype="ShortInlineI" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="rethrow" op1="0xfe" op2="0x1a" flowcontrol="Throw" opcodetype="Objmodel" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + <opcode name="sizeof" op1="0xfe" op2="0x1c" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineType" stackbehaviourpop="Pop0" stackbehaviourpush="Pushi" /> + <opcode name="refanytype" op1="0xfe" op2="0x1d" flowcontrol="Next" opcodetype="Primitive" operandtype="InlineNone" stackbehaviourpop="Pop1" stackbehaviourpush="Pushi" /> + <opcode name="readonly." op1="0xfe" op2="0x1e" flowcontrol="Next" opcodetype="Prefix" operandtype="InlineNone" stackbehaviourpop="Pop0" stackbehaviourpush="Push0" /> + </opcodes> + + </metadata> + + <!-- + This part contains all the collections + that will be used in the Reflection ns + --> + <collections> + <collection type="AssemblyNameReference" container="ModuleDefinition" visit="IReflectionStructure" target="Mono.Cecil" indexed="true" /> + <collection type="ModuleReference" container="ModuleDefinition" visit="IReflectionStructure" indexed="true" target="Mono.Cecil" /> + <collection type="ModuleDefinition" container="AssemblyDefinition" visit="IReflectionStructure" indexed="true" target="Mono.Cecil" /> + <collection type="Resource" container="ModuleDefinition" visit="IReflectionStructure" target="Mono.Cecil" indexed="true" /> + <collection type="TypeDefinition" container="ModuleDefinition" visit="IReflection" target="Mono.Cecil" /> + <collection type="TypeReference" container="ModuleDefinition" visit="IReflection" target="Mono.Cecil" /> + <collection type="TypeReference" container="TypeDefinition" visit="IReflection" name="Interface" indexed="true" target="Mono.Cecil" /> + <collection type="ParameterDefinition" container="IMemberReference" visit="IReflection" indexed="true" target="Mono.Cecil" /> + <collection type="MethodReference" container="MethodDefinition" visit="IReflection" name="Override" indexed="true" target="Mono.Cecil" /> + <collection type="MethodDefinition" container="TypeDefinition" visit="IReflection" indexed="true" target="Mono.Cecil" /> + <collection type="MethodDefinition" container="TypeDefinition" visit="IReflection" name="Constructor" indexed="true" target="Mono.Cecil" /> + <collection type="EventDefinition" container="TypeDefinition" visit="IReflection" target="Mono.Cecil" indexed="true" /> + <collection type="FieldDefinition" container="TypeDefinition" visit="IReflection" target="Mono.Cecil" indexed="true" /> + <collection type="PropertyDefinition" container="TypeDefinition" visit="IReflection" target="Mono.Cecil" indexed="true" /> + <collection type="Instruction" container="MethodBody" visit="ICode" indexed="true" target="Mono.Cecil.Cil" /> + <collection type="ExceptionHandler" container="MethodBody" visit="ICode" indexed="true" target="Mono.Cecil.Cil" /> + <collection type="VariableDefinition" container="IVariableDefinitionProvider" visit="ICode" indexed="true" target="Mono.Cecil.Cil" /> + <collection type="ArrayDimension" container="ArrayType" target="Mono.Cecil" indexed="true" /> + <!-- modified behaviour + <collection type="SecurityDeclaration" container="IHasSecurity" usecontainerinterface="true" target="Mono.Cecil" indexed="true" visit="IReflection" /> + --> + <collection type="CustomAttribute" container="ICustomAttributeProvider" usecontainerinterface="true" target="Mono.Cecil" indexed="true" visit="IReflection" /> + <collection type="TypeReference" container="ModuleDefinition" target="Mono.Cecil" visit="IReflection" name="ExternType" /> + <collection type="TypeDefinition" container="TypeDefinition" target="Mono.Cecil" visit="IReflection" name="NestedType" indexed="true" /> + <collection type="MemberReference" container="ModuleDefinition" target="Mono.Cecil" visit="IReflection" indexed="true" /> + <collection type="GenericParameter" container="IGenericParameterProvider" usecontainerinterface="true" target="Mono.Cecil" indexed="true" visit="IReflection" /> + <collection type="TypeReference" name="GenericArgument" container="IGenericInstance" target="Mono.Cecil" indexed="true" /> + <collection type="TypeReference" name="Constraint" container="GenericParameter" target="Mono.Cecil" indexed="true" /> + <collection type="Scope" container="IScopeProvider" visit="ICode" target="Mono.Cecil.Cil" indexed="true" /> + </collections> + +</cecil> diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/BaseMetadataVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/BaseMetadataVisitor.cs new file mode 100644 index 0000000..c77583f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/BaseMetadataVisitor.cs @@ -0,0 +1,112 @@ +// +// BaseMetadataVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public abstract class BaseMetadataVisitor : IMetadataVisitor { + + public virtual void VisitMetadataRoot (MetadataRoot root) + { + } + + public virtual void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header) + { + } + + public virtual void VisitMetadataStreamCollection (MetadataStreamCollection streams) + { + } + + public virtual void VisitMetadataStream (MetadataStream stream) + { + } + + public virtual void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header) + { + } + + public virtual void VisitGuidHeap (GuidHeap heap) + { + } + + public virtual void VisitStringsHeap (StringsHeap heap) + { + } + + public virtual void VisitTablesHeap (TablesHeap heap) + { + } + + public virtual void VisitBlobHeap (BlobHeap heap) + { + } + + public virtual void VisitUserStringsHeap (UserStringsHeap heap) + { + } + + public virtual void TerminateMetadataRoot (MetadataRoot root) + { + } + } + + public abstract class BaseMetadataTableVisitor : IMetadataTableVisitor { + + public virtual void VisitTableCollection (TableCollection coll) + { + } + +<% $tables.each { |table| %> public virtual void Visit<%=table.table_name%> (<%=table.table_name%> table) + { + } + +<% } %> public virtual void TerminateTableCollection (TableCollection coll) + { + } + + public abstract IMetadataRowVisitor GetRowVisitor(); + } + + public abstract class BaseMetadataRowVisitor : IMetadataRowVisitor { + + public virtual void VisitRowCollection (RowCollection coll) + { + } + +<% $tables.each { |table| %> public virtual void Visit<%=table.row_name%> (<%=table.row_name%> row) + { + } + +<% } %> public virtual void TerminateRowCollection (RowCollection coll) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Code.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Code.cs new file mode 100644 index 0000000..7274f8c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Code.cs @@ -0,0 +1,37 @@ +// +// Code.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public enum Code { +<% $ops.each { |op| %> <%=op.field_name%>, +<% } %> } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/CodedIndex.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/CodedIndex.cs new file mode 100644 index 0000000..9f6a9d8 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/CodedIndex.cs @@ -0,0 +1,38 @@ +// +// CodedIndex.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public enum CodedIndex { +<% $coded_indexes.each { |ci| %> <%=ci.name%><% if ci != $coded_indexes.last %>,<% end %> +<% } +%> } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/IMetadataVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/IMetadataVisitor.cs new file mode 100644 index 0000000..421f8cc --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/IMetadataVisitor.cs @@ -0,0 +1,65 @@ +// +// IMetadataVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public interface IMetadataVisitor { + void VisitMetadataRoot (MetadataRoot root); + void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header); + void VisitMetadataStreamCollection (MetadataStreamCollection streams); + void VisitMetadataStream (MetadataStream stream); + void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header); + void VisitGuidHeap (GuidHeap heap); + void VisitStringsHeap (StringsHeap heap); + void VisitTablesHeap (TablesHeap heap); + void VisitBlobHeap (BlobHeap heap); + void VisitUserStringsHeap (UserStringsHeap heap); + + void TerminateMetadataRoot (MetadataRoot root); + } + + public interface IMetadataTableVisitor { + void VisitTableCollection (TableCollection coll); + +<% $tables.each { |table| %> void Visit<%=table.table_name%> (<%=table.table_name%> table); +<% } %> + void TerminateTableCollection (TableCollection coll); + IMetadataRowVisitor GetRowVisitor(); +} + + public interface IMetadataRowVisitor { + void VisitRowCollection (RowCollection coll); + +<% $tables.each { |table| %> void Visit<%=table.row_name%> (<%=table.row_name%> row); +<% } %> + void TerminateRowCollection (RowCollection coll); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/IndexedCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/IndexedCollection.cs new file mode 100644 index 0000000..e95e819 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/IndexedCollection.cs @@ -0,0 +1,296 @@ +// +// <%=$cur_coll.name%>.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +<% +def member_visibility() + return $cur_coll.type == "Instruction" ? "internal" : "public" +end + +def use_event?() + case $cur_coll.name + when "NestedTypeCollection", "MethodDefinitionCollection", "ConstructorCollection", "FieldDefinitionCollection", "EventDefinitionCollection", "PropertyDefinitionCollection" + return true + end + + return false +end + +%> +namespace <%=$cur_coll.target%> { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class <%=$cur_coll.name%> : CollectionBase<% if (!$cur_coll.visitable.nil?) then %>, <%=$cur_coll.visitable%><% end %> { + + <%=$cur_coll.container_impl%> m_container;<% + if $cur_coll.type == "Instruction" %> + public readonly Instruction Outside = new Instruction (int.MaxValue, OpCodes.Nop);<% end %> + + public <%=$cur_coll.type%> this [int index] { + get { return List [index] as <%=$cur_coll.type%>; } + set { List [index] = value; } + } + + public <%=$cur_coll.container%> Container { + get { return m_container; } + } + + public <%=$cur_coll.name%> (<%=$cur_coll.container_impl%> container) + { + m_container = container; + } + + <%= member_visibility() %> void Add (<%=$cur_coll.type%> value) + {<% +if use_event?() %> + Attach (value); +<% end %> + List.Add (value); + } +<% +if use_event?() %> + + public new void Clear () + { + foreach (<%=$cur_coll.type%> item in this) + Detach (item); + + base.Clear (); + } +<% end %> + public bool Contains (<%=$cur_coll.type%> value) + { + return List.Contains (value); + } + + public int IndexOf (<%=$cur_coll.type%> value) + { + return List.IndexOf (value); + } + + <%= member_visibility() %> void Insert (int index, <%=$cur_coll.type%> value) + {<% +if use_event?() %> + Attach (value); +<% end %> + List.Insert (index, value); + } + + <%= member_visibility() %> void Remove (<%=$cur_coll.type%> value) + { + List.Remove (value); +<% if use_event?() %> + Detach (value); +<% end %> } +<% +if use_event?() %> + + <%= member_visibility() %> new void RemoveAt (int index) + { + <%=$cur_coll.type%> item = this [index]; + Remove (item); + } +<% end %> + protected override void OnValidate (object o) + { + if (! (o is <%=$cur_coll.type%>)) + throw new ArgumentException ("Must be of type " + typeof (<%=$cur_coll.type%>).FullName); + } +<% + case $cur_coll.item_name + when "MethodDefinition" +%> + public MethodDefinition [] GetMethod (string name) + { + ArrayList ret = new ArrayList (); + foreach (MethodDefinition meth in this) + if (meth.Name == name) + ret.Add (meth); + + return ret.ToArray (typeof (MethodDefinition)) as MethodDefinition []; + } + + internal MethodDefinition GetMethodInternal (string name, IList parameters) + { + foreach (MethodDefinition meth in this) { + if (meth.Name != name || meth.Parameters.Count != parameters.Count) + continue; + + bool match = true; + for (int i = 0; i < parameters.Count; i++) { + string pname; + object param = parameters [i]; + if (param is Type) + pname = ReflectionHelper.GetTypeSignature (param as Type); + else if (param is TypeReference) + pname = (param as TypeReference).FullName; + else if (param is ParameterDefinition) + pname = (param as ParameterDefinition).ParameterType.FullName; + else + throw new NotSupportedException (); + + if (meth.Parameters [i].ParameterType.FullName != pname) { + match = false; + break; + } + } + + if (match) + return meth; + } + + return null; + } + + public MethodDefinition GetMethod (string name, Type [] parameters) + { + return GetMethodInternal (name, parameters); + } + + public MethodDefinition GetMethod (string name, TypeReference [] parameters) + { + return GetMethodInternal (name, parameters); + } + + public MethodDefinition GetMethod (string name, ParameterDefinitionCollection parameters) + { + return GetMethodInternal (name, parameters); + } +<% + when "FieldDefinition" +%> + public FieldDefinition GetField (string name) + { + foreach (FieldDefinition field in this) + if (field.Name == name) + return field; + + return null; + } +<% + when "Constructor" +%> + internal MethodDefinition GetConstructorInternal (bool isStatic, IList parameters) + { + foreach (MethodDefinition ctor in this) { + if (ctor.IsStatic != isStatic || ctor.Parameters.Count != parameters.Count) + continue; + + bool match = true; + for (int i = 0; i < parameters.Count; i++) { + string pname; + object param = parameters [i]; + if (param is Type) + pname = ReflectionHelper.GetTypeSignature (param as Type); + else if (param is TypeReference) + pname = (param as TypeReference).FullName; + else if (param is ParameterDefinition) + pname = (param as ParameterDefinition).ParameterType.FullName; + else + throw new NotSupportedException (); + + if (ctor.Parameters [i].ParameterType.FullName != pname) { + match = false; + break; + } + } + + if (match) + return ctor; + } + + return null; + } + + public MethodDefinition GetConstructor (bool isStatic, Type [] parameters) + { + return GetConstructorInternal (isStatic, parameters); + } + + public MethodDefinition GetConstructor (bool isStatic, TypeReference [] parameters) + { + return GetConstructorInternal (isStatic, parameters); + } + + public MethodDefinition GetConstructor (bool isStatic, ParameterDefinitionCollection parameters) + { + return GetConstructorInternal (isStatic, parameters); + } +<% + when "EventDefinition" +%> + public EventDefinition GetEvent (string name) + { + foreach (EventDefinition evt in this) + if (evt.Name == name) + return evt; + + return null; + } +<% + when "PropertyDefinition" +%> + public PropertyDefinition [] GetProperties (string name) + { + ArrayList ret = new ArrayList (); + foreach (PropertyDefinition prop in this) + if (prop.Name == name) + ret.Add (prop); + + return ret.ToArray (typeof (PropertyDefinition)) as PropertyDefinition []; + } +<% + end + + if use_event?() +%> + void Attach (MemberReference member) + { + if (member.DeclaringType != null) + throw new ReflectionException ("Member already attached, clone it instead"); + + member.DeclaringType = m_container; + } + + void Detach (MemberReference member) + { + member.DeclaringType = null; + } +<% end + if !$cur_coll.visitor.nil? then %> + public void Accept (<%=$cur_coll.visitor%> visitor) + { + visitor.<%=$cur_coll.visitThis%> (this); + } +<% end %> } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataRowReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataRowReader.cs new file mode 100644 index 0000000..fc8d271 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataRowReader.cs @@ -0,0 +1,110 @@ +// +// MetadataRowReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + using System.IO; + + using Mono.Cecil.Binary; + + class MetadataRowReader : BaseMetadataRowVisitor { + + MetadataTableReader m_mtrv; + BinaryReader m_binaryReader; + MetadataRoot m_metadataRoot; + IDictionary m_ciCache; + + int m_blobHeapIdxSz; + int m_stringsHeapIdxSz; + int m_guidHeapIdxSz; + + public MetadataRowReader (MetadataTableReader mtrv) + { + m_mtrv = mtrv; + m_binaryReader = mtrv.GetReader (); + m_metadataRoot = mtrv.GetMetadataRoot (); + m_ciCache = new Hashtable (); + } + + int GetIndexSize (int rid) + { + return m_mtrv.GetNumberOfRows (rid) < (1 << 16) ? 2 : 4; + } + + int GetCodedIndexSize (CodedIndex ci) + { + return Utilities.GetCodedIndexSize (ci, + new Utilities.TableRowCounter (m_mtrv.GetNumberOfRows), m_ciCache); + } + + uint ReadByIndexSize (int size) + { + if (size == 2) { + return (uint) m_binaryReader.ReadUInt16 (); + } else if (size == 4) { + return m_binaryReader.ReadUInt32 (); + } else { + throw new MetadataFormatException ("Non valid size for indexing"); + } + } + + public override void VisitRowCollection (RowCollection coll) + { + m_blobHeapIdxSz = m_metadataRoot.Streams.BlobHeap != null ? + m_metadataRoot.Streams.BlobHeap.IndexSize : 2; + m_stringsHeapIdxSz = m_metadataRoot.Streams.StringsHeap != null ? + m_metadataRoot.Streams.StringsHeap.IndexSize : 2; + m_guidHeapIdxSz = m_metadataRoot.Streams.GuidHeap != null ? + m_metadataRoot.Streams.GuidHeap.IndexSize : 2; + } + +<% $tables.each { |table| %> public override void Visit<%=table.row_name%> (<%=table.row_name%> row) + { +<% table.columns.each { |col| + if (col.target.nil?) +%> row.<%=col.property_name%> = <%=col.read_binary("m_binaryReader")%>; +<% elsif (col.target == "BlobHeap") +%> row.<%=col.property_name%> = ReadByIndexSize (m_blobHeapIdxSz); +<% elsif (col.target == "StringsHeap") +%> row.<%=col.property_name%> = ReadByIndexSize (m_stringsHeapIdxSz); +<% elsif (col.target == "GuidHeap") +%> row.<%=col.property_name%> = ReadByIndexSize (m_guidHeapIdxSz); +<% elsif (col.type == "MetadataToken") +%> row.<%=col.property_name%> = Utilities.GetMetadataToken (CodedIndex.<%=col.target%>, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.<%=col.target%>))); +<% else +%> row.<%=col.property_name%> = ReadByIndexSize (GetIndexSize (<%=col.target%>Table.RId)); +<% end +}%> } +<% } %> } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataRowWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataRowWriter.cs new file mode 100644 index 0000000..1ef6ddc --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataRowWriter.cs @@ -0,0 +1,145 @@ +// +// MetadataRowWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + using Mono.Cecil.Binary; + + class MetadataRowWriter : BaseMetadataRowVisitor { + + MetadataRoot m_root; + MemoryBinaryWriter m_binaryWriter; + IDictionary m_ciCache; + + int m_blobHeapIdxSz; + int m_stringsHeapIdxSz; + int m_guidHeapIdxSz; + + public MetadataRowWriter (MetadataTableWriter mtwv) + { + m_binaryWriter = mtwv.GetWriter (); + m_root = mtwv.GetMetadataRoot (); + m_ciCache = new Hashtable (); + } + + void WriteBlobPointer (uint pointer) + { + WriteByIndexSize (pointer, m_blobHeapIdxSz); + } + + void WriteStringPointer (uint pointer) + { + WriteByIndexSize (pointer, m_stringsHeapIdxSz); + } + + void WriteGuidPointer (uint pointer) + { + WriteByIndexSize (pointer, m_guidHeapIdxSz); + } + + void WriteTablePointer (uint pointer, int rid) + { + WriteByIndexSize (pointer, GetNumberOfRows (rid) < (1 << 16) ? 2 : 4); + } + + void WriteMetadataToken (MetadataToken token, CodedIndex ci) + { + WriteByIndexSize (Utilities.CompressMetadataToken (ci, token), + Utilities.GetCodedIndexSize ( + ci, new Utilities.TableRowCounter (GetNumberOfRows), m_ciCache)); + } + + int GetNumberOfRows (int rid) + { + IMetadataTable t = m_root.Streams.TablesHeap [rid]; + if (t == null || t.Rows == null) + return 0; + return t.Rows.Count; + } + + void WriteByIndexSize (uint value, int size) + { + if (size == 4) + m_binaryWriter.Write (value); + else if (size == 2) + m_binaryWriter.Write ((ushort) value); + else + throw new MetadataFormatException ("Non valid size for indexing"); + } + +<% $tables.each { |table| + parameters = "" + table.columns.each { |col| + parameters += col.type + parameters += " " + parameters += col.field_name[1..col.field_name.length] + parameters += ", " if (table.columns.last != col) + } +%> public <%=table.row_name%> Create<%=table.row_name%> (<%=parameters%>) + { + <%=table.row_name%> row = new <%=table.row_name%> (); +<% table.columns.each { |col| %> row.<%=col.property_name%> = <%=col.field_name[1..col.field_name.length]%>; +<% } %> return row; + } + +<% } %> public override void VisitRowCollection (RowCollection coll) + { + m_blobHeapIdxSz = m_root.Streams.BlobHeap != null ? + m_root.Streams.BlobHeap.IndexSize : 2; + m_stringsHeapIdxSz = m_root.Streams.StringsHeap != null ? + m_root.Streams.StringsHeap.IndexSize : 2; + m_guidHeapIdxSz = m_root.Streams.GuidHeap != null ? + m_root.Streams.GuidHeap.IndexSize : 2; + } + +<% $tables.each { |table| %> public override void Visit<%=table.row_name%> (<%=table.row_name%> row) + { +<% table.columns.each { |col| + if (col.target.nil?) +%> <%=col.write_binary("row", "m_binaryWriter")%>; +<% elsif (col.target == "BlobHeap") +%> WriteBlobPointer (row.<%=col.property_name%>); +<% elsif (col.target == "StringsHeap") +%> WriteStringPointer (row.<%=col.property_name%>); +<% elsif (col.target == "GuidHeap") +%> WriteGuidPointer (row.<%=col.property_name%>); +<% elsif (col.type == "MetadataToken") +%> WriteMetadataToken (row.<%=col.property_name%>, CodedIndex.<%=col.target%>); +<% else +%> WriteTablePointer (row.<%=col.property_name%>, <%=col.target%>Table.RId); +<% end +}%> } + +<% } %> } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataTableReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataTableReader.cs new file mode 100644 index 0000000..8f1effc --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataTableReader.cs @@ -0,0 +1,97 @@ +// +// MetadataTableReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + using System.IO; + + class MetadataTableReader : BaseMetadataTableVisitor { + + MetadataRoot m_metadataRoot; + TablesHeap m_heap; + MetadataRowReader m_mrrv; + BinaryReader m_binaryReader; + + int [] m_rows = new int [TablesHeap.MaxTableCount]; + + public MetadataTableReader (MetadataReader mrv) + { + m_metadataRoot = mrv.GetMetadataRoot (); + m_heap = m_metadataRoot.Streams.TablesHeap; + m_binaryReader = new BinaryReader (new MemoryStream (m_heap.Data)); + m_binaryReader.BaseStream.Position = 24; + m_mrrv = new MetadataRowReader (this); + } + + public MetadataRoot GetMetadataRoot () + { + return m_metadataRoot; + } + + public BinaryReader GetReader () + { + return m_binaryReader; + } + + public override IMetadataRowVisitor GetRowVisitor () + { + return m_mrrv; + } + + public int GetNumberOfRows (int rid) + { + return m_rows [rid]; + } +<% $tables.each { |table| %> + public <%=table.table_name%> Get<%=table.table_name%> () + { + return (<%=table.table_name%>) m_heap [<%=table.table_name%>.RId]; + } +<% } %> + public override void VisitTableCollection (TableCollection coll) + { +<% $stables.each { |table| %> if (m_heap.HasTable (<%=table.table_name%>.RId)) { + coll.Add (new <%=table.table_name%> ()); + m_rows [<%=table.table_name%>.RId] = m_binaryReader.ReadInt32 (); + } +<% } %> } + +<% $tables.each { |table| %> public override void Visit<%=table.table_name%> (<%=table.table_name%> table) + { + int number = m_rows [<%=table.table_name%>.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new <%=table.row_name%> ()); + } +<% } %> } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataTableWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataTableWriter.cs new file mode 100644 index 0000000..8e03b27 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/MetadataTableWriter.cs @@ -0,0 +1,98 @@ +// +// MetadataTableWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + using Mono.Cecil.Binary; + + internal sealed class MetadataTableWriter : BaseMetadataTableVisitor { + + MetadataRoot m_root; + TablesHeap m_heap; + MetadataRowWriter m_mrrw; + MemoryBinaryWriter m_binaryWriter; + + public MetadataTableWriter (MetadataWriter mrv, MemoryBinaryWriter writer) + { + m_root = mrv.GetMetadataRoot (); + m_heap = m_root.Streams.TablesHeap; + m_binaryWriter = writer; + m_mrrw = new MetadataRowWriter (this); + } + + public MetadataRoot GetMetadataRoot () + { + return m_root; + } + + public override IMetadataRowVisitor GetRowVisitor () + { + return m_mrrw; + } + + public MemoryBinaryWriter GetWriter () + { + return m_binaryWriter; + } + + void InitializeTable (IMetadataTable table) + { + table.Rows = new RowCollection (); + m_heap.Valid |= 1L << table.Id; + m_heap.Tables.Add (table); + } + + void WriteCount (int rid) + { + if (m_heap.HasTable (rid)) + m_binaryWriter.Write (m_heap [rid].Rows.Count); + } + +<% $tables.each { |table| %> public <%=table.table_name%> Get<%=table.table_name%> () + { + <%=table.table_name%> table = m_heap [<%=table.table_name%>.RId] as <%=table.table_name%>; + if (table != null) + return table; + + table = new <%=table.table_name%> (); + InitializeTable (table); + return table; + } + +<% } %> public override void VisitTableCollection (TableCollection coll) + { +<% $stables.each { |table| %> WriteCount (<%=table.table_name%>.RId); +<% } %> } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/NamedCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/NamedCollection.cs new file mode 100644 index 0000000..64e48de --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/NamedCollection.cs @@ -0,0 +1,232 @@ +// +// <%=$cur_coll.name%>.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +<% +def use_event?() + case $cur_coll.name + when "TypeDefinitionCollection", "TypeReferenceCollection", "ExternTypeCollection" + return true + end + + return false +end +%> +namespace <%=$cur_coll.target%> { + + using System; + using System.Collections; + using System.Collections.Specialized; + + using Mono.Cecil.Cil; + + using Hcp = Mono.Cecil.HashCodeProvider; + using Cmp = System.Collections.Comparer; + + public sealed class <%=$cur_coll.name%> : NameObjectCollectionBase, IList<% if (!$cur_coll.visitable.nil?) then %>, <%=$cur_coll.visitable%><% end %> { + + <%=$cur_coll.container%> m_container; + + public <%=$cur_coll.type%> this [int index] { + get { return this.BaseGet (index) as <%=$cur_coll.type%>; } + set { this.BaseSet (index, value); } + } + + public <%=$cur_coll.type%> this [string fullName] { + get { return this.BaseGet (fullName) as <%=$cur_coll.type%>; } + set { this.BaseSet (fullName, value); } + } + + public <%=$cur_coll.container%> Container { + get { return m_container; } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + bool IList.IsReadOnly { + get { return false; } + } + + bool IList.IsFixedSize { + get { return false; } + } + + object IList.this [int index] { + get { return BaseGet (index); } + set { + Check (value); + BaseSet (index, value); + } + } + + public <%=$cur_coll.name%> (<%=$cur_coll.container%> container) : + base (Hcp.Instance, Cmp.Default) + { + m_container = container; + } + + public void Add (<%=$cur_coll.type%> value) + { + if (value == null) + throw new ArgumentNullException ("value"); + + <% if use_event?() %>Attach (value);<% end %> + + this.BaseAdd (value.FullName, value); + } + + public void Clear () + {<% + if use_event?() %> + foreach (<%=$cur_coll.type%> item in this) + Detach (item); +<% end %> + this.BaseClear (); + } + + public bool Contains (<%=$cur_coll.type%> value) + { + return Contains (value.FullName); + } + + public bool Contains (string fullName) + { + return this.BaseGet (fullName) != null; + } + + public int IndexOf (<%=$cur_coll.type%> value) + { + string [] keys = this.BaseGetAllKeys (); + return Array.IndexOf (keys, value.FullName, 0, keys.Length); + } + + public void Remove (<%=$cur_coll.type%> value) + { + this.BaseRemove (value.FullName); +<% if use_event?() %> + Detach (value); +<% end %> } + + public void RemoveAt (int index) + { + <%=$cur_coll.type%> item = this [index]; + Remove (item); +<% if use_event?() %> + Detach (item); +<% end %> } + + public void CopyTo (Array ary, int index) + { + this.BaseGetAllValues ().CopyTo (ary, index); + } + + public new IEnumerator GetEnumerator () + { + return this.BaseGetAllValues ().GetEnumerator (); + } +<% if !$cur_coll.visitor.nil? then %> + public void Accept (<%=$cur_coll.visitor%> visitor) + { + visitor.<%=$cur_coll.visitThis%> (this); + } +<% end %> +#if CF_1_0 || CF_2_0 + internal object [] BaseGetAllValues () + { + object [] values = new object [this.Count]; + for (int i=0; i < values.Length; ++i) { + values [i] = this.BaseGet (i); + } + return values; + } +#endif + + void Check (object value) + { + if (!(value is <%=$cur_coll.type%>)) + throw new ArgumentException (); + } + + int IList.Add (object value) + { + Check (value); + Add (value as <%=$cur_coll.type%>); + return 0; + } + + bool IList.Contains (object value) + { + Check (value); + return Contains (value as <%=$cur_coll.type%>); + } + + int IList.IndexOf (object value) + { + throw new NotSupportedException (); + } + + void IList.Insert (int index, object value) + { + throw new NotSupportedException (); + } + + void IList.Remove (object value) + { + Check (value); + Remove (value as <%=$cur_coll.type%>); + } +<% + if use_event?() +%> + void Detach (TypeReference type) + { + type.Module = null; + } + + void Attach (TypeReference type) + { + if (type.Module != null) + throw new ReflectionException ("Type is already attached, clone it instead"); + + type.Module = m_container;<% + if $cur_coll.type == "TypeDefinition" %> + type.AttachToScope (m_container); +<% end %> + }<% + + end +%> + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/OpCodes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/OpCodes.cs new file mode 100644 index 0000000..5fc727d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/OpCodes.cs @@ -0,0 +1,67 @@ +// +// OpCodes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +<% + oboc = Array.new + tboc = Array.new + $ops.each { |op| + if op.op1 == "0xff" + oboc.push(op) + else + tboc.push(op) + end + } +%> +namespace Mono.Cecil.Cil { + + public sealed class OpCodes { + + internal static readonly OpCode [] OneByteOpCode = new OpCode [<%=oboc[oboc.length - 1].op2%> + 1]; + internal static readonly OpCode [] TwoBytesOpCode = new OpCode [<%=tboc[tboc.length - 1].op2%> + 1]; + +<% $ops.each { |op| %> public static readonly OpCode <%=op.field_name%> = new OpCode ( + "<%=op.name%>", <%=op.op1%>, <%=op.op2%>, <%=op.size%>, + Code.<%=op.field_name%>, <%=op.flowcontrol%>, + <%=op.opcodetype%>, <%=op.operandtype%>, + <%=op.stackbehaviourpop%>, <%=op.stackbehaviourpush%>); + +<% } %> OpCodes() + { + } + + public static OpCode GetOpCode (Code code) + { + switch (code) { +<% $ops.each { |op| %> case Code.<%=op.field_name%> : return OpCodes.<%=op.field_name%>; +<% } %> default : return OpCodes.Nop; + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Table.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Table.cs new file mode 100644 index 0000000..17ea97b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Table.cs @@ -0,0 +1,81 @@ +// +// <%=$cur_table.table_name%>.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { +<% $cur_table.ref_ns.each { |ns| %> + using <%=ns%>; +<% } +%> + public sealed class <%=$cur_table.table_name%> : IMetadataTable { + + public const int RId = <%=$cur_table.rid%>; + + RowCollection m_rows; + + public <%=$cur_table.row_name%> this [int index] { + get { return m_rows [index] as <%=$cur_table.row_name%>; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal <%=$cur_table.table_name%> () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.Visit<%=$cur_table.table_name%> (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class <%=$cur_table.row_name%> : IMetadataRow { + +<% $cur_table.columns.each { |col| %> public <%=col.type%> <%=col.property_name%>; +<% } %> + internal <%=$cur_table.row_name%> () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.Visit<%=$cur_table.row_name%> (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Tests.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Tests.cs new file mode 100644 index 0000000..0cd4e3c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Tests.cs @@ -0,0 +1,116 @@ +// +// Tests.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen-tests.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Tests { + + using System; + using System.IO; + using System.Collections; + + using NUnit.Framework; + + using Mono.Cecil; + + class Language { + + string m_compiler; + string m_command; + + public string Compiler { + get { return m_compiler; } + } + + public string Command { + get { return m_command; } + } + + public Language (string compiler, string command) + { + m_compiler = compiler; + m_command = command; + } + + static IDictionary m_languages = new Hashtable (); + + static Language () + { +<% + $languages.each { |l| +%> + m_languages.Add ("<%= l.name %>", new Language ( + "<%= l.compiler %>", + "<%= l.command %>" + )); +<% + } +%> + } + + public static Language GetLanguage (string name) + { + return (Language) m_languages [name]; + } + } + + class TestCase { + + Language m_lang; + FileInfo m_file; + + public TestCase (Language lang, string file) + { + m_lang = lang; + m_file = new FileInfo (file); + } + } + + [TestFixture] + class GeneratedTests { + + void Test (TestCase test) + { + } + +<% + $tests.each { |test| +%> + [Test] + public void <%= test.method %> () + { + Test (new TestCase ( + Language.GetLanguage ("<%= test.lang.name %>"), + @"<%= test.file %>")); + } +<% + } +%> + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Utilities.cs b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Utilities.cs new file mode 100644 index 0000000..89f732a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/CodeGen/templates/Utilities.cs @@ -0,0 +1,211 @@ +// +// Utilities.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// <%=Time.now%> +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + using System.IO; + + class Utilities { + + Utilities () + { + } + + public static int ReadCompressedInteger (byte [] data, int pos, out int start) + { + int integer = 0; + start = pos; + if ((data [pos] & 0x80) == 0) { + integer = data [pos]; + start++; + } else if ((data [pos] & 0x40) == 0) { + integer = (data [start] & ~0x80) << 8; + integer |= data [pos + 1]; + start += 2; + } else { + integer = (data [start] & ~0xc0) << 24; + integer |= data [pos + 1] << 16; + integer |= data [pos + 2] << 8; + integer |= data [pos + 3]; + start += 4; + } + return integer; + } + + public static int WriteCompressedInteger (BinaryWriter writer, int value) + { + if (value < 0x80) + writer.Write ((byte) value); + else if (value < 0x4000) { + writer.Write ((byte) (0x80 | (value >> 8))); + writer.Write ((byte) (value & 0xff)); + } else { + writer.Write ((byte) ((value >> 24) | 0xc0)); + writer.Write ((byte) ((value >> 16) & 0xff)); + writer.Write ((byte) ((value >> 8) & 0xff)); + writer.Write ((byte) (value & 0xff)); + } + return (int) writer.BaseStream.Position; + } + + public static MetadataToken GetMetadataToken (CodedIndex cidx, uint data) + { + uint rid = 0; + switch (cidx) { +<% $coded_indexes.each { |ci| %> case CodedIndex.<%=ci.name%> : + rid = data >> <%=ci.size%>; + switch (data & <%=(2 ** ci.size.to_i - 1).to_s%>) { +<% ci.tables.each { |tbl| + name = tbl.name + if (name == "DeclSecurity") + name = "Permission" + elsif (name == "StandAloneSig") + name = "Signature" + end +%> case <%=tbl.tag%> : + return new MetadataToken (TokenType.<%=name%>, rid); +<% } +%> default : + return MetadataToken.Zero; + } +<% } %> default : + return MetadataToken.Zero; + } + } + + public static uint CompressMetadataToken (CodedIndex cidx, MetadataToken token) + { + uint ret = 0; + if (token.RID == 0) + return ret; + switch (cidx) { +<% $coded_indexes.each { |ci| %> case CodedIndex.<%=ci.name%> : + ret = token.RID << <%=ci.size%>; + switch (token.TokenType) { +<% ci.tables.each { |tbl| + name = tbl.name + if (name == "DeclSecurity") + name = "Permission" + elsif (name == "StandAloneSig") + name = "Signature" + end +%> case TokenType.<%=name%> : + return ret | <%=tbl.tag%>; +<% } +%> default : + throw new MetadataFormatException("Non valid Token for <%=ci.name%>"); + } +<% } %> default : + throw new MetadataFormatException ("Non valid CodedIndex"); + } + } + + internal static Type GetCorrespondingTable (TokenType t) + { + switch (t) { + case TokenType.Assembly : + return typeof (AssemblyTable); + case TokenType.AssemblyRef : + return typeof (AssemblyRefTable); + case TokenType.CustomAttribute : + return typeof (CustomAttributeTable); + case TokenType.Event : + return typeof (EventTable); + case TokenType.ExportedType : + return typeof (ExportedTypeTable); + case TokenType.Field : + return typeof (FieldTable); + case TokenType.File : + return typeof (FileTable); + case TokenType.InterfaceImpl : + return typeof (InterfaceImplTable); + case TokenType.MemberRef : + return typeof (MemberRefTable); + case TokenType.Method : + return typeof (MethodTable); + case TokenType.Module : + return typeof (ModuleTable); + case TokenType.ModuleRef : + return typeof (ModuleRefTable); + case TokenType.Param : + return typeof (ParamTable); + case TokenType.Permission : + return typeof (DeclSecurityTable); + case TokenType.Property : + return typeof (PropertyTable); + case TokenType.Signature : + return typeof (StandAloneSigTable); + case TokenType.TypeDef : + return typeof (TypeDefTable); + case TokenType.TypeRef : + return typeof (TypeRefTable); + case TokenType.TypeSpec : + return typeof (TypeSpecTable); + default : + return null; + } + } + + internal delegate int TableRowCounter (int rid); + + internal static int GetCodedIndexSize (CodedIndex ci, TableRowCounter rowCounter, IDictionary codedIndexCache) + { + int bits = 0, max = 0; + if (codedIndexCache [ci] != null) + return (int) codedIndexCache [ci]; + + int res = 0; + int [] rids; + switch (ci) { +<% $coded_indexes.each { |ci| %> case CodedIndex.<%=ci.name%> : + bits = <%=ci.size%>; + rids = new int [<%=ci.tables.length%>]; +<% ci.tables.each_with_index { |tbl, i| +%> rids [<%=i%>] = <%=tbl.name%>Table.RId; +<% } +%> break; +<% } %> default : + throw new MetadataFormatException ("Non valid CodedIndex"); + } + + for (int i = 0; i < rids.Length; i++) { + int rows = rowCounter (rids [i]); + if (rows > max) max = rows; + } + + res = max < (1 << (16 - bits)) ? 2 : 4; + codedIndexCache [ci] = res; + return res; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Makefile b/Mono.Addins.CecilReflector/Mono.Cecil/Makefile new file mode 100644 index 0000000..2277b72 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Makefile @@ -0,0 +1,12 @@ +thisdir = class/Mono.Cecil +include ../../build/rules.make + +LIBRARY = Mono.Cecil.dll +LIBRARY_SNK = ../mono.snk +LIBRARY_PACKAGE = none + +LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll -keyfile:$(LIBRARY_SNK) + +NO_TEST = yes + +include ../../build/library.make diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/BaseImageVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/BaseImageVisitor.cs new file mode 100644 index 0000000..610c0be --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/BaseImageVisitor.cs @@ -0,0 +1,101 @@ +// +// BaseImageVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public abstract class BaseImageVisitor : IBinaryVisitor { + + public virtual void VisitImage (Image img) + { + } + + public virtual void VisitDOSHeader (DOSHeader header) + { + } + + public virtual void VisitPEFileHeader (PEFileHeader header) + { + } + + public virtual void VisitPEOptionalHeader (PEOptionalHeader header) + { + } + + public virtual void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header) + { + } + + public virtual void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header) + { + } + + public virtual void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header) + { + } + + public virtual void VisitSectionCollection (SectionCollection coll) + { + } + + public virtual void VisitSection (Section section) + { + } + + public virtual void VisitImportAddressTable (ImportAddressTable iat) + { + } + + public virtual void VisitDebugHeader (DebugHeader dh) + { + } + + public virtual void VisitCLIHeader (CLIHeader header) + { + } + + public virtual void VisitImportTable (ImportTable it) + { + } + + public virtual void VisitImportLookupTable (ImportLookupTable ilt) + { + } + + public virtual void VisitHintNameTable (HintNameTable hnt) + { + } + + public virtual void VisitExportTable (ExportTable et) + { + } + + public virtual void TerminateImage (Image img) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/CLIHeader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/CLIHeader.cs new file mode 100644 index 0000000..f92198e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/CLIHeader.cs @@ -0,0 +1,68 @@ +// +// CLIHeader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public sealed class CLIHeader : IHeader, IBinaryVisitable { + + public uint Cb; + public ushort MajorRuntimeVersion; + public ushort MinorRuntimeVersion; + public DataDirectory Metadata; + public RuntimeImage Flags; + public uint EntryPointToken; + public DataDirectory Resources; + public DataDirectory StrongNameSignature; + public DataDirectory CodeManagerTable; + public DataDirectory VTableFixups; + public DataDirectory ExportAddressTableJumps; + public DataDirectory ManagedNativeHeader; + + public byte [] ImageHash; + + internal CLIHeader () + { + } + + public void SetDefaultValues () + { + Cb = 0x48; + MajorRuntimeVersion = 2; + MinorRuntimeVersion = 0; + Flags = RuntimeImage.ILOnly; + CodeManagerTable = DataDirectory.Zero; + ExportAddressTableJumps = DataDirectory.Zero; + ManagedNativeHeader = DataDirectory.Zero; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitCLIHeader (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/CopyImageVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/CopyImageVisitor.cs new file mode 100644 index 0000000..864fe45 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/CopyImageVisitor.cs @@ -0,0 +1,119 @@ +// +// CopyImageVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + class CopyImageVisitor : BaseImageVisitor { + + Image m_newImage; + Image m_originalImage; + + public CopyImageVisitor (Image originalImage) + { + m_originalImage = originalImage; + } + + public override void VisitImage (Image img) + { + m_newImage = img; + if (m_originalImage.DebugHeader != null) + m_newImage.AddDebugHeader (); + } + + public override void VisitDebugHeader (DebugHeader dbgHeader) + { + DebugHeader old = m_originalImage.DebugHeader; + dbgHeader.Age = old.Age; + dbgHeader.Characteristics = old.Characteristics; + dbgHeader.FileName = old.FileName; + dbgHeader.Signature = old.Signature; + dbgHeader.TimeDateStamp = ImageInitializer.TimeDateStampFromEpoch(); + dbgHeader.Type = old.Type; + } + + public override void VisitSectionCollection (SectionCollection sections) + { + Section old = null; + foreach (Section s in m_originalImage.Sections) + if (s.Name == Section.Resources) + old = s; + + if (old == null) + return; + + Section rsrc = new Section (); + rsrc.Characteristics = old.Characteristics; + rsrc.Name = old.Name; + + sections.Add (rsrc); + } + + public override void TerminateImage (Image img) + { + if (m_originalImage.ResourceDirectoryRoot == null) + return; + + m_newImage.ResourceDirectoryRoot = CloneResourceDirectoryTable (m_originalImage.ResourceDirectoryRoot); + } + + ResourceDirectoryTable CloneResourceDirectoryTable (ResourceDirectoryTable old) + { + ResourceDirectoryTable rdt = new ResourceDirectoryTable (); + foreach (ResourceDirectoryEntry oldEntry in old.Entries) + rdt.Entries.Add (CloneResourceDirectoryEntry (oldEntry)); + + return rdt; + } + + ResourceDirectoryEntry CloneResourceDirectoryEntry (ResourceDirectoryEntry old) + { + ResourceDirectoryEntry rde; + if (old.IdentifiedByName) + rde = new ResourceDirectoryEntry(old.Name); + else + rde = new ResourceDirectoryEntry (old.ID); + + if (old.Child is ResourceDirectoryTable) + rde.Child = CloneResourceDirectoryTable (old.Child as ResourceDirectoryTable); + else + rde.Child = CloneResourceDataEntry (old.Child as ResourceDataEntry); + + return rde; + } + + ResourceDataEntry CloneResourceDataEntry (ResourceDataEntry old) + { + ResourceDataEntry rde = new ResourceDataEntry (); + rde.Size = old.Size; + rde.Codepage = old.Codepage; + rde.ResourceData = old.ResourceData; + + return rde; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DOSHeader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DOSHeader.cs new file mode 100644 index 0000000..8515433 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DOSHeader.cs @@ -0,0 +1,75 @@ +// +// DOSHeader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public sealed class DOSHeader : IHeader, IBinaryVisitable { + + public byte [] Start; + public byte [] End; + + public uint Lfanew; + + internal DOSHeader () + { + } + + public void SetDefaultValues () + { + Start = new byte [60] { + 0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 + }; + Lfanew = 128; + End = new byte [64] { + 0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, + 0xcd, 0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, + 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x72, + 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x20, 0x63, + 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x62, + 0x65, 0x20, 0x72, 0x75, 0x6e, 0x20, 0x69, + 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20, 0x6d, + 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a, + 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00 + }; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitDOSHeader (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DataDirectory.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DataDirectory.cs new file mode 100644 index 0000000..9762423 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DataDirectory.cs @@ -0,0 +1,87 @@ +// +// DataDirectory.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using Mono.Cecil.Metadata; + + public struct DataDirectory { + + public static readonly DataDirectory Zero = new DataDirectory(RVA.Zero, 0); + + RVA m_virtualAddress; + uint m_size; + + public RVA VirtualAddress { + get { return m_virtualAddress; } + set { m_virtualAddress = value; } + } + + public uint Size { + get { return m_size; } + set { m_size = value; } + } + + public DataDirectory (RVA virtualAddress, uint size) + { + m_virtualAddress = virtualAddress; + m_size = size; + } + + public override int GetHashCode () + { + return (m_virtualAddress.GetHashCode () ^ (int) m_size << 1); + } + + public override bool Equals (object other) + { + if (other is DataDirectory) { + DataDirectory odd = (DataDirectory)other; + return (this.m_virtualAddress == odd.m_virtualAddress && + this.m_size == odd.m_size); + } + return false; + } + + public override string ToString () + { + return string.Format ("{0} [{1}]", + m_virtualAddress.ToString (), m_size.ToString ("X")); + } + + public static bool operator == (DataDirectory one, DataDirectory other) + { + return one.Equals (other); + } + + public static bool operator != (DataDirectory one, DataDirectory other) + { + return !one.Equals (other); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DebugHeader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DebugHeader.cs new file mode 100644 index 0000000..ae4d436 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DebugHeader.cs @@ -0,0 +1,73 @@ +// +// DebugHeader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System; + + public sealed class DebugHeader : IHeader, IBinaryVisitable { + + public uint Characteristics; + public uint TimeDateStamp; + public ushort MajorVersion; + public ushort MinorVersion; + public DebugStoreType Type; + public uint SizeOfData; + public RVA AddressOfRawData; + public uint PointerToRawData; + + public uint Magic; + public Guid Signature; + public uint Age; + public string FileName; + + internal DebugHeader () + { + } + + public void SetDefaultValues () + { + Characteristics = 0; + + this.Magic = 0x53445352; + this.Age = 0; + this.Type = DebugStoreType.CodeView; + this.FileName = string.Empty; + } + + public uint GetSize () + { + return 0x34 + (uint) FileName.Length + 1; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitDebugHeader (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DebugStoreType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DebugStoreType.cs new file mode 100644 index 0000000..ad9ba97 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/DebugStoreType.cs @@ -0,0 +1,45 @@ +// +// DebugStoreType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public enum DebugStoreType : uint { + Unknown = 0x00000000, + COFF = 0x00000001, + CodeView = 0x00000002, + FPO = 0x00000003, + Misc = 0x00000004, + Exception = 0x00000005, + Fixup = 0x00000006, + OMAPToSrc = 0x00000007, + OMAPFromSrc = 0x00000008, + Borland = 0x00000009, + Reserved10 = 0x0000000a, + CLSID = 0x0000000b + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ExportTable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ExportTable.cs new file mode 100644 index 0000000..5032e55 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ExportTable.cs @@ -0,0 +1,59 @@ +// +// ExportTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public sealed class ExportTable : IBinaryVisitable { + + public uint Characteristics; + public uint TimeDateStamp; + public ushort MajorVersion; + public ushort MinorVersion; + public string Name; + public uint Base; + public uint NumberOfFunctions; + public uint NumberOfNames; + public RVA AddressOfFunctions; + public RVA AddressOfNames; + public RVA AddressOfNameOrdinals; + + public RVA [] AddressesOfFunctions; + public RVA [] AddressesOfNames; + public ushort [] NameOrdinals; + public string [] Names; + + internal ExportTable () + { + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitExportTable (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitable.cs new file mode 100644 index 0000000..0d3729e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitable.cs @@ -0,0 +1,35 @@ +// +// IBinaryVisitable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public interface IBinaryVisitable { + void Accept (IBinaryVisitor visitor); + } +} + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitor.cs new file mode 100644 index 0000000..5b24836 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IBinaryVisitor.cs @@ -0,0 +1,51 @@ +// +// IBinaryVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public interface IBinaryVisitor { + void VisitImage (Image img); + void VisitDOSHeader (DOSHeader header); + void VisitPEFileHeader (PEFileHeader header); + void VisitPEOptionalHeader (PEOptionalHeader header); + void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header); + void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header); + void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header); + void VisitSectionCollection (SectionCollection coll); + void VisitSection (Section section); + void VisitImportAddressTable (ImportAddressTable iat); + void VisitDebugHeader (DebugHeader dh); + void VisitCLIHeader (CLIHeader header); + void VisitImportTable (ImportTable it); + void VisitImportLookupTable (ImportLookupTable ilt); + void VisitHintNameTable (HintNameTable hnt); + void VisitExportTable (ExportTable et); + + void TerminateImage (Image img); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IHeader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IHeader.cs new file mode 100644 index 0000000..54f157d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/IHeader.cs @@ -0,0 +1,34 @@ +// +// IHeader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + internal interface IHeader { + void SetDefaultValues (); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Image.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Image.cs new file mode 100644 index 0000000..fdd0200 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Image.cs @@ -0,0 +1,236 @@ +// +// Image.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System; + using System.IO; + + using Mono.Cecil.Metadata; + + public sealed class Image : IBinaryVisitable { + + DOSHeader m_dosHeader; + PEFileHeader m_peFileHeader; + PEOptionalHeader m_peOptionalHeader; + + SectionCollection m_sections; + Section m_textSection; + + ImportAddressTable m_importAddressTable; + CLIHeader m_cliHeader; + ImportTable m_importTable; + ImportLookupTable m_importLookupTable; + HintNameTable m_hintNameTable; + ExportTable m_exportTable; + + DebugHeader m_debugHeader; + MetadataRoot m_mdRoot; + + ResourceDirectoryTable m_rsrcRoot; + + FileInfo m_img; + + public DOSHeader DOSHeader { + get { return m_dosHeader; } + } + + public PEFileHeader PEFileHeader { + get { return m_peFileHeader; } + } + + public PEOptionalHeader PEOptionalHeader { + get { return m_peOptionalHeader; } + } + + public SectionCollection Sections { + get { return m_sections; } + } + + public Section TextSection { + get { return m_textSection; } + set { m_textSection = value; } + } + + public ImportAddressTable ImportAddressTable { + get { return m_importAddressTable; } + } + + public CLIHeader CLIHeader { + get { return m_cliHeader; } + set { m_cliHeader = value; } + } + + public DebugHeader DebugHeader { + get { return m_debugHeader; } + set { m_debugHeader = value; } + } + + public MetadataRoot MetadataRoot { + get { return m_mdRoot; } + } + + public ImportTable ImportTable { + get { return m_importTable; } + } + + public ImportLookupTable ImportLookupTable { + get { return m_importLookupTable; } + } + + public HintNameTable HintNameTable { + get { return m_hintNameTable; } + } + + public ExportTable ExportTable { + get { return m_exportTable; } + set { m_exportTable = value; } + } + + internal ResourceDirectoryTable ResourceDirectoryRoot { + get { return m_rsrcRoot; } + set { m_rsrcRoot = value; } + } + + public FileInfo FileInformation { + get { return m_img; } + } + + internal Image () + { + m_dosHeader = new DOSHeader (); + m_peFileHeader = new PEFileHeader (); + m_peOptionalHeader = new PEOptionalHeader (); + m_sections = new SectionCollection (); + m_importAddressTable = new ImportAddressTable (); + m_importTable = new ImportTable (); + m_importLookupTable = new ImportLookupTable (); + m_hintNameTable = new HintNameTable (); + m_mdRoot = new MetadataRoot (this); + } + + internal Image (FileInfo img) : this () + { + m_img = img; + } + + public long ResolveVirtualAddress (RVA rva) + { + foreach (Section sect in this.Sections) { + if (rva >= sect.VirtualAddress && + rva < sect.VirtualAddress + sect.SizeOfRawData) + + return rva + sect.PointerToRawData - sect.VirtualAddress; + } + + throw new ArgumentOutOfRangeException ("Cannot map the rva to any section"); + } + + public BinaryReader GetReaderAtVirtualAddress (RVA rva) + { + foreach (Section sect in this.Sections) { + if (rva >= sect.VirtualAddress && + rva < sect.VirtualAddress + sect.SizeOfRawData) { + + BinaryReader br = new BinaryReader (new MemoryStream (sect.Data)); + br.BaseStream.Position = rva - sect.VirtualAddress; + return br; + } + } + + return null; + } + + public void AddDebugHeader () + { + m_debugHeader = new DebugHeader (); + m_debugHeader.SetDefaultValues (); + } + + internal void SetFileInfo (FileInfo file) + { + m_img = file; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitImage (this); + + m_dosHeader.Accept (visitor); + m_peFileHeader.Accept (visitor); + m_peOptionalHeader.Accept (visitor); + + m_sections.Accept (visitor); + + m_importAddressTable.Accept (visitor); + + AcceptIfNotNull (m_cliHeader, visitor); + AcceptIfNotNull (m_debugHeader, visitor); + + m_importTable.Accept (visitor); + m_importLookupTable.Accept (visitor); + m_hintNameTable.Accept (visitor); + AcceptIfNotNull (m_exportTable, visitor); + + visitor.TerminateImage (this); + } + + static void AcceptIfNotNull (IBinaryVisitable visitable, IBinaryVisitor visitor) + { + if (visitable == null) + return; + + visitable.Accept (visitor); + } + + public static Image CreateImage () + { + Image img = new Image (); + + ImageInitializer init = new ImageInitializer (img); + img.Accept (init); + + return img; + } + + public static Image GetImage (string file) + { + return ImageReader.Read (file).Image; + } + + public static Image GetImage (byte [] image) + { + return ImageReader.Read (image).Image; + } + + public static Image GetImage (Stream stream) + { + return ImageReader.Read (stream).Image; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageCharacteristics.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageCharacteristics.cs new file mode 100644 index 0000000..278b75d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageCharacteristics.cs @@ -0,0 +1,57 @@ +// +// ImageCharacteristics.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System; + + [Flags] + public enum ImageCharacteristics : ushort { + RelocsStripped = 0x0001, + ExecutableImage = 0x0002, + LineNumsStripped = 0x0004, + LocalSymsStripped = 0x0008, + AggressiveWSTrim = 0x0010, + LargeAddressAware = 0x0020, + ReservedForFutureUse = 0x0040, + BytesReversedLo = 0x0080, + _32BitsMachine = 0x0100, + DebugStripped = 0x0200, + RemovableRunFromSwap = 0x0400, + NetRunFromSwap = 0x0800, + System = 0x1000, + Dll = 0x2000, + UPSystemOnly = 0x4000, + BytesReversedHI = 0x8000, + + __flags = 0x0002 | 0x0004 | 0x0008 | 0x0100, + + CILOnlyDll = 0x2000 | (ushort) __flags, + CILOnlyExe = __flags + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageFormatException.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageFormatException.cs new file mode 100644 index 0000000..1592233 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageFormatException.cs @@ -0,0 +1,53 @@ +// +// ImageFormatException.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System; + + public class ImageFormatException : Exception { + + internal ImageFormatException () : base() + { + } + + internal ImageFormatException (string message) : base(message) + { + } + + internal ImageFormatException (string message, params string[] parameters) : + base(string.Format(message, parameters)) + { + } + + internal ImageFormatException (string message, Exception inner) : + base(message, inner) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageInitializer.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageInitializer.cs new file mode 100644 index 0000000..8424ed1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageInitializer.cs @@ -0,0 +1,139 @@ +// +// ImageInitializer.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System; + + using Mono.Cecil.Metadata; + + class ImageInitializer : BaseImageVisitor { + + Image m_image; + MetadataInitializer m_mdinit; + + public Image Image { + get { return m_image; } + } + + public MetadataInitializer Metadata { + get { return m_mdinit; } + } + + public ImageInitializer (Image image) + { + m_image = image; + m_image.CLIHeader = new CLIHeader (); + m_mdinit = new MetadataInitializer (this); + } + + public override void VisitDOSHeader (DOSHeader header) + { + header.SetDefaultValues (); + } + + public override void VisitPEOptionalHeader (PEOptionalHeader header) + { + header.SetDefaultValues (); + } + + public override void VisitPEFileHeader (PEFileHeader header) + { + header.SetDefaultValues (); + header.TimeDateStamp = TimeDateStampFromEpoch (); + } + + public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header) + { + header.SetDefaultValues (); + } + + public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header) + { + header.SetDefaultValues (); + } + + public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header) + { + header.SetDefaultValues (); + } + + public override void VisitSectionCollection (SectionCollection coll) + { + Section text = new Section (); + text.Name = Section.Text; + text.Characteristics = SectionCharacteristics.ContainsCode | + SectionCharacteristics.MemoryRead | SectionCharacteristics.MemExecute; + m_image.TextSection = text; + + Section reloc = new Section (); + reloc.Name = Section.Relocs; + reloc.Characteristics = SectionCharacteristics.ContainsInitializedData | + SectionCharacteristics.MemDiscardable | SectionCharacteristics.MemoryRead; + + coll.Add (text); + coll.Add (reloc); + } + + public override void VisitSection (Section sect) + { + sect.SetDefaultValues (); + } + + public override void VisitDebugHeader (DebugHeader dh) + { + if (dh != null) + dh.SetDefaultValues (); + } + + public override void VisitCLIHeader (CLIHeader header) + { + header.SetDefaultValues (); + m_image.MetadataRoot.Accept (m_mdinit); + } + + public override void VisitImportTable (ImportTable it) + { + it.ImportAddressTable = new RVA (0x2000); + } + + public override void VisitHintNameTable (HintNameTable hnt) + { + hnt.Hint = 0; + hnt.RuntimeLibrary = HintNameTable.RuntimeCorEE; + hnt.EntryPoint = 0x25ff; + hnt.RVA = new RVA (0x402000); + } + + public static uint TimeDateStampFromEpoch () + { + return (uint) DateTime.UtcNow.Subtract ( + new DateTime (1970, 1, 1)).TotalSeconds; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageReader.cs new file mode 100644 index 0000000..220eb2d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageReader.cs @@ -0,0 +1,472 @@ +// +// ImageReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System; + using System.IO; + using System.Text; + + using Mono.Cecil.Metadata; + + class ImageReader : BaseImageVisitor { + + MetadataReader m_mdReader; + BinaryReader m_binaryReader; + Image m_image; + + public MetadataReader MetadataReader { + get { return m_mdReader; } + } + + public Image Image { + get { return m_image; } + } + + ImageReader (Image img, BinaryReader reader) + { + m_image = img; + m_binaryReader = reader; + } + + static ImageReader Read (Image img, Stream stream) + { + ImageReader reader = new ImageReader (img, new BinaryReader (stream)); + img.Accept (reader); + return reader; + } + + public static ImageReader Read (string file) + { + if (file == null) + throw new ArgumentNullException ("file"); + + FileInfo fi = new FileInfo (file); + if (!File.Exists (fi.FullName)) + #if CF_1_0 || CF_2_0 + throw new FileNotFoundException (fi.FullName); + #else + throw new FileNotFoundException (string.Format ("File '{0}' not found.", fi.FullName), fi.FullName); + #endif + + return Read (new Image (fi), new FileStream ( + fi.FullName, FileMode.Open, + FileAccess.Read, FileShare.Read)); + } + + public static ImageReader Read (byte [] image) + { + if (image == null) + throw new ArgumentNullException ("image"); + + if (image.Length == 0) + throw new ArgumentException ("Empty image array"); + + return Read (new Image (), new MemoryStream (image)); + } + + public static ImageReader Read (Stream stream) + { + if (stream == null) + throw new ArgumentNullException ("stream"); + + if (!stream.CanRead) + throw new ArgumentException ("Can not read from stream"); + + return Read (new Image (), stream); + } + + public BinaryReader GetReader () + { + return m_binaryReader; + } + + public override void VisitImage (Image img) + { + m_mdReader = new MetadataReader (this); + } + + void SetPositionToAddress (RVA address) + { + m_binaryReader.BaseStream.Position = m_image.ResolveVirtualAddress (address); + } + + public override void VisitDOSHeader (DOSHeader header) + { + header.Start = m_binaryReader.ReadBytes (60); + header.Lfanew = m_binaryReader.ReadUInt32 (); + header.End = m_binaryReader.ReadBytes (64); + + m_binaryReader.BaseStream.Position = header.Lfanew; + + if (m_binaryReader.ReadUInt16 () != 0x4550 || + m_binaryReader.ReadUInt16 () != 0) + + throw new ImageFormatException ("Invalid PE File Signature"); + } + + public override void VisitPEFileHeader (PEFileHeader header) + { + header.Machine = m_binaryReader.ReadUInt16 (); + header.NumberOfSections = m_binaryReader.ReadUInt16 (); + header.TimeDateStamp = m_binaryReader.ReadUInt32 (); + header.PointerToSymbolTable = m_binaryReader.ReadUInt32 (); + header.NumberOfSymbols = m_binaryReader.ReadUInt32 (); + header.OptionalHeaderSize = m_binaryReader.ReadUInt16 (); + header.Characteristics = (ImageCharacteristics) m_binaryReader.ReadUInt16 (); + } + + ulong ReadIntOrLong () + { + return m_image.PEOptionalHeader.StandardFields.IsPE64 ? + m_binaryReader.ReadUInt64 () : + m_binaryReader.ReadUInt32 (); + } + + RVA ReadRVA () + { + return m_binaryReader.ReadUInt32 (); + } + + DataDirectory ReadDataDirectory () + { + return new DataDirectory (ReadRVA (), m_binaryReader.ReadUInt32 ()); + } + + public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header) + { + header.ImageBase = ReadIntOrLong (); + header.SectionAlignment = m_binaryReader.ReadUInt32 (); + header.FileAlignment = m_binaryReader.ReadUInt32 (); + header.OSMajor = m_binaryReader.ReadUInt16 (); + header.OSMinor = m_binaryReader.ReadUInt16 (); + header.UserMajor = m_binaryReader.ReadUInt16 (); + header.UserMinor = m_binaryReader.ReadUInt16 (); + header.SubSysMajor = m_binaryReader.ReadUInt16 (); + header.SubSysMinor = m_binaryReader.ReadUInt16 (); + header.Reserved = m_binaryReader.ReadUInt32 (); + header.ImageSize = m_binaryReader.ReadUInt32 (); + header.HeaderSize = m_binaryReader.ReadUInt32 (); + header.FileChecksum = m_binaryReader.ReadUInt32 (); + header.SubSystem = (SubSystem) m_binaryReader.ReadUInt16 (); + header.DLLFlags = m_binaryReader.ReadUInt16 (); + header.StackReserveSize = ReadIntOrLong (); + header.StackCommitSize = ReadIntOrLong (); + header.HeapReserveSize = ReadIntOrLong (); + header.HeapCommitSize = ReadIntOrLong (); + header.LoaderFlags = m_binaryReader.ReadUInt32 (); + header.NumberOfDataDir = m_binaryReader.ReadUInt32 (); + } + + public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header) + { + header.Magic = m_binaryReader.ReadUInt16 (); + header.LMajor = m_binaryReader.ReadByte (); + header.LMinor = m_binaryReader.ReadByte (); + header.CodeSize = m_binaryReader.ReadUInt32 (); + header.InitializedDataSize = m_binaryReader.ReadUInt32 (); + header.UninitializedDataSize = m_binaryReader.ReadUInt32 (); + header.EntryPointRVA = ReadRVA (); + header.BaseOfCode = ReadRVA (); + if (!header.IsPE64) + header.BaseOfData = ReadRVA (); + } + + public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header) + { + header.ExportTable = ReadDataDirectory (); + header.ImportTable = ReadDataDirectory (); + header.ResourceTable = ReadDataDirectory (); + header.ExceptionTable = ReadDataDirectory (); + header.CertificateTable = ReadDataDirectory (); + header.BaseRelocationTable = ReadDataDirectory (); + header.Debug = ReadDataDirectory (); + header.Copyright = ReadDataDirectory (); + header.GlobalPtr = ReadDataDirectory (); + header.TLSTable = ReadDataDirectory (); + header.LoadConfigTable = ReadDataDirectory (); + header.BoundImport = ReadDataDirectory (); + header.IAT = ReadDataDirectory (); + header.DelayImportDescriptor = ReadDataDirectory (); + header.CLIHeader = ReadDataDirectory (); + header.Reserved = ReadDataDirectory (); + + if (header.CLIHeader != DataDirectory.Zero) + m_image.CLIHeader = new CLIHeader (); + if (header.ExportTable != DataDirectory.Zero) + m_image.ExportTable = new ExportTable (); + } + + public override void VisitSectionCollection (SectionCollection coll) + { + for (int i = 0; i < m_image.PEFileHeader.NumberOfSections; i++) + coll.Add (new Section ()); + } + + public override void VisitSection (Section sect) + { + char [] buffer = new char [8]; + int read = 0; + while (read < 8) { + char cur = (char) m_binaryReader.ReadSByte (); + if (cur == '\0') { + m_binaryReader.BaseStream.Position += 8 - read - 1; + break; + } + buffer [read++] = cur; + } + sect.Name = read == 0 ? string.Empty : new string (buffer, 0, read); + if (sect.Name == Section.Text) + m_image.TextSection = sect; + + sect.VirtualSize = m_binaryReader.ReadUInt32 (); + sect.VirtualAddress = ReadRVA (); + sect.SizeOfRawData = m_binaryReader.ReadUInt32 (); + sect.PointerToRawData = ReadRVA (); + sect.PointerToRelocations = ReadRVA (); + sect.PointerToLineNumbers = ReadRVA (); + sect.NumberOfRelocations = m_binaryReader.ReadUInt16 (); + sect.NumberOfLineNumbers = m_binaryReader.ReadUInt16 (); + sect.Characteristics = (SectionCharacteristics) m_binaryReader.ReadUInt32 (); + + long pos = m_binaryReader.BaseStream.Position; + m_binaryReader.BaseStream.Position = sect.PointerToRawData; + sect.Data = m_binaryReader.ReadBytes ((int) sect.SizeOfRawData); + m_binaryReader.BaseStream.Position = pos; + } + + public override void VisitImportAddressTable (ImportAddressTable iat) + { + if (m_image.PEOptionalHeader.DataDirectories.IAT.VirtualAddress == RVA.Zero) + return; + + SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.IAT.VirtualAddress); + + iat.HintNameTableRVA = ReadRVA (); + } + + public override void VisitCLIHeader (CLIHeader header) + { + if (m_image.PEOptionalHeader.DataDirectories.Debug != DataDirectory.Zero) { + m_image.DebugHeader = new DebugHeader (); + VisitDebugHeader (m_image.DebugHeader); + } + + SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.CLIHeader.VirtualAddress); + header.Cb = m_binaryReader.ReadUInt32 (); + header.MajorRuntimeVersion = m_binaryReader.ReadUInt16 (); + header.MinorRuntimeVersion = m_binaryReader.ReadUInt16 (); + header.Metadata = ReadDataDirectory (); + header.Flags = (RuntimeImage) m_binaryReader.ReadUInt32 (); + header.EntryPointToken = m_binaryReader.ReadUInt32 (); + header.Resources = ReadDataDirectory (); + header.StrongNameSignature = ReadDataDirectory (); + header.CodeManagerTable = ReadDataDirectory (); + header.VTableFixups = ReadDataDirectory (); + header.ExportAddressTableJumps = ReadDataDirectory (); + header.ManagedNativeHeader = ReadDataDirectory (); + + if (header.StrongNameSignature != DataDirectory.Zero) { + SetPositionToAddress (header.StrongNameSignature.VirtualAddress); + header.ImageHash = m_binaryReader.ReadBytes ((int) header.StrongNameSignature.Size); + } else + header.ImageHash = new byte [0]; + + SetPositionToAddress (m_image.CLIHeader.Metadata.VirtualAddress); + m_image.MetadataRoot.Accept (m_mdReader); + } + + public override void VisitDebugHeader (DebugHeader header) + { + if (m_image.PEOptionalHeader.DataDirectories.Debug == DataDirectory.Zero) + return; + + long pos = m_binaryReader.BaseStream.Position; + + SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.Debug.VirtualAddress); + header.Characteristics = m_binaryReader.ReadUInt32 (); + header.TimeDateStamp = m_binaryReader.ReadUInt32 (); + header.MajorVersion = m_binaryReader.ReadUInt16 (); + header.MinorVersion = m_binaryReader.ReadUInt16 (); + header.Type = (DebugStoreType) m_binaryReader.ReadUInt32 (); + header.SizeOfData = m_binaryReader.ReadUInt32 (); + header.AddressOfRawData = ReadRVA (); + header.PointerToRawData = m_binaryReader.ReadUInt32 (); + + m_binaryReader.BaseStream.Position = header.PointerToRawData; + + header.Magic = m_binaryReader.ReadUInt32 (); + header.Signature = new Guid (m_binaryReader.ReadBytes (16)); + header.Age = m_binaryReader.ReadUInt32 (); + header.FileName = ReadZeroTerminatedString (); + + m_binaryReader.BaseStream.Position = pos; + } + + string ReadZeroTerminatedString () + { + StringBuilder sb = new StringBuilder (); + while (true) { + byte chr = m_binaryReader.ReadByte (); + if (chr == 0) + break; + sb.Append ((char) chr); + } + return sb.ToString (); + } + + public override void VisitImportTable (ImportTable it) + { + if (m_image.PEOptionalHeader.DataDirectories.ImportTable.VirtualAddress == RVA.Zero) + return; + + SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.ImportTable.VirtualAddress); + + it.ImportLookupTable = ReadRVA (); + it.DateTimeStamp = m_binaryReader.ReadUInt32 (); + it.ForwardChain = m_binaryReader.ReadUInt32 (); + it.Name = ReadRVA (); + it.ImportAddressTable = ReadRVA (); + } + + public override void VisitImportLookupTable (ImportLookupTable ilt) + { + if (m_image.ImportTable.ImportLookupTable == RVA.Zero) + return; + + SetPositionToAddress (m_image.ImportTable.ImportLookupTable); + + ilt.HintNameRVA = ReadRVA (); + } + + public override void VisitHintNameTable (HintNameTable hnt) + { + if (m_image.ImportAddressTable.HintNameTableRVA == RVA.Zero) + return; + + SetPositionToAddress (m_image.ImportAddressTable.HintNameTableRVA); + + hnt.Hint = m_binaryReader.ReadUInt16 (); + + byte [] bytes = m_binaryReader.ReadBytes (11); + hnt.RuntimeMain = Encoding.ASCII.GetString (bytes, 0, bytes.Length); + + SetPositionToAddress (m_image.ImportTable.Name); + + bytes = m_binaryReader.ReadBytes (11); + hnt.RuntimeLibrary = Encoding.ASCII.GetString (bytes, 0, bytes.Length); + + SetPositionToAddress (m_image.PEOptionalHeader.StandardFields.EntryPointRVA); + hnt.EntryPoint = m_binaryReader.ReadUInt16 (); + hnt.RVA = ReadRVA (); + } + + public override void VisitExportTable (ExportTable et) + { + SetPositionToAddress (m_image.PEOptionalHeader.DataDirectories.ExportTable.VirtualAddress); + + et.Characteristics = m_binaryReader.ReadUInt32 (); + et.TimeDateStamp = m_binaryReader.ReadUInt32 (); + et.MajorVersion = m_binaryReader.ReadUInt16 (); + et.MinorVersion = m_binaryReader.ReadUInt16 (); + + //et.Name = + m_binaryReader.ReadUInt32 (); + + et.Base = m_binaryReader.ReadUInt32 (); + et.NumberOfFunctions = m_binaryReader.ReadUInt32 (); + et.NumberOfNames = m_binaryReader.ReadUInt32 (); + et.AddressOfFunctions = m_binaryReader.ReadUInt32 (); + et.AddressOfNames = m_binaryReader.ReadUInt32 (); + et.AddressOfNameOrdinals = m_binaryReader.ReadUInt32 (); + + et.AddressesOfFunctions = ReadArrayOfRVA (et.AddressOfFunctions, et.NumberOfFunctions); + et.AddressesOfNames = ReadArrayOfRVA (et.AddressOfNames, et.NumberOfNames); + et.NameOrdinals = ReadArrayOfUInt16 (et.AddressOfNameOrdinals, et.NumberOfNames); + et.Names = new string [et.NumberOfFunctions]; + + for (int i = 0; i < et.NumberOfFunctions; i++) { + if (et.AddressesOfFunctions [i] == 0) + continue; + + et.Names [i] = ReadFunctionName (et, i); + } + } + + string ReadFunctionName (ExportTable et, int index) + { + for (int i = 0; i < et.NumberOfNames; i++) { + if (et.NameOrdinals [i] != index) + continue; + + SetPositionToAddress (et.AddressesOfNames [i]); + return ReadZeroTerminatedString (); + } + + return string.Empty; + } + + ushort [] ReadArrayOfUInt16 (RVA position, uint length) + { + if (position == RVA.Zero) + return new ushort [0]; + + SetPositionToAddress (position); + ushort [] array = new ushort [length]; + for (int i = 0; i < length; i++) + array [i] = m_binaryReader.ReadUInt16 (); + + return array; + } + + RVA [] ReadArrayOfRVA (RVA position, uint length) + { + if (position == RVA.Zero) + return new RVA [0]; + + SetPositionToAddress (position); + RVA [] addresses = new RVA [length]; + for (int i = 0; i < length; i++) + addresses [i] = m_binaryReader.ReadUInt32 (); + + return addresses; + } + + public override void TerminateImage(Image img) + { + m_binaryReader.Close (); + + try { + ResourceReader resReader = new ResourceReader (img); + img.ResourceDirectoryRoot = resReader.Read (); + } catch { + img.ResourceDirectoryRoot = null; + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageWriter.cs new file mode 100644 index 0000000..495b3ed --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ImageWriter.cs @@ -0,0 +1,427 @@ +// +// ImageWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System.IO; + using System.Text; + + using Mono.Cecil.Metadata; + + class ImageWriter : BaseImageVisitor { + + Image m_img; + AssemblyKind m_kind; + MetadataWriter m_mdWriter; + BinaryWriter m_binaryWriter; + + Section m_textSect; + MemoryBinaryWriter m_textWriter; + Section m_relocSect; + MemoryBinaryWriter m_relocWriter; + Section m_rsrcSect; + MemoryBinaryWriter m_rsrcWriter; + + public ImageWriter (MetadataWriter writer, AssemblyKind kind, BinaryWriter bw) + { + m_mdWriter= writer; + m_img = writer.GetMetadataRoot ().GetImage (); + m_kind = kind; + m_binaryWriter = bw; + + m_textWriter = new MemoryBinaryWriter (); + m_textWriter.BaseStream.Position = 80; + m_relocWriter = new MemoryBinaryWriter (); + } + + public Image GetImage () + { + return m_img; + } + + public MemoryBinaryWriter GetTextWriter () + { + return m_textWriter; + } + + public uint GetAligned (uint integer, uint alignWith) + { + return (integer + alignWith - 1) & ~(alignWith - 1); + } + + public void Initialize () + { + Image img = m_img; + ResourceWriter resWriter = null; + + uint sectAlign = img.PEOptionalHeader.NTSpecificFields.SectionAlignment; + uint fileAlign = img.PEOptionalHeader.NTSpecificFields.FileAlignment; + + m_textSect = img.TextSection; + foreach (Section s in img.Sections) { + if (s.Name == Section.Relocs) + m_relocSect = s; + else if (s.Name == Section.Resources) { + m_rsrcSect = s; + m_rsrcWriter = new MemoryBinaryWriter (); + + resWriter = new ResourceWriter (img, m_rsrcSect, m_rsrcWriter); + resWriter.Write (); + } + } + + // size computations, fields setting, etc. + uint nbSects = (uint) img.Sections.Count; + img.PEFileHeader.NumberOfSections = (ushort) nbSects; + + // build the reloc section data + uint relocSize = 12; + m_relocWriter.Write ((uint) 0); + m_relocWriter.Write (relocSize); + m_relocWriter.Write ((ushort) 0); + m_relocWriter.Write ((ushort) 0); + + m_textSect.VirtualSize = (uint) m_textWriter.BaseStream.Length; + m_relocSect.VirtualSize = (uint) m_relocWriter.BaseStream.Length; + if (m_rsrcSect != null) + m_rsrcSect.VirtualSize = (uint) m_rsrcWriter.BaseStream.Length; + + // start counting before sections headers + // section start + section header sixe * number of sections + uint headersEnd = 0x178 + 0x28 * nbSects; + uint fileOffset = headersEnd; + uint sectOffset = sectAlign; + uint imageSize = 0; + + foreach (Section sect in img.Sections) { + fileOffset = GetAligned (fileOffset, fileAlign); + sectOffset = GetAligned (sectOffset, sectAlign); + + sect.PointerToRawData = new RVA (fileOffset); + sect.VirtualAddress = new RVA (sectOffset); + sect.SizeOfRawData = GetAligned (sect.VirtualSize, fileAlign); + + fileOffset += sect.SizeOfRawData; + sectOffset += sect.SizeOfRawData; + imageSize += GetAligned (sect.SizeOfRawData, sectAlign); + } + + if (m_textSect.VirtualAddress.Value != 0x2000) + throw new ImageFormatException ("Wrong RVA for .text section"); + + if (resWriter != null) + resWriter.Patch (); + + img.PEOptionalHeader.StandardFields.CodeSize = GetAligned ( + m_textSect.SizeOfRawData, fileAlign); + img.PEOptionalHeader.StandardFields.InitializedDataSize = m_textSect.SizeOfRawData; + if (m_rsrcSect != null) + img.PEOptionalHeader.StandardFields.InitializedDataSize += m_rsrcSect.SizeOfRawData; + img.PEOptionalHeader.StandardFields.BaseOfCode = m_textSect.VirtualAddress; + img.PEOptionalHeader.StandardFields.BaseOfData = m_relocSect.VirtualAddress; + + imageSize += headersEnd; + img.PEOptionalHeader.NTSpecificFields.ImageSize = GetAligned (imageSize, sectAlign); + + img.PEOptionalHeader.DataDirectories.BaseRelocationTable = new DataDirectory ( + m_relocSect.VirtualAddress, m_relocSect.VirtualSize); + if (m_rsrcSect != null) + img.PEOptionalHeader.DataDirectories.ResourceTable = new DataDirectory ( + m_rsrcSect.VirtualAddress, (uint) m_rsrcWriter.BaseStream.Length); + + if (m_kind == AssemblyKind.Dll) { + img.PEFileHeader.Characteristics = ImageCharacteristics.CILOnlyDll; + img.HintNameTable.RuntimeMain = HintNameTable.RuntimeMainDll; + img.PEOptionalHeader.NTSpecificFields.DLLFlags = 0x400; + } else { + img.PEFileHeader.Characteristics = ImageCharacteristics.CILOnlyExe; + img.HintNameTable.RuntimeMain = HintNameTable.RuntimeMainExe; + } + + switch (m_kind) { + case AssemblyKind.Dll : + case AssemblyKind.Console : + img.PEOptionalHeader.NTSpecificFields.SubSystem = SubSystem.WindowsCui; + break; + case AssemblyKind.Windows : + img.PEOptionalHeader.NTSpecificFields.SubSystem = SubSystem.WindowsGui; + break; + } + + RVA importTable = new RVA (img.TextSection.VirtualAddress + m_mdWriter.ImportTablePosition); + + img.PEOptionalHeader.DataDirectories.ImportTable = new DataDirectory (importTable, 0x57); + + img.ImportTable.ImportLookupTable = new RVA ((uint) importTable + 0x28); + + img.ImportLookupTable.HintNameRVA = img.ImportAddressTable.HintNameTableRVA = + new RVA ((uint) img.ImportTable.ImportLookupTable + 0x14); + img.ImportTable.Name = new RVA ((uint) img.ImportLookupTable.HintNameRVA + 0xe); + } + + public override void VisitDOSHeader (DOSHeader header) + { + m_binaryWriter.Write (header.Start); + m_binaryWriter.Write (header.Lfanew); + m_binaryWriter.Write (header.End); + + m_binaryWriter.Write ((ushort) 0x4550); + m_binaryWriter.Write ((ushort) 0); + } + + public override void VisitPEFileHeader (PEFileHeader header) + { + m_binaryWriter.Write (header.Machine); + m_binaryWriter.Write (header.NumberOfSections); + m_binaryWriter.Write (header.TimeDateStamp); + m_binaryWriter.Write (header.PointerToSymbolTable); + m_binaryWriter.Write (header.NumberOfSymbols); + m_binaryWriter.Write (header.OptionalHeaderSize); + m_binaryWriter.Write ((ushort) header.Characteristics); + } + + public override void VisitNTSpecificFieldsHeader (PEOptionalHeader.NTSpecificFieldsHeader header) + { + WriteIntOrLong (header.ImageBase); + m_binaryWriter.Write (header.SectionAlignment); + m_binaryWriter.Write (header.FileAlignment); + m_binaryWriter.Write (header.OSMajor); + m_binaryWriter.Write (header.OSMinor); + m_binaryWriter.Write (header.UserMajor); + m_binaryWriter.Write (header.UserMinor); + m_binaryWriter.Write (header.SubSysMajor); + m_binaryWriter.Write (header.SubSysMinor); + m_binaryWriter.Write (header.Reserved); + m_binaryWriter.Write (header.ImageSize); + m_binaryWriter.Write (header.HeaderSize); + m_binaryWriter.Write (header.FileChecksum); + m_binaryWriter.Write ((ushort) header.SubSystem); + m_binaryWriter.Write (header.DLLFlags); + WriteIntOrLong (header.StackReserveSize); + WriteIntOrLong (header.StackCommitSize); + WriteIntOrLong (header.HeapReserveSize); + WriteIntOrLong (header.HeapCommitSize); + m_binaryWriter.Write (header.LoaderFlags); + m_binaryWriter.Write (header.NumberOfDataDir); + } + + public override void VisitStandardFieldsHeader (PEOptionalHeader.StandardFieldsHeader header) + { + m_binaryWriter.Write (header.Magic); + m_binaryWriter.Write (header.LMajor); + m_binaryWriter.Write (header.LMinor); + m_binaryWriter.Write (header.CodeSize); + m_binaryWriter.Write (header.InitializedDataSize); + m_binaryWriter.Write (header.UninitializedDataSize); + m_binaryWriter.Write (header.EntryPointRVA.Value); + m_binaryWriter.Write (header.BaseOfCode.Value); + if (!header.IsPE64) + m_binaryWriter.Write (header.BaseOfData.Value); + } + + void WriteIntOrLong (ulong value) + { + if (m_img.PEOptionalHeader.StandardFields.IsPE64) + m_binaryWriter.Write (value); + else + m_binaryWriter.Write ((uint) value); + } + + public override void VisitDataDirectoriesHeader (PEOptionalHeader.DataDirectoriesHeader header) + { + m_binaryWriter.Write (header.ExportTable.VirtualAddress); + m_binaryWriter.Write (header.ExportTable.Size); + m_binaryWriter.Write (header.ImportTable.VirtualAddress); + m_binaryWriter.Write (header.ImportTable.Size); + m_binaryWriter.Write (header.ResourceTable.VirtualAddress); + m_binaryWriter.Write (header.ResourceTable.Size); + m_binaryWriter.Write (header.ExceptionTable.VirtualAddress); + m_binaryWriter.Write (header.ExceptionTable.Size); + m_binaryWriter.Write (header.CertificateTable.VirtualAddress); + m_binaryWriter.Write (header.CertificateTable.Size); + m_binaryWriter.Write (header.BaseRelocationTable.VirtualAddress); + m_binaryWriter.Write (header.BaseRelocationTable.Size); + m_binaryWriter.Write (header.Debug.VirtualAddress); + m_binaryWriter.Write (header.Debug.Size); + m_binaryWriter.Write (header.Copyright.VirtualAddress); + m_binaryWriter.Write (header.Copyright.Size); + m_binaryWriter.Write (header.GlobalPtr.VirtualAddress); + m_binaryWriter.Write (header.GlobalPtr.Size); + m_binaryWriter.Write (header.TLSTable.VirtualAddress); + m_binaryWriter.Write (header.TLSTable.Size); + m_binaryWriter.Write (header.LoadConfigTable.VirtualAddress); + m_binaryWriter.Write (header.LoadConfigTable.Size); + m_binaryWriter.Write (header.BoundImport.VirtualAddress); + m_binaryWriter.Write (header.BoundImport.Size); + m_binaryWriter.Write (header.IAT.VirtualAddress); + m_binaryWriter.Write (header.IAT.Size); + m_binaryWriter.Write (header.DelayImportDescriptor.VirtualAddress); + m_binaryWriter.Write (header.DelayImportDescriptor.Size); + m_binaryWriter.Write (header.CLIHeader.VirtualAddress); + m_binaryWriter.Write (header.CLIHeader.Size); + m_binaryWriter.Write (header.Reserved.VirtualAddress); + m_binaryWriter.Write (header.Reserved.Size); + } + + public override void VisitSection (Section sect) + { + m_binaryWriter.Write (Encoding.ASCII.GetBytes (sect.Name)); + int more = 8 - sect.Name.Length; + for (int i = 0; i < more; i++) + m_binaryWriter.Write ((byte) 0); + + m_binaryWriter.Write (sect.VirtualSize); + m_binaryWriter.Write (sect.VirtualAddress.Value); + m_binaryWriter.Write (sect.SizeOfRawData); + m_binaryWriter.Write (sect.PointerToRawData.Value); + m_binaryWriter.Write (sect.PointerToRelocations.Value); + m_binaryWriter.Write (sect.PointerToLineNumbers.Value); + m_binaryWriter.Write (sect.NumberOfRelocations); + m_binaryWriter.Write (sect.NumberOfLineNumbers); + m_binaryWriter.Write ((uint) sect.Characteristics); + } + + public override void VisitImportAddressTable (ImportAddressTable iat) + { + m_textWriter.BaseStream.Position = 0; + m_textWriter.Write (iat.HintNameTableRVA.Value); + m_textWriter.Write (new byte [4]); + } + + public override void VisitCLIHeader (CLIHeader header) + { + m_textWriter.Write (header.Cb); + m_textWriter.Write (header.MajorRuntimeVersion); + m_textWriter.Write (header.MinorRuntimeVersion); + m_textWriter.Write (header.Metadata.VirtualAddress); + m_textWriter.Write (header.Metadata.Size); + m_textWriter.Write ((uint) header.Flags); + m_textWriter.Write (header.EntryPointToken); + m_textWriter.Write (header.Resources.VirtualAddress); + m_textWriter.Write (header.Resources.Size); + m_textWriter.Write (header.StrongNameSignature.VirtualAddress); + m_textWriter.Write (header.StrongNameSignature.Size); + m_textWriter.Write (header.CodeManagerTable.VirtualAddress); + m_textWriter.Write (header.CodeManagerTable.Size); + m_textWriter.Write (header.VTableFixups.VirtualAddress); + m_textWriter.Write (header.VTableFixups.Size); + m_textWriter.Write (header.ExportAddressTableJumps.VirtualAddress); + m_textWriter.Write (header.ExportAddressTableJumps.Size); + m_textWriter.Write (header.ManagedNativeHeader.VirtualAddress); + m_textWriter.Write (header.ManagedNativeHeader.Size); + } + + public override void VisitDebugHeader (DebugHeader header) + { + m_textWriter.BaseStream.Position = m_mdWriter.DebugHeaderPosition; + uint sizeUntilData = 0x1c; + header.AddressOfRawData = m_img.TextSection.VirtualAddress + m_mdWriter.DebugHeaderPosition + sizeUntilData; + header.PointerToRawData = 0x200 + m_mdWriter.DebugHeaderPosition + sizeUntilData; + header.SizeOfData = 0x18 + (uint) header.FileName.Length + 1; + + m_textWriter.Write (header.Characteristics); + m_textWriter.Write (header.TimeDateStamp); + m_textWriter.Write (header.MajorVersion); + m_textWriter.Write (header.MinorVersion); + m_textWriter.Write ((uint) header.Type); + m_textWriter.Write (header.SizeOfData); + m_textWriter.Write (header.AddressOfRawData.Value); + m_textWriter.Write (header.PointerToRawData); + + m_textWriter.Write (header.Magic); + m_textWriter.Write (header.Signature.ToByteArray ()); + m_textWriter.Write (header.Age); + m_textWriter.Write (Encoding.ASCII.GetBytes (header.FileName)); + m_textWriter.Write ((byte) 0); + } + + public override void VisitImportTable (ImportTable it) + { + m_textWriter.BaseStream.Position = m_mdWriter.ImportTablePosition; + m_textWriter.Write (it.ImportLookupTable.Value); + m_textWriter.Write (it.DateTimeStamp); + m_textWriter.Write (it.ForwardChain); + m_textWriter.Write (it.Name.Value); + m_textWriter.Write (it.ImportAddressTable.Value); + m_textWriter.Write (new byte [20]); + } + + public override void VisitImportLookupTable (ImportLookupTable ilt) + { + m_textWriter.Write (ilt.HintNameRVA.Value); + m_textWriter.Write (new byte [16]); + } + + public override void VisitHintNameTable (HintNameTable hnt) + { + m_textWriter.Write (hnt.Hint); + m_textWriter.Write (Encoding.ASCII.GetBytes (hnt.RuntimeMain)); + m_textWriter.Write ('\0'); + m_textWriter.Write (Encoding.ASCII.GetBytes (hnt.RuntimeLibrary)); + m_textWriter.Write ('\0'); + m_textWriter.Write (new byte [4]); + + // patch header with ep rva + RVA ep = m_img.TextSection.VirtualAddress + + (uint) m_textWriter.BaseStream.Position; + long pos = m_binaryWriter.BaseStream.Position; + m_binaryWriter.BaseStream.Position = 0xa8; + m_binaryWriter.Write (ep.Value); + m_binaryWriter.BaseStream.Position = pos; + + // patch reloc Sect with ep + uint reloc = (ep.Value + 2) % 0x1000; + uint rva = (ep.Value + 2) - reloc; + + m_relocWriter.BaseStream.Position = 0; + m_relocWriter.Write (rva); + m_relocWriter.BaseStream.Position = 8; + m_relocWriter.Write ((ushort) ((3 << 12) | reloc)); + + m_textWriter.Write (hnt.EntryPoint); + m_textWriter.Write (hnt.RVA); + } + + public override void TerminateImage (Image img) + { + m_binaryWriter.BaseStream.Position = 0x200; + + WriteSection (m_textSect, m_textWriter); + WriteSection (m_relocSect, m_relocWriter); + if (m_rsrcSect != null) + WriteSection (m_rsrcSect, m_rsrcWriter); + } + + void WriteSection (Section sect, MemoryBinaryWriter sectWriter) + { + sectWriter.MemoryStream.WriteTo (m_binaryWriter.BaseStream); + m_binaryWriter.Write (new byte [ + sect.SizeOfRawData - sectWriter.BaseStream.Length]); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Imports.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Imports.cs new file mode 100644 index 0000000..021cb39 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Imports.cs @@ -0,0 +1,98 @@ +// +// Imports.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public sealed class ImportAddressTable : IBinaryVisitable { + + public RVA HintNameTableRVA; + + internal ImportAddressTable () + { + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitImportAddressTable (this); + } + } + + public sealed class ImportTable : IBinaryVisitable { + + public RVA ImportLookupTable; + public uint DateTimeStamp; + public uint ForwardChain; + public RVA Name; + public RVA ImportAddressTable; + + internal ImportTable () + { + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitImportTable (this); + } + } + + public sealed class ImportLookupTable : IBinaryVisitable { + + public RVA HintNameRVA; + + internal ImportLookupTable () + { + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitImportLookupTable (this); + } + } + + public sealed class HintNameTable : IBinaryVisitable { + + public const string RuntimeMainExe = "_CorExeMain"; + public const string RuntimeMainDll = "_CorDllMain"; + public const string RuntimeCorEE = "mscoree.dll"; + + public ushort Hint; + public string RuntimeMain; + public string RuntimeLibrary; + public ushort EntryPoint; + public RVA RVA; + + internal HintNameTable () + { + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitHintNameTable (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/MemoryBinaryWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/MemoryBinaryWriter.cs new file mode 100644 index 0000000..12c8156 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/MemoryBinaryWriter.cs @@ -0,0 +1,70 @@ +// +// MemoryBinaryWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System.IO; + using System.Text; + + internal sealed class MemoryBinaryWriter : BinaryWriter { + + public MemoryStream MemoryStream { + get { return (MemoryStream) this.BaseStream; } + } + + public MemoryBinaryWriter () : base (new MemoryStream ()) + { + } + + public MemoryBinaryWriter (Encoding enc) : base (new MemoryStream (), enc) + { + } + + public void Empty () + { + this.BaseStream.Position = 0; + this.BaseStream.SetLength (0); + } + + public void Write (MemoryBinaryWriter writer) + { + writer.MemoryStream.WriteTo (this.BaseStream); + } + + public byte [] ToArray () + { + return this.MemoryStream.ToArray (); + } + + public void QuadAlign () + { + this.BaseStream.Position += 3; + this.BaseStream.Position &= ~3; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/PEFileHeader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/PEFileHeader.cs new file mode 100644 index 0000000..f38ee62 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/PEFileHeader.cs @@ -0,0 +1,58 @@ +// +// PEFileHeader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public sealed class PEFileHeader : IHeader, IBinaryVisitable { + + public ushort Machine; + public ushort NumberOfSections; + public uint TimeDateStamp; + public uint PointerToSymbolTable; + public uint NumberOfSymbols; + public ushort OptionalHeaderSize; + public ImageCharacteristics Characteristics; + + internal PEFileHeader () + { + } + + public void SetDefaultValues () + { + Machine = 0x14c; + PointerToSymbolTable = 0; + NumberOfSymbols = 0; + OptionalHeaderSize = 0xe0; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitPEFileHeader (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/PEOptionalHeader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/PEOptionalHeader.cs new file mode 100644 index 0000000..0f27ff7 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/PEOptionalHeader.cs @@ -0,0 +1,200 @@ +// +// PEOptionalHeader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public sealed class PEOptionalHeader : IHeader, IBinaryVisitable { + + public StandardFieldsHeader StandardFields; + public NTSpecificFieldsHeader NTSpecificFields; + public DataDirectoriesHeader DataDirectories; + + internal PEOptionalHeader () + { + StandardFields = new StandardFieldsHeader (); + NTSpecificFields = new NTSpecificFieldsHeader (); + DataDirectories = new DataDirectoriesHeader (); + } + + public void SetDefaultValues () + { + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitPEOptionalHeader (this); + + StandardFields.Accept (visitor); + NTSpecificFields.Accept (visitor); + DataDirectories.Accept (visitor); + } + + public sealed class StandardFieldsHeader : IHeader, IBinaryVisitable { + + public ushort Magic; + public byte LMajor; + public byte LMinor; + public uint CodeSize; + public uint InitializedDataSize; + public uint UninitializedDataSize; + public RVA EntryPointRVA; + public RVA BaseOfCode; + public RVA BaseOfData; + + public bool IsPE64 { + get { return Magic == 0x20b; } + set { + if (value) + Magic = 0x20b; + else + Magic = 0x10b; + } + } + + internal StandardFieldsHeader () + { + } + + public void SetDefaultValues () + { + Magic = 0x10b; + LMajor = 6; + LMinor = 0; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitStandardFieldsHeader (this); + } + } + + public sealed class NTSpecificFieldsHeader : IHeader, IBinaryVisitable { + + public ulong ImageBase; + public uint SectionAlignment; + public uint FileAlignment; + public ushort OSMajor; + public ushort OSMinor; + public ushort UserMajor; + public ushort UserMinor; + public ushort SubSysMajor; + public ushort SubSysMinor; + public uint Reserved; + public uint ImageSize; + public uint HeaderSize; + public uint FileChecksum; + public SubSystem SubSystem; + public ushort DLLFlags; + public ulong StackReserveSize; + public ulong StackCommitSize; + public ulong HeapReserveSize; + public ulong HeapCommitSize; + public uint LoaderFlags; + public uint NumberOfDataDir; + + internal NTSpecificFieldsHeader () + { + } + + public void SetDefaultValues () + { + ImageBase = 0x400000; + SectionAlignment = 0x2000; + FileAlignment = 0x200; + OSMajor = 4; + OSMinor = 0; + UserMajor = 0; + UserMinor = 0; + SubSysMajor = 4; + SubSysMinor = 0; + Reserved = 0; + HeaderSize = 0x200; + FileChecksum = 0; + DLLFlags = 0; + StackReserveSize = 0x100000; + StackCommitSize = 0x1000; + HeapReserveSize = 0x100000; + HeapCommitSize = 0x1000; + LoaderFlags = 0; + NumberOfDataDir = 0x10; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitNTSpecificFieldsHeader (this); + } + } + + public sealed class DataDirectoriesHeader : IHeader, IBinaryVisitable { + + public DataDirectory ExportTable; + public DataDirectory ImportTable; + public DataDirectory ResourceTable; + public DataDirectory ExceptionTable; + public DataDirectory CertificateTable; + public DataDirectory BaseRelocationTable; + public DataDirectory Debug; + public DataDirectory Copyright; + public DataDirectory GlobalPtr; + public DataDirectory TLSTable; + public DataDirectory LoadConfigTable; + public DataDirectory BoundImport; + public DataDirectory IAT; + public DataDirectory DelayImportDescriptor; + public DataDirectory CLIHeader; + public DataDirectory Reserved; + + internal DataDirectoriesHeader () + { + } + + public void SetDefaultValues () + { + ExportTable = DataDirectory.Zero; + ResourceTable = DataDirectory.Zero; + ExceptionTable = DataDirectory.Zero; + CertificateTable = DataDirectory.Zero; + Debug = DataDirectory.Zero; + Copyright = DataDirectory.Zero; + GlobalPtr = DataDirectory.Zero; + TLSTable = DataDirectory.Zero; + LoadConfigTable = DataDirectory.Zero; + BoundImport = DataDirectory.Zero; + IAT = new DataDirectory (new RVA (0x2000), 8); + DelayImportDescriptor = DataDirectory.Zero; + CLIHeader = new DataDirectory (new RVA (0x2008), 0x48); + Reserved = DataDirectory.Zero; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitDataDirectoriesHeader (this); + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/RVA.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/RVA.cs new file mode 100644 index 0000000..09fae0d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/RVA.cs @@ -0,0 +1,115 @@ +// +// RVA.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public struct RVA { + + public static readonly RVA Zero = new RVA (0); + + uint m_rva; + + public uint Value { + get { return m_rva; } + set { m_rva = value; } + } + + public RVA (uint rva) + { + m_rva = rva; + } + + public override int GetHashCode () + { + return (int) m_rva; + } + + public override bool Equals (object other) + { + if (other is RVA) + return this.m_rva == ((RVA) other).m_rva; + + return false; + } + + public override string ToString () + { + return string.Format ("0x{0}", m_rva.ToString ("X")); + } + + public static bool operator == (RVA one, RVA other) + { + return one.Equals (other); + } + + public static bool operator != (RVA one, RVA other) + { + return !one.Equals (other); + } + + public static bool operator < (RVA one, RVA other) + { + return one.m_rva < other.m_rva; + } + + public static bool operator > (RVA one, RVA other) + { + return one.m_rva > other.m_rva; + } + + public static bool operator <= (RVA one, RVA other) + { + return one.m_rva <= other.m_rva; + } + + public static bool operator >= (RVA one, RVA other) + { + return one.m_rva >= other.m_rva; + } + + public static RVA operator + (RVA rva, uint x) + { + return new RVA (rva.m_rva + x); + } + + public static RVA operator - (RVA rva, uint x) + { + return new RVA (rva.m_rva - x); + } + + public static implicit operator RVA (uint val) + { + return val == 0 ? RVA.Zero : new RVA (val); + } + + public static implicit operator uint (RVA rva) + { + return rva.m_rva; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDataEntry.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDataEntry.cs new file mode 100644 index 0000000..c2b3b3f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDataEntry.cs @@ -0,0 +1,48 @@ +// +// ResourceDataEntry.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public class ResourceDataEntry : ResourceNode { + + public RVA Data; + public uint Size; + public uint Codepage; + public uint Reserved = 0; + + public byte [] ResourceData; + + public ResourceDataEntry (int offset) : base (offset) + { + } + + public ResourceDataEntry () + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryEntry.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryEntry.cs new file mode 100644 index 0000000..5588b3c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryEntry.cs @@ -0,0 +1,66 @@ +// +// ResourceDirectoryEntry.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public class ResourceDirectoryEntry : ResourceNode { + + private bool m_idByName; + + public int ID; + public ResourceDirectoryString Name; + + public bool IdentifiedByName { + get { return m_idByName; } + } + + public ResourceNode Child; + + public ResourceDirectoryEntry (ResourceDirectoryString name) + { + this.Name = name; + m_idByName = true; + } + + public ResourceDirectoryEntry (ResourceDirectoryString name, int offset) : base (offset) + { + this.Name = name; + m_idByName = true; + } + + public ResourceDirectoryEntry (int id) + { + this.ID = id; + } + + public ResourceDirectoryEntry (int id, int offset) : base (offset) + { + this.ID = id; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryString.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryString.cs new file mode 100644 index 0000000..8c006e0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryString.cs @@ -0,0 +1,45 @@ +// +// ResourceDirectoryString.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public class ResourceDirectoryString : ResourceNode { + + public string String; + + public ResourceDirectoryString (string str) + { + this.String = str; + } + + public ResourceDirectoryString (string str, int offset) : base (offset) + { + this.String = str; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryTable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryTable.cs new file mode 100644 index 0000000..12517bf --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceDirectoryTable.cs @@ -0,0 +1,56 @@ +// +// ResourceDirectoryTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System.Collections; + + public class ResourceDirectoryTable : ResourceNode { + + private ArrayList m_entries; + + public uint Characteristics; + public uint TimeDateStamp; + public ushort MajorVersion; + public ushort MinorVersion; + + public IList Entries { + get { return m_entries; } + } + + public ResourceDirectoryTable (int offset) : base (offset) + { + m_entries = new ArrayList (); + } + + public ResourceDirectoryTable () + { + m_entries = new ArrayList (); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceNode.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceNode.cs new file mode 100644 index 0000000..b51ebd5 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceNode.cs @@ -0,0 +1,44 @@ +// +// ResourceNode.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public abstract class ResourceNode { + + public int Offset; + + internal ResourceNode (int offset) + { + this.Offset = offset; + } + + internal ResourceNode () + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceReader.cs new file mode 100644 index 0000000..60d16e7 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceReader.cs @@ -0,0 +1,143 @@ +// +// ResourceReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System.IO; + using System.Text; + + class ResourceReader { + + Image m_img; + Section m_rsrc; + BinaryReader m_reader; + + public ResourceReader (Image img) + { + m_img = img; + } + + public ResourceDirectoryTable Read () + { + m_rsrc = GetResourceSection (); + if (m_rsrc == null) + return null; + + m_reader = new BinaryReader (new MemoryStream (m_rsrc.Data)); + return ReadDirectoryTable (); + } + + Section GetResourceSection () + { + foreach (Section s in m_img.Sections) + if (s.Name == Section.Resources) + return s; + + return null; + } + + int GetOffset () + { + return (int) m_reader.BaseStream.Position; + } + + ResourceDirectoryTable ReadDirectoryTable () + { + ResourceDirectoryTable rdt = new ResourceDirectoryTable (GetOffset ()); + rdt.Characteristics = m_reader.ReadUInt32 (); + rdt.TimeDateStamp = m_reader.ReadUInt32 (); + rdt.MajorVersion = m_reader.ReadUInt16 (); + rdt.MinorVersion = m_reader.ReadUInt16 (); + ushort nameEntries = m_reader.ReadUInt16 (); + ushort idEntries = m_reader.ReadUInt16 (); + + for (int i = 0; i < nameEntries; i++) + rdt.Entries.Add (ReadDirectoryEntry ()); + + for (int i = 0; i < idEntries; i++) + rdt.Entries.Add (ReadDirectoryEntry ()); + + return rdt; + } + + ResourceDirectoryEntry ReadDirectoryEntry () + { + uint name = m_reader.ReadUInt32 (); + uint child = m_reader.ReadUInt32 (); + + ResourceDirectoryEntry rde; + if ((name & 0x80000000) != 0) + rde = new ResourceDirectoryEntry (ReadDirectoryString ((int) name & 0x7fffffff), GetOffset ()); + else + rde = new ResourceDirectoryEntry ((int) name & 0x7fffffff, GetOffset ()); + + long pos = m_reader.BaseStream.Position; + m_reader.BaseStream.Position = child & 0x7fffffff; + + if ((child & 0x80000000) != 0) + rde.Child = ReadDirectoryTable (); + else + rde.Child = ReadDataEntry (); + + m_reader.BaseStream.Position = pos; + + return rde; + } + + ResourceDirectoryString ReadDirectoryString (int offset) + { + long pos = m_reader.BaseStream.Position; + m_reader.BaseStream.Position = offset; + + byte [] str = m_reader.ReadBytes (m_reader.ReadUInt16 ()); + + ResourceDirectoryString rds = new ResourceDirectoryString ( + Encoding.Unicode.GetString (str, 0, str.Length), + GetOffset ()); + + m_reader.BaseStream.Position = pos; + + return rds; + } + + ResourceNode ReadDataEntry () + { + ResourceDataEntry rde = new ResourceDataEntry (GetOffset ()); + rde.Data = m_reader.ReadUInt32 (); + rde.Size = m_reader.ReadUInt32 (); + rde.Codepage = m_reader.ReadUInt32 (); + rde.Reserved = m_reader.ReadUInt32 (); + + BinaryReader dataReader = m_img.GetReaderAtVirtualAddress (rde.Data); + rde.ResourceData = dataReader.ReadBytes ((int) rde.Size); + dataReader.Close (); + + return rde; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceWriter.cs new file mode 100644 index 0000000..8965f64 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/ResourceWriter.cs @@ -0,0 +1,216 @@ +// +// ResourceWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Text; + +namespace Mono.Cecil.Binary { + + using System.Collections; + + class ResourceWriter { + + Image m_img; + Section m_rsrc; + MemoryBinaryWriter m_writer; + + ArrayList m_dataEntries; + ArrayList m_stringEntries; + + long m_pos; + + public ResourceWriter (Image img, Section rsrc, MemoryBinaryWriter writer) + { + m_img = img; + m_rsrc = rsrc; + m_writer = writer; + + m_dataEntries = new ArrayList (); + m_stringEntries = new ArrayList (); + } + + public void Write () + { + if (m_img.ResourceDirectoryRoot == null) + return; + + ComputeOffset (m_img.ResourceDirectoryRoot); + WriteResourceDirectoryTable (m_img.ResourceDirectoryRoot); + } + + public void Patch () + { + foreach (ResourceDataEntry rde in m_dataEntries) { + GotoOffset (rde.Offset); + m_writer.Write ((uint) rde.Data + m_rsrc.VirtualAddress); + RestoreOffset (); + } + } + + void ComputeOffset (ResourceDirectoryTable root) + { + int offset = 0; + + Queue directoryTables = new Queue (); + directoryTables.Enqueue (root); + + while (directoryTables.Count > 0) { + ResourceDirectoryTable rdt = directoryTables.Dequeue () as ResourceDirectoryTable; + rdt.Offset = offset; + offset += 16; + + foreach (ResourceDirectoryEntry rde in rdt.Entries) { + rde.Offset = offset; + offset += 8; + if (rde.IdentifiedByName) + m_stringEntries.Add (rde.Name); + + if (rde.Child is ResourceDirectoryTable) + directoryTables.Enqueue (rde.Child); + else + m_dataEntries.Add (rde.Child); + } + } + + foreach (ResourceDataEntry rde in m_dataEntries) { + rde.Offset = offset; + offset += 16; + } + + foreach (ResourceDirectoryString rds in m_stringEntries) { + rds.Offset = offset; + byte [] str = Encoding.Unicode.GetBytes (rds.String); + offset += 2 + str.Length; + + offset += 3; + offset &= ~3; + } + + foreach (ResourceDataEntry rde in m_dataEntries) { + rde.Data = (uint) offset; + + offset += rde.ResourceData.Length; + offset += 3; + offset &= ~3; + } + + m_writer.Write (new byte [offset]); + } + + void WriteResourceDirectoryTable (ResourceDirectoryTable rdt) + { + GotoOffset (rdt.Offset); + + m_writer.Write (rdt.Characteristics); + m_writer.Write (rdt.TimeDateStamp); + m_writer.Write (rdt.MajorVersion); + m_writer.Write (rdt.MinorVersion); + + ResourceDirectoryEntry [] namedEntries = GetEntries (rdt, true); + ResourceDirectoryEntry [] idEntries = GetEntries (rdt, false); + + m_writer.Write ((ushort) namedEntries.Length); + m_writer.Write ((ushort) idEntries.Length); + + foreach (ResourceDirectoryEntry rde in namedEntries) + WriteResourceDirectoryEntry (rde); + + foreach (ResourceDirectoryEntry rde in idEntries) + WriteResourceDirectoryEntry (rde); + + RestoreOffset (); + } + + ResourceDirectoryEntry [] GetEntries (ResourceDirectoryTable rdt, bool identifiedByName) + { + ArrayList entries = new ArrayList (); + foreach (ResourceDirectoryEntry rde in rdt.Entries) + if (rde.IdentifiedByName == identifiedByName) + entries.Add (rde); + + return entries.ToArray (typeof (ResourceDirectoryEntry)) as ResourceDirectoryEntry []; + } + + void WriteResourceDirectoryEntry (ResourceDirectoryEntry rde) + { + GotoOffset (rde.Offset); + + if (rde.IdentifiedByName) { + m_writer.Write ((uint) rde.Name.Offset | 0x80000000); + WriteResourceDirectoryString (rde.Name); + } else + m_writer.Write ((uint) rde.ID); + + if (rde.Child is ResourceDirectoryTable) { + m_writer.Write((uint) rde.Child.Offset | 0x80000000); + WriteResourceDirectoryTable (rde.Child as ResourceDirectoryTable); + } else { + m_writer.Write (rde.Child.Offset); + WriteResourceDataEntry (rde.Child as ResourceDataEntry); + } + + RestoreOffset (); + } + + void WriteResourceDataEntry (ResourceDataEntry rde) + { + GotoOffset (rde.Offset); + + m_writer.Write (0); + m_writer.Write ((uint) rde.ResourceData.Length); + m_writer.Write (rde.Codepage); + m_writer.Write (rde.Reserved); + + m_writer.BaseStream.Position = rde.Data; + m_writer.Write (rde.ResourceData); + + RestoreOffset (); + } + + void WriteResourceDirectoryString (ResourceDirectoryString name) + { + GotoOffset (name.Offset); + + byte [] str = Encoding.Unicode.GetBytes (name.String); + m_writer.Write ((ushort) str.Length); + m_writer.Write (str); + + RestoreOffset (); + } + + void GotoOffset (int offset) + { + m_pos = m_writer.BaseStream.Position; + m_writer.BaseStream.Position = offset; + } + + void RestoreOffset () + { + m_writer.BaseStream.Position = m_pos; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/RuntimeImage.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/RuntimeImage.cs new file mode 100644 index 0000000..8866ebb --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/RuntimeImage.cs @@ -0,0 +1,37 @@ +// +// RuntimeImage.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public enum RuntimeImage : uint { + ILOnly = 0x0000001, + F32BitsRequired = 0x0000002, + StrongNameSigned = 0x0000008, + TrackDebugData = 0x00010000 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Section.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Section.cs new file mode 100644 index 0000000..a05714b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/Section.cs @@ -0,0 +1,66 @@ +// +// Section.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public sealed class Section : IHeader, IBinaryVisitable { + + public const string Text = ".text"; + public const string Resources = ".rsrc"; + public const string Relocs = ".reloc"; + public const string SData = ".sdata"; + + public uint VirtualSize; + public RVA VirtualAddress; + public uint SizeOfRawData; + public RVA PointerToRawData; + public RVA PointerToRelocations; + public RVA PointerToLineNumbers; + public ushort NumberOfRelocations; + public ushort NumberOfLineNumbers; + public SectionCharacteristics Characteristics; + + public string Name; + public byte [] Data; + + internal Section () + { + } + + public void SetDefaultValues () + { + PointerToLineNumbers = RVA.Zero; + NumberOfLineNumbers = 0; + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitSection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SectionCharacteristics.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SectionCharacteristics.cs new file mode 100644 index 0000000..66d97ed --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SectionCharacteristics.cs @@ -0,0 +1,70 @@ +// +// SectionCharacteristics.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System; + + [Flags] + public enum SectionCharacteristics : uint { + TypeNoPad = 0x0000008, + ContainsCode = 0x00000020, + ContainsInitializedData = 0x00000040, + ContainsUninitializedData = 0x00000080, + LnkOther = 0x0000100, + LnkInfo = 0x000200, + LnkRemove = 0x0000800, + LnkCOMDAT = 0x00001000, + GPRel = 0x00008000, + MemPurgeable = 0x00020000, + MemLocked = 0x00040000, + MemPreload = 0x00080000, + Align1Bytes = 0x00100000, + Align2Bytes = 0x00200000, + Align4Bytes = 0x00300000, + Align8Bytes = 0x00400000, + Align16Bytes = 0x00500000, + Align32Bytes = 0x00600000, + Align64Bytes = 0x00700000, + Align128Bytes = 0x00800000, + Align256Bytes = 0x00900000, + Align512Bytes = 0x00a00000, + Align1024Bytes = 0x00b00000, + Align2048Bytes = 0x00c00000, + Align4096Bytes = 0x00d00000, + Align8192Bytes = 0x00e00000, + LnkNRelocOvfl = 0x01000000, + MemDiscardable = 0x02000000, + MemNotCached = 0x04000000, + MemNotPaged = 0x08000000, + MemShared = 0x10000000, + MemExecute = 0x20000000, + MemoryRead = 0x40000000, + MemoryWrite = 0x80000000 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SectionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SectionCollection.cs new file mode 100644 index 0000000..2d90eee --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SectionCollection.cs @@ -0,0 +1,114 @@ +// +// SectionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + using System; + using System.Collections; + + public sealed class SectionCollection : ICollection, IBinaryVisitable { + + IList m_items; + + public Section this [int index] + { + get { return m_items [index] as Section; } + set { m_items [index] = value; } + } + + public int Count { + get { return m_items.Count; } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + internal SectionCollection () + { + m_items = new ArrayList (4); + } + + internal void Add (Section value) + { + m_items.Add (value); + } + + internal void Clear () + { + m_items.Clear (); + } + + public bool Contains (Section value) + { + return m_items.Contains (value); + } + + public int IndexOf (Section value) + { + return m_items.IndexOf (value); + } + + internal void Insert (int index, Section value) + { + m_items.Insert (index, value); + } + + internal void Remove (Section value) + { + m_items.Remove (value); + } + + internal void RemoveAt (int index) + { + m_items.Remove (index); + } + + public void CopyTo (Array ary, int index) + { + m_items.CopyTo (ary, index); + } + + public IEnumerator GetEnumerator () + { + return m_items.GetEnumerator (); + } + + public void Accept (IBinaryVisitor visitor) + { + visitor.VisitSectionCollection (this); + + for (int i = 0; i < m_items.Count; i++) + this [i].Accept (visitor); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SubSystem.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SubSystem.cs new file mode 100644 index 0000000..2cab910 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Binary/SubSystem.cs @@ -0,0 +1,45 @@ +// +// SubSystem.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Binary { + + public enum SubSystem : ushort { + Unknown = 0x0, + Native = 0x1, + WindowsGui = 0x2, + WindowsCui = 0x3, + PosixCui = 0x7, + WindowsCeGui = 0x9, + EfiApplication = 0x10, + EfiBootServiceDriver = 0x11, + EfiRuntimeDriver = 0x12, + EfiRom = 0x13, + Xbox = 0x14, + NexusAgent = 0x15 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/BaseCodeVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/BaseCodeVisitor.cs new file mode 100644 index 0000000..d6e5051 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/BaseCodeVisitor.cs @@ -0,0 +1,73 @@ +// +// BaseCodeVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public abstract class BaseCodeVisitor : ICodeVisitor { + + public virtual void VisitMethodBody (MethodBody body) + { + } + + public virtual void VisitInstructionCollection (InstructionCollection instructions) + { + } + + public virtual void VisitInstruction (Instruction instr) + { + } + + public virtual void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh) + { + } + + public virtual void VisitExceptionHandler (ExceptionHandler eh) + { + } + + public virtual void VisitVariableDefinitionCollection (VariableDefinitionCollection variables) + { + } + + public virtual void VisitVariableDefinition (VariableDefinition var) + { + } + + public virtual void VisitScopeCollection (ScopeCollection scopes) + { + } + + public virtual void VisitScope (Scope s) + { + } + + public virtual void TerminateMethodBody (MethodBody body) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CilWorker.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CilWorker.cs new file mode 100644 index 0000000..fbdc0ee --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CilWorker.cs @@ -0,0 +1,357 @@ +// +// CilWorker.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using SR = System.Reflection; + + public sealed class CilWorker { + + MethodBody m_mbody; + InstructionCollection m_instrs; + + internal CilWorker (MethodBody body) + { + m_mbody = body; + m_instrs = m_mbody.Instructions; + } + + public MethodBody GetBody () + { + return m_mbody; + } + + public Instruction Create (OpCode opcode) + { + if (opcode.OperandType != OperandType.InlineNone) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode); + } + + public Instruction Create (OpCode opcode, TypeReference type) + { + if (opcode.OperandType != OperandType.InlineType && + opcode.OperandType != OperandType.InlineTok) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, type); + } + + public Instruction Create (OpCode opcode, MethodReference meth) + { + if (opcode.OperandType != OperandType.InlineMethod && + opcode.OperandType != OperandType.InlineTok) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, meth); + } + + public Instruction Create (OpCode opcode, FieldReference field) + { + if (opcode.OperandType != OperandType.InlineField && + opcode.OperandType != OperandType.InlineTok) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, field); + } + + public Instruction Create (OpCode opcode, string str) + { + if (opcode.OperandType != OperandType.InlineString) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, str); + } + + public Instruction Create (OpCode opcode, sbyte b) + { + if (opcode.OperandType != OperandType.ShortInlineI && + opcode != OpCodes.Ldc_I4_S) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, b); + } + + public Instruction Create (OpCode opcode, byte b) + { + if (opcode.OperandType != OperandType.ShortInlineI || + opcode == OpCodes.Ldc_I4_S) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, b); + } + + public Instruction Create (OpCode opcode, int i) + { + if (opcode.OperandType != OperandType.InlineI) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, i); + } + + public Instruction Create (OpCode opcode, long l) + { + if (opcode.OperandType != OperandType.InlineI8) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, l); + } + + public Instruction Create (OpCode opcode, float f) + { + if (opcode.OperandType != OperandType.ShortInlineR) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, f); + } + + public Instruction Create (OpCode opcode, double d) + { + if (opcode.OperandType != OperandType.InlineR) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, d); + } + + public Instruction Create (OpCode opcode, Instruction label) + { + if (opcode.OperandType != OperandType.InlineBrTarget && + opcode.OperandType != OperandType.ShortInlineBrTarget) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, label); + } + + public Instruction Create (OpCode opcode, Instruction [] labels) + { + if (opcode.OperandType != OperandType.InlineSwitch) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, labels); + } + + public Instruction Create (OpCode opcode, VariableDefinition var) + { + if (opcode.OperandType != OperandType.ShortInlineVar && + opcode.OperandType != OperandType.InlineVar) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, var); + } + + public Instruction Create (OpCode opcode, ParameterDefinition param) + { + if (opcode.OperandType != OperandType.ShortInlineParam && + opcode.OperandType != OperandType.InlineParam) + throw new ArgumentException ("opcode"); + + return FinalCreate (opcode, param); + } + + Instruction FinalCreate (OpCode opcode) + { + return FinalCreate (opcode, null); + } + + Instruction FinalCreate (OpCode opcode, object operand) + { + return new Instruction (opcode, operand); + } + + public Instruction Emit (OpCode opcode) + { + Instruction instr = Create (opcode); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, TypeReference type) + { + Instruction instr = Create (opcode, type); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, MethodReference meth) + { + Instruction instr = Create (opcode, meth); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, FieldReference field) + { + Instruction instr = Create (opcode, field); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, string str) + { + Instruction instr = Create (opcode, str); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, byte b) + { + Instruction instr = Create (opcode, b); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, sbyte b) + { + Instruction instr = Create (opcode, b); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, int i) + { + Instruction instr = Create (opcode, i); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, long l) + { + Instruction instr = Create (opcode, l); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, float f) + { + Instruction instr = Create (opcode, f); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, double d) + { + Instruction instr = Create (opcode, d); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, Instruction target) + { + Instruction instr = Create (opcode, target); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, Instruction [] targets) + { + Instruction instr = Create (opcode, targets); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, VariableDefinition var) + { + Instruction instr = Create (opcode, var); + Append (instr); + return instr; + } + + public Instruction Emit (OpCode opcode, ParameterDefinition param) + { + Instruction instr = Create (opcode, param); + Append (instr); + return instr; + } + + public void InsertBefore (Instruction target, Instruction instr) + { + int index = m_instrs.IndexOf (target); + if (index == -1) + throw new ArgumentOutOfRangeException ("Target instruction not in method body"); + + m_instrs.Insert (index, instr); + instr.Previous = target.Previous; + if (target.Previous != null) + target.Previous.Next = instr; + target.Previous = instr; + instr.Next = target; + } + + public void InsertAfter (Instruction target, Instruction instr) + { + int index = m_instrs.IndexOf (target); + if (index == -1) + throw new ArgumentOutOfRangeException ("Target instruction not in method body"); + + m_instrs.Insert (index + 1, instr); + instr.Next = target.Next; + if (target.Next != null) + target.Next.Previous = instr; + target.Next = instr; + instr.Previous = target; + } + + public void Append (Instruction instr) + { + Instruction last = null, current = instr; + if (m_instrs.Count > 0) + last = m_instrs [m_instrs.Count - 1]; + + if (last != null) { + last.Next = instr; + current.Previous = last; + } + + m_instrs.Add (current); + } + + public void Replace (Instruction old, Instruction instr) + { + int index = m_instrs.IndexOf (old); + if (index == -1) + throw new ArgumentOutOfRangeException ("Target instruction not in method body"); + + InsertAfter (old, instr); + Remove (old); + } + + public void Remove (Instruction instr) + { + if (!m_instrs.Contains (instr)) + throw new ArgumentException ("Instruction not in method body"); + + if (instr.Previous != null) + instr.Previous.Next = instr.Next; + if (instr.Next != null) + instr.Next.Previous = instr.Previous; + m_instrs.Remove (instr); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Code.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Code.cs new file mode 100644 index 0000000..af70ab5 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Code.cs @@ -0,0 +1,255 @@ +// +// Code.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 16 15:37:23 +0100 2007 +// +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public enum Code { + Nop, + Break, + Ldarg_0, + Ldarg_1, + Ldarg_2, + Ldarg_3, + Ldloc_0, + Ldloc_1, + Ldloc_2, + Ldloc_3, + Stloc_0, + Stloc_1, + Stloc_2, + Stloc_3, + Ldarg_S, + Ldarga_S, + Starg_S, + Ldloc_S, + Ldloca_S, + Stloc_S, + Ldnull, + Ldc_I4_M1, + Ldc_I4_0, + Ldc_I4_1, + Ldc_I4_2, + Ldc_I4_3, + Ldc_I4_4, + Ldc_I4_5, + Ldc_I4_6, + Ldc_I4_7, + Ldc_I4_8, + Ldc_I4_S, + Ldc_I4, + Ldc_I8, + Ldc_R4, + Ldc_R8, + Dup, + Pop, + Jmp, + Call, + Calli, + Ret, + Br_S, + Brfalse_S, + Brtrue_S, + Beq_S, + Bge_S, + Bgt_S, + Ble_S, + Blt_S, + Bne_Un_S, + Bge_Un_S, + Bgt_Un_S, + Ble_Un_S, + Blt_Un_S, + Br, + Brfalse, + Brtrue, + Beq, + Bge, + Bgt, + Ble, + Blt, + Bne_Un, + Bge_Un, + Bgt_Un, + Ble_Un, + Blt_Un, + Switch, + Ldind_I1, + Ldind_U1, + Ldind_I2, + Ldind_U2, + Ldind_I4, + Ldind_U4, + Ldind_I8, + Ldind_I, + Ldind_R4, + Ldind_R8, + Ldind_Ref, + Stind_Ref, + Stind_I1, + Stind_I2, + Stind_I4, + Stind_I8, + Stind_R4, + Stind_R8, + Add, + Sub, + Mul, + Div, + Div_Un, + Rem, + Rem_Un, + And, + Or, + Xor, + Shl, + Shr, + Shr_Un, + Neg, + Not, + Conv_I1, + Conv_I2, + Conv_I4, + Conv_I8, + Conv_R4, + Conv_R8, + Conv_U4, + Conv_U8, + Callvirt, + Cpobj, + Ldobj, + Ldstr, + Newobj, + Castclass, + Isinst, + Conv_R_Un, + Unbox, + Throw, + Ldfld, + Ldflda, + Stfld, + Ldsfld, + Ldsflda, + Stsfld, + Stobj, + Conv_Ovf_I1_Un, + Conv_Ovf_I2_Un, + Conv_Ovf_I4_Un, + Conv_Ovf_I8_Un, + Conv_Ovf_U1_Un, + Conv_Ovf_U2_Un, + Conv_Ovf_U4_Un, + Conv_Ovf_U8_Un, + Conv_Ovf_I_Un, + Conv_Ovf_U_Un, + Box, + Newarr, + Ldlen, + Ldelema, + Ldelem_I1, + Ldelem_U1, + Ldelem_I2, + Ldelem_U2, + Ldelem_I4, + Ldelem_U4, + Ldelem_I8, + Ldelem_I, + Ldelem_R4, + Ldelem_R8, + Ldelem_Ref, + Stelem_I, + Stelem_I1, + Stelem_I2, + Stelem_I4, + Stelem_I8, + Stelem_R4, + Stelem_R8, + Stelem_Ref, + Ldelem_Any, + Stelem_Any, + Unbox_Any, + Conv_Ovf_I1, + Conv_Ovf_U1, + Conv_Ovf_I2, + Conv_Ovf_U2, + Conv_Ovf_I4, + Conv_Ovf_U4, + Conv_Ovf_I8, + Conv_Ovf_U8, + Refanyval, + Ckfinite, + Mkrefany, + Ldtoken, + Conv_U2, + Conv_U1, + Conv_I, + Conv_Ovf_I, + Conv_Ovf_U, + Add_Ovf, + Add_Ovf_Un, + Mul_Ovf, + Mul_Ovf_Un, + Sub_Ovf, + Sub_Ovf_Un, + Endfinally, + Leave, + Leave_S, + Stind_I, + Conv_U, + Arglist, + Ceq, + Cgt, + Cgt_Un, + Clt, + Clt_Un, + Ldftn, + Ldvirtftn, + Ldarg, + Ldarga, + Starg, + Ldloc, + Ldloca, + Stloc, + Localloc, + Endfilter, + Unaligned, + Volatile, + Tail, + Initobj, + Constrained, + Cpblk, + Initblk, + No, + Rethrow, + Sizeof, + Refanytype, + Readonly, + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs new file mode 100644 index 0000000..20b1654 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CodeReader.cs @@ -0,0 +1,355 @@ +// +// CodeReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using System.Collections; + using System.IO; + + using Mono.Cecil; + using Mono.Cecil.Metadata; + using Mono.Cecil.Signatures; + + class CodeReader : BaseCodeVisitor { + + ReflectionReader m_reflectReader; + MetadataRoot m_root; + + public CodeReader (ReflectionReader reflectReader) + { + m_reflectReader = reflectReader; + m_root = m_reflectReader.MetadataRoot; + } + + public override void VisitMethodBody (MethodBody body) + { + MethodDefinition meth = body.Method; + MethodBody methBody = body; + BinaryReader br = m_reflectReader.Module.ImageReader.MetadataReader.GetDataReader (meth.RVA); + + // lets read the method + IDictionary instrs; + int flags = br.ReadByte (); + switch (flags & 0x3) { + case (int) MethodHeader.TinyFormat : + methBody.CodeSize = flags >> 2; + methBody.MaxStack = 8; + ReadCilBody (methBody, br, out instrs); + break; + case (int) MethodHeader.FatFormat : + br.BaseStream.Position--; + int fatflags = br.ReadUInt16 (); + //int headersize = (fatflags >> 12) & 0xf; + methBody.MaxStack = br.ReadUInt16 (); + methBody.CodeSize = br.ReadInt32 (); + methBody.LocalVarToken = br.ReadInt32 (); + body.InitLocals = (fatflags & (int) MethodHeader.InitLocals) != 0; + VisitVariableDefinitionCollection (methBody.Variables); + ReadCilBody (methBody, br, out instrs); + if ((fatflags & (int) MethodHeader.MoreSects) != 0) + ReadSection (methBody, br, instrs); + break; + } + + if (m_reflectReader.SymbolReader != null) + m_reflectReader.SymbolReader.Read (methBody); + } + + public static uint GetRid (int token) + { + return (uint) token & 0x00ffffff; + } + + public static ParameterDefinition GetParameter (MethodBody body, int index) + { + if (body.Method.HasThis) { + if (index == 0) + return body.Method.This; + index--; + } + + return body.Method.Parameters [index]; + } + + public static VariableDefinition GetVariable (MethodBody body, int index) + { + return body.Variables [index]; + } + + void ReadCilBody (MethodBody body, BinaryReader br, out IDictionary instructions) + { + long start = br.BaseStream.Position; + Instruction last = null; + InstructionCollection code = body.Instructions; + instructions = new Hashtable (); + GenericContext context = new GenericContext (body.Method); + + while (br.BaseStream.Position < start + body.CodeSize) { + OpCode op; + long offset = br.BaseStream.Position - start; + int cursor = br.ReadByte (); + if (cursor == 0xfe) + op = OpCodes.TwoBytesOpCode [br.ReadByte ()]; + else + op = OpCodes.OneByteOpCode [cursor]; + + Instruction instr = new Instruction ((int) offset, op); + switch (op.OperandType) { + case OperandType.InlineNone : + break; + case OperandType.InlineSwitch : + uint length = br.ReadUInt32 (); + int [] branches = new int [length]; + int [] buf = new int [length]; + for (int i = 0; i < length; i++) + buf [i] = br.ReadInt32 (); + for (int i = 0; i < length; i++) + branches [i] = Convert.ToInt32 (br.BaseStream.Position - start + buf [i]); + instr.Operand = branches; + break; + case OperandType.ShortInlineBrTarget : + sbyte sbrtgt = br.ReadSByte (); + instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + sbrtgt); + break; + case OperandType.InlineBrTarget : + int brtgt = br.ReadInt32 (); + instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + brtgt); + break; + case OperandType.ShortInlineI : + if (op == OpCodes.Ldc_I4_S) + instr.Operand = br.ReadSByte (); + else + instr.Operand = br.ReadByte (); + break; + case OperandType.ShortInlineVar : + instr.Operand = GetVariable (body, br.ReadByte ()); + break; + case OperandType.ShortInlineParam : + instr.Operand = GetParameter (body, br.ReadByte ()); + break; + case OperandType.InlineSig : + instr.Operand = GetCallSiteAt (br.ReadInt32 (), context); + break; + case OperandType.InlineI : + instr.Operand = br.ReadInt32 (); + break; + case OperandType.InlineVar : + instr.Operand = GetVariable (body, br.ReadInt16 ()); + break; + case OperandType.InlineParam : + instr.Operand = GetParameter (body, br.ReadInt16 ()); + break; + case OperandType.InlineI8 : + instr.Operand = br.ReadInt64 (); + break; + case OperandType.ShortInlineR : + instr.Operand = br.ReadSingle (); + break; + case OperandType.InlineR : + instr.Operand = br.ReadDouble (); + break; + case OperandType.InlineString : + instr.Operand = m_root.Streams.UserStringsHeap [GetRid (br.ReadInt32 ())]; + break; + case OperandType.InlineField : + case OperandType.InlineMethod : + case OperandType.InlineType : + case OperandType.InlineTok : + MetadataToken token = new MetadataToken (br.ReadInt32 ()); + switch (token.TokenType) { + case TokenType.TypeDef: + instr.Operand = m_reflectReader.GetTypeDefAt (token.RID); + break; + case TokenType.TypeRef: + instr.Operand = m_reflectReader.GetTypeRefAt (token.RID); + break; + case TokenType.TypeSpec: + instr.Operand = m_reflectReader.GetTypeSpecAt (token.RID, context); + break; + case TokenType.Field: + instr.Operand = m_reflectReader.GetFieldDefAt (token.RID); + break; + case TokenType.Method: + instr.Operand = m_reflectReader.GetMethodDefAt (token.RID); + break; + case TokenType.MethodSpec: + instr.Operand = m_reflectReader.GetMethodSpecAt (token.RID, context); + break; + case TokenType.MemberRef: + instr.Operand = m_reflectReader.GetMemberRefAt (token.RID, context); + break; + default: + throw new ReflectionException ("Wrong token: " + token); + } + break; + } + + instructions.Add (instr.Offset, instr); + + if (last != null) { + last.Next = instr; + instr.Previous = last; + } + + last = instr; + + code.Add (instr); + } + + // resolve branches + foreach (Instruction i in code) { + switch (i.OpCode.OperandType) { + case OperandType.ShortInlineBrTarget: + case OperandType.InlineBrTarget: + i.Operand = GetInstruction (body, instructions, (int) i.Operand); + break; + case OperandType.InlineSwitch: + int [] lbls = (int []) i.Operand; + Instruction [] instrs = new Instruction [lbls.Length]; + for (int j = 0; j < lbls.Length; j++) + instrs [j] = GetInstruction (body, instructions, lbls [j]); + i.Operand = instrs; + break; + } + } + } + + static Instruction GetInstruction (MethodBody body, IDictionary instructions, int offset) + { + Instruction instruction = instructions [offset] as Instruction; + if (instruction != null) + return instruction; + + return body.Instructions.Outside; + } + + void ReadSection (MethodBody body, BinaryReader br, IDictionary instructions) + { + br.BaseStream.Position += 3; + br.BaseStream.Position &= ~3; + + byte flags = br.ReadByte (); + if ((flags & (byte) MethodDataSection.FatFormat) == 0) { + int length = br.ReadByte () / 12; + br.ReadBytes (2); + + for (int i = 0; i < length; i++) { + ExceptionHandler eh = new ExceptionHandler ( + (ExceptionHandlerType) (br.ReadInt16 () & 0x7)); + eh.TryStart = GetInstruction (body, instructions, Convert.ToInt32 (br.ReadInt16 ())); + eh.TryEnd = GetInstruction (body, instructions, eh.TryStart.Offset + Convert.ToInt32 (br.ReadByte ())); + eh.HandlerStart = GetInstruction (body, instructions, Convert.ToInt32 (br.ReadInt16 ())); + eh.HandlerEnd = GetInstruction (body, instructions, eh.HandlerStart.Offset + Convert.ToInt32 (br.ReadByte ())); + ReadExceptionHandlerEnd (eh, br, body, instructions); + body.ExceptionHandlers.Add (eh); + } + } else { + br.BaseStream.Position--; + int length = (br.ReadInt32 () >> 8) / 24; + if ((flags & (int) MethodDataSection.EHTable) == 0) + br.ReadBytes (length * 24); + for (int i = 0; i < length; i++) { + ExceptionHandler eh = new ExceptionHandler ( + (ExceptionHandlerType) (br.ReadInt32 () & 0x7)); + eh.TryStart = GetInstruction (body, instructions, br.ReadInt32 ()); + eh.TryEnd = GetInstruction (body, instructions, eh.TryStart.Offset + br.ReadInt32 ()); + eh.HandlerStart = GetInstruction (body, instructions, br.ReadInt32 ()); + eh.HandlerEnd = GetInstruction (body, instructions, eh.HandlerStart.Offset + br.ReadInt32 ()); + ReadExceptionHandlerEnd(eh, br, body, instructions); + body.ExceptionHandlers.Add (eh); + } + } + + if ((flags & (byte) MethodDataSection.MoreSects) != 0) + ReadSection (body, br, instructions); + } + + void ReadExceptionHandlerEnd (ExceptionHandler eh, BinaryReader br, MethodBody body, IDictionary instructions) + { + switch (eh.Type) { + case ExceptionHandlerType.Catch : + MetadataToken token = new MetadataToken (br.ReadInt32 ()); + eh.CatchType = m_reflectReader.GetTypeDefOrRef (token, new GenericContext (body.Method)); + break; + case ExceptionHandlerType.Filter : + eh.FilterStart = GetInstruction (body, instructions, br.ReadInt32 ()); + eh.FilterEnd = GetInstruction (body, instructions, eh.HandlerStart.Previous.Offset); + break; + default : + br.ReadInt32 (); + break; + } + } + + CallSite GetCallSiteAt (int token, GenericContext context) + { + StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable (); + MethodSig ms = m_reflectReader.SigReader.GetStandAloneMethodSig ( + sasTable [(int) GetRid (token) - 1].Signature); + CallSite cs = new CallSite (ms.HasThis, ms.ExplicitThis, + ms.MethCallConv, m_reflectReader.GetMethodReturnType (ms, context)); + cs.MetadataToken = new MetadataToken (token); + + for (int i = 0; i < ms.ParamCount; i++) { + Param p = ms.Parameters [i]; + cs.Parameters.Add (m_reflectReader.BuildParameterDefinition (i, p, context)); + } + + ReflectionReader.CreateSentinelIfNeeded (cs, ms); + + return cs; + } + + public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables) + { + MethodBody body = variables.Container as MethodBody; + if (body == null || body.LocalVarToken == 0) + return; + + StandAloneSigTable sasTable = m_reflectReader.TableReader.GetStandAloneSigTable (); + StandAloneSigRow sasRow = sasTable [(int) GetRid (body.LocalVarToken) - 1]; + LocalVarSig sig = m_reflectReader.SigReader.GetLocalVarSig (sasRow.Signature); + for (int i = 0; i < sig.Count; i++) { + LocalVarSig.LocalVariable lv = sig.LocalVariables [i]; + TypeReference varType = m_reflectReader.GetTypeRefFromSig ( + lv.Type, new GenericContext (body.Method)); + + if (lv.ByRef) + varType = new ReferenceType (varType); + if ((lv.Constraint & Constraint.Pinned) != 0) + varType = new PinnedType (varType); + + varType = m_reflectReader.GetModifierType (lv.CustomMods, varType); + + body.Variables.Add (new VariableDefinition ( + string.Concat ("V_", i), i, body.Method, varType)); + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs new file mode 100644 index 0000000..446b9a2 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs @@ -0,0 +1,462 @@ +// +// CodeWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using System.Collections; + + using Mono.Cecil; + using Mono.Cecil.Binary; + using Mono.Cecil.Metadata; + using Mono.Cecil.Signatures; + + class CodeWriter : BaseCodeVisitor { + + ReflectionWriter m_reflectWriter; + MemoryBinaryWriter m_binaryWriter; + MemoryBinaryWriter m_codeWriter; + + IDictionary m_localSigCache; + IDictionary m_standaloneSigCache; + + public CodeWriter (ReflectionWriter reflectWriter, MemoryBinaryWriter writer) + { + m_reflectWriter = reflectWriter; + m_binaryWriter = writer; + m_codeWriter = new MemoryBinaryWriter (); + + m_localSigCache = new Hashtable (); + m_standaloneSigCache = new Hashtable (); + } + + public RVA WriteMethodBody (MethodDefinition meth) + { + if (meth.Body == null) + return RVA.Zero; + + RVA ret = m_reflectWriter.MetadataWriter.GetDataCursor (); + meth.Body.Accept (this); + return ret; + } + + public override void VisitMethodBody (MethodBody body) + { + m_codeWriter.Empty (); + } + + void WriteToken (MetadataToken token) + { + if (token.RID == 0) + m_codeWriter.Write (0); + else + m_codeWriter.Write (token.ToUInt ()); + } + + static int GetParameterIndex (MethodBody body, ParameterDefinition p) + { + int idx = body.Method.Parameters.IndexOf (p); + if (idx == -1 && p == body.Method.This) + return 0; + if (body.Method.HasThis) + idx++; + + return idx; + } + + public override void VisitInstructionCollection (InstructionCollection instructions) + { + MethodBody body = instructions.Container; + long start = m_codeWriter.BaseStream.Position; + + ComputeMaxStack (instructions); + + foreach (Instruction instr in instructions) { + + instr.Offset = (int) (m_codeWriter.BaseStream.Position - start); + + if (instr.OpCode.Size == 1) + m_codeWriter.Write (instr.OpCode.Op2); + else { + m_codeWriter.Write (instr.OpCode.Op1); + m_codeWriter.Write (instr.OpCode.Op2); + } + + if (instr.OpCode.OperandType != OperandType.InlineNone && + instr.Operand == null) + throw new ReflectionException ("OpCode {0} have null operand", instr.OpCode.Name); + + switch (instr.OpCode.OperandType) { + case OperandType.InlineNone : + break; + case OperandType.InlineSwitch : + Instruction [] targets = (Instruction []) instr.Operand; + for (int i = 0; i < targets.Length + 1; i++) + m_codeWriter.Write ((uint) 0); + break; + case OperandType.ShortInlineBrTarget : + m_codeWriter.Write ((byte) 0); + break; + case OperandType.InlineBrTarget : + m_codeWriter.Write (0); + break; + case OperandType.ShortInlineI : + if (instr.OpCode == OpCodes.Ldc_I4_S) + m_codeWriter.Write ((sbyte) instr.Operand); + else + m_codeWriter.Write ((byte) instr.Operand); + break; + case OperandType.ShortInlineVar : + m_codeWriter.Write ((byte) body.Variables.IndexOf ( + (VariableDefinition) instr.Operand)); + break; + case OperandType.ShortInlineParam : + m_codeWriter.Write ((byte) GetParameterIndex (body, (ParameterDefinition) instr.Operand)); + break; + case OperandType.InlineSig : + WriteToken (GetCallSiteToken ((CallSite) instr.Operand)); + break; + case OperandType.InlineI : + m_codeWriter.Write ((int) instr.Operand); + break; + case OperandType.InlineVar : + m_codeWriter.Write ((short) body.Variables.IndexOf ( + (VariableDefinition) instr.Operand)); + break; + case OperandType.InlineParam : + m_codeWriter.Write ((short) GetParameterIndex ( + body, (ParameterDefinition) instr.Operand)); + break; + case OperandType.InlineI8 : + m_codeWriter.Write ((long) instr.Operand); + break; + case OperandType.ShortInlineR : + m_codeWriter.Write ((float) instr.Operand); + break; + case OperandType.InlineR : + m_codeWriter.Write ((double) instr.Operand); + break; + case OperandType.InlineString : + WriteToken (new MetadataToken (TokenType.String, + m_reflectWriter.MetadataWriter.AddUserString (instr.Operand as string))); + break; + case OperandType.InlineField : + case OperandType.InlineMethod : + case OperandType.InlineType : + case OperandType.InlineTok : + if (instr.Operand is TypeReference) + WriteToken (m_reflectWriter.GetTypeDefOrRefToken ( + instr.Operand as TypeReference)); + else if (instr.Operand is GenericInstanceMethod) + WriteToken (m_reflectWriter.GetMethodSpecToken (instr.Operand as GenericInstanceMethod)); + else if (instr.Operand is MemberReference) + WriteToken (m_reflectWriter.GetMemberRefToken ((MemberReference) instr.Operand)); + else if (instr.Operand is IMetadataTokenProvider) + WriteToken (((IMetadataTokenProvider) instr.Operand).MetadataToken); + else + throw new ReflectionException ( + string.Format ("Wrong operand for {0} OpCode: {1}", + instr.OpCode.OperandType, + instr.Operand.GetType ().FullName)); + break; + } + } + + // patch branches + long pos = m_codeWriter.BaseStream.Position; + + foreach (Instruction instr in instructions) { + switch (instr.OpCode.OperandType) { + case OperandType.InlineSwitch : + m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size; + Instruction [] targets = (Instruction []) instr.Operand; + m_codeWriter.Write ((uint) targets.Length); + foreach (Instruction tgt in targets) + m_codeWriter.Write ((tgt.Offset - (instr.Offset + + instr.OpCode.Size + (4 * (targets.Length + 1))))); + break; + case OperandType.ShortInlineBrTarget : + m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size; + m_codeWriter.Write ((byte) (((Instruction) instr.Operand).Offset - + (instr.Offset + instr.OpCode.Size + 1))); + break; + case OperandType.InlineBrTarget : + m_codeWriter.BaseStream.Position = instr.Offset + instr.OpCode.Size; + m_codeWriter.Write(((Instruction) instr.Operand).Offset - + (instr.Offset + instr.OpCode.Size + 4)); + break; + } + } + + m_codeWriter.BaseStream.Position = pos; + } + + MetadataToken GetCallSiteToken (CallSite cs) + { + uint sig; + int sentinel = cs.GetSentinel (); + if (sentinel > 0) + sig = m_reflectWriter.SignatureWriter.AddMethodDefSig ( + m_reflectWriter.GetMethodDefSig (cs)); + else + sig = m_reflectWriter.SignatureWriter.AddMethodRefSig ( + m_reflectWriter.GetMethodRefSig (cs)); + + if (m_standaloneSigCache.Contains (sig)) + return (MetadataToken) m_standaloneSigCache [sig]; + + StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable (); + StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow (sig); + + sasTable.Rows.Add(sasRow); + + MetadataToken token = new MetadataToken (TokenType.Signature, (uint) sasTable.Rows.Count); + m_standaloneSigCache [sig] = token; + return token; + } + + static int GetLength (Instruction start, Instruction end, InstructionCollection instructions) + { + Instruction last = instructions [instructions.Count - 1]; + return (end == instructions.Outside ? last.Offset + last.GetSize () : end.Offset) - start.Offset; + } + + static bool IsRangeFat (Instruction start, Instruction end, InstructionCollection instructions) + { + return GetLength (start, end, instructions) >= 256 || + start.Offset >= 65536; + } + + static bool IsFat (ExceptionHandlerCollection seh) + { + for (int i = 0; i < seh.Count; i++) { + ExceptionHandler eh = seh [i]; + if (IsRangeFat (eh.TryStart, eh.TryEnd, seh.Container.Instructions)) + return true; + + if (IsRangeFat (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions)) + return true; + + switch (eh.Type) { + case ExceptionHandlerType.Filter : + if (IsRangeFat (eh.FilterStart, eh.FilterEnd, seh.Container.Instructions)) + return true; + break; + } + } + + return false; + } + + void WriteExceptionHandlerCollection (ExceptionHandlerCollection seh) + { + m_codeWriter.QuadAlign (); + + if (seh.Count < 0x15 && !IsFat (seh)) { + m_codeWriter.Write ((byte) MethodDataSection.EHTable); + m_codeWriter.Write ((byte) (seh.Count * 12 + 4)); + m_codeWriter.Write (new byte [2]); + foreach (ExceptionHandler eh in seh) { + m_codeWriter.Write ((ushort) eh.Type); + m_codeWriter.Write ((ushort) eh.TryStart.Offset); + m_codeWriter.Write ((byte) (eh.TryEnd.Offset - eh.TryStart.Offset)); + m_codeWriter.Write ((ushort) eh.HandlerStart.Offset); + m_codeWriter.Write ((byte) GetLength (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions)); + WriteHandlerSpecific (eh); + } + } else { + m_codeWriter.Write ((byte) (MethodDataSection.FatFormat | MethodDataSection.EHTable)); + WriteFatBlockSize (seh); + foreach (ExceptionHandler eh in seh) { + m_codeWriter.Write ((uint) eh.Type); + m_codeWriter.Write ((uint) eh.TryStart.Offset); + m_codeWriter.Write ((uint) (eh.TryEnd.Offset - eh.TryStart.Offset)); + m_codeWriter.Write ((uint) eh.HandlerStart.Offset); + m_codeWriter.Write ((uint) GetLength (eh.HandlerStart, eh.HandlerEnd, seh.Container.Instructions)); + WriteHandlerSpecific (eh); + } + } + } + + void WriteFatBlockSize (ExceptionHandlerCollection seh) + { + int size = seh.Count * 24 + 4; + m_codeWriter.Write ((byte) (size & 0xff)); + m_codeWriter.Write ((byte) ((size >> 8) & 0xff)); + m_codeWriter.Write ((byte) ((size >> 16) & 0xff)); + } + + void WriteHandlerSpecific (ExceptionHandler eh) + { + switch (eh.Type) { + case ExceptionHandlerType.Catch : + WriteToken (eh.CatchType.MetadataToken); + break; + case ExceptionHandlerType.Filter : + m_codeWriter.Write ((uint) eh.FilterStart.Offset); + break; + default : + m_codeWriter.Write (0); + break; + } + } + + public override void VisitVariableDefinitionCollection (VariableDefinitionCollection variables) + { + MethodBody body = variables.Container as MethodBody; + if (body == null) + return; + + uint sig = m_reflectWriter.SignatureWriter.AddLocalVarSig ( + GetLocalVarSig (variables)); + + if (m_localSigCache.Contains (sig)) { + body.LocalVarToken = (int) m_localSigCache [sig]; + return; + } + + StandAloneSigTable sasTable = m_reflectWriter.MetadataTableWriter.GetStandAloneSigTable (); + StandAloneSigRow sasRow = m_reflectWriter.MetadataRowWriter.CreateStandAloneSigRow ( + sig); + + sasTable.Rows.Add (sasRow); + body.LocalVarToken = sasTable.Rows.Count; + m_localSigCache [sig] = body.LocalVarToken; + } + + public override void TerminateMethodBody (MethodBody body) + { + long pos = m_binaryWriter.BaseStream.Position; + + if (body.Variables.Count > 0 || body.ExceptionHandlers.Count > 0 + || m_codeWriter.BaseStream.Length >= 64 || body.MaxStack > 8) { + + MethodHeader header = MethodHeader.FatFormat; + if (body.InitLocals) + header |= MethodHeader.InitLocals; + if (body.ExceptionHandlers.Count > 0) + header |= MethodHeader.MoreSects; + + m_binaryWriter.Write ((byte) header); + m_binaryWriter.Write ((byte) 0x30); // (header size / 4) << 4 + m_binaryWriter.Write ((short) body.MaxStack); + m_binaryWriter.Write ((int) m_codeWriter.BaseStream.Length); + m_binaryWriter.Write (((int) TokenType.Signature | body.LocalVarToken)); + + WriteExceptionHandlerCollection (body.ExceptionHandlers); + } else + m_binaryWriter.Write ((byte) ((byte) MethodHeader.TinyFormat | + m_codeWriter.BaseStream.Length << 2)); + + m_binaryWriter.Write (m_codeWriter); + m_binaryWriter.QuadAlign (); + + m_reflectWriter.MetadataWriter.AddData ( + (int) (m_binaryWriter.BaseStream.Position - pos)); + } + + public LocalVarSig.LocalVariable GetLocalVariableSig (VariableDefinition var) + { + LocalVarSig.LocalVariable lv = new LocalVarSig.LocalVariable (); + TypeReference type = var.VariableType; + + lv.CustomMods = m_reflectWriter.GetCustomMods (type); + + if (type is PinnedType) { + lv.Constraint |= Constraint.Pinned; + type = (type as PinnedType).ElementType; + } + + if (type is ReferenceType) { + lv.ByRef = true; + type = (type as ReferenceType).ElementType; + } + + lv.Type = m_reflectWriter.GetSigType (type); + + return lv; + } + + public LocalVarSig GetLocalVarSig (VariableDefinitionCollection vars) + { + LocalVarSig lvs = new LocalVarSig (); + lvs.CallingConvention |= 0x7; + lvs.Count = vars.Count; + lvs.LocalVariables = new LocalVarSig.LocalVariable [lvs.Count]; + for (int i = 0; i < lvs.Count; i++) { + lvs.LocalVariables [i] = GetLocalVariableSig (vars [i]); + } + + return lvs; + } + + static void ComputeMaxStack (InstructionCollection instructions) + { + InstructionCollection ehs = new InstructionCollection (null); + foreach (ExceptionHandler eh in instructions.Container.ExceptionHandlers) { + switch (eh.Type) { + case ExceptionHandlerType.Catch : + ehs.Add (eh.HandlerStart); + break; + case ExceptionHandlerType.Filter : + ehs.Add (eh.FilterStart); + break; + } + } + + int max = 0; + foreach (Instruction instr in instructions) { + if (ehs.Contains (instr)) + max++; + + switch (instr.OpCode.StackBehaviourPush) { + case StackBehaviour.Push1: + case StackBehaviour.Pushi: + case StackBehaviour.Pushi8: + case StackBehaviour.Pushr4: + case StackBehaviour.Pushr8: + case StackBehaviour.Pushref: + case StackBehaviour.Varpush: + max++; + break; + case StackBehaviour.Push1_push1: + max += 2; + break; + } + + if (instr.OpCode.OperandType == OperandType.InlineMethod) { + IMethodSignature signature = instr.Operand as IMethodSignature; + if (signature != null && signature.ReturnType.ReturnType.FullName != Constants.Void) + max++; + } + } + + instructions.Container.MaxStack = max; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Document.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Document.cs new file mode 100644 index 0000000..1b40c44 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Document.cs @@ -0,0 +1,80 @@ +// +// Document.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + + public class Document { + + string m_url; + + Guid m_type; + DocumentHashAlgorithm m_hashAlgorithm; + Guid m_language; + Guid m_languageVendor; + + byte [] m_hash; + + public string Url { + get { return m_url; } + set { m_url = value; } + } + + public Guid Type { + get { return m_type; } + set { m_type = value; } + } + + public DocumentHashAlgorithm HashAlgorithm { + get { return m_hashAlgorithm; } + set { m_hashAlgorithm = value; } + } + + public Guid Language { + get { return m_language; } + set { m_language = value; } + } + + public Guid LanguageVendor { + get { return m_languageVendor; } + set { m_languageVendor = value; } + } + + public byte [] Hash { + get { return m_hash; } + set { m_hash = value; } + } + + public Document (string url) + { + m_url = url; + m_hash = new byte [0]; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentHashAlgorithm.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentHashAlgorithm.cs new file mode 100644 index 0000000..cd5791f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentHashAlgorithm.cs @@ -0,0 +1,36 @@ +// +// DocumentHashAlgorithm.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public enum DocumentHashAlgorithm { + [Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)] None, + [Guid (0x406ea660, 0x64cf, 0x4c82, 0xb6, 0xf0, 0x42, 0xd4, 0x81, 0x72, 0xa7, 0x99)] MD5, + [Guid (0xff1816ec, 0xaa5e, 0x4d10, 0x87, 0xf7, 0x6f, 0x49, 0x63, 0x83, 0x34, 0x60)] SHA1 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguage.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguage.cs new file mode 100644 index 0000000..2839948 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguage.cs @@ -0,0 +1,47 @@ +// +// DocumentLanguage.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + + public abstract class DocumentLanguage { + public static readonly Guid None = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00); + public static readonly Guid C = new Guid (0x63a08714, 0xfc37, 0x11d2, 0x90, 0x4c, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1); + public static readonly Guid Cpp = new Guid (0x3a12d0b7, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2); + public static readonly Guid CSharp = new Guid (0x3f5162f8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1); + public static readonly Guid Basic = new Guid (0x3a12d0b8, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2); + public static readonly Guid Java = new Guid (0x3a12d0b4, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2); + public static readonly Guid Cobol = new Guid (0xaf046cd1, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc); + public static readonly Guid Pascal = new Guid (0xaf046cd2, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc); + public static readonly Guid CIL = new Guid (0xaf046cd3, 0xd0e1, 0x11d2, 0x97, 0x7c, 0x0, 0xa0, 0xc9, 0xb4, 0xd5, 0xc); + public static readonly Guid JScript = new Guid (0x3a12d0b6, 0xc26c, 0x11d0, 0xb4, 0x42, 0x0, 0xa0, 0x24, 0x4a, 0x1d, 0xd2); + public static readonly Guid SMC = new Guid (0xd9b9f7b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x0, 0x0, 0xf8, 0x8, 0x49, 0xbd); + public static readonly Guid MCpp = new Guid (0x4b35fde8, 0x07c6, 0x11d3, 0x90, 0x53, 0x0, 0xc0, 0x4f, 0xa3, 0x02, 0xa1); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguageVendor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguageVendor.cs new file mode 100644 index 0000000..e36edef --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentLanguageVendor.cs @@ -0,0 +1,37 @@ +// +// DocumentLanguageVendor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + + public abstract class DocumentLanguageVendor { + public static readonly Guid Other = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + public static readonly Guid Microsoft = new Guid (0x994b45c4, 0xe6e9, 0x11d2, 0x90, 0x3f, 0x00, 0xc0, 0x4f, 0xa3, 0x02, 0xa1); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs new file mode 100644 index 0000000..9df7764 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/DocumentType.cs @@ -0,0 +1,38 @@ +// +// DocumentType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + + public abstract class DocumentType { + + public static readonly Guid Other = new Guid (0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + public static readonly Guid Text = new Guid (0x5a869d0b, 0x6611, 0x11d3, 0xbd, 0x2a, 0x00, 0x00, 0xf8, 0x08, 0x49, 0xbd); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs new file mode 100644 index 0000000..d1ee7bf --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandler.cs @@ -0,0 +1,95 @@ +// +// ExceptionHandler.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using Mono.Cecil; + + public sealed class ExceptionHandler : ICodeVisitable { + + Instruction m_tryStart; + Instruction m_tryEnd; + Instruction m_filterStart; + Instruction m_filterEnd; + Instruction m_handlerStart; + Instruction m_handlerEnd; + + TypeReference m_catchType; + ExceptionHandlerType m_type; + + public Instruction TryStart { + get { return m_tryStart; } + set { m_tryStart = value; } + } + + public Instruction TryEnd { + get { return m_tryEnd; } + set { m_tryEnd = value; } + } + + public Instruction FilterStart { + get { return m_filterStart; } + set { m_filterStart = value; } + } + + public Instruction FilterEnd { + get { return m_filterEnd; } + set { m_filterEnd = value; } + } + + public Instruction HandlerStart { + get { return m_handlerStart; } + set { m_handlerStart = value; } + } + + public Instruction HandlerEnd { + get { return m_handlerEnd; } + set { m_handlerEnd = value; } + } + + public TypeReference CatchType { + get { return m_catchType; } + set { m_catchType = value; } + } + + public ExceptionHandlerType Type { + get { return m_type; } + set { m_type = value; } + } + + public ExceptionHandler (ExceptionHandlerType type) + { + m_type = type; + } + + public void Accept (ICodeVisitor visitor) + { + visitor.VisitExceptionHandler (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerCollection.cs new file mode 100644 index 0000000..dd2b11a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerCollection.cs @@ -0,0 +1,93 @@ +// +// ExceptionHandlerCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:53 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ExceptionHandlerCollection : CollectionBase, ICodeVisitable { + + MethodBody m_container; + + public ExceptionHandler this [int index] { + get { return List [index] as ExceptionHandler; } + set { List [index] = value; } + } + + public MethodBody Container { + get { return m_container; } + } + + public ExceptionHandlerCollection (MethodBody container) + { + m_container = container; + } + + public void Add (ExceptionHandler value) + { + List.Add (value); + } + + public bool Contains (ExceptionHandler value) + { + return List.Contains (value); + } + + public int IndexOf (ExceptionHandler value) + { + return List.IndexOf (value); + } + + public void Insert (int index, ExceptionHandler value) + { + List.Insert (index, value); + } + + public void Remove (ExceptionHandler value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is ExceptionHandler)) + throw new ArgumentException ("Must be of type " + typeof (ExceptionHandler).FullName); + } + + public void Accept (ICodeVisitor visitor) + { + visitor.VisitExceptionHandlerCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerType.cs new file mode 100644 index 0000000..28b8b7c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ExceptionHandlerType.cs @@ -0,0 +1,37 @@ +// +// ExceptionHandlerType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public enum ExceptionHandlerType { + Catch = 0x0000, + Filter = 0x0001, + Finally = 0x0002, + Fault = 0x0004 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/FlowControl.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/FlowControl.cs new file mode 100644 index 0000000..e08104d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/FlowControl.cs @@ -0,0 +1,42 @@ +// +// FlowControl.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public enum FlowControl { + Branch, + Break, + Call, + Cond_Branch, + Meta, + Next, + Phi, + Return, + Throw + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/GuidAttribute.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/GuidAttribute.cs new file mode 100644 index 0000000..d071f8f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/GuidAttribute.cs @@ -0,0 +1,91 @@ +// +// GuidAttribute.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using System.Reflection; + + [AttributeUsage (AttributeTargets.Field)] + public class GuidAttribute : Attribute { + + private Guid m_guid; + + public Guid Guid { + get { return m_guid; } + } + + GuidAttribute () + { + m_guid = new Guid (); + } + + public GuidAttribute ( + uint a, + ushort b, + ushort c, + byte d, + byte e, + byte f, + byte g, + byte h, + byte i, + byte j, + byte k) + { + m_guid = new Guid ((int) a, (short) b, (short) c, d, e, f, g, h, i, j, k); + } + + public static int GetValueFromGuid (Guid id, Type enumeration) + { + foreach (FieldInfo fi in enumeration.GetFields (BindingFlags.Static | BindingFlags.Public)) + if (id == GetGuidAttribute (fi).Guid) + return (int) fi.GetValue (null); + + return -1; + } + + public static Guid GetGuidFromValue (int value, Type enumeration) + { + foreach (FieldInfo fi in enumeration.GetFields (BindingFlags.Static | BindingFlags.Public)) + if (value == (int) fi.GetValue (null)) + return GetGuidAttribute (fi).Guid; + + return new Guid (); + } + + static GuidAttribute GetGuidAttribute (FieldInfo fi) + { + GuidAttribute [] attributes = fi.GetCustomAttributes (typeof (GuidAttribute), false) as GuidAttribute []; + if (attributes == null || attributes.Length != 1) + return new GuidAttribute (); + + return attributes [0]; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitable.cs new file mode 100644 index 0000000..91571d8 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitable.cs @@ -0,0 +1,34 @@ +// +// ICodeVisitable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public interface ICodeVisitable { + void Accept (ICodeVisitor visitor); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitor.cs new file mode 100644 index 0000000..c02335e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ICodeVisitor.cs @@ -0,0 +1,45 @@ +// +// ICodeVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public interface ICodeVisitor { + + void VisitMethodBody (MethodBody body); + void VisitInstructionCollection (InstructionCollection instructions); + void VisitInstruction (Instruction instr); + void VisitExceptionHandlerCollection (ExceptionHandlerCollection seh); + void VisitExceptionHandler (ExceptionHandler eh); + void VisitVariableDefinitionCollection (VariableDefinitionCollection variables); + void VisitVariableDefinition (VariableDefinition var); + void VisitScopeCollection (ScopeCollection scopes); + void VisitScope (Scope scope); + + void TerminateMethodBody (MethodBody body); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/IScopeProvider.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/IScopeProvider.cs new file mode 100644 index 0000000..f7db241 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/IScopeProvider.cs @@ -0,0 +1,35 @@ +// +// Document.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public interface IScopeProvider { + + ScopeCollection Scopes { get; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolReader.cs new file mode 100644 index 0000000..817788c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolReader.cs @@ -0,0 +1,37 @@ +// +// ISymbolReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + + public interface ISymbolReader : IDisposable { + + void Read (MethodBody body); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolStoreFactory.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolStoreFactory.cs new file mode 100644 index 0000000..945c7a0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolStoreFactory.cs @@ -0,0 +1,36 @@ +// +// ISymbolStoreFactory.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public interface ISymbolStoreFactory { + + ISymbolReader CreateReader (ModuleDefinition module, string assemblyFileName); + ISymbolWriter CreateWriter (ModuleDefinition module, string assemblyFileName); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolWriter.cs new file mode 100644 index 0000000..83fab55 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ISymbolWriter.cs @@ -0,0 +1,37 @@ +// +// ISymbolWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + + public interface ISymbolWriter : IDisposable { + + void Write (MethodBody body, byte [][] variables); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/IVariableDefinitionProvider.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/IVariableDefinitionProvider.cs new file mode 100644 index 0000000..9f64797 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/IVariableDefinitionProvider.cs @@ -0,0 +1,35 @@ +// +// IVariableDefinitionProvider.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public interface IVariableDefinitionProvider { + + VariableDefinitionCollection Variables { get; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Instruction.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Instruction.cs new file mode 100644 index 0000000..7e9a5de --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Instruction.cs @@ -0,0 +1,133 @@ +// +// Instruction.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public sealed class Instruction : ICodeVisitable { + + int m_offset; + OpCode m_opCode; + object m_operand; + + Instruction m_previous; + Instruction m_next; + + SequencePoint m_sequencePoint; + + public int Offset { + get { return m_offset; } + set { m_offset = value; } + } + + public OpCode OpCode { + get { return m_opCode; } + set { m_opCode = value; } + } + + public object Operand { + get { return m_operand; } + set { m_operand = value; } + } + + public Instruction Previous { + get { return m_previous; } + set { m_previous = value; } + } + + public Instruction Next { + get { return m_next; } + set { m_next = value; } + } + + public SequencePoint SequencePoint { + get { return m_sequencePoint; } + set { m_sequencePoint = value; } + } + + internal Instruction (int offset, OpCode opCode, object operand) : this (offset, opCode) + { + m_operand = operand; + } + + internal Instruction (int offset, OpCode opCode) + { + m_offset = offset; + m_opCode = opCode; + } + + internal Instruction (OpCode opCode, object operand) : this (0, opCode, operand) + { + } + + internal Instruction (OpCode opCode) : this (0, opCode) + { + } + + public int GetSize () + { + int size = m_opCode.Size; + + switch (m_opCode.OperandType) { + case OperandType.InlineSwitch: + size += (1 + ((Instruction []) m_operand).Length) * 4; + break; + case OperandType.InlineI8: + case OperandType.InlineR: + size += 8; + break; + case OperandType.InlineBrTarget: + case OperandType.InlineField: + case OperandType.InlineI: + case OperandType.InlineMethod: + case OperandType.InlineString: + case OperandType.InlineTok: + case OperandType.InlineType: + case OperandType.ShortInlineR: + size += 4; + break; + case OperandType.InlineParam: + case OperandType.InlineVar: + size += 2; + break; + case OperandType.ShortInlineBrTarget: + case OperandType.ShortInlineI: + case OperandType.ShortInlineParam: + case OperandType.ShortInlineVar: + size += 1; + break; + } + + return size; + } + + public void Accept (ICodeVisitor visitor) + { + visitor.VisitInstruction (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/InstructionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/InstructionCollection.cs new file mode 100644 index 0000000..190750b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/InstructionCollection.cs @@ -0,0 +1,94 @@ +// +// InstructionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Sep 28 17:54:43 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class InstructionCollection : CollectionBase, ICodeVisitable { + + MethodBody m_container; + public readonly Instruction Outside = new Instruction (int.MaxValue, OpCodes.Nop); + + public Instruction this [int index] { + get { return List [index] as Instruction; } + set { List [index] = value; } + } + + public MethodBody Container { + get { return m_container; } + } + + public InstructionCollection (MethodBody container) + { + m_container = container; + } + + internal void Add (Instruction value) + { + List.Add (value); + } + + public bool Contains (Instruction value) + { + return List.Contains (value); + } + + public int IndexOf (Instruction value) + { + return List.IndexOf (value); + } + + internal void Insert (int index, Instruction value) + { + List.Insert (index, value); + } + + internal void Remove (Instruction value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is Instruction)) + throw new ArgumentException ("Must be of type " + typeof (Instruction).FullName); + } + + public void Accept (ICodeVisitor visitor) + { + visitor.VisitInstructionCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs new file mode 100644 index 0000000..a20617a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodBody.cs @@ -0,0 +1,582 @@ +// +// MethodBody.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using Mono.Cecil; + + public sealed class MethodBody : IVariableDefinitionProvider, IScopeProvider, ICodeVisitable { + + MethodDefinition m_method; + int m_maxStack; + int m_codeSize; + bool m_initLocals; + int m_localVarToken; + + InstructionCollection m_instructions; + ExceptionHandlerCollection m_exceptions; + VariableDefinitionCollection m_variables; + ScopeCollection m_scopes; + + private CilWorker m_cilWorker; + + public MethodDefinition Method { + get { return m_method; } + } + + public int MaxStack { + get { return m_maxStack; } + set { m_maxStack = value; } + } + + public int CodeSize { + get { return m_codeSize; } + set { m_codeSize = value; } + } + + public bool InitLocals { + get { return m_initLocals; } + set { m_initLocals = value; } + } + + internal int LocalVarToken { + get { return m_localVarToken; } + set { m_localVarToken = value; } + } + + public CilWorker CilWorker { + get { + if (m_cilWorker == null) + m_cilWorker = new CilWorker (this); + return m_cilWorker; + } + set { m_cilWorker = value; } + } + + public InstructionCollection Instructions { + get { return m_instructions; } + } + + public ExceptionHandlerCollection ExceptionHandlers { + get { return m_exceptions; } + } + + public VariableDefinitionCollection Variables { + get { return m_variables; } + } + + public ScopeCollection Scopes { + get { return m_scopes; } + } + + public MethodBody (MethodDefinition meth) + { + m_method = meth; + m_instructions = new InstructionCollection (this); + m_exceptions = new ExceptionHandlerCollection (this); + m_variables = new VariableDefinitionCollection (this); + m_scopes = new ScopeCollection (this); + } + + internal static Instruction GetInstruction (MethodBody oldBody, MethodBody newBody, Instruction i) + { + int pos = oldBody.Instructions.IndexOf (i); + if (pos > -1 && pos < newBody.Instructions.Count) + return newBody.Instructions [pos]; + + return newBody.Instructions.Outside; + } + + internal static MethodBody Clone (MethodBody body, MethodDefinition parent, ImportContext context) + { + MethodBody nb = new MethodBody (parent); + nb.MaxStack = body.MaxStack; + nb.InitLocals = body.InitLocals; + nb.CodeSize = body.CodeSize; + + foreach (VariableDefinition var in body.Variables) + nb.Variables.Add (new VariableDefinition ( + context.Import (var.VariableType))); + + foreach (Instruction instr in body.Instructions) { + Instruction ni = new Instruction (instr.OpCode); + + switch (instr.OpCode.OperandType) { + case OperandType.InlineParam : + case OperandType.ShortInlineParam : + if (instr.Operand == body.Method.This) + ni.Operand = nb.Method.This; + else { + int param = body.Method.Parameters.IndexOf ((ParameterDefinition) instr.Operand); + ni.Operand = parent.Parameters [param]; + } + break; + case OperandType.InlineVar : + case OperandType.ShortInlineVar : + int var = body.Variables.IndexOf ((VariableDefinition) instr.Operand); + ni.Operand = nb.Variables [var]; + break; + case OperandType.InlineField : + ni.Operand = context.Import ((FieldReference) instr.Operand); + break; + case OperandType.InlineMethod : + ni.Operand = context.Import ((MethodReference) instr.Operand); + break; + case OperandType.InlineType : + ni.Operand = context.Import ((TypeReference) instr.Operand); + break; + case OperandType.InlineTok : + if (instr.Operand is TypeReference) + ni.Operand = context.Import ((TypeReference) instr.Operand); + else if (instr.Operand is FieldReference) + ni.Operand = context.Import ((FieldReference) instr.Operand); + else if (instr.Operand is MethodReference) + ni.Operand = context.Import ((MethodReference) instr.Operand); + break; + case OperandType.ShortInlineBrTarget : + case OperandType.InlineBrTarget : + break; + default : + ni.Operand = instr.Operand; + break; + } + + nb.Instructions.Add (ni); + } + + for (int i = 0; i < body.Instructions.Count; i++) { + Instruction instr = nb.Instructions [i]; + if (instr.OpCode.OperandType != OperandType.ShortInlineBrTarget && + instr.OpCode.OperandType != OperandType.InlineBrTarget) + continue; + + instr.Operand = GetInstruction (body, nb, (Instruction) body.Instructions [i].Operand); + } + + foreach (ExceptionHandler eh in body.ExceptionHandlers) { + ExceptionHandler neh = new ExceptionHandler (eh.Type); + neh.TryStart = GetInstruction (body, nb, eh.TryStart); + neh.TryEnd = GetInstruction (body, nb, eh.TryEnd); + neh.HandlerStart = GetInstruction (body, nb, eh.HandlerStart); + neh.HandlerEnd = GetInstruction (body, nb, eh.HandlerEnd); + + switch (eh.Type) { + case ExceptionHandlerType.Catch : + neh.CatchType = context.Import (eh.CatchType); + break; + case ExceptionHandlerType.Filter : + neh.FilterStart = GetInstruction (body, nb, eh.FilterStart); + neh.FilterEnd = GetInstruction (body, nb, eh.FilterEnd); + break; + } + + nb.ExceptionHandlers.Add (neh); + } + + return nb; + } + + public void Modify () + { + foreach (Instruction i in this.Instructions) { + if (i.OpCode.OpCodeType != OpCodeType.Macro) + continue; + + switch (i.OpCode.Code) { + case Code.Ldarg_0 : + Modify (i, OpCodes.Ldarg, + CodeReader.GetParameter (this, 0)); + break; + case Code.Ldarg_1 : + Modify (i, OpCodes.Ldarg, + CodeReader.GetParameter (this, 1)); + break; + case Code.Ldarg_2 : + Modify (i, OpCodes.Ldarg, + CodeReader.GetParameter (this, 2)); + break; + case Code.Ldarg_3 : + Modify (i, OpCodes.Ldarg, + CodeReader.GetParameter (this, 3)); + break; + case Code.Ldloc_0 : + Modify (i, OpCodes.Ldloc, + CodeReader.GetVariable (this, 0)); + break; + case Code.Ldloc_1 : + Modify (i, OpCodes.Ldloc, + CodeReader.GetVariable (this, 1)); + break; + case Code.Ldloc_2 : + Modify (i, OpCodes.Ldloc, + CodeReader.GetVariable (this, 2)); + break; + case Code.Ldloc_3 : + Modify (i, OpCodes.Ldloc, + CodeReader.GetVariable (this, 3)); + break; + case Code.Stloc_0 : + Modify (i, OpCodes.Stloc, + CodeReader.GetVariable (this, 0)); + break; + case Code.Stloc_1 : + Modify (i, OpCodes.Stloc, + CodeReader.GetVariable (this, 1)); + break; + case Code.Stloc_2 : + Modify (i, OpCodes.Stloc, + CodeReader.GetVariable (this, 2)); + break; + case Code.Stloc_3 : + Modify (i, OpCodes.Stloc, + CodeReader.GetVariable (this, 3)); + break; + case Code.Ldarg_S : + i.OpCode = OpCodes.Ldarg; + break; + case Code.Ldarga_S : + i.OpCode = OpCodes.Ldarga; + break; + case Code.Starg_S : + i.OpCode = OpCodes.Starg; + break; + case Code.Ldloc_S : + i.OpCode = OpCodes.Ldloc; + break; + case Code.Ldloca_S : + i.OpCode = OpCodes.Ldloca; + break; + case Code.Stloc_S : + i.OpCode = OpCodes.Stloc; + break; + case Code.Ldc_I4_M1 : + Modify (i, OpCodes.Ldc_I4, -1); + break; + case Code.Ldc_I4_0 : + Modify (i, OpCodes.Ldc_I4, 0); + break; + case Code.Ldc_I4_1 : + Modify (i, OpCodes.Ldc_I4, 1); + break; + case Code.Ldc_I4_2 : + Modify (i, OpCodes.Ldc_I4, 2); + break; + case Code.Ldc_I4_3 : + Modify (i, OpCodes.Ldc_I4, 3); + break; + case Code.Ldc_I4_4 : + Modify (i, OpCodes.Ldc_I4, 4); + break; + case Code.Ldc_I4_5 : + Modify (i, OpCodes.Ldc_I4, 5); + break; + case Code.Ldc_I4_6 : + Modify (i, OpCodes.Ldc_I4, 6); + break; + case Code.Ldc_I4_7 : + Modify (i, OpCodes.Ldc_I4, 7); + break; + case Code.Ldc_I4_8 : + Modify (i, OpCodes.Ldc_I4, 8); + break; + case Code.Ldc_I4_S : + i.OpCode = OpCodes.Ldc_I4; + i.Operand = (int) (sbyte) i.Operand; + break; + case Code.Br_S : + i.OpCode = OpCodes.Br; + break; + case Code.Brfalse_S : + i.OpCode = OpCodes.Brfalse; + break; + case Code.Brtrue_S : + i.OpCode = OpCodes.Brtrue; + break; + case Code.Beq_S : + i.OpCode = OpCodes.Beq; + break; + case Code.Bge_S : + i.OpCode = OpCodes.Bge; + break; + case Code.Bgt_S : + i.OpCode = OpCodes.Bgt; + break; + case Code.Ble_S : + i.OpCode = OpCodes.Ble; + break; + case Code.Blt_S : + i.OpCode = OpCodes.Blt; + break; + case Code.Bne_Un_S : + i.OpCode = OpCodes.Bne_Un; + break; + case Code.Bge_Un_S : + i.OpCode = OpCodes.Bge_Un; + break; + case Code.Bgt_Un_S : + i.OpCode = OpCodes.Bgt_Un; + break; + case Code.Ble_Un_S : + i.OpCode = OpCodes.Ble_Un; + break; + case Code.Blt_Un_S : + i.OpCode = OpCodes.Blt_Un; + break; + case Code.Leave_S : + i.OpCode = OpCodes.Leave; + break; + } + } + } + + public void Optimize () + { + foreach (Instruction instr in m_instructions) { + int index; + switch (instr.OpCode.Code) { + case Code.Ldarg: + index = m_method.Parameters.IndexOf ((ParameterDefinition) instr.Operand); + if (index == -1 && instr.Operand == m_method.This) + index = 0; + else if (m_method.HasThis) + index++; + + switch (index) { + case 0: + Modify (instr, OpCodes.Ldarg_0, null); + break; + case 1: + Modify (instr, OpCodes.Ldarg_1, null); + break; + case 2: + Modify (instr, OpCodes.Ldarg_2, null); + break; + case 3: + Modify (instr, OpCodes.Ldarg_3, null); + break; + default: + if (index < 256) + Modify (instr, OpCodes.Ldarg_S, instr.Operand); + break; + } + break; + case Code.Ldloc: + index = m_variables.IndexOf ((VariableDefinition) instr.Operand); + switch (index) { + case 0: + Modify (instr, OpCodes.Ldloc_0, null); + break; + case 1: + Modify (instr, OpCodes.Ldloc_1, null); + break; + case 2: + Modify (instr, OpCodes.Ldloc_2, null); + break; + case 3: + Modify (instr, OpCodes.Ldloc_3, null); + break; + default: + if (index < 256) + Modify (instr, OpCodes.Ldloc_S, instr.Operand); + break; + } + break; + case Code.Stloc: + index = m_variables.IndexOf ((VariableDefinition) instr.Operand); + switch (index) { + case 0: + Modify (instr, OpCodes.Stloc_0, null); + break; + case 1: + Modify (instr, OpCodes.Stloc_1, null); + break; + case 2: + Modify (instr, OpCodes.Stloc_2, null); + break; + case 3: + Modify (instr, OpCodes.Stloc_3, null); + break; + default: + if (index < 256) + Modify (instr, OpCodes.Stloc_S, instr.Operand); + break; + } + break; + case Code.Ldarga: + index = m_method.Parameters.IndexOf ((ParameterDefinition) instr.Operand); + if (index == -1 && instr.Operand == m_method.This) + index = 0; + else if (m_method.HasThis) + index++; + if (index < 256) + Modify (instr, OpCodes.Ldarga_S, instr.Operand); + break; + case Code.Ldloca: + if (m_variables.IndexOf ((VariableDefinition) instr.Operand) < 256) + Modify (instr, OpCodes.Ldloca_S, instr.Operand); + break; + case Code.Ldc_I4: + int i = (int) instr.Operand; + switch (i) { + case -1: + Modify (instr, OpCodes.Ldc_I4_M1, null); + break; + case 0: + Modify (instr, OpCodes.Ldc_I4_0, null); + break; + case 1: + Modify (instr, OpCodes.Ldc_I4_1, null); + break; + case 2: + Modify (instr, OpCodes.Ldc_I4_2, null); + break; + case 3: + Modify (instr, OpCodes.Ldc_I4_3, null); + break; + case 4: + Modify (instr, OpCodes.Ldc_I4_4, null); + break; + case 5: + Modify (instr, OpCodes.Ldc_I4_5, null); + break; + case 6: + Modify (instr, OpCodes.Ldc_I4_6, null); + break; + case 7: + Modify (instr, OpCodes.Ldc_I4_7, null); + break; + case 8: + Modify (instr, OpCodes.Ldc_I4_8, null); + break; + default: + if (i >= -128 || i < 128) + Modify (instr, OpCodes.Ldc_I4_S, (sbyte) i); + break; + } + break; + } + } + + OptimizeBranches (); + } + + void OptimizeBranches () + { + ComputeOffsets (); + + foreach (Instruction instr in m_instructions) { + if (instr.OpCode.OperandType != OperandType.InlineBrTarget) + continue; + + if (OptimizeBranch (instr)) + ComputeOffsets (); + } + } + + static bool OptimizeBranch (Instruction instr) + { + int offset = ((Instruction) instr.Operand).Offset - (instr.Offset + instr.OpCode.Size + 4); + if (! (offset >= -128 && offset <= 127)) + return false; + + switch (instr.OpCode.Code) { + case Code.Br: + instr.OpCode = OpCodes.Br_S; + break; + case Code.Brfalse: + instr.OpCode = OpCodes.Brfalse_S; + break; + case Code.Brtrue: + instr.OpCode = OpCodes.Brtrue_S; + break; + case Code.Beq: + instr.OpCode = OpCodes.Beq_S; + break; + case Code.Bge: + instr.OpCode = OpCodes.Bge_S; + break; + case Code.Bgt: + instr.OpCode = OpCodes.Bgt_S; + break; + case Code.Ble: + instr.OpCode = OpCodes.Ble_S; + break; + case Code.Blt: + instr.OpCode = OpCodes.Blt_S; + break; + case Code.Bne_Un: + instr.OpCode = OpCodes.Bne_Un_S; + break; + case Code.Bge_Un: + instr.OpCode = OpCodes.Bge_Un_S; + break; + case Code.Bgt_Un: + instr.OpCode = OpCodes.Bgt_Un_S; + break; + case Code.Ble_Un: + instr.OpCode = OpCodes.Ble_Un_S; + break; + case Code.Blt_Un: + instr.OpCode = OpCodes.Blt_Un_S; + break; + case Code.Leave: + instr.OpCode = OpCodes.Leave_S; + break; + } + + return true; + } + + void ComputeOffsets () + { + int offset = 0; + + foreach (Instruction instr in m_instructions) { + instr.Offset = offset; + offset += instr.GetSize (); + } + } + + static void Modify (Instruction i, OpCode op, object operand) + { + i.OpCode = op; + i.Operand = operand; + } + + public void Accept (ICodeVisitor visitor) + { + visitor.VisitMethodBody (this); + m_variables.Accept (visitor); + m_instructions.Accept (visitor); + m_exceptions.Accept (visitor); + m_scopes.Accept (visitor); + + visitor.TerminateMethodBody (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodDataSection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodDataSection.cs new file mode 100644 index 0000000..295ccdb --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodDataSection.cs @@ -0,0 +1,37 @@ +// +// MethodDataSection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + internal enum MethodDataSection : ushort { + EHTable = 0x1, + OptILTable = 0x2, + FatFormat = 0x40, + MoreSects = 0x80 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodHeader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodHeader.cs new file mode 100644 index 0000000..c90ce2f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/MethodHeader.cs @@ -0,0 +1,37 @@ +// +// MethodHeader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + internal enum MethodHeader : ushort { + TinyFormat = 0x2, + FatFormat = 0x3, + MoreSects = 0x8, + InitLocals = 0x10 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs new file mode 100644 index 0000000..c6d0417 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCode.cs @@ -0,0 +1,139 @@ +// +// OpCode.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public struct OpCode { + + string m_name; + byte m_op1; + byte m_op2; + int m_size; + + Code m_code; + FlowControl m_flowControl; + OpCodeType m_opCodeType; + OperandType m_operandType; + StackBehaviour m_stackBehaviourPop; + StackBehaviour m_stackBehaviourPush; + + public string Name { + get { return m_name; } + } + + public int Size { + get { return m_size; } + } + + public byte Op1 { + get { return m_op1; } + } + + public byte Op2 { + get { return m_op2; } + } + + public short Value { + get { return m_size == 1 ? m_op2 : (short) ((m_op1 << 8) | m_op2); } + } + + public Code Code { + get { return m_code; } + } + + public FlowControl FlowControl { + get { return m_flowControl; } + } + + public OpCodeType OpCodeType { + get { return m_opCodeType; } + } + + public OperandType OperandType { + get { return m_operandType; } + } + + public StackBehaviour StackBehaviourPop { + get { return m_stackBehaviourPop; } + } + + public StackBehaviour StackBehaviourPush { + get { return m_stackBehaviourPush; } + } + + internal OpCode (string name, byte op1, byte op2, int size, + Code code, FlowControl flowControl, + OpCodeType opCodeType, OperandType operandType, + StackBehaviour pop, StackBehaviour push) + { + m_name = name; + m_op1 = op1; + m_op2 = op2; + m_size = size; + m_code = code; + m_flowControl = flowControl; + m_opCodeType = opCodeType; + m_operandType = operandType; + m_stackBehaviourPop = pop; + m_stackBehaviourPush = push; + + if (op1 == 0xff) + OpCodes.OneByteOpCode [op2] = this; + else + OpCodes.TwoBytesOpCode [op2] = this; + } + + public override int GetHashCode () + { + return this.Value; + } + + public override bool Equals (object obj) + { + if (!(obj is OpCode)) + return false; + OpCode v = (OpCode) obj; + return v.m_op1 == m_op1 && v.m_op2 == m_op2; + } + + public static bool operator == (OpCode one, OpCode other) + { + return one.Equals (other); + } + + public static bool operator != (OpCode one, OpCode other) + { + return !one.Equals (other); + } + + public override string ToString () + { + return m_name; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCodeType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCodeType.cs new file mode 100644 index 0000000..c6106d9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCodeType.cs @@ -0,0 +1,39 @@ +// +// OpCodeType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public enum OpCodeType { + Annotation, + Macro, + Nternal, + Objmodel, + Prefix, + Primitive + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs new file mode 100644 index 0000000..fa3b0b2 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OpCodes.cs @@ -0,0 +1,1583 @@ +// +// OpCodes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Sat Aug 18 08:11:28 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public sealed class OpCodes { + + internal static readonly OpCode [] OneByteOpCode = new OpCode [0xe0 + 1]; + internal static readonly OpCode [] TwoBytesOpCode = new OpCode [0x1e + 1]; + + public static readonly OpCode Nop = new OpCode ( + "nop", 0xff, 0x00, 1, + Code.Nop, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Break = new OpCode ( + "break", 0xff, 0x01, 1, + Code.Break, FlowControl.Break, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Ldarg_0 = new OpCode ( + "ldarg.0", 0xff, 0x02, 1, + Code.Ldarg_0, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldarg_1 = new OpCode ( + "ldarg.1", 0xff, 0x03, 1, + Code.Ldarg_1, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldarg_2 = new OpCode ( + "ldarg.2", 0xff, 0x04, 1, + Code.Ldarg_2, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldarg_3 = new OpCode ( + "ldarg.3", 0xff, 0x05, 1, + Code.Ldarg_3, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldloc_0 = new OpCode ( + "ldloc.0", 0xff, 0x06, 1, + Code.Ldloc_0, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldloc_1 = new OpCode ( + "ldloc.1", 0xff, 0x07, 1, + Code.Ldloc_1, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldloc_2 = new OpCode ( + "ldloc.2", 0xff, 0x08, 1, + Code.Ldloc_2, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldloc_3 = new OpCode ( + "ldloc.3", 0xff, 0x09, 1, + Code.Ldloc_3, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Stloc_0 = new OpCode ( + "stloc.0", 0xff, 0x0a, 1, + Code.Stloc_0, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Stloc_1 = new OpCode ( + "stloc.1", 0xff, 0x0b, 1, + Code.Stloc_1, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Stloc_2 = new OpCode ( + "stloc.2", 0xff, 0x0c, 1, + Code.Stloc_2, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Stloc_3 = new OpCode ( + "stloc.3", 0xff, 0x0d, 1, + Code.Stloc_3, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Ldarg_S = new OpCode ( + "ldarg.s", 0xff, 0x0e, 1, + Code.Ldarg_S, FlowControl.Next, + OpCodeType.Macro, OperandType.ShortInlineParam, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldarga_S = new OpCode ( + "ldarga.s", 0xff, 0x0f, 1, + Code.Ldarga_S, FlowControl.Next, + OpCodeType.Macro, OperandType.ShortInlineParam, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Starg_S = new OpCode ( + "starg.s", 0xff, 0x10, 1, + Code.Starg_S, FlowControl.Next, + OpCodeType.Macro, OperandType.ShortInlineParam, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Ldloc_S = new OpCode ( + "ldloc.s", 0xff, 0x11, 1, + Code.Ldloc_S, FlowControl.Next, + OpCodeType.Macro, OperandType.ShortInlineVar, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldloca_S = new OpCode ( + "ldloca.s", 0xff, 0x12, 1, + Code.Ldloca_S, FlowControl.Next, + OpCodeType.Macro, OperandType.ShortInlineVar, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Stloc_S = new OpCode ( + "stloc.s", 0xff, 0x13, 1, + Code.Stloc_S, FlowControl.Next, + OpCodeType.Macro, OperandType.ShortInlineVar, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Ldnull = new OpCode ( + "ldnull", 0xff, 0x14, 1, + Code.Ldnull, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushref); + + public static readonly OpCode Ldc_I4_M1 = new OpCode ( + "ldc.i4.m1", 0xff, 0x15, 1, + Code.Ldc_I4_M1, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_0 = new OpCode ( + "ldc.i4.0", 0xff, 0x16, 1, + Code.Ldc_I4_0, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_1 = new OpCode ( + "ldc.i4.1", 0xff, 0x17, 1, + Code.Ldc_I4_1, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_2 = new OpCode ( + "ldc.i4.2", 0xff, 0x18, 1, + Code.Ldc_I4_2, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_3 = new OpCode ( + "ldc.i4.3", 0xff, 0x19, 1, + Code.Ldc_I4_3, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_4 = new OpCode ( + "ldc.i4.4", 0xff, 0x1a, 1, + Code.Ldc_I4_4, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_5 = new OpCode ( + "ldc.i4.5", 0xff, 0x1b, 1, + Code.Ldc_I4_5, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_6 = new OpCode ( + "ldc.i4.6", 0xff, 0x1c, 1, + Code.Ldc_I4_6, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_7 = new OpCode ( + "ldc.i4.7", 0xff, 0x1d, 1, + Code.Ldc_I4_7, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_8 = new OpCode ( + "ldc.i4.8", 0xff, 0x1e, 1, + Code.Ldc_I4_8, FlowControl.Next, + OpCodeType.Macro, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4_S = new OpCode ( + "ldc.i4.s", 0xff, 0x1f, 1, + Code.Ldc_I4_S, FlowControl.Next, + OpCodeType.Macro, OperandType.ShortInlineI, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I4 = new OpCode ( + "ldc.i4", 0xff, 0x20, 1, + Code.Ldc_I4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineI, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldc_I8 = new OpCode ( + "ldc.i8", 0xff, 0x21, 1, + Code.Ldc_I8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineI8, + StackBehaviour.Pop0, StackBehaviour.Pushi8); + + public static readonly OpCode Ldc_R4 = new OpCode ( + "ldc.r4", 0xff, 0x22, 1, + Code.Ldc_R4, FlowControl.Next, + OpCodeType.Primitive, OperandType.ShortInlineR, + StackBehaviour.Pop0, StackBehaviour.Pushr4); + + public static readonly OpCode Ldc_R8 = new OpCode ( + "ldc.r8", 0xff, 0x23, 1, + Code.Ldc_R8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineR, + StackBehaviour.Pop0, StackBehaviour.Pushr8); + + public static readonly OpCode Dup = new OpCode ( + "dup", 0xff, 0x25, 1, + Code.Dup, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Push1_push1); + + public static readonly OpCode Pop = new OpCode ( + "pop", 0xff, 0x26, 1, + Code.Pop, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Jmp = new OpCode ( + "jmp", 0xff, 0x27, 1, + Code.Jmp, FlowControl.Call, + OpCodeType.Primitive, OperandType.InlineMethod, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Call = new OpCode ( + "call", 0xff, 0x28, 1, + Code.Call, FlowControl.Call, + OpCodeType.Primitive, OperandType.InlineMethod, + StackBehaviour.Varpop, StackBehaviour.Varpush); + + public static readonly OpCode Calli = new OpCode ( + "calli", 0xff, 0x29, 1, + Code.Calli, FlowControl.Call, + OpCodeType.Primitive, OperandType.InlineSig, + StackBehaviour.Varpop, StackBehaviour.Varpush); + + public static readonly OpCode Ret = new OpCode ( + "ret", 0xff, 0x2a, 1, + Code.Ret, FlowControl.Return, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Varpop, StackBehaviour.Push0); + + public static readonly OpCode Br_S = new OpCode ( + "br.s", 0xff, 0x2b, 1, + Code.Br_S, FlowControl.Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Brfalse_S = new OpCode ( + "brfalse.s", 0xff, 0x2c, 1, + Code.Brfalse_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Popi, StackBehaviour.Push0); + + public static readonly OpCode Brtrue_S = new OpCode ( + "brtrue.s", 0xff, 0x2d, 1, + Code.Brtrue_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Popi, StackBehaviour.Push0); + + public static readonly OpCode Beq_S = new OpCode ( + "beq.s", 0xff, 0x2e, 1, + Code.Beq_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bge_S = new OpCode ( + "bge.s", 0xff, 0x2f, 1, + Code.Bge_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bgt_S = new OpCode ( + "bgt.s", 0xff, 0x30, 1, + Code.Bgt_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Ble_S = new OpCode ( + "ble.s", 0xff, 0x31, 1, + Code.Ble_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Blt_S = new OpCode ( + "blt.s", 0xff, 0x32, 1, + Code.Blt_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bne_Un_S = new OpCode ( + "bne.un.s", 0xff, 0x33, 1, + Code.Bne_Un_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bge_Un_S = new OpCode ( + "bge.un.s", 0xff, 0x34, 1, + Code.Bge_Un_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bgt_Un_S = new OpCode ( + "bgt.un.s", 0xff, 0x35, 1, + Code.Bgt_Un_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Ble_Un_S = new OpCode ( + "ble.un.s", 0xff, 0x36, 1, + Code.Ble_Un_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Blt_Un_S = new OpCode ( + "blt.un.s", 0xff, 0x37, 1, + Code.Blt_Un_S, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Br = new OpCode ( + "br", 0xff, 0x38, 1, + Code.Br, FlowControl.Branch, + OpCodeType.Primitive, OperandType.InlineBrTarget, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Brfalse = new OpCode ( + "brfalse", 0xff, 0x39, 1, + Code.Brfalse, FlowControl.Cond_Branch, + OpCodeType.Primitive, OperandType.InlineBrTarget, + StackBehaviour.Popi, StackBehaviour.Push0); + + public static readonly OpCode Brtrue = new OpCode ( + "brtrue", 0xff, 0x3a, 1, + Code.Brtrue, FlowControl.Cond_Branch, + OpCodeType.Primitive, OperandType.InlineBrTarget, + StackBehaviour.Popi, StackBehaviour.Push0); + + public static readonly OpCode Beq = new OpCode ( + "beq", 0xff, 0x3b, 1, + Code.Beq, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bge = new OpCode ( + "bge", 0xff, 0x3c, 1, + Code.Bge, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bgt = new OpCode ( + "bgt", 0xff, 0x3d, 1, + Code.Bgt, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Ble = new OpCode ( + "ble", 0xff, 0x3e, 1, + Code.Ble, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Blt = new OpCode ( + "blt", 0xff, 0x3f, 1, + Code.Blt, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bne_Un = new OpCode ( + "bne.un", 0xff, 0x40, 1, + Code.Bne_Un, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bge_Un = new OpCode ( + "bge.un", 0xff, 0x41, 1, + Code.Bge_Un, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Bgt_Un = new OpCode ( + "bgt.un", 0xff, 0x42, 1, + Code.Bgt_Un, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Ble_Un = new OpCode ( + "ble.un", 0xff, 0x43, 1, + Code.Ble_Un, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Blt_Un = new OpCode ( + "blt.un", 0xff, 0x44, 1, + Code.Blt_Un, FlowControl.Cond_Branch, + OpCodeType.Macro, OperandType.InlineBrTarget, + StackBehaviour.Pop1_pop1, StackBehaviour.Push0); + + public static readonly OpCode Switch = new OpCode ( + "switch", 0xff, 0x45, 1, + Code.Switch, FlowControl.Cond_Branch, + OpCodeType.Primitive, OperandType.InlineSwitch, + StackBehaviour.Popi, StackBehaviour.Push0); + + public static readonly OpCode Ldind_I1 = new OpCode ( + "ldind.i1", 0xff, 0x46, 1, + Code.Ldind_I1, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldind_U1 = new OpCode ( + "ldind.u1", 0xff, 0x47, 1, + Code.Ldind_U1, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldind_I2 = new OpCode ( + "ldind.i2", 0xff, 0x48, 1, + Code.Ldind_I2, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldind_U2 = new OpCode ( + "ldind.u2", 0xff, 0x49, 1, + Code.Ldind_U2, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldind_I4 = new OpCode ( + "ldind.i4", 0xff, 0x4a, 1, + Code.Ldind_I4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldind_U4 = new OpCode ( + "ldind.u4", 0xff, 0x4b, 1, + Code.Ldind_U4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldind_I8 = new OpCode ( + "ldind.i8", 0xff, 0x4c, 1, + Code.Ldind_I8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi8); + + public static readonly OpCode Ldind_I = new OpCode ( + "ldind.i", 0xff, 0x4d, 1, + Code.Ldind_I, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldind_R4 = new OpCode ( + "ldind.r4", 0xff, 0x4e, 1, + Code.Ldind_R4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushr4); + + public static readonly OpCode Ldind_R8 = new OpCode ( + "ldind.r8", 0xff, 0x4f, 1, + Code.Ldind_R8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushr8); + + public static readonly OpCode Ldind_Ref = new OpCode ( + "ldind.ref", 0xff, 0x50, 1, + Code.Ldind_Ref, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushref); + + public static readonly OpCode Stind_Ref = new OpCode ( + "stind.ref", 0xff, 0x51, 1, + Code.Stind_Ref, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Stind_I1 = new OpCode ( + "stind.i1", 0xff, 0x52, 1, + Code.Stind_I1, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Stind_I2 = new OpCode ( + "stind.i2", 0xff, 0x53, 1, + Code.Stind_I2, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Stind_I4 = new OpCode ( + "stind.i4", 0xff, 0x54, 1, + Code.Stind_I4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Stind_I8 = new OpCode ( + "stind.i8", 0xff, 0x55, 1, + Code.Stind_I8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popi8, StackBehaviour.Push0); + + public static readonly OpCode Stind_R4 = new OpCode ( + "stind.r4", 0xff, 0x56, 1, + Code.Stind_R4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popr4, StackBehaviour.Push0); + + public static readonly OpCode Stind_R8 = new OpCode ( + "stind.r8", 0xff, 0x57, 1, + Code.Stind_R8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popr8, StackBehaviour.Push0); + + public static readonly OpCode Add = new OpCode ( + "add", 0xff, 0x58, 1, + Code.Add, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Sub = new OpCode ( + "sub", 0xff, 0x59, 1, + Code.Sub, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Mul = new OpCode ( + "mul", 0xff, 0x5a, 1, + Code.Mul, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Div = new OpCode ( + "div", 0xff, 0x5b, 1, + Code.Div, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Div_Un = new OpCode ( + "div.un", 0xff, 0x5c, 1, + Code.Div_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Rem = new OpCode ( + "rem", 0xff, 0x5d, 1, + Code.Rem, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Rem_Un = new OpCode ( + "rem.un", 0xff, 0x5e, 1, + Code.Rem_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode And = new OpCode ( + "and", 0xff, 0x5f, 1, + Code.And, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Or = new OpCode ( + "or", 0xff, 0x60, 1, + Code.Or, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Xor = new OpCode ( + "xor", 0xff, 0x61, 1, + Code.Xor, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Shl = new OpCode ( + "shl", 0xff, 0x62, 1, + Code.Shl, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Shr = new OpCode ( + "shr", 0xff, 0x63, 1, + Code.Shr, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Shr_Un = new OpCode ( + "shr.un", 0xff, 0x64, 1, + Code.Shr_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Neg = new OpCode ( + "neg", 0xff, 0x65, 1, + Code.Neg, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Push1); + + public static readonly OpCode Not = new OpCode ( + "not", 0xff, 0x66, 1, + Code.Not, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Push1); + + public static readonly OpCode Conv_I1 = new OpCode ( + "conv.i1", 0xff, 0x67, 1, + Code.Conv_I1, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_I2 = new OpCode ( + "conv.i2", 0xff, 0x68, 1, + Code.Conv_I2, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_I4 = new OpCode ( + "conv.i4", 0xff, 0x69, 1, + Code.Conv_I4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_I8 = new OpCode ( + "conv.i8", 0xff, 0x6a, 1, + Code.Conv_I8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi8); + + public static readonly OpCode Conv_R4 = new OpCode ( + "conv.r4", 0xff, 0x6b, 1, + Code.Conv_R4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushr4); + + public static readonly OpCode Conv_R8 = new OpCode ( + "conv.r8", 0xff, 0x6c, 1, + Code.Conv_R8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushr8); + + public static readonly OpCode Conv_U4 = new OpCode ( + "conv.u4", 0xff, 0x6d, 1, + Code.Conv_U4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_U8 = new OpCode ( + "conv.u8", 0xff, 0x6e, 1, + Code.Conv_U8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi8); + + public static readonly OpCode Callvirt = new OpCode ( + "callvirt", 0xff, 0x6f, 1, + Code.Callvirt, FlowControl.Call, + OpCodeType.Objmodel, OperandType.InlineMethod, + StackBehaviour.Varpop, StackBehaviour.Varpush); + + public static readonly OpCode Cpobj = new OpCode ( + "cpobj", 0xff, 0x70, 1, + Code.Cpobj, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Ldobj = new OpCode ( + "ldobj", 0xff, 0x71, 1, + Code.Ldobj, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popi, StackBehaviour.Push1); + + public static readonly OpCode Ldstr = new OpCode ( + "ldstr", 0xff, 0x72, 1, + Code.Ldstr, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineString, + StackBehaviour.Pop0, StackBehaviour.Pushref); + + public static readonly OpCode Newobj = new OpCode ( + "newobj", 0xff, 0x73, 1, + Code.Newobj, FlowControl.Call, + OpCodeType.Objmodel, OperandType.InlineMethod, + StackBehaviour.Varpop, StackBehaviour.Pushref); + + public static readonly OpCode Castclass = new OpCode ( + "castclass", 0xff, 0x74, 1, + Code.Castclass, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popref, StackBehaviour.Pushref); + + public static readonly OpCode Isinst = new OpCode ( + "isinst", 0xff, 0x75, 1, + Code.Isinst, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popref, StackBehaviour.Pushi); + + public static readonly OpCode Conv_R_Un = new OpCode ( + "conv.r.un", 0xff, 0x76, 1, + Code.Conv_R_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushr8); + + public static readonly OpCode Unbox = new OpCode ( + "unbox", 0xff, 0x79, 1, + Code.Unbox, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineType, + StackBehaviour.Popref, StackBehaviour.Pushi); + + public static readonly OpCode Throw = new OpCode ( + "throw", 0xff, 0x7a, 1, + Code.Throw, FlowControl.Throw, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref, StackBehaviour.Push0); + + public static readonly OpCode Ldfld = new OpCode ( + "ldfld", 0xff, 0x7b, 1, + Code.Ldfld, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineField, + StackBehaviour.Popref, StackBehaviour.Push1); + + public static readonly OpCode Ldflda = new OpCode ( + "ldflda", 0xff, 0x7c, 1, + Code.Ldflda, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineField, + StackBehaviour.Popref, StackBehaviour.Pushi); + + public static readonly OpCode Stfld = new OpCode ( + "stfld", 0xff, 0x7d, 1, + Code.Stfld, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineField, + StackBehaviour.Popref_pop1, StackBehaviour.Push0); + + public static readonly OpCode Ldsfld = new OpCode ( + "ldsfld", 0xff, 0x7e, 1, + Code.Ldsfld, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineField, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldsflda = new OpCode ( + "ldsflda", 0xff, 0x7f, 1, + Code.Ldsflda, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineField, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Stsfld = new OpCode ( + "stsfld", 0xff, 0x80, 1, + Code.Stsfld, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineField, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Stobj = new OpCode ( + "stobj", 0xff, 0x81, 1, + Code.Stobj, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popi_pop1, StackBehaviour.Push0); + + public static readonly OpCode Conv_Ovf_I1_Un = new OpCode ( + "conv.ovf.i1.un", 0xff, 0x82, 1, + Code.Conv_Ovf_I1_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_I2_Un = new OpCode ( + "conv.ovf.i2.un", 0xff, 0x83, 1, + Code.Conv_Ovf_I2_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_I4_Un = new OpCode ( + "conv.ovf.i4.un", 0xff, 0x84, 1, + Code.Conv_Ovf_I4_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_I8_Un = new OpCode ( + "conv.ovf.i8.un", 0xff, 0x85, 1, + Code.Conv_Ovf_I8_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi8); + + public static readonly OpCode Conv_Ovf_U1_Un = new OpCode ( + "conv.ovf.u1.un", 0xff, 0x86, 1, + Code.Conv_Ovf_U1_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_U2_Un = new OpCode ( + "conv.ovf.u2.un", 0xff, 0x87, 1, + Code.Conv_Ovf_U2_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_U4_Un = new OpCode ( + "conv.ovf.u4.un", 0xff, 0x88, 1, + Code.Conv_Ovf_U4_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_U8_Un = new OpCode ( + "conv.ovf.u8.un", 0xff, 0x89, 1, + Code.Conv_Ovf_U8_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi8); + + public static readonly OpCode Conv_Ovf_I_Un = new OpCode ( + "conv.ovf.i.un", 0xff, 0x8a, 1, + Code.Conv_Ovf_I_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_U_Un = new OpCode ( + "conv.ovf.u.un", 0xff, 0x8b, 1, + Code.Conv_Ovf_U_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Box = new OpCode ( + "box", 0xff, 0x8c, 1, + Code.Box, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineType, + StackBehaviour.Pop1, StackBehaviour.Pushref); + + public static readonly OpCode Newarr = new OpCode ( + "newarr", 0xff, 0x8d, 1, + Code.Newarr, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popi, StackBehaviour.Pushref); + + public static readonly OpCode Ldlen = new OpCode ( + "ldlen", 0xff, 0x8e, 1, + Code.Ldlen, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref, StackBehaviour.Pushi); + + public static readonly OpCode Ldelema = new OpCode ( + "ldelema", 0xff, 0x8f, 1, + Code.Ldelema, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popref_popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldelem_I1 = new OpCode ( + "ldelem.i1", 0xff, 0x90, 1, + Code.Ldelem_I1, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldelem_U1 = new OpCode ( + "ldelem.u1", 0xff, 0x91, 1, + Code.Ldelem_U1, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldelem_I2 = new OpCode ( + "ldelem.i2", 0xff, 0x92, 1, + Code.Ldelem_I2, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldelem_U2 = new OpCode ( + "ldelem.u2", 0xff, 0x93, 1, + Code.Ldelem_U2, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldelem_I4 = new OpCode ( + "ldelem.i4", 0xff, 0x94, 1, + Code.Ldelem_I4, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldelem_U4 = new OpCode ( + "ldelem.u4", 0xff, 0x95, 1, + Code.Ldelem_U4, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldelem_I8 = new OpCode ( + "ldelem.i8", 0xff, 0x96, 1, + Code.Ldelem_I8, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushi8); + + public static readonly OpCode Ldelem_I = new OpCode ( + "ldelem.i", 0xff, 0x97, 1, + Code.Ldelem_I, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushi); + + public static readonly OpCode Ldelem_R4 = new OpCode ( + "ldelem.r4", 0xff, 0x98, 1, + Code.Ldelem_R4, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushr4); + + public static readonly OpCode Ldelem_R8 = new OpCode ( + "ldelem.r8", 0xff, 0x99, 1, + Code.Ldelem_R8, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushr8); + + public static readonly OpCode Ldelem_Ref = new OpCode ( + "ldelem.ref", 0xff, 0x9a, 1, + Code.Ldelem_Ref, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi, StackBehaviour.Pushref); + + public static readonly OpCode Stelem_I = new OpCode ( + "stelem.i", 0xff, 0x9b, 1, + Code.Stelem_I, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Stelem_I1 = new OpCode ( + "stelem.i1", 0xff, 0x9c, 1, + Code.Stelem_I1, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Stelem_I2 = new OpCode ( + "stelem.i2", 0xff, 0x9d, 1, + Code.Stelem_I2, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Stelem_I4 = new OpCode ( + "stelem.i4", 0xff, 0x9e, 1, + Code.Stelem_I4, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Stelem_I8 = new OpCode ( + "stelem.i8", 0xff, 0x9f, 1, + Code.Stelem_I8, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi_popi8, StackBehaviour.Push0); + + public static readonly OpCode Stelem_R4 = new OpCode ( + "stelem.r4", 0xff, 0xa0, 1, + Code.Stelem_R4, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi_popr4, StackBehaviour.Push0); + + public static readonly OpCode Stelem_R8 = new OpCode ( + "stelem.r8", 0xff, 0xa1, 1, + Code.Stelem_R8, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi_popr8, StackBehaviour.Push0); + + public static readonly OpCode Stelem_Ref = new OpCode ( + "stelem.ref", 0xff, 0xa2, 1, + Code.Stelem_Ref, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Popref_popi_popref, StackBehaviour.Push0); + + public static readonly OpCode Ldelem_Any = new OpCode ( + "ldelem.any", 0xff, 0xa3, 1, + Code.Ldelem_Any, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popref_popi, StackBehaviour.Push1); + + public static readonly OpCode Stelem_Any = new OpCode ( + "stelem.any", 0xff, 0xa4, 1, + Code.Stelem_Any, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popref_popi_popref, StackBehaviour.Push0); + + public static readonly OpCode Unbox_Any = new OpCode ( + "unbox.any", 0xff, 0xa5, 1, + Code.Unbox_Any, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popref, StackBehaviour.Push1); + + public static readonly OpCode Conv_Ovf_I1 = new OpCode ( + "conv.ovf.i1", 0xff, 0xb3, 1, + Code.Conv_Ovf_I1, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_U1 = new OpCode ( + "conv.ovf.u1", 0xff, 0xb4, 1, + Code.Conv_Ovf_U1, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_I2 = new OpCode ( + "conv.ovf.i2", 0xff, 0xb5, 1, + Code.Conv_Ovf_I2, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_U2 = new OpCode ( + "conv.ovf.u2", 0xff, 0xb6, 1, + Code.Conv_Ovf_U2, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_I4 = new OpCode ( + "conv.ovf.i4", 0xff, 0xb7, 1, + Code.Conv_Ovf_I4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_U4 = new OpCode ( + "conv.ovf.u4", 0xff, 0xb8, 1, + Code.Conv_Ovf_U4, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_I8 = new OpCode ( + "conv.ovf.i8", 0xff, 0xb9, 1, + Code.Conv_Ovf_I8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi8); + + public static readonly OpCode Conv_Ovf_U8 = new OpCode ( + "conv.ovf.u8", 0xff, 0xba, 1, + Code.Conv_Ovf_U8, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi8); + + public static readonly OpCode Refanyval = new OpCode ( + "refanyval", 0xff, 0xc2, 1, + Code.Refanyval, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineType, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Ckfinite = new OpCode ( + "ckfinite", 0xff, 0xc3, 1, + Code.Ckfinite, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushr8); + + public static readonly OpCode Mkrefany = new OpCode ( + "mkrefany", 0xff, 0xc6, 1, + Code.Mkrefany, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineType, + StackBehaviour.Popi, StackBehaviour.Push1); + + public static readonly OpCode Ldtoken = new OpCode ( + "ldtoken", 0xff, 0xd0, 1, + Code.Ldtoken, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineTok, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Conv_U2 = new OpCode ( + "conv.u2", 0xff, 0xd1, 1, + Code.Conv_U2, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_U1 = new OpCode ( + "conv.u1", 0xff, 0xd2, 1, + Code.Conv_U1, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_I = new OpCode ( + "conv.i", 0xff, 0xd3, 1, + Code.Conv_I, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_I = new OpCode ( + "conv.ovf.i", 0xff, 0xd4, 1, + Code.Conv_Ovf_I, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Conv_Ovf_U = new OpCode ( + "conv.ovf.u", 0xff, 0xd5, 1, + Code.Conv_Ovf_U, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Add_Ovf = new OpCode ( + "add.ovf", 0xff, 0xd6, 1, + Code.Add_Ovf, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Add_Ovf_Un = new OpCode ( + "add.ovf.un", 0xff, 0xd7, 1, + Code.Add_Ovf_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Mul_Ovf = new OpCode ( + "mul.ovf", 0xff, 0xd8, 1, + Code.Mul_Ovf, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Mul_Ovf_Un = new OpCode ( + "mul.ovf.un", 0xff, 0xd9, 1, + Code.Mul_Ovf_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Sub_Ovf = new OpCode ( + "sub.ovf", 0xff, 0xda, 1, + Code.Sub_Ovf, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Sub_Ovf_Un = new OpCode ( + "sub.ovf.un", 0xff, 0xdb, 1, + Code.Sub_Ovf_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Push1); + + public static readonly OpCode Endfinally = new OpCode ( + "endfinally", 0xff, 0xdc, 1, + Code.Endfinally, FlowControl.Return, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Leave = new OpCode ( + "leave", 0xff, 0xdd, 1, + Code.Leave, FlowControl.Branch, + OpCodeType.Primitive, OperandType.InlineBrTarget, + StackBehaviour.PopAll, StackBehaviour.Push0); + + public static readonly OpCode Leave_S = new OpCode ( + "leave.s", 0xff, 0xde, 1, + Code.Leave_S, FlowControl.Branch, + OpCodeType.Macro, OperandType.ShortInlineBrTarget, + StackBehaviour.PopAll, StackBehaviour.Push0); + + public static readonly OpCode Stind_I = new OpCode ( + "stind.i", 0xff, 0xdf, 1, + Code.Stind_I, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Conv_U = new OpCode ( + "conv.u", 0xff, 0xe0, 1, + Code.Conv_U, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Arglist = new OpCode ( + "arglist", 0xfe, 0x00, 2, + Code.Arglist, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ceq = new OpCode ( + "ceq", 0xfe, 0x01, 2, + Code.Ceq, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Pushi); + + public static readonly OpCode Cgt = new OpCode ( + "cgt", 0xfe, 0x02, 2, + Code.Cgt, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Pushi); + + public static readonly OpCode Cgt_Un = new OpCode ( + "cgt.un", 0xfe, 0x03, 2, + Code.Cgt_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Pushi); + + public static readonly OpCode Clt = new OpCode ( + "clt", 0xfe, 0x04, 2, + Code.Clt, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Pushi); + + public static readonly OpCode Clt_Un = new OpCode ( + "clt.un", 0xfe, 0x05, 2, + Code.Clt_Un, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1_pop1, StackBehaviour.Pushi); + + public static readonly OpCode Ldftn = new OpCode ( + "ldftn", 0xfe, 0x06, 2, + Code.Ldftn, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineMethod, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Ldvirtftn = new OpCode ( + "ldvirtftn", 0xfe, 0x07, 2, + Code.Ldvirtftn, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineMethod, + StackBehaviour.Popref, StackBehaviour.Pushi); + + public static readonly OpCode Ldarg = new OpCode ( + "ldarg", 0xfe, 0x09, 2, + Code.Ldarg, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineParam, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldarga = new OpCode ( + "ldarga", 0xfe, 0x0a, 2, + Code.Ldarga, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineParam, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Starg = new OpCode ( + "starg", 0xfe, 0x0b, 2, + Code.Starg, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineParam, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Ldloc = new OpCode ( + "ldloc", 0xfe, 0x0c, 2, + Code.Ldloc, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineVar, + StackBehaviour.Pop0, StackBehaviour.Push1); + + public static readonly OpCode Ldloca = new OpCode ( + "ldloca", 0xfe, 0x0d, 2, + Code.Ldloca, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineVar, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Stloc = new OpCode ( + "stloc", 0xfe, 0x0e, 2, + Code.Stloc, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineVar, + StackBehaviour.Pop1, StackBehaviour.Push0); + + public static readonly OpCode Localloc = new OpCode ( + "localloc", 0xfe, 0x0f, 2, + Code.Localloc, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Pushi); + + public static readonly OpCode Endfilter = new OpCode ( + "endfilter", 0xfe, 0x11, 2, + Code.Endfilter, FlowControl.Return, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi, StackBehaviour.Push0); + + public static readonly OpCode Unaligned = new OpCode ( + "unaligned.", 0xfe, 0x12, 2, + Code.Unaligned, FlowControl.Meta, + OpCodeType.Prefix, OperandType.ShortInlineI, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Volatile = new OpCode ( + "volatile.", 0xfe, 0x13, 2, + Code.Volatile, FlowControl.Meta, + OpCodeType.Prefix, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Tail = new OpCode ( + "tail.", 0xfe, 0x14, 2, + Code.Tail, FlowControl.Meta, + OpCodeType.Prefix, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Initobj = new OpCode ( + "initobj", 0xfe, 0x15, 2, + Code.Initobj, FlowControl.Next, + OpCodeType.Objmodel, OperandType.InlineType, + StackBehaviour.Popi, StackBehaviour.Push0); + + public static readonly OpCode Constrained = new OpCode ( + "constrained.", 0xfe, 0x16, 2, + Code.Constrained, FlowControl.Next, + OpCodeType.Prefix, OperandType.InlineTok, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Cpblk = new OpCode ( + "cpblk", 0xfe, 0x17, 2, + Code.Cpblk, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popi_popi, StackBehaviour.Push0); + + public static readonly OpCode Initblk = new OpCode ( + "initblk", 0xfe, 0x18, 2, + Code.Initblk, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Popi_popi_popi, StackBehaviour.Push0); + + public static readonly OpCode No = new OpCode ( + "no.", 0xfe, 0x19, 2, + Code.No, FlowControl.Next, + OpCodeType.Prefix, OperandType.ShortInlineI, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Rethrow = new OpCode ( + "rethrow", 0xfe, 0x1a, 2, + Code.Rethrow, FlowControl.Throw, + OpCodeType.Objmodel, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push0); + + public static readonly OpCode Sizeof = new OpCode ( + "sizeof", 0xfe, 0x1c, 2, + Code.Sizeof, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineType, + StackBehaviour.Pop0, StackBehaviour.Pushi); + + public static readonly OpCode Refanytype = new OpCode ( + "refanytype", 0xfe, 0x1d, 2, + Code.Refanytype, FlowControl.Next, + OpCodeType.Primitive, OperandType.InlineNone, + StackBehaviour.Pop1, StackBehaviour.Pushi); + + public static readonly OpCode Readonly = new OpCode ( + "readonly.", 0xfe, 0x1e, 2, + Code.Readonly, FlowControl.Next, + OpCodeType.Prefix, OperandType.InlineNone, + StackBehaviour.Pop0, StackBehaviour.Push0); + + OpCodes() + { + } + + public static OpCode GetOpCode (Code code) + { + switch (code) { + case Code.Nop : return OpCodes.Nop; + case Code.Break : return OpCodes.Break; + case Code.Ldarg_0 : return OpCodes.Ldarg_0; + case Code.Ldarg_1 : return OpCodes.Ldarg_1; + case Code.Ldarg_2 : return OpCodes.Ldarg_2; + case Code.Ldarg_3 : return OpCodes.Ldarg_3; + case Code.Ldloc_0 : return OpCodes.Ldloc_0; + case Code.Ldloc_1 : return OpCodes.Ldloc_1; + case Code.Ldloc_2 : return OpCodes.Ldloc_2; + case Code.Ldloc_3 : return OpCodes.Ldloc_3; + case Code.Stloc_0 : return OpCodes.Stloc_0; + case Code.Stloc_1 : return OpCodes.Stloc_1; + case Code.Stloc_2 : return OpCodes.Stloc_2; + case Code.Stloc_3 : return OpCodes.Stloc_3; + case Code.Ldarg_S : return OpCodes.Ldarg_S; + case Code.Ldarga_S : return OpCodes.Ldarga_S; + case Code.Starg_S : return OpCodes.Starg_S; + case Code.Ldloc_S : return OpCodes.Ldloc_S; + case Code.Ldloca_S : return OpCodes.Ldloca_S; + case Code.Stloc_S : return OpCodes.Stloc_S; + case Code.Ldnull : return OpCodes.Ldnull; + case Code.Ldc_I4_M1 : return OpCodes.Ldc_I4_M1; + case Code.Ldc_I4_0 : return OpCodes.Ldc_I4_0; + case Code.Ldc_I4_1 : return OpCodes.Ldc_I4_1; + case Code.Ldc_I4_2 : return OpCodes.Ldc_I4_2; + case Code.Ldc_I4_3 : return OpCodes.Ldc_I4_3; + case Code.Ldc_I4_4 : return OpCodes.Ldc_I4_4; + case Code.Ldc_I4_5 : return OpCodes.Ldc_I4_5; + case Code.Ldc_I4_6 : return OpCodes.Ldc_I4_6; + case Code.Ldc_I4_7 : return OpCodes.Ldc_I4_7; + case Code.Ldc_I4_8 : return OpCodes.Ldc_I4_8; + case Code.Ldc_I4_S : return OpCodes.Ldc_I4_S; + case Code.Ldc_I4 : return OpCodes.Ldc_I4; + case Code.Ldc_I8 : return OpCodes.Ldc_I8; + case Code.Ldc_R4 : return OpCodes.Ldc_R4; + case Code.Ldc_R8 : return OpCodes.Ldc_R8; + case Code.Dup : return OpCodes.Dup; + case Code.Pop : return OpCodes.Pop; + case Code.Jmp : return OpCodes.Jmp; + case Code.Call : return OpCodes.Call; + case Code.Calli : return OpCodes.Calli; + case Code.Ret : return OpCodes.Ret; + case Code.Br_S : return OpCodes.Br_S; + case Code.Brfalse_S : return OpCodes.Brfalse_S; + case Code.Brtrue_S : return OpCodes.Brtrue_S; + case Code.Beq_S : return OpCodes.Beq_S; + case Code.Bge_S : return OpCodes.Bge_S; + case Code.Bgt_S : return OpCodes.Bgt_S; + case Code.Ble_S : return OpCodes.Ble_S; + case Code.Blt_S : return OpCodes.Blt_S; + case Code.Bne_Un_S : return OpCodes.Bne_Un_S; + case Code.Bge_Un_S : return OpCodes.Bge_Un_S; + case Code.Bgt_Un_S : return OpCodes.Bgt_Un_S; + case Code.Ble_Un_S : return OpCodes.Ble_Un_S; + case Code.Blt_Un_S : return OpCodes.Blt_Un_S; + case Code.Br : return OpCodes.Br; + case Code.Brfalse : return OpCodes.Brfalse; + case Code.Brtrue : return OpCodes.Brtrue; + case Code.Beq : return OpCodes.Beq; + case Code.Bge : return OpCodes.Bge; + case Code.Bgt : return OpCodes.Bgt; + case Code.Ble : return OpCodes.Ble; + case Code.Blt : return OpCodes.Blt; + case Code.Bne_Un : return OpCodes.Bne_Un; + case Code.Bge_Un : return OpCodes.Bge_Un; + case Code.Bgt_Un : return OpCodes.Bgt_Un; + case Code.Ble_Un : return OpCodes.Ble_Un; + case Code.Blt_Un : return OpCodes.Blt_Un; + case Code.Switch : return OpCodes.Switch; + case Code.Ldind_I1 : return OpCodes.Ldind_I1; + case Code.Ldind_U1 : return OpCodes.Ldind_U1; + case Code.Ldind_I2 : return OpCodes.Ldind_I2; + case Code.Ldind_U2 : return OpCodes.Ldind_U2; + case Code.Ldind_I4 : return OpCodes.Ldind_I4; + case Code.Ldind_U4 : return OpCodes.Ldind_U4; + case Code.Ldind_I8 : return OpCodes.Ldind_I8; + case Code.Ldind_I : return OpCodes.Ldind_I; + case Code.Ldind_R4 : return OpCodes.Ldind_R4; + case Code.Ldind_R8 : return OpCodes.Ldind_R8; + case Code.Ldind_Ref : return OpCodes.Ldind_Ref; + case Code.Stind_Ref : return OpCodes.Stind_Ref; + case Code.Stind_I1 : return OpCodes.Stind_I1; + case Code.Stind_I2 : return OpCodes.Stind_I2; + case Code.Stind_I4 : return OpCodes.Stind_I4; + case Code.Stind_I8 : return OpCodes.Stind_I8; + case Code.Stind_R4 : return OpCodes.Stind_R4; + case Code.Stind_R8 : return OpCodes.Stind_R8; + case Code.Add : return OpCodes.Add; + case Code.Sub : return OpCodes.Sub; + case Code.Mul : return OpCodes.Mul; + case Code.Div : return OpCodes.Div; + case Code.Div_Un : return OpCodes.Div_Un; + case Code.Rem : return OpCodes.Rem; + case Code.Rem_Un : return OpCodes.Rem_Un; + case Code.And : return OpCodes.And; + case Code.Or : return OpCodes.Or; + case Code.Xor : return OpCodes.Xor; + case Code.Shl : return OpCodes.Shl; + case Code.Shr : return OpCodes.Shr; + case Code.Shr_Un : return OpCodes.Shr_Un; + case Code.Neg : return OpCodes.Neg; + case Code.Not : return OpCodes.Not; + case Code.Conv_I1 : return OpCodes.Conv_I1; + case Code.Conv_I2 : return OpCodes.Conv_I2; + case Code.Conv_I4 : return OpCodes.Conv_I4; + case Code.Conv_I8 : return OpCodes.Conv_I8; + case Code.Conv_R4 : return OpCodes.Conv_R4; + case Code.Conv_R8 : return OpCodes.Conv_R8; + case Code.Conv_U4 : return OpCodes.Conv_U4; + case Code.Conv_U8 : return OpCodes.Conv_U8; + case Code.Callvirt : return OpCodes.Callvirt; + case Code.Cpobj : return OpCodes.Cpobj; + case Code.Ldobj : return OpCodes.Ldobj; + case Code.Ldstr : return OpCodes.Ldstr; + case Code.Newobj : return OpCodes.Newobj; + case Code.Castclass : return OpCodes.Castclass; + case Code.Isinst : return OpCodes.Isinst; + case Code.Conv_R_Un : return OpCodes.Conv_R_Un; + case Code.Unbox : return OpCodes.Unbox; + case Code.Throw : return OpCodes.Throw; + case Code.Ldfld : return OpCodes.Ldfld; + case Code.Ldflda : return OpCodes.Ldflda; + case Code.Stfld : return OpCodes.Stfld; + case Code.Ldsfld : return OpCodes.Ldsfld; + case Code.Ldsflda : return OpCodes.Ldsflda; + case Code.Stsfld : return OpCodes.Stsfld; + case Code.Stobj : return OpCodes.Stobj; + case Code.Conv_Ovf_I1_Un : return OpCodes.Conv_Ovf_I1_Un; + case Code.Conv_Ovf_I2_Un : return OpCodes.Conv_Ovf_I2_Un; + case Code.Conv_Ovf_I4_Un : return OpCodes.Conv_Ovf_I4_Un; + case Code.Conv_Ovf_I8_Un : return OpCodes.Conv_Ovf_I8_Un; + case Code.Conv_Ovf_U1_Un : return OpCodes.Conv_Ovf_U1_Un; + case Code.Conv_Ovf_U2_Un : return OpCodes.Conv_Ovf_U2_Un; + case Code.Conv_Ovf_U4_Un : return OpCodes.Conv_Ovf_U4_Un; + case Code.Conv_Ovf_U8_Un : return OpCodes.Conv_Ovf_U8_Un; + case Code.Conv_Ovf_I_Un : return OpCodes.Conv_Ovf_I_Un; + case Code.Conv_Ovf_U_Un : return OpCodes.Conv_Ovf_U_Un; + case Code.Box : return OpCodes.Box; + case Code.Newarr : return OpCodes.Newarr; + case Code.Ldlen : return OpCodes.Ldlen; + case Code.Ldelema : return OpCodes.Ldelema; + case Code.Ldelem_I1 : return OpCodes.Ldelem_I1; + case Code.Ldelem_U1 : return OpCodes.Ldelem_U1; + case Code.Ldelem_I2 : return OpCodes.Ldelem_I2; + case Code.Ldelem_U2 : return OpCodes.Ldelem_U2; + case Code.Ldelem_I4 : return OpCodes.Ldelem_I4; + case Code.Ldelem_U4 : return OpCodes.Ldelem_U4; + case Code.Ldelem_I8 : return OpCodes.Ldelem_I8; + case Code.Ldelem_I : return OpCodes.Ldelem_I; + case Code.Ldelem_R4 : return OpCodes.Ldelem_R4; + case Code.Ldelem_R8 : return OpCodes.Ldelem_R8; + case Code.Ldelem_Ref : return OpCodes.Ldelem_Ref; + case Code.Stelem_I : return OpCodes.Stelem_I; + case Code.Stelem_I1 : return OpCodes.Stelem_I1; + case Code.Stelem_I2 : return OpCodes.Stelem_I2; + case Code.Stelem_I4 : return OpCodes.Stelem_I4; + case Code.Stelem_I8 : return OpCodes.Stelem_I8; + case Code.Stelem_R4 : return OpCodes.Stelem_R4; + case Code.Stelem_R8 : return OpCodes.Stelem_R8; + case Code.Stelem_Ref : return OpCodes.Stelem_Ref; + case Code.Ldelem_Any : return OpCodes.Ldelem_Any; + case Code.Stelem_Any : return OpCodes.Stelem_Any; + case Code.Unbox_Any : return OpCodes.Unbox_Any; + case Code.Conv_Ovf_I1 : return OpCodes.Conv_Ovf_I1; + case Code.Conv_Ovf_U1 : return OpCodes.Conv_Ovf_U1; + case Code.Conv_Ovf_I2 : return OpCodes.Conv_Ovf_I2; + case Code.Conv_Ovf_U2 : return OpCodes.Conv_Ovf_U2; + case Code.Conv_Ovf_I4 : return OpCodes.Conv_Ovf_I4; + case Code.Conv_Ovf_U4 : return OpCodes.Conv_Ovf_U4; + case Code.Conv_Ovf_I8 : return OpCodes.Conv_Ovf_I8; + case Code.Conv_Ovf_U8 : return OpCodes.Conv_Ovf_U8; + case Code.Refanyval : return OpCodes.Refanyval; + case Code.Ckfinite : return OpCodes.Ckfinite; + case Code.Mkrefany : return OpCodes.Mkrefany; + case Code.Ldtoken : return OpCodes.Ldtoken; + case Code.Conv_U2 : return OpCodes.Conv_U2; + case Code.Conv_U1 : return OpCodes.Conv_U1; + case Code.Conv_I : return OpCodes.Conv_I; + case Code.Conv_Ovf_I : return OpCodes.Conv_Ovf_I; + case Code.Conv_Ovf_U : return OpCodes.Conv_Ovf_U; + case Code.Add_Ovf : return OpCodes.Add_Ovf; + case Code.Add_Ovf_Un : return OpCodes.Add_Ovf_Un; + case Code.Mul_Ovf : return OpCodes.Mul_Ovf; + case Code.Mul_Ovf_Un : return OpCodes.Mul_Ovf_Un; + case Code.Sub_Ovf : return OpCodes.Sub_Ovf; + case Code.Sub_Ovf_Un : return OpCodes.Sub_Ovf_Un; + case Code.Endfinally : return OpCodes.Endfinally; + case Code.Leave : return OpCodes.Leave; + case Code.Leave_S : return OpCodes.Leave_S; + case Code.Stind_I : return OpCodes.Stind_I; + case Code.Conv_U : return OpCodes.Conv_U; + case Code.Arglist : return OpCodes.Arglist; + case Code.Ceq : return OpCodes.Ceq; + case Code.Cgt : return OpCodes.Cgt; + case Code.Cgt_Un : return OpCodes.Cgt_Un; + case Code.Clt : return OpCodes.Clt; + case Code.Clt_Un : return OpCodes.Clt_Un; + case Code.Ldftn : return OpCodes.Ldftn; + case Code.Ldvirtftn : return OpCodes.Ldvirtftn; + case Code.Ldarg : return OpCodes.Ldarg; + case Code.Ldarga : return OpCodes.Ldarga; + case Code.Starg : return OpCodes.Starg; + case Code.Ldloc : return OpCodes.Ldloc; + case Code.Ldloca : return OpCodes.Ldloca; + case Code.Stloc : return OpCodes.Stloc; + case Code.Localloc : return OpCodes.Localloc; + case Code.Endfilter : return OpCodes.Endfilter; + case Code.Unaligned : return OpCodes.Unaligned; + case Code.Volatile : return OpCodes.Volatile; + case Code.Tail : return OpCodes.Tail; + case Code.Initobj : return OpCodes.Initobj; + case Code.Constrained : return OpCodes.Constrained; + case Code.Cpblk : return OpCodes.Cpblk; + case Code.Initblk : return OpCodes.Initblk; + case Code.No : return OpCodes.No; + case Code.Rethrow : return OpCodes.Rethrow; + case Code.Sizeof : return OpCodes.Sizeof; + case Code.Refanytype : return OpCodes.Refanytype; + case Code.Readonly : return OpCodes.Readonly; + default : return OpCodes.Nop; + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OperandType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OperandType.cs new file mode 100644 index 0000000..938b2b9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/OperandType.cs @@ -0,0 +1,53 @@ +// +// OperandType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public enum OperandType { + InlineBrTarget, + InlineField, + InlineI, + InlineI8, + InlineMethod, + InlineNone, + InlinePhi, + InlineR, + InlineSig, + InlineString, + InlineSwitch, + InlineTok, + InlineType, + InlineVar, + InlineParam, + ShortInlineBrTarget, + ShortInlineI, + ShortInlineR, + ShortInlineVar, + ShortInlineParam + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Scope.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Scope.cs new file mode 100644 index 0000000..ce4068c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/Scope.cs @@ -0,0 +1,79 @@ +// +// Scope.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public class Scope : IScopeProvider, IVariableDefinitionProvider, ICodeVisitable { + + Instruction m_start; + Instruction m_end; + + Scope m_parent; + ScopeCollection m_scopes; + + VariableDefinitionCollection m_variables; + + public Instruction Start { + get { return m_start; } + set { m_start = value; } + } + + public Instruction End { + get { return m_end; } + set { m_end = value; } + } + + public Scope Parent { + get { return m_parent; } + set { m_parent = value; } + } + + public ScopeCollection Scopes { + get { + if (m_scopes == null) + m_scopes = new ScopeCollection (this); + + return m_scopes; + } + } + + public VariableDefinitionCollection Variables { + get { + if (m_variables == null) + m_variables = new VariableDefinitionCollection (this); + + return m_variables; + } + } + + public void Accept (ICodeVisitor visitor) + { + visitor.VisitScope (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ScopeCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ScopeCollection.cs new file mode 100644 index 0000000..6872e70 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/ScopeCollection.cs @@ -0,0 +1,93 @@ +// +// ScopeCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:54 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ScopeCollection : CollectionBase, ICodeVisitable { + + IScopeProvider m_container; + + public Scope this [int index] { + get { return List [index] as Scope; } + set { List [index] = value; } + } + + public IScopeProvider Container { + get { return m_container; } + } + + public ScopeCollection (IScopeProvider container) + { + m_container = container; + } + + public void Add (Scope value) + { + List.Add (value); + } + + public bool Contains (Scope value) + { + return List.Contains (value); + } + + public int IndexOf (Scope value) + { + return List.IndexOf (value); + } + + public void Insert (int index, Scope value) + { + List.Insert (index, value); + } + + public void Remove (Scope value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is Scope)) + throw new ArgumentException ("Must be of type " + typeof (Scope).FullName); + } + + public void Accept (ICodeVisitor visitor) + { + visitor.VisitScopeCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs new file mode 100644 index 0000000..81dc110 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/SequencePoint.cs @@ -0,0 +1,78 @@ +// +// SequencePoint.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public class SequencePoint { + + Document m_document; + + int m_startLine; + int m_startColumn; + int m_endLine; + int m_endColumn; + + public int StartLine { + get { return m_startLine; } + set { m_startLine = value; } + } + + public int StartColumn { + get { return m_startColumn; } + set { m_startColumn = value; } + } + + public int EndLine { + get { return m_endLine; } + set { m_endLine = value; } + } + + public int EndColumn { + get { return m_endColumn; } + set { m_endColumn = value; } + } + + public Document Document { + get { return m_document; } + set { m_document = value; } + } + + public SequencePoint (Document document) + { + m_document = document; + } + + public SequencePoint (Document doc, int startLine, int startCol, int endLine, int endCol) : this (doc) + { + m_startLine = startLine; + m_startColumn = startCol; + m_endLine = endLine; + m_endColumn = endCol; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/StackBehaviour.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/StackBehaviour.cs new file mode 100644 index 0000000..edab8aa --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/StackBehaviour.cs @@ -0,0 +1,62 @@ +// +// StackBehaviour.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public enum StackBehaviour { + Pop0, + Pop1, + Pop1_pop1, + Popi, + Popi_pop1, + Popi_popi, + Popi_popi8, + Popi_popi_popi, + Popi_popr4, + Popi_popr8, + Popref, + Popref_pop1, + Popref_popi, + Popref_popi_popi, + Popref_popi_popi8, + Popref_popi_popr4, + Popref_popi_popr8, + Popref_popi_popref, + PopAll, + Push0, + Push1, + Push1_push1, + Pushi, + Pushi8, + Pushr4, + Pushr8, + Pushref, + Varpop, + Varpush + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/SymbolStoreHelper.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/SymbolStoreHelper.cs new file mode 100644 index 0000000..c68d3c3 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/SymbolStoreHelper.cs @@ -0,0 +1,77 @@ +// +// SymbolStoreHelper.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using SR = System.Reflection; + + class SymbolStoreHelper { + + static readonly string MonoSymbolSupport = "Mono.Cecil.Mdb.MdbFactory, Mono.Cecil.Mdb"; + static readonly string DotNetSymbolSupport = "Mono.Cecil.Pdb.PdbFactory, Mono.Cecil.Pdb"; + + static ISymbolStoreFactory s_factory; + + SymbolStoreHelper () + { + } + + public static ISymbolReader GetReader (ModuleDefinition module) + { + InitFactory (); + + return s_factory.CreateReader (module, module.Image.FileInformation.FullName); + } + + public static ISymbolWriter GetWriter (ModuleDefinition module, string assemblyFileName) + { + InitFactory (); + + return s_factory.CreateWriter (module, assemblyFileName); + } + + static void InitFactory () + { + if (s_factory != null) + return; + + Type factoryType = Type.GetType (OnMono () ? + MonoSymbolSupport : + DotNetSymbolSupport, + true); + + s_factory = (ISymbolStoreFactory) Activator.CreateInstance (factoryType); + } + + static bool OnMono () + { + return typeof (object).Assembly.GetType ("System.MonoType", false) != null; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs new file mode 100644 index 0000000..6518f5b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableDefinition.cs @@ -0,0 +1,55 @@ +// +// VariableDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public sealed class VariableDefinition : VariableReference { + + MethodDefinition m_method; + + public MethodDefinition Method { + get { return m_method; } + set { m_method = value; } + } + + public VariableDefinition (TypeReference variableType) : base (variableType) + { + } + + public VariableDefinition (string name, int index, MethodDefinition method, TypeReference variableType) : + base (name, index, variableType) + { + m_method = method; + } + + public override void Accept (ICodeVisitor visitor) + { + visitor.VisitVariableDefinition (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableDefinitionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableDefinitionCollection.cs new file mode 100644 index 0000000..3bd8446 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableDefinitionCollection.cs @@ -0,0 +1,93 @@ +// +// VariableDefinitionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:53 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class VariableDefinitionCollection : CollectionBase, ICodeVisitable { + + IVariableDefinitionProvider m_container; + + public VariableDefinition this [int index] { + get { return List [index] as VariableDefinition; } + set { List [index] = value; } + } + + public IVariableDefinitionProvider Container { + get { return m_container; } + } + + public VariableDefinitionCollection (IVariableDefinitionProvider container) + { + m_container = container; + } + + public void Add (VariableDefinition value) + { + List.Add (value); + } + + public bool Contains (VariableDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (VariableDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, VariableDefinition value) + { + List.Insert (index, value); + } + + public void Remove (VariableDefinition value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is VariableDefinition)) + throw new ArgumentException ("Must be of type " + typeof (VariableDefinition).FullName); + } + + public void Accept (ICodeVisitor visitor) + { + visitor.VisitVariableDefinitionCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs new file mode 100644 index 0000000..7100730 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Cil/VariableReference.cs @@ -0,0 +1,73 @@ +// +// VariableReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Cil { + + public abstract class VariableReference : ICodeVisitable { + + string m_name; + int m_index; + TypeReference m_variableType; + + public string Name { + get { return m_name; } + set { m_name = value; } + } + + public int Index { + get { return m_index; } + set { m_index = value; } + } + + public TypeReference VariableType { + get { return m_variableType; } + set { m_variableType = value; } + } + + public VariableReference (TypeReference variableType) + { + m_variableType = variableType; + } + + public VariableReference (string name, int index, TypeReference variableType) : this (variableType) + { + m_name = name; + m_index = index; + } + + public override string ToString () + { + if (m_name != null && m_name.Length > 0) + return m_name; + + return string.Concat ("V_", m_index); + } + + public abstract void Accept (ICodeVisitor visitor); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Assembly.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Assembly.cs new file mode 100644 index 0000000..72da5c2 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Assembly.cs @@ -0,0 +1,88 @@ +// +// AssemblyTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class AssemblyTable : IMetadataTable { + + public const int RId = 0x20; + + RowCollection m_rows; + + public AssemblyRow this [int index] { + get { return m_rows [index] as AssemblyRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal AssemblyTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitAssemblyTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class AssemblyRow : IMetadataRow { + + public AssemblyHashAlgorithm HashAlgId; + public ushort MajorVersion; + public ushort MinorVersion; + public ushort BuildNumber; + public ushort RevisionNumber; + public AssemblyFlags Flags; + public uint PublicKey; + public uint Name; + public uint Culture; + + internal AssemblyRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitAssemblyRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyOS.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyOS.cs new file mode 100644 index 0000000..b6b193b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyOS.cs @@ -0,0 +1,80 @@ +// +// AssemblyOSTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class AssemblyOSTable : IMetadataTable { + + public const int RId = 0x22; + + RowCollection m_rows; + + public AssemblyOSRow this [int index] { + get { return m_rows [index] as AssemblyOSRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal AssemblyOSTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitAssemblyOSTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class AssemblyOSRow : IMetadataRow { + + public uint OSPlatformID; + public uint OSMajorVersion; + public uint OSMinorVersion; + + internal AssemblyOSRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitAssemblyOSRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyProcessor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyProcessor.cs new file mode 100644 index 0000000..ca7c7a9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyProcessor.cs @@ -0,0 +1,78 @@ +// +// AssemblyProcessorTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class AssemblyProcessorTable : IMetadataTable { + + public const int RId = 0x21; + + RowCollection m_rows; + + public AssemblyProcessorRow this [int index] { + get { return m_rows [index] as AssemblyProcessorRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal AssemblyProcessorTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitAssemblyProcessorTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class AssemblyProcessorRow : IMetadataRow { + + public uint Processor; + + internal AssemblyProcessorRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitAssemblyProcessorRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRef.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRef.cs new file mode 100644 index 0000000..06b5006 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRef.cs @@ -0,0 +1,88 @@ +// +// AssemblyRefTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class AssemblyRefTable : IMetadataTable { + + public const int RId = 0x23; + + RowCollection m_rows; + + public AssemblyRefRow this [int index] { + get { return m_rows [index] as AssemblyRefRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal AssemblyRefTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitAssemblyRefTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class AssemblyRefRow : IMetadataRow { + + public ushort MajorVersion; + public ushort MinorVersion; + public ushort BuildNumber; + public ushort RevisionNumber; + public AssemblyFlags Flags; + public uint PublicKeyOrToken; + public uint Name; + public uint Culture; + public uint HashValue; + + internal AssemblyRefRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitAssemblyRefRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefOS.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefOS.cs new file mode 100644 index 0000000..db794e9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefOS.cs @@ -0,0 +1,81 @@ +// +// AssemblyRefOSTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class AssemblyRefOSTable : IMetadataTable { + + public const int RId = 0x25; + + RowCollection m_rows; + + public AssemblyRefOSRow this [int index] { + get { return m_rows [index] as AssemblyRefOSRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal AssemblyRefOSTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitAssemblyRefOSTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class AssemblyRefOSRow : IMetadataRow { + + public uint OSPlatformID; + public uint OSMajorVersion; + public uint OSMinorVersion; + public uint AssemblyRef; + + internal AssemblyRefOSRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitAssemblyRefOSRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefProcessor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefProcessor.cs new file mode 100644 index 0000000..80cef8b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/AssemblyRefProcessor.cs @@ -0,0 +1,79 @@ +// +// AssemblyRefProcessorTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class AssemblyRefProcessorTable : IMetadataTable { + + public const int RId = 0x24; + + RowCollection m_rows; + + public AssemblyRefProcessorRow this [int index] { + get { return m_rows [index] as AssemblyRefProcessorRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal AssemblyRefProcessorTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitAssemblyRefProcessorTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class AssemblyRefProcessorRow : IMetadataRow { + + public uint Processor; + public uint AssemblyRef; + + internal AssemblyRefProcessorRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitAssemblyRefProcessorRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/BaseMetadataVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/BaseMetadataVisitor.cs new file mode 100644 index 0000000..fd6ac0f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/BaseMetadataVisitor.cs @@ -0,0 +1,448 @@ +// +// BaseMetadataVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public abstract class BaseMetadataVisitor : IMetadataVisitor { + + public virtual void VisitMetadataRoot (MetadataRoot root) + { + } + + public virtual void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header) + { + } + + public virtual void VisitMetadataStreamCollection (MetadataStreamCollection streams) + { + } + + public virtual void VisitMetadataStream (MetadataStream stream) + { + } + + public virtual void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header) + { + } + + public virtual void VisitGuidHeap (GuidHeap heap) + { + } + + public virtual void VisitStringsHeap (StringsHeap heap) + { + } + + public virtual void VisitTablesHeap (TablesHeap heap) + { + } + + public virtual void VisitBlobHeap (BlobHeap heap) + { + } + + public virtual void VisitUserStringsHeap (UserStringsHeap heap) + { + } + + public virtual void TerminateMetadataRoot (MetadataRoot root) + { + } + } + + public abstract class BaseMetadataTableVisitor : IMetadataTableVisitor { + + public virtual void VisitTableCollection (TableCollection coll) + { + } + + public virtual void VisitAssemblyTable (AssemblyTable table) + { + } + + public virtual void VisitAssemblyOSTable (AssemblyOSTable table) + { + } + + public virtual void VisitAssemblyProcessorTable (AssemblyProcessorTable table) + { + } + + public virtual void VisitAssemblyRefTable (AssemblyRefTable table) + { + } + + public virtual void VisitAssemblyRefOSTable (AssemblyRefOSTable table) + { + } + + public virtual void VisitAssemblyRefProcessorTable (AssemblyRefProcessorTable table) + { + } + + public virtual void VisitClassLayoutTable (ClassLayoutTable table) + { + } + + public virtual void VisitConstantTable (ConstantTable table) + { + } + + public virtual void VisitCustomAttributeTable (CustomAttributeTable table) + { + } + + public virtual void VisitDeclSecurityTable (DeclSecurityTable table) + { + } + + public virtual void VisitEventTable (EventTable table) + { + } + + public virtual void VisitEventMapTable (EventMapTable table) + { + } + + public virtual void VisitEventPtrTable (EventPtrTable table) + { + } + + public virtual void VisitExportedTypeTable (ExportedTypeTable table) + { + } + + public virtual void VisitFieldTable (FieldTable table) + { + } + + public virtual void VisitFieldLayoutTable (FieldLayoutTable table) + { + } + + public virtual void VisitFieldMarshalTable (FieldMarshalTable table) + { + } + + public virtual void VisitFieldPtrTable (FieldPtrTable table) + { + } + + public virtual void VisitFieldRVATable (FieldRVATable table) + { + } + + public virtual void VisitFileTable (FileTable table) + { + } + + public virtual void VisitGenericParamTable (GenericParamTable table) + { + } + + public virtual void VisitGenericParamConstraintTable (GenericParamConstraintTable table) + { + } + + public virtual void VisitImplMapTable (ImplMapTable table) + { + } + + public virtual void VisitInterfaceImplTable (InterfaceImplTable table) + { + } + + public virtual void VisitManifestResourceTable (ManifestResourceTable table) + { + } + + public virtual void VisitMemberRefTable (MemberRefTable table) + { + } + + public virtual void VisitMethodTable (MethodTable table) + { + } + + public virtual void VisitMethodImplTable (MethodImplTable table) + { + } + + public virtual void VisitMethodPtrTable (MethodPtrTable table) + { + } + + public virtual void VisitMethodSemanticsTable (MethodSemanticsTable table) + { + } + + public virtual void VisitMethodSpecTable (MethodSpecTable table) + { + } + + public virtual void VisitModuleTable (ModuleTable table) + { + } + + public virtual void VisitModuleRefTable (ModuleRefTable table) + { + } + + public virtual void VisitNestedClassTable (NestedClassTable table) + { + } + + public virtual void VisitParamTable (ParamTable table) + { + } + + public virtual void VisitParamPtrTable (ParamPtrTable table) + { + } + + public virtual void VisitPropertyTable (PropertyTable table) + { + } + + public virtual void VisitPropertyMapTable (PropertyMapTable table) + { + } + + public virtual void VisitPropertyPtrTable (PropertyPtrTable table) + { + } + + public virtual void VisitStandAloneSigTable (StandAloneSigTable table) + { + } + + public virtual void VisitTypeDefTable (TypeDefTable table) + { + } + + public virtual void VisitTypeRefTable (TypeRefTable table) + { + } + + public virtual void VisitTypeSpecTable (TypeSpecTable table) + { + } + + public virtual void TerminateTableCollection (TableCollection coll) + { + } + + public abstract IMetadataRowVisitor GetRowVisitor(); + } + + public abstract class BaseMetadataRowVisitor : IMetadataRowVisitor { + + public virtual void VisitRowCollection (RowCollection coll) + { + } + + public virtual void VisitAssemblyRow (AssemblyRow row) + { + } + + public virtual void VisitAssemblyOSRow (AssemblyOSRow row) + { + } + + public virtual void VisitAssemblyProcessorRow (AssemblyProcessorRow row) + { + } + + public virtual void VisitAssemblyRefRow (AssemblyRefRow row) + { + } + + public virtual void VisitAssemblyRefOSRow (AssemblyRefOSRow row) + { + } + + public virtual void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row) + { + } + + public virtual void VisitClassLayoutRow (ClassLayoutRow row) + { + } + + public virtual void VisitConstantRow (ConstantRow row) + { + } + + public virtual void VisitCustomAttributeRow (CustomAttributeRow row) + { + } + + public virtual void VisitDeclSecurityRow (DeclSecurityRow row) + { + } + + public virtual void VisitEventRow (EventRow row) + { + } + + public virtual void VisitEventMapRow (EventMapRow row) + { + } + + public virtual void VisitEventPtrRow (EventPtrRow row) + { + } + + public virtual void VisitExportedTypeRow (ExportedTypeRow row) + { + } + + public virtual void VisitFieldRow (FieldRow row) + { + } + + public virtual void VisitFieldLayoutRow (FieldLayoutRow row) + { + } + + public virtual void VisitFieldMarshalRow (FieldMarshalRow row) + { + } + + public virtual void VisitFieldPtrRow (FieldPtrRow row) + { + } + + public virtual void VisitFieldRVARow (FieldRVARow row) + { + } + + public virtual void VisitFileRow (FileRow row) + { + } + + public virtual void VisitGenericParamRow (GenericParamRow row) + { + } + + public virtual void VisitGenericParamConstraintRow (GenericParamConstraintRow row) + { + } + + public virtual void VisitImplMapRow (ImplMapRow row) + { + } + + public virtual void VisitInterfaceImplRow (InterfaceImplRow row) + { + } + + public virtual void VisitManifestResourceRow (ManifestResourceRow row) + { + } + + public virtual void VisitMemberRefRow (MemberRefRow row) + { + } + + public virtual void VisitMethodRow (MethodRow row) + { + } + + public virtual void VisitMethodImplRow (MethodImplRow row) + { + } + + public virtual void VisitMethodPtrRow (MethodPtrRow row) + { + } + + public virtual void VisitMethodSemanticsRow (MethodSemanticsRow row) + { + } + + public virtual void VisitMethodSpecRow (MethodSpecRow row) + { + } + + public virtual void VisitModuleRow (ModuleRow row) + { + } + + public virtual void VisitModuleRefRow (ModuleRefRow row) + { + } + + public virtual void VisitNestedClassRow (NestedClassRow row) + { + } + + public virtual void VisitParamRow (ParamRow row) + { + } + + public virtual void VisitParamPtrRow (ParamPtrRow row) + { + } + + public virtual void VisitPropertyRow (PropertyRow row) + { + } + + public virtual void VisitPropertyMapRow (PropertyMapRow row) + { + } + + public virtual void VisitPropertyPtrRow (PropertyPtrRow row) + { + } + + public virtual void VisitStandAloneSigRow (StandAloneSigRow row) + { + } + + public virtual void VisitTypeDefRow (TypeDefRow row) + { + } + + public virtual void VisitTypeRefRow (TypeRefRow row) + { + } + + public virtual void VisitTypeSpecRow (TypeSpecRow row) + { + } + + public virtual void TerminateRowCollection (RowCollection coll) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs new file mode 100644 index 0000000..57dd2e1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/BlobHeap.cs @@ -0,0 +1,54 @@ +// +// BlobHeap.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System.IO; + + public class BlobHeap : MetadataHeap { + + internal BlobHeap (MetadataStream stream) : base (stream, MetadataStream.Blob) + { + } + + public byte [] Read (uint index) + { + return ReadBytesFromStream (index); + } + + public BinaryReader GetReader (uint index) + { + return new BinaryReader (new MemoryStream (Read (index))); + } + + public override void Accept (IMetadataVisitor visitor) + { + visitor.VisitBlobHeap (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ClassLayout.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ClassLayout.cs new file mode 100644 index 0000000..cb83be4 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ClassLayout.cs @@ -0,0 +1,80 @@ +// +// ClassLayoutTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class ClassLayoutTable : IMetadataTable { + + public const int RId = 0x0f; + + RowCollection m_rows; + + public ClassLayoutRow this [int index] { + get { return m_rows [index] as ClassLayoutRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ClassLayoutTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitClassLayoutTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ClassLayoutRow : IMetadataRow { + + public ushort PackingSize; + public uint ClassSize; + public uint Parent; + + internal ClassLayoutRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitClassLayoutRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs new file mode 100644 index 0000000..2cf5578 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CodedIndex.cs @@ -0,0 +1,49 @@ +// +// CodedIndex.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Mar 20 16:02:16 +0100 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public enum CodedIndex { + TypeDefOrRef, + HasConstant, + HasCustomAttribute, + HasFieldMarshal, + HasDeclSecurity, + MemberRefParent, + HasSemantics, + MethodDefOrRef, + MemberForwarded, + Implementation, + CustomAttributeType, + ResolutionScope, + TypeOrMethodDef + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Constant.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Constant.cs new file mode 100644 index 0000000..3ca867d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Constant.cs @@ -0,0 +1,80 @@ +// +// ConstantTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class ConstantTable : IMetadataTable { + + public const int RId = 0x0b; + + RowCollection m_rows; + + public ConstantRow this [int index] { + get { return m_rows [index] as ConstantRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ConstantTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitConstantTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ConstantRow : IMetadataRow { + + public ElementType Type; + public MetadataToken Parent; + public uint Value; + + internal ConstantRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitConstantRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CultureUtils.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CultureUtils.cs new file mode 100644 index 0000000..426f92b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CultureUtils.cs @@ -0,0 +1,83 @@ +// +// CultureUtils.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + using System.Globalization; + + class CultureUtils { + + static IDictionary m_cultures; + + CultureUtils () + { + } + + static void LoadCultures () + { + if (m_cultures != null) + return; + +#if CF_1_0 || CF_2_0 + CultureInfo [] cultures = new CultureInfo [0]; +#else + CultureInfo [] cultures = CultureInfo.GetCultures (CultureTypes.AllCultures); +#endif + m_cultures = new Hashtable (cultures.Length + 2); + + foreach (CultureInfo ci in cultures) + if (!m_cultures.Contains (ci.Name)) + m_cultures.Add (ci.Name, ci); + + if (!m_cultures.Contains (string.Empty)) + m_cultures.Add (string.Empty, CultureInfo.InvariantCulture); + + m_cultures.Add ("neutral", CultureInfo.InvariantCulture); + } + + public static bool IsValid (string culture) + { + if (culture == null) + throw new ArgumentNullException ("culture"); + + LoadCultures (); + + return m_cultures.Contains (culture); + } + + public static CultureInfo GetCultureInfo (string culture) + { + if (IsValid (culture)) + return m_cultures [culture] as CultureInfo; + + return CultureInfo.InvariantCulture; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CustomAttribute.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CustomAttribute.cs new file mode 100644 index 0000000..21a0d0c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/CustomAttribute.cs @@ -0,0 +1,80 @@ +// +// CustomAttributeTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:25 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class CustomAttributeTable : IMetadataTable { + + public const int RId = 0x0c; + + RowCollection m_rows; + + public CustomAttributeRow this [int index] { + get { return m_rows [index] as CustomAttributeRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal CustomAttributeTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitCustomAttributeTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class CustomAttributeRow : IMetadataRow { + + public MetadataToken Parent; + public MetadataToken Type; + public uint Value; + + internal CustomAttributeRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitCustomAttributeRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/DeclSecurity.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/DeclSecurity.cs new file mode 100644 index 0000000..1b2fbdc --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/DeclSecurity.cs @@ -0,0 +1,82 @@ +// +// DeclSecurityTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class DeclSecurityTable : IMetadataTable { + + public const int RId = 0x0e; + + RowCollection m_rows; + + public DeclSecurityRow this [int index] { + get { return m_rows [index] as DeclSecurityRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal DeclSecurityTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitDeclSecurityTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class DeclSecurityRow : IMetadataRow { + + public SecurityAction Action; + public MetadataToken Parent; + public uint PermissionSet; + + internal DeclSecurityRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitDeclSecurityRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs new file mode 100644 index 0000000..4d78f43 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ElementType.cs @@ -0,0 +1,73 @@ +// +// ElementType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public enum ElementType { + End = 0x00, // Marks end of a list + Void = 0x01, + Boolean = 0x02, + Char = 0x03, + I1 = 0x04, + U1 = 0x05, + I2 = 0x06, + U2 = 0x07, + I4 = 0x08, + U4 = 0x09, + I8 = 0x0a, + U8 = 0x0b, + R4 = 0x0c, + R8 = 0x0d, + String = 0x0e, + Ptr = 0x0f, // Followed by <type> token + ByRef = 0x10, // Followed by <type> token + ValueType = 0x11, // Followed by <type> token + Class = 0x12, // Followed by <type> token + Var = 0x13, // Followed by generic parameter number + Array = 0x14, // <type> <rank> <boundsCount> <bound1> <loCount> <lo1> + GenericInst = 0x15, // <type> <type-arg-count> <type-1> ... <type-n> */ + TypedByRef = 0x16, + I = 0x18, // System.IntPtr + U = 0x19, // System.UIntPtr + FnPtr = 0x1b, // Followed by full method signature + Object = 0x1c, // System.Object + SzArray = 0x1d, // Single-dim array with 0 lower bound + MVar = 0x1e, // Followed by generic parameter number + CModReqD = 0x1f, // Required modifier : followed by a TypeDef or TypeRef token + CModOpt = 0x20, // Optional modifier : followed by a TypeDef or TypeRef token + Internal = 0x21, // Implemented within the CLI + Modifier = 0x40, // Or'd with following element types + Sentinel = 0x41, // Sentinel for varargs method signature + Pinned = 0x45, // Denotes a local variable that points at a pinned object + + // special undocumented constants + Type = 0x50, + Boxed = 0x51, + Enum = 0x55 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Event.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Event.cs new file mode 100644 index 0000000..a60fedb --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Event.cs @@ -0,0 +1,82 @@ +// +// EventTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class EventTable : IMetadataTable { + + public const int RId = 0x14; + + RowCollection m_rows; + + public EventRow this [int index] { + get { return m_rows [index] as EventRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal EventTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitEventTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class EventRow : IMetadataRow { + + public EventAttributes EventFlags; + public uint Name; + public MetadataToken EventType; + + internal EventRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitEventRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/EventMap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/EventMap.cs new file mode 100644 index 0000000..c3be845 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/EventMap.cs @@ -0,0 +1,79 @@ +// +// EventMapTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class EventMapTable : IMetadataTable { + + public const int RId = 0x12; + + RowCollection m_rows; + + public EventMapRow this [int index] { + get { return m_rows [index] as EventMapRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal EventMapTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitEventMapTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class EventMapRow : IMetadataRow { + + public uint Parent; + public uint EventList; + + internal EventMapRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitEventMapRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/EventPtr.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/EventPtr.cs new file mode 100644 index 0000000..094fe5c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/EventPtr.cs @@ -0,0 +1,78 @@ +// +// EventPtrTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class EventPtrTable : IMetadataTable { + + public const int RId = 0x13; + + RowCollection m_rows; + + public EventPtrRow this [int index] { + get { return m_rows [index] as EventPtrRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal EventPtrTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitEventPtrTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class EventPtrRow : IMetadataRow { + + public uint Event; + + internal EventPtrRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitEventPtrRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ExportedType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ExportedType.cs new file mode 100644 index 0000000..bca827f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ExportedType.cs @@ -0,0 +1,84 @@ +// +// ExportedTypeTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class ExportedTypeTable : IMetadataTable { + + public const int RId = 0x27; + + RowCollection m_rows; + + public ExportedTypeRow this [int index] { + get { return m_rows [index] as ExportedTypeRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ExportedTypeTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitExportedTypeTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ExportedTypeRow : IMetadataRow { + + public TypeAttributes Flags; + public uint TypeDefId; + public uint TypeName; + public uint TypeNamespace; + public MetadataToken Implementation; + + internal ExportedTypeRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitExportedTypeRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Field.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Field.cs new file mode 100644 index 0000000..65b7998 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Field.cs @@ -0,0 +1,82 @@ +// +// FieldTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class FieldTable : IMetadataTable { + + public const int RId = 0x04; + + RowCollection m_rows; + + public FieldRow this [int index] { + get { return m_rows [index] as FieldRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal FieldTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitFieldTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class FieldRow : IMetadataRow { + + public FieldAttributes Flags; + public uint Name; + public uint Signature; + + internal FieldRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitFieldRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldLayout.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldLayout.cs new file mode 100644 index 0000000..5cf1563 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldLayout.cs @@ -0,0 +1,79 @@ +// +// FieldLayoutTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class FieldLayoutTable : IMetadataTable { + + public const int RId = 0x10; + + RowCollection m_rows; + + public FieldLayoutRow this [int index] { + get { return m_rows [index] as FieldLayoutRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal FieldLayoutTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitFieldLayoutTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class FieldLayoutRow : IMetadataRow { + + public uint Offset; + public uint Field; + + internal FieldLayoutRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitFieldLayoutRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldMarshal.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldMarshal.cs new file mode 100644 index 0000000..f5c6936 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldMarshal.cs @@ -0,0 +1,79 @@ +// +// FieldMarshalTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class FieldMarshalTable : IMetadataTable { + + public const int RId = 0x0d; + + RowCollection m_rows; + + public FieldMarshalRow this [int index] { + get { return m_rows [index] as FieldMarshalRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal FieldMarshalTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitFieldMarshalTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class FieldMarshalRow : IMetadataRow { + + public MetadataToken Parent; + public uint NativeType; + + internal FieldMarshalRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitFieldMarshalRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldPtr.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldPtr.cs new file mode 100644 index 0000000..b0d0c8a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldPtr.cs @@ -0,0 +1,78 @@ +// +// FieldPtrTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class FieldPtrTable : IMetadataTable { + + public const int RId = 0x03; + + RowCollection m_rows; + + public FieldPtrRow this [int index] { + get { return m_rows [index] as FieldPtrRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal FieldPtrTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitFieldPtrTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class FieldPtrRow : IMetadataRow { + + public uint Field; + + internal FieldPtrRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitFieldPtrRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldRVA.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldRVA.cs new file mode 100644 index 0000000..e4e9fce --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/FieldRVA.cs @@ -0,0 +1,81 @@ +// +// FieldRVATable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil.Binary; + + public sealed class FieldRVATable : IMetadataTable { + + public const int RId = 0x1d; + + RowCollection m_rows; + + public FieldRVARow this [int index] { + get { return m_rows [index] as FieldRVARow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal FieldRVATable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitFieldRVATable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class FieldRVARow : IMetadataRow { + + public RVA RVA; + public uint Field; + + internal FieldRVARow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitFieldRVARow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/File.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/File.cs new file mode 100644 index 0000000..de10919 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/File.cs @@ -0,0 +1,82 @@ +// +// FileTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class FileTable : IMetadataTable { + + public const int RId = 0x26; + + RowCollection m_rows; + + public FileRow this [int index] { + get { return m_rows [index] as FileRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal FileTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitFileTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class FileRow : IMetadataRow { + + public FileAttributes Flags; + public uint Name; + public uint HashValue; + + internal FileRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitFileRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GenericParam.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GenericParam.cs new file mode 100644 index 0000000..219ca60 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GenericParam.cs @@ -0,0 +1,83 @@ +// +// GenericParamTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class GenericParamTable : IMetadataTable { + + public const int RId = 0x2a; + + RowCollection m_rows; + + public GenericParamRow this [int index] { + get { return m_rows [index] as GenericParamRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal GenericParamTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitGenericParamTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class GenericParamRow : IMetadataRow { + + public ushort Number; + public GenericParameterAttributes Flags; + public MetadataToken Owner; + public uint Name; + + internal GenericParamRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitGenericParamRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GenericParamConstraint.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GenericParamConstraint.cs new file mode 100644 index 0000000..f6aa328 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GenericParamConstraint.cs @@ -0,0 +1,79 @@ +// +// GenericParamConstraintTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class GenericParamConstraintTable : IMetadataTable { + + public const int RId = 0x2c; + + RowCollection m_rows; + + public GenericParamConstraintRow this [int index] { + get { return m_rows [index] as GenericParamConstraintRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal GenericParamConstraintTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitGenericParamConstraintTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class GenericParamConstraintRow : IMetadataRow { + + public uint Owner; + public MetadataToken Constraint; + + internal GenericParamConstraintRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitGenericParamConstraintRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs new file mode 100644 index 0000000..6ab60aa --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/GuidHeap.cs @@ -0,0 +1,74 @@ +// +// GuidHeap.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + public class GuidHeap : MetadataHeap { + + readonly IDictionary m_guids; + + public IDictionary Guids { + get { return m_guids; } + } + + public GuidHeap (MetadataStream stream) : base (stream, MetadataStream.GUID) + { + m_guids = new Hashtable (); + } + + public Guid this [uint index] { + get { + if (index == 0) + return new Guid (new byte [16]); + + int idx = (int) index - 1; + + if (m_guids.Contains (idx)) + return (Guid) m_guids [idx]; + + if (idx + 16 > this.Data.Length) + throw new IndexOutOfRangeException (); + + byte[] buffer = new byte [16]; + Buffer.BlockCopy (this.Data, idx, buffer, 0, 16); + Guid res = new Guid (buffer); + m_guids [idx] = res; + return res; + } + set { m_guids [index] = value; } + } + + public override void Accept (IMetadataVisitor visitor) + { + visitor.VisitGuidHeap (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataRow.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataRow.cs new file mode 100644 index 0000000..012d5bf --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataRow.cs @@ -0,0 +1,33 @@ +// +// IMetadataRow.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public interface IMetadataRow : IMetadataRowVisitable { + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataTable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataTable.cs new file mode 100644 index 0000000..2fdf849 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataTable.cs @@ -0,0 +1,35 @@ +// +// IMetadataTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public interface IMetadataTable : IMetadataTableVisitable { + int Id { get; } + RowCollection Rows { get; set; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitable.cs new file mode 100644 index 0000000..09ce018 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitable.cs @@ -0,0 +1,42 @@ +// +// IMetadataVisitable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public interface IMetadataVisitable { + void Accept (IMetadataVisitor visitor); + } + + public interface IMetadataTableVisitable { + void Accept (IMetadataTableVisitor visitor); + } + + public interface IMetadataRowVisitable { + void Accept (IMetadataRowVisitor visitor); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitor.cs new file mode 100644 index 0000000..3bbea3a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/IMetadataVisitor.cs @@ -0,0 +1,149 @@ +// +// IMetadataVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public interface IMetadataVisitor { + void VisitMetadataRoot (MetadataRoot root); + void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header); + void VisitMetadataStreamCollection (MetadataStreamCollection streams); + void VisitMetadataStream (MetadataStream stream); + void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header); + void VisitGuidHeap (GuidHeap heap); + void VisitStringsHeap (StringsHeap heap); + void VisitTablesHeap (TablesHeap heap); + void VisitBlobHeap (BlobHeap heap); + void VisitUserStringsHeap (UserStringsHeap heap); + + void TerminateMetadataRoot (MetadataRoot root); + } + + public interface IMetadataTableVisitor { + void VisitTableCollection (TableCollection coll); + + void VisitAssemblyTable (AssemblyTable table); + void VisitAssemblyOSTable (AssemblyOSTable table); + void VisitAssemblyProcessorTable (AssemblyProcessorTable table); + void VisitAssemblyRefTable (AssemblyRefTable table); + void VisitAssemblyRefOSTable (AssemblyRefOSTable table); + void VisitAssemblyRefProcessorTable (AssemblyRefProcessorTable table); + void VisitClassLayoutTable (ClassLayoutTable table); + void VisitConstantTable (ConstantTable table); + void VisitCustomAttributeTable (CustomAttributeTable table); + void VisitDeclSecurityTable (DeclSecurityTable table); + void VisitEventTable (EventTable table); + void VisitEventMapTable (EventMapTable table); + void VisitEventPtrTable (EventPtrTable table); + void VisitExportedTypeTable (ExportedTypeTable table); + void VisitFieldTable (FieldTable table); + void VisitFieldLayoutTable (FieldLayoutTable table); + void VisitFieldMarshalTable (FieldMarshalTable table); + void VisitFieldPtrTable (FieldPtrTable table); + void VisitFieldRVATable (FieldRVATable table); + void VisitFileTable (FileTable table); + void VisitGenericParamTable (GenericParamTable table); + void VisitGenericParamConstraintTable (GenericParamConstraintTable table); + void VisitImplMapTable (ImplMapTable table); + void VisitInterfaceImplTable (InterfaceImplTable table); + void VisitManifestResourceTable (ManifestResourceTable table); + void VisitMemberRefTable (MemberRefTable table); + void VisitMethodTable (MethodTable table); + void VisitMethodImplTable (MethodImplTable table); + void VisitMethodPtrTable (MethodPtrTable table); + void VisitMethodSemanticsTable (MethodSemanticsTable table); + void VisitMethodSpecTable (MethodSpecTable table); + void VisitModuleTable (ModuleTable table); + void VisitModuleRefTable (ModuleRefTable table); + void VisitNestedClassTable (NestedClassTable table); + void VisitParamTable (ParamTable table); + void VisitParamPtrTable (ParamPtrTable table); + void VisitPropertyTable (PropertyTable table); + void VisitPropertyMapTable (PropertyMapTable table); + void VisitPropertyPtrTable (PropertyPtrTable table); + void VisitStandAloneSigTable (StandAloneSigTable table); + void VisitTypeDefTable (TypeDefTable table); + void VisitTypeRefTable (TypeRefTable table); + void VisitTypeSpecTable (TypeSpecTable table); + + void TerminateTableCollection (TableCollection coll); + IMetadataRowVisitor GetRowVisitor(); +} + + public interface IMetadataRowVisitor { + void VisitRowCollection (RowCollection coll); + + void VisitAssemblyRow (AssemblyRow row); + void VisitAssemblyOSRow (AssemblyOSRow row); + void VisitAssemblyProcessorRow (AssemblyProcessorRow row); + void VisitAssemblyRefRow (AssemblyRefRow row); + void VisitAssemblyRefOSRow (AssemblyRefOSRow row); + void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row); + void VisitClassLayoutRow (ClassLayoutRow row); + void VisitConstantRow (ConstantRow row); + void VisitCustomAttributeRow (CustomAttributeRow row); + void VisitDeclSecurityRow (DeclSecurityRow row); + void VisitEventRow (EventRow row); + void VisitEventMapRow (EventMapRow row); + void VisitEventPtrRow (EventPtrRow row); + void VisitExportedTypeRow (ExportedTypeRow row); + void VisitFieldRow (FieldRow row); + void VisitFieldLayoutRow (FieldLayoutRow row); + void VisitFieldMarshalRow (FieldMarshalRow row); + void VisitFieldPtrRow (FieldPtrRow row); + void VisitFieldRVARow (FieldRVARow row); + void VisitFileRow (FileRow row); + void VisitGenericParamRow (GenericParamRow row); + void VisitGenericParamConstraintRow (GenericParamConstraintRow row); + void VisitImplMapRow (ImplMapRow row); + void VisitInterfaceImplRow (InterfaceImplRow row); + void VisitManifestResourceRow (ManifestResourceRow row); + void VisitMemberRefRow (MemberRefRow row); + void VisitMethodRow (MethodRow row); + void VisitMethodImplRow (MethodImplRow row); + void VisitMethodPtrRow (MethodPtrRow row); + void VisitMethodSemanticsRow (MethodSemanticsRow row); + void VisitMethodSpecRow (MethodSpecRow row); + void VisitModuleRow (ModuleRow row); + void VisitModuleRefRow (ModuleRefRow row); + void VisitNestedClassRow (NestedClassRow row); + void VisitParamRow (ParamRow row); + void VisitParamPtrRow (ParamPtrRow row); + void VisitPropertyRow (PropertyRow row); + void VisitPropertyMapRow (PropertyMapRow row); + void VisitPropertyPtrRow (PropertyPtrRow row); + void VisitStandAloneSigRow (StandAloneSigRow row); + void VisitTypeDefRow (TypeDefRow row); + void VisitTypeRefRow (TypeRefRow row); + void VisitTypeSpecRow (TypeSpecRow row); + + void TerminateRowCollection (RowCollection coll); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ImplMap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ImplMap.cs new file mode 100644 index 0000000..3548312 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ImplMap.cs @@ -0,0 +1,83 @@ +// +// ImplMapTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class ImplMapTable : IMetadataTable { + + public const int RId = 0x1c; + + RowCollection m_rows; + + public ImplMapRow this [int index] { + get { return m_rows [index] as ImplMapRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ImplMapTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitImplMapTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ImplMapRow : IMetadataRow { + + public PInvokeAttributes MappingFlags; + public MetadataToken MemberForwarded; + public uint ImportName; + public uint ImportScope; + + internal ImplMapRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitImplMapRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/InterfaceImpl.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/InterfaceImpl.cs new file mode 100644 index 0000000..fc527c5 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/InterfaceImpl.cs @@ -0,0 +1,79 @@ +// +// InterfaceImplTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class InterfaceImplTable : IMetadataTable { + + public const int RId = 0x09; + + RowCollection m_rows; + + public InterfaceImplRow this [int index] { + get { return m_rows [index] as InterfaceImplRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal InterfaceImplTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitInterfaceImplTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class InterfaceImplRow : IMetadataRow { + + public uint Class; + public MetadataToken Interface; + + internal InterfaceImplRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitInterfaceImplRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ManifestResource.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ManifestResource.cs new file mode 100644 index 0000000..07caf51 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ManifestResource.cs @@ -0,0 +1,83 @@ +// +// ManifestResourceTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class ManifestResourceTable : IMetadataTable { + + public const int RId = 0x28; + + RowCollection m_rows; + + public ManifestResourceRow this [int index] { + get { return m_rows [index] as ManifestResourceRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ManifestResourceTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitManifestResourceTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ManifestResourceRow : IMetadataRow { + + public uint Offset; + public ManifestResourceAttributes Flags; + public uint Name; + public MetadataToken Implementation; + + internal ManifestResourceRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitManifestResourceRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MemberRef.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MemberRef.cs new file mode 100644 index 0000000..7a51aaa --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MemberRef.cs @@ -0,0 +1,80 @@ +// +// MemberRefTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class MemberRefTable : IMetadataTable { + + public const int RId = 0x0a; + + RowCollection m_rows; + + public MemberRefRow this [int index] { + get { return m_rows [index] as MemberRefRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal MemberRefTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitMemberRefTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class MemberRefRow : IMetadataRow { + + public MetadataToken Class; + public uint Name; + public uint Signature; + + internal MemberRefRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitMemberRefRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataFormatException.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataFormatException.cs new file mode 100644 index 0000000..dd91790 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataFormatException.cs @@ -0,0 +1,55 @@ +// +// MetadataFormatException.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + + using Mono.Cecil.Binary; + + public class MetadataFormatException : ImageFormatException { + + internal MetadataFormatException () : base () + { + } + + internal MetadataFormatException (string message) : base (message) + { + } + + internal MetadataFormatException (string message, params string [] parameters) : + base (string.Format (message, parameters)) + { + } + + internal MetadataFormatException (string message, Exception inner) : + base (message, inner) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataHeap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataHeap.cs new file mode 100644 index 0000000..7ce2d28 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataHeap.cs @@ -0,0 +1,92 @@ +// +// MetadataHeap.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + + using Mono.Cecil; + + public abstract class MetadataHeap : IMetadataVisitable { + + MetadataStream m_stream; + string m_name; + byte [] m_data; + + public string Name { + get { return m_name; } + } + + public byte [] Data { + get { return m_data; } + set { m_data = value; } + } + + public int IndexSize; + + internal MetadataHeap (MetadataStream stream, string name) + { + m_name = name; + m_stream = stream; + } + + public static MetadataHeap HeapFactory (MetadataStream stream) + { + switch (stream.Header.Name) { + case MetadataStream.Tables : + case MetadataStream.IncrementalTables : + return new TablesHeap (stream); + case MetadataStream.GUID : + return new GuidHeap (stream); + case MetadataStream.Strings : + return new StringsHeap (stream); + case MetadataStream.UserStrings : + return new UserStringsHeap (stream); + case MetadataStream.Blob : + return new BlobHeap (stream); + default : + return null; + } + } + + public MetadataStream GetStream () + { + return m_stream; + } + + protected virtual byte [] ReadBytesFromStream (uint pos) + { + int start, length = Utilities.ReadCompressedInteger (m_data, (int) pos, out start); + byte [] buffer = new byte [length]; + Buffer.BlockCopy (m_data, start, buffer, 0, length); + return buffer; + } + + public abstract void Accept (IMetadataVisitor visitor); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataInitializer.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataInitializer.cs new file mode 100644 index 0000000..3087d9d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataInitializer.cs @@ -0,0 +1,77 @@ +// +// MetadataInitializer.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.IO; + using System.Text; + + using Mono.Cecil; + using Mono.Cecil.Binary; + + class MetadataInitializer : BaseMetadataVisitor { + + MetadataRoot m_root; + + public MetadataInitializer (ImageInitializer init) + { + m_root = init.Image.MetadataRoot; + } + + public override void VisitMetadataRoot (MetadataRoot root) + { + root.Header = new MetadataRoot.MetadataRootHeader (); + root.Streams = new MetadataStreamCollection (); + } + + public override void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header) + { + header.SetDefaultValues (); + } + + public override void VisitMetadataStreamCollection (MetadataStreamCollection coll) + { + MetadataStream tables = new MetadataStream (); + tables.Header.Name = MetadataStream.Tables; + tables.Heap = MetadataHeap.HeapFactory (tables); + TablesHeap th = tables.Heap as TablesHeap; + th.Tables = new TableCollection (th); + m_root.Streams.Add (tables); + } + + public override void VisitTablesHeap (TablesHeap th) + { + th.Reserved = 0; + th.MajorVersion = 1; + th.MinorVersion = 0; + th.Reserved2 = 1; + th.Sorted = 0x2003301fa00; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataReader.cs new file mode 100644 index 0000000..a32c2e2 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataReader.cs @@ -0,0 +1,229 @@ +// +// MetadataReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.IO; + using System.Text; + + using Mono.Cecil.Binary; + + class MetadataReader : BaseMetadataVisitor { + + ImageReader m_ir; + BinaryReader m_binaryReader; + MetadataTableReader m_tableReader; + MetadataRoot m_root; + + public MetadataTableReader TableReader { + get { return m_tableReader; } + } + + public MetadataReader (ImageReader brv) + { + m_ir = brv; + m_binaryReader = brv.GetReader (); + } + + public MetadataRoot GetMetadataRoot () + { + return m_root; + } + + public BinaryReader GetDataReader (RVA rva) + { + return m_ir.Image.GetReaderAtVirtualAddress (rva); + } + + public override void VisitMetadataRoot (MetadataRoot root) + { + m_root = root; + root.Header = new MetadataRoot.MetadataRootHeader (); + root.Streams = new MetadataStreamCollection (); + } + + public override void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header) + { + long headpos = m_binaryReader.BaseStream.Position; + + header.Signature = m_binaryReader.ReadUInt32 (); + + if (header.Signature != MetadataRoot.MetadataRootHeader.StandardSignature) + throw new MetadataFormatException ("Wrong magic number"); + + header.MajorVersion = m_binaryReader.ReadUInt16 (); + header.MinorVersion = m_binaryReader.ReadUInt16 (); + header.Reserved = m_binaryReader.ReadUInt32 (); + + // read version + uint length = m_binaryReader.ReadUInt32 (); + if (length != 0) { + long pos = m_binaryReader.BaseStream.Position; + + byte [] version, buffer = new byte [length]; + int read = 0; + while (read < length) { + byte cur = (byte)m_binaryReader.ReadSByte (); + if (cur == 0) + break; + buffer [read++] = cur; + } + version = new byte [read]; + Buffer.BlockCopy (buffer, 0, version, 0, read); + header.Version = Encoding.UTF8.GetString (version, 0, version.Length); + + pos += length - headpos + 3; + pos &= ~3; + pos += headpos; + + m_binaryReader.BaseStream.Position = pos; + } else + header.Version = string.Empty; + + header.Flags = m_binaryReader.ReadUInt16 (); + header.Streams = m_binaryReader.ReadUInt16 (); + } + + public override void VisitMetadataStreamCollection (MetadataStreamCollection coll) + { + for (int i = 0; i < m_root.Header.Streams; i++) + coll.Add (new MetadataStream ()); + } + + public override void VisitMetadataStreamHeader (MetadataStream.MetadataStreamHeader header) + { + header.Offset = m_binaryReader.ReadUInt32 (); + header.Size = m_binaryReader.ReadUInt32 (); + + StringBuilder buffer = new StringBuilder (); + while (true) { + char cur = (char) m_binaryReader.ReadSByte (); + if (cur == '\0') + break; + buffer.Append (cur); + } + header.Name = buffer.ToString (); + if (header.Name.Length == 0) + throw new MetadataFormatException ("Invalid stream name"); + + long rootpos = m_root.GetImage ().ResolveVirtualAddress ( + m_root.GetImage ().CLIHeader.Metadata.VirtualAddress); + + long curpos = m_binaryReader.BaseStream.Position; + + if (header.Size != 0) + curpos -= rootpos; + + curpos += 3; + curpos &= ~3; + + if (header.Size != 0) + curpos += rootpos; + + m_binaryReader.BaseStream.Position = curpos; + + header.Stream.Heap = MetadataHeap.HeapFactory (header.Stream); + } + + public override void VisitGuidHeap (GuidHeap heap) + { + VisitHeap (heap); + } + + public override void VisitStringsHeap (StringsHeap heap) + { + VisitHeap (heap); + + if (heap.Data.Length < 1 && heap.Data [0] != 0) + throw new MetadataFormatException ("Malformed #Strings heap"); + + heap [(uint) 0] = string.Empty; + } + + public override void VisitTablesHeap (TablesHeap heap) + { + VisitHeap (heap); + heap.Tables = new TableCollection (heap); + + BinaryReader br = new BinaryReader (new MemoryStream (heap.Data)); + try { + heap.Reserved = br.ReadUInt32 (); + heap.MajorVersion = br.ReadByte (); + heap.MinorVersion = br.ReadByte (); + heap.HeapSizes = br.ReadByte (); + heap.Reserved2 = br.ReadByte (); + heap.Valid = br.ReadInt64 (); + heap.Sorted = br.ReadInt64 (); + } finally { + // COMPACT FRAMEWORK NOTE: BinaryReader is not IDisposable + br.Close (); + } + } + + public override void VisitBlobHeap (BlobHeap heap) + { + VisitHeap (heap); + } + + public override void VisitUserStringsHeap (UserStringsHeap heap) + { + VisitHeap (heap); + } + + void VisitHeap (MetadataHeap heap) + { + long cursor = m_binaryReader.BaseStream.Position; + + m_binaryReader.BaseStream.Position = m_root.GetImage ().ResolveVirtualAddress ( + m_root.GetImage ().CLIHeader.Metadata.VirtualAddress) + + heap.GetStream ().Header.Offset; + + heap.Data = m_binaryReader.ReadBytes ((int) heap.GetStream ().Header.Size); + + m_binaryReader.BaseStream.Position = cursor; + } + + void SetHeapIndexSize (MetadataHeap heap, byte flag) + { + if (heap == null) + return; + TablesHeap th = m_root.Streams.TablesHeap; + heap.IndexSize = ((th.HeapSizes & flag) > 0) ? 4 : 2; + } + + public override void TerminateMetadataRoot (MetadataRoot root) + { + SetHeapIndexSize (root.Streams.StringsHeap, 0x01); + SetHeapIndexSize (root.Streams.GuidHeap, 0x02); + SetHeapIndexSize (root.Streams.BlobHeap, 0x04); + m_tableReader = new MetadataTableReader (this); + root.Streams.TablesHeap.Tables.Accept (m_tableReader); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRoot.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRoot.cs new file mode 100644 index 0000000..9305149 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRoot.cs @@ -0,0 +1,99 @@ +// +// MetadataRoot.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil.Binary; + + public sealed class MetadataRoot : IMetadataVisitable { + + MetadataRootHeader m_header; + Image m_image; + + MetadataStreamCollection m_streams; + + public MetadataRootHeader Header { + get { return m_header; } + set { m_header = value; } + } + + public MetadataStreamCollection Streams { + get { return m_streams; } + set { m_streams = value; } + } + + internal MetadataRoot (Image img) + { + m_image = img; + } + + public Image GetImage () + { + return m_image; + } + + public void Accept (IMetadataVisitor visitor) + { + visitor.VisitMetadataRoot (this); + + m_header.Accept (visitor); + m_streams.Accept (visitor); + + visitor.TerminateMetadataRoot (this); + } + + public sealed class MetadataRootHeader : IHeader, IMetadataVisitable { + + public const uint StandardSignature = 0x424a5342; + + public uint Signature; + public ushort MinorVersion; + public ushort MajorVersion; + public uint Reserved; + public string Version; + public ushort Flags; + public ushort Streams; + + internal MetadataRootHeader () + { + } + + public void SetDefaultValues () + { + Signature = StandardSignature; + Reserved = 0; + Flags = 0; + } + + public void Accept (IMetadataVisitor visitor) + { + visitor.VisitMetadataRootHeader (this); + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRowReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRowReader.cs new file mode 100644 index 0000000..a071b3c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRowReader.cs @@ -0,0 +1,367 @@ +// +// MetadataRowReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Jul 17 00:22:32 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + using System.IO; + + using Mono.Cecil.Binary; + + class MetadataRowReader : BaseMetadataRowVisitor { + + MetadataTableReader m_mtrv; + BinaryReader m_binaryReader; + MetadataRoot m_metadataRoot; + IDictionary m_ciCache; + + int m_blobHeapIdxSz; + int m_stringsHeapIdxSz; + int m_guidHeapIdxSz; + + public MetadataRowReader (MetadataTableReader mtrv) + { + m_mtrv = mtrv; + m_binaryReader = mtrv.GetReader (); + m_metadataRoot = mtrv.GetMetadataRoot (); + m_ciCache = new Hashtable (); + } + + int GetIndexSize (int rid) + { + return m_mtrv.GetNumberOfRows (rid) < (1 << 16) ? 2 : 4; + } + + int GetCodedIndexSize (CodedIndex ci) + { + return Utilities.GetCodedIndexSize (ci, + new Utilities.TableRowCounter (m_mtrv.GetNumberOfRows), m_ciCache); + } + + uint ReadByIndexSize (int size) + { + if (size == 2) { + return (uint) m_binaryReader.ReadUInt16 (); + } else if (size == 4) { + return m_binaryReader.ReadUInt32 (); + } else { + throw new MetadataFormatException ("Non valid size for indexing"); + } + } + + public override void VisitRowCollection (RowCollection coll) + { + m_blobHeapIdxSz = m_metadataRoot.Streams.BlobHeap != null ? + m_metadataRoot.Streams.BlobHeap.IndexSize : 2; + m_stringsHeapIdxSz = m_metadataRoot.Streams.StringsHeap != null ? + m_metadataRoot.Streams.StringsHeap.IndexSize : 2; + m_guidHeapIdxSz = m_metadataRoot.Streams.GuidHeap != null ? + m_metadataRoot.Streams.GuidHeap.IndexSize : 2; + } + + public override void VisitAssemblyRow (AssemblyRow row) + { + row.HashAlgId = (Mono.Cecil.AssemblyHashAlgorithm) m_binaryReader.ReadUInt32 (); + row.MajorVersion = m_binaryReader.ReadUInt16 (); + row.MinorVersion = m_binaryReader.ReadUInt16 (); + row.BuildNumber = m_binaryReader.ReadUInt16 (); + row.RevisionNumber = m_binaryReader.ReadUInt16 (); + row.Flags = (Mono.Cecil.AssemblyFlags) m_binaryReader.ReadUInt32 (); + row.PublicKey = ReadByIndexSize (m_blobHeapIdxSz); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Culture = ReadByIndexSize (m_stringsHeapIdxSz); + } + public override void VisitAssemblyOSRow (AssemblyOSRow row) + { + row.OSPlatformID = m_binaryReader.ReadUInt32 (); + row.OSMajorVersion = m_binaryReader.ReadUInt32 (); + row.OSMinorVersion = m_binaryReader.ReadUInt32 (); + } + public override void VisitAssemblyProcessorRow (AssemblyProcessorRow row) + { + row.Processor = m_binaryReader.ReadUInt32 (); + } + public override void VisitAssemblyRefRow (AssemblyRefRow row) + { + row.MajorVersion = m_binaryReader.ReadUInt16 (); + row.MinorVersion = m_binaryReader.ReadUInt16 (); + row.BuildNumber = m_binaryReader.ReadUInt16 (); + row.RevisionNumber = m_binaryReader.ReadUInt16 (); + row.Flags = (Mono.Cecil.AssemblyFlags) m_binaryReader.ReadUInt32 (); + row.PublicKeyOrToken = ReadByIndexSize (m_blobHeapIdxSz); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Culture = ReadByIndexSize (m_stringsHeapIdxSz); + row.HashValue = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitAssemblyRefOSRow (AssemblyRefOSRow row) + { + row.OSPlatformID = m_binaryReader.ReadUInt32 (); + row.OSMajorVersion = m_binaryReader.ReadUInt32 (); + row.OSMinorVersion = m_binaryReader.ReadUInt32 (); + row.AssemblyRef = ReadByIndexSize (GetIndexSize (AssemblyRefTable.RId)); + } + public override void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row) + { + row.Processor = m_binaryReader.ReadUInt32 (); + row.AssemblyRef = ReadByIndexSize (GetIndexSize (AssemblyRefTable.RId)); + } + public override void VisitClassLayoutRow (ClassLayoutRow row) + { + row.PackingSize = m_binaryReader.ReadUInt16 (); + row.ClassSize = m_binaryReader.ReadUInt32 (); + row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId)); + } + public override void VisitConstantRow (ConstantRow row) + { + row.Type = (Mono.Cecil.Metadata.ElementType) m_binaryReader.ReadUInt16 (); + row.Parent = Utilities.GetMetadataToken (CodedIndex.HasConstant, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasConstant))); + row.Value = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitCustomAttributeRow (CustomAttributeRow row) + { + row.Parent = Utilities.GetMetadataToken (CodedIndex.HasCustomAttribute, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasCustomAttribute))); + row.Type = Utilities.GetMetadataToken (CodedIndex.CustomAttributeType, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.CustomAttributeType))); + row.Value = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitDeclSecurityRow (DeclSecurityRow row) + { + row.Action = (Mono.Cecil.SecurityAction) m_binaryReader.ReadInt16 (); + row.Parent = Utilities.GetMetadataToken (CodedIndex.HasDeclSecurity, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasDeclSecurity))); + row.PermissionSet = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitEventRow (EventRow row) + { + row.EventFlags = (Mono.Cecil.EventAttributes) m_binaryReader.ReadUInt16 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.EventType = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef))); + } + public override void VisitEventMapRow (EventMapRow row) + { + row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId)); + row.EventList = ReadByIndexSize (GetIndexSize (EventTable.RId)); + } + public override void VisitEventPtrRow (EventPtrRow row) + { + row.Event = ReadByIndexSize (GetIndexSize (EventTable.RId)); + } + public override void VisitExportedTypeRow (ExportedTypeRow row) + { + row.Flags = (Mono.Cecil.TypeAttributes) m_binaryReader.ReadUInt32 (); + row.TypeDefId = m_binaryReader.ReadUInt32 (); + row.TypeName = ReadByIndexSize (m_stringsHeapIdxSz); + row.TypeNamespace = ReadByIndexSize (m_stringsHeapIdxSz); + row.Implementation = Utilities.GetMetadataToken (CodedIndex.Implementation, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.Implementation))); + } + public override void VisitFieldRow (FieldRow row) + { + row.Flags = (Mono.Cecil.FieldAttributes) m_binaryReader.ReadUInt16 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Signature = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitFieldLayoutRow (FieldLayoutRow row) + { + row.Offset = m_binaryReader.ReadUInt32 (); + row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId)); + } + public override void VisitFieldMarshalRow (FieldMarshalRow row) + { + row.Parent = Utilities.GetMetadataToken (CodedIndex.HasFieldMarshal, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasFieldMarshal))); + row.NativeType = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitFieldPtrRow (FieldPtrRow row) + { + row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId)); + } + public override void VisitFieldRVARow (FieldRVARow row) + { + row.RVA = new RVA (m_binaryReader.ReadUInt32 ()); + row.Field = ReadByIndexSize (GetIndexSize (FieldTable.RId)); + } + public override void VisitFileRow (FileRow row) + { + row.Flags = (Mono.Cecil.FileAttributes) m_binaryReader.ReadUInt32 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.HashValue = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitGenericParamRow (GenericParamRow row) + { + row.Number = m_binaryReader.ReadUInt16 (); + row.Flags = (Mono.Cecil.GenericParameterAttributes) m_binaryReader.ReadUInt16 (); + row.Owner = Utilities.GetMetadataToken (CodedIndex.TypeOrMethodDef, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeOrMethodDef))); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + } + public override void VisitGenericParamConstraintRow (GenericParamConstraintRow row) + { + row.Owner = ReadByIndexSize (GetIndexSize (GenericParamTable.RId)); + row.Constraint = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef))); + } + public override void VisitImplMapRow (ImplMapRow row) + { + row.MappingFlags = (Mono.Cecil.PInvokeAttributes) m_binaryReader.ReadUInt16 (); + row.MemberForwarded = Utilities.GetMetadataToken (CodedIndex.MemberForwarded, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.MemberForwarded))); + row.ImportName = ReadByIndexSize (m_stringsHeapIdxSz); + row.ImportScope = ReadByIndexSize (GetIndexSize (ModuleRefTable.RId)); + } + public override void VisitInterfaceImplRow (InterfaceImplRow row) + { + row.Class = ReadByIndexSize (GetIndexSize (TypeDefTable.RId)); + row.Interface = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef))); + } + public override void VisitManifestResourceRow (ManifestResourceRow row) + { + row.Offset = m_binaryReader.ReadUInt32 (); + row.Flags = (Mono.Cecil.ManifestResourceAttributes) m_binaryReader.ReadUInt32 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Implementation = Utilities.GetMetadataToken (CodedIndex.Implementation, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.Implementation))); + } + public override void VisitMemberRefRow (MemberRefRow row) + { + row.Class = Utilities.GetMetadataToken (CodedIndex.MemberRefParent, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.MemberRefParent))); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Signature = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitMethodRow (MethodRow row) + { + row.RVA = new RVA (m_binaryReader.ReadUInt32 ()); + row.ImplFlags = (Mono.Cecil.MethodImplAttributes) m_binaryReader.ReadUInt16 (); + row.Flags = (Mono.Cecil.MethodAttributes) m_binaryReader.ReadUInt16 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Signature = ReadByIndexSize (m_blobHeapIdxSz); + row.ParamList = ReadByIndexSize (GetIndexSize (ParamTable.RId)); + } + public override void VisitMethodImplRow (MethodImplRow row) + { + row.Class = ReadByIndexSize (GetIndexSize (TypeDefTable.RId)); + row.MethodBody = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef))); + row.MethodDeclaration = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef))); + } + public override void VisitMethodPtrRow (MethodPtrRow row) + { + row.Method = ReadByIndexSize (GetIndexSize (MethodTable.RId)); + } + public override void VisitMethodSemanticsRow (MethodSemanticsRow row) + { + row.Semantics = (Mono.Cecil.MethodSemanticsAttributes) m_binaryReader.ReadUInt16 (); + row.Method = ReadByIndexSize (GetIndexSize (MethodTable.RId)); + row.Association = Utilities.GetMetadataToken (CodedIndex.HasSemantics, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.HasSemantics))); + } + public override void VisitMethodSpecRow (MethodSpecRow row) + { + row.Method = Utilities.GetMetadataToken (CodedIndex.MethodDefOrRef, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.MethodDefOrRef))); + row.Instantiation = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitModuleRow (ModuleRow row) + { + row.Generation = m_binaryReader.ReadUInt16 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Mvid = ReadByIndexSize (m_guidHeapIdxSz); + row.EncId = ReadByIndexSize (m_guidHeapIdxSz); + row.EncBaseId = ReadByIndexSize (m_guidHeapIdxSz); + } + public override void VisitModuleRefRow (ModuleRefRow row) + { + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + } + public override void VisitNestedClassRow (NestedClassRow row) + { + row.NestedClass = ReadByIndexSize (GetIndexSize (TypeDefTable.RId)); + row.EnclosingClass = ReadByIndexSize (GetIndexSize (TypeDefTable.RId)); + } + public override void VisitParamRow (ParamRow row) + { + row.Flags = (Mono.Cecil.ParameterAttributes) m_binaryReader.ReadUInt16 (); + row.Sequence = m_binaryReader.ReadUInt16 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + } + public override void VisitParamPtrRow (ParamPtrRow row) + { + row.Param = ReadByIndexSize (GetIndexSize (ParamTable.RId)); + } + public override void VisitPropertyRow (PropertyRow row) + { + row.Flags = (Mono.Cecil.PropertyAttributes) m_binaryReader.ReadUInt16 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Type = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitPropertyMapRow (PropertyMapRow row) + { + row.Parent = ReadByIndexSize (GetIndexSize (TypeDefTable.RId)); + row.PropertyList = ReadByIndexSize (GetIndexSize (PropertyTable.RId)); + } + public override void VisitPropertyPtrRow (PropertyPtrRow row) + { + row.Property = ReadByIndexSize (GetIndexSize (PropertyTable.RId)); + } + public override void VisitStandAloneSigRow (StandAloneSigRow row) + { + row.Signature = ReadByIndexSize (m_blobHeapIdxSz); + } + public override void VisitTypeDefRow (TypeDefRow row) + { + row.Flags = (Mono.Cecil.TypeAttributes) m_binaryReader.ReadUInt32 (); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Namespace = ReadByIndexSize (m_stringsHeapIdxSz); + row.Extends = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.TypeDefOrRef))); + row.FieldList = ReadByIndexSize (GetIndexSize (FieldTable.RId)); + row.MethodList = ReadByIndexSize (GetIndexSize (MethodTable.RId)); + } + public override void VisitTypeRefRow (TypeRefRow row) + { + row.ResolutionScope = Utilities.GetMetadataToken (CodedIndex.ResolutionScope, + ReadByIndexSize (GetCodedIndexSize (CodedIndex.ResolutionScope))); + row.Name = ReadByIndexSize (m_stringsHeapIdxSz); + row.Namespace = ReadByIndexSize (m_stringsHeapIdxSz); + } + public override void VisitTypeSpecRow (TypeSpecRow row) + { + row.Signature = ReadByIndexSize (m_blobHeapIdxSz); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRowWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRowWriter.cs new file mode 100644 index 0000000..baddfc0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataRowWriter.cs @@ -0,0 +1,796 @@ +// +// MetadataRowWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + using Mono.Cecil.Binary; + + class MetadataRowWriter : BaseMetadataRowVisitor { + + MetadataRoot m_root; + MemoryBinaryWriter m_binaryWriter; + IDictionary m_ciCache; + + int m_blobHeapIdxSz; + int m_stringsHeapIdxSz; + int m_guidHeapIdxSz; + + public MetadataRowWriter (MetadataTableWriter mtwv) + { + m_binaryWriter = mtwv.GetWriter (); + m_root = mtwv.GetMetadataRoot (); + m_ciCache = new Hashtable (); + } + + void WriteBlobPointer (uint pointer) + { + WriteByIndexSize (pointer, m_blobHeapIdxSz); + } + + void WriteStringPointer (uint pointer) + { + WriteByIndexSize (pointer, m_stringsHeapIdxSz); + } + + void WriteGuidPointer (uint pointer) + { + WriteByIndexSize (pointer, m_guidHeapIdxSz); + } + + void WriteTablePointer (uint pointer, int rid) + { + WriteByIndexSize (pointer, GetNumberOfRows (rid) < (1 << 16) ? 2 : 4); + } + + void WriteMetadataToken (MetadataToken token, CodedIndex ci) + { + WriteByIndexSize (Utilities.CompressMetadataToken (ci, token), + Utilities.GetCodedIndexSize ( + ci, new Utilities.TableRowCounter (GetNumberOfRows), m_ciCache)); + } + + int GetNumberOfRows (int rid) + { + IMetadataTable t = m_root.Streams.TablesHeap [rid]; + if (t == null || t.Rows == null) + return 0; + return t.Rows.Count; + } + + void WriteByIndexSize (uint value, int size) + { + if (size == 4) + m_binaryWriter.Write (value); + else if (size == 2) + m_binaryWriter.Write ((ushort) value); + else + throw new MetadataFormatException ("Non valid size for indexing"); + } + + public AssemblyRow CreateAssemblyRow (AssemblyHashAlgorithm _hashAlgId, ushort _majorVersion, ushort _minorVersion, ushort _buildNumber, ushort _revisionNumber, AssemblyFlags _flags, uint _publicKey, uint _name, uint _culture) + { + AssemblyRow row = new AssemblyRow (); + row.HashAlgId = _hashAlgId; + row.MajorVersion = _majorVersion; + row.MinorVersion = _minorVersion; + row.BuildNumber = _buildNumber; + row.RevisionNumber = _revisionNumber; + row.Flags = _flags; + row.PublicKey = _publicKey; + row.Name = _name; + row.Culture = _culture; + return row; + } + + public AssemblyOSRow CreateAssemblyOSRow (uint _oSPlatformID, uint _oSMajorVersion, uint _oSMinorVersion) + { + AssemblyOSRow row = new AssemblyOSRow (); + row.OSPlatformID = _oSPlatformID; + row.OSMajorVersion = _oSMajorVersion; + row.OSMinorVersion = _oSMinorVersion; + return row; + } + + public AssemblyProcessorRow CreateAssemblyProcessorRow (uint _processor) + { + AssemblyProcessorRow row = new AssemblyProcessorRow (); + row.Processor = _processor; + return row; + } + + public AssemblyRefRow CreateAssemblyRefRow (ushort _majorVersion, ushort _minorVersion, ushort _buildNumber, ushort _revisionNumber, AssemblyFlags _flags, uint _publicKeyOrToken, uint _name, uint _culture, uint _hashValue) + { + AssemblyRefRow row = new AssemblyRefRow (); + row.MajorVersion = _majorVersion; + row.MinorVersion = _minorVersion; + row.BuildNumber = _buildNumber; + row.RevisionNumber = _revisionNumber; + row.Flags = _flags; + row.PublicKeyOrToken = _publicKeyOrToken; + row.Name = _name; + row.Culture = _culture; + row.HashValue = _hashValue; + return row; + } + + public AssemblyRefOSRow CreateAssemblyRefOSRow (uint _oSPlatformID, uint _oSMajorVersion, uint _oSMinorVersion, uint _assemblyRef) + { + AssemblyRefOSRow row = new AssemblyRefOSRow (); + row.OSPlatformID = _oSPlatformID; + row.OSMajorVersion = _oSMajorVersion; + row.OSMinorVersion = _oSMinorVersion; + row.AssemblyRef = _assemblyRef; + return row; + } + + public AssemblyRefProcessorRow CreateAssemblyRefProcessorRow (uint _processor, uint _assemblyRef) + { + AssemblyRefProcessorRow row = new AssemblyRefProcessorRow (); + row.Processor = _processor; + row.AssemblyRef = _assemblyRef; + return row; + } + + public ClassLayoutRow CreateClassLayoutRow (ushort _packingSize, uint _classSize, uint _parent) + { + ClassLayoutRow row = new ClassLayoutRow (); + row.PackingSize = _packingSize; + row.ClassSize = _classSize; + row.Parent = _parent; + return row; + } + + public ConstantRow CreateConstantRow (ElementType _type, MetadataToken _parent, uint _value) + { + ConstantRow row = new ConstantRow (); + row.Type = _type; + row.Parent = _parent; + row.Value = _value; + return row; + } + + public CustomAttributeRow CreateCustomAttributeRow (MetadataToken _parent, MetadataToken _type, uint _value) + { + CustomAttributeRow row = new CustomAttributeRow (); + row.Parent = _parent; + row.Type = _type; + row.Value = _value; + return row; + } + + public DeclSecurityRow CreateDeclSecurityRow (SecurityAction _action, MetadataToken _parent, uint _permissionSet) + { + DeclSecurityRow row = new DeclSecurityRow (); + row.Action = _action; + row.Parent = _parent; + row.PermissionSet = _permissionSet; + return row; + } + + public EventRow CreateEventRow (EventAttributes _eventFlags, uint _name, MetadataToken _eventType) + { + EventRow row = new EventRow (); + row.EventFlags = _eventFlags; + row.Name = _name; + row.EventType = _eventType; + return row; + } + + public EventMapRow CreateEventMapRow (uint _parent, uint _eventList) + { + EventMapRow row = new EventMapRow (); + row.Parent = _parent; + row.EventList = _eventList; + return row; + } + + public EventPtrRow CreateEventPtrRow (uint _event) + { + EventPtrRow row = new EventPtrRow (); + row.Event = _event; + return row; + } + + public ExportedTypeRow CreateExportedTypeRow (TypeAttributes _flags, uint _typeDefId, uint _typeName, uint _typeNamespace, MetadataToken _implementation) + { + ExportedTypeRow row = new ExportedTypeRow (); + row.Flags = _flags; + row.TypeDefId = _typeDefId; + row.TypeName = _typeName; + row.TypeNamespace = _typeNamespace; + row.Implementation = _implementation; + return row; + } + + public FieldRow CreateFieldRow (FieldAttributes _flags, uint _name, uint _signature) + { + FieldRow row = new FieldRow (); + row.Flags = _flags; + row.Name = _name; + row.Signature = _signature; + return row; + } + + public FieldLayoutRow CreateFieldLayoutRow (uint _offset, uint _field) + { + FieldLayoutRow row = new FieldLayoutRow (); + row.Offset = _offset; + row.Field = _field; + return row; + } + + public FieldMarshalRow CreateFieldMarshalRow (MetadataToken _parent, uint _nativeType) + { + FieldMarshalRow row = new FieldMarshalRow (); + row.Parent = _parent; + row.NativeType = _nativeType; + return row; + } + + public FieldPtrRow CreateFieldPtrRow (uint _field) + { + FieldPtrRow row = new FieldPtrRow (); + row.Field = _field; + return row; + } + + public FieldRVARow CreateFieldRVARow (RVA _rVA, uint _field) + { + FieldRVARow row = new FieldRVARow (); + row.RVA = _rVA; + row.Field = _field; + return row; + } + + public FileRow CreateFileRow (FileAttributes _flags, uint _name, uint _hashValue) + { + FileRow row = new FileRow (); + row.Flags = _flags; + row.Name = _name; + row.HashValue = _hashValue; + return row; + } + + public GenericParamRow CreateGenericParamRow (ushort _number, GenericParameterAttributes _flags, MetadataToken _owner, uint _name) + { + GenericParamRow row = new GenericParamRow (); + row.Number = _number; + row.Flags = _flags; + row.Owner = _owner; + row.Name = _name; + return row; + } + + public GenericParamConstraintRow CreateGenericParamConstraintRow (uint _owner, MetadataToken _constraint) + { + GenericParamConstraintRow row = new GenericParamConstraintRow (); + row.Owner = _owner; + row.Constraint = _constraint; + return row; + } + + public ImplMapRow CreateImplMapRow (PInvokeAttributes _mappingFlags, MetadataToken _memberForwarded, uint _importName, uint _importScope) + { + ImplMapRow row = new ImplMapRow (); + row.MappingFlags = _mappingFlags; + row.MemberForwarded = _memberForwarded; + row.ImportName = _importName; + row.ImportScope = _importScope; + return row; + } + + public InterfaceImplRow CreateInterfaceImplRow (uint _class, MetadataToken _interface) + { + InterfaceImplRow row = new InterfaceImplRow (); + row.Class = _class; + row.Interface = _interface; + return row; + } + + public ManifestResourceRow CreateManifestResourceRow (uint _offset, ManifestResourceAttributes _flags, uint _name, MetadataToken _implementation) + { + ManifestResourceRow row = new ManifestResourceRow (); + row.Offset = _offset; + row.Flags = _flags; + row.Name = _name; + row.Implementation = _implementation; + return row; + } + + public MemberRefRow CreateMemberRefRow (MetadataToken _class, uint _name, uint _signature) + { + MemberRefRow row = new MemberRefRow (); + row.Class = _class; + row.Name = _name; + row.Signature = _signature; + return row; + } + + public MethodRow CreateMethodRow (RVA _rVA, MethodImplAttributes _implFlags, MethodAttributes _flags, uint _name, uint _signature, uint _paramList) + { + MethodRow row = new MethodRow (); + row.RVA = _rVA; + row.ImplFlags = _implFlags; + row.Flags = _flags; + row.Name = _name; + row.Signature = _signature; + row.ParamList = _paramList; + return row; + } + + public MethodImplRow CreateMethodImplRow (uint _class, MetadataToken _methodBody, MetadataToken _methodDeclaration) + { + MethodImplRow row = new MethodImplRow (); + row.Class = _class; + row.MethodBody = _methodBody; + row.MethodDeclaration = _methodDeclaration; + return row; + } + + public MethodPtrRow CreateMethodPtrRow (uint _method) + { + MethodPtrRow row = new MethodPtrRow (); + row.Method = _method; + return row; + } + + public MethodSemanticsRow CreateMethodSemanticsRow (MethodSemanticsAttributes _semantics, uint _method, MetadataToken _association) + { + MethodSemanticsRow row = new MethodSemanticsRow (); + row.Semantics = _semantics; + row.Method = _method; + row.Association = _association; + return row; + } + + public MethodSpecRow CreateMethodSpecRow (MetadataToken _method, uint _instantiation) + { + MethodSpecRow row = new MethodSpecRow (); + row.Method = _method; + row.Instantiation = _instantiation; + return row; + } + + public ModuleRow CreateModuleRow (ushort _generation, uint _name, uint _mvid, uint _encId, uint _encBaseId) + { + ModuleRow row = new ModuleRow (); + row.Generation = _generation; + row.Name = _name; + row.Mvid = _mvid; + row.EncId = _encId; + row.EncBaseId = _encBaseId; + return row; + } + + public ModuleRefRow CreateModuleRefRow (uint _name) + { + ModuleRefRow row = new ModuleRefRow (); + row.Name = _name; + return row; + } + + public NestedClassRow CreateNestedClassRow (uint _nestedClass, uint _enclosingClass) + { + NestedClassRow row = new NestedClassRow (); + row.NestedClass = _nestedClass; + row.EnclosingClass = _enclosingClass; + return row; + } + + public ParamRow CreateParamRow (ParameterAttributes _flags, ushort _sequence, uint _name) + { + ParamRow row = new ParamRow (); + row.Flags = _flags; + row.Sequence = _sequence; + row.Name = _name; + return row; + } + + public ParamPtrRow CreateParamPtrRow (uint _param) + { + ParamPtrRow row = new ParamPtrRow (); + row.Param = _param; + return row; + } + + public PropertyRow CreatePropertyRow (PropertyAttributes _flags, uint _name, uint _type) + { + PropertyRow row = new PropertyRow (); + row.Flags = _flags; + row.Name = _name; + row.Type = _type; + return row; + } + + public PropertyMapRow CreatePropertyMapRow (uint _parent, uint _propertyList) + { + PropertyMapRow row = new PropertyMapRow (); + row.Parent = _parent; + row.PropertyList = _propertyList; + return row; + } + + public PropertyPtrRow CreatePropertyPtrRow (uint _property) + { + PropertyPtrRow row = new PropertyPtrRow (); + row.Property = _property; + return row; + } + + public StandAloneSigRow CreateStandAloneSigRow (uint _signature) + { + StandAloneSigRow row = new StandAloneSigRow (); + row.Signature = _signature; + return row; + } + + public TypeDefRow CreateTypeDefRow (TypeAttributes _flags, uint _name, uint _namespace, MetadataToken _extends, uint _fieldList, uint _methodList) + { + TypeDefRow row = new TypeDefRow (); + row.Flags = _flags; + row.Name = _name; + row.Namespace = _namespace; + row.Extends = _extends; + row.FieldList = _fieldList; + row.MethodList = _methodList; + return row; + } + + public TypeRefRow CreateTypeRefRow (MetadataToken _resolutionScope, uint _name, uint _namespace) + { + TypeRefRow row = new TypeRefRow (); + row.ResolutionScope = _resolutionScope; + row.Name = _name; + row.Namespace = _namespace; + return row; + } + + public TypeSpecRow CreateTypeSpecRow (uint _signature) + { + TypeSpecRow row = new TypeSpecRow (); + row.Signature = _signature; + return row; + } + + public override void VisitRowCollection (RowCollection coll) + { + m_blobHeapIdxSz = m_root.Streams.BlobHeap != null ? + m_root.Streams.BlobHeap.IndexSize : 2; + m_stringsHeapIdxSz = m_root.Streams.StringsHeap != null ? + m_root.Streams.StringsHeap.IndexSize : 2; + m_guidHeapIdxSz = m_root.Streams.GuidHeap != null ? + m_root.Streams.GuidHeap.IndexSize : 2; + } + + public override void VisitAssemblyRow (AssemblyRow row) + { + m_binaryWriter.Write ((uint) row.HashAlgId); + m_binaryWriter.Write (row.MajorVersion); + m_binaryWriter.Write (row.MinorVersion); + m_binaryWriter.Write (row.BuildNumber); + m_binaryWriter.Write (row.RevisionNumber); + m_binaryWriter.Write ((uint) row.Flags); + WriteBlobPointer (row.PublicKey); + WriteStringPointer (row.Name); + WriteStringPointer (row.Culture); + } + + public override void VisitAssemblyOSRow (AssemblyOSRow row) + { + m_binaryWriter.Write (row.OSPlatformID); + m_binaryWriter.Write (row.OSMajorVersion); + m_binaryWriter.Write (row.OSMinorVersion); + } + + public override void VisitAssemblyProcessorRow (AssemblyProcessorRow row) + { + m_binaryWriter.Write (row.Processor); + } + + public override void VisitAssemblyRefRow (AssemblyRefRow row) + { + m_binaryWriter.Write (row.MajorVersion); + m_binaryWriter.Write (row.MinorVersion); + m_binaryWriter.Write (row.BuildNumber); + m_binaryWriter.Write (row.RevisionNumber); + m_binaryWriter.Write ((uint) row.Flags); + WriteBlobPointer (row.PublicKeyOrToken); + WriteStringPointer (row.Name); + WriteStringPointer (row.Culture); + WriteBlobPointer (row.HashValue); + } + + public override void VisitAssemblyRefOSRow (AssemblyRefOSRow row) + { + m_binaryWriter.Write (row.OSPlatformID); + m_binaryWriter.Write (row.OSMajorVersion); + m_binaryWriter.Write (row.OSMinorVersion); + WriteTablePointer (row.AssemblyRef, AssemblyRefTable.RId); + } + + public override void VisitAssemblyRefProcessorRow (AssemblyRefProcessorRow row) + { + m_binaryWriter.Write (row.Processor); + WriteTablePointer (row.AssemblyRef, AssemblyRefTable.RId); + } + + public override void VisitClassLayoutRow (ClassLayoutRow row) + { + m_binaryWriter.Write (row.PackingSize); + m_binaryWriter.Write (row.ClassSize); + WriteTablePointer (row.Parent, TypeDefTable.RId); + } + + public override void VisitConstantRow (ConstantRow row) + { + m_binaryWriter.Write ((ushort) row.Type); + WriteMetadataToken (row.Parent, CodedIndex.HasConstant); + WriteBlobPointer (row.Value); + } + + public override void VisitCustomAttributeRow (CustomAttributeRow row) + { + WriteMetadataToken (row.Parent, CodedIndex.HasCustomAttribute); + WriteMetadataToken (row.Type, CodedIndex.CustomAttributeType); + WriteBlobPointer (row.Value); + } + + public override void VisitDeclSecurityRow (DeclSecurityRow row) + { + m_binaryWriter.Write ((short) row.Action); + WriteMetadataToken (row.Parent, CodedIndex.HasDeclSecurity); + WriteBlobPointer (row.PermissionSet); + } + + public override void VisitEventRow (EventRow row) + { + m_binaryWriter.Write ((ushort) row.EventFlags); + WriteStringPointer (row.Name); + WriteMetadataToken (row.EventType, CodedIndex.TypeDefOrRef); + } + + public override void VisitEventMapRow (EventMapRow row) + { + WriteTablePointer (row.Parent, TypeDefTable.RId); + WriteTablePointer (row.EventList, EventTable.RId); + } + + public override void VisitEventPtrRow (EventPtrRow row) + { + WriteTablePointer (row.Event, EventTable.RId); + } + + public override void VisitExportedTypeRow (ExportedTypeRow row) + { + m_binaryWriter.Write ((uint) row.Flags); + m_binaryWriter.Write (row.TypeDefId); + WriteStringPointer (row.TypeName); + WriteStringPointer (row.TypeNamespace); + WriteMetadataToken (row.Implementation, CodedIndex.Implementation); + } + + public override void VisitFieldRow (FieldRow row) + { + m_binaryWriter.Write ((ushort) row.Flags); + WriteStringPointer (row.Name); + WriteBlobPointer (row.Signature); + } + + public override void VisitFieldLayoutRow (FieldLayoutRow row) + { + m_binaryWriter.Write (row.Offset); + WriteTablePointer (row.Field, FieldTable.RId); + } + + public override void VisitFieldMarshalRow (FieldMarshalRow row) + { + WriteMetadataToken (row.Parent, CodedIndex.HasFieldMarshal); + WriteBlobPointer (row.NativeType); + } + + public override void VisitFieldPtrRow (FieldPtrRow row) + { + WriteTablePointer (row.Field, FieldTable.RId); + } + + public override void VisitFieldRVARow (FieldRVARow row) + { + m_binaryWriter.Write (row.RVA.Value); + WriteTablePointer (row.Field, FieldTable.RId); + } + + public override void VisitFileRow (FileRow row) + { + m_binaryWriter.Write ((uint) row.Flags); + WriteStringPointer (row.Name); + WriteBlobPointer (row.HashValue); + } + + public override void VisitGenericParamRow (GenericParamRow row) + { + m_binaryWriter.Write (row.Number); + m_binaryWriter.Write ((ushort) row.Flags); + WriteMetadataToken (row.Owner, CodedIndex.TypeOrMethodDef); + WriteStringPointer (row.Name); + } + + public override void VisitGenericParamConstraintRow (GenericParamConstraintRow row) + { + WriteTablePointer (row.Owner, GenericParamTable.RId); + WriteMetadataToken (row.Constraint, CodedIndex.TypeDefOrRef); + } + + public override void VisitImplMapRow (ImplMapRow row) + { + m_binaryWriter.Write ((ushort) row.MappingFlags); + WriteMetadataToken (row.MemberForwarded, CodedIndex.MemberForwarded); + WriteStringPointer (row.ImportName); + WriteTablePointer (row.ImportScope, ModuleRefTable.RId); + } + + public override void VisitInterfaceImplRow (InterfaceImplRow row) + { + WriteTablePointer (row.Class, TypeDefTable.RId); + WriteMetadataToken (row.Interface, CodedIndex.TypeDefOrRef); + } + + public override void VisitManifestResourceRow (ManifestResourceRow row) + { + m_binaryWriter.Write (row.Offset); + m_binaryWriter.Write ((uint) row.Flags); + WriteStringPointer (row.Name); + WriteMetadataToken (row.Implementation, CodedIndex.Implementation); + } + + public override void VisitMemberRefRow (MemberRefRow row) + { + WriteMetadataToken (row.Class, CodedIndex.MemberRefParent); + WriteStringPointer (row.Name); + WriteBlobPointer (row.Signature); + } + + public override void VisitMethodRow (MethodRow row) + { + m_binaryWriter.Write (row.RVA.Value); + m_binaryWriter.Write ((ushort) row.ImplFlags); + m_binaryWriter.Write ((ushort) row.Flags); + WriteStringPointer (row.Name); + WriteBlobPointer (row.Signature); + WriteTablePointer (row.ParamList, ParamTable.RId); + } + + public override void VisitMethodImplRow (MethodImplRow row) + { + WriteTablePointer (row.Class, TypeDefTable.RId); + WriteMetadataToken (row.MethodBody, CodedIndex.MethodDefOrRef); + WriteMetadataToken (row.MethodDeclaration, CodedIndex.MethodDefOrRef); + } + + public override void VisitMethodPtrRow (MethodPtrRow row) + { + WriteTablePointer (row.Method, MethodTable.RId); + } + + public override void VisitMethodSemanticsRow (MethodSemanticsRow row) + { + m_binaryWriter.Write ((ushort) row.Semantics); + WriteTablePointer (row.Method, MethodTable.RId); + WriteMetadataToken (row.Association, CodedIndex.HasSemantics); + } + + public override void VisitMethodSpecRow (MethodSpecRow row) + { + WriteMetadataToken (row.Method, CodedIndex.MethodDefOrRef); + WriteBlobPointer (row.Instantiation); + } + + public override void VisitModuleRow (ModuleRow row) + { + m_binaryWriter.Write (row.Generation); + WriteStringPointer (row.Name); + WriteGuidPointer (row.Mvid); + WriteGuidPointer (row.EncId); + WriteGuidPointer (row.EncBaseId); + } + + public override void VisitModuleRefRow (ModuleRefRow row) + { + WriteStringPointer (row.Name); + } + + public override void VisitNestedClassRow (NestedClassRow row) + { + WriteTablePointer (row.NestedClass, TypeDefTable.RId); + WriteTablePointer (row.EnclosingClass, TypeDefTable.RId); + } + + public override void VisitParamRow (ParamRow row) + { + m_binaryWriter.Write ((ushort) row.Flags); + m_binaryWriter.Write (row.Sequence); + WriteStringPointer (row.Name); + } + + public override void VisitParamPtrRow (ParamPtrRow row) + { + WriteTablePointer (row.Param, ParamTable.RId); + } + + public override void VisitPropertyRow (PropertyRow row) + { + m_binaryWriter.Write ((ushort) row.Flags); + WriteStringPointer (row.Name); + WriteBlobPointer (row.Type); + } + + public override void VisitPropertyMapRow (PropertyMapRow row) + { + WriteTablePointer (row.Parent, TypeDefTable.RId); + WriteTablePointer (row.PropertyList, PropertyTable.RId); + } + + public override void VisitPropertyPtrRow (PropertyPtrRow row) + { + WriteTablePointer (row.Property, PropertyTable.RId); + } + + public override void VisitStandAloneSigRow (StandAloneSigRow row) + { + WriteBlobPointer (row.Signature); + } + + public override void VisitTypeDefRow (TypeDefRow row) + { + m_binaryWriter.Write ((uint) row.Flags); + WriteStringPointer (row.Name); + WriteStringPointer (row.Namespace); + WriteMetadataToken (row.Extends, CodedIndex.TypeDefOrRef); + WriteTablePointer (row.FieldList, FieldTable.RId); + WriteTablePointer (row.MethodList, MethodTable.RId); + } + + public override void VisitTypeRefRow (TypeRefRow row) + { + WriteMetadataToken (row.ResolutionScope, CodedIndex.ResolutionScope); + WriteStringPointer (row.Name); + WriteStringPointer (row.Namespace); + } + + public override void VisitTypeSpecRow (TypeSpecRow row) + { + WriteBlobPointer (row.Signature); + } + + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataStream.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataStream.cs new file mode 100644 index 0000000..96ba0b4 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataStream.cs @@ -0,0 +1,90 @@ +// +// MetadataStream.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public class MetadataStream : IMetadataVisitable { + + public const string Strings = "#Strings"; + public const string Tables = "#~"; + public const string IncrementalTables = "#-"; + public const string Blob = "#Blob"; + public const string GUID = "#GUID"; + public const string UserStrings = "#US"; + + MetadataStreamHeader m_header; + MetadataHeap m_heap; + + public MetadataStreamHeader Header { + get { return m_header; } + set { m_header = value; } + } + + public MetadataHeap Heap { + get { return m_heap; } + set { m_heap = value; } + } + + internal MetadataStream () + { + m_header = new MetadataStreamHeader (this); + } + + public void Accept (IMetadataVisitor visitor) + { + visitor.VisitMetadataStream (this); + + m_header.Accept (visitor); + if (m_heap != null) + m_heap.Accept (visitor); + } + + public class MetadataStreamHeader : IMetadataVisitable { + + public uint Offset; + public uint Size; + public string Name; + + private MetadataStream m_stream; + + public MetadataStream Stream { + get { return m_stream; } + } + + internal MetadataStreamHeader (MetadataStream stream) + { + m_stream = stream; + } + + public void Accept (IMetadataVisitor visitor) + { + visitor.VisitMetadataStreamHeader (this); + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataStreamCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataStreamCollection.cs new file mode 100644 index 0000000..b602f17 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataStreamCollection.cs @@ -0,0 +1,145 @@ +// +// MetadataStreamCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + public class MetadataStreamCollection : ICollection, IMetadataVisitable { + + IList m_items; + + BlobHeap m_blobHeap; + GuidHeap m_guidHeap; + StringsHeap m_stringsHeap; + UserStringsHeap m_usHeap; + TablesHeap m_tablesHeap; + + public MetadataStream this [int index] { + get { return m_items [index] as MetadataStream; } + set { m_items [index] = value; } + } + + public int Count { + get { return m_items.Count; } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + public BlobHeap BlobHeap { + get { + if (m_blobHeap == null) + m_blobHeap = GetHeap (MetadataStream.Blob) as BlobHeap; + return m_blobHeap; + } + } + + public GuidHeap GuidHeap { + get { + if (m_guidHeap == null) + m_guidHeap = GetHeap (MetadataStream.GUID) as GuidHeap; + return m_guidHeap; + } + } + + public StringsHeap StringsHeap { + get { + if (m_stringsHeap == null) + m_stringsHeap = GetHeap (MetadataStream.Strings) as StringsHeap; + return m_stringsHeap; + } + } + + public TablesHeap TablesHeap { + get { + if (m_tablesHeap == null) + m_tablesHeap = GetHeap (MetadataStream.Tables) as TablesHeap; + return m_tablesHeap; + } + } + + public UserStringsHeap UserStringsHeap { + get { + if (m_usHeap == null) + m_usHeap = GetHeap (MetadataStream.UserStrings) as UserStringsHeap; + return m_usHeap; + } + } + + public MetadataStreamCollection () + { + m_items = new ArrayList (5); + } + + private MetadataHeap GetHeap (string name) + { + for (int i = 0; i < m_items.Count; i++) { + MetadataStream stream = m_items [i] as MetadataStream; + if (stream.Heap.Name == name) + return stream.Heap; + } + + return null; + } + + internal void Add (MetadataStream value) + { + m_items.Add (value); + } + + internal void Remove (MetadataStream value) + { + m_items.Remove (value); + } + + public void CopyTo (Array ary, int index) + { + m_items.CopyTo (ary, index); + } + + public IEnumerator GetEnumerator () + { + return m_items.GetEnumerator (); + } + + public void Accept (IMetadataVisitor visitor) + { + visitor.VisitMetadataStreamCollection (this); + + for (int i = 0; i < m_items.Count; i++) + this [i].Accept (visitor); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableReader.cs new file mode 100644 index 0000000..f24362f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableReader.cs @@ -0,0 +1,769 @@ +// +// MetadataTableReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Jul 17 00:22:32 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + using System.IO; + + class MetadataTableReader : BaseMetadataTableVisitor { + + MetadataRoot m_metadataRoot; + TablesHeap m_heap; + MetadataRowReader m_mrrv; + BinaryReader m_binaryReader; + + int [] m_rows = new int [TablesHeap.MaxTableCount]; + + public MetadataTableReader (MetadataReader mrv) + { + m_metadataRoot = mrv.GetMetadataRoot (); + m_heap = m_metadataRoot.Streams.TablesHeap; + m_binaryReader = new BinaryReader (new MemoryStream (m_heap.Data)); + m_binaryReader.BaseStream.Position = 24; + m_mrrv = new MetadataRowReader (this); + } + + public MetadataRoot GetMetadataRoot () + { + return m_metadataRoot; + } + + public BinaryReader GetReader () + { + return m_binaryReader; + } + + public override IMetadataRowVisitor GetRowVisitor () + { + return m_mrrv; + } + + public int GetNumberOfRows (int rid) + { + return m_rows [rid]; + } + + public AssemblyTable GetAssemblyTable () + { + return (AssemblyTable) m_heap [AssemblyTable.RId]; + } + + public AssemblyOSTable GetAssemblyOSTable () + { + return (AssemblyOSTable) m_heap [AssemblyOSTable.RId]; + } + + public AssemblyProcessorTable GetAssemblyProcessorTable () + { + return (AssemblyProcessorTable) m_heap [AssemblyProcessorTable.RId]; + } + + public AssemblyRefTable GetAssemblyRefTable () + { + return (AssemblyRefTable) m_heap [AssemblyRefTable.RId]; + } + + public AssemblyRefOSTable GetAssemblyRefOSTable () + { + return (AssemblyRefOSTable) m_heap [AssemblyRefOSTable.RId]; + } + + public AssemblyRefProcessorTable GetAssemblyRefProcessorTable () + { + return (AssemblyRefProcessorTable) m_heap [AssemblyRefProcessorTable.RId]; + } + + public ClassLayoutTable GetClassLayoutTable () + { + return (ClassLayoutTable) m_heap [ClassLayoutTable.RId]; + } + + public ConstantTable GetConstantTable () + { + return (ConstantTable) m_heap [ConstantTable.RId]; + } + + public CustomAttributeTable GetCustomAttributeTable () + { + return (CustomAttributeTable) m_heap [CustomAttributeTable.RId]; + } + + public DeclSecurityTable GetDeclSecurityTable () + { + return (DeclSecurityTable) m_heap [DeclSecurityTable.RId]; + } + + public EventTable GetEventTable () + { + return (EventTable) m_heap [EventTable.RId]; + } + + public EventMapTable GetEventMapTable () + { + return (EventMapTable) m_heap [EventMapTable.RId]; + } + + public EventPtrTable GetEventPtrTable () + { + return (EventPtrTable) m_heap [EventPtrTable.RId]; + } + + public ExportedTypeTable GetExportedTypeTable () + { + return (ExportedTypeTable) m_heap [ExportedTypeTable.RId]; + } + + public FieldTable GetFieldTable () + { + return (FieldTable) m_heap [FieldTable.RId]; + } + + public FieldLayoutTable GetFieldLayoutTable () + { + return (FieldLayoutTable) m_heap [FieldLayoutTable.RId]; + } + + public FieldMarshalTable GetFieldMarshalTable () + { + return (FieldMarshalTable) m_heap [FieldMarshalTable.RId]; + } + + public FieldPtrTable GetFieldPtrTable () + { + return (FieldPtrTable) m_heap [FieldPtrTable.RId]; + } + + public FieldRVATable GetFieldRVATable () + { + return (FieldRVATable) m_heap [FieldRVATable.RId]; + } + + public FileTable GetFileTable () + { + return (FileTable) m_heap [FileTable.RId]; + } + + public GenericParamTable GetGenericParamTable () + { + return (GenericParamTable) m_heap [GenericParamTable.RId]; + } + + public GenericParamConstraintTable GetGenericParamConstraintTable () + { + return (GenericParamConstraintTable) m_heap [GenericParamConstraintTable.RId]; + } + + public ImplMapTable GetImplMapTable () + { + return (ImplMapTable) m_heap [ImplMapTable.RId]; + } + + public InterfaceImplTable GetInterfaceImplTable () + { + return (InterfaceImplTable) m_heap [InterfaceImplTable.RId]; + } + + public ManifestResourceTable GetManifestResourceTable () + { + return (ManifestResourceTable) m_heap [ManifestResourceTable.RId]; + } + + public MemberRefTable GetMemberRefTable () + { + return (MemberRefTable) m_heap [MemberRefTable.RId]; + } + + public MethodTable GetMethodTable () + { + return (MethodTable) m_heap [MethodTable.RId]; + } + + public MethodImplTable GetMethodImplTable () + { + return (MethodImplTable) m_heap [MethodImplTable.RId]; + } + + public MethodPtrTable GetMethodPtrTable () + { + return (MethodPtrTable) m_heap [MethodPtrTable.RId]; + } + + public MethodSemanticsTable GetMethodSemanticsTable () + { + return (MethodSemanticsTable) m_heap [MethodSemanticsTable.RId]; + } + + public MethodSpecTable GetMethodSpecTable () + { + return (MethodSpecTable) m_heap [MethodSpecTable.RId]; + } + + public ModuleTable GetModuleTable () + { + return (ModuleTable) m_heap [ModuleTable.RId]; + } + + public ModuleRefTable GetModuleRefTable () + { + return (ModuleRefTable) m_heap [ModuleRefTable.RId]; + } + + public NestedClassTable GetNestedClassTable () + { + return (NestedClassTable) m_heap [NestedClassTable.RId]; + } + + public ParamTable GetParamTable () + { + return (ParamTable) m_heap [ParamTable.RId]; + } + + public ParamPtrTable GetParamPtrTable () + { + return (ParamPtrTable) m_heap [ParamPtrTable.RId]; + } + + public PropertyTable GetPropertyTable () + { + return (PropertyTable) m_heap [PropertyTable.RId]; + } + + public PropertyMapTable GetPropertyMapTable () + { + return (PropertyMapTable) m_heap [PropertyMapTable.RId]; + } + + public PropertyPtrTable GetPropertyPtrTable () + { + return (PropertyPtrTable) m_heap [PropertyPtrTable.RId]; + } + + public StandAloneSigTable GetStandAloneSigTable () + { + return (StandAloneSigTable) m_heap [StandAloneSigTable.RId]; + } + + public TypeDefTable GetTypeDefTable () + { + return (TypeDefTable) m_heap [TypeDefTable.RId]; + } + + public TypeRefTable GetTypeRefTable () + { + return (TypeRefTable) m_heap [TypeRefTable.RId]; + } + + public TypeSpecTable GetTypeSpecTable () + { + return (TypeSpecTable) m_heap [TypeSpecTable.RId]; + } + + public override void VisitTableCollection (TableCollection coll) + { + if (m_heap.HasTable (ModuleTable.RId)) { + coll.Add (new ModuleTable ()); + m_rows [ModuleTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (TypeRefTable.RId)) { + coll.Add (new TypeRefTable ()); + m_rows [TypeRefTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (TypeDefTable.RId)) { + coll.Add (new TypeDefTable ()); + m_rows [TypeDefTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (FieldPtrTable.RId)) { + coll.Add (new FieldPtrTable ()); + m_rows [FieldPtrTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (FieldTable.RId)) { + coll.Add (new FieldTable ()); + m_rows [FieldTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (MethodPtrTable.RId)) { + coll.Add (new MethodPtrTable ()); + m_rows [MethodPtrTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (MethodTable.RId)) { + coll.Add (new MethodTable ()); + m_rows [MethodTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (ParamPtrTable.RId)) { + coll.Add (new ParamPtrTable ()); + m_rows [ParamPtrTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (ParamTable.RId)) { + coll.Add (new ParamTable ()); + m_rows [ParamTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (InterfaceImplTable.RId)) { + coll.Add (new InterfaceImplTable ()); + m_rows [InterfaceImplTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (MemberRefTable.RId)) { + coll.Add (new MemberRefTable ()); + m_rows [MemberRefTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (ConstantTable.RId)) { + coll.Add (new ConstantTable ()); + m_rows [ConstantTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (CustomAttributeTable.RId)) { + coll.Add (new CustomAttributeTable ()); + m_rows [CustomAttributeTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (FieldMarshalTable.RId)) { + coll.Add (new FieldMarshalTable ()); + m_rows [FieldMarshalTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (DeclSecurityTable.RId)) { + coll.Add (new DeclSecurityTable ()); + m_rows [DeclSecurityTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (ClassLayoutTable.RId)) { + coll.Add (new ClassLayoutTable ()); + m_rows [ClassLayoutTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (FieldLayoutTable.RId)) { + coll.Add (new FieldLayoutTable ()); + m_rows [FieldLayoutTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (StandAloneSigTable.RId)) { + coll.Add (new StandAloneSigTable ()); + m_rows [StandAloneSigTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (EventMapTable.RId)) { + coll.Add (new EventMapTable ()); + m_rows [EventMapTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (EventPtrTable.RId)) { + coll.Add (new EventPtrTable ()); + m_rows [EventPtrTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (EventTable.RId)) { + coll.Add (new EventTable ()); + m_rows [EventTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (PropertyMapTable.RId)) { + coll.Add (new PropertyMapTable ()); + m_rows [PropertyMapTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (PropertyPtrTable.RId)) { + coll.Add (new PropertyPtrTable ()); + m_rows [PropertyPtrTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (PropertyTable.RId)) { + coll.Add (new PropertyTable ()); + m_rows [PropertyTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (MethodSemanticsTable.RId)) { + coll.Add (new MethodSemanticsTable ()); + m_rows [MethodSemanticsTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (MethodImplTable.RId)) { + coll.Add (new MethodImplTable ()); + m_rows [MethodImplTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (ModuleRefTable.RId)) { + coll.Add (new ModuleRefTable ()); + m_rows [ModuleRefTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (TypeSpecTable.RId)) { + coll.Add (new TypeSpecTable ()); + m_rows [TypeSpecTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (ImplMapTable.RId)) { + coll.Add (new ImplMapTable ()); + m_rows [ImplMapTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (FieldRVATable.RId)) { + coll.Add (new FieldRVATable ()); + m_rows [FieldRVATable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (AssemblyTable.RId)) { + coll.Add (new AssemblyTable ()); + m_rows [AssemblyTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (AssemblyProcessorTable.RId)) { + coll.Add (new AssemblyProcessorTable ()); + m_rows [AssemblyProcessorTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (AssemblyOSTable.RId)) { + coll.Add (new AssemblyOSTable ()); + m_rows [AssemblyOSTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (AssemblyRefTable.RId)) { + coll.Add (new AssemblyRefTable ()); + m_rows [AssemblyRefTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (AssemblyRefProcessorTable.RId)) { + coll.Add (new AssemblyRefProcessorTable ()); + m_rows [AssemblyRefProcessorTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (AssemblyRefOSTable.RId)) { + coll.Add (new AssemblyRefOSTable ()); + m_rows [AssemblyRefOSTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (FileTable.RId)) { + coll.Add (new FileTable ()); + m_rows [FileTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (ExportedTypeTable.RId)) { + coll.Add (new ExportedTypeTable ()); + m_rows [ExportedTypeTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (ManifestResourceTable.RId)) { + coll.Add (new ManifestResourceTable ()); + m_rows [ManifestResourceTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (NestedClassTable.RId)) { + coll.Add (new NestedClassTable ()); + m_rows [NestedClassTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (GenericParamTable.RId)) { + coll.Add (new GenericParamTable ()); + m_rows [GenericParamTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (MethodSpecTable.RId)) { + coll.Add (new MethodSpecTable ()); + m_rows [MethodSpecTable.RId] = m_binaryReader.ReadInt32 (); + } + if (m_heap.HasTable (GenericParamConstraintTable.RId)) { + coll.Add (new GenericParamConstraintTable ()); + m_rows [GenericParamConstraintTable.RId] = m_binaryReader.ReadInt32 (); + } + } + + public override void VisitAssemblyTable (AssemblyTable table) + { + int number = m_rows [AssemblyTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new AssemblyRow ()); + } + public override void VisitAssemblyOSTable (AssemblyOSTable table) + { + int number = m_rows [AssemblyOSTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new AssemblyOSRow ()); + } + public override void VisitAssemblyProcessorTable (AssemblyProcessorTable table) + { + int number = m_rows [AssemblyProcessorTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new AssemblyProcessorRow ()); + } + public override void VisitAssemblyRefTable (AssemblyRefTable table) + { + int number = m_rows [AssemblyRefTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new AssemblyRefRow ()); + } + public override void VisitAssemblyRefOSTable (AssemblyRefOSTable table) + { + int number = m_rows [AssemblyRefOSTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new AssemblyRefOSRow ()); + } + public override void VisitAssemblyRefProcessorTable (AssemblyRefProcessorTable table) + { + int number = m_rows [AssemblyRefProcessorTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new AssemblyRefProcessorRow ()); + } + public override void VisitClassLayoutTable (ClassLayoutTable table) + { + int number = m_rows [ClassLayoutTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ClassLayoutRow ()); + } + public override void VisitConstantTable (ConstantTable table) + { + int number = m_rows [ConstantTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ConstantRow ()); + } + public override void VisitCustomAttributeTable (CustomAttributeTable table) + { + int number = m_rows [CustomAttributeTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new CustomAttributeRow ()); + } + public override void VisitDeclSecurityTable (DeclSecurityTable table) + { + int number = m_rows [DeclSecurityTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new DeclSecurityRow ()); + } + public override void VisitEventTable (EventTable table) + { + int number = m_rows [EventTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new EventRow ()); + } + public override void VisitEventMapTable (EventMapTable table) + { + int number = m_rows [EventMapTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new EventMapRow ()); + } + public override void VisitEventPtrTable (EventPtrTable table) + { + int number = m_rows [EventPtrTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new EventPtrRow ()); + } + public override void VisitExportedTypeTable (ExportedTypeTable table) + { + int number = m_rows [ExportedTypeTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ExportedTypeRow ()); + } + public override void VisitFieldTable (FieldTable table) + { + int number = m_rows [FieldTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new FieldRow ()); + } + public override void VisitFieldLayoutTable (FieldLayoutTable table) + { + int number = m_rows [FieldLayoutTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new FieldLayoutRow ()); + } + public override void VisitFieldMarshalTable (FieldMarshalTable table) + { + int number = m_rows [FieldMarshalTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new FieldMarshalRow ()); + } + public override void VisitFieldPtrTable (FieldPtrTable table) + { + int number = m_rows [FieldPtrTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new FieldPtrRow ()); + } + public override void VisitFieldRVATable (FieldRVATable table) + { + int number = m_rows [FieldRVATable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new FieldRVARow ()); + } + public override void VisitFileTable (FileTable table) + { + int number = m_rows [FileTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new FileRow ()); + } + public override void VisitGenericParamTable (GenericParamTable table) + { + int number = m_rows [GenericParamTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new GenericParamRow ()); + } + public override void VisitGenericParamConstraintTable (GenericParamConstraintTable table) + { + int number = m_rows [GenericParamConstraintTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new GenericParamConstraintRow ()); + } + public override void VisitImplMapTable (ImplMapTable table) + { + int number = m_rows [ImplMapTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ImplMapRow ()); + } + public override void VisitInterfaceImplTable (InterfaceImplTable table) + { + int number = m_rows [InterfaceImplTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new InterfaceImplRow ()); + } + public override void VisitManifestResourceTable (ManifestResourceTable table) + { + int number = m_rows [ManifestResourceTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ManifestResourceRow ()); + } + public override void VisitMemberRefTable (MemberRefTable table) + { + int number = m_rows [MemberRefTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new MemberRefRow ()); + } + public override void VisitMethodTable (MethodTable table) + { + int number = m_rows [MethodTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new MethodRow ()); + } + public override void VisitMethodImplTable (MethodImplTable table) + { + int number = m_rows [MethodImplTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new MethodImplRow ()); + } + public override void VisitMethodPtrTable (MethodPtrTable table) + { + int number = m_rows [MethodPtrTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new MethodPtrRow ()); + } + public override void VisitMethodSemanticsTable (MethodSemanticsTable table) + { + int number = m_rows [MethodSemanticsTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new MethodSemanticsRow ()); + } + public override void VisitMethodSpecTable (MethodSpecTable table) + { + int number = m_rows [MethodSpecTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new MethodSpecRow ()); + } + public override void VisitModuleTable (ModuleTable table) + { + int number = m_rows [ModuleTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ModuleRow ()); + } + public override void VisitModuleRefTable (ModuleRefTable table) + { + int number = m_rows [ModuleRefTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ModuleRefRow ()); + } + public override void VisitNestedClassTable (NestedClassTable table) + { + int number = m_rows [NestedClassTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new NestedClassRow ()); + } + public override void VisitParamTable (ParamTable table) + { + int number = m_rows [ParamTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ParamRow ()); + } + public override void VisitParamPtrTable (ParamPtrTable table) + { + int number = m_rows [ParamPtrTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new ParamPtrRow ()); + } + public override void VisitPropertyTable (PropertyTable table) + { + int number = m_rows [PropertyTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new PropertyRow ()); + } + public override void VisitPropertyMapTable (PropertyMapTable table) + { + int number = m_rows [PropertyMapTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new PropertyMapRow ()); + } + public override void VisitPropertyPtrTable (PropertyPtrTable table) + { + int number = m_rows [PropertyPtrTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new PropertyPtrRow ()); + } + public override void VisitStandAloneSigTable (StandAloneSigTable table) + { + int number = m_rows [StandAloneSigTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new StandAloneSigRow ()); + } + public override void VisitTypeDefTable (TypeDefTable table) + { + int number = m_rows [TypeDefTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new TypeDefRow ()); + } + public override void VisitTypeRefTable (TypeRefTable table) + { + int number = m_rows [TypeRefTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new TypeRefRow ()); + } + public override void VisitTypeSpecTable (TypeSpecTable table) + { + int number = m_rows [TypeSpecTable.RId]; + table.Rows = new RowCollection (number); + for (int i = 0; i < number; i++) + table.Rows.Add (new TypeSpecRow ()); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableWriter.cs new file mode 100644 index 0000000..6c7fab4 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataTableWriter.cs @@ -0,0 +1,602 @@ +// +// MetadataTableWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + using Mono.Cecil.Binary; + + internal sealed class MetadataTableWriter : BaseMetadataTableVisitor { + + MetadataRoot m_root; + TablesHeap m_heap; + MetadataRowWriter m_mrrw; + MemoryBinaryWriter m_binaryWriter; + + public MetadataTableWriter (MetadataWriter mrv, MemoryBinaryWriter writer) + { + m_root = mrv.GetMetadataRoot (); + m_heap = m_root.Streams.TablesHeap; + m_binaryWriter = writer; + m_mrrw = new MetadataRowWriter (this); + } + + public MetadataRoot GetMetadataRoot () + { + return m_root; + } + + public override IMetadataRowVisitor GetRowVisitor () + { + return m_mrrw; + } + + public MemoryBinaryWriter GetWriter () + { + return m_binaryWriter; + } + + void InitializeTable (IMetadataTable table) + { + table.Rows = new RowCollection (); + m_heap.Valid |= 1L << table.Id; + m_heap.Tables.Add (table); + } + + void WriteCount (int rid) + { + if (m_heap.HasTable (rid)) + m_binaryWriter.Write (m_heap [rid].Rows.Count); + } + + public AssemblyTable GetAssemblyTable () + { + AssemblyTable table = m_heap [AssemblyTable.RId] as AssemblyTable; + if (table != null) + return table; + + table = new AssemblyTable (); + InitializeTable (table); + return table; + } + + public AssemblyOSTable GetAssemblyOSTable () + { + AssemblyOSTable table = m_heap [AssemblyOSTable.RId] as AssemblyOSTable; + if (table != null) + return table; + + table = new AssemblyOSTable (); + InitializeTable (table); + return table; + } + + public AssemblyProcessorTable GetAssemblyProcessorTable () + { + AssemblyProcessorTable table = m_heap [AssemblyProcessorTable.RId] as AssemblyProcessorTable; + if (table != null) + return table; + + table = new AssemblyProcessorTable (); + InitializeTable (table); + return table; + } + + public AssemblyRefTable GetAssemblyRefTable () + { + AssemblyRefTable table = m_heap [AssemblyRefTable.RId] as AssemblyRefTable; + if (table != null) + return table; + + table = new AssemblyRefTable (); + InitializeTable (table); + return table; + } + + public AssemblyRefOSTable GetAssemblyRefOSTable () + { + AssemblyRefOSTable table = m_heap [AssemblyRefOSTable.RId] as AssemblyRefOSTable; + if (table != null) + return table; + + table = new AssemblyRefOSTable (); + InitializeTable (table); + return table; + } + + public AssemblyRefProcessorTable GetAssemblyRefProcessorTable () + { + AssemblyRefProcessorTable table = m_heap [AssemblyRefProcessorTable.RId] as AssemblyRefProcessorTable; + if (table != null) + return table; + + table = new AssemblyRefProcessorTable (); + InitializeTable (table); + return table; + } + + public ClassLayoutTable GetClassLayoutTable () + { + ClassLayoutTable table = m_heap [ClassLayoutTable.RId] as ClassLayoutTable; + if (table != null) + return table; + + table = new ClassLayoutTable (); + InitializeTable (table); + return table; + } + + public ConstantTable GetConstantTable () + { + ConstantTable table = m_heap [ConstantTable.RId] as ConstantTable; + if (table != null) + return table; + + table = new ConstantTable (); + InitializeTable (table); + return table; + } + + public CustomAttributeTable GetCustomAttributeTable () + { + CustomAttributeTable table = m_heap [CustomAttributeTable.RId] as CustomAttributeTable; + if (table != null) + return table; + + table = new CustomAttributeTable (); + InitializeTable (table); + return table; + } + + public DeclSecurityTable GetDeclSecurityTable () + { + DeclSecurityTable table = m_heap [DeclSecurityTable.RId] as DeclSecurityTable; + if (table != null) + return table; + + table = new DeclSecurityTable (); + InitializeTable (table); + return table; + } + + public EventTable GetEventTable () + { + EventTable table = m_heap [EventTable.RId] as EventTable; + if (table != null) + return table; + + table = new EventTable (); + InitializeTable (table); + return table; + } + + public EventMapTable GetEventMapTable () + { + EventMapTable table = m_heap [EventMapTable.RId] as EventMapTable; + if (table != null) + return table; + + table = new EventMapTable (); + InitializeTable (table); + return table; + } + + public EventPtrTable GetEventPtrTable () + { + EventPtrTable table = m_heap [EventPtrTable.RId] as EventPtrTable; + if (table != null) + return table; + + table = new EventPtrTable (); + InitializeTable (table); + return table; + } + + public ExportedTypeTable GetExportedTypeTable () + { + ExportedTypeTable table = m_heap [ExportedTypeTable.RId] as ExportedTypeTable; + if (table != null) + return table; + + table = new ExportedTypeTable (); + InitializeTable (table); + return table; + } + + public FieldTable GetFieldTable () + { + FieldTable table = m_heap [FieldTable.RId] as FieldTable; + if (table != null) + return table; + + table = new FieldTable (); + InitializeTable (table); + return table; + } + + public FieldLayoutTable GetFieldLayoutTable () + { + FieldLayoutTable table = m_heap [FieldLayoutTable.RId] as FieldLayoutTable; + if (table != null) + return table; + + table = new FieldLayoutTable (); + InitializeTable (table); + return table; + } + + public FieldMarshalTable GetFieldMarshalTable () + { + FieldMarshalTable table = m_heap [FieldMarshalTable.RId] as FieldMarshalTable; + if (table != null) + return table; + + table = new FieldMarshalTable (); + InitializeTable (table); + return table; + } + + public FieldPtrTable GetFieldPtrTable () + { + FieldPtrTable table = m_heap [FieldPtrTable.RId] as FieldPtrTable; + if (table != null) + return table; + + table = new FieldPtrTable (); + InitializeTable (table); + return table; + } + + public FieldRVATable GetFieldRVATable () + { + FieldRVATable table = m_heap [FieldRVATable.RId] as FieldRVATable; + if (table != null) + return table; + + table = new FieldRVATable (); + InitializeTable (table); + return table; + } + + public FileTable GetFileTable () + { + FileTable table = m_heap [FileTable.RId] as FileTable; + if (table != null) + return table; + + table = new FileTable (); + InitializeTable (table); + return table; + } + + public GenericParamTable GetGenericParamTable () + { + GenericParamTable table = m_heap [GenericParamTable.RId] as GenericParamTable; + if (table != null) + return table; + + table = new GenericParamTable (); + InitializeTable (table); + return table; + } + + public GenericParamConstraintTable GetGenericParamConstraintTable () + { + GenericParamConstraintTable table = m_heap [GenericParamConstraintTable.RId] as GenericParamConstraintTable; + if (table != null) + return table; + + table = new GenericParamConstraintTable (); + InitializeTable (table); + return table; + } + + public ImplMapTable GetImplMapTable () + { + ImplMapTable table = m_heap [ImplMapTable.RId] as ImplMapTable; + if (table != null) + return table; + + table = new ImplMapTable (); + InitializeTable (table); + return table; + } + + public InterfaceImplTable GetInterfaceImplTable () + { + InterfaceImplTable table = m_heap [InterfaceImplTable.RId] as InterfaceImplTable; + if (table != null) + return table; + + table = new InterfaceImplTable (); + InitializeTable (table); + return table; + } + + public ManifestResourceTable GetManifestResourceTable () + { + ManifestResourceTable table = m_heap [ManifestResourceTable.RId] as ManifestResourceTable; + if (table != null) + return table; + + table = new ManifestResourceTable (); + InitializeTable (table); + return table; + } + + public MemberRefTable GetMemberRefTable () + { + MemberRefTable table = m_heap [MemberRefTable.RId] as MemberRefTable; + if (table != null) + return table; + + table = new MemberRefTable (); + InitializeTable (table); + return table; + } + + public MethodTable GetMethodTable () + { + MethodTable table = m_heap [MethodTable.RId] as MethodTable; + if (table != null) + return table; + + table = new MethodTable (); + InitializeTable (table); + return table; + } + + public MethodImplTable GetMethodImplTable () + { + MethodImplTable table = m_heap [MethodImplTable.RId] as MethodImplTable; + if (table != null) + return table; + + table = new MethodImplTable (); + InitializeTable (table); + return table; + } + + public MethodPtrTable GetMethodPtrTable () + { + MethodPtrTable table = m_heap [MethodPtrTable.RId] as MethodPtrTable; + if (table != null) + return table; + + table = new MethodPtrTable (); + InitializeTable (table); + return table; + } + + public MethodSemanticsTable GetMethodSemanticsTable () + { + MethodSemanticsTable table = m_heap [MethodSemanticsTable.RId] as MethodSemanticsTable; + if (table != null) + return table; + + table = new MethodSemanticsTable (); + InitializeTable (table); + return table; + } + + public MethodSpecTable GetMethodSpecTable () + { + MethodSpecTable table = m_heap [MethodSpecTable.RId] as MethodSpecTable; + if (table != null) + return table; + + table = new MethodSpecTable (); + InitializeTable (table); + return table; + } + + public ModuleTable GetModuleTable () + { + ModuleTable table = m_heap [ModuleTable.RId] as ModuleTable; + if (table != null) + return table; + + table = new ModuleTable (); + InitializeTable (table); + return table; + } + + public ModuleRefTable GetModuleRefTable () + { + ModuleRefTable table = m_heap [ModuleRefTable.RId] as ModuleRefTable; + if (table != null) + return table; + + table = new ModuleRefTable (); + InitializeTable (table); + return table; + } + + public NestedClassTable GetNestedClassTable () + { + NestedClassTable table = m_heap [NestedClassTable.RId] as NestedClassTable; + if (table != null) + return table; + + table = new NestedClassTable (); + InitializeTable (table); + return table; + } + + public ParamTable GetParamTable () + { + ParamTable table = m_heap [ParamTable.RId] as ParamTable; + if (table != null) + return table; + + table = new ParamTable (); + InitializeTable (table); + return table; + } + + public ParamPtrTable GetParamPtrTable () + { + ParamPtrTable table = m_heap [ParamPtrTable.RId] as ParamPtrTable; + if (table != null) + return table; + + table = new ParamPtrTable (); + InitializeTable (table); + return table; + } + + public PropertyTable GetPropertyTable () + { + PropertyTable table = m_heap [PropertyTable.RId] as PropertyTable; + if (table != null) + return table; + + table = new PropertyTable (); + InitializeTable (table); + return table; + } + + public PropertyMapTable GetPropertyMapTable () + { + PropertyMapTable table = m_heap [PropertyMapTable.RId] as PropertyMapTable; + if (table != null) + return table; + + table = new PropertyMapTable (); + InitializeTable (table); + return table; + } + + public PropertyPtrTable GetPropertyPtrTable () + { + PropertyPtrTable table = m_heap [PropertyPtrTable.RId] as PropertyPtrTable; + if (table != null) + return table; + + table = new PropertyPtrTable (); + InitializeTable (table); + return table; + } + + public StandAloneSigTable GetStandAloneSigTable () + { + StandAloneSigTable table = m_heap [StandAloneSigTable.RId] as StandAloneSigTable; + if (table != null) + return table; + + table = new StandAloneSigTable (); + InitializeTable (table); + return table; + } + + public TypeDefTable GetTypeDefTable () + { + TypeDefTable table = m_heap [TypeDefTable.RId] as TypeDefTable; + if (table != null) + return table; + + table = new TypeDefTable (); + InitializeTable (table); + return table; + } + + public TypeRefTable GetTypeRefTable () + { + TypeRefTable table = m_heap [TypeRefTable.RId] as TypeRefTable; + if (table != null) + return table; + + table = new TypeRefTable (); + InitializeTable (table); + return table; + } + + public TypeSpecTable GetTypeSpecTable () + { + TypeSpecTable table = m_heap [TypeSpecTable.RId] as TypeSpecTable; + if (table != null) + return table; + + table = new TypeSpecTable (); + InitializeTable (table); + return table; + } + + public override void VisitTableCollection (TableCollection coll) + { + WriteCount (ModuleTable.RId); + WriteCount (TypeRefTable.RId); + WriteCount (TypeDefTable.RId); + WriteCount (FieldPtrTable.RId); + WriteCount (FieldTable.RId); + WriteCount (MethodPtrTable.RId); + WriteCount (MethodTable.RId); + WriteCount (ParamPtrTable.RId); + WriteCount (ParamTable.RId); + WriteCount (InterfaceImplTable.RId); + WriteCount (MemberRefTable.RId); + WriteCount (ConstantTable.RId); + WriteCount (CustomAttributeTable.RId); + WriteCount (FieldMarshalTable.RId); + WriteCount (DeclSecurityTable.RId); + WriteCount (ClassLayoutTable.RId); + WriteCount (FieldLayoutTable.RId); + WriteCount (StandAloneSigTable.RId); + WriteCount (EventMapTable.RId); + WriteCount (EventPtrTable.RId); + WriteCount (EventTable.RId); + WriteCount (PropertyMapTable.RId); + WriteCount (PropertyPtrTable.RId); + WriteCount (PropertyTable.RId); + WriteCount (MethodSemanticsTable.RId); + WriteCount (MethodImplTable.RId); + WriteCount (ModuleRefTable.RId); + WriteCount (TypeSpecTable.RId); + WriteCount (ImplMapTable.RId); + WriteCount (FieldRVATable.RId); + WriteCount (AssemblyTable.RId); + WriteCount (AssemblyProcessorTable.RId); + WriteCount (AssemblyOSTable.RId); + WriteCount (AssemblyRefTable.RId); + WriteCount (AssemblyRefProcessorTable.RId); + WriteCount (AssemblyRefOSTable.RId); + WriteCount (FileTable.RId); + WriteCount (ExportedTypeTable.RId); + WriteCount (ManifestResourceTable.RId); + WriteCount (NestedClassTable.RId); + WriteCount (GenericParamTable.RId); + WriteCount (MethodSpecTable.RId); + WriteCount (GenericParamConstraintTable.RId); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs new file mode 100644 index 0000000..d584fed --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataToken.cs @@ -0,0 +1,99 @@ +// +// MetadataToken.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public struct MetadataToken { + + uint m_rid; + TokenType m_type; + + public uint RID { + get { return m_rid; } + } + + public TokenType TokenType { + get { return m_type; } + } + + public static readonly MetadataToken Zero = new MetadataToken ((TokenType) 0, 0); + + public MetadataToken (int token) + { + m_type = (TokenType) (token & 0xff000000); + m_rid = (uint) token & 0x00ffffff; + } + + public MetadataToken (TokenType table, uint rid) + { + m_type = table; + m_rid = rid; + } + + internal static MetadataToken FromMetadataRow (TokenType table, int rowIndex) + { + return new MetadataToken (table, (uint) rowIndex + 1); + } + + public uint ToUInt () + { + return (uint) m_type | m_rid; + } + + public override int GetHashCode () + { + return (int) ToUInt (); + } + + public override bool Equals (object other) + { + if (other is MetadataToken) { + MetadataToken o = (MetadataToken) other; + return o.m_rid == m_rid && o.m_type == m_type; + } + + return false; + } + + public static bool operator == (MetadataToken one, MetadataToken other) + { + return one.Equals (other); + } + + public static bool operator != (MetadataToken one, MetadataToken other) + { + return !one.Equals (other); + } + + public override string ToString () + { + return string.Format ("{0} [0x{1}]", + m_type, m_rid.ToString ("x4")); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataWriter.cs new file mode 100644 index 0000000..e872af2 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MetadataWriter.cs @@ -0,0 +1,506 @@ +// +// MetadataWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + using System.IO; + using System.Text; + + using Mono.Cecil; + using Mono.Cecil.Binary; + + internal sealed class MetadataWriter : BaseMetadataVisitor { + + AssemblyDefinition m_assembly; + MetadataRoot m_root; + TargetRuntime m_runtime; + ImageWriter m_imgWriter; + MetadataTableWriter m_tableWriter; + MemoryBinaryWriter m_binaryWriter; + + IDictionary m_stringCache; + MemoryBinaryWriter m_stringWriter; + + IDictionary m_guidCache; + MemoryBinaryWriter m_guidWriter; + + IDictionary m_usCache; + MemoryBinaryWriter m_usWriter; + + IDictionary m_blobCache; + MemoryBinaryWriter m_blobWriter; + + MemoryBinaryWriter m_tWriter; + + MemoryBinaryWriter m_cilWriter; + + MemoryBinaryWriter m_fieldDataWriter; + MemoryBinaryWriter m_resWriter; + + uint m_mdStart, m_mdSize; + uint m_resStart, m_resSize; + uint m_snsStart, m_snsSize; + uint m_debugHeaderStart; + uint m_imporTableStart; + + uint m_entryPointToken; + + RVA m_cursor = new RVA (0x2050); + + public MemoryBinaryWriter CilWriter { + get { return m_cilWriter; } + } + + public uint DebugHeaderPosition { + get { return m_debugHeaderStart; } + } + + public uint ImportTablePosition { + get { return m_imporTableStart; } + } + + public uint EntryPointToken { + get { return m_entryPointToken; } + set { m_entryPointToken = value; } + } + + public MetadataWriter (AssemblyDefinition asm, MetadataRoot root, + AssemblyKind kind, TargetRuntime rt, BinaryWriter writer) + { + m_assembly = asm; + m_root = root; + m_runtime = rt; + m_imgWriter = new ImageWriter (this, kind, writer); + m_binaryWriter = m_imgWriter.GetTextWriter (); + + m_stringCache = new Hashtable (); + m_stringWriter = new MemoryBinaryWriter (Encoding.UTF8); + m_stringWriter.Write ((byte) 0); + + m_guidCache = new Hashtable (); + m_guidWriter = new MemoryBinaryWriter (); + + m_usCache = new Hashtable (); + m_usWriter = new MemoryBinaryWriter (Encoding.Unicode); + m_usWriter.Write ((byte) 0); + + m_blobCache = new Hashtable (); + m_blobWriter = new MemoryBinaryWriter (); + m_blobWriter.Write ((byte) 0); + + m_tWriter = new MemoryBinaryWriter (); + m_tableWriter = new MetadataTableWriter (this, m_tWriter); + + m_cilWriter = new MemoryBinaryWriter (); + + m_fieldDataWriter = new MemoryBinaryWriter (); + m_resWriter = new MemoryBinaryWriter (); + } + + public MetadataRoot GetMetadataRoot () + { + return m_root; + } + + public ImageWriter GetImageWriter () + { + return m_imgWriter; + } + + public MemoryBinaryWriter GetWriter () + { + return m_binaryWriter; + } + + public MetadataTableWriter GetTableVisitor () + { + return m_tableWriter; + } + + public void AddData (int length) + { + m_cursor += new RVA ((uint) length); + } + + public RVA GetDataCursor () + { + return m_cursor; + } + + public uint AddString (string str) + { + if (str == null || str.Length == 0) + return 0; + + if (m_stringCache.Contains (str)) + return (uint) m_stringCache [str]; + + uint pointer = (uint) m_stringWriter.BaseStream.Position; + m_stringCache [str] = pointer; + m_stringWriter.Write (Encoding.UTF8.GetBytes (str)); + m_stringWriter.Write ('\0'); + return pointer; + } + + public uint AddBlob (byte [] data) + { + if (data == null || data.Length == 0) + return 0; + + // using CompactFramework compatible version of + // Convert.ToBase64String + string key = Convert.ToBase64String (data, 0, data.Length); + if (m_blobCache.Contains (key)) + return (uint) m_blobCache [key]; + + uint pointer = (uint) m_blobWriter.BaseStream.Position; + m_blobCache [key] = pointer; + Utilities.WriteCompressedInteger (m_blobWriter, data.Length); + m_blobWriter.Write (data); + return pointer; + } + + public uint AddGuid (Guid g) + { + if (m_guidCache.Contains (g)) + return (uint) m_guidCache [g]; + + uint pointer = (uint) m_guidWriter.BaseStream.Position; + m_guidCache [g] = pointer; + m_guidWriter.Write (g.ToByteArray ()); + return pointer + 1; + } + + public uint AddUserString (string str) + { + if (str == null) + return 0; + + if (m_usCache.Contains (str)) + return (uint) m_usCache [str]; + + uint pointer = (uint) m_usWriter.BaseStream.Position; + m_usCache [str] = pointer; + byte [] us = Encoding.Unicode.GetBytes (str); + Utilities.WriteCompressedInteger (m_usWriter, us.Length + 1); + m_usWriter.Write (us); + m_usWriter.Write ((byte) (RequiresSpecialHandling (us) ? 1 : 0)); + return pointer; + } + + static bool RequiresSpecialHandling (byte [] chars) + { + for (int i = 0; i < chars.Length; i++) { + byte c = chars [i]; + if ((i % 2) == 1) + if (c != 0) + return true; + + if (InRange (0x01, 0x08, c) || + InRange (0x0e, 0x1f, c) || + c == 0x27 || + c == 0x2d || + c == 0x7f) { + + return true; + } + } + + return false; + } + + static bool InRange (int left, int right, int value) + { + return left <= value && value <= right; + } + + void CreateStream (string name) + { + MetadataStream stream = new MetadataStream (); + stream.Header.Name = name; + stream.Heap = MetadataHeap.HeapFactory (stream); + m_root.Streams.Add (stream); + } + + void SetHeapSize (MetadataHeap heap, MemoryBinaryWriter data, byte flag) + { + if (data.BaseStream.Length > 65536) { + m_root.Streams.TablesHeap.HeapSizes |= flag; + heap.IndexSize = 4; + } else + heap.IndexSize = 2; + } + + public uint AddResource (byte [] data) + { + uint offset = (uint) m_resWriter.BaseStream.Position; + m_resWriter.Write (data.Length); + m_resWriter.Write (data); + m_resWriter.QuadAlign (); + return offset; + } + + public void AddFieldInitData (byte [] data) + { + m_fieldDataWriter.Write (data); + m_fieldDataWriter.QuadAlign (); + } + + uint GetStrongNameSignatureSize () + { + if (m_assembly.Name.PublicKey != null) { + // in fx 2.0 the key may be from 384 to 16384 bits + // so we must calculate the signature size based on + // the size of the public key (minus the 32 byte header) + int size = m_assembly.Name.PublicKey.Length; + if (size > 32) + return (uint) (size - 32); + // note: size == 16 for the ECMA "key" which is replaced + // by the runtime with a 1024 bits key (128 bytes) + } + return 128; // default strongname signature size + } + + public override void VisitMetadataRoot (MetadataRoot root) + { + WriteMemStream (m_cilWriter); + WriteMemStream (m_fieldDataWriter); + m_resStart = (uint) m_binaryWriter.BaseStream.Position; + WriteMemStream (m_resWriter); + m_resSize = (uint) (m_binaryWriter.BaseStream.Position - m_resStart); + + // for now, we only reserve the place for the strong name signature + if ((m_assembly.Name.Flags & AssemblyFlags.PublicKey) > 0) { + m_snsStart = (uint) m_binaryWriter.BaseStream.Position; + m_snsSize = GetStrongNameSignatureSize (); + m_binaryWriter.Write (new byte [m_snsSize]); + m_binaryWriter.QuadAlign (); + } + + // save place for debug header + if (m_imgWriter.GetImage ().DebugHeader != null) { + m_debugHeaderStart = (uint) m_binaryWriter.BaseStream.Position; + m_binaryWriter.Write (new byte [m_imgWriter.GetImage ().DebugHeader.GetSize ()]); + m_binaryWriter.QuadAlign (); + } + + m_mdStart = (uint) m_binaryWriter.BaseStream.Position; + + if (m_stringWriter.BaseStream.Length > 1) { + CreateStream (MetadataStream.Strings); + SetHeapSize (root.Streams.StringsHeap, m_stringWriter, 0x01); + m_stringWriter.QuadAlign (); + } + + if (m_guidWriter.BaseStream.Length > 0) { + CreateStream (MetadataStream.GUID); + SetHeapSize (root.Streams.GuidHeap, m_guidWriter, 0x02); + } + + if (m_blobWriter.BaseStream.Length > 1) { + CreateStream (MetadataStream.Blob); + SetHeapSize (root.Streams.BlobHeap, m_blobWriter, 0x04); + m_blobWriter.QuadAlign (); + } + + if (m_usWriter.BaseStream.Length > 2) { + CreateStream (MetadataStream.UserStrings); + m_usWriter.QuadAlign (); + } + + m_root.Header.MajorVersion = 1; + m_root.Header.MinorVersion = 1; + + switch (m_runtime) { + case TargetRuntime.NET_1_0 : + m_root.Header.Version = "v1.0.3705"; + break; + case TargetRuntime.NET_1_1 : + m_root.Header.Version = "v1.1.4322"; + break; + case TargetRuntime.NET_2_0 : + m_root.Header.Version = "v2.0.50727"; + break; + } + + m_root.Streams.TablesHeap.Tables.Accept (m_tableWriter); + + if (m_tWriter.BaseStream.Length == 0) + m_root.Streams.Remove (m_root.Streams.TablesHeap.GetStream ()); + } + + public override void VisitMetadataRootHeader (MetadataRoot.MetadataRootHeader header) + { + m_binaryWriter.Write (header.Signature); + m_binaryWriter.Write (header.MajorVersion); + m_binaryWriter.Write (header.MinorVersion); + m_binaryWriter.Write (header.Reserved); + m_binaryWriter.Write (header.Version.Length + 3 & (~3)); + m_binaryWriter.Write (Encoding.ASCII.GetBytes (header.Version)); + m_binaryWriter.QuadAlign (); + m_binaryWriter.Write (header.Flags); + m_binaryWriter.Write ((ushort) m_root.Streams.Count); + } + + public override void VisitMetadataStreamCollection (MetadataStreamCollection streams) + { + foreach (MetadataStream stream in streams) { + MetadataStream.MetadataStreamHeader header = stream.Header; + + header.Offset = (uint) (m_binaryWriter.BaseStream.Position); + m_binaryWriter.Write (header.Offset); + MemoryBinaryWriter container; + string name = header.Name; + uint size = 0; + switch (header.Name) { + case MetadataStream.Tables : + container = m_tWriter; + size += 24; // header + break; + case MetadataStream.Strings : + name += "\0\0\0\0"; + container = m_stringWriter; + break; + case MetadataStream.GUID : + container = m_guidWriter; + break; + case MetadataStream.Blob : + container = m_blobWriter; + break; + case MetadataStream.UserStrings : + container = m_usWriter; + break; + default : + throw new MetadataFormatException ("Unknown stream kind"); + } + + size += (uint) (container.BaseStream.Length + 3 & (~3)); + m_binaryWriter.Write (size); + m_binaryWriter.Write (Encoding.ASCII.GetBytes (name)); + m_binaryWriter.QuadAlign (); + } + } + + void WriteMemStream (MemoryBinaryWriter writer) + { + m_binaryWriter.Write (writer); + m_binaryWriter.QuadAlign (); + } + + void PatchStreamHeaderOffset (MetadataHeap heap) + { + long pos = m_binaryWriter.BaseStream.Position; + m_binaryWriter.BaseStream.Position = heap.GetStream ().Header.Offset; + m_binaryWriter.Write ((uint) (pos - m_mdStart)); + m_binaryWriter.BaseStream.Position = pos; + } + + public override void VisitGuidHeap (GuidHeap heap) + { + PatchStreamHeaderOffset (heap); + WriteMemStream (m_guidWriter); + } + + public override void VisitStringsHeap (StringsHeap heap) + { + PatchStreamHeaderOffset (heap); + WriteMemStream (m_stringWriter); + } + + public override void VisitTablesHeap (TablesHeap heap) + { + PatchStreamHeaderOffset (heap); + m_binaryWriter.Write (heap.Reserved); + switch (m_runtime) { + case TargetRuntime.NET_1_0 : + case TargetRuntime.NET_1_1 : + heap.MajorVersion = 1; + heap.MinorVersion = 0; + break; + case TargetRuntime.NET_2_0 : + heap.MajorVersion = 2; + heap.MinorVersion = 0; + break; + } + m_binaryWriter.Write (heap.MajorVersion); + m_binaryWriter.Write (heap.MinorVersion); + m_binaryWriter.Write (heap.HeapSizes); + m_binaryWriter.Write (heap.Reserved2); + m_binaryWriter.Write (heap.Valid); + m_binaryWriter.Write (heap.Sorted); + WriteMemStream (m_tWriter); + } + + public override void VisitBlobHeap (BlobHeap heap) + { + PatchStreamHeaderOffset (heap); + WriteMemStream (m_blobWriter); + } + + public override void VisitUserStringsHeap (UserStringsHeap heap) + { + PatchStreamHeaderOffset (heap); + WriteMemStream (m_usWriter); + } + + void PatchHeader () + { + Image img = m_imgWriter.GetImage (); + + img.CLIHeader.EntryPointToken = m_entryPointToken; + + if (m_mdSize > 0) + img.CLIHeader.Metadata = new DataDirectory ( + img.TextSection.VirtualAddress + m_mdStart, m_imporTableStart - m_mdStart); + + if (m_resSize > 0) + img.CLIHeader.Resources = new DataDirectory ( + img.TextSection.VirtualAddress + m_resStart, m_resSize); + + if (m_snsStart > 0) + img.CLIHeader.StrongNameSignature = new DataDirectory ( + img.TextSection.VirtualAddress + m_snsStart, m_snsSize); + + if (m_debugHeaderStart > 0) + img.PEOptionalHeader.DataDirectories.Debug = new DataDirectory ( + img.TextSection.VirtualAddress + m_debugHeaderStart, 0x1c); + } + + public override void TerminateMetadataRoot (MetadataRoot root) + { + m_mdSize = (uint) (m_binaryWriter.BaseStream.Position - m_mdStart); + m_imporTableStart = (uint) m_binaryWriter.BaseStream.Position; + m_binaryWriter.Write (new byte [0x60]); // imports + m_imgWriter.Initialize (); + PatchHeader (); + root.GetImage ().Accept (m_imgWriter); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Method.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Method.cs new file mode 100644 index 0000000..3d195bc --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Method.cs @@ -0,0 +1,87 @@ +// +// MethodTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + using Mono.Cecil.Binary; + + public sealed class MethodTable : IMetadataTable { + + public const int RId = 0x06; + + RowCollection m_rows; + + public MethodRow this [int index] { + get { return m_rows [index] as MethodRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal MethodTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitMethodTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class MethodRow : IMetadataRow { + + public RVA RVA; + public MethodImplAttributes ImplFlags; + public MethodAttributes Flags; + public uint Name; + public uint Signature; + public uint ParamList; + + internal MethodRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitMethodRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodImpl.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodImpl.cs new file mode 100644 index 0000000..fa9a9d2 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodImpl.cs @@ -0,0 +1,80 @@ +// +// MethodImplTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class MethodImplTable : IMetadataTable { + + public const int RId = 0x19; + + RowCollection m_rows; + + public MethodImplRow this [int index] { + get { return m_rows [index] as MethodImplRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal MethodImplTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitMethodImplTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class MethodImplRow : IMetadataRow { + + public uint Class; + public MetadataToken MethodBody; + public MetadataToken MethodDeclaration; + + internal MethodImplRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitMethodImplRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodPtr.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodPtr.cs new file mode 100644 index 0000000..7a81b88 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodPtr.cs @@ -0,0 +1,78 @@ +// +// MethodPtrTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class MethodPtrTable : IMetadataTable { + + public const int RId = 0x05; + + RowCollection m_rows; + + public MethodPtrRow this [int index] { + get { return m_rows [index] as MethodPtrRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal MethodPtrTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitMethodPtrTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class MethodPtrRow : IMetadataRow { + + public uint Method; + + internal MethodPtrRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitMethodPtrRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodSemantics.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodSemantics.cs new file mode 100644 index 0000000..c1dd175 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodSemantics.cs @@ -0,0 +1,82 @@ +// +// MethodSemanticsTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class MethodSemanticsTable : IMetadataTable { + + public const int RId = 0x18; + + RowCollection m_rows; + + public MethodSemanticsRow this [int index] { + get { return m_rows [index] as MethodSemanticsRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal MethodSemanticsTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitMethodSemanticsTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class MethodSemanticsRow : IMetadataRow { + + public MethodSemanticsAttributes Semantics; + public uint Method; + public MetadataToken Association; + + internal MethodSemanticsRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitMethodSemanticsRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodSpec.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodSpec.cs new file mode 100644 index 0000000..dc5a61d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/MethodSpec.cs @@ -0,0 +1,79 @@ +// +// MethodSpecTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class MethodSpecTable : IMetadataTable { + + public const int RId = 0x2b; + + RowCollection m_rows; + + public MethodSpecRow this [int index] { + get { return m_rows [index] as MethodSpecRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal MethodSpecTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitMethodSpecTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class MethodSpecRow : IMetadataRow { + + public MetadataToken Method; + public uint Instantiation; + + internal MethodSpecRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitMethodSpecRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Module.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Module.cs new file mode 100644 index 0000000..be06b96 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Module.cs @@ -0,0 +1,82 @@ +// +// ModuleTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class ModuleTable : IMetadataTable { + + public const int RId = 0x00; + + RowCollection m_rows; + + public ModuleRow this [int index] { + get { return m_rows [index] as ModuleRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ModuleTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitModuleTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ModuleRow : IMetadataRow { + + public ushort Generation; + public uint Name; + public uint Mvid; + public uint EncId; + public uint EncBaseId; + + internal ModuleRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitModuleRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ModuleRef.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ModuleRef.cs new file mode 100644 index 0000000..fd88991 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ModuleRef.cs @@ -0,0 +1,78 @@ +// +// ModuleRefTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class ModuleRefTable : IMetadataTable { + + public const int RId = 0x1a; + + RowCollection m_rows; + + public ModuleRefRow this [int index] { + get { return m_rows [index] as ModuleRefRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ModuleRefTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitModuleRefTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ModuleRefRow : IMetadataRow { + + public uint Name; + + internal ModuleRefRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitModuleRefRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/NestedClass.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/NestedClass.cs new file mode 100644 index 0000000..9920a64 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/NestedClass.cs @@ -0,0 +1,79 @@ +// +// NestedClassTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class NestedClassTable : IMetadataTable { + + public const int RId = 0x29; + + RowCollection m_rows; + + public NestedClassRow this [int index] { + get { return m_rows [index] as NestedClassRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal NestedClassTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitNestedClassTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class NestedClassRow : IMetadataRow { + + public uint NestedClass; + public uint EnclosingClass; + + internal NestedClassRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitNestedClassRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Param.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Param.cs new file mode 100644 index 0000000..5704ce6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Param.cs @@ -0,0 +1,82 @@ +// +// ParamTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class ParamTable : IMetadataTable { + + public const int RId = 0x08; + + RowCollection m_rows; + + public ParamRow this [int index] { + get { return m_rows [index] as ParamRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ParamTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitParamTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ParamRow : IMetadataRow { + + public ParameterAttributes Flags; + public ushort Sequence; + public uint Name; + + internal ParamRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitParamRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ParamPtr.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ParamPtr.cs new file mode 100644 index 0000000..ffba322 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/ParamPtr.cs @@ -0,0 +1,78 @@ +// +// ParamPtrTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class ParamPtrTable : IMetadataTable { + + public const int RId = 0x07; + + RowCollection m_rows; + + public ParamPtrRow this [int index] { + get { return m_rows [index] as ParamPtrRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal ParamPtrTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitParamPtrTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class ParamPtrRow : IMetadataRow { + + public uint Param; + + internal ParamPtrRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitParamPtrRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Property.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Property.cs new file mode 100644 index 0000000..5f3bcc9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Property.cs @@ -0,0 +1,82 @@ +// +// PropertyTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class PropertyTable : IMetadataTable { + + public const int RId = 0x17; + + RowCollection m_rows; + + public PropertyRow this [int index] { + get { return m_rows [index] as PropertyRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal PropertyTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitPropertyTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class PropertyRow : IMetadataRow { + + public PropertyAttributes Flags; + public uint Name; + public uint Type; + + internal PropertyRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitPropertyRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/PropertyMap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/PropertyMap.cs new file mode 100644 index 0000000..5a3b13c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/PropertyMap.cs @@ -0,0 +1,79 @@ +// +// PropertyMapTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class PropertyMapTable : IMetadataTable { + + public const int RId = 0x15; + + RowCollection m_rows; + + public PropertyMapRow this [int index] { + get { return m_rows [index] as PropertyMapRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal PropertyMapTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitPropertyMapTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class PropertyMapRow : IMetadataRow { + + public uint Parent; + public uint PropertyList; + + internal PropertyMapRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitPropertyMapRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/PropertyPtr.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/PropertyPtr.cs new file mode 100644 index 0000000..f767757 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/PropertyPtr.cs @@ -0,0 +1,78 @@ +// +// PropertyPtrTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Thu Feb 22 14:39:38 CET 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class PropertyPtrTable : IMetadataTable { + + public const int RId = 0x16; + + RowCollection m_rows; + + public PropertyPtrRow this [int index] { + get { return m_rows [index] as PropertyPtrRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal PropertyPtrTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitPropertyPtrTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class PropertyPtrRow : IMetadataRow { + + public uint Property; + + internal PropertyPtrRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitPropertyPtrRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/RowCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/RowCollection.cs new file mode 100644 index 0000000..4da8c4e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/RowCollection.cs @@ -0,0 +1,125 @@ +// +// RowCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + public class RowCollection : ICollection, IMetadataRowVisitable { + + ArrayList m_items; + + public IMetadataRow this [int index] { + get { return m_items [index] as IMetadataRow; } + set { m_items [index] = value; } + } + + public int Count { + get { return m_items.Count; } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + internal RowCollection (int size) + { + m_items = new ArrayList (size); + } + + internal RowCollection () + { + m_items = new ArrayList (); + } + + internal void Add (IMetadataRow value) + { + m_items.Add (value); + } + + public void Clear () + { + m_items.Clear (); + } + + public bool Contains (IMetadataRow value) + { + return m_items.Contains (value); + } + + public int IndexOf (IMetadataRow value) + { + return m_items.IndexOf (value); + } + + public void Insert (int index, IMetadataRow value) + { + m_items.Insert (index, value); + } + + public void Remove (IMetadataRow value) + { + m_items.Remove (value); + } + + public void RemoveAt (int index) + { + m_items.Remove (index); + } + + public void CopyTo (Array ary, int index) + { + m_items.CopyTo (ary, index); + } + + public void Sort (IComparer comp) + { + m_items.Sort (comp); + } + + public IEnumerator GetEnumerator () + { + return m_items.GetEnumerator (); + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitRowCollection (this); + + for (int i = 0; i < m_items.Count; i++) + this [i].Accept (visitor); + + visitor.TerminateRowCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/StandAloneSig.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/StandAloneSig.cs new file mode 100644 index 0000000..cb3c7f9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/StandAloneSig.cs @@ -0,0 +1,78 @@ +// +// StandAloneSigTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class StandAloneSigTable : IMetadataTable { + + public const int RId = 0x11; + + RowCollection m_rows; + + public StandAloneSigRow this [int index] { + get { return m_rows [index] as StandAloneSigRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal StandAloneSigTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitStandAloneSigTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class StandAloneSigRow : IMetadataRow { + + public uint Signature; + + internal StandAloneSigRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitStandAloneSigRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/StringsHeap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/StringsHeap.cs new file mode 100644 index 0000000..6121cf8 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/StringsHeap.cs @@ -0,0 +1,76 @@ +// +// StringsHeap.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System.Collections; + using System.Text; + + public class StringsHeap : MetadataHeap { + + IDictionary m_strings; + + public string this [uint index] { + get { + string str = m_strings [index] as string; + if (str == null) { + str = ReadStringAt (index); + m_strings [index] = str; + } + return str; + } + set { m_strings [index] = value; } + } + + internal StringsHeap (MetadataStream stream) : base (stream, MetadataStream.Strings) + { + m_strings = new Hashtable (); + } + + string ReadStringAt (uint index) + { + if (index > Data.Length - 1) + return string.Empty; + + int length = 0; + for (int i = (int) index; i < Data.Length; i++) { + if (Data [i] == 0) + break; + + length++; + } + + return Encoding.UTF8.GetString (Data, (int) index, length); + } + + public override void Accept (IMetadataVisitor visitor) + { + visitor.VisitStringsHeap (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TableCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TableCollection.cs new file mode 100644 index 0000000..817ccb0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TableCollection.cs @@ -0,0 +1,115 @@ +// +// TableCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + public class TableCollection : ICollection, IMetadataTableVisitable { + + IMetadataTable [] m_tables = new IMetadataTable [TablesHeap.MaxTableCount]; + + TablesHeap m_heap; + + public IMetadataTable this [int index] { + get { return m_tables [index]; } + set { m_tables [index] = value; } + } + + public int Count { + get { + return GetList ().Count; + } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + public TablesHeap Heap { + get { return m_heap; } + } + + internal TableCollection (TablesHeap heap) + { + m_heap = heap; + } + + internal void Add (IMetadataTable value) + { + m_tables [value.Id] = value; + } + + public bool Contains (IMetadataTable value) + { + return m_tables [value.Id] != null; + } + + internal void Remove (IMetadataTable value) + { + m_tables [value.Id] = null; + } + + public void CopyTo (Array array, int index) + { + GetList ().CopyTo (array, index); + } + + internal IList GetList () + { + IList tables = new ArrayList (); + for (int i = 0; i < m_tables.Length; i++) { + IMetadataTable table = m_tables [i]; + if (table != null) + tables.Add (table); + } + + return tables; + } + + public IEnumerator GetEnumerator () + { + return GetList ().GetEnumerator (); + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitTableCollection (this); + + foreach (IMetadataTable table in GetList ()) + table.Accept (visitor); + + visitor.TerminateTableCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TablesHeap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TablesHeap.cs new file mode 100644 index 0000000..583ac7e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TablesHeap.cs @@ -0,0 +1,73 @@ +// +// TablesHeap.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + + public class TablesHeap : MetadataHeap { + + public uint Reserved; + public byte MajorVersion; + public byte MinorVersion; + public byte HeapSizes; + public byte Reserved2; + public long Valid; + public long Sorted; + + TableCollection m_tables; + + public const int MaxTableCount = 45; + + public TableCollection Tables { + get { return m_tables; } + set { m_tables = value; } + } + + public IMetadataTable this [int id] + { + get { return m_tables [id]; } + set { m_tables [id] = value; } + } + + internal TablesHeap (MetadataStream stream) : base(stream, MetadataStream.Tables) + { + } + + public bool HasTable (int id) + { + return (Valid & (1L << id)) != 0; + } + + public override void Accept (IMetadataVisitor visitor) + { + visitor.VisitTablesHeap (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs new file mode 100644 index 0000000..44de804 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TokenType.cs @@ -0,0 +1,58 @@ +// +// TokenType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public enum TokenType : uint { + Module = 0x00000000, + TypeRef = 0x01000000, + TypeDef = 0x02000000, + Field = 0x04000000, + Method = 0x06000000, + Param = 0x08000000, + InterfaceImpl = 0x09000000, + MemberRef = 0x0a000000, + CustomAttribute = 0x0c000000, + Permission = 0x0e000000, + Signature = 0x11000000, + Event = 0x14000000, + Property = 0x17000000, + ModuleRef = 0x1a000000, + TypeSpec = 0x1b000000, + Assembly = 0x20000000, + AssemblyRef = 0x23000000, + File = 0x26000000, + ExportedType = 0x27000000, + ManifestResource = 0x28000000, + GenericParam = 0x2a000000, + MethodSpec = 0x2b000000, + String = 0x70000000, + Name = 0x71000000, + BaseType = 0x72000000 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeDef.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeDef.cs new file mode 100644 index 0000000..d611ac9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeDef.cs @@ -0,0 +1,85 @@ +// +// TypeDefTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using Mono.Cecil; + + public sealed class TypeDefTable : IMetadataTable { + + public const int RId = 0x02; + + RowCollection m_rows; + + public TypeDefRow this [int index] { + get { return m_rows [index] as TypeDefRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal TypeDefTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitTypeDefTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class TypeDefRow : IMetadataRow { + + public TypeAttributes Flags; + public uint Name; + public uint Namespace; + public MetadataToken Extends; + public uint FieldList; + public uint MethodList; + + internal TypeDefRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitTypeDefRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeRef.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeRef.cs new file mode 100644 index 0000000..d27d72e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeRef.cs @@ -0,0 +1,80 @@ +// +// TypeRefTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class TypeRefTable : IMetadataTable { + + public const int RId = 0x01; + + RowCollection m_rows; + + public TypeRefRow this [int index] { + get { return m_rows [index] as TypeRefRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal TypeRefTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitTypeRefTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class TypeRefRow : IMetadataRow { + + public MetadataToken ResolutionScope; + public uint Name; + public uint Namespace; + + internal TypeRefRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitTypeRefRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeSpec.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeSpec.cs new file mode 100644 index 0000000..5c20402 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/TypeSpec.cs @@ -0,0 +1,78 @@ +// +// TypeSpecTable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Oct 10 23:08:26 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + public sealed class TypeSpecTable : IMetadataTable { + + public const int RId = 0x1b; + + RowCollection m_rows; + + public TypeSpecRow this [int index] { + get { return m_rows [index] as TypeSpecRow; } + set { m_rows [index] = value; } + } + + public RowCollection Rows { + get { return m_rows; } + set { m_rows = value; } + } + + public int Id { + get { return RId; } + } + + internal TypeSpecTable () + { + } + + public void Accept (IMetadataTableVisitor visitor) + { + visitor.VisitTypeSpecTable (this); + this.Rows.Accept (visitor.GetRowVisitor ()); + } + } + + public sealed class TypeSpecRow : IMetadataRow { + + public uint Signature; + + internal TypeSpecRow () + { + } + + public void Accept (IMetadataRowVisitor visitor) + { + visitor.VisitTypeSpecRow (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/UserStringsHeap.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/UserStringsHeap.cs new file mode 100644 index 0000000..fb5302f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/UserStringsHeap.cs @@ -0,0 +1,72 @@ +// +// UserStringsHeap.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System.Collections; + using System.Text; + + public class UserStringsHeap : MetadataHeap { + + readonly IDictionary m_strings; + + public string this [uint offset] { + get { + string us = m_strings [offset] as string; + if (us != null) + return us; + + us = ReadStringAt ((int) offset); + if (us != null && us.Length != 0) + m_strings [offset] = us; + + return us; + } + set { m_strings [offset] = value; } + } + + internal UserStringsHeap (MetadataStream stream) : base (stream, MetadataStream.UserStrings) + { + m_strings = new Hashtable (); + } + + string ReadStringAt (int offset) + { + int length = Utilities.ReadCompressedInteger (this.Data, offset, out offset) - 1; + if (length < 1) + return string.Empty; + + return Encoding.Unicode.GetString (this.Data, offset, length); + } + + public override void Accept (IMetadataVisitor visitor) + { + visitor.VisitUserStringsHeap (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs new file mode 100644 index 0000000..cc6353a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Metadata/Utilities.cs @@ -0,0 +1,645 @@ +// +// Utilities.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Tue Jul 17 00:22:33 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Metadata { + + using System; + using System.Collections; + using System.IO; + + class Utilities { + + Utilities () + { + } + + public static int ReadCompressedInteger (byte [] data, int pos, out int start) + { + int integer = 0; + start = pos; + if ((data [pos] & 0x80) == 0) { + integer = data [pos]; + start++; + } else if ((data [pos] & 0x40) == 0) { + integer = (data [start] & ~0x80) << 8; + integer |= data [pos + 1]; + start += 2; + } else { + integer = (data [start] & ~0xc0) << 24; + integer |= data [pos + 1] << 16; + integer |= data [pos + 2] << 8; + integer |= data [pos + 3]; + start += 4; + } + return integer; + } + + public static int WriteCompressedInteger (BinaryWriter writer, int value) + { + if (value < 0x80) + writer.Write ((byte) value); + else if (value < 0x4000) { + writer.Write ((byte) (0x80 | (value >> 8))); + writer.Write ((byte) (value & 0xff)); + } else { + writer.Write ((byte) ((value >> 24) | 0xc0)); + writer.Write ((byte) ((value >> 16) & 0xff)); + writer.Write ((byte) ((value >> 8) & 0xff)); + writer.Write ((byte) (value & 0xff)); + } + return (int) writer.BaseStream.Position; + } + + public static MetadataToken GetMetadataToken (CodedIndex cidx, uint data) + { + uint rid = 0; + switch (cidx) { + case CodedIndex.TypeDefOrRef : + rid = data >> 2; + switch (data & 3) { + case 0 : + return new MetadataToken (TokenType.TypeDef, rid); + case 1 : + return new MetadataToken (TokenType.TypeRef, rid); + case 2 : + return new MetadataToken (TokenType.TypeSpec, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.HasConstant : + rid = data >> 2; + switch (data & 3) { + case 0 : + return new MetadataToken (TokenType.Field, rid); + case 1 : + return new MetadataToken (TokenType.Param, rid); + case 2 : + return new MetadataToken (TokenType.Property, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.HasCustomAttribute : + rid = data >> 5; + switch (data & 31) { + case 0 : + return new MetadataToken (TokenType.Method, rid); + case 1 : + return new MetadataToken (TokenType.Field, rid); + case 2 : + return new MetadataToken (TokenType.TypeRef, rid); + case 3 : + return new MetadataToken (TokenType.TypeDef, rid); + case 4 : + return new MetadataToken (TokenType.Param, rid); + case 5 : + return new MetadataToken (TokenType.InterfaceImpl, rid); + case 6 : + return new MetadataToken (TokenType.MemberRef, rid); + case 7 : + return new MetadataToken (TokenType.Module, rid); + case 8 : + return new MetadataToken (TokenType.Permission, rid); + case 9 : + return new MetadataToken (TokenType.Property, rid); + case 10 : + return new MetadataToken (TokenType.Event, rid); + case 11 : + return new MetadataToken (TokenType.Signature, rid); + case 12 : + return new MetadataToken (TokenType.ModuleRef, rid); + case 13 : + return new MetadataToken (TokenType.TypeSpec, rid); + case 14 : + return new MetadataToken (TokenType.Assembly, rid); + case 15 : + return new MetadataToken (TokenType.AssemblyRef, rid); + case 16 : + return new MetadataToken (TokenType.File, rid); + case 17 : + return new MetadataToken (TokenType.ExportedType, rid); + case 18 : + return new MetadataToken (TokenType.ManifestResource, rid); + case 19 : + return new MetadataToken (TokenType.GenericParam, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.HasFieldMarshal : + rid = data >> 1; + switch (data & 1) { + case 0 : + return new MetadataToken (TokenType.Field, rid); + case 1 : + return new MetadataToken (TokenType.Param, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.HasDeclSecurity : + rid = data >> 2; + switch (data & 3) { + case 0 : + return new MetadataToken (TokenType.TypeDef, rid); + case 1 : + return new MetadataToken (TokenType.Method, rid); + case 2 : + return new MetadataToken (TokenType.Assembly, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.MemberRefParent : + rid = data >> 3; + switch (data & 7) { + case 0 : + return new MetadataToken (TokenType.TypeDef, rid); + case 1 : + return new MetadataToken (TokenType.TypeRef, rid); + case 2 : + return new MetadataToken (TokenType.ModuleRef, rid); + case 3 : + return new MetadataToken (TokenType.Method, rid); + case 4 : + return new MetadataToken (TokenType.TypeSpec, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.HasSemantics : + rid = data >> 1; + switch (data & 1) { + case 0 : + return new MetadataToken (TokenType.Event, rid); + case 1 : + return new MetadataToken (TokenType.Property, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.MethodDefOrRef : + rid = data >> 1; + switch (data & 1) { + case 0 : + return new MetadataToken (TokenType.Method, rid); + case 1 : + return new MetadataToken (TokenType.MemberRef, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.MemberForwarded : + rid = data >> 1; + switch (data & 1) { + case 0 : + return new MetadataToken (TokenType.Field, rid); + case 1 : + return new MetadataToken (TokenType.Method, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.Implementation : + rid = data >> 2; + switch (data & 3) { + case 0 : + return new MetadataToken (TokenType.File, rid); + case 1 : + return new MetadataToken (TokenType.AssemblyRef, rid); + case 2 : + return new MetadataToken (TokenType.ExportedType, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.CustomAttributeType : + rid = data >> 3; + switch (data & 7) { + case 2 : + return new MetadataToken (TokenType.Method, rid); + case 3 : + return new MetadataToken (TokenType.MemberRef, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.ResolutionScope : + rid = data >> 2; + switch (data & 3) { + case 0 : + return new MetadataToken (TokenType.Module, rid); + case 1 : + return new MetadataToken (TokenType.ModuleRef, rid); + case 2 : + return new MetadataToken (TokenType.AssemblyRef, rid); + case 3 : + return new MetadataToken (TokenType.TypeRef, rid); + default : + return MetadataToken.Zero; + } + case CodedIndex.TypeOrMethodDef : + rid = data >> 1; + switch (data & 1) { + case 0 : + return new MetadataToken (TokenType.TypeDef, rid); + case 1 : + return new MetadataToken (TokenType.Method, rid); + default : + return MetadataToken.Zero; + } + default : + return MetadataToken.Zero; + } + } + + public static uint CompressMetadataToken (CodedIndex cidx, MetadataToken token) + { + uint ret = 0; + if (token.RID == 0) + return ret; + switch (cidx) { + case CodedIndex.TypeDefOrRef : + ret = token.RID << 2; + switch (token.TokenType) { + case TokenType.TypeDef : + return ret | 0; + case TokenType.TypeRef : + return ret | 1; + case TokenType.TypeSpec : + return ret | 2; + default : + throw new MetadataFormatException("Non valid Token for TypeDefOrRef"); + } + case CodedIndex.HasConstant : + ret = token.RID << 2; + switch (token.TokenType) { + case TokenType.Field : + return ret | 0; + case TokenType.Param : + return ret | 1; + case TokenType.Property : + return ret | 2; + default : + throw new MetadataFormatException("Non valid Token for HasConstant"); + } + case CodedIndex.HasCustomAttribute : + ret = token.RID << 5; + switch (token.TokenType) { + case TokenType.Method : + return ret | 0; + case TokenType.Field : + return ret | 1; + case TokenType.TypeRef : + return ret | 2; + case TokenType.TypeDef : + return ret | 3; + case TokenType.Param : + return ret | 4; + case TokenType.InterfaceImpl : + return ret | 5; + case TokenType.MemberRef : + return ret | 6; + case TokenType.Module : + return ret | 7; + case TokenType.Permission : + return ret | 8; + case TokenType.Property : + return ret | 9; + case TokenType.Event : + return ret | 10; + case TokenType.Signature : + return ret | 11; + case TokenType.ModuleRef : + return ret | 12; + case TokenType.TypeSpec : + return ret | 13; + case TokenType.Assembly : + return ret | 14; + case TokenType.AssemblyRef : + return ret | 15; + case TokenType.File : + return ret | 16; + case TokenType.ExportedType : + return ret | 17; + case TokenType.ManifestResource : + return ret | 18; + case TokenType.GenericParam : + return ret | 19; + default : + throw new MetadataFormatException("Non valid Token for HasCustomAttribute"); + } + case CodedIndex.HasFieldMarshal : + ret = token.RID << 1; + switch (token.TokenType) { + case TokenType.Field : + return ret | 0; + case TokenType.Param : + return ret | 1; + default : + throw new MetadataFormatException("Non valid Token for HasFieldMarshal"); + } + case CodedIndex.HasDeclSecurity : + ret = token.RID << 2; + switch (token.TokenType) { + case TokenType.TypeDef : + return ret | 0; + case TokenType.Method : + return ret | 1; + case TokenType.Assembly : + return ret | 2; + default : + throw new MetadataFormatException("Non valid Token for HasDeclSecurity"); + } + case CodedIndex.MemberRefParent : + ret = token.RID << 3; + switch (token.TokenType) { + case TokenType.TypeDef : + return ret | 0; + case TokenType.TypeRef : + return ret | 1; + case TokenType.ModuleRef : + return ret | 2; + case TokenType.Method : + return ret | 3; + case TokenType.TypeSpec : + return ret | 4; + default : + throw new MetadataFormatException("Non valid Token for MemberRefParent"); + } + case CodedIndex.HasSemantics : + ret = token.RID << 1; + switch (token.TokenType) { + case TokenType.Event : + return ret | 0; + case TokenType.Property : + return ret | 1; + default : + throw new MetadataFormatException("Non valid Token for HasSemantics"); + } + case CodedIndex.MethodDefOrRef : + ret = token.RID << 1; + switch (token.TokenType) { + case TokenType.Method : + return ret | 0; + case TokenType.MemberRef : + return ret | 1; + default : + throw new MetadataFormatException("Non valid Token for MethodDefOrRef"); + } + case CodedIndex.MemberForwarded : + ret = token.RID << 1; + switch (token.TokenType) { + case TokenType.Field : + return ret | 0; + case TokenType.Method : + return ret | 1; + default : + throw new MetadataFormatException("Non valid Token for MemberForwarded"); + } + case CodedIndex.Implementation : + ret = token.RID << 2; + switch (token.TokenType) { + case TokenType.File : + return ret | 0; + case TokenType.AssemblyRef : + return ret | 1; + case TokenType.ExportedType : + return ret | 2; + default : + throw new MetadataFormatException("Non valid Token for Implementation"); + } + case CodedIndex.CustomAttributeType : + ret = token.RID << 3; + switch (token.TokenType) { + case TokenType.Method : + return ret | 2; + case TokenType.MemberRef : + return ret | 3; + default : + throw new MetadataFormatException("Non valid Token for CustomAttributeType"); + } + case CodedIndex.ResolutionScope : + ret = token.RID << 2; + switch (token.TokenType) { + case TokenType.Module : + return ret | 0; + case TokenType.ModuleRef : + return ret | 1; + case TokenType.AssemblyRef : + return ret | 2; + case TokenType.TypeRef : + return ret | 3; + default : + throw new MetadataFormatException("Non valid Token for ResolutionScope"); + } + case CodedIndex.TypeOrMethodDef : + ret = token.RID << 1; + switch (token.TokenType) { + case TokenType.TypeDef : + return ret | 0; + case TokenType.Method : + return ret | 1; + default : + throw new MetadataFormatException("Non valid Token for TypeOrMethodDef"); + } + default : + throw new MetadataFormatException ("Non valid CodedIndex"); + } + } + + internal static Type GetCorrespondingTable (TokenType t) + { + switch (t) { + case TokenType.Assembly : + return typeof (AssemblyTable); + case TokenType.AssemblyRef : + return typeof (AssemblyRefTable); + case TokenType.CustomAttribute : + return typeof (CustomAttributeTable); + case TokenType.Event : + return typeof (EventTable); + case TokenType.ExportedType : + return typeof (ExportedTypeTable); + case TokenType.Field : + return typeof (FieldTable); + case TokenType.File : + return typeof (FileTable); + case TokenType.InterfaceImpl : + return typeof (InterfaceImplTable); + case TokenType.MemberRef : + return typeof (MemberRefTable); + case TokenType.Method : + return typeof (MethodTable); + case TokenType.Module : + return typeof (ModuleTable); + case TokenType.ModuleRef : + return typeof (ModuleRefTable); + case TokenType.Param : + return typeof (ParamTable); + case TokenType.Permission : + return typeof (DeclSecurityTable); + case TokenType.Property : + return typeof (PropertyTable); + case TokenType.Signature : + return typeof (StandAloneSigTable); + case TokenType.TypeDef : + return typeof (TypeDefTable); + case TokenType.TypeRef : + return typeof (TypeRefTable); + case TokenType.TypeSpec : + return typeof (TypeSpecTable); + default : + return null; + } + } + + internal delegate int TableRowCounter (int rid); + + internal static int GetCodedIndexSize (CodedIndex ci, TableRowCounter rowCounter, IDictionary codedIndexCache) + { + int bits = 0, max = 0; + if (codedIndexCache [ci] != null) + return (int) codedIndexCache [ci]; + + int res = 0; + int [] rids; + switch (ci) { + case CodedIndex.TypeDefOrRef : + bits = 2; + rids = new int [3]; + rids [0] = TypeDefTable.RId; + rids [1] = TypeRefTable.RId; + rids [2] = TypeSpecTable.RId; + break; + case CodedIndex.HasConstant : + bits = 2; + rids = new int [3]; + rids [0] = FieldTable.RId; + rids [1] = ParamTable.RId; + rids [2] = PropertyTable.RId; + break; + case CodedIndex.HasCustomAttribute : + bits = 5; + rids = new int [20]; + rids [0] = MethodTable.RId; + rids [1] = FieldTable.RId; + rids [2] = TypeRefTable.RId; + rids [3] = TypeDefTable.RId; + rids [4] = ParamTable.RId; + rids [5] = InterfaceImplTable.RId; + rids [6] = MemberRefTable.RId; + rids [7] = ModuleTable.RId; + rids [8] = DeclSecurityTable.RId; + rids [9] = PropertyTable.RId; + rids [10] = EventTable.RId; + rids [11] = StandAloneSigTable.RId; + rids [12] = ModuleRefTable.RId; + rids [13] = TypeSpecTable.RId; + rids [14] = AssemblyTable.RId; + rids [15] = AssemblyRefTable.RId; + rids [16] = FileTable.RId; + rids [17] = ExportedTypeTable.RId; + rids [18] = ManifestResourceTable.RId; + rids [19] = GenericParamTable.RId; + break; + case CodedIndex.HasFieldMarshal : + bits = 1; + rids = new int [2]; + rids [0] = FieldTable.RId; + rids [1] = ParamTable.RId; + break; + case CodedIndex.HasDeclSecurity : + bits = 2; + rids = new int [3]; + rids [0] = TypeDefTable.RId; + rids [1] = MethodTable.RId; + rids [2] = AssemblyTable.RId; + break; + case CodedIndex.MemberRefParent : + bits = 3; + rids = new int [5]; + rids [0] = TypeDefTable.RId; + rids [1] = TypeRefTable.RId; + rids [2] = ModuleRefTable.RId; + rids [3] = MethodTable.RId; + rids [4] = TypeSpecTable.RId; + break; + case CodedIndex.HasSemantics : + bits = 1; + rids = new int [2]; + rids [0] = EventTable.RId; + rids [1] = PropertyTable.RId; + break; + case CodedIndex.MethodDefOrRef : + bits = 1; + rids = new int [2]; + rids [0] = MethodTable.RId; + rids [1] = MemberRefTable.RId; + break; + case CodedIndex.MemberForwarded : + bits = 1; + rids = new int [2]; + rids [0] = FieldTable.RId; + rids [1] = MethodTable.RId; + break; + case CodedIndex.Implementation : + bits = 2; + rids = new int [3]; + rids [0] = FileTable.RId; + rids [1] = AssemblyRefTable.RId; + rids [2] = ExportedTypeTable.RId; + break; + case CodedIndex.CustomAttributeType : + bits = 3; + rids = new int [2]; + rids [0] = MethodTable.RId; + rids [1] = MemberRefTable.RId; + break; + case CodedIndex.ResolutionScope : + bits = 2; + rids = new int [4]; + rids [0] = ModuleTable.RId; + rids [1] = ModuleRefTable.RId; + rids [2] = AssemblyRefTable.RId; + rids [3] = TypeRefTable.RId; + break; + case CodedIndex.TypeOrMethodDef : + bits = 1; + rids = new int [2]; + rids [0] = TypeDefTable.RId; + rids [1] = MethodTable.RId; + break; + default : + throw new MetadataFormatException ("Non valid CodedIndex"); + } + + for (int i = 0; i < rids.Length; i++) { + int rows = rowCounter (rids [i]); + if (rows > max) max = rows; + } + + res = max < (1 << (16 - bits)) ? 2 : 4; + codedIndexCache [ci] = res; + return res; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Array.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Array.cs new file mode 100644 index 0000000..c708963 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Array.cs @@ -0,0 +1,43 @@ +// +// Array.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class ARRAY : SigType { + + public CustomMod [] CustomMods; + public SigType Type; + public ArrayShape Shape; + + public ARRAY () : base (ElementType.Array) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ArrayShape.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ArrayShape.cs new file mode 100644 index 0000000..7cf3940 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ArrayShape.cs @@ -0,0 +1,43 @@ +// +// ArrayShape.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class ArrayShape { + + public int Rank; + public int NumSizes; + public int [] Sizes; + public int NumLoBounds; + public int [] LoBounds; + + public ArrayShape () + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/BaseSignatureVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/BaseSignatureVisitor.cs new file mode 100644 index 0000000..0a37a5b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/BaseSignatureVisitor.cs @@ -0,0 +1,53 @@ +// +// BaseSignatureVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal abstract class BaseSignatureVisitor : ISignatureVisitor { + + public virtual void VisitMethodDefSig (MethodDefSig methodDef) + { + } + + public virtual void VisitMethodRefSig (MethodRefSig methodRef) + { + } + + public virtual void VisitFieldSig (FieldSig field) + { + } + + public virtual void VisitPropertySig (PropertySig property) + { + } + + public virtual void VisitLocalVarSig (LocalVarSig localvar) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Class.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Class.cs new file mode 100644 index 0000000..ef908e6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Class.cs @@ -0,0 +1,41 @@ +// +// Class.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class CLASS : SigType { + + public MetadataToken Type; + + public CLASS () : base (ElementType.Class) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Constraint.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Constraint.cs new file mode 100644 index 0000000..416707b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Constraint.cs @@ -0,0 +1,37 @@ +// +// Constraints.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal enum Constraint : byte { + None = 0x0, + Pinned = (byte) ElementType.Pinned + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/CustomAttrib.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/CustomAttrib.cs new file mode 100644 index 0000000..aca30e2 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/CustomAttrib.cs @@ -0,0 +1,80 @@ +// +// CustomAttrib.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class CustomAttrib { + + public const ushort StdProlog = 0x0001; + + public MethodReference Constructor; + + public ushort Prolog; + public FixedArg [] FixedArgs; + public ushort NumNamed; + public NamedArg [] NamedArgs; + public bool Read; + + public CustomAttrib (MethodReference ctor) + { + Constructor = ctor; + } + + public struct FixedArg { + + public bool SzArray; + public uint NumElem; + public Elem [] Elems; + } + + public struct Elem { + + public bool Simple; + public bool String; + public bool Type; + public bool BoxedValueType; + + public ElementType FieldOrPropType; + public object Value; + + public TypeReference ElemType; + } + + public struct NamedArg { + + public bool Field; + public bool Property; + + public ElementType FieldOrPropType; + public string FieldOrPropName; + public FixedArg FixedArg; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/CustomMod.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/CustomMod.cs new file mode 100644 index 0000000..242f4d2 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/CustomMod.cs @@ -0,0 +1,48 @@ +// +// CustomMod.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class CustomMod { + + public enum CMODType : byte { + None = 0x0, + OPT = (byte) ElementType.CModOpt, + REQD = (byte) ElementType.CModReqD + } + + public CMODType CMOD; + public MetadataToken TypeDefOrRef; + + public CustomMod () + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/FieldSig.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/FieldSig.cs new file mode 100644 index 0000000..a01c058 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/FieldSig.cs @@ -0,0 +1,50 @@ +// +// FieldSig.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class FieldSig : Signature { + + public bool Field; + public CustomMod [] CustomMods; + public SigType Type; + + public FieldSig () : base () + { + } + + public FieldSig (uint blobIndex) : base (blobIndex) + { + } + + public override void Accept (ISignatureVisitor visitor) + { + visitor.VisitFieldSig (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/FnPtr.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/FnPtr.cs new file mode 100644 index 0000000..02fc330 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/FnPtr.cs @@ -0,0 +1,41 @@ +// +// FnPtr.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class FNPTR : SigType { + + public MethodSig Method; + + public FNPTR () : base (ElementType.FnPtr) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericArg.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericArg.cs new file mode 100644 index 0000000..74edb4a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericArg.cs @@ -0,0 +1,41 @@ +// +// GenericArg.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + class GenericArg { + + public CustomMod [] CustomMods; + public SigType Type; + + public GenericArg (SigType type) + { + Type = type; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericInst.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericInst.cs new file mode 100644 index 0000000..02bd111 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericInst.cs @@ -0,0 +1,46 @@ +// +// GenericInst.cs +// +// Author: +// Martin Baulig <baulig@ximian.com> +// Jb Evain <jbevain@gmail.com> +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil; + using Mono.Cecil.Metadata; + + internal sealed class GENERICINST : SigType { + + public bool ValueType; + public MetadataToken Type; + + public GenericInstSignature Signature; + + public GENERICINST () : base (ElementType.GenericInst) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericInstSignature.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericInstSignature.cs new file mode 100644 index 0000000..94d41c4 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/GenericInstSignature.cs @@ -0,0 +1,40 @@ +// +// GenericInstSignature.cs +// +// Author: +// Martin Baulig <martin@ximian.com> +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class GenericInstSignature { + + public int Arity; + public GenericArg [] Types; + + public GenericInstSignature () + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitable.cs new file mode 100644 index 0000000..81374f0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitable.cs @@ -0,0 +1,35 @@ +// +// ISignatureVisitable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal interface ISignatureVisitable { + + void Accept (ISignatureVisitor visitor); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitor.cs new file mode 100644 index 0000000..e473e87 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ISignatureVisitor.cs @@ -0,0 +1,39 @@ +// +// ISignatureVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal interface ISignatureVisitor { + + void VisitMethodDefSig (MethodDefSig methodDef); + void VisitMethodRefSig (MethodRefSig methodRef); + void VisitFieldSig (FieldSig field); + void VisitPropertySig (PropertySig property); + void VisitLocalVarSig (LocalVarSig localvar); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/InputOutputItem.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/InputOutputItem.cs new file mode 100644 index 0000000..5240a81 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/InputOutputItem.cs @@ -0,0 +1,38 @@ +// +// InputOutputItem.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal abstract class InputOutputItem { + + public CustomMod [] CustomMods; + public bool ByRef; + public SigType Type; + public bool TypedByRef; + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/LocalVarSig.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/LocalVarSig.cs new file mode 100644 index 0000000..071c90c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/LocalVarSig.cs @@ -0,0 +1,58 @@ +// +// LocalVarSig.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class LocalVarSig : Signature { + + public bool Local; + public int Count; + public LocalVariable [] LocalVariables; + + public LocalVarSig () : base () + { + } + + public LocalVarSig (uint blobIndex) : base (blobIndex) + { + } + + public override void Accept (ISignatureVisitor visitor) + { + visitor.VisitLocalVarSig (this); + } + + public struct LocalVariable { + + public CustomMod [] CustomMods; + public Constraint Constraint; + public bool ByRef; + public SigType Type; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MVar.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MVar.cs new file mode 100644 index 0000000..3fca4a4 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MVar.cs @@ -0,0 +1,42 @@ +// +// MVar.cs +// +// Author: +// Martin Baulig <martin@ximian.com> +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class MVAR : SigType { + + public int Index; + + public MVAR (int index) : base (ElementType.MVar) + { + this.Index = index; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MarshalSig.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MarshalSig.cs new file mode 100644 index 0000000..4b99c57 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MarshalSig.cs @@ -0,0 +1,93 @@ +// +// MarshalSig.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using System; + + using Mono.Cecil; + + internal sealed class MarshalSig { + + public NativeType NativeInstrinsic; + public IMarshalSigSpec Spec; + + public MarshalSig (NativeType nt) + { + this.NativeInstrinsic = nt; + } + + public interface IMarshalSigSpec { + } + + public sealed class Array : IMarshalSigSpec { + + public NativeType ArrayElemType; + public int ParamNum; + public int ElemMult; + public int NumElem; + + public Array () + { + this.ParamNum = 0; + this.ElemMult = 0; + this.NumElem = 0; + } + } + + public sealed class CustomMarshaler : IMarshalSigSpec { + + public string Guid; + public string UnmanagedType; + public string ManagedType; + public string Cookie; + } + + public sealed class FixedArray : IMarshalSigSpec { + + public int NumElem; + public NativeType ArrayElemType; + + public FixedArray () + { + this.NumElem = 0; + this.ArrayElemType = NativeType.NONE; + } + } + + public sealed class SafeArray : IMarshalSigSpec { + + public VariantType ArrayElemType; + } + + public sealed class FixedSysString : IMarshalSigSpec { + + public int Size; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodDefSig.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodDefSig.cs new file mode 100644 index 0000000..b7e2e58 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodDefSig.cs @@ -0,0 +1,48 @@ +// +// MethodDefSig.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class MethodDefSig : MethodRefSig { + + public int GenericParameterCount; + + public MethodDefSig () : this (0) + { + } + + public MethodDefSig (uint blobIndex) : base (blobIndex) + { + } + + public override void Accept (ISignatureVisitor visitor) + { + visitor.VisitMethodDefSig (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodRefSig.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodRefSig.cs new file mode 100644 index 0000000..63cc35b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodRefSig.cs @@ -0,0 +1,49 @@ +// +// MethodRefSig.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal class MethodRefSig : MethodSig { + + public int Sentinel; + + public MethodRefSig () : this (0) + { + } + + public MethodRefSig (uint blobIndex) : base (blobIndex) + { + Sentinel = -1; + } + + public override void Accept (ISignatureVisitor visitor) + { + visitor.VisitMethodRefSig (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodSig.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodSig.cs new file mode 100644 index 0000000..3b65809 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodSig.cs @@ -0,0 +1,50 @@ +// +// MethodSig.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using Mono.Cecil; + +namespace Mono.Cecil.Signatures { + + internal abstract class MethodSig : Signature { + + public bool HasThis; + public bool ExplicitThis; + public MethodCallingConvention MethCallConv; + public int ParamCount; + public RetType RetType; + public Param [] Parameters; + + public MethodSig () : base () + { + } + + public MethodSig (uint blobIndex) : base (blobIndex) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodSpec.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodSpec.cs new file mode 100644 index 0000000..0ad0f8b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/MethodSpec.cs @@ -0,0 +1,40 @@ +// +// TypeSpec.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class MethodSpec { + + public GenericInstSignature Signature; + + public MethodSpec (GenericInstSignature sig) + { + this.Signature = sig; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Param.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Param.cs new file mode 100644 index 0000000..0bd7a0d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Param.cs @@ -0,0 +1,33 @@ +// +// Param.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class Param : InputOutputItem { + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/PropertySig.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/PropertySig.cs new file mode 100644 index 0000000..5db0820 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/PropertySig.cs @@ -0,0 +1,52 @@ +// +// PropertySig.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class PropertySig : Signature { + + public bool Property; + public int ParamCount; + public CustomMod [] CustomMods; + public SigType Type; + public Param [] Parameters; + + public PropertySig () : base () + { + } + + public PropertySig (uint blobIndex) : base (blobIndex) + { + } + + public override void Accept (ISignatureVisitor visitor) + { + visitor.VisitPropertySig (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Ptr.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Ptr.cs new file mode 100644 index 0000000..e95394d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Ptr.cs @@ -0,0 +1,43 @@ +// +// Ptr.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class PTR : SigType { + + public CustomMod [] CustomMods; + public SigType PtrType; + public bool Void; + + public PTR () : base (ElementType.Ptr) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/RetType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/RetType.cs new file mode 100644 index 0000000..6541211 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/RetType.cs @@ -0,0 +1,39 @@ +// +// RetType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class RetType : InputOutputItem { + + public bool Void; + + public RetType () + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SigType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SigType.cs new file mode 100644 index 0000000..6e2d19b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SigType.cs @@ -0,0 +1,42 @@ +// +// SigType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal class SigType { + + public ElementType ElementType; + + public SigType (ElementType elem) + { + ElementType = elem; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Signature.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Signature.cs new file mode 100644 index 0000000..5d9e254 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Signature.cs @@ -0,0 +1,50 @@ +// +// Signature.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using System; + + internal abstract class Signature : ISignatureVisitable { + + public byte CallingConvention; + public uint BlobIndex; + + public Signature (uint blobIndex) + { + BlobIndex = blobIndex; + } + + public Signature () + { + BlobIndex = 0; + } + + public abstract void Accept (ISignatureVisitor visitor); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs new file mode 100644 index 0000000..97f8761 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SignatureReader.cs @@ -0,0 +1,961 @@ +// +// SignatureReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using System; + using System.Collections; + using System.IO; + using System.Text; + + using Mono.Cecil; + using Mono.Cecil.Metadata; + + internal sealed class SignatureReader : BaseSignatureVisitor { + + MetadataRoot m_root; + ReflectionReader m_reflectReader; + byte [] m_blobData; + + IDictionary m_signatures; + + IAssemblyResolver AssemblyResolver { + get { return m_reflectReader.Module.Assembly.Resolver; } + } + + public SignatureReader (MetadataRoot root, ReflectionReader reflectReader) + { + m_root = root; + m_reflectReader = reflectReader; + + m_blobData = m_root.Streams.BlobHeap != null ? m_root.Streams.BlobHeap.Data : new byte [0]; + + m_signatures = new Hashtable (); + } + + public FieldSig GetFieldSig (uint index) + { + FieldSig f = m_signatures [index] as FieldSig; + if (f == null) { + f = new FieldSig (index); + f.Accept (this); + m_signatures [index] = f; + } + return f; + } + + public PropertySig GetPropSig (uint index) + { + PropertySig p = m_signatures [index] as PropertySig; + if (p == null) { + p = new PropertySig (index); + p.Accept (this); + m_signatures [index] = p; + } + return p; + } + + public MethodDefSig GetMethodDefSig (uint index) + { + MethodDefSig m = m_signatures [index] as MethodDefSig; + if (m == null) { + m = new MethodDefSig (index); + m.Accept (this); + m_signatures [index] = m; + } + return m; + } + + public MethodRefSig GetMethodRefSig (uint index) + { + MethodRefSig m = m_signatures [index] as MethodRefSig; + if (m == null) { + m = new MethodRefSig (index); + m.Accept (this); + m_signatures [index] = m; + } + return m; + } + + public TypeSpec GetTypeSpec (uint index) + { + TypeSpec ts = m_signatures [index] as TypeSpec; + + if (ts == null) { + ts = ReadTypeSpec (m_blobData, (int) index); + m_signatures [index] = ts; + } + + return ts; + } + + public MethodSpec GetMethodSpec (uint index) + { + MethodSpec ms = m_signatures [index] as MethodSpec; + + if (ms == null) { + ms = ReadMethodSpec (m_blobData, (int) index); + m_signatures [index] = ms; + } + + return ms; + } + + public LocalVarSig GetLocalVarSig (uint index) + { + LocalVarSig lv = m_signatures [index] as LocalVarSig; + if (lv == null) { + lv = new LocalVarSig (index); + lv.Accept (this); + m_signatures [index] = lv; + } + return lv; + } + + public CustomAttrib GetCustomAttrib (uint index, MethodReference ctor) + { + return GetCustomAttrib (index, ctor, false); + } + + public CustomAttrib GetCustomAttrib (uint index, MethodReference ctor, bool resolve) + { + return ReadCustomAttrib ((int) index, ctor, resolve); + } + + public CustomAttrib GetCustomAttrib (byte [] data, MethodReference ctor) + { + return GetCustomAttrib (data, ctor, false); + } + + public CustomAttrib GetCustomAttrib (byte [] data, MethodReference ctor, bool resolve) + { + BinaryReader br = new BinaryReader (new MemoryStream (data)); + return ReadCustomAttrib (br, data, ctor, resolve); + } + + public Signature GetMemberRefSig (TokenType tt, uint index) + { + int start, callconv; + Utilities.ReadCompressedInteger (m_blobData, (int) index, out start); + callconv = m_blobData [start]; + if ((callconv & 0x5) == 0x5 || (callconv & 0x10) == 0x10) // vararg || generic? + return GetMethodDefSig (index); + if ((callconv & 0x6) != 0) // field ? + return GetFieldSig (index); + + switch (tt) { + case TokenType.TypeDef : + case TokenType.TypeRef : + case TokenType.TypeSpec : + return GetMethodRefSig (index); + case TokenType.ModuleRef : + case TokenType.Method : + return GetMethodDefSig (index); + } + return null; + } + + public MarshalSig GetMarshalSig (uint index) + { + MarshalSig ms = m_signatures [index] as MarshalSig; + if (ms == null) { + byte [] data = m_root.Streams.BlobHeap.Read (index); + ms = ReadMarshalSig (data); + m_signatures [index] = ms; + } + return ms; + } + + public MethodSig GetStandAloneMethodSig (uint index) + { + byte [] data = m_root.Streams.BlobHeap.Read (index); + int start; + if ((data [0] & 0x5) > 0) { + MethodRefSig mrs = new MethodRefSig (index); + ReadMethodRefSig (mrs, data, 0, out start); + return mrs; + } else { + MethodDefSig mds = new MethodDefSig (index); + ReadMethodDefSig (mds, data, 0, out start); + return mds; + } + } + + public override void VisitMethodDefSig (MethodDefSig methodDef) + { + int start; + ReadMethodDefSig (methodDef, m_root.Streams.BlobHeap.Read (methodDef.BlobIndex), 0, out start); + } + + public override void VisitMethodRefSig (MethodRefSig methodRef) + { + int start; + ReadMethodRefSig (methodRef, m_root.Streams.BlobHeap.Read (methodRef.BlobIndex), 0, out start); + } + + public override void VisitFieldSig (FieldSig field) + { + int start; + Utilities.ReadCompressedInteger (m_blobData, (int) field.BlobIndex, out start); + field.CallingConvention = m_blobData [start]; + field.Field = (field.CallingConvention & 0x6) != 0; + field.CustomMods = ReadCustomMods (m_blobData, start + 1, out start); + field.Type = ReadType (m_blobData, start, out start); + } + + public override void VisitPropertySig (PropertySig property) + { + int start; + Utilities.ReadCompressedInteger (m_blobData, (int) property.BlobIndex, out start); + property.CallingConvention = m_blobData [start]; + property.Property = (property.CallingConvention & 0x8) != 0; + property.ParamCount = Utilities.ReadCompressedInteger (m_blobData, start + 1, out start); + property.CustomMods = ReadCustomMods (m_blobData, start, out start); + property.Type = ReadType (m_blobData, start, out start); + property.Parameters = ReadParameters (property.ParamCount, m_blobData, start); + } + + public override void VisitLocalVarSig (LocalVarSig localvar) + { + int start; + Utilities.ReadCompressedInteger (m_blobData, (int) localvar.BlobIndex, out start); + localvar.CallingConvention = m_blobData [start]; + localvar.Local = (localvar.CallingConvention & 0x7) != 0; + localvar.Count = Utilities.ReadCompressedInteger (m_blobData, start + 1, out start); + localvar.LocalVariables = ReadLocalVariables (localvar.Count, m_blobData, start); + } + + void ReadMethodDefSig (MethodDefSig methodDef, byte [] data, int pos, out int start) + { + methodDef.CallingConvention = data [pos]; + start = pos + 1; + methodDef.HasThis = (methodDef.CallingConvention & 0x20) != 0; + methodDef.ExplicitThis = (methodDef.CallingConvention & 0x40) != 0; + if ((methodDef.CallingConvention & 0x5) != 0) + methodDef.MethCallConv |= MethodCallingConvention.VarArg; + else if ((methodDef.CallingConvention & 0x10) != 0) { + methodDef.MethCallConv |= MethodCallingConvention.Generic; + methodDef.GenericParameterCount = Utilities.ReadCompressedInteger (data, start, out start); + } else + methodDef.MethCallConv |= MethodCallingConvention.Default; + + methodDef.ParamCount = Utilities.ReadCompressedInteger (data, start, out start); + methodDef.RetType = ReadRetType (data, start, out start); + int sentpos; + methodDef.Parameters = ReadParameters (methodDef.ParamCount, data, start, out sentpos); + methodDef.Sentinel = sentpos; + } + + void ReadMethodRefSig (MethodRefSig methodRef, byte [] data, int pos, out int start) + { + methodRef.CallingConvention = data [pos]; + start = pos + 1; + methodRef.HasThis = (methodRef.CallingConvention & 0x20) != 0; + methodRef.ExplicitThis = (methodRef.CallingConvention & 0x40) != 0; + if ((methodRef.CallingConvention & 0x1) != 0) + methodRef.MethCallConv |= MethodCallingConvention.C; + else if ((methodRef.CallingConvention & 0x2) != 0) + methodRef.MethCallConv |= MethodCallingConvention.StdCall; + else if ((methodRef.CallingConvention & 0x3) != 0) + methodRef.MethCallConv |= MethodCallingConvention.ThisCall; + else if ((methodRef.CallingConvention & 0x4) != 0) + methodRef.MethCallConv |= MethodCallingConvention.FastCall; + else if ((methodRef.CallingConvention & 0x5) != 0) + methodRef.MethCallConv |= MethodCallingConvention.VarArg; + else + methodRef.MethCallConv |= MethodCallingConvention.Default; + methodRef.ParamCount = Utilities.ReadCompressedInteger (data, start, out start); + methodRef.RetType = ReadRetType (data, start, out start); + int sentpos; + methodRef.Parameters = ReadParameters (methodRef.ParamCount, data, start, out sentpos); + methodRef.Sentinel = sentpos; + } + + LocalVarSig.LocalVariable [] ReadLocalVariables (int length, byte [] data, int pos) + { + int start = pos; + LocalVarSig.LocalVariable [] types = new LocalVarSig.LocalVariable [length]; + for (int i = 0; i < length; i++) + types [i] = ReadLocalVariable (data, start, out start); + return types; + } + + LocalVarSig.LocalVariable ReadLocalVariable (byte [] data, int pos, out int start) + { + start = pos; + LocalVarSig.LocalVariable lv = new LocalVarSig.LocalVariable (); + lv.ByRef = false; + int cursor; + while (true) { + lv.CustomMods = ReadCustomMods (data, start, out start); + cursor = start; + int current = Utilities.ReadCompressedInteger (data, start, out start); + if (current == (int) ElementType.Pinned) // the only possible constraint + lv.Constraint |= Constraint.Pinned; + else if (current == (int) ElementType.ByRef) { + lv.ByRef = true; + + if (lv.CustomMods == null || lv.CustomMods.Length == 0) + lv.CustomMods = ReadCustomMods (data, start, out start); + } else { + lv.Type = ReadType (data, cursor, out start); + break; + } + } + return lv; + } + + TypeSpec ReadTypeSpec (byte [] data, int pos) + { + int start = pos; + Utilities.ReadCompressedInteger (data, start, out start); + TypeSpec ts = new TypeSpec (); + ts.CustomMods = ReadCustomMods (data, start, out start); + ts.Type = ReadType (data, start, out start); + return ts; + } + + MethodSpec ReadMethodSpec (byte [] data, int pos) + { + int start = pos; + + Utilities.ReadCompressedInteger (data, start, out start); + if (Utilities.ReadCompressedInteger (data, start, out start) != 0x0a) + throw new ReflectionException ("Invalid MethodSpec signature"); + + return new MethodSpec (ReadGenericInstSignature (data, start, out start)); + } + + RetType ReadRetType (byte [] data, int pos, out int start) + { + RetType rt = new RetType (); + start = pos; + rt.CustomMods = ReadCustomMods (data, start, out start); + int curs = start; + ElementType flag = (ElementType) Utilities.ReadCompressedInteger (data, start, out start); + switch (flag) { + case ElementType.Void : + rt.ByRef = rt.TypedByRef = false; + rt.Void = true; + break; + case ElementType.TypedByRef : + rt.ByRef = rt.Void = false; + rt.TypedByRef = true; + break; + case ElementType.ByRef : + rt.TypedByRef = rt.Void = false; + rt.ByRef = true; + + if (rt.CustomMods == null || rt.CustomMods.Length == 0) + rt.CustomMods = ReadCustomMods (data, start, out start); + + rt.Type = ReadType (data, start, out start); + break; + default : + rt.TypedByRef = rt.Void = rt.ByRef = false; + rt.Type = ReadType (data, curs, out start); + break; + } + return rt; + } + + Param [] ReadParameters (int length, byte [] data, int pos) + { + Param [] ret = new Param [length]; + int start = pos; + for (int i = 0; i < length; i++) + ret [i] = ReadParameter (data, start, out start); + return ret; + } + + Param [] ReadParameters (int length, byte [] data, int pos, out int sentinelpos) + { + Param [] ret = new Param [length]; + int start = pos; + sentinelpos = -1; + + for (int i = 0; i < length; i++) { + int curs = start; + int flag = Utilities.ReadCompressedInteger (data, start, out start); + + if (flag == (int) ElementType.Sentinel) { + sentinelpos = i; + curs = start; + } + + ret [i] = ReadParameter (data, curs, out start); + } + + return ret; + } + + Param ReadParameter (byte [] data, int pos, out int start) + { + Param p = new Param (); + start = pos; + + p.CustomMods = ReadCustomMods (data, start, out start); + int curs = start; + ElementType flag = (ElementType) Utilities.ReadCompressedInteger (data, start, out start); + switch (flag) { + case ElementType.TypedByRef : + p.TypedByRef = true; + p.ByRef = false; + break; + case ElementType.ByRef : + p.TypedByRef = false; + p.ByRef = true; + + if (p.CustomMods == null || p.CustomMods.Length == 0) + p.CustomMods = ReadCustomMods (data, start, out start); + + p.Type = ReadType (data, start, out start); + break; + default : + p.TypedByRef = false; + p.ByRef = false; + p.Type = ReadType (data, curs, out start); + break; + } + return p; + } + + SigType ReadType (byte [] data, int pos, out int start) + { + start = pos; + ElementType element = (ElementType) Utilities.ReadCompressedInteger (data, start, out start); + switch (element) { + case ElementType.ValueType : + VALUETYPE vt = new VALUETYPE (); + vt.Type = Utilities.GetMetadataToken(CodedIndex.TypeDefOrRef, + (uint) Utilities.ReadCompressedInteger (data, start, out start)); + return vt; + case ElementType.Class : + CLASS c = new CLASS (); + c.Type = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef, + (uint) Utilities.ReadCompressedInteger (data, start, out start)); + return c; + case ElementType.Ptr : + PTR p = new PTR (); + int buf = start; + int flag = Utilities.ReadCompressedInteger (data, start, out start); + p.Void = flag == (int) ElementType.Void; + if (p.Void) + return p; + start = buf; + p.CustomMods = ReadCustomMods (data, start, out start); + p.PtrType = ReadType (data, start, out start); + return p; + case ElementType.FnPtr : + FNPTR fp = new FNPTR (); + if ((data [start] & 0x5) != 0) { + MethodRefSig mr = new MethodRefSig ((uint) start); + ReadMethodRefSig (mr, data, start, out start); + fp.Method = mr; + } else { + MethodDefSig md = new MethodDefSig ((uint) start); + ReadMethodDefSig (md, data, start, out start); + fp.Method = md; + } + return fp; + case ElementType.Array : + ARRAY ary = new ARRAY (); + ary.CustomMods = ReadCustomMods (data, start, out start); + ArrayShape shape = new ArrayShape (); + ary.Type = ReadType (data, start, out start); + shape.Rank = Utilities.ReadCompressedInteger (data, start, out start); + shape.NumSizes = Utilities.ReadCompressedInteger (data, start, out start); + shape.Sizes = new int [shape.NumSizes]; + for (int i = 0; i < shape.NumSizes; i++) + shape.Sizes [i] = Utilities.ReadCompressedInteger (data, start, out start); + shape.NumLoBounds = Utilities.ReadCompressedInteger (data, start, out start); + shape.LoBounds = new int [shape.NumLoBounds]; + for (int i = 0; i < shape.NumLoBounds; i++) + shape.LoBounds [i] = Utilities.ReadCompressedInteger (data, start, out start); + ary.Shape = shape; + return ary; + case ElementType.SzArray : + SZARRAY sa = new SZARRAY (); + sa.CustomMods = ReadCustomMods (data, start, out start); + sa.Type = ReadType (data, start, out start); + return sa; + case ElementType.Var: + return new VAR (Utilities.ReadCompressedInteger (data, start, out start)); + case ElementType.MVar: + return new MVAR (Utilities.ReadCompressedInteger (data, start, out start)); + case ElementType.GenericInst: + GENERICINST ginst = new GENERICINST (); + + ginst.ValueType = ((ElementType) Utilities.ReadCompressedInteger ( + data, start, out start)) == ElementType.ValueType; + + ginst.Type = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef, + (uint) Utilities.ReadCompressedInteger (data, start, out start)); + + ginst.Signature = ReadGenericInstSignature (data, start, out start); + + return ginst; + default : + return new SigType (element); + } + } + + GenericInstSignature ReadGenericInstSignature (byte [] data, int pos, out int start) + { + start = pos; + GenericInstSignature gis = new GenericInstSignature (); + gis.Arity = Utilities.ReadCompressedInteger (data, start, out start); + gis.Types = new GenericArg [gis.Arity]; + for (int i = 0; i < gis.Arity; i++) + gis.Types [i] = ReadGenericArg (data, start, out start); + + return gis; + } + + GenericArg ReadGenericArg (byte[] data, int pos, out int start) + { + start = pos; + CustomMod [] mods = ReadCustomMods (data, start, out start); + GenericArg arg = new GenericArg (ReadType (data, start, out start)); + arg.CustomMods = mods; + return arg; + } + + CustomMod [] ReadCustomMods (byte [] data, int pos, out int start) + { + ArrayList cmods = new ArrayList (); + start = pos; + while (true) { + int buf = start; + ElementType flag = (ElementType) Utilities.ReadCompressedInteger (data, start, out start); + start = buf; + if (!((flag == ElementType.CModOpt) || (flag == ElementType.CModReqD))) + break; + cmods.Add (ReadCustomMod (data, start, out start)); + } + return cmods.ToArray (typeof (CustomMod)) as CustomMod []; + } + + CustomMod ReadCustomMod (byte [] data, int pos, out int start) + { + CustomMod cm = new CustomMod (); + start = pos; + ElementType cmod = (ElementType) Utilities.ReadCompressedInteger (data, start, out start); + if (cmod == ElementType.CModOpt) + cm.CMOD = CustomMod.CMODType.OPT; + else if (cmod == ElementType.CModReqD) + cm.CMOD = CustomMod.CMODType.REQD; + else + cm.CMOD = CustomMod.CMODType.None; + cm.TypeDefOrRef = Utilities.GetMetadataToken (CodedIndex.TypeDefOrRef, + (uint) Utilities.ReadCompressedInteger (data, start, out start)); + return cm; + } + + CustomAttrib ReadCustomAttrib (int pos, MethodReference ctor, bool resolve) + { + int start, length = Utilities.ReadCompressedInteger (m_blobData, pos, out start); + byte [] data = new byte [length]; + Buffer.BlockCopy (m_blobData, start, data, 0, length); + try { + return ReadCustomAttrib (new BinaryReader ( + new MemoryStream (data)), data, ctor, resolve); + } catch { + CustomAttrib ca = new CustomAttrib (ctor); + ca.Read = false; + return ca; + } + } + + CustomAttrib ReadCustomAttrib (BinaryReader br, byte [] data, MethodReference ctor, bool resolve) + { + CustomAttrib ca = new CustomAttrib (ctor); + if (data.Length == 0) { + ca.FixedArgs = new CustomAttrib.FixedArg [0]; + ca.NamedArgs = new CustomAttrib.NamedArg [0]; + return ca; + } + + bool read = true; + + ca.Prolog = br.ReadUInt16 (); + if (ca.Prolog != CustomAttrib.StdProlog) + throw new MetadataFormatException ("Non standard prolog for custom attribute"); + + ca.FixedArgs = new CustomAttrib.FixedArg [ctor.Parameters.Count]; + for (int i = 0; i < ca.FixedArgs.Length && read; i++) + ca.FixedArgs [i] = ReadFixedArg (data, br, + ctor.Parameters [i].ParameterType, ref read, resolve); + + if (br.BaseStream.Position == br.BaseStream.Length) + read = false; + + if (!read) { + ca.Read = read; + return ca; + } + + ca.NumNamed = br.ReadUInt16 (); + ca.NamedArgs = new CustomAttrib.NamedArg [ca.NumNamed]; + for (int i = 0; i < ca.NumNamed && read; i++) + ca.NamedArgs [i] = ReadNamedArg (data, br, ref read, resolve); + + ca.Read = read; + return ca; + } + + CustomAttrib.FixedArg ReadFixedArg (byte [] data, BinaryReader br, + TypeReference param, ref bool read, bool resolve) + { + CustomAttrib.FixedArg fa = new CustomAttrib.FixedArg (); + if (param is ArrayType) { + param = ((ArrayType) param).ElementType; + fa.SzArray = true; + fa.NumElem = br.ReadUInt32 (); + + if (fa.NumElem == 0 || fa.NumElem == 0xffffffff) { + fa.Elems = new CustomAttrib.Elem [0]; + fa.NumElem = 0; + return fa; + } + + fa.Elems = new CustomAttrib.Elem [fa.NumElem]; + for (int i = 0; i < fa.NumElem; i++) + fa.Elems [i] = ReadElem (data, br, param, ref read, resolve); + } else + fa.Elems = new CustomAttrib.Elem [] { ReadElem (data, br, param, ref read, resolve) }; + + return fa; + } + + TypeReference CreateEnumTypeReference (string enumName) + { + string asmName = null; + int asmStart = enumName.IndexOf (','); + if (asmStart != -1) { + asmName = enumName.Substring (asmStart + 1); + enumName = enumName.Substring (0, asmStart); + } + // Inner class style is reflection style. + enumName = enumName.Replace ('+', '/'); + AssemblyNameReference asm; + if (asmName == null) { + // If no assembly is given then the ECMA standard says the + // assembly is either the current one or mscorlib. + if (m_reflectReader.Module.Types.Contains (enumName)) + return m_reflectReader.Module.Types [enumName]; + + asm = m_reflectReader.Corlib; + } else + asm = AssemblyNameReference.Parse (asmName); + + string [] outers = enumName.Split ('/'); + string outerfullname = outers [0]; + string ns = null; + int nsIndex = outerfullname.LastIndexOf ('.'); + if (nsIndex != -1) + ns = outerfullname.Substring (0, nsIndex); + string name = outerfullname.Substring (nsIndex + 1); + TypeReference decType = new TypeReference (name, ns, asm); + for (int i = 1; i < outers.Length; i++) { + TypeReference t = new TypeReference (outers [i], null, asm); + t.DeclaringType = decType; + decType = t; + } + decType.IsValueType = true; + + return decType; + } + + TypeReference ReadTypeReference (byte [] data, BinaryReader br, out ElementType elemType) + { + bool array = false; + elemType = (ElementType) br.ReadByte (); + if (elemType == ElementType.SzArray) { + elemType = (ElementType) br.ReadByte (); + array = true; + } + + TypeReference res; + if (elemType == ElementType.Enum) + res = CreateEnumTypeReference (ReadUTF8String (data, br)); + else + res = TypeReferenceFromElemType (elemType); + + if (array) + res = new ArrayType (res); + + return res; + } + + TypeReference TypeReferenceFromElemType (ElementType elemType) + { + switch (elemType) { + case ElementType.Boxed : + return m_reflectReader.SearchCoreType (Constants.Object); + case ElementType.String : + return m_reflectReader.SearchCoreType (Constants.String); + case ElementType.Type : + return m_reflectReader.SearchCoreType (Constants.Type); + case ElementType.Boolean : + return m_reflectReader.SearchCoreType (Constants.Boolean); + case ElementType.Char : + return m_reflectReader.SearchCoreType (Constants.Char); + case ElementType.R4 : + return m_reflectReader.SearchCoreType (Constants.Single); + case ElementType.R8 : + return m_reflectReader.SearchCoreType (Constants.Double); + case ElementType.I1 : + return m_reflectReader.SearchCoreType (Constants.SByte); + case ElementType.I2 : + return m_reflectReader.SearchCoreType (Constants.Int16); + case ElementType.I4 : + return m_reflectReader.SearchCoreType (Constants.Int32); + case ElementType.I8 : + return m_reflectReader.SearchCoreType (Constants.Int64); + case ElementType.U1 : + return m_reflectReader.SearchCoreType (Constants.Byte); + case ElementType.U2 : + return m_reflectReader.SearchCoreType (Constants.UInt16); + case ElementType.U4 : + return m_reflectReader.SearchCoreType (Constants.UInt32); + case ElementType.U8 : + return m_reflectReader.SearchCoreType (Constants.UInt64); + default : + throw new MetadataFormatException ("Non valid type in CustomAttrib.Elem: 0x{0}", + ((byte) elemType).ToString("x2")); + } + } + + internal CustomAttrib.NamedArg ReadNamedArg (byte [] data, BinaryReader br, ref bool read, bool resolve) + { + CustomAttrib.NamedArg na = new CustomAttrib.NamedArg (); + byte kind = br.ReadByte (); + if (kind == 0x53) { // field + na.Field = true; + na.Property = false; + } else if (kind == 0x54) { // property + na.Field = false; + na.Property = true; + } else + throw new MetadataFormatException ("Wrong kind of namedarg found: 0x" + kind.ToString("x2")); + + TypeReference elemType = ReadTypeReference (data, br, out na.FieldOrPropType); + na.FieldOrPropName = ReadUTF8String (data, br); + na.FixedArg = ReadFixedArg (data, br, elemType, ref read, resolve); + + return na; + } + + CustomAttrib.Elem ReadElem (byte [] data, BinaryReader br, TypeReference elemType, ref bool read, bool resolve) + { + CustomAttrib.Elem elem = new CustomAttrib.Elem (); + + string elemName = elemType.FullName; + + if (elemName == Constants.Object) { + elemType = ReadTypeReference (data, br, out elem.FieldOrPropType); + if (elemType is ArrayType) { + read = false; // Don't know how to represent arrays as an object value. + return elem; + } else if (elemType.FullName == Constants.Object) + throw new MetadataFormatException ("Non valid type in CustomAttrib.Elem after boxed prefix: 0x{0}", + ((byte) elem.FieldOrPropType).ToString("x2")); + + elem = ReadElem (data, br, elemType, ref read, resolve); + elem.String = elem.Simple = elem.Type = false; + elem.BoxedValueType = true; + return elem; + } + + elem.ElemType = elemType; + + if (elemName == Constants.Type || elemName == Constants.String) { + switch (elemType.FullName) { + case Constants.String: + elem.String = true; + elem.BoxedValueType = elem.Simple = elem.Type = false; + break; + case Constants.Type: + elem.Type = true; + elem.BoxedValueType = elem.Simple = elem.String = false; + break; + } + + if (data [br.BaseStream.Position] == 0xff) { // null + elem.Value = null; + br.BaseStream.Position++; + } else { + elem.Value = ReadUTF8String (data, br); + } + return elem; + } + + elem.String = elem.Type = elem.BoxedValueType = false; + if (!ReadSimpleValue (br, ref elem, elem.ElemType)) { + if (!resolve) { // until enums writing is implemented + read = false; + return elem; + } + TypeReference typeRef = GetEnumUnderlyingType (elem.ElemType, resolve); + if (typeRef == null || !ReadSimpleValue (br, ref elem, typeRef)) + read = false; + } + + return elem; + } + + TypeReference GetEnumUnderlyingType (TypeReference enumType, bool resolve) + { + TypeDefinition type = enumType as TypeDefinition; + if (type == null && resolve && AssemblyResolver != null) { + if (enumType.Scope is ModuleDefinition) + throw new NotSupportedException (); + + AssemblyDefinition asm = AssemblyResolver.Resolve ( + ((AssemblyNameReference) enumType.Scope).FullName); + type = asm.MainModule.Types [enumType.FullName]; + } + + if (type != null && type.IsEnum) + return type.Fields.GetField ("value__").FieldType; + + return null; + } + + bool ReadSimpleValue (BinaryReader br, ref CustomAttrib.Elem elem, TypeReference type) + { + switch (type.FullName) { + case Constants.Boolean : + elem.Value = br.ReadByte () == 1; + break; + case Constants.Char : + elem.Value = (char) br.ReadUInt16 (); + break; + case Constants.Single : + elem.Value = br.ReadSingle (); + break; + case Constants.Double : + elem.Value = br.ReadDouble (); + break; + case Constants.Byte : + elem.Value = br.ReadByte (); + break; + case Constants.Int16 : + elem.Value = br.ReadInt16 (); + break; + case Constants.Int32 : + elem.Value = br.ReadInt32 (); + break; + case Constants.Int64 : + elem.Value = br.ReadInt64 (); + break; + case Constants.SByte : + elem.Value = br.ReadSByte (); + break; + case Constants.UInt16 : + elem.Value = br.ReadUInt16 (); + break; + case Constants.UInt32 : + elem.Value = br.ReadUInt32 (); + break; + case Constants.UInt64 : + elem.Value = br.ReadUInt64 (); + break; + default : // enum + return false; + } + elem.Simple = true; + return true; + } + + MarshalSig ReadMarshalSig (byte [] data) + { + int start; + MarshalSig ms = new MarshalSig ((NativeType) Utilities.ReadCompressedInteger (data, 0, out start)); + switch (ms.NativeInstrinsic) { + case NativeType.ARRAY: + MarshalSig.Array ar = new MarshalSig.Array (); + ar.ArrayElemType = (NativeType) Utilities.ReadCompressedInteger (data, start, out start); + if (start < data.Length) + ar.ParamNum = Utilities.ReadCompressedInteger (data, start, out start); + if (start < data.Length) + ar.NumElem = Utilities.ReadCompressedInteger (data, start, out start); + if (start < data.Length) + ar.ElemMult = Utilities.ReadCompressedInteger (data, start, out start); + ms.Spec = ar; + break; + case NativeType.CUSTOMMARSHALER: + MarshalSig.CustomMarshaler cm = new MarshalSig.CustomMarshaler (); + cm.Guid = ReadUTF8String (data, start, out start); + cm.UnmanagedType = ReadUTF8String (data, start, out start); + cm.ManagedType = ReadUTF8String (data, start, out start); + cm.Cookie = ReadUTF8String (data, start, out start); + ms.Spec = cm; + break; + case NativeType.FIXEDARRAY: + MarshalSig.FixedArray fa = new MarshalSig.FixedArray (); + fa.NumElem = Utilities.ReadCompressedInteger (data, start, out start); + if (start < data.Length) + fa.ArrayElemType = (NativeType) Utilities.ReadCompressedInteger (data, start, out start); + ms.Spec = fa; + break; + case NativeType.SAFEARRAY: + MarshalSig.SafeArray sa = new MarshalSig.SafeArray (); + if (start < data.Length) + sa.ArrayElemType = (VariantType) Utilities.ReadCompressedInteger (data, start, out start); + ms.Spec = sa; + break; + case NativeType.FIXEDSYSSTRING: + MarshalSig.FixedSysString fss = new MarshalSig.FixedSysString (); + if (start < data.Length) + fss.Size = Utilities.ReadCompressedInteger (data, start, out start); + ms.Spec = fss; + break; + } + return ms; + } + + static internal string ReadUTF8String (byte [] data, BinaryReader br) + { + int start = (int)br.BaseStream.Position; + string val = ReadUTF8String (data, start, out start); + br.BaseStream.Position = start; + return val; + } + + static internal string ReadUTF8String (byte [] data, int pos, out int start) + { + int length = Utilities.ReadCompressedInteger (data, pos, out start); + pos = start; + start += length; + // COMPACT FRAMEWORK NOTE: Encoding.GetString (byte[]) is not supported. + return Encoding.UTF8.GetString (data, pos, length); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs new file mode 100644 index 0000000..dfe92d7 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SignatureWriter.cs @@ -0,0 +1,564 @@ +// +// SignatureWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using System; + using System.Text; + + using Mono.Cecil; + using Mono.Cecil.Binary; + using Mono.Cecil.Metadata; + + internal sealed class SignatureWriter : BaseSignatureVisitor { + + MetadataWriter m_mdWriter; + MemoryBinaryWriter m_sigWriter; + + public SignatureWriter (MetadataWriter mdWriter) + { + m_mdWriter = mdWriter; + m_sigWriter = new MemoryBinaryWriter (); + } + + uint GetPointer () + { + return m_mdWriter.AddBlob (m_sigWriter.ToArray ()); + } + + public uint AddMethodDefSig (MethodDefSig methSig) + { + return AddSignature (methSig); + } + + public uint AddMethodRefSig (MethodRefSig methSig) + { + return AddSignature (methSig); + } + + public uint AddPropertySig (PropertySig ps) + { + return AddSignature (ps); + } + + public uint AddFieldSig (FieldSig fSig) + { + return AddSignature (fSig); + } + + public uint AddLocalVarSig (LocalVarSig lvs) + { + return AddSignature (lvs); + } + + uint AddSignature (Signature s) + { + m_sigWriter.Empty (); + s.Accept (this); + return GetPointer (); + } + + public uint AddTypeSpec (TypeSpec ts) + { + m_sigWriter.Empty (); + Write (ts); + return GetPointer (); + } + + public uint AddMethodSpec (MethodSpec ms) + { + m_sigWriter.Empty (); + Write (ms); + return GetPointer (); + } + + public uint AddMarshalSig (MarshalSig ms) + { + m_sigWriter.Empty (); + Write (ms); + return GetPointer (); + } + + public uint AddCustomAttribute (CustomAttrib ca, MethodReference ctor) + { + CompressCustomAttribute (ca, ctor, m_sigWriter); + return GetPointer (); + } + + public byte [] CompressCustomAttribute (CustomAttrib ca, MethodReference ctor) + { + MemoryBinaryWriter writer = new MemoryBinaryWriter (); + CompressCustomAttribute (ca, ctor, writer); + return writer.ToArray (); + } + + public byte [] CompressFieldSig (FieldSig field) + { + m_sigWriter.Empty (); + VisitFieldSig (field); + return m_sigWriter.ToArray (); + } + + public byte [] CompressLocalVar (LocalVarSig.LocalVariable var) + { + m_sigWriter.Empty (); + Write (var); + return m_sigWriter.ToArray (); + } + + void CompressCustomAttribute (CustomAttrib ca, MethodReference ctor, MemoryBinaryWriter writer) + { + m_sigWriter.Empty (); + Write (ca, ctor, writer); + } + + public override void VisitMethodDefSig (MethodDefSig methodDef) + { + m_sigWriter.Write (methodDef.CallingConvention); + if (methodDef.GenericParameterCount > 0) + Write (methodDef.GenericParameterCount); + Write (methodDef.ParamCount); + Write (methodDef.RetType); + Write (methodDef.Parameters, methodDef.Sentinel); + } + + public override void VisitMethodRefSig (MethodRefSig methodRef) + { + m_sigWriter.Write (methodRef.CallingConvention); + Write (methodRef.ParamCount); + Write (methodRef.RetType); + Write (methodRef.Parameters, methodRef.Sentinel); + } + + public override void VisitFieldSig (FieldSig field) + { + m_sigWriter.Write (field.CallingConvention); + Write (field.CustomMods); + Write (field.Type); + } + + public override void VisitPropertySig (PropertySig property) + { + m_sigWriter.Write (property.CallingConvention); + Write (property.ParamCount); + Write (property.CustomMods); + Write (property.Type); + Write (property.Parameters); + } + + public override void VisitLocalVarSig (LocalVarSig localvar) + { + m_sigWriter.Write (localvar.CallingConvention); + Write (localvar.Count); + Write (localvar.LocalVariables); + } + + void Write (LocalVarSig.LocalVariable [] vars) + { + foreach (LocalVarSig.LocalVariable var in vars) + Write (var); + } + + void Write (LocalVarSig.LocalVariable var) + { + Write (var.CustomMods); + if ((var.Constraint & Constraint.Pinned) != 0) + Write (ElementType.Pinned); + if (var.ByRef) + Write (ElementType.ByRef); + Write (var.Type); + } + + void Write (RetType retType) + { + Write (retType.CustomMods); + if (retType.Void) + Write (ElementType.Void); + else if (retType.TypedByRef) + Write (ElementType.TypedByRef); + else if (retType.ByRef) { + Write (ElementType.ByRef); + Write (retType.Type); + } else + Write (retType.Type); + } + + void Write (Param [] parameters, int sentinel) + { + for (int i = 0; i < parameters.Length; i++) { + if (i == sentinel) + Write (ElementType.Sentinel); + + Write (parameters [i]); + } + } + + void Write (Param [] parameters) + { + foreach (Param p in parameters) + Write (p); + } + + void Write (ElementType et) + { + Write ((int) et); + } + + void Write (SigType t) + { + Write ((int) t.ElementType); + + switch (t.ElementType) { + case ElementType.ValueType : + Write ((int) Utilities.CompressMetadataToken ( + CodedIndex.TypeDefOrRef, ((VALUETYPE) t).Type)); + break; + case ElementType.Class : + Write ((int) Utilities.CompressMetadataToken ( + CodedIndex.TypeDefOrRef, ((CLASS) t).Type)); + break; + case ElementType.Ptr : + PTR p = (PTR) t; + if (p.Void) + Write (ElementType.Void); + else { + Write (p.CustomMods); + Write (p.PtrType); + } + break; + case ElementType.FnPtr : + FNPTR fp = (FNPTR) t; + if (fp.Method is MethodRefSig) + (fp.Method as MethodRefSig).Accept (this); + else + (fp.Method as MethodDefSig).Accept (this); + break; + case ElementType.Array : + ARRAY ary = (ARRAY) t; + Write (ary.CustomMods); + ArrayShape shape = ary.Shape; + Write (ary.Type); + Write (shape.Rank); + Write (shape.NumSizes); + foreach (int size in shape.Sizes) + Write (size); + Write (shape.NumLoBounds); + foreach (int loBound in shape.LoBounds) + Write (loBound); + break; + case ElementType.SzArray : + SZARRAY sa = (SZARRAY) t; + Write (sa.CustomMods); + Write (sa.Type); + break; + case ElementType.Var : + Write (((VAR) t).Index); + break; + case ElementType.MVar : + Write (((MVAR) t).Index); + break; + case ElementType.GenericInst : + GENERICINST gi = t as GENERICINST; + Write (gi.ValueType ? ElementType.ValueType : ElementType.Class); + Write ((int) Utilities.CompressMetadataToken ( + CodedIndex.TypeDefOrRef, gi.Type)); + Write (gi.Signature); + break; + } + } + + void Write (TypeSpec ts) + { + Write (ts.CustomMods); + Write (ts.Type); + } + + void Write (MethodSpec ms) + { + Write (0x0a); + Write (ms.Signature); + } + + void Write (GenericInstSignature gis) + { + Write (gis.Arity); + for (int i = 0; i < gis.Arity; i++) + Write (gis.Types [i]); + } + + void Write (GenericArg arg) + { + Write (arg.CustomMods); + Write (arg.Type); + } + + void Write (Param p) + { + Write (p.CustomMods); + if (p.TypedByRef) + Write (ElementType.TypedByRef); + else if (p.ByRef) { + Write (ElementType.ByRef); + Write (p.Type); + } else + Write (p.Type); + } + + void Write (CustomMod [] customMods) + { + foreach (CustomMod cm in customMods) + Write (cm); + } + + void Write (CustomMod cm) + { + switch (cm.CMOD) { + case CustomMod.CMODType.OPT : + Write (ElementType.CModOpt); + break; + case CustomMod.CMODType.REQD : + Write (ElementType.CModReqD); + break; + } + + Write ((int) Utilities.CompressMetadataToken ( + CodedIndex.TypeDefOrRef, cm.TypeDefOrRef)); + } + + void Write (MarshalSig ms) + { + Write ((int) ms.NativeInstrinsic); + switch (ms.NativeInstrinsic) { + case NativeType.ARRAY : + MarshalSig.Array ar = (MarshalSig.Array) ms.Spec; + Write ((int) ar.ArrayElemType); + if (ar.ParamNum != -1) + Write (ar.ParamNum); + if (ar.NumElem != -1) + Write (ar.NumElem); + if (ar.ElemMult != -1) + Write (ar.ElemMult); + break; + case NativeType.CUSTOMMARSHALER : + MarshalSig.CustomMarshaler cm = (MarshalSig.CustomMarshaler) ms.Spec; + Write (cm.Guid); + Write (cm.UnmanagedType); + Write (cm.ManagedType); + Write (cm.Cookie); + break; + case NativeType.FIXEDARRAY : + MarshalSig.FixedArray fa = (MarshalSig.FixedArray) ms.Spec; + Write (fa.NumElem); + if (fa.ArrayElemType != NativeType.NONE) + Write ((int) fa.ArrayElemType); + break; + case NativeType.SAFEARRAY : + Write ((int) ((MarshalSig.SafeArray) ms.Spec).ArrayElemType); + break; + case NativeType.FIXEDSYSSTRING : + Write (((MarshalSig.FixedSysString) ms.Spec).Size); + break; + } + } + + void Write (CustomAttrib ca, MethodReference ctor, MemoryBinaryWriter writer) + { + if (ca == null) + return; + + if (ca.Prolog != CustomAttrib.StdProlog) + return; + + writer.Write (ca.Prolog); + + for (int i = 0; i < ctor.Parameters.Count; i++) + Write (ca.FixedArgs [i], writer); + + writer.Write (ca.NumNamed); + + for (int i = 0; i < ca.NumNamed; i++) + Write (ca.NamedArgs [i], writer); + } + + void Write (CustomAttrib.FixedArg fa, MemoryBinaryWriter writer) + { + if (fa.SzArray) + writer.Write (fa.NumElem); + + foreach (CustomAttrib.Elem elem in fa.Elems) + Write (elem, writer); + } + + static string GetEnumFullName (TypeReference type) + { + string fullname = type.FullName; + + if (type.IsNested) + fullname = fullname.Replace ('/', '+'); + + if (type is TypeDefinition) + return fullname; + + return string.Concat (fullname, ", ", type.Module.Assembly.Name.FullName); + } + + void Write (CustomAttrib.NamedArg na, MemoryBinaryWriter writer) + { + if (na.Field) + writer.Write ((byte) 0x53); + else if (na.Property) + writer.Write ((byte) 0x54); + else + throw new MetadataFormatException ("Unknown kind of namedarg"); + + if (na.FieldOrPropType == ElementType.Class) + na.FieldOrPropType = ElementType.Enum; + + if (na.FixedArg.SzArray) + writer.Write ((byte) ElementType.SzArray); + + if (na.FieldOrPropType == ElementType.Object) + writer.Write ((byte) ElementType.Boxed); + else + writer.Write ((byte) na.FieldOrPropType); + + if (na.FieldOrPropType == ElementType.Enum) + Write (GetEnumFullName (na.FixedArg.Elems [0].ElemType)); + + Write (na.FieldOrPropName); + + Write (na.FixedArg, writer); + } + + static ElementType GetElementTypeFromTypeCode (TypeCode tc) + { + switch (tc) { + case TypeCode.Byte: + return ElementType.U1; + case TypeCode.SByte: + return ElementType.I1; + case TypeCode.Int16: + return ElementType.I2; + case TypeCode.UInt16: + return ElementType.U2; + case TypeCode.Int32: + return ElementType.I4; + case TypeCode.UInt32: + return ElementType.U4; + case TypeCode.Int64: + return ElementType.I8; + case TypeCode.UInt64: + return ElementType.U8; + default: + throw new ArgumentException ("tc"); + } + } + + void Write (CustomAttrib.Elem elem, MemoryBinaryWriter writer) + { + if (elem.String) + elem.FieldOrPropType = ElementType.String; + else if (elem.Type) + elem.FieldOrPropType = ElementType.Type; + + if (elem.FieldOrPropType == ElementType.Class) // an enum in fact + elem.FieldOrPropType = GetElementTypeFromTypeCode (Type.GetTypeCode (elem.Value.GetType ())); + + if (elem.BoxedValueType) + Write (elem.FieldOrPropType); + + switch (elem.FieldOrPropType) { + case ElementType.Boolean : + writer.Write ((byte) ((bool) elem.Value ? 1 : 0)); + break; + case ElementType.Char : + writer.Write ((ushort) (char) elem.Value); + break; + case ElementType.R4 : + writer.Write ((float) elem.Value); + break; + case ElementType.R8 : + writer.Write ((double) elem.Value); + break; + case ElementType.I1 : + writer.Write ((sbyte) elem.Value); + break; + case ElementType.I2 : + writer.Write ((short) elem.Value); + break; + case ElementType.I4 : + writer.Write ((int) elem.Value); + break; + case ElementType.I8 : + writer.Write ((long) elem.Value); + break; + case ElementType.U1 : + writer.Write ((byte) elem.Value); + break; + case ElementType.U2 : + writer.Write ((ushort) elem.Value); + break; + case ElementType.U4 : + writer.Write ((uint) elem.Value); + break; + case ElementType.U8 : + writer.Write ((long) elem.Value); + break; + case ElementType.String : + case ElementType.Type : + string s = elem.Value as string; + if (s == null) + writer.Write ((byte) 0xff); + else if (s.Length == 0) + writer.Write ((byte) 0x00); + else + Write (s); + break; + case ElementType.Object : + if (elem.Value != null) + throw new NotSupportedException ("Unknown state"); + writer.Write ((byte) 0xff); + break; + default : + throw new NotImplementedException ("WriteElem " + elem.FieldOrPropType.ToString ()); + } + } + + void Write (string s) + { + byte [] str = Encoding.UTF8.GetBytes (s); + Write (str.Length); + m_sigWriter.Write (str); + } + + void Write (int i) + { + Utilities.WriteCompressedInteger (m_sigWriter, i); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SzArray.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SzArray.cs new file mode 100644 index 0000000..08ad8f1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/SzArray.cs @@ -0,0 +1,42 @@ +// +// SzArray.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class SZARRAY : SigType { + + public CustomMod [] CustomMods; + public SigType Type; + + public SZARRAY () : base (ElementType.SzArray) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/TypeSpec.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/TypeSpec.cs new file mode 100644 index 0000000..7664df3 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/TypeSpec.cs @@ -0,0 +1,36 @@ +// +// TypeSpec.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + internal sealed class TypeSpec { + + public CustomMod [] CustomMods; + public SigType Type; + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ValueType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ValueType.cs new file mode 100644 index 0000000..36b2661 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/ValueType.cs @@ -0,0 +1,41 @@ +// +// ValueType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class VALUETYPE : SigType { + + public MetadataToken Type; + + public VALUETYPE () : base (ElementType.ValueType) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Var.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Var.cs new file mode 100644 index 0000000..97b35b6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.Signatures/Var.cs @@ -0,0 +1,42 @@ +// +// Var.cs +// +// Author: +// Martin Baulig <martin@ximian.com> +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil.Signatures { + + using Mono.Cecil.Metadata; + + internal sealed class VAR : SigType { + + public int Index; + + public VAR (int index) : base (ElementType.Var) + { + this.Index = index; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.csproj b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.csproj new file mode 100644 index 0000000..c6c6d93 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.csproj @@ -0,0 +1,365 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Mono.Cecil</RootNamespace> + <AssemblyName>Mono.Cecil</AssemblyName> + <StartupObject> + </StartupObject> + <SignAssembly>true</SignAssembly> + <AssemblyOriginatorKeyFile>..\mono.snk</AssemblyOriginatorKeyFile> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <ItemGroup> + <Compile Include="Mono.Cecil.Binary\BaseImageVisitor.cs" /> + <Compile Include="Mono.Cecil.Binary\CLIHeader.cs" /> + <Compile Include="Mono.Cecil.Binary\CopyImageVisitor.cs" /> + <Compile Include="Mono.Cecil.Binary\DataDirectory.cs" /> + <Compile Include="Mono.Cecil.Binary\DebugHeader.cs" /> + <Compile Include="Mono.Cecil.Binary\DebugStoreType.cs" /> + <Compile Include="Mono.Cecil.Binary\DOSHeader.cs" /> + <Compile Include="Mono.Cecil.Binary\ExportTable.cs" /> + <Compile Include="Mono.Cecil.Binary\IBinaryVisitable.cs" /> + <Compile Include="Mono.Cecil.Binary\IBinaryVisitor.cs" /> + <Compile Include="Mono.Cecil.Binary\IHeader.cs" /> + <Compile Include="Mono.Cecil.Binary\Image.cs" /> + <Compile Include="Mono.Cecil.Binary\ImageCharacteristics.cs" /> + <Compile Include="Mono.Cecil.Binary\ImageFormatException.cs" /> + <Compile Include="Mono.Cecil.Binary\ImageInitializer.cs" /> + <Compile Include="Mono.Cecil.Binary\ImageReader.cs" /> + <Compile Include="Mono.Cecil.Binary\ImageWriter.cs" /> + <Compile Include="Mono.Cecil.Binary\Imports.cs" /> + <Compile Include="Mono.Cecil.Binary\MemoryBinaryWriter.cs" /> + <Compile Include="Mono.Cecil.Binary\PEFileHeader.cs" /> + <Compile Include="Mono.Cecil.Binary\PEOptionalHeader.cs" /> + <Compile Include="Mono.Cecil.Binary\ResourceDataEntry.cs" /> + <Compile Include="Mono.Cecil.Binary\ResourceDirectoryEntry.cs" /> + <Compile Include="Mono.Cecil.Binary\ResourceDirectoryString.cs" /> + <Compile Include="Mono.Cecil.Binary\ResourceDirectoryTable.cs" /> + <Compile Include="Mono.Cecil.Binary\ResourceNode.cs" /> + <Compile Include="Mono.Cecil.Binary\ResourceReader.cs" /> + <Compile Include="Mono.Cecil.Binary\ResourceWriter.cs" /> + <Compile Include="Mono.Cecil.Binary\RuntimeImage.cs" /> + <Compile Include="Mono.Cecil.Binary\RVA.cs" /> + <Compile Include="Mono.Cecil.Binary\Section.cs" /> + <Compile Include="Mono.Cecil.Binary\SectionCharacteristics.cs" /> + <Compile Include="Mono.Cecil.Binary\SectionCollection.cs" /> + <Compile Include="Mono.Cecil.Binary\SubSystem.cs" /> + <Compile Include="Mono.Cecil.Cil\BaseCodeVisitor.cs" /> + <Compile Include="Mono.Cecil.Cil\CilWorker.cs" /> + <Compile Include="Mono.Cecil.Cil\Code.cs" /> + <Compile Include="Mono.Cecil.Cil\CodeReader.cs" /> + <Compile Include="Mono.Cecil.Cil\CodeWriter.cs" /> + <Compile Include="Mono.Cecil.Cil\DocumentType.cs" /> + <Compile Include="Mono.Cecil.Cil\Document.cs" /> + <Compile Include="Mono.Cecil.Cil\DocumentHashAlgorithm.cs" /> + <Compile Include="Mono.Cecil.Cil\DocumentLanguage.cs" /> + <Compile Include="Mono.Cecil.Cil\DocumentLanguageVendor.cs" /> + <Compile Include="Mono.Cecil.Cil\ExceptionHandler.cs" /> + <Compile Include="Mono.Cecil.Cil\ExceptionHandlerCollection.cs" /> + <Compile Include="Mono.Cecil.Cil\ExceptionHandlerType.cs" /> + <Compile Include="Mono.Cecil.Cil\FlowControl.cs" /> + <Compile Include="Mono.Cecil.Cil\GuidAttribute.cs" /> + <Compile Include="Mono.Cecil.Cil\ICodeVisitable.cs" /> + <Compile Include="Mono.Cecil.Cil\ICodeVisitor.cs" /> + <Compile Include="Mono.Cecil.Cil\Instruction.cs" /> + <Compile Include="Mono.Cecil.Cil\InstructionCollection.cs" /> + <Compile Include="Mono.Cecil.Cil\IScopeProvider.cs" /> + <Compile Include="Mono.Cecil.Cil\ISymbolReader.cs" /> + <Compile Include="Mono.Cecil.Cil\ISymbolStoreFactory.cs" /> + <Compile Include="Mono.Cecil.Cil\ISymbolWriter.cs" /> + <Compile Include="Mono.Cecil.Cil\IVariableDefinitionProvider.cs" /> + <Compile Include="Mono.Cecil.Cil\MethodBody.cs" /> + <Compile Include="Mono.Cecil.Cil\MethodDataSection.cs" /> + <Compile Include="Mono.Cecil.Cil\MethodHeader.cs" /> + <Compile Include="Mono.Cecil.Cil\OpCode.cs" /> + <Compile Include="Mono.Cecil.Cil\OpCodes.cs" /> + <Compile Include="Mono.Cecil.Cil\OpCodeType.cs" /> + <Compile Include="Mono.Cecil.Cil\OperandType.cs" /> + <Compile Include="Mono.Cecil.Cil\Scope.cs" /> + <Compile Include="Mono.Cecil.Cil\ScopeCollection.cs" /> + <Compile Include="Mono.Cecil.Cil\SequencePoint.cs" /> + <Compile Include="Mono.Cecil.Cil\StackBehaviour.cs" /> + <Compile Include="Mono.Cecil.Cil\SymbolStoreHelper.cs" /> + <Compile Include="Mono.Cecil.Cil\VariableDefinition.cs" /> + <Compile Include="Mono.Cecil.Cil\VariableDefinitionCollection.cs" /> + <Compile Include="Mono.Cecil.Cil\VariableReference.cs" /> + <Compile Include="Mono.Cecil.Metadata\Assembly.cs" /> + <Compile Include="Mono.Cecil.Metadata\AssemblyOS.cs" /> + <Compile Include="Mono.Cecil.Metadata\AssemblyProcessor.cs" /> + <Compile Include="Mono.Cecil.Metadata\AssemblyRef.cs" /> + <Compile Include="Mono.Cecil.Metadata\AssemblyRefOS.cs" /> + <Compile Include="Mono.Cecil.Metadata\AssemblyRefProcessor.cs" /> + <Compile Include="Mono.Cecil.Metadata\BaseMetadataVisitor.cs" /> + <Compile Include="Mono.Cecil.Metadata\BlobHeap.cs" /> + <Compile Include="Mono.Cecil.Metadata\ClassLayout.cs" /> + <Compile Include="Mono.Cecil.Metadata\CodedIndex.cs" /> + <Compile Include="Mono.Cecil.Metadata\Constant.cs" /> + <Compile Include="Mono.Cecil.Metadata\CultureUtils.cs" /> + <Compile Include="Mono.Cecil.Metadata\CustomAttribute.cs" /> + <Compile Include="Mono.Cecil.Metadata\DeclSecurity.cs" /> + <Compile Include="Mono.Cecil.Metadata\ElementType.cs" /> + <Compile Include="Mono.Cecil.Metadata\Event.cs" /> + <Compile Include="Mono.Cecil.Metadata\EventMap.cs" /> + <Compile Include="Mono.Cecil.Metadata\EventPtr.cs" /> + <Compile Include="Mono.Cecil.Metadata\ExportedType.cs" /> + <Compile Include="Mono.Cecil.Metadata\Field.cs" /> + <Compile Include="Mono.Cecil.Metadata\FieldLayout.cs" /> + <Compile Include="Mono.Cecil.Metadata\FieldMarshal.cs" /> + <Compile Include="Mono.Cecil.Metadata\FieldPtr.cs" /> + <Compile Include="Mono.Cecil.Metadata\FieldRVA.cs" /> + <Compile Include="Mono.Cecil.Metadata\File.cs" /> + <Compile Include="Mono.Cecil.Metadata\GenericParam.cs" /> + <Compile Include="Mono.Cecil.Metadata\GenericParamConstraint.cs" /> + <Compile Include="Mono.Cecil.Metadata\GuidHeap.cs" /> + <Compile Include="Mono.Cecil.Metadata\IMetadataRow.cs" /> + <Compile Include="Mono.Cecil.Metadata\IMetadataTable.cs" /> + <Compile Include="Mono.Cecil.Metadata\IMetadataVisitable.cs" /> + <Compile Include="Mono.Cecil.Metadata\IMetadataVisitor.cs" /> + <Compile Include="Mono.Cecil.Metadata\ImplMap.cs" /> + <Compile Include="Mono.Cecil.Metadata\InterfaceImpl.cs" /> + <Compile Include="Mono.Cecil.Metadata\ManifestResource.cs" /> + <Compile Include="Mono.Cecil.Metadata\MemberRef.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataFormatException.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataHeap.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataInitializer.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataReader.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataRoot.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataRowReader.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataRowWriter.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataStream.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataStreamCollection.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataTableReader.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataTableWriter.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataToken.cs" /> + <Compile Include="Mono.Cecil.Metadata\MetadataWriter.cs" /> + <Compile Include="Mono.Cecil.Metadata\Method.cs" /> + <Compile Include="Mono.Cecil.Metadata\MethodImpl.cs" /> + <Compile Include="Mono.Cecil.Metadata\MethodPtr.cs" /> + <Compile Include="Mono.Cecil.Metadata\MethodSemantics.cs" /> + <Compile Include="Mono.Cecil.Metadata\MethodSpec.cs" /> + <Compile Include="Mono.Cecil.Metadata\Module.cs" /> + <Compile Include="Mono.Cecil.Metadata\ModuleRef.cs" /> + <Compile Include="Mono.Cecil.Metadata\NestedClass.cs" /> + <Compile Include="Mono.Cecil.Metadata\Param.cs" /> + <Compile Include="Mono.Cecil.Metadata\ParamPtr.cs" /> + <Compile Include="Mono.Cecil.Metadata\Property.cs" /> + <Compile Include="Mono.Cecil.Metadata\PropertyMap.cs" /> + <Compile Include="Mono.Cecil.Metadata\PropertyPtr.cs" /> + <Compile Include="Mono.Cecil.Metadata\RowCollection.cs" /> + <Compile Include="Mono.Cecil.Metadata\StandAloneSig.cs" /> + <Compile Include="Mono.Cecil.Metadata\StringsHeap.cs" /> + <Compile Include="Mono.Cecil.Metadata\TableCollection.cs" /> + <Compile Include="Mono.Cecil.Metadata\TablesHeap.cs" /> + <Compile Include="Mono.Cecil.Metadata\TokenType.cs" /> + <Compile Include="Mono.Cecil.Metadata\TypeDef.cs" /> + <Compile Include="Mono.Cecil.Metadata\TypeRef.cs" /> + <Compile Include="Mono.Cecil.Metadata\TypeSpec.cs" /> + <Compile Include="Mono.Cecil.Metadata\UserStringsHeap.cs" /> + <Compile Include="Mono.Cecil.Metadata\Utilities.cs" /> + <Compile Include="Mono.Cecil.Signatures\Array.cs" /> + <Compile Include="Mono.Cecil.Signatures\ArrayShape.cs" /> + <Compile Include="Mono.Cecil.Signatures\BaseSignatureVisitor.cs" /> + <Compile Include="Mono.Cecil.Signatures\Class.cs" /> + <Compile Include="Mono.Cecil.Signatures\Constraint.cs" /> + <Compile Include="Mono.Cecil.Signatures\CustomAttrib.cs" /> + <Compile Include="Mono.Cecil.Signatures\CustomMod.cs" /> + <Compile Include="Mono.Cecil.Signatures\FieldSig.cs" /> + <Compile Include="Mono.Cecil.Signatures\FnPtr.cs" /> + <Compile Include="Mono.Cecil.Signatures\GenericArg.cs" /> + <Compile Include="Mono.Cecil.Signatures\GenericInst.cs" /> + <Compile Include="Mono.Cecil.Signatures\GenericInstSignature.cs" /> + <Compile Include="Mono.Cecil.Signatures\InputOutputItem.cs" /> + <Compile Include="Mono.Cecil.Signatures\ISignatureVisitable.cs" /> + <Compile Include="Mono.Cecil.Signatures\ISignatureVisitor.cs" /> + <Compile Include="Mono.Cecil.Signatures\LocalVarSig.cs" /> + <Compile Include="Mono.Cecil.Signatures\MarshalSig.cs" /> + <Compile Include="Mono.Cecil.Signatures\MethodDefSig.cs" /> + <Compile Include="Mono.Cecil.Signatures\MethodRefSig.cs" /> + <Compile Include="Mono.Cecil.Signatures\MethodSig.cs" /> + <Compile Include="Mono.Cecil.Signatures\MethodSpec.cs" /> + <Compile Include="Mono.Cecil.Signatures\MVar.cs" /> + <Compile Include="Mono.Cecil.Signatures\Param.cs" /> + <Compile Include="Mono.Cecil.Signatures\PropertySig.cs" /> + <Compile Include="Mono.Cecil.Signatures\Ptr.cs" /> + <Compile Include="Mono.Cecil.Signatures\RetType.cs" /> + <Compile Include="Mono.Cecil.Signatures\Signature.cs" /> + <Compile Include="Mono.Cecil.Signatures\SignatureReader.cs" /> + <Compile Include="Mono.Cecil.Signatures\SignatureWriter.cs" /> + <Compile Include="Mono.Cecil.Signatures\SigType.cs" /> + <Compile Include="Mono.Cecil.Signatures\SzArray.cs" /> + <Compile Include="Mono.Cecil.Signatures\TypeSpec.cs" /> + <Compile Include="Mono.Cecil.Signatures\ValueType.cs" /> + <Compile Include="Mono.Cecil.Signatures\Var.cs" /> + <Compile Include="Mono.Cecil\AggressiveReflectionReader.cs" /> + <Compile Include="Mono.Cecil\ArrayDimension.cs" /> + <Compile Include="Mono.Cecil\ArrayDimensionCollection.cs" /> + <Compile Include="Mono.Cecil\ArrayType.cs" /> + <Compile Include="Mono.Cecil\AssemblyDefinition.cs" /> + <Compile Include="Mono.Cecil\AssemblyFactory.cs" /> + <Compile Include="Mono.Cecil\AssemblyFlags.cs" /> + <Compile Include="Mono.Cecil\AssemblyHashAlgorithm.cs" /> + <Compile Include="Mono.Cecil\AssemblyInfo.cs" /> + <Compile Include="Mono.Cecil\AssemblyKind.cs" /> + <Compile Include="Mono.Cecil\AssemblyLinkedResource.cs" /> + <Compile Include="Mono.Cecil\AssemblyNameDefinition.cs" /> + <Compile Include="Mono.Cecil\AssemblyNameReference.cs" /> + <Compile Include="Mono.Cecil\AssemblyNameReferenceCollection.cs" /> + <Compile Include="Mono.Cecil\BaseAssemblyResolver.cs" /> + <Compile Include="Mono.Cecil\BaseReflectionReader.cs" /> + <Compile Include="Mono.Cecil\BaseReflectionVisitor.cs" /> + <Compile Include="Mono.Cecil\BaseStructureVisitor.cs" /> + <Compile Include="Mono.Cecil\CallSite.cs" /> + <Compile Include="Mono.Cecil\CompactFrameworkCompatibility.cs" /> + <Compile Include="Mono.Cecil\Constants.cs" /> + <Compile Include="Mono.Cecil\ConstraintCollection.cs" /> + <Compile Include="Mono.Cecil\ConstructorCollection.cs" /> + <Compile Include="Mono.Cecil\CustomAttribute.cs" /> + <Compile Include="Mono.Cecil\CustomAttributeCollection.cs" /> + <Compile Include="Mono.Cecil\DefaultAssemblyResolver.cs" /> + <Compile Include="Mono.Cecil\DefaultImporter.cs" /> + <Compile Include="Mono.Cecil\EmbeddedResource.cs" /> + <Compile Include="Mono.Cecil\EventAttributes.cs" /> + <Compile Include="Mono.Cecil\EventDefinition.cs" /> + <Compile Include="Mono.Cecil\EventDefinitionCollection.cs" /> + <Compile Include="Mono.Cecil\EventReference.cs" /> + <Compile Include="Mono.Cecil\ExternTypeCollection.cs" /> + <Compile Include="Mono.Cecil\FieldAttributes.cs" /> + <Compile Include="Mono.Cecil\FieldDefinition.cs" /> + <Compile Include="Mono.Cecil\FieldDefinitionCollection.cs" /> + <Compile Include="Mono.Cecil\FieldReference.cs" /> + <Compile Include="Mono.Cecil\FileAttributes.cs" /> + <Compile Include="Mono.Cecil\FunctionPointerType.cs" /> + <Compile Include="Mono.Cecil\GenericArgumentCollection.cs" /> + <Compile Include="Mono.Cecil\GenericContext.cs" /> + <Compile Include="Mono.Cecil\GenericInstanceMethod.cs" /> + <Compile Include="Mono.Cecil\GenericInstanceType.cs" /> + <Compile Include="Mono.Cecil\GenericParameter.cs" /> + <Compile Include="Mono.Cecil\GenericParameterAttributes.cs" /> + <Compile Include="Mono.Cecil\GenericParameterCollection.cs" /> + <Compile Include="Mono.Cecil\HashCodeProvider.cs" /> + <Compile Include="Mono.Cecil\IAnnotationProvider.cs" /> + <Compile Include="Mono.Cecil\IAssemblyResolver.cs" /> + <Compile Include="Mono.Cecil\ICustomAttributeProvider.cs" /> + <Compile Include="Mono.Cecil\IDetailReader.cs" /> + <Compile Include="Mono.Cecil\IGenericInstance.cs" /> + <Compile Include="Mono.Cecil\IGenericParameterProvider.cs" /> + <Compile Include="Mono.Cecil\IHasConstant.cs" /> + <Compile Include="Mono.Cecil\IHasMarshalSpec.cs" /> + <Compile Include="Mono.Cecil\IHasSecurity.cs" /> + <Compile Include="Mono.Cecil\IImporter.cs" /> + <Compile Include="Mono.Cecil\IMemberDefinition.cs" /> + <Compile Include="Mono.Cecil\IMemberReference.cs" /> + <Compile Include="Mono.Cecil\IMetadataScope.cs" /> + <Compile Include="Mono.Cecil\IMetadataTokenProvider.cs" /> + <Compile Include="Mono.Cecil\IMethodSignature.cs" /> + <Compile Include="Mono.Cecil\ImportContext.cs" /> + <Compile Include="Mono.Cecil\InterfaceCollection.cs" /> + <Compile Include="Mono.Cecil\IReflectionStructureVisitable.cs" /> + <Compile Include="Mono.Cecil\IReflectionStructureVisitor.cs" /> + <Compile Include="Mono.Cecil\IReflectionVisitable.cs" /> + <Compile Include="Mono.Cecil\IReflectionVisitor.cs" /> + <Compile Include="Mono.Cecil\IRequireResolving.cs" /> + <Compile Include="Mono.Cecil\LinkedResource.cs" /> + <Compile Include="Mono.Cecil\ManifestResourceAttributes.cs" /> + <Compile Include="Mono.Cecil\MarshalSpec.cs" /> + <Compile Include="Mono.Cecil\MemberReference.cs" /> + <Compile Include="Mono.Cecil\MemberReferenceCollection.cs" /> + <Compile Include="Mono.Cecil\MethodAttributes.cs" /> + <Compile Include="Mono.Cecil\MethodCallingConvention.cs" /> + <Compile Include="Mono.Cecil\MethodDefinition.cs" /> + <Compile Include="Mono.Cecil\MethodDefinitionCollection.cs" /> + <Compile Include="Mono.Cecil\MethodImplAttributes.cs" /> + <Compile Include="Mono.Cecil\MethodReference.cs" /> + <Compile Include="Mono.Cecil\MethodReturnType.cs" /> + <Compile Include="Mono.Cecil\MethodSemanticsAttributes.cs" /> + <Compile Include="Mono.Cecil\MethodSpecification.cs" /> + <Compile Include="Mono.Cecil\Modifiers.cs" /> + <Compile Include="Mono.Cecil\ModuleDefinition.cs" /> + <Compile Include="Mono.Cecil\ModuleDefinitionCollection.cs" /> + <Compile Include="Mono.Cecil\ModuleReference.cs" /> + <Compile Include="Mono.Cecil\ModuleReferenceCollection.cs" /> + <Compile Include="Mono.Cecil\NativeType.cs" /> + <Compile Include="Mono.Cecil\NestedTypeCollection.cs" /> + <Compile Include="Mono.Cecil\NullReferenceImporter.cs" /> + <Compile Include="Mono.Cecil\OverrideCollection.cs" /> + <Compile Include="Mono.Cecil\ParameterAttributes.cs" /> + <Compile Include="Mono.Cecil\ParameterDefinition.cs" /> + <Compile Include="Mono.Cecil\ParameterDefinitionCollection.cs" /> + <Compile Include="Mono.Cecil\ParameterReference.cs" /> + <Compile Include="Mono.Cecil\PinnedType.cs" /> + <Compile Include="Mono.Cecil\PInvokeAttributes.cs" /> + <Compile Include="Mono.Cecil\PInvokeInfo.cs" /> + <Compile Include="Mono.Cecil\PointerType.cs" /> + <Compile Include="Mono.Cecil\PropertyAttributes.cs" /> + <Compile Include="Mono.Cecil\PropertyDefinition.cs" /> + <Compile Include="Mono.Cecil\PropertyDefinitionCollection.cs" /> + <Compile Include="Mono.Cecil\PropertyReference.cs" /> + <Compile Include="Mono.Cecil\ReferenceType.cs" /> + <Compile Include="Mono.Cecil\ReflectionController.cs" /> + <Compile Include="Mono.Cecil\ReflectionException.cs" /> + <Compile Include="Mono.Cecil\ReflectionHelper.cs" /> + <Compile Include="Mono.Cecil\ReflectionReader.cs" /> + <Compile Include="Mono.Cecil\ReflectionWriter.cs" /> + <Compile Include="Mono.Cecil\Resource.cs" /> + <Compile Include="Mono.Cecil\ResourceCollection.cs" /> + <Compile Include="Mono.Cecil\SecurityAction.cs" /> + <Compile Include="Mono.Cecil\SecurityDeclaration.cs" /> + <Compile Include="Mono.Cecil\SecurityDeclarationCollection.cs" /> + <Compile Include="Mono.Cecil\SecurityDeclarationReader.cs" /> + <Compile Include="Mono.Cecil\SentinelType.cs" /> + <Compile Include="Mono.Cecil\StructureReader.cs" /> + <Compile Include="Mono.Cecil\StructureWriter.cs" /> + <Compile Include="Mono.Cecil\TableComparers.cs" /> + <Compile Include="Mono.Cecil\TargetRuntime.cs" /> + <Compile Include="Mono.Cecil\TypeAttributes.cs" /> + <Compile Include="Mono.Cecil\TypeDefinition.cs" /> + <Compile Include="Mono.Cecil\TypeDefinitionCollection.cs" /> + <Compile Include="Mono.Cecil\TypeReference.cs" /> + <Compile Include="Mono.Cecil\TypeReferenceCollection.cs" /> + <Compile Include="Mono.Cecil\TypeSpecification.cs" /> + <Compile Include="Mono.Cecil\VariantType.cs" /> + <Compile Include="Mono.Xml\MiniParser.cs" /> + <Compile Include="Mono.Xml\SecurityParser.cs" /> + <Compile Include="Mono.Xml\SmallXmlParser.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="AUTHORS" /> + <None Include="ChangeLog" /> + <None Include="configure" /> + <None Include="default.build" /> + <None Include="Makefile" /> + <None Include="mono-cecil.pc.in" /> + <None Include="Mono.Cecil.dll.sources" /> + <None Include="Mono.Xml\ChangeLog" /> + <None Include="NEWS" /> + <None Include="README" /> + <None Include="TODO" /> + </ItemGroup> + <ItemGroup> + <Reference Include="System" /> + </ItemGroup> +</Project> diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.dll.sources b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.dll.sources new file mode 100644 index 0000000..d3568bf --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil.dll.sources @@ -0,0 +1,311 @@ +./Mono.Cecil/AggressiveReflectionReader.cs +./Mono.Cecil/ArrayDimension.cs +./Mono.Cecil/ArrayDimensionCollection.cs +./Mono.Cecil/ArrayType.cs +./Mono.Cecil/AssemblyDefinition.cs +./Mono.Cecil/AssemblyFactory.cs +./Mono.Cecil/AssemblyFlags.cs +./Mono.Cecil/AssemblyHashAlgorithm.cs +./Mono.Cecil/AssemblyInfo.cs +./Mono.Cecil/AssemblyKind.cs +./Mono.Cecil/AssemblyLinkedResource.cs +./Mono.Cecil/AssemblyNameDefinition.cs +./Mono.Cecil/AssemblyNameReference.cs +./Mono.Cecil/AssemblyNameReferenceCollection.cs +./Mono.Cecil/BaseAssemblyResolver.cs +./Mono.Cecil/BaseReflectionReader.cs +./Mono.Cecil/BaseReflectionVisitor.cs +./Mono.Cecil/BaseStructureVisitor.cs +./Mono.Cecil/CallSite.cs +./Mono.Cecil/CompactFrameworkCompatibility.cs +./Mono.Cecil/Constants.cs +./Mono.Cecil/ConstraintCollection.cs +./Mono.Cecil/ConstructorCollection.cs +./Mono.Cecil/CustomAttribute.cs +./Mono.Cecil/CustomAttributeCollection.cs +./Mono.Cecil/DefaultAssemblyResolver.cs +./Mono.Cecil/DefaultImporter.cs +./Mono.Cecil/EmbeddedResource.cs +./Mono.Cecil/EventAttributes.cs +./Mono.Cecil/EventDefinition.cs +./Mono.Cecil/EventDefinitionCollection.cs +./Mono.Cecil/EventReference.cs +./Mono.Cecil/ExternTypeCollection.cs +./Mono.Cecil/FieldAttributes.cs +./Mono.Cecil/FieldDefinition.cs +./Mono.Cecil/FieldDefinitionCollection.cs +./Mono.Cecil/FieldReference.cs +./Mono.Cecil/FileAttributes.cs +./Mono.Cecil/FunctionPointerType.cs +./Mono.Cecil/GenericArgumentCollection.cs +./Mono.Cecil/GenericContext.cs +./Mono.Cecil/GenericInstanceMethod.cs +./Mono.Cecil/GenericInstanceType.cs +./Mono.Cecil/GenericParameter.cs +./Mono.Cecil/GenericParameterAttributes.cs +./Mono.Cecil/GenericParameterCollection.cs +./Mono.Cecil/HashCodeProvider.cs +./Mono.Cecil/IAnnotationProvider.cs +./Mono.Cecil/IAssemblyResolver.cs +./Mono.Cecil/ICustomAttributeProvider.cs +./Mono.Cecil/IDetailReader.cs +./Mono.Cecil/IGenericInstance.cs +./Mono.Cecil/IGenericParameterProvider.cs +./Mono.Cecil/IHasConstant.cs +./Mono.Cecil/IHasMarshalSpec.cs +./Mono.Cecil/IHasSecurity.cs +./Mono.Cecil/IImporter.cs +./Mono.Cecil/IMemberDefinition.cs +./Mono.Cecil/IMemberReference.cs +./Mono.Cecil/IMetadataScope.cs +./Mono.Cecil/IMetadataTokenProvider.cs +./Mono.Cecil/IMethodSignature.cs +./Mono.Cecil/ImportContext.cs +./Mono.Cecil/InterfaceCollection.cs +./Mono.Cecil/IReflectionStructureVisitable.cs +./Mono.Cecil/IReflectionStructureVisitor.cs +./Mono.Cecil/IReflectionVisitable.cs +./Mono.Cecil/IReflectionVisitor.cs +./Mono.Cecil/IRequireResolving.cs +./Mono.Cecil/LinkedResource.cs +./Mono.Cecil/ManifestResourceAttributes.cs +./Mono.Cecil/MarshalSpec.cs +./Mono.Cecil/MemberReference.cs +./Mono.Cecil/MemberReferenceCollection.cs +./Mono.Cecil/MethodAttributes.cs +./Mono.Cecil/MethodCallingConvention.cs +./Mono.Cecil/MethodDefinition.cs +./Mono.Cecil/MethodDefinitionCollection.cs +./Mono.Cecil/MethodImplAttributes.cs +./Mono.Cecil/MethodReference.cs +./Mono.Cecil/MethodReturnType.cs +./Mono.Cecil/MethodSemanticsAttributes.cs +./Mono.Cecil/MethodSpecification.cs +./Mono.Cecil/Modifiers.cs +./Mono.Cecil/ModuleDefinition.cs +./Mono.Cecil/ModuleDefinitionCollection.cs +./Mono.Cecil/ModuleReference.cs +./Mono.Cecil/ModuleReferenceCollection.cs +./Mono.Cecil/NativeType.cs +./Mono.Cecil/NestedTypeCollection.cs +./Mono.Cecil/NullReferenceImporter.cs +./Mono.Cecil/OverrideCollection.cs +./Mono.Cecil/ParameterAttributes.cs +./Mono.Cecil/ParameterDefinition.cs +./Mono.Cecil/ParameterDefinitionCollection.cs +./Mono.Cecil/ParameterReference.cs +./Mono.Cecil/PinnedType.cs +./Mono.Cecil/PInvokeAttributes.cs +./Mono.Cecil/PInvokeInfo.cs +./Mono.Cecil/PointerType.cs +./Mono.Cecil/PropertyAttributes.cs +./Mono.Cecil/PropertyDefinition.cs +./Mono.Cecil/PropertyDefinitionCollection.cs +./Mono.Cecil/PropertyReference.cs +./Mono.Cecil/ReferenceType.cs +./Mono.Cecil/ReflectionController.cs +./Mono.Cecil/ReflectionException.cs +./Mono.Cecil/ReflectionHelper.cs +./Mono.Cecil/ReflectionReader.cs +./Mono.Cecil/ReflectionWriter.cs +./Mono.Cecil/Resource.cs +./Mono.Cecil/ResourceCollection.cs +./Mono.Cecil/SecurityAction.cs +./Mono.Cecil/SecurityDeclaration.cs +./Mono.Cecil/SecurityDeclarationCollection.cs +./Mono.Cecil/SecurityDeclarationReader.cs +./Mono.Cecil/SentinelType.cs +./Mono.Cecil/StructureReader.cs +./Mono.Cecil/StructureWriter.cs +./Mono.Cecil/TableComparers.cs +./Mono.Cecil/TargetRuntime.cs +./Mono.Cecil/TypeAttributes.cs +./Mono.Cecil/TypeDefinition.cs +./Mono.Cecil/TypeDefinitionCollection.cs +./Mono.Cecil/TypeReference.cs +./Mono.Cecil/TypeReferenceCollection.cs +./Mono.Cecil/TypeSpecification.cs +./Mono.Cecil/VariantType.cs +./Mono.Cecil.Binary/BaseImageVisitor.cs +./Mono.Cecil.Binary/CLIHeader.cs +./Mono.Cecil.Binary/CopyImageVisitor.cs +./Mono.Cecil.Binary/DataDirectory.cs +./Mono.Cecil.Binary/DebugHeader.cs +./Mono.Cecil.Binary/DebugStoreType.cs +./Mono.Cecil.Binary/DOSHeader.cs +./Mono.Cecil.Binary/ExportTable.cs +./Mono.Cecil.Binary/IBinaryVisitable.cs +./Mono.Cecil.Binary/IBinaryVisitor.cs +./Mono.Cecil.Binary/IHeader.cs +./Mono.Cecil.Binary/Image.cs +./Mono.Cecil.Binary/ImageCharacteristics.cs +./Mono.Cecil.Binary/ImageFormatException.cs +./Mono.Cecil.Binary/ImageInitializer.cs +./Mono.Cecil.Binary/ImageReader.cs +./Mono.Cecil.Binary/ImageWriter.cs +./Mono.Cecil.Binary/Imports.cs +./Mono.Cecil.Binary/MemoryBinaryWriter.cs +./Mono.Cecil.Binary/PEFileHeader.cs +./Mono.Cecil.Binary/PEOptionalHeader.cs +./Mono.Cecil.Binary/ResourceDataEntry.cs +./Mono.Cecil.Binary/ResourceDirectoryEntry.cs +./Mono.Cecil.Binary/ResourceDirectoryString.cs +./Mono.Cecil.Binary/ResourceDirectoryTable.cs +./Mono.Cecil.Binary/ResourceNode.cs +./Mono.Cecil.Binary/ResourceReader.cs +./Mono.Cecil.Binary/ResourceWriter.cs +./Mono.Cecil.Binary/RuntimeImage.cs +./Mono.Cecil.Binary/RVA.cs +./Mono.Cecil.Binary/Section.cs +./Mono.Cecil.Binary/SectionCharacteristics.cs +./Mono.Cecil.Binary/SectionCollection.cs +./Mono.Cecil.Binary/SubSystem.cs +./Mono.Cecil.Metadata/Assembly.cs +./Mono.Cecil.Metadata/AssemblyOS.cs +./Mono.Cecil.Metadata/AssemblyProcessor.cs +./Mono.Cecil.Metadata/AssemblyRef.cs +./Mono.Cecil.Metadata/AssemblyRefOS.cs +./Mono.Cecil.Metadata/AssemblyRefProcessor.cs +./Mono.Cecil.Metadata/BaseMetadataVisitor.cs +./Mono.Cecil.Metadata/BlobHeap.cs +./Mono.Cecil.Metadata/ClassLayout.cs +./Mono.Cecil.Metadata/CodedIndex.cs +./Mono.Cecil.Metadata/Constant.cs +./Mono.Cecil.Metadata/CultureUtils.cs +./Mono.Cecil.Metadata/CustomAttribute.cs +./Mono.Cecil.Metadata/DeclSecurity.cs +./Mono.Cecil.Metadata/ElementType.cs +./Mono.Cecil.Metadata/Event.cs +./Mono.Cecil.Metadata/EventMap.cs +./Mono.Cecil.Metadata/EventPtr.cs +./Mono.Cecil.Metadata/ExportedType.cs +./Mono.Cecil.Metadata/Field.cs +./Mono.Cecil.Metadata/FieldLayout.cs +./Mono.Cecil.Metadata/FieldMarshal.cs +./Mono.Cecil.Metadata/FieldPtr.cs +./Mono.Cecil.Metadata/FieldRVA.cs +./Mono.Cecil.Metadata/File.cs +./Mono.Cecil.Metadata/GenericParam.cs +./Mono.Cecil.Metadata/GenericParamConstraint.cs +./Mono.Cecil.Metadata/GuidHeap.cs +./Mono.Cecil.Metadata/IMetadataRow.cs +./Mono.Cecil.Metadata/IMetadataTable.cs +./Mono.Cecil.Metadata/IMetadataVisitable.cs +./Mono.Cecil.Metadata/IMetadataVisitor.cs +./Mono.Cecil.Metadata/ImplMap.cs +./Mono.Cecil.Metadata/InterfaceImpl.cs +./Mono.Cecil.Metadata/ManifestResource.cs +./Mono.Cecil.Metadata/MemberRef.cs +./Mono.Cecil.Metadata/MetadataFormatException.cs +./Mono.Cecil.Metadata/MetadataHeap.cs +./Mono.Cecil.Metadata/MetadataInitializer.cs +./Mono.Cecil.Metadata/MetadataReader.cs +./Mono.Cecil.Metadata/MetadataRoot.cs +./Mono.Cecil.Metadata/MetadataRowReader.cs +./Mono.Cecil.Metadata/MetadataRowWriter.cs +./Mono.Cecil.Metadata/MetadataStream.cs +./Mono.Cecil.Metadata/MetadataStreamCollection.cs +./Mono.Cecil.Metadata/MetadataTableReader.cs +./Mono.Cecil.Metadata/MetadataTableWriter.cs +./Mono.Cecil.Metadata/MetadataToken.cs +./Mono.Cecil.Metadata/MetadataWriter.cs +./Mono.Cecil.Metadata/Method.cs +./Mono.Cecil.Metadata/MethodImpl.cs +./Mono.Cecil.Metadata/MethodPtr.cs +./Mono.Cecil.Metadata/MethodSemantics.cs +./Mono.Cecil.Metadata/MethodSpec.cs +./Mono.Cecil.Metadata/Module.cs +./Mono.Cecil.Metadata/ModuleRef.cs +./Mono.Cecil.Metadata/NestedClass.cs +./Mono.Cecil.Metadata/Param.cs +./Mono.Cecil.Metadata/ParamPtr.cs +./Mono.Cecil.Metadata/Property.cs +./Mono.Cecil.Metadata/PropertyMap.cs +./Mono.Cecil.Metadata/PropertyPtr.cs +./Mono.Cecil.Metadata/RowCollection.cs +./Mono.Cecil.Metadata/StandAloneSig.cs +./Mono.Cecil.Metadata/StringsHeap.cs +./Mono.Cecil.Metadata/TableCollection.cs +./Mono.Cecil.Metadata/TablesHeap.cs +./Mono.Cecil.Metadata/TokenType.cs +./Mono.Cecil.Metadata/TypeDef.cs +./Mono.Cecil.Metadata/TypeRef.cs +./Mono.Cecil.Metadata/TypeSpec.cs +./Mono.Cecil.Metadata/UserStringsHeap.cs +./Mono.Cecil.Metadata/Utilities.cs +./Mono.Cecil.Cil/BaseCodeVisitor.cs +./Mono.Cecil.Cil/CilWorker.cs +./Mono.Cecil.Cil/Code.cs +./Mono.Cecil.Cil/CodeReader.cs +./Mono.Cecil.Cil/CodeWriter.cs +./Mono.Cecil.Cil/Document.cs +./Mono.Cecil.Cil/DocumentHashAlgorithm.cs +./Mono.Cecil.Cil/DocumentLanguage.cs +./Mono.Cecil.Cil/DocumentLanguageVendor.cs +./Mono.Cecil.Cil/DocumentType.cs +./Mono.Cecil.Cil/ExceptionHandler.cs +./Mono.Cecil.Cil/ExceptionHandlerCollection.cs +./Mono.Cecil.Cil/ExceptionHandlerType.cs +./Mono.Cecil.Cil/FlowControl.cs +./Mono.Cecil.Cil/GuidAttribute.cs +./Mono.Cecil.Cil/ICodeVisitable.cs +./Mono.Cecil.Cil/ICodeVisitor.cs +./Mono.Cecil.Cil/Instruction.cs +./Mono.Cecil.Cil/InstructionCollection.cs +./Mono.Cecil.Cil/IScopeProvider.cs +./Mono.Cecil.Cil/ISymbolReader.cs +./Mono.Cecil.Cil/ISymbolStoreFactory.cs +./Mono.Cecil.Cil/ISymbolWriter.cs +./Mono.Cecil.Cil/IVariableDefinitionProvider.cs +./Mono.Cecil.Cil/MethodBody.cs +./Mono.Cecil.Cil/MethodDataSection.cs +./Mono.Cecil.Cil/MethodHeader.cs +./Mono.Cecil.Cil/OpCode.cs +./Mono.Cecil.Cil/OpCodes.cs +./Mono.Cecil.Cil/OpCodeType.cs +./Mono.Cecil.Cil/OperandType.cs +./Mono.Cecil.Cil/Scope.cs +./Mono.Cecil.Cil/ScopeCollection.cs +./Mono.Cecil.Cil/SequencePoint.cs +./Mono.Cecil.Cil/StackBehaviour.cs +./Mono.Cecil.Cil/SymbolStoreHelper.cs +./Mono.Cecil.Cil/VariableDefinition.cs +./Mono.Cecil.Cil/VariableDefinitionCollection.cs +./Mono.Cecil.Cil/VariableReference.cs +./Mono.Cecil.Signatures/Array.cs +./Mono.Cecil.Signatures/ArrayShape.cs +./Mono.Cecil.Signatures/BaseSignatureVisitor.cs +./Mono.Cecil.Signatures/Class.cs +./Mono.Cecil.Signatures/Constraint.cs +./Mono.Cecil.Signatures/CustomAttrib.cs +./Mono.Cecil.Signatures/CustomMod.cs +./Mono.Cecil.Signatures/FieldSig.cs +./Mono.Cecil.Signatures/FnPtr.cs +./Mono.Cecil.Signatures/GenericArg.cs +./Mono.Cecil.Signatures/GenericInst.cs +./Mono.Cecil.Signatures/GenericInstSignature.cs +./Mono.Cecil.Signatures/InputOutputItem.cs +./Mono.Cecil.Signatures/ISignatureVisitable.cs +./Mono.Cecil.Signatures/ISignatureVisitor.cs +./Mono.Cecil.Signatures/LocalVarSig.cs +./Mono.Cecil.Signatures/MarshalSig.cs +./Mono.Cecil.Signatures/MethodDefSig.cs +./Mono.Cecil.Signatures/MethodRefSig.cs +./Mono.Cecil.Signatures/MethodSig.cs +./Mono.Cecil.Signatures/MethodSpec.cs +./Mono.Cecil.Signatures/MVar.cs +./Mono.Cecil.Signatures/Param.cs +./Mono.Cecil.Signatures/PropertySig.cs +./Mono.Cecil.Signatures/Ptr.cs +./Mono.Cecil.Signatures/RetType.cs +./Mono.Cecil.Signatures/Signature.cs +./Mono.Cecil.Signatures/SignatureReader.cs +./Mono.Cecil.Signatures/SignatureWriter.cs +./Mono.Cecil.Signatures/SigType.cs +./Mono.Cecil.Signatures/SzArray.cs +./Mono.Cecil.Signatures/TypeSpec.cs +./Mono.Cecil.Signatures/ValueType.cs +./Mono.Cecil.Signatures/Var.cs +./Mono.Xml/MiniParser.cs +./Mono.Xml/SecurityParser.cs +./Mono.Xml/SmallXmlParser.cs diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AggressiveReflectionReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AggressiveReflectionReader.cs new file mode 100644 index 0000000..3979db7 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AggressiveReflectionReader.cs @@ -0,0 +1,452 @@ +// +// AggressiveRefletionReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + using Mono.Cecil.Metadata; + using Mono.Cecil.Signatures; + + internal sealed class AggressiveReflectionReader : ReflectionReader { + + public AggressiveReflectionReader (ModuleDefinition module) : base (module) + { + } + + public override void VisitTypeDefinitionCollection (TypeDefinitionCollection types) + { + base.VisitTypeDefinitionCollection (types); + + ReadGenericParameterConstraints (); + ReadClassLayoutInfos (); + ReadFieldLayoutInfos (); + ReadPInvokeInfos (); + ReadProperties (); + ReadEvents (); + ReadSemantics (); + ReadInterfaces (); + ReadOverrides (); + ReadSecurityDeclarations (); + ReadCustomAttributes (); + ReadConstants (); + ReadExternTypes (); + ReadMarshalSpecs (); + ReadInitialValues (); + + m_events = null; + m_properties = null; + m_parameters = null; + } + + void ReadGenericParameterConstraints () + { + if (!m_tHeap.HasTable (GenericParamConstraintTable.RId)) + return; + + GenericParamConstraintTable gpcTable = m_tableReader.GetGenericParamConstraintTable (); + for (int i = 0; i < gpcTable.Rows.Count; i++) { + GenericParamConstraintRow gpcRow = gpcTable [i]; + GenericParameter gp = GetGenericParameterAt (gpcRow.Owner); + + gp.Constraints.Add (GetTypeDefOrRef (gpcRow.Constraint, new GenericContext (gp.Owner))); + } + } + + void ReadClassLayoutInfos () + { + if (!m_tHeap.HasTable (ClassLayoutTable.RId)) + return; + + ClassLayoutTable clTable = m_tableReader.GetClassLayoutTable (); + for (int i = 0; i < clTable.Rows.Count; i++) { + ClassLayoutRow clRow = clTable [i]; + TypeDefinition type = GetTypeDefAt (clRow.Parent); + type.PackingSize = clRow.PackingSize; + type.ClassSize = clRow.ClassSize; + } + } + + void ReadFieldLayoutInfos () + { + if (!m_tHeap.HasTable (FieldLayoutTable.RId)) + return; + + FieldLayoutTable flTable = m_tableReader.GetFieldLayoutTable (); + for (int i = 0; i < flTable.Rows.Count; i++) { + FieldLayoutRow flRow = flTable [i]; + FieldDefinition field = GetFieldDefAt (flRow.Field); + field.Offset = flRow.Offset; + } + } + + void ReadPInvokeInfos () + { + if (!m_tHeap.HasTable (ImplMapTable.RId)) + return; + + ImplMapTable imTable = m_tableReader.GetImplMapTable (); + for (int i = 0; i < imTable.Rows.Count; i++) { + ImplMapRow imRow = imTable [i]; + if (imRow.MemberForwarded.TokenType == TokenType.Method) { // should always be true + MethodDefinition meth = GetMethodDefAt (imRow.MemberForwarded.RID); + meth.PInvokeInfo = new PInvokeInfo ( + meth, imRow.MappingFlags, MetadataRoot.Streams.StringsHeap [imRow.ImportName], + Module.ModuleReferences [(int) imRow.ImportScope - 1]); + } + } + } + + void ReadProperties () + { + if (!m_tHeap.HasTable (PropertyTable.RId)) + return; + + PropertyTable propsTable = m_tableReader.GetPropertyTable (); + PropertyMapTable pmapTable = m_tableReader.GetPropertyMapTable (); + m_properties = new PropertyDefinition [propsTable.Rows.Count]; + for (int i = 0; i < pmapTable.Rows.Count; i++) { + PropertyMapRow pmapRow = pmapTable [i]; + if (pmapRow.Parent == 0) + continue; + + TypeDefinition owner = GetTypeDefAt (pmapRow.Parent); + + GenericContext context = new GenericContext (owner); + + int start = (int) pmapRow.PropertyList, last = propsTable.Rows.Count + 1, end; + if (i < pmapTable.Rows.Count - 1) + end = (int) pmapTable [i + 1].PropertyList; + else + end = last; + + if (end > last) + end = last; + + for (int j = start; j < end; j++) { + PropertyRow prow = propsTable [j - 1]; + PropertySig psig = m_sigReader.GetPropSig (prow.Type); + PropertyDefinition pdef = new PropertyDefinition ( + m_root.Streams.StringsHeap [prow.Name], + GetTypeRefFromSig (psig.Type, context), + prow.Flags); + pdef.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Property, j - 1); + + pdef.PropertyType = GetModifierType (psig.CustomMods, pdef.PropertyType); + + if (!IsDeleted (pdef)) + owner.Properties.Add (pdef); + + m_properties [j - 1] = pdef; + } + } + } + + void ReadEvents () + { + if (!m_tHeap.HasTable (EventTable.RId)) + return; + + EventTable evtTable = m_tableReader.GetEventTable (); + EventMapTable emapTable = m_tableReader.GetEventMapTable (); + m_events = new EventDefinition [evtTable.Rows.Count]; + for (int i = 0; i < emapTable.Rows.Count; i++) { + EventMapRow emapRow = emapTable [i]; + if (emapRow.Parent == 0) + continue; + + TypeDefinition owner = GetTypeDefAt (emapRow.Parent); + GenericContext context = new GenericContext (owner); + + int start = (int) emapRow.EventList, last = evtTable.Rows.Count + 1, end; + if (i < (emapTable.Rows.Count - 1)) + end = (int) emapTable [i + 1].EventList; + else + end = last; + + if (end > last) + end = last; + + for (int j = start; j < end; j++) { + EventRow erow = evtTable [j - 1]; + EventDefinition edef = new EventDefinition ( + m_root.Streams.StringsHeap [erow.Name], + GetTypeDefOrRef (erow.EventType, context), erow.EventFlags); + edef.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Event, j - 1); + + if (!IsDeleted (edef)) + owner.Events.Add (edef); + + m_events [j - 1] = edef; + } + } + } + + void ReadSemantics () + { + if (!m_tHeap.HasTable (MethodSemanticsTable.RId)) + return; + + MethodSemanticsTable semTable = m_tableReader.GetMethodSemanticsTable (); + for (int i = 0; i < semTable.Rows.Count; i++) { + MethodSemanticsRow semRow = semTable [i]; + MethodDefinition semMeth = GetMethodDefAt (semRow.Method); + semMeth.SemanticsAttributes = semRow.Semantics; + switch (semRow.Association.TokenType) { + case TokenType.Event : + EventDefinition evt = GetEventDefAt (semRow.Association.RID); + if ((semRow.Semantics & MethodSemanticsAttributes.AddOn) != 0) + evt.AddMethod = semMeth; + else if ((semRow.Semantics & MethodSemanticsAttributes.Fire) != 0) + evt.InvokeMethod = semMeth; + else if ((semRow.Semantics & MethodSemanticsAttributes.RemoveOn) != 0) + evt.RemoveMethod = semMeth; + break; + case TokenType.Property : + PropertyDefinition prop = GetPropertyDefAt (semRow.Association.RID); + if ((semRow.Semantics & MethodSemanticsAttributes.Getter) != 0) + prop.GetMethod = semMeth; + else if ((semRow.Semantics & MethodSemanticsAttributes.Setter) != 0) + prop.SetMethod = semMeth; + break; + } + } + } + + void ReadInterfaces () + { + if (!m_tHeap.HasTable (InterfaceImplTable.RId)) + return; + + InterfaceImplTable intfsTable = m_tableReader.GetInterfaceImplTable (); + for (int i = 0; i < intfsTable.Rows.Count; i++) { + InterfaceImplRow intfsRow = intfsTable [i]; + TypeDefinition owner = GetTypeDefAt (intfsRow.Class); + owner.Interfaces.Add (GetTypeDefOrRef (intfsRow.Interface, new GenericContext (owner))); + } + } + + void ReadOverrides () + { + if (!m_tHeap.HasTable (MethodImplTable.RId)) + return; + + MethodImplTable implTable = m_tableReader.GetMethodImplTable (); + for (int i = 0; i < implTable.Rows.Count; i++) { + MethodImplRow implRow = implTable [i]; + if (implRow.MethodBody.TokenType == TokenType.Method) { + MethodDefinition owner = GetMethodDefAt (implRow.MethodBody.RID); + switch (implRow.MethodDeclaration.TokenType) { + case TokenType.Method : + owner.Overrides.Add ( + GetMethodDefAt (implRow.MethodDeclaration.RID)); + break; + case TokenType.MemberRef : + owner.Overrides.Add ( + (MethodReference) GetMemberRefAt ( + implRow.MethodDeclaration.RID, new GenericContext (owner))); + break; + } + } + } + } + + void ReadSecurityDeclarations () + { + if (!m_tHeap.HasTable (DeclSecurityTable.RId)) + return; + + DeclSecurityTable dsTable = m_tableReader.GetDeclSecurityTable (); + for (int i = 0; i < dsTable.Rows.Count; i++) { + DeclSecurityRow dsRow = dsTable [i]; + SecurityDeclaration dec = BuildSecurityDeclaration (dsRow); + + if (dsRow.Parent.RID == 0) + continue; + + IHasSecurity owner = null; + switch (dsRow.Parent.TokenType) { + case TokenType.Assembly : + owner = this.Module.Assembly; + break; + case TokenType.TypeDef : + owner = GetTypeDefAt (dsRow.Parent.RID); + break; + case TokenType.Method : + owner = GetMethodDefAt (dsRow.Parent.RID); + break; + } + + owner.SecurityDeclarations.Add (dec); + } + } + + void ReadCustomAttributes () + { + if (!m_tHeap.HasTable (CustomAttributeTable.RId)) + return; + + CustomAttributeTable caTable = m_tableReader.GetCustomAttributeTable (); + for (int i = 0; i < caTable.Rows.Count; i++) { + CustomAttributeRow caRow = caTable [i]; + MethodReference ctor; + + if (caRow.Type.RID == 0) + continue; + + if (caRow.Type.TokenType == TokenType.Method) + ctor = GetMethodDefAt (caRow.Type.RID); + else + ctor = GetMemberRefAt (caRow.Type.RID, new GenericContext ()) as MethodReference; + + CustomAttrib ca = m_sigReader.GetCustomAttrib (caRow.Value, ctor); + CustomAttribute cattr; + if (!ca.Read) { + cattr = new CustomAttribute (ctor); + cattr.Resolved = false; + cattr.Blob = m_root.Streams.BlobHeap.Read (caRow.Value); + } else + cattr = BuildCustomAttribute (ctor, ca); + + if (caRow.Parent.RID == 0) + continue; + + ICustomAttributeProvider owner = null; + switch (caRow.Parent.TokenType) { + case TokenType.Assembly : + owner = this.Module.Assembly; + break; + case TokenType.Module : + owner = this.Module; + break; + case TokenType.TypeDef : + owner = GetTypeDefAt (caRow.Parent.RID); + break; + case TokenType.TypeRef : + owner = GetTypeRefAt (caRow.Parent.RID); + break; + case TokenType.Field : + owner = GetFieldDefAt (caRow.Parent.RID); + break; + case TokenType.Method : + owner = GetMethodDefAt (caRow.Parent.RID); + break; + case TokenType.Property : + owner = GetPropertyDefAt (caRow.Parent.RID); + break; + case TokenType.Event : + owner = GetEventDefAt (caRow.Parent.RID); + break; + case TokenType.Param : + owner = GetParamDefAt (caRow.Parent.RID); + break; + case TokenType.GenericParam : + owner = GetGenericParameterAt (caRow.Parent.RID); + break; + default : + //TODO: support other ? + break; + } + + if (owner != null) + owner.CustomAttributes.Add (cattr); + } + } + + void ReadConstants () + { + if (!m_tHeap.HasTable (ConstantTable.RId)) + return; + + ConstantTable csTable = m_tableReader.GetConstantTable (); + for (int i = 0; i < csTable.Rows.Count; i++) { + ConstantRow csRow = csTable [i]; + + object constant = GetConstant (csRow.Value, csRow.Type); + + IHasConstant owner = null; + switch (csRow.Parent.TokenType) { + case TokenType.Field : + owner = GetFieldDefAt (csRow.Parent.RID); + break; + case TokenType.Property : + owner = GetPropertyDefAt (csRow.Parent.RID); + break; + case TokenType.Param : + owner = GetParamDefAt (csRow.Parent.RID); + break; + } + + owner.Constant = constant; + } + } + + void ReadExternTypes () + { + base.VisitExternTypeCollection (Module.ExternTypes); + } + + void ReadMarshalSpecs () + { + if (!m_tHeap.HasTable (FieldMarshalTable.RId)) + return; + + FieldMarshalTable fmTable = m_tableReader.GetFieldMarshalTable (); + for (int i = 0; i < fmTable.Rows.Count; i++) { + FieldMarshalRow fmRow = fmTable [i]; + + IHasMarshalSpec owner = null; + switch (fmRow.Parent.TokenType) { + case TokenType.Field: + owner = GetFieldDefAt (fmRow.Parent.RID); + break; + case TokenType.Param: + owner = GetParamDefAt (fmRow.Parent.RID); + break; + } + + owner.MarshalSpec = BuildMarshalDesc ( + m_sigReader.GetMarshalSig (fmRow.NativeType), owner); + } + } + + void ReadInitialValues () + { + if (!m_tHeap.HasTable (FieldRVATable.RId)) + return; + + FieldRVATable frTable = m_tableReader.GetFieldRVATable (); + for (int i = 0; i < frTable.Rows.Count; i++) { + FieldRVARow frRow = frTable [i]; + FieldDefinition field = GetFieldDefAt (frRow.Field); + field.RVA = frRow.RVA; + SetInitialValue (field); + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayDimension.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayDimension.cs new file mode 100644 index 0000000..e7dafbb --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayDimension.cs @@ -0,0 +1,59 @@ +// +// ArrayDimension.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class ArrayDimension { + + int m_lowerBound; + int m_upperBound; + + public int LowerBound { + get { return m_lowerBound; } + set { m_lowerBound = value; } + } + + public int UpperBound { + get { return m_upperBound; } + set { m_upperBound = value; } + } + + public ArrayDimension (int lb, int ub) + { + m_lowerBound = lb; + m_upperBound = ub; + } + + public override string ToString () + { + if (m_upperBound == 0) + return string.Empty; + return string.Concat (m_lowerBound, "...", m_upperBound); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayDimensionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayDimensionCollection.cs new file mode 100644 index 0000000..c31cfb1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayDimensionCollection.cs @@ -0,0 +1,88 @@ +// +// ArrayDimensionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:53 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ArrayDimensionCollection : CollectionBase { + + ArrayType m_container; + + public ArrayDimension this [int index] { + get { return List [index] as ArrayDimension; } + set { List [index] = value; } + } + + public ArrayType Container { + get { return m_container; } + } + + public ArrayDimensionCollection (ArrayType container) + { + m_container = container; + } + + public void Add (ArrayDimension value) + { + List.Add (value); + } + + public bool Contains (ArrayDimension value) + { + return List.Contains (value); + } + + public int IndexOf (ArrayDimension value) + { + return List.IndexOf (value); + } + + public void Insert (int index, ArrayDimension value) + { + List.Insert (index, value); + } + + public void Remove (ArrayDimension value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is ArrayDimension)) + throw new ArgumentException ("Must be of type " + typeof (ArrayDimension).FullName); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayType.cs new file mode 100644 index 0000000..097738c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ArrayType.cs @@ -0,0 +1,105 @@ +// +// ArrayType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Text; + + using Mono.Cecil.Signatures; + + public sealed class ArrayType : TypeSpecification { + + private ArrayDimensionCollection m_dimensions; + + public ArrayDimensionCollection Dimensions { + get { return m_dimensions; } + } + + public int Rank { + get { return m_dimensions.Count; } + } + + public bool IsSizedArray { + get { + if (this.Rank != 1) + return false; + ArrayDimension dim = m_dimensions [0]; + return dim.UpperBound == 0; + } + } + + public override string Name { + get { return string.Concat (base.Name, Suffix ()); } + } + + public override string FullName { + get { return string.Concat (base.FullName, Suffix ()); } + } + + string Suffix () + { + StringBuilder sb = new StringBuilder (); + sb.Append ("["); + for (int i = 0; i < m_dimensions.Count; i++) { + ArrayDimension dim = m_dimensions [i]; + string rank = dim.ToString (); + if (i < m_dimensions.Count - 1) + sb.Append (","); + if (rank.Length > 0) { + sb.Append (" "); + sb.Append (rank); + } + } + sb.Append ("]"); + return sb.ToString (); + } + + internal ArrayType (TypeReference elementsType, ArrayShape shape) : base (elementsType) + { + m_dimensions = new ArrayDimensionCollection (this); + for (int i = 0; i < shape.Rank; i++) { + int lower = 0, upper = 0; + if (i < shape.NumSizes) + if (i < shape.NumLoBounds) { + lower = shape.LoBounds [i]; + upper = shape.LoBounds [i] + shape.Sizes [i] - 1; + } else + upper = shape.Sizes [i] - 1; + + m_dimensions.Add (new ArrayDimension (lower, upper)); + } + } + + public ArrayType (TypeReference elementsType) : base (elementsType) + { + m_dimensions = new ArrayDimensionCollection (this); + m_dimensions.Add (new ArrayDimension (0, 0)); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs new file mode 100644 index 0000000..1187433 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyDefinition.cs @@ -0,0 +1,158 @@ +// +// AssemblyDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Metadata; + + public class AssemblyDefinition : ICustomAttributeProvider, + IHasSecurity, IAnnotationProvider, IReflectionStructureVisitable { + + MetadataToken m_token; + AssemblyNameDefinition m_asmName; + ModuleDefinitionCollection m_modules; + SecurityDeclarationCollection m_secDecls; + CustomAttributeCollection m_customAttrs; + MethodDefinition m_ep; + TargetRuntime m_runtime; + AssemblyKind m_kind; + + ModuleDefinition m_mainModule; + StructureReader m_reader; + + IAssemblyResolver m_resolver; + IDictionary m_annotations; + + public MetadataToken MetadataToken { + get { return m_token; } + set { m_token = value; } + } + + public AssemblyNameDefinition Name { + get { return m_asmName; } + } + + public ModuleDefinitionCollection Modules { + get { return m_modules; } + } + + public SecurityDeclarationCollection SecurityDeclarations { + get { + if (m_secDecls == null) + m_secDecls = new SecurityDeclarationCollection (this); + + return m_secDecls; + } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_customAttrs == null) + m_customAttrs = new CustomAttributeCollection (this); + + return m_customAttrs; + } + } + + public MethodDefinition EntryPoint { + get { return m_ep; } + set { m_ep = value; } + } + + public TargetRuntime Runtime { + get { return m_runtime; } + set { m_runtime = value; } + } + + public AssemblyKind Kind { + get { return m_kind; } + set { m_kind = value; } + } + + public ModuleDefinition MainModule { + get { + if (m_mainModule == null) + foreach (ModuleDefinition module in m_modules) + if (module.Main) + m_mainModule = module; + + return m_mainModule; + } + } + + internal StructureReader Reader { + get { return m_reader; } + } + + public IAssemblyResolver Resolver { + get { return m_resolver; } + set { m_resolver = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { + if (m_annotations == null) + m_annotations = new Hashtable (); + return m_annotations; + } + } + + internal AssemblyDefinition (AssemblyNameDefinition name) + { + if (name == null) + throw new ArgumentNullException ("name"); + + m_asmName = name; + m_modules = new ModuleDefinitionCollection (this); + m_resolver = new DefaultAssemblyResolver (); + } + + internal AssemblyDefinition (AssemblyNameDefinition name, StructureReader reader) : this (name) + { + m_reader = reader; + } + + public void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitAssemblyDefinition (this); + + m_asmName.Accept (visitor); + m_modules.Accept (visitor); + + visitor.TerminateAssemblyDefinition (this); + } + + public override string ToString () + { + return m_asmName.FullName; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyFactory.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyFactory.cs new file mode 100644 index 0000000..fb0c689 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyFactory.cs @@ -0,0 +1,176 @@ +// +// AssemblyFactory.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.IO; + using SR = System.Reflection; + + using Mono.Cecil.Binary; + + public sealed class AssemblyFactory { + + AssemblyFactory () + { + } + + static AssemblyDefinition GetAssembly (ImageReader irv, bool manifestOnly) + { + StructureReader srv = new StructureReader (irv, manifestOnly); + AssemblyDefinition asm = new AssemblyDefinition ( + new AssemblyNameDefinition (), srv); + + asm.Accept (srv); + return asm; + } + + static AssemblyDefinition GetAssembly (ImageReader reader) + { + return GetAssembly (reader, false); + } + + static AssemblyDefinition GetAssemblyManifest (ImageReader reader) + { + return GetAssembly (reader, true); + } + + public static AssemblyDefinition GetAssembly (string file) + { + return GetAssembly (ImageReader.Read (file)); + } + + public static AssemblyDefinition GetAssembly (byte [] assembly) + { + return GetAssembly (ImageReader.Read (assembly)); + } + + public static AssemblyDefinition GetAssembly (Stream stream) + { + return GetAssembly (ImageReader.Read (stream)); + } + + public static AssemblyDefinition GetAssemblyManifest (string file) + { + return GetAssemblyManifest (ImageReader.Read (file)); + } + + public static AssemblyDefinition GetAssemblyManifest (byte [] assembly) + { + return GetAssemblyManifest (ImageReader.Read (assembly)); + } + + public static AssemblyDefinition GetAssemblyManifest (Stream stream) + { + return GetAssemblyManifest (ImageReader.Read (stream)); + } + + static TargetRuntime CurrentRuntime () + { + Version corlib = typeof (object).Assembly.GetName ().Version; + if (corlib.Major == 1) + return corlib.Minor == 0 ? TargetRuntime.NET_1_0 : TargetRuntime.NET_1_1; + else // if (corlib.Major == 2) + return TargetRuntime.NET_2_0; + } + + public static AssemblyDefinition DefineAssembly (string name, AssemblyKind kind) + { + return DefineAssembly (name, name, CurrentRuntime (), kind); + } + + public static AssemblyDefinition DefineAssembly (string name, TargetRuntime rt, AssemblyKind kind) + { + return DefineAssembly (name, name, rt, kind); + } + + public static AssemblyDefinition DefineAssembly (string assemblyName, string moduleName, TargetRuntime rt, AssemblyKind kind) + { + AssemblyNameDefinition asmName = new AssemblyNameDefinition (); + asmName.Name = assemblyName; + AssemblyDefinition asm = new AssemblyDefinition (asmName); + asm.Runtime = rt; + asm.Kind = kind; + ModuleDefinition main = new ModuleDefinition (moduleName, asm, true); + asm.Modules.Add (main); + return asm; + } + + static void WriteAssembly (AssemblyDefinition asm, BinaryWriter bw) + { + asm.Accept (new StructureWriter (asm, bw)); + } + + public static void SaveAssembly (AssemblyDefinition asm, string file) + { + using (FileStream fs = new FileStream ( + file, FileMode.Create, FileAccess.Write, FileShare.None)) { + + SaveAssembly (asm, fs); + asm.MainModule.Image.SetFileInfo (new FileInfo (file)); + } + } + + public static void SaveAssembly (AssemblyDefinition asm, out byte [] assembly) + { + MemoryBinaryWriter bw = new MemoryBinaryWriter (); + SaveAssembly (asm, bw.BaseStream); + assembly = bw.ToArray (); + } + + public static void SaveAssembly (AssemblyDefinition asm, Stream stream) + { + BinaryWriter bw = new BinaryWriter (stream); + try { + WriteAssembly (asm, bw); + } finally { + bw.Close (); + } + + foreach (ModuleDefinition module in asm.Modules) + if (module.Controller.Writer.SaveSymbols) + module.Controller.Writer.WriteSymbols (module); + } + +#if !CF_1_0 && !CF_2_0 + public static SR.Assembly CreateReflectionAssembly (AssemblyDefinition asm, AppDomain domain) + { + using (MemoryBinaryWriter writer = new MemoryBinaryWriter ()) { + + WriteAssembly (asm, writer); + return domain.Load (writer.ToArray ()); + } + } + + public static SR.Assembly CreateReflectionAssembly (AssemblyDefinition asm) + { + return CreateReflectionAssembly (asm, AppDomain.CurrentDomain); + } +#endif + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs new file mode 100644 index 0000000..9231fc8 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyFlags.cs @@ -0,0 +1,41 @@ +// +// AssemblyFlags.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum AssemblyFlags : uint { + PublicKey = 0x0001, + SideBySideCompatible = 0x0000, + Retargetable = 0x0100, + EnableJITcompileTracking = 0x8000, + DisableJITcompileOptimizer = 0x4000 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs new file mode 100644 index 0000000..e32c2ec --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyHashAlgorithm.cs @@ -0,0 +1,37 @@ +// +// AssemblyHashAlgorithm.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public enum AssemblyHashAlgorithm : uint { + None = 0x0000, + Reserved = 0x8003, // MD5 + SHA1 = 0x8004 + } +} + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyInfo.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyInfo.cs new file mode 100644 index 0000000..6092924 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyInfo.cs @@ -0,0 +1,55 @@ +// +// AssemblyInfo.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +#if !EMBEDDED + +[assembly: AssemblyTitle ("Mono.Cecil")] +[assembly: AssemblyDescription ("Library for reading and writing CIL images")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyProduct ("Mono.Cecil")] +[assembly: AssemblyCopyright ("(C) 2005 - 2007, Jb Evain")] +[assembly: AssemblyCulture ("")] + +[assembly: CLSCompliant (false)] +[assembly: ComVisible (false)] + +[assembly: AssemblyVersion ("0.6.8.8607")] + +#if KEYFILE +[assembly: AssemblyKeyFile("../../mono.snk")] +#endif + +#endif + + + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyKind.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyKind.cs new file mode 100644 index 0000000..7d5e7c0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyKind.cs @@ -0,0 +1,36 @@ +// +// AssemblyKind.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public enum AssemblyKind { + Dll, + Console, + Windows + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs new file mode 100644 index 0000000..0ff9ff1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyLinkedResource.cs @@ -0,0 +1,51 @@ +// +// AssemblyLinkedResource.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class AssemblyLinkedResource : Resource { + + private AssemblyNameReference m_asmRef; + + public AssemblyNameReference Assembly { + get { return m_asmRef; } + set { m_asmRef = value; } + } + + public AssemblyLinkedResource (string name, ManifestResourceAttributes flags, + AssemblyNameReference asmRef) : base (name, flags) + { + m_asmRef = asmRef; + } + + public override void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitAssemblyLinkedResource (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs new file mode 100644 index 0000000..bf54fb5 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameDefinition.cs @@ -0,0 +1,52 @@ +// +// AssemblyNameDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + public sealed class AssemblyNameDefinition : AssemblyNameReference { + + public override byte [] Hash { + get { return new byte [0]; } + } + + public AssemblyNameDefinition () : base() + { + } + + public AssemblyNameDefinition (string name, string culture, Version version) : base (name, culture, version) + { + } + + public override void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitAssemblyNameDefinition (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs new file mode 100644 index 0000000..bb1f55c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameReference.cs @@ -0,0 +1,275 @@ +// +// AssemblyNameReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + using System.Globalization; + using System.Security.Cryptography; + using System.Text; + + using Mono.Cecil.Metadata; + + public class AssemblyNameReference : IMetadataScope, IAnnotationProvider, IReflectionStructureVisitable { + + string m_name; + string m_culture; + Version m_version; + AssemblyFlags m_flags; + byte [] m_publicKey; + byte [] m_publicKeyToken; + AssemblyHashAlgorithm m_hashAlgo; + byte [] m_hash; + MetadataToken m_token; + IDictionary m_annotations; + + bool m_fullNameDiscarded = true; + string m_fullName; + + public string Name { + get { return m_name; } + set { + m_name = value; + m_fullNameDiscarded = true; + } + } + + public string Culture { + get { return m_culture; } + set { + m_culture = value; + m_fullNameDiscarded = true; + } + } + + public Version Version { + get { return m_version; } + set { + m_version = value; + m_fullNameDiscarded = true; + } + } + + public AssemblyFlags Flags { + get { return m_flags; } + set { m_flags = value; } + } + + public bool HasPublicKey { + get { return (m_flags & AssemblyFlags.PublicKey) != 0; } + set { + if (value) + m_flags |= AssemblyFlags.PublicKey; + else + m_flags &= ~AssemblyFlags.PublicKey; + } + } + + public bool IsSideBySideCompatible { + get { return (m_flags & AssemblyFlags.SideBySideCompatible) != 0; } + set { + if (value) + m_flags |= AssemblyFlags.SideBySideCompatible; + else + m_flags &= ~AssemblyFlags.SideBySideCompatible; + } + } + + public bool IsRetargetable { + get { return (m_flags & AssemblyFlags.Retargetable) != 0; } + set { + if (value) + m_flags |= AssemblyFlags.Retargetable; + else + m_flags &= ~AssemblyFlags.Retargetable; + } + } + + public byte [] PublicKey { + get { return m_publicKey; } + set { + m_publicKey = value; + m_publicKeyToken = null; + m_fullNameDiscarded = true; + } + } + + public byte [] PublicKeyToken { + get { +#if !CF_1_0 + if ((m_publicKeyToken == null || m_publicKeyToken.Length == 0) && (m_publicKey != null && m_publicKey.Length > 0)) { + HashAlgorithm ha; + switch (m_hashAlgo) { + case AssemblyHashAlgorithm.Reserved: + ha = MD5.Create (); break; + default: + // None default to SHA1 + ha = SHA1.Create (); break; + } + byte [] hash = ha.ComputeHash (m_publicKey); + // we need the last 8 bytes in reverse order + m_publicKeyToken = new byte [8]; + Array.Copy (hash, (hash.Length - 8), m_publicKeyToken, 0, 8); + Array.Reverse (m_publicKeyToken, 0, 8); + } +#endif + return m_publicKeyToken; + } + set { + m_publicKeyToken = value; + m_fullNameDiscarded = true; + } + } + + public string FullName { + get { + if (m_fullName != null && !m_fullNameDiscarded) + return m_fullName; + + StringBuilder sb = new StringBuilder (); + string sep = ", "; + sb.Append (m_name); + if (m_version != null) { + sb.Append (sep); + sb.Append ("Version="); + sb.Append (m_version.ToString ()); + } + sb.Append (sep); + sb.Append ("Culture="); + sb.Append (m_culture == null || m_culture == string.Empty ? "neutral" : m_culture); + sb.Append (sep); + sb.Append ("PublicKeyToken="); + if (this.PublicKeyToken != null && m_publicKeyToken.Length > 0) { + for (int i = 0 ; i < m_publicKeyToken.Length ; i++) { + sb.Append (m_publicKeyToken [i].ToString ("x2")); + } + } else { + sb.Append ("null"); + } + m_fullName = sb.ToString (); + m_fullNameDiscarded = false; + return m_fullName; + } + } + + public static AssemblyNameReference Parse (string fullName) + { + if (fullName == null) + throw new ArgumentNullException ("fullName"); + if (fullName.Length == 0) + throw new ArgumentException ("Name can not be empty"); + + AssemblyNameReference name = new AssemblyNameReference (); + string [] tokens = fullName.Split (','); + for (int i = 0; i < tokens.Length; i++) { + string token = tokens [i].Trim (); + + if (i == 0) { + name.Name = token; + continue; + } + + string [] parts = token.Split ('='); + if (parts.Length != 2) + throw new ArgumentException ("Malformed name"); + + switch (parts [0]) { + case "Version": + name.Version = new Version (parts [1]); + break; + case "Culture": + name.Culture = parts [1]; + break; + case "PublicKeyToken": + string pkToken = parts [1]; + if (pkToken == "null") + break; + + name.PublicKeyToken = new byte [pkToken.Length / 2]; + for (int j = 0; j < name.PublicKeyToken.Length; j++) { + name.PublicKeyToken [j] = Byte.Parse (pkToken.Substring (j * 2, 2), NumberStyles.HexNumber); + } + break; + } + } + + return name; + } + + public AssemblyHashAlgorithm HashAlgorithm + { + get { return m_hashAlgo; } + set { m_hashAlgo = value; } + } + + public virtual byte [] Hash { + get { return m_hash; } + set { m_hash = value; } + } + + public MetadataToken MetadataToken { + get { return m_token; } + set { m_token = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { + if (m_annotations == null) + m_annotations = new Hashtable (); + return m_annotations; + } + } + + public AssemblyNameReference () : this (string.Empty, string.Empty, new Version (0, 0, 0, 0)) + { + } + + public AssemblyNameReference (string name, string culture, Version version) + { + if (name == null) + throw new ArgumentNullException ("name"); + if (culture == null) + throw new ArgumentNullException ("culture"); + m_name = name; + m_culture = culture; + m_version = version; + m_hashAlgo = AssemblyHashAlgorithm.None; + } + + public override string ToString () + { + return this.FullName; + } + + public virtual void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitAssemblyNameReference (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameReferenceCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameReferenceCollection.cs new file mode 100644 index 0000000..be2b3b9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/AssemblyNameReferenceCollection.cs @@ -0,0 +1,93 @@ +// +// AssemblyNameReferenceCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:52 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class AssemblyNameReferenceCollection : CollectionBase, IReflectionStructureVisitable { + + ModuleDefinition m_container; + + public AssemblyNameReference this [int index] { + get { return List [index] as AssemblyNameReference; } + set { List [index] = value; } + } + + public ModuleDefinition Container { + get { return m_container; } + } + + public AssemblyNameReferenceCollection (ModuleDefinition container) + { + m_container = container; + } + + public void Add (AssemblyNameReference value) + { + List.Add (value); + } + + public bool Contains (AssemblyNameReference value) + { + return List.Contains (value); + } + + public int IndexOf (AssemblyNameReference value) + { + return List.IndexOf (value); + } + + public void Insert (int index, AssemblyNameReference value) + { + List.Insert (index, value); + } + + public void Remove (AssemblyNameReference value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is AssemblyNameReference)) + throw new ArgumentException ("Must be of type " + typeof (AssemblyNameReference).FullName); + } + + public void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitAssemblyNameReferenceCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs new file mode 100644 index 0000000..3d276cf --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseAssemblyResolver.cs @@ -0,0 +1,211 @@ +// +// BaseAssemblyResolver.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + using System.IO; + using SR = System.Reflection; + using System.Text; + + public abstract class BaseAssemblyResolver : IAssemblyResolver { + + ArrayList m_directories; + + public void AddSearchDirectory (string directory) + { + m_directories.Add (directory); + } + + public void RemoveSearchDirectory (string directory) + { + m_directories.Remove (directory); + } + + public string [] GetSearchDirectories () + { + return (string []) m_directories.ToArray (); + } + + public virtual AssemblyDefinition Resolve (string fullName) + { + return Resolve (AssemblyNameReference.Parse (fullName)); + } + + public BaseAssemblyResolver () + { + m_directories = new ArrayList (); + m_directories.Add ("."); + m_directories.Add ("bin"); + } + + public virtual AssemblyDefinition Resolve (AssemblyNameReference name) + { + AssemblyDefinition assembly; + string frameworkdir = Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName); + + assembly = SearchDirectory (name, m_directories); + if (assembly != null) + return assembly; + + if (IsZero (name.Version)) { + assembly = SearchDirectory (name, new string [] {frameworkdir}); + if (assembly != null) + return assembly; + } + +#if !CF_1_0 && !CF_2_0 + if (name.Name == "mscorlib") { + assembly = GetCorlib (name); + if (assembly != null) + return assembly; + } + + assembly = GetAssemblyInGac (name); + if (assembly != null) + return assembly; +#endif + + assembly = SearchDirectory (name, new string [] {frameworkdir}); + if (assembly != null) + return assembly; + + throw new FileNotFoundException ("Could not resolve: " + name); + } + + static readonly string [] _extentions = new string [] { ".dll", ".exe" }; + + static AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable directories) + { + foreach (string dir in directories) { + foreach (string ext in _extentions) { + string file = Path.Combine (dir, name.Name + ext); + if (File.Exists (file)) + return AssemblyFactory.GetAssembly (file); + } + } + + return null; + } + + static bool IsZero (Version version) + { + return version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0; + } + +#if !CF_1_0 && !CF_2_0 + static AssemblyDefinition GetCorlib (AssemblyNameReference reference) + { + SR.AssemblyName corlib = typeof (object).Assembly.GetName (); + if (corlib.Version == reference.Version || IsZero (reference.Version)) + return AssemblyFactory.GetAssembly (typeof (object).Module.FullyQualifiedName); + + string path = Directory.GetParent ( + Directory.GetParent ( + typeof (object).Module.FullyQualifiedName).FullName + ).FullName; + + if (OnMono ()) { + if (reference.Version.Major == 1) + path = Path.Combine (path, "1.0"); + else if (reference.Version.Major == 2) + path = Path.Combine (path, "2.0"); + else + throw new NotSupportedException ("Version not supported: " + reference.Version); + } else { + if (reference.Version.ToString () == "1.0.3300.0") + path = Path.Combine (path, "v1.0.3705"); + else if (reference.Version.ToString () == "1.0.5000.0") + path = Path.Combine (path, "v1.1.4322"); + else if (reference.Version.ToString () == "2.0.0.0") + path = Path.Combine (path, "v2.0.50727"); + else + throw new NotSupportedException ("Version not supported: " + reference.Version); + } + + if (File.Exists (Path.Combine (path, "mscorlib.dll"))) + return AssemblyFactory.GetAssembly (Path.Combine (path, "mscorlib.dll")); + + return null; + } + + public static bool OnMono () + { + return typeof (object).Assembly.GetType ("System.MonoType", false) != null; + } + + static AssemblyDefinition GetAssemblyInGac (AssemblyNameReference reference) + { + if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0) + return null; + + string currentGac = GetCurrentGacPath (); + if (OnMono ()) { + string s = GetAssemblyFile (reference, currentGac); + if (File.Exists (s)) + return AssemblyFactory.GetAssembly (s); + } else { + string [] gacs = new string [] {"GAC_MSIL", "GAC_32", "GAC"}; + for (int i = 0; i < gacs.Length; i++) { + string gac = Path.Combine (Directory.GetParent (currentGac).FullName, gacs [i]); + string asm = GetAssemblyFile (reference, gac); + if (Directory.Exists (gac) && File.Exists (asm)) + return AssemblyFactory.GetAssembly (asm); + } + } + + return null; + } + + static string GetAssemblyFile (AssemblyNameReference reference, string gac) + { + StringBuilder sb = new StringBuilder (); + sb.Append (reference.Version); + sb.Append ("__"); + for (int i = 0; i < reference.PublicKeyToken.Length; i++) + sb.Append (reference.PublicKeyToken [i].ToString ("x2")); + + return Path.Combine ( + Path.Combine ( + Path.Combine (gac, reference.Name), sb.ToString ()), + string.Concat (reference.Name, ".dll")); + } + + static string GetCurrentGacPath () + { + return Directory.GetParent ( + Directory.GetParent ( + Path.GetDirectoryName ( + typeof (Uri).Module.FullyQualifiedName) + ).FullName + ).FullName; + } +#endif + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseReflectionReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseReflectionReader.cs new file mode 100644 index 0000000..ceeec17 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseReflectionReader.cs @@ -0,0 +1,73 @@ +// +// BaseReflectionReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + internal abstract class BaseReflectionReader : BaseReflectionVisitor, IDetailReader { + + public virtual void ReadSemantic (EventDefinition evt) + { + } + + public virtual void ReadSemantic (PropertyDefinition prop) + { + } + + public virtual void ReadMarshalSpec (ParameterDefinition param) + { + } + + public virtual void ReadMarshalSpec (FieldDefinition field) + { + } + + public virtual void ReadLayout (TypeDefinition type) + { + } + + public virtual void ReadLayout (FieldDefinition field) + { + } + + public virtual void ReadConstant (FieldDefinition field) + { + } + + public virtual void ReadConstant (PropertyDefinition prop) + { + } + + public virtual void ReadConstant (ParameterDefinition param) + { + } + + public virtual void ReadInitialValue (FieldDefinition field) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseReflectionVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseReflectionVisitor.cs new file mode 100644 index 0000000..3d3a514 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseReflectionVisitor.cs @@ -0,0 +1,188 @@ +// +// BaseReflectionVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + public abstract class BaseReflectionVisitor : IReflectionVisitor { + + public virtual void VisitModuleDefinition (ModuleDefinition module) + { + } + + public virtual void VisitTypeDefinitionCollection (TypeDefinitionCollection types) + { + } + + public virtual void VisitTypeDefinition (TypeDefinition type) + { + } + + public virtual void VisitTypeReferenceCollection (TypeReferenceCollection refs) + { + } + + public virtual void VisitTypeReference (TypeReference type) + { + } + + public virtual void VisitMemberReferenceCollection (MemberReferenceCollection members) + { + } + + public virtual void VisitMemberReference (MemberReference member) + { + } + + public virtual void VisitInterfaceCollection (InterfaceCollection interfaces) + { + } + + public virtual void VisitInterface (TypeReference interf) + { + } + + public virtual void VisitExternTypeCollection (ExternTypeCollection externs) + { + } + + public virtual void VisitExternType (TypeReference externType) + { + } + + public virtual void VisitOverrideCollection (OverrideCollection meth) + { + } + + public virtual void VisitOverride (MethodReference ov) + { + } + + public virtual void VisitNestedTypeCollection (NestedTypeCollection nestedTypes) + { + } + + public virtual void VisitNestedType (TypeDefinition nestedType) + { + } + + public virtual void VisitParameterDefinitionCollection (ParameterDefinitionCollection parameters) + { + } + + public virtual void VisitParameterDefinition (ParameterDefinition parameter) + { + } + + public virtual void VisitMethodDefinitionCollection (MethodDefinitionCollection methods) + { + } + + public virtual void VisitMethodDefinition (MethodDefinition method) + { + } + + public virtual void VisitConstructorCollection (ConstructorCollection ctors) + { + } + + public virtual void VisitConstructor (MethodDefinition ctor) + { + } + + public virtual void VisitPInvokeInfo (PInvokeInfo pinvk) + { + } + + public virtual void VisitEventDefinitionCollection (EventDefinitionCollection events) + { + } + + public virtual void VisitEventDefinition (EventDefinition evt) + { + } + + public virtual void VisitFieldDefinitionCollection (FieldDefinitionCollection fields) + { + } + + public virtual void VisitFieldDefinition (FieldDefinition field) + { + } + + public virtual void VisitPropertyDefinitionCollection (PropertyDefinitionCollection properties) + { + } + + public virtual void VisitPropertyDefinition (PropertyDefinition property) + { + } + + public virtual void VisitSecurityDeclarationCollection (SecurityDeclarationCollection secDecls) + { + } + + public virtual void VisitSecurityDeclaration (SecurityDeclaration secDecl) + { + } + + public virtual void VisitCustomAttributeCollection (CustomAttributeCollection customAttrs) + { + } + + public virtual void VisitCustomAttribute (CustomAttribute customAttr) + { + } + + public virtual void VisitGenericParameterCollection (GenericParameterCollection genparams) + { + } + + public virtual void VisitGenericParameter (GenericParameter genparam) + { + } + + public virtual void VisitMarshalSpec (MarshalSpec marshalSpec) + { + } + + public virtual void TerminateModuleDefinition (ModuleDefinition module) + { + } + + protected void VisitCollection (ICollection coll) + { + if (coll.Count == 0) + return; + + foreach (IReflectionVisitable visitable in coll) + visitable.Accept (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseStructureVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseStructureVisitor.cs new file mode 100644 index 0000000..1acec7d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/BaseStructureVisitor.cs @@ -0,0 +1,96 @@ +// +// BaseStructureVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + public abstract class BaseStructureVisitor : IReflectionStructureVisitor { + + public virtual void VisitAssemblyDefinition (AssemblyDefinition asm) + { + } + + public virtual void VisitAssemblyNameDefinition (AssemblyNameDefinition name) + { + } + + public virtual void VisitAssemblyNameReferenceCollection (AssemblyNameReferenceCollection names) + { + } + + public virtual void VisitAssemblyNameReference (AssemblyNameReference name) + { + } + + public virtual void VisitResourceCollection (ResourceCollection resources) + { + } + + public virtual void VisitEmbeddedResource (EmbeddedResource res) + { + } + + public virtual void VisitLinkedResource (LinkedResource res) + { + } + + public virtual void VisitAssemblyLinkedResource (AssemblyLinkedResource res) + { + } + + public virtual void VisitModuleDefinition (ModuleDefinition module) + { + } + + public virtual void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules) + { + } + + public virtual void VisitModuleReference (ModuleReference module) + { + } + + public virtual void VisitModuleReferenceCollection (ModuleReferenceCollection modules) + { + } + + public virtual void TerminateAssemblyDefinition (AssemblyDefinition asm) + { + } + + protected void VisitCollection (ICollection coll) + { + if (coll.Count == 0) + return; + + foreach (IReflectionStructureVisitable visitable in coll) + visitable.Accept (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CallSite.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CallSite.cs new file mode 100644 index 0000000..586203c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CallSite.cs @@ -0,0 +1,103 @@ +// +// CallSite.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + using System.Text; + + using Mono.Cecil.Metadata; + + public sealed class CallSite : IMethodSignature, IAnnotationProvider, IMetadataTokenProvider { + + MethodReference m_function; + + public bool HasThis { + get { return m_function.HasThis; } + set { m_function.HasThis = value; } + } + + public bool ExplicitThis { + get { return m_function.ExplicitThis; } + set { m_function.ExplicitThis = value; } + } + + public MethodCallingConvention CallingConvention { + get { return m_function.CallingConvention; } + set { m_function.CallingConvention = value; } + } + + public ParameterDefinitionCollection Parameters { + get { return m_function.Parameters; } + } + + public MethodReturnType ReturnType { + get { return m_function.ReturnType; } + set { m_function.ReturnType = value; } + } + + public MetadataToken MetadataToken { + get { return m_function.MetadataToken; } + set { m_function.MetadataToken = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { return ((IAnnotationProvider) m_function).Annotations; } + } + + public CallSite (bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType) + { + m_function = new MethodReference (string.Empty, hasThis, explicitThis, callConv); + m_function.ReturnType = retType; + } + + public int GetSentinel () + { + return m_function.GetSentinel (); + } + + public override string ToString () + { + int sentinel = GetSentinel (); + StringBuilder sb = new StringBuilder (); + sb.Append (m_function.ReturnType.ReturnType.FullName); + sb.Append ("("); + for (int i = 0; i < m_function.Parameters.Count; i++) { + if (i > 0) + sb.Append (","); + + if (i == sentinel) + sb.Append ("...,"); + + sb.Append (m_function.Parameters [i].ParameterType.FullName); + } + sb.Append (")"); + return sb.ToString (); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CompactFrameworkCompatibility.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CompactFrameworkCompatibility.cs new file mode 100644 index 0000000..85fde6e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CompactFrameworkCompatibility.cs @@ -0,0 +1,68 @@ +// +// FrameworkCompatibility.cs +// +// Author: +// Rodrigo B. de Oliveira (rodrigobamboo@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +#if CF_1_0 +namespace System { + + internal class NotImplementedException : System.Exception { + + public NotImplementedException (string message) : base (message) + { + } + + public NotImplementedException () + { + } + } +} +#endif + +#if CF_1_0 || CF_2_0 +namespace System.Security { + + public class SecurityElement { + + public SecurityElement (string tag) + { + } + + public string Text + { + get { return string.Empty; } + set {} + } + + public void AddChild (SecurityElement child) + { + } + + public void AddAttribute (string name, string value) + { + } + } +} +#endif diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Constants.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Constants.cs new file mode 100644 index 0000000..32491e6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Constants.cs @@ -0,0 +1,65 @@ +// +// Constants.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public class Constants { + + Constants () + { + } + + public const string Corlib = "mscorlib"; + + public const string ModuleType = "<Module>"; + public const string PrivateImplDetails = "<PrivateImplementationDetails>"; + public const string Deleted = "_Deleted"; + + public const string Void = "System.Void"; + public const string Object = "System.Object"; + public const string String = "System.String"; + public const string Boolean = "System.Boolean"; + public const string Char = "System.Char"; + public const string Single = "System.Single"; + public const string Double = "System.Double"; + public const string SByte = "System.SByte"; + public const string Byte = "System.Byte"; + public const string Int16 = "System.Int16"; + public const string UInt16 = "System.UInt16"; + public const string Int32 = "System.Int32"; + public const string UInt32 = "System.UInt32"; + public const string Int64 = "System.Int64"; + public const string UInt64 = "System.UInt64"; + public const string IntPtr = "System.IntPtr"; + public const string UIntPtr = "System.UIntPtr"; + public const string TypedReference = "System.TypedReference"; + public const string Type = "System.Type"; + public const string ValueType = "System.ValueType"; + public const string Enum = "System.Enum"; + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ConstraintCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ConstraintCollection.cs new file mode 100644 index 0000000..0c0f293 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ConstraintCollection.cs @@ -0,0 +1,88 @@ +// +// ConstraintCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:54 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ConstraintCollection : CollectionBase { + + GenericParameter m_container; + + public TypeReference this [int index] { + get { return List [index] as TypeReference; } + set { List [index] = value; } + } + + public GenericParameter Container { + get { return m_container; } + } + + public ConstraintCollection (GenericParameter container) + { + m_container = container; + } + + public void Add (TypeReference value) + { + List.Add (value); + } + + public bool Contains (TypeReference value) + { + return List.Contains (value); + } + + public int IndexOf (TypeReference value) + { + return List.IndexOf (value); + } + + public void Insert (int index, TypeReference value) + { + List.Insert (index, value); + } + + public void Remove (TypeReference value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is TypeReference)) + throw new ArgumentException ("Must be of type " + typeof (TypeReference).FullName); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ConstructorCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ConstructorCollection.cs new file mode 100644 index 0000000..d348f5b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ConstructorCollection.cs @@ -0,0 +1,175 @@ +// +// ConstructorCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:56 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ConstructorCollection : CollectionBase, IReflectionVisitable { + + TypeDefinition m_container; + + public MethodDefinition this [int index] { + get { return List [index] as MethodDefinition; } + set { List [index] = value; } + } + + public TypeDefinition Container { + get { return m_container; } + } + + public ConstructorCollection (TypeDefinition container) + { + m_container = container; + } + + public void Add (MethodDefinition value) + { + Attach (value); + + List.Add (value); + } + + + public new void Clear () + { + foreach (MethodDefinition item in this) + Detach (item); + + base.Clear (); + } + + public bool Contains (MethodDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (MethodDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, MethodDefinition value) + { + Attach (value); + + List.Insert (index, value); + } + + public void Remove (MethodDefinition value) + { + List.Remove (value); + + Detach (value); + } + + + public new void RemoveAt (int index) + { + MethodDefinition item = this [index]; + Remove (item); + } + + protected override void OnValidate (object o) + { + if (! (o is MethodDefinition)) + throw new ArgumentException ("Must be of type " + typeof (MethodDefinition).FullName); + } + + internal MethodDefinition GetConstructorInternal (bool isStatic, IList parameters) + { + foreach (MethodDefinition ctor in this) { + if (ctor.IsStatic != isStatic || ctor.Parameters.Count != parameters.Count) + continue; + + bool match = true; + for (int i = 0; i < parameters.Count; i++) { + string pname; + object param = parameters [i]; + if (param is Type) + pname = ReflectionHelper.GetTypeSignature (param as Type); + else if (param is TypeReference) + pname = (param as TypeReference).FullName; + else if (param is ParameterDefinition) + pname = (param as ParameterDefinition).ParameterType.FullName; + else + throw new NotSupportedException (); + + if (ctor.Parameters [i].ParameterType.FullName != pname) { + match = false; + break; + } + } + + if (match) + return ctor; + } + + return null; + } + + public MethodDefinition GetConstructor (bool isStatic, Type [] parameters) + { + return GetConstructorInternal (isStatic, parameters); + } + + public MethodDefinition GetConstructor (bool isStatic, TypeReference [] parameters) + { + return GetConstructorInternal (isStatic, parameters); + } + + public MethodDefinition GetConstructor (bool isStatic, ParameterDefinitionCollection parameters) + { + return GetConstructorInternal (isStatic, parameters); + } + + void Attach (MemberReference member) + { + if (member.DeclaringType != null) + throw new ReflectionException ("Member already attached, clone it instead"); + + member.DeclaringType = m_container; + } + + void Detach (MemberReference member) + { + member.DeclaringType = null; + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitConstructorCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CustomAttribute.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CustomAttribute.cs new file mode 100644 index 0000000..c98f933 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CustomAttribute.cs @@ -0,0 +1,193 @@ +// +// CustomAttribute.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + public sealed class CustomAttribute : IRequireResolving, IAnnotationProvider, IReflectionVisitable { + + MethodReference m_ctor; + IList m_parameters; + IDictionary m_fields; + IDictionary m_properties; + IDictionary m_fieldTypes; + IDictionary m_propTypes; + IDictionary m_annotations; + + bool m_resolved; + byte [] m_blob; + + public MethodReference Constructor { + get { return m_ctor; } + set { m_ctor = value; } + } + + public IList ConstructorParameters { + get { + if (m_parameters == null) + m_parameters = new ArrayList (); + return m_parameters; + } + } + + public IDictionary Fields { + get { + if (m_fields == null) + m_fields = new Hashtable (); + + return m_fields; + } + } + + public IDictionary Properties { + get { + if (m_properties == null) + m_properties = new Hashtable (); + + return m_properties; + } + } + + internal IDictionary FieldTypes { + get { + if (m_fieldTypes == null) + m_fieldTypes = new Hashtable (); + + return m_fieldTypes; + } + } + + internal IDictionary PropertyTypes { + get { + if (m_propTypes == null) + m_propTypes = new Hashtable (); + + return m_propTypes; + } + } + + public bool Resolved { + get { return m_resolved; } + set { m_resolved = value; } + } + + public byte [] Blob { + get { return m_blob; } + set { m_blob = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { + if (m_annotations == null) + m_annotations = new Hashtable (); + return m_annotations; + } + } + + public CustomAttribute (MethodReference ctor) + { + m_ctor = ctor; + m_resolved = true; + } + + public TypeReference GetFieldType (string fieldName) + { + return (TypeReference) FieldTypes [fieldName]; + } + + public TypeReference GetPropertyType (string propertyName) + { + return (TypeReference) PropertyTypes [propertyName]; + } + + public void SetFieldType (string fieldName, TypeReference type) + { + FieldTypes [fieldName] = type; + } + + public void SetPropertyType (string propertyName, TypeReference type) + { + PropertyTypes [propertyName] = type; + } + + public CustomAttribute Clone () + { + return Clone (this, new ImportContext (NullReferenceImporter.Instance)); + } + + static void Clone (IDictionary original, IDictionary target) + { + target.Clear (); + foreach (DictionaryEntry entry in original) + target.Add (entry.Key, entry.Value); + } + + internal static CustomAttribute Clone (CustomAttribute custattr, ImportContext context) + { + CustomAttribute ca = new CustomAttribute (context.Import (custattr.Constructor)); + custattr.CopyTo (ca); + return ca; + } + + void CopyTo (CustomAttribute target) + { + target.Resolved = Resolved; + if (!Resolved) { + target.Blob = Blob; + return; + } + + foreach (object o in ConstructorParameters) + target.ConstructorParameters.Add (o); + Clone (Fields, target.Fields); + Clone (FieldTypes, target.FieldTypes); + Clone (Properties, target.Properties); + Clone (PropertyTypes, target.PropertyTypes); + } + + public bool Resolve () + { + if (Resolved) + return true; + + ReflectionReader r = m_ctor.DeclaringType.Module.Controller.Reader; + CustomAttribute newCa = r.GetCustomAttribute (m_ctor, Blob, true); + if (!newCa.Resolved) + return false; + + newCa.CopyTo (this); + return true; + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitCustomAttribute (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CustomAttributeCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CustomAttributeCollection.cs new file mode 100644 index 0000000..023b35a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/CustomAttributeCollection.cs @@ -0,0 +1,93 @@ +// +// CustomAttributeCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:53 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class CustomAttributeCollection : CollectionBase, IReflectionVisitable { + + ICustomAttributeProvider m_container; + + public CustomAttribute this [int index] { + get { return List [index] as CustomAttribute; } + set { List [index] = value; } + } + + public ICustomAttributeProvider Container { + get { return m_container; } + } + + public CustomAttributeCollection (ICustomAttributeProvider container) + { + m_container = container; + } + + public void Add (CustomAttribute value) + { + List.Add (value); + } + + public bool Contains (CustomAttribute value) + { + return List.Contains (value); + } + + public int IndexOf (CustomAttribute value) + { + return List.IndexOf (value); + } + + public void Insert (int index, CustomAttribute value) + { + List.Insert (index, value); + } + + public void Remove (CustomAttribute value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is CustomAttribute)) + throw new ArgumentException ("Must be of type " + typeof (CustomAttribute).FullName); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitCustomAttributeCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs new file mode 100644 index 0000000..95b8789 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/DefaultAssemblyResolver.cs @@ -0,0 +1,62 @@ +// +// DefaultAssemblyResolver.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + public class DefaultAssemblyResolver : BaseAssemblyResolver { + + IDictionary m_cache; + + public DefaultAssemblyResolver () + { + m_cache = new Hashtable (); + } + + public override AssemblyDefinition Resolve (AssemblyNameReference name) + { + AssemblyDefinition asm = (AssemblyDefinition) m_cache [name.FullName]; + if (asm == null) { + asm = base.Resolve (name); + m_cache [name.FullName] = asm; + } + + return asm; + } + + protected void RegisterAssembly (AssemblyDefinition assembly) + { + string key = assembly.Name.FullName; + if (m_cache.Contains (key)) + return; + + m_cache [key] = assembly; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/DefaultImporter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/DefaultImporter.cs new file mode 100644 index 0000000..f8d3011 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/DefaultImporter.cs @@ -0,0 +1,230 @@ +// +// DefaultReferenceImporter.cs +// +// Author: +// Jb Evain (jbevain@novell.com) +// +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + public class DefaultImporter : IImporter { + + ModuleDefinition m_module; + + public ModuleDefinition Module { + get { return m_module; } + } + + public DefaultImporter (ModuleDefinition module) + { + m_module = module; + } + + public AssemblyNameReference ImportAssembly (AssemblyNameReference asm) + { + AssemblyNameReference asmRef = GetAssemblyNameReference (asm); + if (asmRef != null) + return asmRef; + + asmRef = new AssemblyNameReference ( + asm.Name, asm.Culture, asm.Version); + asmRef.PublicKeyToken = asm.PublicKeyToken; + asmRef.HashAlgorithm = asm.HashAlgorithm; + m_module.AssemblyReferences.Add (asmRef); + return asmRef; + } + + AssemblyNameReference GetAssemblyNameReference (AssemblyNameReference asm) + { + foreach (AssemblyNameReference reference in m_module.AssemblyReferences) + if (reference.FullName == asm.FullName) + return reference; + + return null; + } + + TypeReference GetTypeSpec (TypeReference t, ImportContext context) + { + Stack s = new Stack (); + while (t is TypeSpecification) { + s.Push (t); + t = (t as TypeSpecification).ElementType; + } + + TypeReference elementType = ImportTypeReference (t, context); + while (s.Count > 0) { + t = (TypeReference) s.Pop (); + if (t is PointerType) + elementType = new PointerType (elementType); + else if (t is ArrayType) // deal with complex arrays + elementType = new ArrayType (elementType); + else if (t is ReferenceType) + elementType = new ReferenceType (elementType); + else if (t is GenericInstanceType) { + GenericInstanceType git = t as GenericInstanceType; + GenericInstanceType genElemType = new GenericInstanceType (elementType); + + context.GenericContext.CheckProvider (genElemType.GetOriginalType (), git.GenericArguments.Count); + foreach (TypeReference arg in git.GenericArguments) + genElemType.GenericArguments.Add (ImportTypeReference (arg, context)); + + elementType = genElemType; + } else + throw new ReflectionException ("Unknown element type: {0}", t.GetType ().Name); + } + + return elementType; + } + + static GenericParameter GetGenericParameter (GenericParameter gp, ImportContext context) + { + GenericParameter p; + if (gp.Owner is TypeReference) + p = context.GenericContext.Type.GenericParameters [gp.Position]; + else if (gp.Owner is MethodReference) + p = context.GenericContext.Method.GenericParameters [gp.Position]; + else + throw new NotSupportedException (); + + return p; + } + + public virtual TypeReference ImportTypeReference (TypeReference t, ImportContext context) + { + if (t.Module == m_module) + return t; + + if (t is TypeSpecification) + return GetTypeSpec (t, context); + + if (t is GenericParameter) + return GetGenericParameter (t as GenericParameter, context); + + TypeReference type = m_module.TypeReferences [t.FullName]; + if (type != null) + return type; + + AssemblyNameReference asm; + if (t.Scope is AssemblyNameReference) + asm = ImportAssembly ((AssemblyNameReference) t.Scope); + else if (t.Scope is ModuleDefinition) + asm = ImportAssembly (((ModuleDefinition) t.Scope).Assembly.Name); + else + throw new NotImplementedException (); + + type = new TypeReference (t.Name, t.Namespace, asm, t.IsValueType); + + context.GenericContext.Type = type; + + foreach (GenericParameter gp in t.GenericParameters) + type.GenericParameters.Add (GenericParameter.Clone (gp, context)); + + m_module.TypeReferences.Add (type); + return type; + } + + public virtual FieldReference ImportFieldReference (FieldReference fr, ImportContext context) + { + if (fr.DeclaringType.Module == m_module) + return fr; + + FieldReference field = (FieldReference) GetMemberReference (fr); + if (field != null) + return field; + + field = new FieldReference ( + fr.Name, + ImportTypeReference (fr.DeclaringType, context), + ImportTypeReference (fr.FieldType, context)); + + m_module.MemberReferences.Add (field); + return field; + } + + MethodReference GetMethodSpec (MethodReference meth, ImportContext context) + { + if (!(meth is GenericInstanceMethod)) + return null; + + GenericInstanceMethod gim = meth as GenericInstanceMethod; + GenericInstanceMethod ngim = new GenericInstanceMethod ( + ImportMethodReference (gim.ElementMethod, context)); + + context.GenericContext.CheckProvider (ngim.GetOriginalMethod (), gim.GenericArguments.Count); + foreach (TypeReference arg in gim.GenericArguments) + ngim.GenericArguments.Add (ImportTypeReference (arg, context)); + + return ngim; + } + + public virtual MethodReference ImportMethodReference (MethodReference mr, ImportContext context) + { + if (mr.DeclaringType.Module == m_module) + return mr; + + if (mr is MethodSpecification) + return GetMethodSpec (mr, context); + + MethodReference meth = (MethodReference) GetMemberReference (mr); + if (meth != null) + return meth; + + meth = new MethodReference ( + mr.Name, + mr.HasThis, + mr.ExplicitThis, + mr.CallingConvention); + meth.DeclaringType = ImportTypeReference (mr.DeclaringType, context); + + TypeReference contextType = meth.DeclaringType.GetOriginalType (); + + context.GenericContext.Method = meth; + context.GenericContext.Type = contextType; + + foreach (GenericParameter gp in mr.GenericParameters) + meth.GenericParameters.Add (GenericParameter.Clone (gp, context)); + + meth.ReturnType.ReturnType = ImportTypeReference (mr.ReturnType.ReturnType, context); + + foreach (ParameterDefinition param in mr.Parameters) + meth.Parameters.Add (new ParameterDefinition ( + ImportTypeReference (param.ParameterType, context))); + + m_module.MemberReferences.Add (meth); + return meth; + } + + MemberReference GetMemberReference (MemberReference member) + { + foreach (MemberReference reference in m_module.MemberReferences) + if (reference.ToString () == member.ToString ()) + return reference; + + return null; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EmbeddedResource.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EmbeddedResource.cs new file mode 100644 index 0000000..7bd67be --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EmbeddedResource.cs @@ -0,0 +1,56 @@ +// +// EmbeddedResource.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class EmbeddedResource : Resource { + + byte [] m_data; + + public byte [] Data { + get { return m_data; } + set { m_data = value; } + } + + public EmbeddedResource (string name, ManifestResourceAttributes flags) : + base (name, flags) + { + } + + public EmbeddedResource (string name, ManifestResourceAttributes flags, byte [] data) : + base (name, flags) + { + m_data = data; + } + + public override void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitEmbeddedResource (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventAttributes.cs new file mode 100644 index 0000000..2db3a3c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventAttributes.cs @@ -0,0 +1,38 @@ +// +// EventAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum EventAttributes : ushort { + SpecialName = 0x0200, // Event is special + RTSpecialName = 0x0400 // CLI provides 'special' behavior, depending upon the name of the event + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventDefinition.cs new file mode 100644 index 0000000..ff76cc3 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventDefinition.cs @@ -0,0 +1,159 @@ +// +// EventDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class EventDefinition : EventReference, IMemberDefinition, ICustomAttributeProvider { + + EventAttributes m_attributes; + + CustomAttributeCollection m_customAttrs; + + MethodDefinition m_addMeth; + MethodDefinition m_invMeth; + MethodDefinition m_remMeth; + + public EventAttributes Attributes { + get { return m_attributes; } + set { m_attributes = value; } + } + + public MethodDefinition AddMethod { + get { return m_addMeth; } + set { m_addMeth = value; } + } + + public MethodDefinition InvokeMethod { + get { return m_invMeth; } + set { m_invMeth = value; } + } + + public MethodDefinition RemoveMethod { + get { return m_remMeth; } + set { m_remMeth = value; } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_customAttrs == null) + m_customAttrs = new CustomAttributeCollection (this); + + return m_customAttrs; + } + } + + #region EventAttributes + + public bool IsSpecialName { + get { return (m_attributes & EventAttributes.SpecialName) != 0; } + set { + if (value) + m_attributes |= EventAttributes.SpecialName; + else + m_attributes &= ~EventAttributes.SpecialName; + } + } + + public bool IsRuntimeSpecialName { + get { return (m_attributes & EventAttributes.RTSpecialName) != 0; } + set { + if (value) + m_attributes |= EventAttributes.RTSpecialName; + else + m_attributes &= ~EventAttributes.RTSpecialName; + } + } + + #endregion + + public EventDefinition (string name, TypeReference eventType, + EventAttributes attrs) : base (name, eventType) + { + m_attributes = attrs; + } + + public static MethodDefinition CreateAddMethod (EventDefinition evt) + { + MethodDefinition add = new MethodDefinition ( + string.Concat ("add_", evt.Name), (MethodAttributes) 0, evt.EventType); + evt.AddMethod = add; + return add; + } + + public static MethodDefinition CreateRemoveMethod (EventDefinition evt) + { + MethodDefinition remove = new MethodDefinition ( + string.Concat ("remove_", evt.Name), (MethodAttributes) 0, evt.EventType); + evt.RemoveMethod = remove; + return remove; + } + + public static MethodDefinition CreateInvokeMethod (EventDefinition evt) + { + MethodDefinition raise = new MethodDefinition ( + string.Concat ("raise_", evt.Name), (MethodAttributes) 0, evt.EventType); + evt.InvokeMethod = raise; + return raise; + } + + public EventDefinition Clone () + { + return Clone (this, new ImportContext (NullReferenceImporter.Instance, this.DeclaringType)); + } + + internal static EventDefinition Clone (EventDefinition evt, ImportContext context) + { + EventDefinition ne = new EventDefinition ( + evt.Name, + context.Import (evt.EventType), + evt.Attributes); + + if (context.GenericContext.Type is TypeDefinition) { + TypeDefinition type = context.GenericContext.Type as TypeDefinition; + if (evt.AddMethod != null) + ne.AddMethod = type.Methods.GetMethod (evt.AddMethod.Name) [0]; + if (evt.InvokeMethod != null) + ne.InvokeMethod = type.Methods.GetMethod (evt.InvokeMethod.Name) [0]; + if (evt.RemoveMethod != null) + ne.RemoveMethod = type.Methods.GetMethod (evt.RemoveMethod.Name) [0]; + } + + foreach (CustomAttribute ca in evt.CustomAttributes) + ne.CustomAttributes.Add (CustomAttribute.Clone (ca, context)); + + return ne; + } + + public override void Accept (IReflectionVisitor visitor) + { + visitor.VisitEventDefinition (this); + + this.CustomAttributes.Accept (visitor); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventDefinitionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventDefinitionCollection.cs new file mode 100644 index 0000000..f646dfb --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventDefinitionCollection.cs @@ -0,0 +1,137 @@ +// +// EventDefinitionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:57 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class EventDefinitionCollection : CollectionBase, IReflectionVisitable { + + TypeDefinition m_container; + + public EventDefinition this [int index] { + get { return List [index] as EventDefinition; } + set { List [index] = value; } + } + + public TypeDefinition Container { + get { return m_container; } + } + + public EventDefinitionCollection (TypeDefinition container) + { + m_container = container; + } + + public void Add (EventDefinition value) + { + Attach (value); + + List.Add (value); + } + + + public new void Clear () + { + foreach (EventDefinition item in this) + Detach (item); + + base.Clear (); + } + + public bool Contains (EventDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (EventDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, EventDefinition value) + { + Attach (value); + + List.Insert (index, value); + } + + public void Remove (EventDefinition value) + { + List.Remove (value); + + Detach (value); + } + + + public new void RemoveAt (int index) + { + EventDefinition item = this [index]; + Remove (item); + } + + protected override void OnValidate (object o) + { + if (! (o is EventDefinition)) + throw new ArgumentException ("Must be of type " + typeof (EventDefinition).FullName); + } + + public EventDefinition GetEvent (string name) + { + foreach (EventDefinition evt in this) + if (evt.Name == name) + return evt; + + return null; + } + + void Attach (MemberReference member) + { + if (member.DeclaringType != null) + throw new ReflectionException ("Member already attached, clone it instead"); + + member.DeclaringType = m_container; + } + + void Detach (MemberReference member) + { + member.DeclaringType = null; + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitEventDefinitionCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventReference.cs new file mode 100644 index 0000000..734452e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/EventReference.cs @@ -0,0 +1,50 @@ +// +// EventReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public abstract class EventReference : MemberReference { + + TypeReference m_eventType; + + public TypeReference EventType { + get { return m_eventType; } + set { m_eventType = value; } + } + + public EventReference (string name, TypeReference eventType) : base (name) + { + m_eventType = eventType; + } + + public override string ToString () + { + return string.Concat (m_eventType.FullName, " ", base.ToString ()); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ExternTypeCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ExternTypeCollection.cs new file mode 100644 index 0000000..c40f68d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ExternTypeCollection.cs @@ -0,0 +1,214 @@ +// +// ExternTypeCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:57 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + using System.Collections.Specialized; + + using Mono.Cecil.Cil; + + using Hcp = Mono.Cecil.HashCodeProvider; + using Cmp = System.Collections.Comparer; + + public sealed class ExternTypeCollection : NameObjectCollectionBase, IList, IReflectionVisitable { + + ModuleDefinition m_container; + + public TypeReference this [int index] { + get { return this.BaseGet (index) as TypeReference; } + set { this.BaseSet (index, value); } + } + + public TypeReference this [string fullName] { + get { return this.BaseGet (fullName) as TypeReference; } + set { this.BaseSet (fullName, value); } + } + + public ModuleDefinition Container { + get { return m_container; } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + bool IList.IsReadOnly { + get { return false; } + } + + bool IList.IsFixedSize { + get { return false; } + } + + object IList.this [int index] { + get { return BaseGet (index); } + set { + Check (value); + BaseSet (index, value); + } + } + + public ExternTypeCollection (ModuleDefinition container) : + base (Hcp.Instance, Cmp.Default) + { + m_container = container; + } + + public void Add (TypeReference value) + { + if (value == null) + throw new ArgumentNullException ("value"); + + Attach (value); + + this.BaseAdd (value.FullName, value); + } + + public void Clear () + { + foreach (TypeReference item in this) + Detach (item); + + this.BaseClear (); + } + + public bool Contains (TypeReference value) + { + return Contains (value.FullName); + } + + public bool Contains (string fullName) + { + return this.BaseGet (fullName) != null; + } + + public int IndexOf (TypeReference value) + { + string [] keys = this.BaseGetAllKeys (); + return Array.IndexOf (keys, value.FullName, 0, keys.Length); + } + + public void Remove (TypeReference value) + { + this.BaseRemove (value.FullName); + + Detach (value); + } + + public void RemoveAt (int index) + { + TypeReference item = this [index]; + Remove (item); + + Detach (item); + } + + public void CopyTo (Array ary, int index) + { + this.BaseGetAllValues ().CopyTo (ary, index); + } + + public new IEnumerator GetEnumerator () + { + return this.BaseGetAllValues ().GetEnumerator (); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitExternTypeCollection (this); + } + +#if CF_1_0 || CF_2_0 + internal object [] BaseGetAllValues () + { + object [] values = new object [this.Count]; + for (int i=0; i < values.Length; ++i) { + values [i] = this.BaseGet (i); + } + return values; + } +#endif + + void Check (object value) + { + if (!(value is TypeReference)) + throw new ArgumentException (); + } + + int IList.Add (object value) + { + Check (value); + Add (value as TypeReference); + return 0; + } + + bool IList.Contains (object value) + { + Check (value); + return Contains (value as TypeReference); + } + + int IList.IndexOf (object value) + { + throw new NotSupportedException (); + } + + void IList.Insert (int index, object value) + { + throw new NotSupportedException (); + } + + void IList.Remove (object value) + { + Check (value); + Remove (value as TypeReference); + } + + void Detach (TypeReference type) + { + type.Module = null; + } + + void Attach (TypeReference type) + { + if (type.Module != null) + throw new ReflectionException ("Type is already attached, clone it instead"); + + type.Module = m_container; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldAttributes.cs new file mode 100644 index 0000000..b7e90f0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldAttributes.cs @@ -0,0 +1,59 @@ +// +// FieldAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum FieldAttributes : ushort { + FieldAccessMask = 0x0007, + Compilercontrolled = 0x0000, // Member not referenceable + Private = 0x0001, // Accessible only by the parent type + FamANDAssem = 0x0002, // Accessible by sub-types only in this assembly + Assembly = 0x0003, // Accessible by anyone in the Assembly + Family = 0x0004, // Accessible only by type and sub-types + FamORAssem = 0x0005, // Accessible by sub-types anywhere, plus anyone in the assembly + Public = 0x0006, // Accessible by anyone who has visibility to this scope field contract attributes + + Static = 0x0010, // Defined on type, else per instance + InitOnly = 0x0020, // Field may only be initialized, not written after init + Literal = 0x0040, // Value is compile time constant + NotSerialized = 0x0080, // Field does not have to be serialized when type is remoted + SpecialName = 0x0200, // Field is special + + // Interop Attributes + PInvokeImpl = 0x2000, // Implementation is forwarded through PInvoke + + // Additional flags + RTSpecialName = 0x0400, // CLI provides 'special' behavior, depending upon the name of the field + HasFieldMarshal = 0x1000, // Field has marshalling information + HasDefault = 0x8000, // Field has default + HasFieldRVA = 0x0100 // Field has RVA + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldDefinition.cs new file mode 100644 index 0000000..9e3154a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldDefinition.cs @@ -0,0 +1,317 @@ +// +// FieldDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using Mono.Cecil; + using Mono.Cecil.Binary; + + public sealed class FieldDefinition : FieldReference, IMemberDefinition, + ICustomAttributeProvider, IHasMarshalSpec, IHasConstant { + + FieldAttributes m_attributes; + + CustomAttributeCollection m_customAttrs; + + bool m_hasInfo; + uint m_offset; + + RVA m_rva; + byte [] m_initVal; + + bool m_hasConstant; + object m_const; + + MarshalSpec m_marshalDesc; + + public bool HasLayoutInfo { + get { return m_hasInfo; } + } + + public uint Offset { + get { return m_offset; } + set { + m_hasInfo = true; + m_offset = value; + } + } + + public RVA RVA { + get { return m_rva; } + set { m_rva = value; } + } + + public byte [] InitialValue { + get { return m_initVal; } + set { m_initVal = value; } + } + + public FieldAttributes Attributes { + get { return m_attributes; } + set { m_attributes = value; } + } + + public bool HasConstant { + get { return m_hasConstant; } + } + + public object Constant { + get { return m_const; } + set { + m_hasConstant = true; + m_const = value; + } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_customAttrs == null) + m_customAttrs = new CustomAttributeCollection (this); + + return m_customAttrs; + } + } + + public MarshalSpec MarshalSpec { + get { return m_marshalDesc; } + set { + m_marshalDesc = value; + if (value != null) + m_attributes |= FieldAttributes.HasFieldMarshal; + else + m_attributes &= FieldAttributes.HasFieldMarshal; + } + } + + #region FieldAttributes + + public bool IsCompilerControlled { + get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Compilercontrolled; } + set { + if (value) { + m_attributes &= ~FieldAttributes.FieldAccessMask; + m_attributes |= FieldAttributes.Compilercontrolled; + } else + m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Compilercontrolled); + } + } + + public bool IsPrivate { + get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private; } + set { + if (value) { + m_attributes &= ~FieldAttributes.FieldAccessMask; + m_attributes |= FieldAttributes.Private; + } else + m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Private); + } + } + + public bool IsFamilyAndAssembly { + get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem; } + set { + if (value) { + m_attributes &= ~FieldAttributes.FieldAccessMask; + m_attributes |= FieldAttributes.FamANDAssem; + } else + m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.FamANDAssem); + } + } + + public bool IsAssembly { + get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly; } + set { + if (value) { + m_attributes &= ~FieldAttributes.FieldAccessMask; + m_attributes |= FieldAttributes.Assembly; + } else + m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Assembly); + } + } + + public bool IsFamily { + get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family; } + set { + if (value) { + m_attributes &= ~FieldAttributes.FieldAccessMask; + m_attributes |= FieldAttributes.Family; + } else + m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Family); + } + } + + public bool IsFamilyOrAssembly { + get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem; } + set { + if (value) { + m_attributes &= ~FieldAttributes.FieldAccessMask; + m_attributes |= FieldAttributes.FamORAssem; + } else + m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.FamORAssem); + } + } + + public bool IsPublic { + get { return (m_attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public; } + set { + if (value) { + m_attributes &= ~FieldAttributes.FieldAccessMask; + m_attributes |= FieldAttributes.Public; + } else + m_attributes &= ~(FieldAttributes.FieldAccessMask & FieldAttributes.Public); + } + } + + public bool IsStatic { + get { return (m_attributes & FieldAttributes.Static) != 0; } + set { + if (value) + m_attributes |= FieldAttributes.Static; + else + m_attributes &= ~FieldAttributes.Static; + } + } + + public bool IsInitOnly { + get { return (m_attributes & FieldAttributes.InitOnly) != 0; } + set { + if (value) + m_attributes |= FieldAttributes.InitOnly; + else + m_attributes &= ~FieldAttributes.InitOnly; + } + } + + public bool IsLiteral { + get { return (m_attributes & FieldAttributes.Literal) != 0; } + set { + if (value) + m_attributes |= FieldAttributes.Literal; + else + m_attributes &= ~FieldAttributes.Literal; + } + } + + public bool IsNotSerialized { + get { return (m_attributes & FieldAttributes.NotSerialized) != 0; } + set { + if (value) + m_attributes |= FieldAttributes.NotSerialized; + else + m_attributes &= ~FieldAttributes.NotSerialized; + } + } + + public bool IsSpecialName { + get { return (m_attributes & FieldAttributes.SpecialName) != 0; } + set { + if (value) + m_attributes |= FieldAttributes.SpecialName; + else + m_attributes &= ~FieldAttributes.SpecialName; + } + } + + public bool IsPInvokeImpl { + get { return (m_attributes & FieldAttributes.PInvokeImpl) != 0; } + set { + if (value) + m_attributes |= FieldAttributes.PInvokeImpl; + else + m_attributes &= ~FieldAttributes.PInvokeImpl; + } + } + + public bool IsRuntimeSpecialName { + get { return (m_attributes & FieldAttributes.RTSpecialName) != 0; } + set { + if (value) + m_attributes |= FieldAttributes.RTSpecialName; + else + m_attributes &= ~FieldAttributes.RTSpecialName; + } + } + + public bool HasDefault { + get { return (m_attributes & FieldAttributes.HasDefault) != 0; } + set { + if (value) + m_attributes |= FieldAttributes.HasDefault; + else + m_attributes &= ~FieldAttributes.HasDefault; + } + } + + #endregion + + public FieldDefinition (string name, TypeReference fieldType, + FieldAttributes attrs) : base (name, fieldType) + { + m_attributes = attrs; + } + + public FieldDefinition Clone () + { + return Clone (this, new ImportContext (NullReferenceImporter.Instance, this.DeclaringType)); + } + + internal static FieldDefinition Clone (FieldDefinition field, ImportContext context) + { + FieldDefinition nf = new FieldDefinition ( + field.Name, + context.Import (field.FieldType), + field.Attributes); + + if (field.HasConstant) + nf.Constant = field.Constant; + if (field.MarshalSpec != null) + nf.MarshalSpec = field.MarshalSpec; + if (field.RVA != RVA.Zero) + nf.InitialValue = field.InitialValue; + else + nf.InitialValue = new byte [0]; + if (field.HasLayoutInfo) + nf.Offset = field.Offset; + + foreach (CustomAttribute ca in field.CustomAttributes) + nf.CustomAttributes.Add (CustomAttribute.Clone (ca, context)); + + return nf; + } + + public override void Accept (IReflectionVisitor visitor) + { + visitor.VisitFieldDefinition (this); + + if (this.MarshalSpec != null) + this.MarshalSpec.Accept (visitor); + + this.CustomAttributes.Accept (visitor); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldDefinitionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldDefinitionCollection.cs new file mode 100644 index 0000000..366ec3d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldDefinitionCollection.cs @@ -0,0 +1,137 @@ +// +// FieldDefinitionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:57 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class FieldDefinitionCollection : CollectionBase, IReflectionVisitable { + + TypeDefinition m_container; + + public FieldDefinition this [int index] { + get { return List [index] as FieldDefinition; } + set { List [index] = value; } + } + + public TypeDefinition Container { + get { return m_container; } + } + + public FieldDefinitionCollection (TypeDefinition container) + { + m_container = container; + } + + public void Add (FieldDefinition value) + { + Attach (value); + + List.Add (value); + } + + + public new void Clear () + { + foreach (FieldDefinition item in this) + Detach (item); + + base.Clear (); + } + + public bool Contains (FieldDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (FieldDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, FieldDefinition value) + { + Attach (value); + + List.Insert (index, value); + } + + public void Remove (FieldDefinition value) + { + List.Remove (value); + + Detach (value); + } + + + public new void RemoveAt (int index) + { + FieldDefinition item = this [index]; + Remove (item); + } + + protected override void OnValidate (object o) + { + if (! (o is FieldDefinition)) + throw new ArgumentException ("Must be of type " + typeof (FieldDefinition).FullName); + } + + public FieldDefinition GetField (string name) + { + foreach (FieldDefinition field in this) + if (field.Name == name) + return field; + + return null; + } + + void Attach (MemberReference member) + { + if (member.DeclaringType != null) + throw new ReflectionException ("Member already attached, clone it instead"); + + member.DeclaringType = m_container; + } + + void Detach (MemberReference member) + { + member.DeclaringType = null; + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitFieldDefinitionCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldReference.cs new file mode 100644 index 0000000..d81a01a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FieldReference.cs @@ -0,0 +1,58 @@ +// +// FieldReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using Mono.Cecil; + + public class FieldReference : MemberReference { + + TypeReference m_fieldType; + + public TypeReference FieldType { + get { return m_fieldType; } + set { m_fieldType = value; } + } + + internal FieldReference (string name, TypeReference fieldType) : base (name) + { + m_fieldType = fieldType; + } + + public FieldReference (string name, TypeReference declaringType, TypeReference fieldType) : + this (name, fieldType) + { + this.DeclaringType = declaringType; + } + + public override string ToString () + { + return string.Concat (m_fieldType.FullName, " ", base.ToString ()); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FileAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FileAttributes.cs new file mode 100644 index 0000000..1379a86 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FileAttributes.cs @@ -0,0 +1,35 @@ +// +// FileAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public enum FileAttributes : uint { + ContainsMetaData = 0x0000, // This is not a resource file + ContainsNoMetaData = 0x0001, // This is a resource file or other non-metadata-containing file + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs new file mode 100644 index 0000000..e454f19 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/FunctionPointerType.cs @@ -0,0 +1,110 @@ +// +// FunctionPointerType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Text; + + public sealed class FunctionPointerType : TypeSpecification, IMethodSignature { + + MethodReference m_function; + + public bool HasThis { + get { return m_function.HasThis; } + set { m_function.HasThis = value; } + } + + public bool ExplicitThis { + get { return m_function.ExplicitThis; } + set { m_function.ExplicitThis = value; } + } + + public MethodCallingConvention CallingConvention { + get { return m_function.CallingConvention; } + set { m_function.CallingConvention = value; } + } + + public ParameterDefinitionCollection Parameters { + get { return m_function.Parameters; } + } + + public MethodReturnType ReturnType { + get { return m_function.ReturnType; } + set { m_function.ReturnType = value; } + } + + public override string Name { + get { return m_function.Name; } + set { throw new InvalidOperationException (); } + } + + public override string Namespace { + get { return string.Empty; } + set { throw new InvalidOperationException (); } + } + + public override IMetadataScope Scope { + get { return m_function.DeclaringType.Scope; } + } + + public override string FullName { + get { + int sentinel = GetSentinel (); + StringBuilder sb = new StringBuilder (); + sb.Append (m_function.Name); + sb.Append (" "); + sb.Append (m_function.ReturnType.ReturnType.FullName); + sb.Append (" *("); + for (int i = 0; i < m_function.Parameters.Count; i++) { + if (i > 0) + sb.Append (","); + + if (i == sentinel) + sb.Append ("...,"); + + sb.Append (m_function.Parameters [i].ParameterType.FullName); + } + sb.Append (")"); + return sb.ToString (); + } + } + + public FunctionPointerType (bool hasThis, bool explicitThis, MethodCallingConvention callConv, MethodReturnType retType) : + base (retType.ReturnType) + { + m_function = new MethodReference ("method", hasThis, explicitThis, callConv); + m_function.ReturnType = retType; + } + + public int GetSentinel () + { + return m_function.GetSentinel (); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericArgumentCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericArgumentCollection.cs new file mode 100644 index 0000000..cdb82e9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericArgumentCollection.cs @@ -0,0 +1,88 @@ +// +// GenericArgumentCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:54 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class GenericArgumentCollection : CollectionBase { + + IGenericInstance m_container; + + public TypeReference this [int index] { + get { return List [index] as TypeReference; } + set { List [index] = value; } + } + + public IGenericInstance Container { + get { return m_container; } + } + + public GenericArgumentCollection (IGenericInstance container) + { + m_container = container; + } + + public void Add (TypeReference value) + { + List.Add (value); + } + + public bool Contains (TypeReference value) + { + return List.Contains (value); + } + + public int IndexOf (TypeReference value) + { + return List.IndexOf (value); + } + + public void Insert (int index, TypeReference value) + { + List.Insert (index, value); + } + + public void Remove (TypeReference value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is TypeReference)) + throw new ArgumentException ("Must be of type " + typeof (TypeReference).FullName); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericContext.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericContext.cs new file mode 100644 index 0000000..b3c198d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericContext.cs @@ -0,0 +1,92 @@ +// +// GenericContext.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public class GenericContext { + + TypeReference m_type; + MethodReference m_method; + + public TypeReference Type { + get { return m_type; } + set { m_type = value; } + } + + public MethodReference Method { + get { return m_method; } + set { m_method = value; } + } + + public bool AllowCreation { + get { return m_type != null && m_type.GetType () == typeof (TypeReference); } + } + + public bool Null { + get { return m_type == null && m_method == null; } + } + + public GenericContext () + { + } + + public GenericContext (TypeReference type, MethodReference meth) + { + m_type = type; + m_method = meth; + } + + public GenericContext (IGenericParameterProvider provider) + { + if (provider is TypeReference) + m_type = provider as TypeReference; + else if (provider is MethodReference) { + MethodReference meth = provider as MethodReference; + m_method = meth; + m_type = meth.DeclaringType; + } + } + + internal void CheckProvider (IGenericParameterProvider provider, int count) + { + if (!AllowCreation) + return; + + for (int i = provider.GenericParameters.Count; i < count; i++) + provider.GenericParameters.Add (new GenericParameter (i, provider)); + } + + public GenericContext Clone () + { + GenericContext ctx = new GenericContext (); + ctx.Type = m_type; + ctx.Method = m_method; + return ctx; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs new file mode 100644 index 0000000..6926bb0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericInstanceMethod.cs @@ -0,0 +1,75 @@ +// +// IGenericInstanceMethod.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Text; + + public sealed class GenericInstanceMethod : MethodSpecification, IGenericInstance { + + private GenericArgumentCollection m_genArgs; + + public GenericArgumentCollection GenericArguments { + get { + if (m_genArgs == null) + m_genArgs = new GenericArgumentCollection (this); + return m_genArgs; + } + } + + public GenericInstanceMethod (MethodReference elemMethod) : base (elemMethod) + { + } + + public override string ToString () + { + StringBuilder sb = new StringBuilder (); + MethodReference meth = this.ElementMethod; + sb.Append (meth.ReturnType.ReturnType.FullName); + sb.Append (" "); + sb.Append (meth.DeclaringType.FullName); + sb.Append ("::"); + sb.Append (meth.Name); + sb.Append ("<"); + for (int i = 0; i < this.GenericArguments.Count; i++) { + if (i > 0) + sb.Append (","); + sb.Append (this.GenericArguments [i].FullName); + } + sb.Append (">"); + sb.Append ("("); + for (int i = 0; i < meth.Parameters.Count; i++) { + sb.Append (meth.Parameters [i].ParameterType.FullName); + if (i < meth.Parameters.Count - 1) + sb.Append (","); + } + sb.Append (")"); + return sb.ToString (); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericInstanceType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericInstanceType.cs new file mode 100644 index 0000000..df015dc --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericInstanceType.cs @@ -0,0 +1,71 @@ +// +// GenericInstanceType.cs +// +// Author: +// Martin Baulig <martin@ximian.com> +// Jb Evain <jbevain@gmail.com> +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Text; + + public sealed class GenericInstanceType : TypeSpecification, IGenericInstance { + + private GenericArgumentCollection m_genArgs; + + public GenericArgumentCollection GenericArguments { + get { + if (m_genArgs == null) + m_genArgs = new GenericArgumentCollection (this); + return m_genArgs; + } + } + + public override bool IsValueType { + get { return m_isValueType; } + set { m_isValueType = value; } + } + + public override string FullName { + get { + StringBuilder sb = new StringBuilder (); + sb.Append (base.FullName); + sb.Append ("<"); + for (int i = 0; i < this.GenericArguments.Count; i++) { + if (i > 0) + sb.Append (","); + sb.Append (this.GenericArguments [i].FullName); + } + sb.Append (">"); + return sb.ToString (); + } + } + + public GenericInstanceType (TypeReference elementType) : base (elementType) + { + m_isValueType = elementType.IsValueType; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameter.cs new file mode 100644 index 0000000..3a1b7a1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameter.cs @@ -0,0 +1,193 @@ +// +// GenericParameter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + public sealed class GenericParameter : TypeReference { + + int m_position; + string m_name; + GenericParameterAttributes m_attributes; + IGenericParameterProvider m_owner; + ConstraintCollection m_constraints; + + public int Position { + get { return m_position; } + set { m_position = value; } + } + + public GenericParameterAttributes Attributes { + get { return m_attributes; } + set { m_attributes = value; } + } + + public IGenericParameterProvider Owner { + get { return m_owner; } + } + + public ConstraintCollection Constraints { + get { + if (m_constraints == null) + m_constraints = new ConstraintCollection (this); + + return m_constraints; + } + } + + public override string Name { + get { + if (m_name != null) + return m_name; + + if (m_owner is TypeReference) + return string.Concat ("!", m_position.ToString ()); + else if (m_owner is MethodReference) + return string.Concat ("!!", m_position.ToString ()); + else + throw new InvalidOperationException (); + } + set { m_name = value; } + } + + public override string Namespace { + get { return string.Empty; } + set { throw new InvalidOperationException (); } + } + + public override string FullName { + get { return Name; } + } + + #region GenericParameterAttributes + + public bool IsNonVariant { + get { return (m_attributes & GenericParameterAttributes.VarianceMask) == GenericParameterAttributes.NonVariant; } + set { + if (value) { + m_attributes &= ~GenericParameterAttributes.VarianceMask; + m_attributes |= GenericParameterAttributes.NonVariant; + } else + m_attributes &= ~(GenericParameterAttributes.VarianceMask & GenericParameterAttributes.NonVariant); + } + } + + public bool IsCovariant { + get { return (m_attributes & GenericParameterAttributes.VarianceMask) == GenericParameterAttributes.Covariant; } + set { + if (value) { + m_attributes &= ~GenericParameterAttributes.VarianceMask; + m_attributes |= GenericParameterAttributes.Covariant; + } else + m_attributes &= ~(GenericParameterAttributes.VarianceMask & GenericParameterAttributes.Covariant); + } + } + + public bool IsContravariant { + get { return (m_attributes & GenericParameterAttributes.VarianceMask) == GenericParameterAttributes.Contravariant; } + set { + if (value) { + m_attributes &= ~GenericParameterAttributes.VarianceMask; + m_attributes |= GenericParameterAttributes.Contravariant; + } else + m_attributes &= ~(GenericParameterAttributes.VarianceMask & GenericParameterAttributes.Contravariant); + } + } + + public bool HasReferenceTypeConstraint { + get { return (m_attributes & GenericParameterAttributes.SpecialConstraintMask) == GenericParameterAttributes.ReferenceTypeConstraint; } + set { + if (value) { + m_attributes &= ~GenericParameterAttributes.SpecialConstraintMask; + m_attributes |= GenericParameterAttributes.ReferenceTypeConstraint; + } else + m_attributes &= ~(GenericParameterAttributes.SpecialConstraintMask & GenericParameterAttributes.ReferenceTypeConstraint); + } + } + + public bool HasNotNullableValueTypeConstraint { + get { return (m_attributes & GenericParameterAttributes.SpecialConstraintMask) == GenericParameterAttributes.NotNullableValueTypeConstraint; } + set { + if (value) { + m_attributes &= ~GenericParameterAttributes.SpecialConstraintMask; + m_attributes |= GenericParameterAttributes.NotNullableValueTypeConstraint; + } else + m_attributes &= ~(GenericParameterAttributes.SpecialConstraintMask & GenericParameterAttributes.NotNullableValueTypeConstraint); + } + } + + public bool HasDefaultConstructorConstraint { + get { return (m_attributes & GenericParameterAttributes.SpecialConstraintMask) == GenericParameterAttributes.DefaultConstructorConstraint; } + set { + if (value) { + m_attributes &= ~GenericParameterAttributes.SpecialConstraintMask; + m_attributes |= GenericParameterAttributes.DefaultConstructorConstraint; + } else + m_attributes &= ~(GenericParameterAttributes.SpecialConstraintMask & GenericParameterAttributes.DefaultConstructorConstraint); + } + } + + #endregion + + internal GenericParameter (int pos, IGenericParameterProvider owner) : + base (string.Empty, string.Empty) + { + m_position = pos; + m_owner = owner; + } + + public GenericParameter (string name, IGenericParameterProvider owner) : + base (string.Empty, string.Empty) + { + m_name = name; + m_owner = owner; + } + + internal static GenericParameter Clone (GenericParameter gp, ImportContext context) + { + GenericParameter ngp; + if (gp.Owner is TypeReference) + ngp = new GenericParameter (gp.m_name, context.GenericContext.Type); + else if (gp.Owner is MethodReference) + ngp = new GenericParameter (gp.m_name, context.GenericContext.Method); + else + throw new NotSupportedException (); + + ngp.Position = gp.Owner.GenericParameters.IndexOf (gp); + ngp.Attributes = gp.Attributes; + + foreach (TypeReference constraint in gp.Constraints) + ngp.Constraints.Add (context.Import (constraint)); + foreach (CustomAttribute ca in gp.CustomAttributes) + ngp.CustomAttributes.Add (CustomAttribute.Clone (ca, context)); + + return ngp; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs new file mode 100644 index 0000000..d7d65c7 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameterAttributes.cs @@ -0,0 +1,45 @@ +// +// GenericParameterAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum GenericParameterAttributes : ushort { + VarianceMask = 0x0003, + NonVariant = 0x0000, + Covariant = 0x0001, + Contravariant = 0x0002, + + SpecialConstraintMask = 0x001c, + ReferenceTypeConstraint = 0x0004, + NotNullableValueTypeConstraint = 0x0008, + DefaultConstructorConstraint = 0x0010 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameterCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameterCollection.cs new file mode 100644 index 0000000..fc00972 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/GenericParameterCollection.cs @@ -0,0 +1,93 @@ +// +// GenericParameterCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:53 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class GenericParameterCollection : CollectionBase, IReflectionVisitable { + + IGenericParameterProvider m_container; + + public GenericParameter this [int index] { + get { return List [index] as GenericParameter; } + set { List [index] = value; } + } + + public IGenericParameterProvider Container { + get { return m_container; } + } + + public GenericParameterCollection (IGenericParameterProvider container) + { + m_container = container; + } + + public void Add (GenericParameter value) + { + List.Add (value); + } + + public bool Contains (GenericParameter value) + { + return List.Contains (value); + } + + public int IndexOf (GenericParameter value) + { + return List.IndexOf (value); + } + + public void Insert (int index, GenericParameter value) + { + List.Insert (index, value); + } + + public void Remove (GenericParameter value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is GenericParameter)) + throw new ArgumentException ("Must be of type " + typeof (GenericParameter).FullName); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitGenericParameterCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/HashCodeProvider.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/HashCodeProvider.cs new file mode 100644 index 0000000..6b7b80c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/HashCodeProvider.cs @@ -0,0 +1,46 @@ +// +// HashCodeProvider.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + internal sealed class HashCodeProvider : IHashCodeProvider { + + public static readonly HashCodeProvider Instance = new HashCodeProvider (); + + HashCodeProvider () + { + } + + public int GetHashCode (object o) + { + return o.GetHashCode (); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IAnnotationProvider.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IAnnotationProvider.cs new file mode 100644 index 0000000..bf5e249 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IAnnotationProvider.cs @@ -0,0 +1,37 @@ +// +// AssemblyDefinition.cs +// +// Author: +// Jb Evain (jbevain@novell.com) +// +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + public interface IAnnotationProvider { + + IDictionary Annotations { get; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IAssemblyResolver.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IAssemblyResolver.cs new file mode 100644 index 0000000..3619d4e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IAssemblyResolver.cs @@ -0,0 +1,36 @@ +// +// IAssemblyResolver.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IAssemblyResolver { + + AssemblyDefinition Resolve (string fullName); + AssemblyDefinition Resolve (AssemblyNameReference name); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs new file mode 100644 index 0000000..10c1f1d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ICustomAttributeProvider.cs @@ -0,0 +1,37 @@ +// +// ICustomAttributeProvider.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Reflection; + + public interface ICustomAttributeProvider { + + CustomAttributeCollection CustomAttributes { get; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IDetailReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IDetailReader.cs new file mode 100644 index 0000000..ca70132 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IDetailReader.cs @@ -0,0 +1,48 @@ +// +// IDetailReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + internal interface IDetailReader { + + void ReadSemantic (EventDefinition evt); + void ReadSemantic (PropertyDefinition prop); + + void ReadMarshalSpec (ParameterDefinition param); + void ReadMarshalSpec (FieldDefinition field); + + void ReadLayout (TypeDefinition type); + void ReadLayout (FieldDefinition field); + + void ReadConstant (FieldDefinition field); + void ReadConstant (PropertyDefinition prop); + void ReadConstant (ParameterDefinition param); + + void ReadInitialValue (FieldDefinition field); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IGenericInstance.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IGenericInstance.cs new file mode 100644 index 0000000..43f60fc --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IGenericInstance.cs @@ -0,0 +1,35 @@ +// +// IGenericInstanceMethod.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IGenericInstance : IMetadataTokenProvider { + + GenericArgumentCollection GenericArguments { get; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs new file mode 100644 index 0000000..df2c23f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IGenericParameterProvider.cs @@ -0,0 +1,35 @@ +// +// IGenericParameterProvider.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IGenericParameterProvider : IMetadataTokenProvider { + + GenericParameterCollection GenericParameters { get; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasConstant.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasConstant.cs new file mode 100644 index 0000000..e2126b4 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasConstant.cs @@ -0,0 +1,36 @@ +// +// IHasConstant.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IHasConstant : IMetadataTokenProvider { + + bool HasConstant { get; } + object Constant { get; set; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasMarshalSpec.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasMarshalSpec.cs new file mode 100644 index 0000000..69f69d6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasMarshalSpec.cs @@ -0,0 +1,35 @@ +// +// IHasMarshalSpec.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IHasMarshalSpec : IMetadataTokenProvider { + + MarshalSpec MarshalSpec { get; set; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasSecurity.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasSecurity.cs new file mode 100644 index 0000000..a8f5b9a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IHasSecurity.cs @@ -0,0 +1,35 @@ +// +// IHasSecurity.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IHasSecurity : IMetadataTokenProvider { + + SecurityDeclarationCollection SecurityDeclarations { get; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IImporter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IImporter.cs new file mode 100644 index 0000000..b9ee8b0 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IImporter.cs @@ -0,0 +1,37 @@ +// +// IImporter.cs +// +// Author: +// Jb Evain (jbevain@novell.com) +// +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IImporter { + + TypeReference ImportTypeReference (TypeReference type, ImportContext context); + FieldReference ImportFieldReference (FieldReference field, ImportContext context); + MethodReference ImportMethodReference (MethodReference method, ImportContext context); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMemberDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMemberDefinition.cs new file mode 100644 index 0000000..dc618fa --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMemberDefinition.cs @@ -0,0 +1,36 @@ +// +// IMemberDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IMemberDefinition : IMemberReference { + + bool IsSpecialName { get; set; } + bool IsRuntimeSpecialName { get; set; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMemberReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMemberReference.cs new file mode 100644 index 0000000..016565f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMemberReference.cs @@ -0,0 +1,36 @@ +// +// IMemberReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IMemberReference : IMetadataTokenProvider, IAnnotationProvider, IReflectionVisitable { + + string Name { get; set; } + TypeReference DeclaringType { get; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMetadataScope.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMetadataScope.cs new file mode 100644 index 0000000..d0a0eac --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMetadataScope.cs @@ -0,0 +1,34 @@ +// +// IMetadataScope.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IMetadataScope : IMetadataTokenProvider { + string Name { get; set; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs new file mode 100644 index 0000000..332f1af --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMetadataTokenProvider.cs @@ -0,0 +1,37 @@ +// +// IMetadataTokenProvider.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using Mono.Cecil.Metadata; + + public interface IMetadataTokenProvider { + + MetadataToken MetadataToken { get; set; } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMethodSignature.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMethodSignature.cs new file mode 100644 index 0000000..385a481 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IMethodSignature.cs @@ -0,0 +1,42 @@ +// +// IMethodSignature.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IMethodSignature { + + bool HasThis { get; set; } + bool ExplicitThis { get; set; } + MethodCallingConvention CallingConvention { get; set; } + + ParameterDefinitionCollection Parameters { get; } + MethodReturnType ReturnType { get; } + + int GetSentinel (); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionStructureVisitable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionStructureVisitable.cs new file mode 100644 index 0000000..f522cf1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionStructureVisitable.cs @@ -0,0 +1,36 @@ +// +// IReflectionStructureVisitable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IReflectionStructureVisitable { + + void Accept (IReflectionStructureVisitor visitor); + } +} + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionStructureVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionStructureVisitor.cs new file mode 100644 index 0000000..81a6e3b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionStructureVisitor.cs @@ -0,0 +1,49 @@ +// +// IReflectionStructureVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IReflectionStructureVisitor { + + void VisitAssemblyDefinition (AssemblyDefinition asm); + void VisitAssemblyNameDefinition (AssemblyNameDefinition name); + void VisitAssemblyNameReferenceCollection (AssemblyNameReferenceCollection names); + void VisitAssemblyNameReference (AssemblyNameReference name); + void VisitResourceCollection (ResourceCollection resources); + void VisitEmbeddedResource (EmbeddedResource res); + void VisitLinkedResource (LinkedResource res); + void VisitAssemblyLinkedResource (AssemblyLinkedResource res); + void VisitModuleDefinition (ModuleDefinition module); + void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules); + void VisitModuleReference (ModuleReference module); + void VisitModuleReferenceCollection (ModuleReferenceCollection modules); + + void TerminateAssemblyDefinition (AssemblyDefinition asm); + } +} + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionVisitable.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionVisitable.cs new file mode 100644 index 0000000..ac4f706 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionVisitable.cs @@ -0,0 +1,36 @@ +// +// IReflectionVisitable.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IReflectionVisitable { + + void Accept (IReflectionVisitor visitor); + } +} + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionVisitor.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionVisitor.cs new file mode 100644 index 0000000..c85633b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IReflectionVisitor.cs @@ -0,0 +1,71 @@ +// +// IReflectionVisitor.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IReflectionVisitor { + + void VisitModuleDefinition (ModuleDefinition module); + void VisitTypeDefinitionCollection (TypeDefinitionCollection types); + void VisitTypeDefinition (TypeDefinition type); + void VisitTypeReferenceCollection (TypeReferenceCollection refs); + void VisitTypeReference (TypeReference type); + void VisitMemberReferenceCollection (MemberReferenceCollection members); + void VisitMemberReference (MemberReference member); + void VisitInterfaceCollection (InterfaceCollection interfaces); + void VisitInterface (TypeReference interf); + void VisitExternTypeCollection (ExternTypeCollection externs); + void VisitExternType (TypeReference externType); + void VisitOverrideCollection (OverrideCollection meth); + void VisitOverride (MethodReference ov); + void VisitNestedTypeCollection (NestedTypeCollection nestedTypes); + void VisitNestedType (TypeDefinition nestedType); + void VisitParameterDefinitionCollection (ParameterDefinitionCollection parameters); + void VisitParameterDefinition (ParameterDefinition parameter); + void VisitMethodDefinitionCollection (MethodDefinitionCollection methods); + void VisitMethodDefinition (MethodDefinition method); + void VisitConstructorCollection (ConstructorCollection ctors); + void VisitConstructor (MethodDefinition ctor); + void VisitPInvokeInfo (PInvokeInfo pinvk); + void VisitEventDefinitionCollection (EventDefinitionCollection events); + void VisitEventDefinition (EventDefinition evt); + void VisitFieldDefinitionCollection (FieldDefinitionCollection fields); + void VisitFieldDefinition (FieldDefinition field); + void VisitPropertyDefinitionCollection (PropertyDefinitionCollection properties); + void VisitPropertyDefinition (PropertyDefinition property); + void VisitSecurityDeclarationCollection (SecurityDeclarationCollection secDecls); + void VisitSecurityDeclaration (SecurityDeclaration secDecl); + void VisitCustomAttributeCollection (CustomAttributeCollection customAttrs); + void VisitCustomAttribute (CustomAttribute customAttr); + void VisitGenericParameterCollection (GenericParameterCollection genparams); + void VisitGenericParameter (GenericParameter genparam); + void VisitMarshalSpec (MarshalSpec marshalSpec); + + void TerminateModuleDefinition (ModuleDefinition module); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IRequireResolving.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IRequireResolving.cs new file mode 100644 index 0000000..92eac83 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/IRequireResolving.cs @@ -0,0 +1,37 @@ +// +// IRequireResolving.cs +// +// Author: +// Jb Evain <jbevain@gmail.com> +// +// Copyright (C) 2006 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public interface IRequireResolving { + + byte [] Blob { get; } + bool Resolved { get; } + bool Resolve (); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ImportContext.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ImportContext.cs new file mode 100644 index 0000000..9fd36b6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ImportContext.cs @@ -0,0 +1,67 @@ +// +// ImportContext.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2006 Evaluant RC S.A. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public class ImportContext { + + GenericContext m_genContext; + IImporter m_importer; + + public GenericContext GenericContext { + get { return m_genContext; } + } + + public ImportContext (IImporter importer) + { + m_genContext = new GenericContext (); + m_importer = importer; + } + + public ImportContext (IImporter importer, IGenericParameterProvider provider) + { + m_importer = importer; + m_genContext = new GenericContext (provider); + } + + public TypeReference Import (TypeReference type) + { + return m_importer.ImportTypeReference (type, this); + } + + public MethodReference Import (MethodReference meth) + { + return m_importer.ImportMethodReference (meth, this); + } + + public FieldReference Import (FieldReference field) + { + return m_importer.ImportFieldReference (field, this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/InterfaceCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/InterfaceCollection.cs new file mode 100644 index 0000000..9999680 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/InterfaceCollection.cs @@ -0,0 +1,93 @@ +// +// InterfaceCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:52 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class InterfaceCollection : CollectionBase, IReflectionVisitable { + + TypeDefinition m_container; + + public TypeReference this [int index] { + get { return List [index] as TypeReference; } + set { List [index] = value; } + } + + public TypeDefinition Container { + get { return m_container; } + } + + public InterfaceCollection (TypeDefinition container) + { + m_container = container; + } + + public void Add (TypeReference value) + { + List.Add (value); + } + + public bool Contains (TypeReference value) + { + return List.Contains (value); + } + + public int IndexOf (TypeReference value) + { + return List.IndexOf (value); + } + + public void Insert (int index, TypeReference value) + { + List.Insert (index, value); + } + + public void Remove (TypeReference value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is TypeReference)) + throw new ArgumentException ("Must be of type " + typeof (TypeReference).FullName); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitInterfaceCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/LinkedResource.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/LinkedResource.cs new file mode 100644 index 0000000..09d4588 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/LinkedResource.cs @@ -0,0 +1,57 @@ +// +// LinkedResource.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class LinkedResource : Resource { + + byte [] m_hash; + string m_file; + + public byte [] Hash { + get { return m_hash; } + set { m_hash = value; } + } + + public string File { + get { return m_file; } + set { m_file = value; } + } + + public LinkedResource (string name, ManifestResourceAttributes flags, string file) : + base (name, flags) + { + m_file = file; + } + + public override void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitLinkedResource (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs new file mode 100644 index 0000000..1d77f9f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ManifestResourceAttributes.cs @@ -0,0 +1,39 @@ +// +// ManigestResourceAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum ManifestResourceAttributes { + VisibilityMask = 0x0007, + Public = 0x0001, // The resource is exported from the Assembly + Private = 0x0002 // The resource is private to the Assembly + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MarshalSpec.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MarshalSpec.cs new file mode 100644 index 0000000..4610c09 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MarshalSpec.cs @@ -0,0 +1,171 @@ +// +// MarshalDesc.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + public class MarshalSpec { + + NativeType m_natIntr; + IHasMarshalSpec m_container; + + public NativeType NativeIntrinsic { + get { return m_natIntr; } + set { m_natIntr = value; } + } + + public IHasMarshalSpec Container { + get { return m_container; } + set { m_container = value; } + } + + public MarshalSpec (NativeType natIntr, IHasMarshalSpec container) + { + m_natIntr = natIntr; + m_container = container; + } + + public virtual void Accept (IReflectionVisitor visitor) + { + visitor.VisitMarshalSpec (this); + } + } + + public sealed class ArrayMarshalSpec : MarshalSpec { + + NativeType m_elemType; + int m_paramNum; + int m_elemMult; + int m_numElem; + + public NativeType ElemType { + get { return m_elemType; } + set { m_elemType = value; } + } + + public int ParamNum { + get { return m_paramNum; } + set { m_paramNum = value; } + } + + public int ElemMult { + get { return m_elemMult; } + set { m_elemMult = value; } + } + + public int NumElem { + get { return m_numElem; } + set { m_numElem = value; } + } + + public ArrayMarshalSpec (IHasMarshalSpec container) : base (NativeType.ARRAY, container) + { + } + } + + public sealed class CustomMarshalerSpec : MarshalSpec { + + Guid m_guid; + string m_unmanagedType; + string m_managedType; + string m_cookie; + + public Guid Guid { + get { return m_guid; } + set { m_guid = value; } + } + + public String UnmanagedType { + get { return m_unmanagedType; } + set { m_unmanagedType = value; } + } + + public string ManagedType { + get { return m_managedType; } + set { m_managedType = value; } + } + + public string Cookie { + get { return m_cookie; } + set { m_cookie = value; } + } + + public CustomMarshalerSpec (IHasMarshalSpec container) : base (NativeType.CUSTOMMARSHALER, container) + { + } + } + + public sealed class SafeArraySpec : MarshalSpec { + + private VariantType m_elemType; + + public VariantType ElemType { + get { return m_elemType; } + set { m_elemType = value; } + } + + public SafeArraySpec (IHasMarshalSpec container) : base (NativeType.SAFEARRAY, container) + { + } + } + + public sealed class FixedArraySpec : MarshalSpec { + + private int m_numElem; + private NativeType m_elemType; + + public int NumElem { + get { return m_numElem; } + set { m_numElem = value; } + } + + public NativeType ElemType { + get { return m_elemType; } + set { m_elemType = value; } + } + + public FixedArraySpec (IHasMarshalSpec container) : base (NativeType.FIXEDARRAY, container) + { + } + } + + public sealed class FixedSysStringSpec : MarshalSpec { + + private int m_size; + + public int Size { + get { return m_size; } + set { m_size = value; } + } + + public FixedSysStringSpec (IHasMarshalSpec container) : base (NativeType.FIXEDSYSSTRING, container) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MemberReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MemberReference.cs new file mode 100644 index 0000000..95fcb69 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MemberReference.cs @@ -0,0 +1,82 @@ +// +// MemberReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + using Mono.Cecil.Metadata; + + public abstract class MemberReference : IMemberReference { + + string m_name; + TypeReference m_decType; + MetadataToken m_token; + IDictionary m_annotations; + + public virtual string Name { + get { return m_name; } + set { m_name = value; } + } + + public virtual TypeReference DeclaringType { + get { return m_decType; } + set { m_decType = value; } + } + + public MetadataToken MetadataToken { + get { return m_token; } + set { m_token = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { + if (m_annotations == null) + m_annotations = new Hashtable (); + return m_annotations; + } + } + + public MemberReference (string name) + { + m_name = name; + } + + public override string ToString () + { + if (m_decType == null) + return m_name; + + return string.Concat (m_decType.FullName, "::", m_name); + } + + public virtual void Accept (IReflectionVisitor visitor) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MemberReferenceCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MemberReferenceCollection.cs new file mode 100644 index 0000000..fd69d6c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MemberReferenceCollection.cs @@ -0,0 +1,93 @@ +// +// MemberReferenceCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:53 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class MemberReferenceCollection : CollectionBase, IReflectionVisitable { + + ModuleDefinition m_container; + + public MemberReference this [int index] { + get { return List [index] as MemberReference; } + set { List [index] = value; } + } + + public ModuleDefinition Container { + get { return m_container; } + } + + public MemberReferenceCollection (ModuleDefinition container) + { + m_container = container; + } + + public void Add (MemberReference value) + { + List.Add (value); + } + + public bool Contains (MemberReference value) + { + return List.Contains (value); + } + + public int IndexOf (MemberReference value) + { + return List.IndexOf (value); + } + + public void Insert (int index, MemberReference value) + { + List.Insert (index, value); + } + + public void Remove (MemberReference value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is MemberReference)) + throw new ArgumentException ("Must be of type " + typeof (MemberReference).FullName); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitMemberReferenceCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodAttributes.cs new file mode 100644 index 0000000..c57b906 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodAttributes.cs @@ -0,0 +1,65 @@ +// +// MethodAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum MethodAttributes : ushort { + MemberAccessMask = 0x0007, + Compilercontrolled = 0x0000, // Member not referenceable + Private = 0x0001, // Accessible only by the parent type + FamANDAssem = 0x0002, // Accessible by sub-types only in this Assembly + Assem = 0x0003, // Accessibly by anyone in the Assembly + Family = 0x0004, // Accessible only by type and sub-types + FamORAssem = 0x0005, // Accessibly by sub-types anywhere, plus anyone in assembly + Public = 0x0006, // Accessibly by anyone who has visibility to this scope + + Static = 0x0010, // Defined on type, else per instance + Final = 0x0020, // Method may not be overridden + Virtual = 0x0040, // Method is virtual + HideBySig = 0x0080, // Method hides by name+sig, else just by name + + VtableLayoutMask = 0x0100, // Use this mask to retrieve vtable attributes + ReuseSlot = 0x0000, // Method reuses existing slot in vtable + NewSlot = 0x0100, // Method always gets a new slot in the vtable + + Abstract = 0x0400, // Method does not provide an implementation + SpecialName = 0x0800, // Method is special + + // Interop Attributes + PInvokeImpl = 0x2000, // Implementation is forwarded through PInvoke + UnmanagedExport = 0x0008, // Reserved: shall be zero for conforming implementations + + // Additional flags + RTSpecialName = 0x1000, // CLI provides 'special' behavior, depending upon the name of the method + HasSecurity = 0x4000, // Method has security associate with it + RequireSecObject = 0x8000 // Method calls another method containing security code + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs new file mode 100644 index 0000000..0eb6088 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodCallingConvention.cs @@ -0,0 +1,40 @@ +// +// MethodCallingConvention.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public enum MethodCallingConvention : byte { + Default = 0x0, + C = 0x1, + StdCall = 0x2, + ThisCall = 0x3, + FastCall = 0x4, + VarArg = 0x5, + Generic = 0x10 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodDefinition.cs new file mode 100644 index 0000000..8d28807 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodDefinition.cs @@ -0,0 +1,559 @@ +// +// MethodDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using Mono.Cecil.Binary; + using Mono.Cecil.Cil; + + public sealed class MethodDefinition : MethodReference, IMemberDefinition, + IHasSecurity, ICustomAttributeProvider { + + public const string Cctor = ".cctor"; + public const string Ctor = ".ctor"; + + MethodAttributes m_attributes; + MethodImplAttributes m_implAttrs; + MethodSemanticsAttributes m_semAttrs; + SecurityDeclarationCollection m_secDecls; + CustomAttributeCollection m_customAttrs; + + ModuleDefinition m_module; + + MethodBody m_body; + RVA m_rva; + OverrideCollection m_overrides; + PInvokeInfo m_pinvoke; + readonly ParameterDefinition m_this; + + public MethodAttributes Attributes { + get { return m_attributes; } + set { m_attributes = value; } + } + + public MethodImplAttributes ImplAttributes { + get { return m_implAttrs; } + set { m_implAttrs = value; } + } + + public MethodSemanticsAttributes SemanticsAttributes { + get { return m_semAttrs; } + set { m_semAttrs = value; } + } + + public override TypeReference DeclaringType { + get { return base.DeclaringType; } + set { + base.DeclaringType = value; + TypeDefinition t = value as TypeDefinition; + if (t != null) + m_module = t.Module; + } + } + + public SecurityDeclarationCollection SecurityDeclarations { + get { + if (m_secDecls == null) + m_secDecls = new SecurityDeclarationCollection (this); + + return m_secDecls; + } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_customAttrs == null) + m_customAttrs = new CustomAttributeCollection (this); + + return m_customAttrs; + } + } + + public RVA RVA { + get { return m_rva; } + set { m_rva = value; } + } + + public MethodBody Body { + get { + LoadBody (); + return m_body; + } + set { m_body = value; } + } + + public PInvokeInfo PInvokeInfo { + get { return m_pinvoke; } + set { m_pinvoke = value; } + } + + public OverrideCollection Overrides { + get { + if (m_overrides == null) + m_overrides = new OverrideCollection (this); + + return m_overrides; + } + } + + public ParameterDefinition This { + get { return m_this; } + } + + #region MethodAttributes + + public bool IsCompilerControlled { + get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Compilercontrolled; } + set { + if (value) { + m_attributes &= ~MethodAttributes.MemberAccessMask; + m_attributes |= MethodAttributes.Compilercontrolled; + } else + m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Compilercontrolled); + } + } + + public bool IsPrivate { + get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; } + set { + if (value) { + m_attributes &= ~MethodAttributes.MemberAccessMask; + m_attributes |= MethodAttributes.Private; + } else + m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Private); + } + } + + public bool IsFamilyAndAssembly { + get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem; } + set { + if (value) { + m_attributes &= ~MethodAttributes.MemberAccessMask; + m_attributes |= MethodAttributes.FamANDAssem; + } else + m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.FamANDAssem); + } + } + + public bool IsAssembly { + get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assem; } + set { + if (value) { + m_attributes &= ~MethodAttributes.MemberAccessMask; + m_attributes |= MethodAttributes.Assem; + } else + m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Assem); + } + } + + public bool IsFamily { + get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family; } + set { + if (value) { + m_attributes &= ~MethodAttributes.MemberAccessMask; + m_attributes |= MethodAttributes.Family; + } else + m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Family); + } + } + + public bool IsFamilyOrAssembly { + get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem; } + set { + if (value) { + m_attributes &= ~MethodAttributes.MemberAccessMask; + m_attributes |= MethodAttributes.FamORAssem; + } else + m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.FamORAssem); + } + } + + public bool IsPublic { + get { return (m_attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public; } + set { + if (value) { + m_attributes &= ~MethodAttributes.MemberAccessMask; + m_attributes |= MethodAttributes.Public; + } else + m_attributes &= ~(MethodAttributes.MemberAccessMask & MethodAttributes.Public); + } + } + + public bool IsStatic { + get { return (m_attributes & MethodAttributes.Static) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.Static; + else + m_attributes &= ~MethodAttributes.Static; + } + } + + public bool IsFinal { + get { return (m_attributes & MethodAttributes.Final) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.Final; + else + m_attributes &= ~MethodAttributes.Final; + } + } + + public bool IsVirtual { + get { return (m_attributes & MethodAttributes.Virtual) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.Virtual; + else + m_attributes &= ~MethodAttributes.Virtual; + } + } + + public bool IsHideBySig { + get { return (m_attributes & MethodAttributes.HideBySig) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.HideBySig; + else + m_attributes &= ~MethodAttributes.HideBySig; + } + } + + public bool IsReuseSlot { + get { return (m_attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot; } + set { + if (value) { + m_attributes &= ~MethodAttributes.VtableLayoutMask; + m_attributes |= MethodAttributes.ReuseSlot; + } else + m_attributes &= ~(MethodAttributes.VtableLayoutMask & MethodAttributes.ReuseSlot); + } + } + + public bool IsNewSlot { + get { return (m_attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot; } + set { + if (value) { + m_attributes &= ~MethodAttributes.VtableLayoutMask; + m_attributes |= MethodAttributes.NewSlot; + } else + m_attributes &= ~(MethodAttributes.VtableLayoutMask & MethodAttributes.NewSlot); + } + } + + public bool IsAbstract { + get { return (m_attributes & MethodAttributes.Abstract) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.Abstract; + else + m_attributes &= ~MethodAttributes.Abstract; + } + } + + public bool IsSpecialName { + get { return (m_attributes & MethodAttributes.SpecialName) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.SpecialName; + else + m_attributes &= ~MethodAttributes.SpecialName; + } + } + + public bool IsPInvokeImpl { + get { return (m_attributes & MethodAttributes.PInvokeImpl) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.PInvokeImpl; + else + m_attributes &= ~MethodAttributes.PInvokeImpl; + } + } + + public bool IsUnmanagedExport { + get { return (m_attributes & MethodAttributes.UnmanagedExport) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.UnmanagedExport; + else + m_attributes &= ~MethodAttributes.UnmanagedExport; + } + } + + public bool IsRuntimeSpecialName { + get { return (m_attributes & MethodAttributes.RTSpecialName) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.RTSpecialName; + else + m_attributes &= ~MethodAttributes.RTSpecialName; + } + } + + public bool HasSecurity { + get { return (m_attributes & MethodAttributes.HasSecurity) != 0; } + set { + if (value) + m_attributes |= MethodAttributes.HasSecurity; + else + m_attributes &= ~MethodAttributes.HasSecurity; + } + } + + #endregion + + #region MethodImplAttributes + + public bool IsIL { + get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.IL; } + set { + if (value) { + m_implAttrs &= ~MethodImplAttributes.CodeTypeMask; + m_implAttrs |= MethodImplAttributes.IL; + } else + m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.IL); + } + } + + public bool IsNative { + get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.Native; } + set { + if (value) { + m_implAttrs &= ~MethodImplAttributes.CodeTypeMask; + m_implAttrs |= MethodImplAttributes.Native; + } else + m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.Native); + } + } + + public bool IsRuntime { + get { return (m_implAttrs & MethodImplAttributes.CodeTypeMask) == MethodImplAttributes.Runtime; } + set { + if (value) { + m_implAttrs &= ~MethodImplAttributes.CodeTypeMask; + m_implAttrs |= MethodImplAttributes.Runtime; + } else + m_implAttrs &= ~(MethodImplAttributes.CodeTypeMask & MethodImplAttributes.Runtime); + } + } + + public bool IsUnmanaged { + get { return (m_implAttrs & MethodImplAttributes.ManagedMask) == MethodImplAttributes.Unmanaged; } + set { + if (value) { + m_implAttrs &= ~MethodImplAttributes.ManagedMask; + m_implAttrs |= MethodImplAttributes.Unmanaged; + } else + m_implAttrs &= ~(MethodImplAttributes.ManagedMask & MethodImplAttributes.Unmanaged); + } + } + + public bool IsManaged { + get { return (m_implAttrs & MethodImplAttributes.ManagedMask) == MethodImplAttributes.Managed; } + set { + if (value) { + m_implAttrs &= ~MethodImplAttributes.ManagedMask; + m_implAttrs |= MethodImplAttributes.Managed; + } else + m_implAttrs &= ~(MethodImplAttributes.ManagedMask & MethodImplAttributes.Managed); + } + } + + public bool IsForwardRef { + get { return (m_implAttrs & MethodImplAttributes.ForwardRef) != 0; } + set { + if (value) + m_implAttrs |= MethodImplAttributes.ForwardRef; + else + m_implAttrs &= ~MethodImplAttributes.ForwardRef; + } + } + + public bool IsPreserveSig { + get { return (m_implAttrs & MethodImplAttributes.PreserveSig) != 0; } + set { + if (value) + m_implAttrs |= MethodImplAttributes.PreserveSig; + else + m_implAttrs &= ~MethodImplAttributes.PreserveSig; + } + } + + public bool IsInternalCall { + get { return (m_implAttrs & MethodImplAttributes.InternalCall) != 0; } + set { + if (value) + m_implAttrs |= MethodImplAttributes.InternalCall; + else + m_implAttrs &= ~MethodImplAttributes.InternalCall; + } + } + + public bool IsSynchronized { + get { return (m_implAttrs & MethodImplAttributes.Synchronized) != 0; } + set { + if (value) + m_implAttrs |= MethodImplAttributes.Synchronized; + else + m_implAttrs &= ~MethodImplAttributes.Synchronized; + } + } + + public bool NoInlining { + get { return (m_implAttrs & MethodImplAttributes.NoInlining) != 0; } + set { + if (value) + m_implAttrs |= MethodImplAttributes.NoInlining; + else + m_implAttrs &= ~MethodImplAttributes.NoInlining; + } + } + + #endregion + + public bool IsConstructor { + get { + return this.IsRuntimeSpecialName && this.IsSpecialName && + (this.Name == Cctor || this.Name == Ctor); + } + } + + public bool HasBody { + get { + return (m_attributes & MethodAttributes.Abstract) == 0 && + (m_attributes & MethodAttributes.PInvokeImpl) == 0 && + (m_implAttrs & MethodImplAttributes.InternalCall) == 0 && + (m_implAttrs & MethodImplAttributes.Native) == 0 && + (m_implAttrs & MethodImplAttributes.Unmanaged) == 0 && + (m_implAttrs & MethodImplAttributes.Runtime) == 0; + } + } + + public MethodDefinition (string name, RVA rva, + MethodAttributes attrs, MethodImplAttributes implAttrs, + bool hasThis, bool explicitThis, MethodCallingConvention callConv) : + base (name, hasThis, explicitThis, callConv) + { + m_rva = rva; + m_attributes = attrs; + m_implAttrs = implAttrs; + + if (!IsStatic) + m_this = new ParameterDefinition ("this", 0, (ParameterAttributes) 0, null); + } + + internal MethodDefinition (string name, MethodAttributes attrs) : base (name) + { + m_attributes = attrs; + + this.HasThis = !this.IsStatic; + if (!IsStatic) + m_this = new ParameterDefinition ("this", 0, (ParameterAttributes) 0, null); + } + + public MethodDefinition (string name, MethodAttributes attrs, TypeReference returnType) : + this (name, attrs) + { + this.ReturnType.ReturnType = returnType; + } + + internal void LoadBody () + { + if (m_body == null && this.HasBody) { + m_body = new MethodBody (this); + if (m_module != null && m_rva != RVA.Zero) + m_module.Controller.Reader.Code.VisitMethodBody (m_body); + } + } + + public MethodDefinition Clone () + { + return Clone (this, new ImportContext (NullReferenceImporter.Instance, this)); + } + + internal static MethodDefinition Clone (MethodDefinition meth, ImportContext context) + { + MethodDefinition nm = new MethodDefinition ( + meth.Name, + RVA.Zero, + meth.Attributes, + meth.ImplAttributes, + meth.HasThis, + meth.ExplicitThis, + meth.CallingConvention); + + context.GenericContext.Method = nm; + + foreach (GenericParameter p in meth.GenericParameters) + nm.GenericParameters.Add (GenericParameter.Clone (p, context)); + + nm.ReturnType.ReturnType = context.Import (meth.ReturnType.ReturnType); + + if (meth.ReturnType.HasConstant) + nm.ReturnType.Constant = meth.ReturnType.Constant; + + if (meth.ReturnType.MarshalSpec != null) + nm.ReturnType.MarshalSpec = meth.ReturnType.MarshalSpec; + + foreach (CustomAttribute ca in meth.ReturnType.CustomAttributes) + nm.ReturnType.CustomAttributes.Add (CustomAttribute.Clone (ca, context)); + + if (meth.PInvokeInfo != null) + nm.PInvokeInfo = meth.PInvokeInfo; // TODO: import module ? + foreach (ParameterDefinition param in meth.Parameters) + nm.Parameters.Add (ParameterDefinition.Clone (param, context)); + foreach (MethodReference ov in meth.Overrides) + nm.Overrides.Add (context.Import (ov)); + foreach (CustomAttribute ca in meth.CustomAttributes) + nm.CustomAttributes.Add (CustomAttribute.Clone (ca, context)); + foreach (SecurityDeclaration sec in meth.SecurityDeclarations) + nm.SecurityDeclarations.Add (SecurityDeclaration.Clone (sec)); + + if (meth.Body != null) + nm.Body = MethodBody.Clone (meth.Body, nm, context); + + return nm; + } + + public override void Accept (IReflectionVisitor visitor) + { + visitor.VisitMethodDefinition (this); + + this.GenericParameters.Accept (visitor); + this.Parameters.Accept (visitor); + + if (this.PInvokeInfo != null) + this.PInvokeInfo.Accept (visitor); + + this.SecurityDeclarations.Accept (visitor); + this.Overrides.Accept (visitor); + this.CustomAttributes.Accept (visitor); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodDefinitionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodDefinitionCollection.cs new file mode 100644 index 0000000..ec0b1de --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodDefinitionCollection.cs @@ -0,0 +1,185 @@ +// +// MethodDefinitionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:56 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class MethodDefinitionCollection : CollectionBase, IReflectionVisitable { + + TypeDefinition m_container; + + public MethodDefinition this [int index] { + get { return List [index] as MethodDefinition; } + set { List [index] = value; } + } + + public TypeDefinition Container { + get { return m_container; } + } + + public MethodDefinitionCollection (TypeDefinition container) + { + m_container = container; + } + + public void Add (MethodDefinition value) + { + Attach (value); + + List.Add (value); + } + + + public new void Clear () + { + foreach (MethodDefinition item in this) + Detach (item); + + base.Clear (); + } + + public bool Contains (MethodDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (MethodDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, MethodDefinition value) + { + Attach (value); + + List.Insert (index, value); + } + + public void Remove (MethodDefinition value) + { + List.Remove (value); + + Detach (value); + } + + + public new void RemoveAt (int index) + { + MethodDefinition item = this [index]; + Remove (item); + } + + protected override void OnValidate (object o) + { + if (! (o is MethodDefinition)) + throw new ArgumentException ("Must be of type " + typeof (MethodDefinition).FullName); + } + + public MethodDefinition [] GetMethod (string name) + { + ArrayList ret = new ArrayList (); + foreach (MethodDefinition meth in this) + if (meth.Name == name) + ret.Add (meth); + + return ret.ToArray (typeof (MethodDefinition)) as MethodDefinition []; + } + + internal MethodDefinition GetMethodInternal (string name, IList parameters) + { + foreach (MethodDefinition meth in this) { + if (meth.Name != name || meth.Parameters.Count != parameters.Count) + continue; + + bool match = true; + for (int i = 0; i < parameters.Count; i++) { + string pname; + object param = parameters [i]; + if (param is Type) + pname = ReflectionHelper.GetTypeSignature (param as Type); + else if (param is TypeReference) + pname = (param as TypeReference).FullName; + else if (param is ParameterDefinition) + pname = (param as ParameterDefinition).ParameterType.FullName; + else + throw new NotSupportedException (); + + if (meth.Parameters [i].ParameterType.FullName != pname) { + match = false; + break; + } + } + + if (match) + return meth; + } + + return null; + } + + public MethodDefinition GetMethod (string name, Type [] parameters) + { + return GetMethodInternal (name, parameters); + } + + public MethodDefinition GetMethod (string name, TypeReference [] parameters) + { + return GetMethodInternal (name, parameters); + } + + public MethodDefinition GetMethod (string name, ParameterDefinitionCollection parameters) + { + return GetMethodInternal (name, parameters); + } + + void Attach (MemberReference member) + { + if (member.DeclaringType != null) + throw new ReflectionException ("Member already attached, clone it instead"); + + member.DeclaringType = m_container; + } + + void Detach (MemberReference member) + { + member.DeclaringType = null; + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitMethodDefinitionCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs new file mode 100644 index 0000000..ed70118 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodImplAttributes.cs @@ -0,0 +1,53 @@ +// +// MethodImplAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum MethodImplAttributes : ushort { + CodeTypeMask = 0x0003, + IL = 0x0000, // Method impl is CIL + Native = 0x0001, // Method impl is native + OPTIL = 0x0002, // Reserved: shall be zero in conforming implementations + Runtime = 0x0003, // Method impl is provided by the runtime + + ManagedMask = 0x0004, // Flags specifying whether the code is managed or unmanaged + Unmanaged = 0x0004, // Method impl is unmanaged, otherwise managed + Managed = 0x0000, // Method impl is managed + + // Implementation info and interop + ForwardRef = 0x0010, // Indicates method is defined; used primarily in merge scenarios + PreserveSig = 0x0080, // Reserved: conforming implementations may ignore + InternalCall = 0x1000, // Reserved: shall be zero in conforming implementations + Synchronized = 0x0020, // Method is single threaded through the body + NoInlining = 0x0008, // Method may not be inlined + MaxMethodImplVal = 0xffff // Range check value + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodReference.cs new file mode 100644 index 0000000..8c1aced --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodReference.cs @@ -0,0 +1,138 @@ +// +// MethodReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Text; + + public class MethodReference : MemberReference, IMethodSignature, IGenericParameterProvider { + + ParameterDefinitionCollection m_parameters; + MethodReturnType m_returnType; + + bool m_hasThis; + bool m_explicitThis; + MethodCallingConvention m_callConv; + GenericParameterCollection m_genparams; + + public virtual bool HasThis { + get { return m_hasThis; } + set { m_hasThis = value; } + } + + public virtual bool ExplicitThis { + get { return m_explicitThis; } + set { m_explicitThis = value; } + } + + public virtual MethodCallingConvention CallingConvention { + get { return m_callConv; } + set { m_callConv = value; } + } + + public virtual ParameterDefinitionCollection Parameters { + get { + if (m_parameters == null) + m_parameters = new ParameterDefinitionCollection (this); + return m_parameters; + } + } + + public GenericParameterCollection GenericParameters { + get { + if (m_genparams == null) + m_genparams = new GenericParameterCollection (this); + return m_genparams; + } + } + + public virtual MethodReturnType ReturnType { + get { return m_returnType;} + set { m_returnType = value; } + } + + internal MethodReference (string name, bool hasThis, + bool explicitThis, MethodCallingConvention callConv) : this (name) + { + m_parameters = new ParameterDefinitionCollection (this); + m_hasThis = hasThis; + m_explicitThis = explicitThis; + m_callConv = callConv; + } + + internal MethodReference (string name) : base (name) + { + m_returnType = new MethodReturnType (null); + } + + public MethodReference (string name, + TypeReference declaringType, TypeReference returnType, + bool hasThis, bool explicitThis, MethodCallingConvention callConv) : + this (name, hasThis, explicitThis, callConv) + { + this.DeclaringType = declaringType; + this.ReturnType.ReturnType = returnType; + } + + public virtual MethodReference GetOriginalMethod () + { + return this; + } + + public int GetSentinel () + { + for (int i = 0; i < Parameters.Count; i++) + if (Parameters [i].ParameterType is SentinelType) + return i; + + return -1; + } + + public override string ToString () + { + int sentinel = GetSentinel (); + + StringBuilder sb = new StringBuilder (); + sb.Append (m_returnType.ReturnType.FullName); + sb.Append (" "); + sb.Append (base.ToString ()); + sb.Append ("("); + for (int i = 0; i < this.Parameters.Count; i++) { + if (i > 0) + sb.Append (","); + + if (i == sentinel) + sb.Append ("...,"); + + sb.Append (this.Parameters [i].ParameterType.FullName); + } + sb.Append (")"); + return sb.ToString (); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodReturnType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodReturnType.cs new file mode 100644 index 0000000..4406199 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodReturnType.cs @@ -0,0 +1,110 @@ +// +// MethodReturnType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Reflection; + + using Mono.Cecil.Metadata; + + public sealed class MethodReturnType : ICustomAttributeProvider, IHasMarshalSpec, IHasConstant { + + MethodReference m_method; + ParameterDefinition m_param; + + TypeReference m_returnType; + + public MethodReference Method { + get { return m_method; } + set { m_method = value; } + } + + public TypeReference ReturnType { + get { return m_returnType; } + set { m_returnType = value; } + } + + internal ParameterDefinition Parameter { + get { return m_param; } + set { m_param = value; } + } + + public MetadataToken MetadataToken { + get { return m_param.MetadataToken; } + set { m_param.MetadataToken = value; } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_param == null) { + m_param = new ParameterDefinition ( + string.Empty, 0, (ParameterAttributes) 0, m_returnType); + m_param.Method = m_method; + } + + return m_param.CustomAttributes; + } + } + + public bool HasConstant { + get { + if (m_param == null) + return false; + + return m_param.HasConstant; + } + } + + public object Constant { + get { + if (m_param == null) + return null; + + return m_param.Constant; + } + set { + m_param.Constant = value; + } + } + + public MarshalSpec MarshalSpec { + get { + if (m_param == null) + return null; + + return m_param.MarshalSpec; + } + set { m_param.MarshalSpec = value; } + } + + public MethodReturnType (TypeReference retType) + { + m_returnType = retType; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs new file mode 100644 index 0000000..6db44b5 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodSemanticsAttributes.cs @@ -0,0 +1,42 @@ +// +// MethodSemanticsAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum MethodSemanticsAttributes : ushort { + Setter = 0x0001, // Setter for property + Getter = 0x0002, // Getter for property + Other = 0x0004, // Other method for property or event + AddOn = 0x0008, // AddOn method for event + RemoveOn = 0x0010, // RemoveOn method for event + Fire = 0x0020 // Fire method for event + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodSpecification.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodSpecification.cs new file mode 100644 index 0000000..d7e6285 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/MethodSpecification.cs @@ -0,0 +1,86 @@ +// +// MethodSpecification.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + public abstract class MethodSpecification : MethodReference { + + MethodReference m_elementMethod; + + public MethodReference ElementMethod { + get { return m_elementMethod; } + set { m_elementMethod = value; } + } + + public override string Name { + get { return m_elementMethod.Name; } + set { throw new InvalidOperationException (); } + } + + public override MethodCallingConvention CallingConvention { + get { return m_elementMethod.CallingConvention; } + set { throw new InvalidOperationException (); } + } + + public override bool HasThis { + get { return m_elementMethod.HasThis; } + set { throw new InvalidOperationException (); } + } + + public override bool ExplicitThis { + get { return m_elementMethod.ExplicitThis; } + set { throw new InvalidOperationException (); } + } + + public override MethodReturnType ReturnType { + get { return m_elementMethod.ReturnType; } + set { throw new InvalidOperationException (); } + } + + public override TypeReference DeclaringType { + get { return m_elementMethod.DeclaringType; } + set { throw new InvalidOperationException (); } + } + + public override ParameterDefinitionCollection Parameters { + get { return m_elementMethod.Parameters; } + } + + internal MethodSpecification (MethodReference elemMethod) : base (string.Empty) + { + m_elementMethod = elemMethod; + } + + public override MethodReference GetOriginalMethod() + { + return m_elementMethod.GetOriginalMethod (); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Modifiers.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Modifiers.cs new file mode 100644 index 0000000..7007636 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Modifiers.cs @@ -0,0 +1,87 @@ +// +// Modifiers.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public abstract class ModType : TypeSpecification { + + TypeReference m_modifierType; + + public TypeReference ModifierType { + get { return m_modifierType; } + set { m_modifierType = value; } + } + + public override string Name + { + get { return string.Concat (base.Name, Suffix ()); } + } + + public override string FullName + { + get { return string.Concat (base.FullName, Suffix ()); } + } + + string Suffix () + { + return string.Concat (" ", ModifierName, "(", this.ModifierType.FullName, ")"); + } + + protected abstract string ModifierName { + get; + } + + public ModType (TypeReference elemType, TypeReference modType) : base (elemType) + { + m_modifierType = modType; + } + } + + public sealed class ModifierOptional : ModType { + + protected override string ModifierName { + get { return "modopt"; } + } + + public ModifierOptional (TypeReference elemType, TypeReference modType) : base (elemType, modType) + { + } + + } + + public sealed class ModifierRequired : ModType { + + protected override string ModifierName { + get { return "modreq"; } + } + + public ModifierRequired (TypeReference elemType, TypeReference modType) : base (elemType, modType) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs new file mode 100644 index 0000000..7526b81 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleDefinition.cs @@ -0,0 +1,528 @@ +// +// ModuleDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using SR = System.Reflection; + using SS = System.Security; + using SSP = System.Security.Permissions; + using System.Text; + + using Mono.Cecil.Cil; + using Mono.Cecil.Binary; + using Mono.Cecil.Metadata; + + public sealed class ModuleDefinition : ModuleReference, ICustomAttributeProvider, IMetadataScope, + IReflectionStructureVisitable, IReflectionVisitable { + + Guid m_mvid; + bool m_main; + bool m_manifestOnly; + + AssemblyNameReferenceCollection m_asmRefs; + ModuleReferenceCollection m_modRefs; + ResourceCollection m_res; + TypeDefinitionCollection m_types; + TypeReferenceCollection m_refs; + ExternTypeCollection m_externs; + MemberReferenceCollection m_members; + CustomAttributeCollection m_customAttrs; + + AssemblyDefinition m_asm; + Image m_image; + + ImageReader m_imgReader; + ReflectionController m_controller; + SecurityDeclarationReader m_secReader; + + public Guid Mvid { + get { return m_mvid; } + set { m_mvid = value; } + } + + public bool Main { + get { return m_main; } + set { m_main = value; } + } + + public AssemblyNameReferenceCollection AssemblyReferences { + get { return m_asmRefs; } + } + + public ModuleReferenceCollection ModuleReferences { + get { return m_modRefs; } + } + + public ResourceCollection Resources { + get { return m_res; } + } + + public TypeDefinitionCollection Types { + get { return m_types; } + } + + public TypeReferenceCollection TypeReferences { + get { return m_refs; } + } + + public MemberReferenceCollection MemberReferences { + get { return m_members; } + } + + public ExternTypeCollection ExternTypes { + get { + if (m_externs == null) + m_externs = new ExternTypeCollection (this); + + return m_externs; + } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_customAttrs == null) + m_customAttrs = new CustomAttributeCollection (this); + + return m_customAttrs; + } + } + + public AssemblyDefinition Assembly { + get { return m_asm; } + } + + internal ReflectionController Controller { + get { return m_controller; } + } + + internal ImageReader ImageReader { + get { return m_imgReader; } + } + + public Image Image { + get { return m_image; } + set { + m_image = value; + m_secReader = null; + } + } + + public ModuleDefinition (string name, AssemblyDefinition asm) : + this (name, asm, null, false) + { + } + + public ModuleDefinition (string name, AssemblyDefinition asm, bool main) : + this (name, asm, null, main) + { + } + + internal ModuleDefinition (string name, AssemblyDefinition asm, StructureReader reader) : + this (name, asm, reader, false) + { + } + + internal ModuleDefinition (string name, AssemblyDefinition asm, StructureReader reader, bool main) : base (name) + { + if (asm == null) + throw new ArgumentNullException ("asm"); + if (name == null || name.Length == 0) + throw new ArgumentNullException ("name"); + + m_asm = asm; + m_main = main; +#if !CF_1_0 + m_mvid = Guid.NewGuid (); +#endif + if (reader != null) { + m_image = reader.Image; + m_imgReader = reader.ImageReader; + m_manifestOnly = reader.ManifestOnly; + } else + m_image = Image.CreateImage (); + + m_modRefs = new ModuleReferenceCollection (this); + m_asmRefs = new AssemblyNameReferenceCollection (this); + m_res = new ResourceCollection (this); + m_types = new TypeDefinitionCollection (this); + m_refs = new TypeReferenceCollection (this); + m_members = new MemberReferenceCollection (this); + + m_controller = new ReflectionController (this); + } + + public IMetadataTokenProvider LookupByToken (MetadataToken token) + { + return m_controller.Reader.LookupByToken (token); + } + + public IMetadataTokenProvider LookupByToken (TokenType table, int rid) + { + return LookupByToken (new MetadataToken (table, (uint) rid)); + } + + void CheckContext (TypeDefinition context) + { + if (context == null) + throw new ArgumentNullException ("context"); + if (context.Module != this) + throw new ArgumentException ("The context parameter does not belongs to this module"); + if (context.GenericParameters.Count == 0) + throw new ArgumentException ("The context parameter is not a generic type"); + } + + ImportContext GetContext () + { + return new ImportContext (m_controller.Importer); + } + + static ImportContext GetContext (IImporter importer) + { + return new ImportContext (importer); + } + + ImportContext GetContext (TypeDefinition context) + { + return new ImportContext (m_controller.Importer, context); + } + + static ImportContext GetContext (IImporter importer, TypeDefinition context) + { + return new ImportContext (importer, context); + } + + public TypeReference Import (Type type) + { + if (type == null) + throw new ArgumentNullException ("type"); + + return m_controller.Helper.ImportSystemType (type, GetContext ()); + } + + public TypeReference Import (Type type, TypeDefinition context) + { + if (type == null) + throw new ArgumentNullException ("type"); + CheckContext (context); + + return m_controller.Helper.ImportSystemType (type, GetContext (context)); + } + + public MethodReference Import (SR.MethodBase meth) + { + if (meth == null) + throw new ArgumentNullException ("meth"); + + if (meth is SR.ConstructorInfo) + return m_controller.Helper.ImportConstructorInfo ( + meth as SR.ConstructorInfo, GetContext ()); + else + return m_controller.Helper.ImportMethodInfo ( + meth as SR.MethodInfo, GetContext ()); + } + + public MethodReference Import (SR.MethodBase meth, TypeDefinition context) + { + if (meth == null) + throw new ArgumentNullException ("meth"); + CheckContext (context); + + if (meth is SR.ConstructorInfo) + return m_controller.Helper.ImportConstructorInfo ( + meth as SR.ConstructorInfo, GetContext (context)); + else + return m_controller.Helper.ImportMethodInfo ( + meth as SR.MethodInfo, GetContext (context)); + } + + public FieldReference Import (SR.FieldInfo field) + { + if (field == null) + throw new ArgumentNullException ("field"); + + return m_controller.Helper.ImportFieldInfo (field, GetContext ()); + } + + public FieldReference Import (SR.FieldInfo field, TypeDefinition context) + { + if (field == null) + throw new ArgumentNullException ("field"); + CheckContext (context); + + return m_controller.Helper.ImportFieldInfo (field, GetContext (context)); + } + + public TypeReference Import (TypeReference type) + { + if (type == null) + throw new ArgumentNullException ("type"); + + return m_controller.Importer.ImportTypeReference (type, GetContext ()); + } + + public TypeReference Import (TypeReference type, TypeDefinition context) + { + if (type == null) + throw new ArgumentNullException ("type"); + CheckContext (context); + + return m_controller.Importer.ImportTypeReference (type, GetContext (context)); + } + + public MethodReference Import (MethodReference meth) + { + if (meth == null) + throw new ArgumentNullException ("meth"); + + return m_controller.Importer.ImportMethodReference (meth, GetContext ()); + } + + public MethodReference Import (MethodReference meth, TypeDefinition context) + { + if (meth == null) + throw new ArgumentNullException ("meth"); + CheckContext (context); + + return m_controller.Importer.ImportMethodReference (meth, GetContext (context)); + } + + public FieldReference Import (FieldReference field) + { + if (field == null) + throw new ArgumentNullException ("field"); + + return m_controller.Importer.ImportFieldReference (field, GetContext ()); + } + + public FieldReference Import (FieldReference field, TypeDefinition context) + { + if (field == null) + throw new ArgumentNullException ("field"); + CheckContext (context); + + return m_controller.Importer.ImportFieldReference (field, GetContext (context)); + } + + static FieldDefinition ImportFieldDefinition (FieldDefinition field, ImportContext context) + { + return FieldDefinition.Clone (field, context); + } + + static MethodDefinition ImportMethodDefinition (MethodDefinition meth, ImportContext context) + { + return MethodDefinition.Clone (meth, context); + } + + static TypeDefinition ImportTypeDefinition (TypeDefinition type, ImportContext context) + { + return TypeDefinition.Clone (type, context); + } + + public TypeDefinition Inject (TypeDefinition type) + { + return Inject (type, m_controller.Importer); + } + + public TypeDefinition Inject (TypeDefinition type, IImporter importer) + { + if (type == null) + throw new ArgumentNullException ("type"); + if (importer == null) + throw new ArgumentNullException ("importer"); + + TypeDefinition definition = ImportTypeDefinition (type, GetContext (importer)); + this.Types.Add (definition); + return definition; + } + + public TypeDefinition Inject (TypeDefinition type, TypeDefinition context) + { + return Inject (type, context, m_controller.Importer); + } + + public TypeDefinition Inject (TypeDefinition type, TypeDefinition context, IImporter importer) + { + Check (type, context, importer); + + TypeDefinition definition = ImportTypeDefinition (type, GetContext (importer, context)); + context.NestedTypes.Add (definition); + return definition; + } + + public MethodDefinition Inject (MethodDefinition meth, TypeDefinition context) + { + return Inject (meth, context, m_controller.Importer); + } + + void Check (IMemberDefinition definition, TypeDefinition context, IImporter importer) + { + if (definition == null) + throw new ArgumentNullException ("definition"); + if (context == null) + throw new ArgumentNullException ("context"); + if (importer == null) + throw new ArgumentNullException ("importer"); + if (context.Module != this) + throw new ArgumentException ("The context parameter does not belongs to this module"); + } + + public MethodDefinition Inject (MethodDefinition meth, TypeDefinition context, IImporter importer) + { + Check (meth, context, importer); + + MethodDefinition definition = ImportMethodDefinition (meth, GetContext (importer, context)); + context.Methods.Add (definition); + return definition; + } + + public FieldDefinition Inject (FieldDefinition field, TypeDefinition context, IImporter importer) + { + Check (field, context, importer); + + FieldDefinition definition = ImportFieldDefinition (field, GetContext (importer, context)); + context.Fields.Add (definition); + return definition; + } + + public void FullLoad () + { + if (m_manifestOnly) + m_controller.Reader.VisitModuleDefinition (this); + + foreach (TypeDefinition type in this.Types) { + foreach (MethodDefinition meth in type.Methods) + meth.LoadBody (); + foreach (MethodDefinition ctor in type.Constructors) + ctor.LoadBody (); + } + + if (m_controller.Reader.SymbolReader == null) + return; + + m_controller.Reader.SymbolReader.Dispose (); + m_controller.Reader.SymbolReader = null; + } + + public void LoadSymbols () + { + m_controller.Reader.SymbolReader = SymbolStoreHelper.GetReader (this); + } + + public void LoadSymbols (ISymbolReader reader) + { + m_controller.Reader.SymbolReader = reader; + } + + public void SaveSymbols () + { + m_controller.Writer.SaveSymbols = true; + } + + public void SaveSymbols (ISymbolWriter writer) + { + SaveSymbols (); + m_controller.Writer.SymbolWriter = writer; + } + + public void SaveSymbols (string outputDirectory) + { + SaveSymbols (); + m_controller.Writer.OutputFile = outputDirectory; + } + + public void SaveSymbols (string outputDirectory, ISymbolWriter writer) + { + SaveSymbols (outputDirectory); + m_controller.Writer.SymbolWriter = writer; + } + + public byte [] GetAsByteArray (CustomAttribute ca) + { + CustomAttribute customAttr = ca; + if (!ca.Resolved) + if (customAttr.Blob != null) + return customAttr.Blob; + else + return new byte [0]; + + return m_controller.Writer.SignatureWriter.CompressCustomAttribute ( + ReflectionWriter.GetCustomAttributeSig (ca), ca.Constructor); + } + + public byte [] GetAsByteArray (SecurityDeclaration dec) + { + // TODO - add support for 2.0 format + // note: the 1.x format is still supported in 2.0 so this isn't an immediate problem + if (!dec.Resolved) + return dec.Blob; + +#if !CF_1_0 && !CF_2_0 + if (dec.PermissionSet != null) + return Encoding.Unicode.GetBytes (dec.PermissionSet.ToXml ().ToString ()); +#endif + + return new byte [0]; + } + + public CustomAttribute FromByteArray (MethodReference ctor, byte [] data) + { + return m_controller.Reader.GetCustomAttribute (ctor, data); + } + + public SecurityDeclaration FromByteArray (SecurityAction action, byte [] declaration) + { + if (m_secReader == null) + m_secReader = new SecurityDeclarationReader (Image.MetadataRoot, m_controller.Reader); + return m_secReader.FromByteArray (action, declaration); + } + + public override void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitModuleDefinition (this); + + this.AssemblyReferences.Accept (visitor); + this.ModuleReferences.Accept (visitor); + this.Resources.Accept (visitor); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitModuleDefinition (this); + + this.Types.Accept (visitor); + this.TypeReferences.Accept (visitor); + } + + public override string ToString () + { + string s = (m_main ? "(main), Mvid=" : "Mvid="); + return s + m_mvid; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleDefinitionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleDefinitionCollection.cs new file mode 100644 index 0000000..71d1619 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleDefinitionCollection.cs @@ -0,0 +1,93 @@ +// +// ModuleDefinitionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:54 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ModuleDefinitionCollection : CollectionBase, IReflectionStructureVisitable { + + AssemblyDefinition m_container; + + public ModuleDefinition this [int index] { + get { return List [index] as ModuleDefinition; } + set { List [index] = value; } + } + + public AssemblyDefinition Container { + get { return m_container; } + } + + public ModuleDefinitionCollection (AssemblyDefinition container) + { + m_container = container; + } + + public void Add (ModuleDefinition value) + { + List.Add (value); + } + + public bool Contains (ModuleDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (ModuleDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, ModuleDefinition value) + { + List.Insert (index, value); + } + + public void Remove (ModuleDefinition value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is ModuleDefinition)) + throw new ArgumentException ("Must be of type " + typeof (ModuleDefinition).FullName); + } + + public void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitModuleDefinitionCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleReference.cs new file mode 100644 index 0000000..713b96a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleReference.cs @@ -0,0 +1,71 @@ +// +// ModuleReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + using Mono.Cecil; + using Mono.Cecil.Metadata; + + public class ModuleReference : IMetadataScope, IAnnotationProvider, IReflectionStructureVisitable { + + string m_name; + MetadataToken m_token; + IDictionary m_annotations; + + public string Name { + get { return m_name; } + set { m_name = value; } + } + + public MetadataToken MetadataToken { + get { return m_token; } + set { m_token = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { + if (m_annotations == null) + m_annotations = new Hashtable (); + return m_annotations; + } + } + + public ModuleReference (string name) + { + m_name = name; + } + + public virtual void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitModuleReference (this); + } + } +} + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleReferenceCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleReferenceCollection.cs new file mode 100644 index 0000000..03057b3 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ModuleReferenceCollection.cs @@ -0,0 +1,93 @@ +// +// ModuleReferenceCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:53 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ModuleReferenceCollection : CollectionBase, IReflectionStructureVisitable { + + ModuleDefinition m_container; + + public ModuleReference this [int index] { + get { return List [index] as ModuleReference; } + set { List [index] = value; } + } + + public ModuleDefinition Container { + get { return m_container; } + } + + public ModuleReferenceCollection (ModuleDefinition container) + { + m_container = container; + } + + public void Add (ModuleReference value) + { + List.Add (value); + } + + public bool Contains (ModuleReference value) + { + return List.Contains (value); + } + + public int IndexOf (ModuleReference value) + { + return List.IndexOf (value); + } + + public void Insert (int index, ModuleReference value) + { + List.Insert (index, value); + } + + public void Remove (ModuleReference value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is ModuleReference)) + throw new ArgumentException ("Must be of type " + typeof (ModuleReference).FullName); + } + + public void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitModuleReferenceCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NativeType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NativeType.cs new file mode 100644 index 0000000..c0df049 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NativeType.cs @@ -0,0 +1,73 @@ +// +// NativeType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public enum NativeType { + NONE = 0x66, + + BOOLEAN = 0x02, + I1 = 0x03, + U1 = 0x04, + I2 = 0x05, + U2 = 0x06, + I4 = 0x07, + U4 = 0x08, + I8 = 0x09, + U8 = 0x0a, + R4 = 0x0b, + R8 = 0x0c, + LPSTR = 0x14, + INT = 0x1f, + UINT = 0x20, + FUNC = 0x26, + ARRAY = 0x2a, + + // Msft specific + CURRENCY = 0x0f, + BSTR = 0x13, + LPWSTR = 0x15, + LPTSTR = 0x16, + FIXEDSYSSTRING = 0x17, + IUNKNOWN = 0x19, + IDISPATCH = 0x1a, + STRUCT = 0x1b, + INTF = 0x1c, + SAFEARRAY = 0x1d, + FIXEDARRAY = 0x1e, + BYVALSTR = 0x22, + ANSIBSTR = 0x23, + TBSTR = 0x24, + VARIANTBOOL = 0x25, + ASANY = 0x28, + LPSTRUCT = 0x2b, + CUSTOMMARSHALER = 0x2c, + ERROR = 0x2d, + MAX = 0x50 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NestedTypeCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NestedTypeCollection.cs new file mode 100644 index 0000000..9e0ee29 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NestedTypeCollection.cs @@ -0,0 +1,128 @@ +// +// NestedTypeCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:57 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class NestedTypeCollection : CollectionBase, IReflectionVisitable { + + TypeDefinition m_container; + + public TypeDefinition this [int index] { + get { return List [index] as TypeDefinition; } + set { List [index] = value; } + } + + public TypeDefinition Container { + get { return m_container; } + } + + public NestedTypeCollection (TypeDefinition container) + { + m_container = container; + } + + public void Add (TypeDefinition value) + { + Attach (value); + + List.Add (value); + } + + + public new void Clear () + { + foreach (TypeDefinition item in this) + Detach (item); + + base.Clear (); + } + + public bool Contains (TypeDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (TypeDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, TypeDefinition value) + { + Attach (value); + + List.Insert (index, value); + } + + public void Remove (TypeDefinition value) + { + List.Remove (value); + + Detach (value); + } + + + public new void RemoveAt (int index) + { + TypeDefinition item = this [index]; + Remove (item); + } + + protected override void OnValidate (object o) + { + if (! (o is TypeDefinition)) + throw new ArgumentException ("Must be of type " + typeof (TypeDefinition).FullName); + } + + void Attach (MemberReference member) + { + if (member.DeclaringType != null) + throw new ReflectionException ("Member already attached, clone it instead"); + + member.DeclaringType = m_container; + } + + void Detach (MemberReference member) + { + member.DeclaringType = null; + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitNestedTypeCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NullReferenceImporter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NullReferenceImporter.cs new file mode 100644 index 0000000..0df44b7 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/NullReferenceImporter.cs @@ -0,0 +1,50 @@ +// +// NullReferenceImporter.cs +// +// Author: +// Jb Evain (jbevain@novell.com) +// +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + class NullReferenceImporter : IImporter { + + public static readonly NullReferenceImporter Instance = new NullReferenceImporter (); + + public TypeReference ImportTypeReference (TypeReference type, ImportContext context) + { + return type; + } + + public FieldReference ImportFieldReference (FieldReference field, ImportContext context) + { + return field; + } + + public MethodReference ImportMethodReference (MethodReference method, ImportContext context) + { + return method; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/OverrideCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/OverrideCollection.cs new file mode 100644 index 0000000..77341af --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/OverrideCollection.cs @@ -0,0 +1,93 @@ +// +// OverrideCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:53 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class OverrideCollection : CollectionBase, IReflectionVisitable { + + MethodDefinition m_container; + + public MethodReference this [int index] { + get { return List [index] as MethodReference; } + set { List [index] = value; } + } + + public MethodDefinition Container { + get { return m_container; } + } + + public OverrideCollection (MethodDefinition container) + { + m_container = container; + } + + public void Add (MethodReference value) + { + List.Add (value); + } + + public bool Contains (MethodReference value) + { + return List.Contains (value); + } + + public int IndexOf (MethodReference value) + { + return List.IndexOf (value); + } + + public void Insert (int index, MethodReference value) + { + List.Insert (index, value); + } + + public void Remove (MethodReference value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is MethodReference)) + throw new ArgumentException ("Must be of type " + typeof (MethodReference).FullName); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitOverrideCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs new file mode 100644 index 0000000..30d3935 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PInvokeAttributes.cs @@ -0,0 +1,53 @@ +// +// PInvokeAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum PInvokeAttributes : ushort { + NoMangle = 0x0001, // PInvoke is to use the member name as specified + + // Character set + CharSetMask = 0x0006, + CharSetNotSpec = 0x0000, + CharSetAnsi = 0x0002, + CharSetUnicode = 0x0004, + CharSetAuto = 0x0006, + SupportsLastError = 0x0040, // Information about target function. Not relevant for fields + + // Calling convetion + CallConvMask = 0x0700, + CallConvWinapi = 0x0100, + CallConvCdecl = 0x0200, + CallConvStdCall = 0x0300, + CallConvThiscall = 0x0400, + CallConvFastcall = 0x0500 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PInvokeInfo.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PInvokeInfo.cs new file mode 100644 index 0000000..40c1551 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PInvokeInfo.cs @@ -0,0 +1,200 @@ +// +// PInvokeInfo.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class PInvokeInfo : IReflectionVisitable { + + MethodDefinition m_meth; + + PInvokeAttributes m_attributes; + string m_entryPoint; + ModuleReference m_module; + + public MethodDefinition Method { + get { return m_meth; } + } + + public PInvokeAttributes Attributes { + get { return m_attributes; } + set { m_attributes = value; } + } + + public string EntryPoint { + get { return m_entryPoint; } + set { m_entryPoint = value; } + } + + public ModuleReference Module { + get { return m_module; } + set { m_module = value; } + } + + #region PInvokeAttributes + + public bool IsNoMangle { + get { return (m_attributes & PInvokeAttributes.NoMangle) != 0; } + set { + if (value) + m_attributes |= PInvokeAttributes.NoMangle; + else + m_attributes &= ~PInvokeAttributes.NoMangle; + } + } + + public bool IsCharSetNotSpec { + get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetNotSpec; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CharSetMask; + m_attributes |= PInvokeAttributes.CharSetNotSpec; + } else + m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetNotSpec); + } + } + + public bool IsCharSetAnsi { + get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAnsi; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CharSetMask; + m_attributes |= PInvokeAttributes.CharSetAnsi; + } else + m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAnsi); + } + } + + public bool IsCharSetUnicode { + get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetUnicode; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CharSetMask; + m_attributes |= PInvokeAttributes.CharSetUnicode; + } else + m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetUnicode); + } + } + + public bool IsCharSetAuto { + get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.CharSetAuto; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CharSetMask; + m_attributes |= PInvokeAttributes.CharSetAuto; + } else + m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.CharSetAuto); + } + } + + public bool SupportsLastError { + get { return (m_attributes & PInvokeAttributes.CharSetMask) == PInvokeAttributes.SupportsLastError; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CharSetMask; + m_attributes |= PInvokeAttributes.SupportsLastError; + } else + m_attributes &= ~(PInvokeAttributes.CharSetMask & PInvokeAttributes.SupportsLastError); + } + } + + public bool IsCallConvWinapi { + get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvWinapi; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CallConvMask; + m_attributes |= PInvokeAttributes.CallConvWinapi; + } else + m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvWinapi); + } + } + + public bool IsCallConvCdecl { + get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvCdecl; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CallConvMask; + m_attributes |= PInvokeAttributes.CallConvCdecl; + } else + m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvCdecl); + } + } + + public bool IsCallConvStdCall { + get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvStdCall; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CallConvMask; + m_attributes |= PInvokeAttributes.CallConvStdCall; + } else + m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvStdCall); + } + } + + public bool IsCallConvThiscall { + get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvThiscall; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CallConvMask; + m_attributes |= PInvokeAttributes.CallConvThiscall; + } else + m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvThiscall); + } + } + + public bool IsCallConvFastcall { + get { return (m_attributes & PInvokeAttributes.CallConvMask) == PInvokeAttributes.CallConvFastcall; } + set { + if (value) { + m_attributes &= ~PInvokeAttributes.CallConvMask; + m_attributes |= PInvokeAttributes.CallConvFastcall; + } else + m_attributes &= ~(PInvokeAttributes.CallConvMask & PInvokeAttributes.CallConvFastcall); + } + } + + #endregion + + public PInvokeInfo (MethodDefinition meth) + { + m_meth = meth; + } + + public PInvokeInfo (MethodDefinition meth, PInvokeAttributes attrs, + string entryPoint, ModuleReference mod) : this (meth) + { + m_attributes = attrs; + m_entryPoint = entryPoint; + m_module = mod; + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitPInvokeInfo (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterAttributes.cs new file mode 100644 index 0000000..d112209 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterAttributes.cs @@ -0,0 +1,43 @@ +// +// ParameterAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum ParameterAttributes : ushort { + None = 0x0000, + In = 0x0001, // Param is [In] + Out = 0x0002, // Param is [Out] + Optional = 0x0010, // Param is optional + HasDefault = 0x1000, // Param has default value + HasFieldMarshal = 0x2000, // Param has field marshal + Unused = 0xcfe0 // Reserved: shall be zero in a conforming implementation + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs new file mode 100644 index 0000000..5aef109 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterDefinition.cs @@ -0,0 +1,175 @@ +// +// ParameterDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class ParameterDefinition : ParameterReference, IHasMarshalSpec, + IMetadataTokenProvider, ICustomAttributeProvider, IHasConstant { + + ParameterAttributes m_attributes; + + bool m_hasConstant; + object m_const; + + MethodReference m_method; + CustomAttributeCollection m_customAttrs; + + MarshalSpec m_marshalDesc; + + public ParameterAttributes Attributes { + get { return m_attributes; } + set { m_attributes = value; } + } + + public bool HasConstant { + get { return m_hasConstant; } + } + + public object Constant { + get { return m_const; } + set { + m_hasConstant = true; + m_const = value; + } + } + + public MethodReference Method { + get { return m_method; } + set { m_method = value; } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_customAttrs == null) + m_customAttrs = new CustomAttributeCollection (this); + + return m_customAttrs; + } + } + + public MarshalSpec MarshalSpec { + get { return m_marshalDesc; } + set { + m_marshalDesc = value; + if (value != null) + m_attributes |= ParameterAttributes.HasFieldMarshal; + else + m_attributes &= ~ParameterAttributes.HasFieldMarshal; + } + } + + #region ParameterAttributes + + public bool IsIn { + get { return (m_attributes & ParameterAttributes.In) != 0; } + set { + if (value) + m_attributes |= ParameterAttributes.In; + else + m_attributes &= ~ParameterAttributes.In; + } + } + + public bool IsOut { + get { return (m_attributes & ParameterAttributes.Out) != 0; } + set { + if (value) + m_attributes |= ParameterAttributes.Out; + else + m_attributes &= ~ParameterAttributes.Out; + } + } + + public bool IsOptional { + get { return (m_attributes & ParameterAttributes.Optional) != 0; } + set { + if (value) + m_attributes |= ParameterAttributes.Optional; + else + m_attributes &= ~ParameterAttributes.Optional; + } + } + + public bool HasDefault { + get { return (m_attributes & ParameterAttributes.HasDefault) != 0; } + set { + if (value) + m_attributes |= ParameterAttributes.HasDefault; + else + m_attributes &= ~ParameterAttributes.HasDefault; + } + } + + #endregion + + public ParameterDefinition (TypeReference paramType) : + this (string.Empty, -1, (ParameterAttributes) 0, paramType) + { + } + + public ParameterDefinition (string name, int seq, ParameterAttributes attrs, TypeReference paramType) : base (name, seq, paramType) + { + m_attributes = attrs; + } + + public ParameterDefinition Clone () + { + return Clone (this, new ImportContext (NullReferenceImporter.Instance, m_method)); + } + + internal static ParameterDefinition Clone (ParameterDefinition param, ImportContext context) + { + ParameterDefinition np = new ParameterDefinition ( + param.Name, + param.Sequence, + param.Attributes, + context.Import (param.ParameterType)); + + if (param.HasConstant) + np.Constant = param.Constant; + + if (param.MarshalSpec != null) + np.MarshalSpec = param.MarshalSpec; + + foreach (CustomAttribute ca in param.CustomAttributes) + np.CustomAttributes.Add (CustomAttribute.Clone (ca, context)); + + return np; + } + + public override void Accept (IReflectionVisitor visitor) + { + visitor.VisitParameterDefinition (this); + + if (this.MarshalSpec != null) + this.MarshalSpec.Accept (visitor); + + this.CustomAttributes.Accept (visitor); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs new file mode 100644 index 0000000..5fa2229 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterDefinitionCollection.cs @@ -0,0 +1,93 @@ +// +// ParameterDefinitionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:52 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ParameterDefinitionCollection : CollectionBase, IReflectionVisitable { + + IMemberReference m_container; + + public ParameterDefinition this [int index] { + get { return List [index] as ParameterDefinition; } + set { List [index] = value; } + } + + public IMemberReference Container { + get { return m_container; } + } + + public ParameterDefinitionCollection (IMemberReference container) + { + m_container = container; + } + + public void Add (ParameterDefinition value) + { + List.Add (value); + } + + public bool Contains (ParameterDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (ParameterDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, ParameterDefinition value) + { + List.Insert (index, value); + } + + public void Remove (ParameterDefinition value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is ParameterDefinition)) + throw new ArgumentException ("Must be of type " + typeof (ParameterDefinition).FullName); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitParameterDefinitionCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterReference.cs new file mode 100644 index 0000000..f7bda3e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ParameterReference.cs @@ -0,0 +1,88 @@ +// +// ParameterReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + using Mono.Cecil.Metadata; + + public abstract class ParameterReference : IMetadataTokenProvider, IAnnotationProvider, IReflectionVisitable { + + string m_name; + int m_sequence; + TypeReference m_paramType; + MetadataToken m_token; + IDictionary m_annotations; + + public string Name { + get { return m_name; } + set { m_name = value; } + } + + public int Sequence { + get { return m_sequence; } + set { m_sequence = value; } + } + + public TypeReference ParameterType { + get { return m_paramType; } + set { m_paramType = value; } + } + + public MetadataToken MetadataToken { + get { return m_token; } + set { m_token = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { + if (m_annotations == null) + m_annotations = new Hashtable (); + return m_annotations; + } + } + + public ParameterReference (string name, int sequence, TypeReference parameterType) + { + m_name = name; + m_sequence = sequence; + m_paramType = parameterType; + } + + public override string ToString () + { + if (m_name != null && m_name.Length > 0) + return m_name; + + return string.Concat ("A_", m_sequence); + } + + public abstract void Accept (IReflectionVisitor visitor); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PinnedType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PinnedType.cs new file mode 100644 index 0000000..f62a6bd --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PinnedType.cs @@ -0,0 +1,37 @@ +// +// PinnedType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class PinnedType : TypeSpecification { + + public PinnedType (TypeReference pType) : base (pType) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PointerType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PointerType.cs new file mode 100644 index 0000000..1228733 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PointerType.cs @@ -0,0 +1,45 @@ +// +// PointerType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class PointerType : TypeSpecification { + + public override string Name { + get { return string.Concat (base.Name, "*"); } + } + + public override string FullName { + get { return string.Concat (base.FullName, "*"); } + } + + public PointerType (TypeReference pType) : base (pType) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyAttributes.cs new file mode 100644 index 0000000..f11468f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyAttributes.cs @@ -0,0 +1,40 @@ +// +// PropertyAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum PropertyAttributes : ushort { + SpecialName = 0x0200, // Property is special + RTSpecialName = 0x0400, // Runtime(metadata internal APIs) should check name encoding + HasDefault = 0x1000, // Property has default + Unused = 0xe9ff // Reserved: shall be zero in a conforming implementation + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyDefinition.cs new file mode 100644 index 0000000..23086e8 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyDefinition.cs @@ -0,0 +1,225 @@ +// +// PropertyDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Text; + + public sealed class PropertyDefinition : PropertyReference, + IMemberDefinition, ICustomAttributeProvider, IHasConstant { + + PropertyAttributes m_attributes; + + CustomAttributeCollection m_customAttrs; + + MethodDefinition m_getMeth; + MethodDefinition m_setMeth; + + bool m_hasConstant; + object m_const; + + public PropertyAttributes Attributes { + get { return m_attributes; } + set { m_attributes = value; } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_customAttrs == null) + m_customAttrs = new CustomAttributeCollection (this); + + return m_customAttrs; + } + } + + public override ParameterDefinitionCollection Parameters { + get { + if (this.GetMethod != null) + return CloneParameterCollection (this.GetMethod.Parameters); + else if (this.SetMethod != null) { + ParameterDefinitionCollection parameters = + CloneParameterCollection (this.SetMethod.Parameters); + if (parameters.Count > 0) + parameters.RemoveAt (parameters.Count - 1); + return parameters; + } + + if (m_parameters == null) + m_parameters = new ParameterDefinitionCollection (this); + + return m_parameters; + } + } + + public MethodDefinition GetMethod { + get { return m_getMeth; } + set { m_getMeth = value; } + } + + public MethodDefinition SetMethod { + get { return m_setMeth; } + set { m_setMeth = value; } + } + + ParameterDefinitionCollection CloneParameterCollection (ParameterDefinitionCollection original) + { + ParameterDefinitionCollection clone = new ParameterDefinitionCollection ( + original.Container); + foreach (ParameterDefinition param in original) + clone.Add (param); + return clone; + } + + public bool HasConstant { + get { return m_hasConstant; } + } + + public object Constant { + get { return m_const; } + set { + m_hasConstant = true; + m_const = value; + } + } + + #region PropertyAttributes + + public bool IsSpecialName { + get { return (m_attributes & PropertyAttributes.SpecialName) != 0; } + set { + if (value) + m_attributes |= PropertyAttributes.SpecialName; + else + m_attributes &= ~PropertyAttributes.SpecialName; + } + } + + public bool IsRuntimeSpecialName { + get { return (m_attributes & PropertyAttributes.RTSpecialName) != 0; } + set { + if (value) + m_attributes |= PropertyAttributes.RTSpecialName; + else + m_attributes &= ~PropertyAttributes.RTSpecialName; + } + } + + public bool HasDefault { + get { return (m_attributes & PropertyAttributes.HasDefault) != 0; } + set { + if (value) + m_attributes |= PropertyAttributes.HasDefault; + else + m_attributes &= ~PropertyAttributes.HasDefault; + } + } + + #endregion + + public PropertyDefinition (string name, TypeReference propertyType, PropertyAttributes attrs) : base (name, propertyType) + { + m_attributes = attrs; + } + + public static MethodDefinition CreateGetMethod (PropertyDefinition prop) + { + MethodDefinition get = new MethodDefinition ( + string.Concat ("get_", prop.Name), (MethodAttributes) 0, prop.PropertyType); + prop.GetMethod = get; + return get; + } + + public static MethodDefinition CreateSetMethod (PropertyDefinition prop) + { + MethodDefinition set = new MethodDefinition ( + string.Concat ("set_", prop.Name), (MethodAttributes) 0, prop.PropertyType); + prop.SetMethod = set; + return set; + } + + public PropertyDefinition Clone () + { + return Clone (this, new ImportContext (NullReferenceImporter.Instance, this.DeclaringType)); + } + + internal static PropertyDefinition Clone (PropertyDefinition prop, ImportContext context) + { + PropertyDefinition np = new PropertyDefinition ( + prop.Name, + context.Import (prop.PropertyType), + prop.Attributes); + + if (prop.HasConstant) + np.Constant = prop.Constant; + + if (context.GenericContext.Type is TypeDefinition) { + TypeDefinition type = context.GenericContext.Type as TypeDefinition; + if (prop.SetMethod != null) + np.SetMethod = type.Methods.GetMethod (prop.SetMethod.Name, prop.SetMethod.Parameters); + if (prop.GetMethod != null) + np.GetMethod = type.Methods.GetMethod (prop.GetMethod.Name, prop.GetMethod.Parameters); + } + + foreach (CustomAttribute ca in prop.CustomAttributes) + np.CustomAttributes.Add (CustomAttribute.Clone (ca, context)); + + return np; + } + + public override string ToString () + { + StringBuilder sb = new StringBuilder (); + sb.Append (PropertyType.ToString ()); + sb.Append (' '); + + if (this.DeclaringType != null) { + sb.Append (this.DeclaringType.ToString ()); + sb.Append ("::"); + } + + sb.Append (this.Name); + sb.Append ('('); + ParameterDefinitionCollection parameters = this.Parameters; + for (int i = 0; i < parameters.Count; i++) { + if (i > 0) + sb.Append (','); + sb.Append (parameters [i].ParameterType.ToString ()); + } + sb.Append (')'); + return sb.ToString (); + } + + public override void Accept (IReflectionVisitor visitor) + { + visitor.VisitPropertyDefinition (this); + + this.CustomAttributes.Accept (visitor); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyDefinitionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyDefinitionCollection.cs new file mode 100644 index 0000000..7860b6c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyDefinitionCollection.cs @@ -0,0 +1,138 @@ +// +// PropertyDefinitionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:57 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class PropertyDefinitionCollection : CollectionBase, IReflectionVisitable { + + TypeDefinition m_container; + + public PropertyDefinition this [int index] { + get { return List [index] as PropertyDefinition; } + set { List [index] = value; } + } + + public TypeDefinition Container { + get { return m_container; } + } + + public PropertyDefinitionCollection (TypeDefinition container) + { + m_container = container; + } + + public void Add (PropertyDefinition value) + { + Attach (value); + + List.Add (value); + } + + + public new void Clear () + { + foreach (PropertyDefinition item in this) + Detach (item); + + base.Clear (); + } + + public bool Contains (PropertyDefinition value) + { + return List.Contains (value); + } + + public int IndexOf (PropertyDefinition value) + { + return List.IndexOf (value); + } + + public void Insert (int index, PropertyDefinition value) + { + Attach (value); + + List.Insert (index, value); + } + + public void Remove (PropertyDefinition value) + { + List.Remove (value); + + Detach (value); + } + + + public new void RemoveAt (int index) + { + PropertyDefinition item = this [index]; + Remove (item); + } + + protected override void OnValidate (object o) + { + if (! (o is PropertyDefinition)) + throw new ArgumentException ("Must be of type " + typeof (PropertyDefinition).FullName); + } + + public PropertyDefinition [] GetProperties (string name) + { + ArrayList ret = new ArrayList (); + foreach (PropertyDefinition prop in this) + if (prop.Name == name) + ret.Add (prop); + + return ret.ToArray (typeof (PropertyDefinition)) as PropertyDefinition []; + } + + void Attach (MemberReference member) + { + if (member.DeclaringType != null) + throw new ReflectionException ("Member already attached, clone it instead"); + + member.DeclaringType = m_container; + } + + void Detach (MemberReference member) + { + member.DeclaringType = null; + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitPropertyDefinitionCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyReference.cs new file mode 100644 index 0000000..20112b6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/PropertyReference.cs @@ -0,0 +1,50 @@ +// +// PropertyReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public abstract class PropertyReference : MemberReference { + + TypeReference m_propertyType; + protected ParameterDefinitionCollection m_parameters; + + public TypeReference PropertyType { + get { return m_propertyType; } + set { m_propertyType = value; } + } + + public abstract ParameterDefinitionCollection Parameters { + get; + } + + public PropertyReference (string name, TypeReference propertyType) : base (name) + { + m_propertyType = propertyType; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReferenceType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReferenceType.cs new file mode 100644 index 0000000..6d1e0e8 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReferenceType.cs @@ -0,0 +1,45 @@ +// +// ReferenceType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class ReferenceType : TypeSpecification { + + public override string Name { + get { return string.Concat (base.Name, "&"); } + } + + public override string FullName { + get { return string.Concat (base.FullName, "&"); } + } + + public ReferenceType (TypeReference type) : base (type) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionController.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionController.cs new file mode 100644 index 0000000..22fdab1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionController.cs @@ -0,0 +1,62 @@ +// +// ReflectionController.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + internal sealed class ReflectionController { + + ReflectionReader m_reader; + ReflectionWriter m_writer; + ReflectionHelper m_helper; + DefaultImporter m_importer; + + public ReflectionReader Reader { + get { return m_reader; } + } + + public ReflectionWriter Writer { + get { return m_writer; } + } + + public ReflectionHelper Helper { + get { return m_helper; } + } + + public IImporter Importer { + get { return m_importer; } + } + + public ReflectionController (ModuleDefinition module) + { + m_reader = new AggressiveReflectionReader (module); + m_writer = new ReflectionWriter (module); + m_helper = new ReflectionHelper (module); + m_importer = new DefaultImporter (module); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionException.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionException.cs new file mode 100644 index 0000000..4027313 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionException.cs @@ -0,0 +1,55 @@ +// +// ReflectionException.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + using Mono.Cecil.Metadata; + + public sealed class ReflectionException : MetadataFormatException { + + internal ReflectionException () : base () + { + } + + internal ReflectionException (string message) : base (message) + { + } + + internal ReflectionException (string message, params string [] parameters) : + base (string.Format (message, parameters)) + { + } + + internal ReflectionException (string message, Exception inner) : + base (message, inner) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionHelper.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionHelper.cs new file mode 100644 index 0000000..d3e2a87 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionHelper.cs @@ -0,0 +1,395 @@ +// +// ReflectionHelper.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// (C) 2006 Evaluant RC S.A. +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + using SR = System.Reflection; + using System.Text; + + internal sealed class ReflectionHelper { + + ModuleDefinition m_module; + + public ReflectionHelper (ModuleDefinition module) + { + m_module = module; + } + + public AssemblyNameReference ImportAssembly (SR.Assembly asm) + { + AssemblyNameReference asmRef = GetAssemblyNameReference (asm.GetName ()); + if (asmRef != null) + return asmRef; + + SR.AssemblyName asmName = asm.GetName (); + asmRef = new AssemblyNameReference ( + asmName.Name, asmName.CultureInfo.Name, asmName.Version); + asmRef.PublicKeyToken = asmName.GetPublicKeyToken (); + asmRef.HashAlgorithm = (AssemblyHashAlgorithm) asmName.HashAlgorithm; + asmRef.Culture = asmName.CultureInfo.ToString (); + m_module.AssemblyReferences.Add (asmRef); + return asmRef; + } + + AssemblyNameReference GetAssemblyNameReference (SR.AssemblyName name) + { + foreach (AssemblyNameReference reference in m_module.AssemblyReferences) + if (reference.FullName == name.FullName) + return reference; + + return null; + } + + public static string GetTypeSignature (Type t) + { + if (t.HasElementType) { + if (t.IsPointer) + return string.Concat (GetTypeSignature (t.GetElementType ()), "*"); + else if (t.IsArray) // deal with complex arrays + return string.Concat (GetTypeSignature (t.GetElementType ()), "[]"); + else if (t.IsByRef) + return string.Concat (GetTypeSignature (t.GetElementType ()), "&"); + } + + if (IsGenericTypeSpec (t)) { + StringBuilder sb = new StringBuilder (); + sb.Append (GetTypeSignature (GetGenericTypeDefinition (t))); + sb.Append ("<"); + Type [] genArgs = GetGenericArguments (t); + for (int i = 0; i < genArgs.Length; i++) { + if (i > 0) + sb.Append (","); + sb.Append (GetTypeSignature (genArgs [i])); + } + sb.Append (">"); + return sb.ToString (); + } + + if (IsGenericParameter (t)) + return t.Name; + + if (t.DeclaringType != null) + return string.Concat (t.DeclaringType.FullName, "/", t.Name); + + if (t.Namespace == null || t.Namespace.Length == 0) + return t.Name; + + return string.Concat (t.Namespace, ".", t.Name); + } + + static bool GetProperty (object o, string prop) + { + SR.PropertyInfo pi = o.GetType ().GetProperty (prop); + if (pi == null) + return false; + + return (bool) pi.GetValue (o, null); + } + + public static bool IsGenericType (Type t) + { + return GetProperty (t, "IsGenericType"); + } + + static bool IsGenericParameter (Type t) + { + return GetProperty (t, "IsGenericParameter"); + } + + static bool IsGenericTypeDefinition (Type t) + { + return GetProperty (t, "IsGenericTypeDefinition"); + } + + static bool IsGenericTypeSpec (Type t) + { + return IsGenericType (t) && !IsGenericTypeDefinition (t); + } + + static Type GetGenericTypeDefinition (Type t) + { + return (Type) t.GetType ().GetMethod ("GetGenericTypeDefinition").Invoke (t, null); + } + + static Type [] GetGenericArguments (Type t) + { + return (Type []) t.GetType ().GetMethod ("GetGenericArguments").Invoke (t, null); + } + + GenericInstanceType GetGenericType (Type t, TypeReference element, ImportContext context) + { + GenericInstanceType git = new GenericInstanceType (element); + foreach (Type genArg in GetGenericArguments (t)) + git.GenericArguments.Add (ImportSystemType (genArg, context)); + + return git; + } + + static bool GenericParameterOfMethod (Type t) + { + return t.GetType ().GetProperty ("DeclaringMethod").GetValue (t, null) != null; + } + + static GenericParameter GetGenericParameter (Type t, ImportContext context) + { + int pos = (int) t.GetType ().GetProperty ("GenericParameterPosition").GetValue (t, null); + if (GenericParameterOfMethod (t)) + return context.GenericContext.Method.GenericParameters [pos]; + else + return context.GenericContext.Type.GenericParameters [pos]; + } + + TypeReference GetTypeSpec (Type t, ImportContext context) + { + Stack s = new Stack (); + while (t.HasElementType || IsGenericTypeSpec (t)) { + s.Push (t); + if (t.HasElementType) + t = t.GetElementType (); + else if (IsGenericTypeSpec (t)) { + t = (Type) t.GetType ().GetMethod ("GetGenericTypeDefinition").Invoke (t, null); + break; + } + } + + TypeReference elementType = ImportSystemType (t, context); + while (s.Count > 0) { + t = (Type) s.Pop (); + if (t.IsPointer) + elementType = new PointerType (elementType); + else if (t.IsArray) // deal with complex arrays + elementType = new ArrayType (elementType); + else if (t.IsByRef) + elementType = new ReferenceType (elementType); + else if (IsGenericTypeSpec (t)) + elementType = GetGenericType (t, elementType, context); + else + throw new ReflectionException ("Unknown element type"); + } + + return elementType; + } + + public TypeReference ImportSystemType (Type t, ImportContext context) + { + if (t.HasElementType || IsGenericTypeSpec (t)) + return GetTypeSpec (t, context); + + if (IsGenericParameter (t)) + return GetGenericParameter (t, context); + + TypeReference type = m_module.TypeReferences [GetTypeSignature (t)]; + if (type != null) { + if (t.IsValueType && !type.IsValueType) + type.IsValueType = true; + + return type; + } + + AssemblyNameReference asm = ImportAssembly (t.Assembly); + type = new TypeReference (t.Name, t.Namespace, asm, t.IsValueType); + + if (IsGenericTypeDefinition (t)) + foreach (Type genParam in GetGenericArguments (t)) + type.GenericParameters.Add (new GenericParameter (genParam.Name, type)); + + context.GenericContext.Type = type; + + m_module.TypeReferences.Add (type); + return type; + } + + static string GetMethodBaseSignature (SR.MethodBase meth, Type declaringType, Type retType) + { + StringBuilder sb = new StringBuilder (); + sb.Append (GetTypeSignature (retType)); + sb.Append (' '); + sb.Append (GetTypeSignature (declaringType)); + sb.Append ("::"); + sb.Append (meth.Name); + if (IsGenericMethodSpec (meth)) { + sb.Append ("<"); + Type [] genArgs = GetGenericArguments (meth as SR.MethodInfo); + for (int i = 0; i < genArgs.Length; i++) { + if (i > 0) + sb.Append (","); + sb.Append (GetTypeSignature (genArgs [i])); + } + sb.Append (">"); + } + sb.Append ("("); + SR.ParameterInfo [] parameters = meth.GetParameters (); + for (int i = 0; i < parameters.Length; i++) { + if (i > 0) + sb.Append (", "); + sb.Append (GetTypeSignature (parameters [i].ParameterType)); + } + sb.Append (")"); + return sb.ToString (); + } + + static bool IsGenericMethod (SR.MethodBase mb) + { + return GetProperty (mb, "IsGenericMethod"); + } + + static bool IsGenericMethodDefinition (SR.MethodBase mb) + { + return GetProperty (mb, "IsGenericMethodDefinition"); + } + + static bool IsGenericMethodSpec (SR.MethodBase mb) + { + return IsGenericMethod (mb) && !IsGenericMethodDefinition (mb); + } + + static Type [] GetGenericArguments (SR.MethodInfo mi) + { + return (Type []) mi.GetType ().GetMethod ("GetGenericArguments").Invoke (mi, null); + } + + static int GetMetadataToken (SR.MethodInfo mi) + { + return (int) mi.GetType ().GetProperty ("MetadataToken").GetValue (mi, null); + } + + MethodReference ImportGenericInstanceMethod (SR.MethodInfo mi, ImportContext context) + { + SR.MethodInfo gmd = (SR.MethodInfo) mi.GetType ().GetMethod ("GetGenericMethodDefinition").Invoke (mi, null); + GenericInstanceMethod gim = new GenericInstanceMethod ( + ImportMethodBase (gmd, gmd.ReturnType, context)); + + foreach (Type genArg in GetGenericArguments (mi)) + gim.GenericArguments.Add (ImportSystemType (genArg, context)); + + return gim; + } + + MethodReference ImportMethodBase (SR.MethodBase mb, Type retType, ImportContext context) + { + if (IsGenericMethod (mb) && !IsGenericMethodDefinition (mb)) + return ImportGenericInstanceMethod ((SR.MethodInfo) mb, context); + + Type originalDecType = mb.DeclaringType; + Type declaringTypeDef = originalDecType; + while (IsGenericTypeSpec (declaringTypeDef)) + declaringTypeDef = GetGenericTypeDefinition (declaringTypeDef); + + if (mb.DeclaringType != declaringTypeDef && mb is SR.MethodInfo) { + int mt = GetMetadataToken (mb as SR.MethodInfo); + // hack to get the generic method definition from the constructed method + foreach (SR.MethodInfo mi in declaringTypeDef.GetMethods ()) { + if (GetMetadataToken (mi) == mt) { + mb = mi; + retType = mi.ReturnType; + break; + } + } + } + + string sig = GetMethodBaseSignature (mb, originalDecType, retType); + MethodReference meth = (MethodReference) GetMemberReference (sig); + if (meth != null) + return meth; + + meth = new MethodReference ( + mb.Name, + (mb.CallingConvention & SR.CallingConventions.HasThis) > 0, + (mb.CallingConvention & SR.CallingConventions.ExplicitThis) > 0, + MethodCallingConvention.Default); // TODO: get the real callconv + meth.DeclaringType = ImportSystemType (originalDecType, context); + + if (IsGenericMethod (mb)) + foreach (Type genParam in GetGenericArguments (mb as SR.MethodInfo)) + meth.GenericParameters.Add (new GenericParameter (genParam.Name, meth)); + + context.GenericContext.Method = meth; + context.GenericContext.Type = ImportSystemType (declaringTypeDef, context); + + meth.ReturnType.ReturnType = ImportSystemType (retType, context); + + SR.ParameterInfo [] parameters = mb.GetParameters (); + for (int i = 0; i < parameters.Length; i++) + meth.Parameters.Add (new ParameterDefinition ( + ImportSystemType (parameters [i].ParameterType, context))); + + m_module.MemberReferences.Add (meth); + return meth; + } + + public MethodReference ImportConstructorInfo (SR.ConstructorInfo ci, ImportContext context) + { + return ImportMethodBase (ci, typeof (void), context); + } + + public MethodReference ImportMethodInfo (SR.MethodInfo mi, ImportContext context) + { + return ImportMethodBase (mi, mi.ReturnType, context); + } + + static string GetFieldSignature (SR.FieldInfo field) + { + StringBuilder sb = new StringBuilder (); + sb.Append (GetTypeSignature (field.FieldType)); + sb.Append (' '); + sb.Append (GetTypeSignature (field.DeclaringType)); + sb.Append ("::"); + sb.Append (field.Name); + return sb.ToString (); + } + + public FieldReference ImportFieldInfo (SR.FieldInfo fi, ImportContext context) + { + string sig = GetFieldSignature (fi); + FieldReference f = (FieldReference) GetMemberReference (sig); + if (f != null) + return f; + + f = new FieldReference ( + fi.Name, + ImportSystemType (fi.DeclaringType, context), + ImportSystemType (fi.FieldType, context)); + + m_module.MemberReferences.Add (f); + return f; + } + + MemberReference GetMemberReference (string signature) + { + foreach (MemberReference reference in m_module.MemberReferences) + if (reference.ToString () == signature) + return reference; + + return null; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionReader.cs new file mode 100644 index 0000000..a6296ab --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionReader.cs @@ -0,0 +1,1179 @@ +// +// ReflectionReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.IO; + using System.Text; + + using Mono.Cecil.Binary; + using Mono.Cecil.Cil; + using Mono.Cecil.Metadata; + using Mono.Cecil.Signatures; + + internal abstract class ReflectionReader : BaseReflectionReader { + + ModuleDefinition m_module; + ImageReader m_reader; + SecurityDeclarationReader m_secReader; + protected MetadataTableReader m_tableReader; + protected MetadataRoot m_root; + protected TablesHeap m_tHeap; + protected bool m_checkDeleted; + + protected TypeDefinition [] m_typeDefs; + protected TypeReference [] m_typeRefs; + protected TypeReference [] m_typeSpecs; + protected MethodDefinition [] m_meths; + protected FieldDefinition [] m_fields; + protected EventDefinition [] m_events; + protected PropertyDefinition [] m_properties; + protected MemberReference [] m_memberRefs; + protected ParameterDefinition [] m_parameters; + protected GenericParameter [] m_genericParameters; + protected GenericInstanceMethod [] m_methodSpecs; + + bool m_isCorlib; + AssemblyNameReference m_corlib; + + protected SignatureReader m_sigReader; + protected CodeReader m_codeReader; + protected ISymbolReader m_symbolReader; + + internal AssemblyNameReference Corlib { + get { + if (m_corlib != null) + return m_corlib; + + foreach (AssemblyNameReference ar in m_module.AssemblyReferences) { + if (ar.Name == Constants.Corlib) { + m_corlib = ar; + return m_corlib; + } + } + + return null; + } + } + + public ModuleDefinition Module { + get { return m_module; } + } + + public SignatureReader SigReader { + get { return m_sigReader; } + } + + public MetadataTableReader TableReader { + get { return m_tableReader; } + } + + public CodeReader Code { + get { return m_codeReader; } + } + + public ISymbolReader SymbolReader { + get { return m_symbolReader; } + set { m_symbolReader = value; } + } + + public MetadataRoot MetadataRoot { + get { return m_root; } + } + + public ReflectionReader (ModuleDefinition module) + { + m_module = module; + m_reader = m_module.ImageReader; + m_root = m_module.Image.MetadataRoot; + m_tHeap = m_root.Streams.TablesHeap; + m_checkDeleted = (m_tHeap.HeapSizes & 0x80) != 0; + if (m_reader != null) + m_tableReader = m_reader.MetadataReader.TableReader; + m_codeReader = new CodeReader (this); + m_sigReader = new SignatureReader (m_root, this); + m_isCorlib = module.Assembly.Name.Name == Constants.Corlib; + } + + public TypeDefinition GetTypeDefAt (uint rid) + { + return m_typeDefs [rid - 1]; + } + + public TypeReference GetTypeRefAt (uint rid) + { + return m_typeRefs [rid - 1]; + } + + public TypeReference GetTypeSpecAt (uint rid, GenericContext context) + { + int index = (int) rid - 1; + TypeReference tspec = m_typeSpecs [index]; + if (tspec != null) + return tspec; + + TypeSpecTable tsTable = m_tableReader.GetTypeSpecTable (); + TypeSpecRow tsRow = tsTable [index]; + TypeSpec ts = m_sigReader.GetTypeSpec (tsRow.Signature); + tspec = GetTypeRefFromSig (ts.Type, context); + tspec = GetModifierType (ts.CustomMods, tspec); + tspec.MetadataToken = MetadataToken.FromMetadataRow (TokenType.TypeSpec, index); + m_typeSpecs [index] = tspec; + + return tspec; + } + + public FieldDefinition GetFieldDefAt (uint rid) + { + return m_fields [rid - 1]; + } + + public MethodDefinition GetMethodDefAt (uint rid) + { + return m_meths [rid - 1]; + } + + protected bool IsDeleted (IMemberDefinition member) + { + if (!m_checkDeleted) + return false; + + if (!member.IsSpecialName || !member.IsRuntimeSpecialName) + return false; + + return member.Name.StartsWith (Constants.Deleted); + } + + public MemberReference GetMemberRefAt (uint rid, GenericContext context) + { + int index = (int) rid - 1; + MemberReference member = m_memberRefs [rid - 1]; + if (member != null) + return member; + + MemberRefTable mrTable = m_tableReader.GetMemberRefTable (); + MemberRefRow mrefRow = mrTable [index]; + + Signature sig = m_sigReader.GetMemberRefSig (mrefRow.Class.TokenType, mrefRow.Signature); + switch (mrefRow.Class.TokenType) { + case TokenType.TypeDef : + case TokenType.TypeRef : + case TokenType.TypeSpec : + TypeReference declaringType = GetTypeDefOrRef (mrefRow.Class, context); + GenericContext nc = context.Clone (); + + if (declaringType is GenericInstanceType) { + TypeReference ct = declaringType; + while (ct is GenericInstanceType) + ct = (ct as GenericInstanceType).ElementType; + + nc.Type = ct; + } + + if (sig is FieldSig) { + FieldSig fs = sig as FieldSig; + TypeReference fieldType = GetTypeRefFromSig (fs.Type, nc); + fieldType = GetModifierType (fs.CustomMods, fieldType); + + member = new FieldReference ( + m_root.Streams.StringsHeap [mrefRow.Name], + declaringType, + fieldType); + } else { + string name = m_root.Streams.StringsHeap [mrefRow.Name]; + MethodSig ms = (MethodSig) sig; + + member = CreateMethodReferenceFromSig (ms, name, declaringType, nc); + } + break; + case TokenType.Method : + // really not sure about this + MethodDefinition methdef = GetMethodDefAt (mrefRow.Class.RID); + + member = CreateMethodReferenceFromSig ((MethodSig) sig, methdef.Name, methdef.DeclaringType, new GenericContext ()); + break; + case TokenType.ModuleRef : + break; // TODO, implement that, or not + } + + member.MetadataToken = MetadataToken.FromMetadataRow (TokenType.MemberRef, index); + m_module.MemberReferences.Add (member); + m_memberRefs [index] = member; + + return member; + } + + MethodReference CreateMethodReferenceFromSig (MethodSig ms, string name, TypeReference declaringType, GenericContext context) + { + MethodReference methref = new MethodReference ( + name, ms.HasThis, ms.ExplicitThis, ms.MethCallConv); + methref.DeclaringType = declaringType; + + if (ms is MethodDefSig) { + int arity = (ms as MethodDefSig).GenericParameterCount; + for (int i = 0; i < arity; i++) + methref.GenericParameters.Add (new GenericParameter (i, methref)); + } + + if (methref.GenericParameters.Count > 0) + context.Method = methref; + + methref.ReturnType = GetMethodReturnType (ms, context); + + methref.ReturnType.Method = methref; + for (int j = 0; j < ms.ParamCount; j++) { + Param p = ms.Parameters [j]; + ParameterDefinition pdef = BuildParameterDefinition (j, p, context); + pdef.Method = methref; + methref.Parameters.Add (pdef); + } + + CreateSentinelIfNeeded (methref, ms); + + return methref; + } + + public static void CreateSentinelIfNeeded (IMethodSignature meth, MethodSig signature) + { + MethodDefSig sig = signature as MethodDefSig; + if (sig == null) + return; + + int sentinel = sig.Sentinel; + + if (sig.Sentinel < 0 || sig.Sentinel >= meth.Parameters.Count) + return; + + ParameterDefinition param = meth.Parameters [sentinel]; + param.ParameterType = new SentinelType (param.ParameterType); + } + + public PropertyDefinition GetPropertyDefAt (uint rid) + { + return m_properties [rid - 1]; + } + + public EventDefinition GetEventDefAt (uint rid) + { + return m_events [rid - 1]; + } + + public ParameterDefinition GetParamDefAt (uint rid) + { + return m_parameters [rid - 1]; + } + + public GenericParameter GetGenericParameterAt (uint rid) + { + return m_genericParameters [rid - 1]; + } + + public GenericInstanceMethod GetMethodSpecAt (uint rid, GenericContext context) + { + int index = (int) rid - 1; + GenericInstanceMethod gim = m_methodSpecs [index]; + if (gim != null) + return gim; + + MethodSpecTable msTable = m_tableReader.GetMethodSpecTable (); + MethodSpecRow msRow = msTable [index]; + + MethodSpec sig = m_sigReader.GetMethodSpec (msRow.Instantiation); + + MethodReference meth; + if (msRow.Method.TokenType == TokenType.Method) + meth = GetMethodDefAt (msRow.Method.RID); + else if (msRow.Method.TokenType == TokenType.MemberRef) + meth = (MethodReference) GetMemberRefAt (msRow.Method.RID, context); + else + throw new ReflectionException ("Unknown method type for method spec"); + + gim = new GenericInstanceMethod (meth); + context.CheckProvider (meth, sig.Signature.Arity); + foreach (GenericArg arg in sig.Signature.Types) + gim.GenericArguments.Add (GetGenericArg (arg, context)); + + m_methodSpecs [index] = gim; + + return gim; + } + + public TypeReference GetTypeDefOrRef (MetadataToken token, GenericContext context) + { + if (token.RID == 0) + return null; + + switch (token.TokenType) { + case TokenType.TypeDef : + return GetTypeDefAt (token.RID); + case TokenType.TypeRef : + return GetTypeRefAt (token.RID); + case TokenType.TypeSpec : + return GetTypeSpecAt (token.RID, context); + default : + return null; + } + } + + public TypeReference SearchCoreType (string fullName) + { + if (m_isCorlib) + return m_module.Types [fullName]; + + TypeReference coreType = m_module.TypeReferences [fullName]; + if (coreType == null) { + string [] parts = fullName.Split ('.'); + if (parts.Length != 2) + throw new ReflectionException ("Unvalid core type name"); + coreType = new TypeReference (parts [1], parts [0], Corlib); + m_module.TypeReferences.Add (coreType); + } + if (!coreType.IsValueType) { + switch (coreType.FullName) { + case Constants.Boolean : + case Constants.Char : + case Constants.Single : + case Constants.Double : + case Constants.SByte : + case Constants.Byte : + case Constants.Int16 : + case Constants.UInt16 : + case Constants.Int32 : + case Constants.UInt32 : + case Constants.Int64 : + case Constants.UInt64 : + case Constants.IntPtr : + case Constants.UIntPtr : + coreType.IsValueType = true; + break; + } + } + return coreType; + } + + public IMetadataTokenProvider LookupByToken (MetadataToken token) + { + switch (token.TokenType) { + case TokenType.TypeDef : + return GetTypeDefAt (token.RID); + case TokenType.TypeRef : + return GetTypeRefAt (token.RID); + case TokenType.Method : + return GetMethodDefAt (token.RID); + case TokenType.Field : + return GetFieldDefAt (token.RID); + case TokenType.Event : + return GetEventDefAt (token.RID); + case TokenType.Property : + return GetPropertyDefAt (token.RID); + case TokenType.Param : + return GetParamDefAt (token.RID); + default : + throw new NotSupportedException ("Lookup is not allowed on this kind of token"); + } + } + + public CustomAttribute GetCustomAttribute (MethodReference ctor, byte [] data, bool resolve) + { + CustomAttrib sig = m_sigReader.GetCustomAttrib (data, ctor, resolve); + return BuildCustomAttribute (ctor, sig); + } + + public CustomAttribute GetCustomAttribute (MethodReference ctor, byte [] data) + { + return GetCustomAttribute (ctor, data, false); + } + + public override void VisitModuleDefinition (ModuleDefinition mod) + { + VisitTypeDefinitionCollection (mod.Types); + } + + public override void VisitTypeDefinitionCollection (TypeDefinitionCollection types) + { + // type def reading + TypeDefTable typesTable = m_tableReader.GetTypeDefTable (); + m_typeDefs = new TypeDefinition [typesTable.Rows.Count]; + for (int i = 0; i < typesTable.Rows.Count; i++) { + TypeDefRow type = typesTable [i]; + TypeDefinition t = new TypeDefinition ( + m_root.Streams.StringsHeap [type.Name], + m_root.Streams.StringsHeap [type.Namespace], + type.Flags); + t.MetadataToken = MetadataToken.FromMetadataRow (TokenType.TypeDef, i); + + m_typeDefs [i] = t; + } + + // nested types + if (m_tHeap.HasTable (NestedClassTable.RId)) { + NestedClassTable nested = m_tableReader.GetNestedClassTable (); + for (int i = 0; i < nested.Rows.Count; i++) { + NestedClassRow row = nested [i]; + + TypeDefinition parent = GetTypeDefAt (row.EnclosingClass); + TypeDefinition child = GetTypeDefAt (row.NestedClass); + + if (!IsDeleted (child)) + parent.NestedTypes.Add (child); + } + } + + foreach (TypeDefinition type in m_typeDefs) + if (!IsDeleted (type)) + types.Add (type); + + // type ref reading + if (m_tHeap.HasTable (TypeRefTable.RId)) { + TypeRefTable typesRef = m_tableReader.GetTypeRefTable (); + + m_typeRefs = new TypeReference [typesRef.Rows.Count]; + + for (int i = 0; i < typesRef.Rows.Count; i++) + AddTypeRef (typesRef, i); + } else + m_typeRefs = new TypeReference [0]; + + ReadTypeSpecs (); + ReadMethodSpecs (); + + ReadMethods (); + ReadGenericParameters (); + + // set base types + for (int i = 0; i < typesTable.Rows.Count; i++) { + TypeDefRow type = typesTable [i]; + TypeDefinition child = m_typeDefs [i]; + child.BaseType = GetTypeDefOrRef (type.Extends, new GenericContext (child)); + } + + CompleteMethods (); + ReadAllFields (); + ReadMemberReferences (); + } + + void AddTypeRef (TypeRefTable typesRef, int i) + { + // Check if index has been already added. + if (m_typeRefs [i] != null) + return; + + TypeRefRow type = typesRef [i]; + IMetadataScope scope = null; + TypeReference parent = null; + + if (type.ResolutionScope.RID != 0) { + int rid = (int) type.ResolutionScope.RID - 1; + switch (type.ResolutionScope.TokenType) { + case TokenType.AssemblyRef: + scope = m_module.AssemblyReferences [rid]; + break; + case TokenType.ModuleRef: + scope = m_module.ModuleReferences [rid]; + break; + case TokenType.Module: + scope = m_module.Assembly.Modules [rid]; + break; + case TokenType.TypeRef: + AddTypeRef (typesRef, rid); + parent = GetTypeRefAt (type.ResolutionScope.RID); + scope = parent.Scope; + break; + } + } + + TypeReference t = new TypeReference ( + m_root.Streams.StringsHeap [type.Name], + m_root.Streams.StringsHeap [type.Namespace], + scope); + t.MetadataToken = MetadataToken.FromMetadataRow (TokenType.TypeRef, i); + + if (parent != null) + t.DeclaringType = parent; + + m_typeRefs [i] = t; + m_module.TypeReferences.Add (t); + } + + void ReadTypeSpecs () + { + if (!m_tHeap.HasTable (TypeSpecTable.RId)) + return; + + TypeSpecTable tsTable = m_tableReader.GetTypeSpecTable (); + m_typeSpecs = new TypeReference [tsTable.Rows.Count]; + } + + void ReadMethodSpecs () + { + if (!m_tHeap.HasTable (MethodSpecTable.RId)) + return; + + MethodSpecTable msTable = m_tableReader.GetMethodSpecTable (); + m_methodSpecs = new GenericInstanceMethod [msTable.Rows.Count]; + } + + void ReadGenericParameters () + { + if (!m_tHeap.HasTable (GenericParamTable.RId)) + return; + + GenericParamTable gpTable = m_tableReader.GetGenericParamTable (); + m_genericParameters = new GenericParameter [gpTable.Rows.Count]; + for (int i = 0; i < gpTable.Rows.Count; i++) { + GenericParamRow gpRow = gpTable [i]; + IGenericParameterProvider owner; + if (gpRow.Owner.TokenType == TokenType.Method) + owner = GetMethodDefAt (gpRow.Owner.RID); + else if (gpRow.Owner.TokenType == TokenType.TypeDef) + owner = GetTypeDefAt (gpRow.Owner.RID); + else + throw new ReflectionException ("Unknown owner type for generic parameter"); + + GenericParameter gp = new GenericParameter (gpRow.Number, owner); + gp.Attributes = gpRow.Flags; + gp.Name = MetadataRoot.Streams.StringsHeap [gpRow.Name]; + gp.MetadataToken = MetadataToken.FromMetadataRow (TokenType.GenericParam, i); + + owner.GenericParameters.Add (gp); + m_genericParameters [i] = gp; + } + } + + void ReadAllFields () + { + TypeDefTable tdefTable = m_tableReader.GetTypeDefTable (); + + if (!m_tHeap.HasTable (FieldTable.RId)) { + m_fields = new FieldDefinition [0]; + return; + } + + FieldTable fldTable = m_tableReader.GetFieldTable (); + m_fields = new FieldDefinition [fldTable.Rows.Count]; + + for (int i = 0; i < m_typeDefs.Length; i++) { + TypeDefinition dec = m_typeDefs [i]; + GenericContext context = new GenericContext (dec); + + int index = i, next; + + if (index == tdefTable.Rows.Count - 1) + next = fldTable.Rows.Count + 1; + else + next = (int) (tdefTable [index + 1]).FieldList; + + for (int j = (int) tdefTable [index].FieldList; j < next; j++) { + FieldRow frow = fldTable [j - 1]; + FieldSig fsig = m_sigReader.GetFieldSig (frow.Signature); + + FieldDefinition fdef = new FieldDefinition ( + m_root.Streams.StringsHeap [frow.Name], + GetTypeRefFromSig (fsig.Type, context), frow.Flags); + fdef.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Field, j - 1); + + if (fsig.CustomMods.Length > 0) + fdef.FieldType = GetModifierType (fsig.CustomMods, fdef.FieldType); + + if (!IsDeleted (fdef)) + dec.Fields.Add (fdef); + + m_fields [j - 1] = fdef; + } + } + } + + void ReadMethods () + { + if (!m_tHeap.HasTable (MethodTable.RId)) { + m_meths = new MethodDefinition [0]; + return; + } + + MethodTable mTable = m_tableReader.GetMethodTable (); + m_meths = new MethodDefinition [mTable.Rows.Count]; + for (int i = 0; i < mTable.Rows.Count; i++) { + MethodRow mRow = mTable [i]; + MethodDefinition meth = new MethodDefinition ( + m_root.Streams.StringsHeap [mRow.Name], + mRow.Flags); + meth.RVA = mRow.RVA; + meth.ImplAttributes = mRow.ImplFlags; + + meth.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Method, i); + + m_meths [i] = meth; + } + } + + void CompleteMethods () + { + TypeDefTable tdefTable = m_tableReader.GetTypeDefTable (); + + if (!m_tHeap.HasTable (MethodTable.RId)) { + m_meths = new MethodDefinition [0]; + return; + } + + MethodTable methTable = m_tableReader.GetMethodTable (); + ParamTable paramTable = m_tableReader.GetParamTable (); + if (!m_tHeap.HasTable (ParamTable.RId)) + m_parameters = new ParameterDefinition [0]; + else + m_parameters = new ParameterDefinition [paramTable.Rows.Count]; + + for (int i = 0; i < m_typeDefs.Length; i++) { + TypeDefinition dec = m_typeDefs [i]; + + int index = i, next; + + if (index == tdefTable.Rows.Count - 1) + next = methTable.Rows.Count + 1; + else + next = (int) (tdefTable [index + 1]).MethodList; + + for (int j = (int) tdefTable [index].MethodList; j < next; j++) { + MethodRow methRow = methTable [j - 1]; + MethodDefinition mdef = m_meths [j - 1]; + + if (!IsDeleted (mdef)) { + if (mdef.IsConstructor) + dec.Constructors.Add (mdef); + else + dec.Methods.Add (mdef); + } + + GenericContext context = new GenericContext (mdef); + + MethodDefSig msig = m_sigReader.GetMethodDefSig (methRow.Signature); + mdef.HasThis = msig.HasThis; + mdef.ExplicitThis = msig.ExplicitThis; + mdef.CallingConvention = msig.MethCallConv; + + int prms; + if (j == methTable.Rows.Count) + prms = m_parameters.Length + 1; + else + prms = (int) (methTable [j]).ParamList; + + ParameterDefinition retparam = null; + + //TODO: optimize this + int start = (int) methRow.ParamList - 1; + + if (paramTable != null && start < prms - 1) { + + ParamRow pRetRow = paramTable [start]; + + if (pRetRow != null && pRetRow.Sequence == 0) { // ret type + + retparam = new ParameterDefinition ( + m_root.Streams.StringsHeap [pRetRow.Name], + 0, + pRetRow.Flags, + null); + + retparam.Method = mdef; + m_parameters [start] = retparam; + start++; + } + } + + for (int k = 0; k < msig.ParamCount; k++) { + + int pointer = start + k; + + ParamRow pRow = null; + + if (paramTable != null && pointer < prms - 1) + pRow = paramTable [pointer]; + + Param psig = msig.Parameters [k]; + + ParameterDefinition pdef; + if (pRow != null) { + pdef = BuildParameterDefinition ( + m_root.Streams.StringsHeap [pRow.Name], + pRow.Sequence, pRow.Flags, psig, context); + pdef.MetadataToken = MetadataToken.FromMetadataRow (TokenType.Param, pointer); + m_parameters [pointer] = pdef; + } else + pdef = BuildParameterDefinition (k + 1, psig, context); + + pdef.Method = mdef; + mdef.Parameters.Add (pdef); + } + + mdef.ReturnType = GetMethodReturnType (msig, context); + MethodReturnType mrt = mdef.ReturnType; + mrt.Method = mdef; + if (retparam != null) { + mrt.Parameter = retparam; + mrt.Parameter.ParameterType = mrt.ReturnType; + } + } + } + + uint eprid = CodeReader.GetRid ((int) m_reader.Image.CLIHeader.EntryPointToken); + if (eprid > 0 && eprid <= m_meths.Length) + m_module.Assembly.EntryPoint = GetMethodDefAt (eprid); + } + + void ReadMemberReferences () + { + if (!m_tHeap.HasTable (MemberRefTable.RId)) + return; + + MemberRefTable mrefTable = m_tableReader.GetMemberRefTable (); + m_memberRefs = new MemberReference [mrefTable.Rows.Count]; + } + + public override void VisitExternTypeCollection (ExternTypeCollection externs) + { + ExternTypeCollection ext = externs; + + if (!m_tHeap.HasTable (ExportedTypeTable.RId)) + return; + + ExportedTypeTable etTable = m_tableReader.GetExportedTypeTable (); + TypeReference [] buffer = new TypeReference [etTable.Rows.Count]; + + for (int i = 0; i < etTable.Rows.Count; i++) { + ExportedTypeRow etRow = etTable [i]; + if (etRow.Implementation.TokenType != TokenType.File) + continue; + + string name = m_root.Streams.StringsHeap [etRow.TypeName]; + string ns = m_root.Streams.StringsHeap [etRow.TypeNamespace]; + if (ns.Length == 0) + buffer [i] = m_module.TypeReferences [name]; + else + buffer [i] = m_module.TypeReferences [string.Concat (ns, '.', name)]; + } + + for (int i = 0; i < etTable.Rows.Count; i++) { + ExportedTypeRow etRow = etTable [i]; + if (etRow.Implementation.TokenType != TokenType.ExportedType) + continue; + + TypeReference owner = buffer [etRow.Implementation.RID - 1]; + string name = m_root.Streams.StringsHeap [etRow.TypeName]; + buffer [i] = m_module.TypeReferences [string.Concat (owner.FullName, '/', name)]; + } + + for (int i = 0; i < buffer.Length; i++) { + TypeReference curs = buffer [i]; + if (curs != null) + ext.Add (curs); + } + } + + static object GetFixedArgValue (CustomAttrib.FixedArg fa) + { + if (fa.SzArray) { + object [] vals = new object [fa.NumElem]; + for (int j = 0; j < vals.Length; j++) + vals [j] = fa.Elems [j].Value; + return vals; + } else + return fa.Elems [0].Value; + } + + TypeReference GetFixedArgType (CustomAttrib.FixedArg fa) + { + if (fa.SzArray) { + if (fa.NumElem == 0) + return new ArrayType (SearchCoreType (Constants.Object)); + else + return new ArrayType (fa.Elems [0].ElemType); + } else + return fa.Elems [0].ElemType; + } + + TypeReference GetNamedArgType (CustomAttrib.NamedArg na) + { + if (na.FieldOrPropType == ElementType.Boxed) + return SearchCoreType (Constants.Object); + + return GetFixedArgType (na.FixedArg); + } + + protected CustomAttribute BuildCustomAttribute (MethodReference ctor, CustomAttrib sig) + { + CustomAttribute cattr = new CustomAttribute (ctor); + + foreach (CustomAttrib.FixedArg fa in sig.FixedArgs) + cattr.ConstructorParameters.Add (GetFixedArgValue (fa)); + + foreach (CustomAttrib.NamedArg na in sig.NamedArgs) { + object value = GetFixedArgValue (na.FixedArg); + if (na.Field) { + cattr.Fields [na.FieldOrPropName] = value; + cattr.SetFieldType (na.FieldOrPropName, GetNamedArgType (na)); + } else if (na.Property) { + cattr.Properties [na.FieldOrPropName] = value; + cattr.SetPropertyType (na.FieldOrPropName, GetNamedArgType (na)); + } else + throw new ReflectionException ("Non valid named arg"); + } + + return cattr; + } + + void CompleteParameter (ParameterDefinition parameter, Param signature, GenericContext context) + { + TypeReference paramType; + + if (signature.ByRef) + paramType = new ReferenceType (GetTypeRefFromSig (signature.Type, context)); + else if (signature.TypedByRef) + paramType = SearchCoreType (Constants.TypedReference); + else + paramType = GetTypeRefFromSig (signature.Type, context); + + paramType = GetModifierType (signature.CustomMods, paramType); + + parameter.ParameterType = paramType; + } + + public ParameterDefinition BuildParameterDefinition (int sequence, Param psig, GenericContext context) + { + ParameterDefinition parameter = new ParameterDefinition (null); + parameter.Sequence = sequence; + + CompleteParameter (parameter, psig, context); + + return parameter; + } + + public ParameterDefinition BuildParameterDefinition (string name, int sequence, ParameterAttributes attrs, Param psig, GenericContext context) + { + ParameterDefinition parameter = new ParameterDefinition (name, sequence, attrs, null); + + CompleteParameter (parameter, psig, context); + + return parameter; + } + + protected SecurityDeclaration BuildSecurityDeclaration (DeclSecurityRow dsRow) + { + return BuildSecurityDeclaration (dsRow.Action, m_root.Streams.BlobHeap.Read (dsRow.PermissionSet)); + } + + public SecurityDeclaration BuildSecurityDeclaration (SecurityAction action, byte [] permset) + { + if (m_secReader == null) + m_secReader = new SecurityDeclarationReader (m_root, this); + + return m_secReader.FromByteArray (action, permset); + } + + protected MarshalSpec BuildMarshalDesc (MarshalSig ms, IHasMarshalSpec container) + { + if (ms.Spec is MarshalSig.Array) { + ArrayMarshalSpec amd = new ArrayMarshalSpec (container); + MarshalSig.Array ar = (MarshalSig.Array) ms.Spec; + amd.ElemType = ar.ArrayElemType; + amd.NumElem = ar.NumElem; + amd.ParamNum = ar.ParamNum; + amd.ElemMult = ar.ElemMult; + return amd; + } else if (ms.Spec is MarshalSig.CustomMarshaler) { + CustomMarshalerSpec cmd = new CustomMarshalerSpec (container); + MarshalSig.CustomMarshaler cmsig = (MarshalSig.CustomMarshaler) ms.Spec; + cmd.Guid = cmsig.Guid.Length > 0 ? new Guid (cmsig.Guid) : new Guid (); + cmd.UnmanagedType = cmsig.UnmanagedType; + cmd.ManagedType = cmsig.ManagedType; + cmd.Cookie = cmsig.Cookie; + return cmd; + } else if (ms.Spec is MarshalSig.FixedArray) { + FixedArraySpec fad = new FixedArraySpec (container); + MarshalSig.FixedArray fasig = (MarshalSig.FixedArray) ms.Spec; + fad.ElemType = fasig.ArrayElemType; + fad.NumElem = fasig.NumElem; + return fad; + } else if (ms.Spec is MarshalSig.FixedSysString) { + FixedSysStringSpec fssc = new FixedSysStringSpec (container); + fssc.Size = ((MarshalSig.FixedSysString) ms.Spec).Size; + return fssc; + } else if (ms.Spec is MarshalSig.SafeArray) { + SafeArraySpec sad = new SafeArraySpec (container); + sad.ElemType = ((MarshalSig.SafeArray) ms.Spec).ArrayElemType; + return sad; + } else { + return new MarshalSpec (ms.NativeInstrinsic, container); + } + } + + public TypeReference GetModifierType (CustomMod [] cmods, TypeReference type) + { + if (cmods == null || cmods.Length == 0) + return type; + + TypeReference ret = type; + for (int i = cmods.Length - 1; i >= 0; i--) { + CustomMod cmod = cmods [i]; + TypeReference modType; + + if (cmod.TypeDefOrRef.TokenType == TokenType.TypeDef) + modType = GetTypeDefAt (cmod.TypeDefOrRef.RID); + else + modType = GetTypeRefAt (cmod.TypeDefOrRef.RID); + + if (cmod.CMOD == CustomMod.CMODType.OPT) + ret = new ModifierOptional (ret, modType); + else if (cmod.CMOD == CustomMod.CMODType.REQD) + ret = new ModifierRequired (ret, modType); + } + return ret; + } + + public MethodReturnType GetMethodReturnType (MethodSig msig, GenericContext context) + { + TypeReference retType; + if (msig.RetType.Void) + retType = SearchCoreType (Constants.Void); + else if (msig.RetType.ByRef) + retType = new ReferenceType (GetTypeRefFromSig (msig.RetType.Type, context)); + else if (msig.RetType.TypedByRef) + retType = SearchCoreType (Constants.TypedReference); + else + retType = GetTypeRefFromSig (msig.RetType.Type, context); + + retType = GetModifierType (msig.RetType.CustomMods, retType); + + return new MethodReturnType (retType); + } + + public TypeReference GetTypeRefFromSig (SigType t, GenericContext context) + { + switch (t.ElementType) { + case ElementType.Class : + CLASS c = t as CLASS; + return GetTypeDefOrRef (c.Type, context); + case ElementType.ValueType : + VALUETYPE vt = t as VALUETYPE; + TypeReference vtr = GetTypeDefOrRef (vt.Type, context); + vtr.IsValueType = true; + return vtr; + case ElementType.String : + return SearchCoreType (Constants.String); + case ElementType.Object : + return SearchCoreType (Constants.Object); + case ElementType.Void : + return SearchCoreType (Constants.Void); + case ElementType.Boolean : + return SearchCoreType (Constants.Boolean); + case ElementType.Char : + return SearchCoreType (Constants.Char); + case ElementType.I1 : + return SearchCoreType (Constants.SByte); + case ElementType.U1 : + return SearchCoreType (Constants.Byte); + case ElementType.I2 : + return SearchCoreType (Constants.Int16); + case ElementType.U2 : + return SearchCoreType (Constants.UInt16); + case ElementType.I4 : + return SearchCoreType (Constants.Int32); + case ElementType.U4 : + return SearchCoreType (Constants.UInt32); + case ElementType.I8 : + return SearchCoreType (Constants.Int64); + case ElementType.U8 : + return SearchCoreType (Constants.UInt64); + case ElementType.R4 : + return SearchCoreType (Constants.Single); + case ElementType.R8 : + return SearchCoreType (Constants.Double); + case ElementType.I : + return SearchCoreType (Constants.IntPtr); + case ElementType.U : + return SearchCoreType (Constants.UIntPtr); + case ElementType.TypedByRef : + return SearchCoreType (Constants.TypedReference); + case ElementType.Array : + ARRAY ary = t as ARRAY; + return new ArrayType (GetTypeRefFromSig (ary.Type, context), ary.Shape); + case ElementType.SzArray : + SZARRAY szary = t as SZARRAY; + ArrayType at = new ArrayType (GetTypeRefFromSig (szary.Type, context)); + return at; + case ElementType.Ptr : + PTR pointer = t as PTR; + if (pointer.Void) + return new PointerType (SearchCoreType (Constants.Void)); + return new PointerType (GetTypeRefFromSig (pointer.PtrType, context)); + case ElementType.FnPtr : + FNPTR funcptr = t as FNPTR; + FunctionPointerType fnptr = new FunctionPointerType (funcptr.Method.HasThis, funcptr.Method.ExplicitThis, + funcptr.Method.MethCallConv, GetMethodReturnType (funcptr.Method, context)); + + for (int i = 0; i < funcptr.Method.ParamCount; i++) { + Param p = funcptr.Method.Parameters [i]; + fnptr.Parameters.Add (BuildParameterDefinition (i, p, context)); + } + + CreateSentinelIfNeeded (fnptr, funcptr.Method); + + return fnptr; + case ElementType.Var: + VAR var = t as VAR; + context.CheckProvider (context.Type, var.Index + 1); + + if (context.Type is GenericInstanceType) + return (context.Type as GenericInstanceType).GenericArguments [var.Index]; + else + return context.Type.GenericParameters [var.Index]; + case ElementType.MVar: + MVAR mvar = t as MVAR; + context.CheckProvider (context.Method, mvar.Index + 1); + + if (context.Method is GenericInstanceMethod) + return (context.Method as GenericInstanceMethod).GenericArguments [mvar.Index]; + else + return context.Method.GenericParameters [mvar.Index]; + case ElementType.GenericInst: + GENERICINST ginst = t as GENERICINST; + GenericInstanceType instance = new GenericInstanceType (GetTypeDefOrRef (ginst.Type, context)); + instance.IsValueType = ginst.ValueType; + context.CheckProvider (instance.GetOriginalType (), ginst.Signature.Arity); + + for (int i = 0; i < ginst.Signature.Arity; i++) + instance.GenericArguments.Add (GetGenericArg ( + ginst.Signature.Types [i], context)); + + return instance; + default: + break; + } + return null; + } + + TypeReference GetGenericArg (GenericArg arg, GenericContext context) + { + TypeReference type = GetTypeRefFromSig (arg.Type, context); + type = GetModifierType (arg.CustomMods, type); + return type; + } + + static bool IsOdd (int i) + { + return (i & 1) == 1; + } + + protected object GetConstant (uint pos, ElementType elemType) + { + if (elemType == ElementType.Class) + return null; + + byte [] constant = m_root.Streams.BlobHeap.Read (pos); + + if (elemType == ElementType.String) { + int length = constant.Length; + if (IsOdd (length)) + length--; + + return Encoding.Unicode.GetString (constant, 0, length); + } + + BinaryReader br = new BinaryReader (new MemoryStream (constant)); + + switch (elemType) { + case ElementType.Boolean : + return br.ReadByte () == 1; + case ElementType.Char : + return (char) br.ReadUInt16 (); + case ElementType.I1 : + return br.ReadSByte (); + case ElementType.I2 : + return br.ReadInt16 (); + case ElementType.I4 : + return br.ReadInt32 (); + case ElementType.I8 : + return br.ReadInt64 (); + case ElementType.U1 : + return br.ReadByte (); + case ElementType.U2 : + return br.ReadUInt16 (); + case ElementType.U4 : + return br.ReadUInt32 (); + case ElementType.U8 : + return br.ReadUInt64 (); + case ElementType.R4 : + return br.ReadSingle (); + case ElementType.R8 : + return br.ReadDouble (); + default : + throw new ReflectionException ("Non valid element in constant table"); + } + } + + protected void SetInitialValue (FieldDefinition field) + { + int size = 0; + TypeReference fieldType = field.FieldType; + switch (fieldType.FullName) { + case Constants.Byte: + case Constants.SByte: + size = 1; + break; + case Constants.Int16: + case Constants.UInt16: + case Constants.Char: + size = 2; + break; + case Constants.Int32: + case Constants.UInt32: + case Constants.Single: + size = 4; + break; + case Constants.Int64: + case Constants.UInt64: + case Constants.Double: + size = 8; + break; + default: + fieldType = fieldType.GetOriginalType (); + + TypeDefinition fieldTypeDef = fieldType as TypeDefinition; + + if (fieldTypeDef != null) + size = (int) fieldTypeDef.ClassSize; + break; + } + + if (size > 0 && field.RVA != RVA.Zero) { + BinaryReader br = m_reader.MetadataReader.GetDataReader (field.RVA); + field.InitialValue = br == null ? new byte [size] : br.ReadBytes (size); + } else + field.InitialValue = new byte [0]; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionWriter.cs new file mode 100644 index 0000000..01cab15 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ReflectionWriter.cs @@ -0,0 +1,1522 @@ +// +// ReflectionWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 - 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + using System.Globalization; + using System.Text; + + using Mono.Cecil.Binary; + using Mono.Cecil.Cil; + using Mono.Cecil.Metadata; + using Mono.Cecil.Signatures; + + internal sealed class ReflectionWriter : BaseReflectionVisitor { + + StructureWriter m_structureWriter; + ModuleDefinition m_mod; + SignatureWriter m_sigWriter; + CodeWriter m_codeWriter; + MetadataWriter m_mdWriter; + MetadataTableWriter m_tableWriter; + MetadataRowWriter m_rowWriter; + + bool m_saveSymbols; + string m_asmOutput; + ISymbolWriter m_symbolWriter; + + ArrayList m_typeDefStack; + ArrayList m_methodStack; + ArrayList m_fieldStack; + ArrayList m_genericParamStack; + IDictionary m_typeSpecTokenCache; + IDictionary m_memberRefTokenCache; + + uint m_methodIndex; + uint m_fieldIndex; + uint m_paramIndex; + uint m_eventIndex; + uint m_propertyIndex; + + MemoryBinaryWriter m_constWriter; + + public StructureWriter StructureWriter { + get { return m_structureWriter; } + set { + m_structureWriter = value; + + Initialize (); + } + } + + public CodeWriter CodeWriter { + get { return m_codeWriter; } + } + + public bool SaveSymbols { + get { return m_saveSymbols; } + set { m_saveSymbols = value; } + } + + public string OutputFile + { + get { return m_asmOutput; } + set { m_asmOutput = value; } + } + + public ISymbolWriter SymbolWriter { + get { return m_symbolWriter; } + set { m_symbolWriter = value; } + } + + public SignatureWriter SignatureWriter { + get { return m_sigWriter; } + } + + public MetadataWriter MetadataWriter { + get { return m_mdWriter; } + } + + public MetadataTableWriter MetadataTableWriter { + get { return m_tableWriter; } + } + + public MetadataRowWriter MetadataRowWriter { + get { return m_rowWriter; } + } + + public ReflectionWriter (ModuleDefinition mod) + { + m_mod = mod; + } + + void Initialize () + { + m_mdWriter = new MetadataWriter ( + m_mod.Assembly, + m_mod.Image.MetadataRoot, + m_structureWriter.Assembly.Kind, + m_mod.Assembly.Runtime, + m_structureWriter.GetWriter ()); + m_tableWriter = m_mdWriter.GetTableVisitor (); + m_rowWriter = m_tableWriter.GetRowVisitor () as MetadataRowWriter; + m_sigWriter = new SignatureWriter (m_mdWriter); + m_codeWriter = new CodeWriter (this, m_mdWriter.CilWriter); + + m_typeDefStack = new ArrayList (); + m_methodStack = new ArrayList (); + m_fieldStack = new ArrayList (); + m_genericParamStack = new ArrayList (); + m_typeSpecTokenCache = new Hashtable (); + m_memberRefTokenCache = new Hashtable (); + + m_methodIndex = 1; + m_fieldIndex = 1; + m_paramIndex = 1; + m_eventIndex = 1; + m_propertyIndex = 1; + + m_constWriter = new MemoryBinaryWriter (); + } + + public TypeReference GetCoreType (string name) + { + return m_mod.Controller.Reader.SearchCoreType (name); + } + + public static uint GetRidFor (IMetadataTokenProvider tp) + { + return tp.MetadataToken.RID; + } + + public uint GetRidFor (AssemblyNameReference asmName) + { + return (uint) m_mod.AssemblyReferences.IndexOf (asmName) + 1; + } + + public uint GetRidFor (ModuleDefinition mod) + { + return (uint) m_mod.Assembly.Modules.IndexOf (mod) + 1; + } + + public uint GetRidFor (ModuleReference modRef) + { + return (uint) m_mod.ModuleReferences.IndexOf (modRef) + 1; + } + + static bool IsTypeSpec (TypeReference type) + { + return type is TypeSpecification || type is GenericParameter; + } + + public MetadataToken GetTypeDefOrRefToken (TypeReference type) + { + if (IsTypeSpec (type)) { + uint sig = m_sigWriter.AddTypeSpec (GetTypeSpecSig (type)); + if (m_typeSpecTokenCache.Contains (sig)) + return (MetadataToken) m_typeSpecTokenCache [sig]; + + TypeSpecTable tsTable = m_tableWriter.GetTypeSpecTable (); + TypeSpecRow tsRow = m_rowWriter.CreateTypeSpecRow (sig); + tsTable.Rows.Add (tsRow); + + MetadataToken token = new MetadataToken (TokenType.TypeSpec, (uint) tsTable.Rows.Count); + if (! (type is GenericParameter)) + type.MetadataToken = token; + + m_typeSpecTokenCache [sig] = token; + return token; + } else if (type != null) + return type.MetadataToken; + else // <Module> and interfaces + return new MetadataToken (TokenType.TypeRef, 0); + } + + public MetadataToken GetMemberRefToken (MemberReference member) + { + if (member is MethodSpecification) + return GetMemberRefToken (((MethodSpecification) member).ElementMethod); + if (member is IMemberDefinition) + return member.MetadataToken; + if (m_memberRefTokenCache.Contains (member)) + return (MetadataToken) m_memberRefTokenCache [member]; + + MemberRefTable mrTable = m_tableWriter.GetMemberRefTable (); + + uint sig = 0; + if (member is FieldReference) + sig = m_sigWriter.AddFieldSig (GetFieldSig ((FieldReference) member)); + else if (member is MethodReference) + sig = m_sigWriter.AddMethodRefSig (GetMethodRefSig ((MethodReference) member)); + + MetadataToken declaringType = GetTypeDefOrRefToken (member.DeclaringType); + uint name = m_mdWriter.AddString (member.Name); + + for (int i = 0; i < mrTable.Rows.Count; i++) { + MemberRefRow row = mrTable [i]; + if (row.Class == declaringType && row.Name == name && row.Signature == sig) + return MetadataToken.FromMetadataRow (TokenType.MemberRef, i); + } + + MemberRefRow mrRow = m_rowWriter.CreateMemberRefRow ( + declaringType, + name, + sig); + + mrTable.Rows.Add (mrRow); + member.MetadataToken = new MetadataToken ( + TokenType.MemberRef, (uint) mrTable.Rows.Count); + m_memberRefTokenCache [member] = member.MetadataToken; + return member.MetadataToken; + } + + public MetadataToken GetMethodSpecToken (GenericInstanceMethod gim) + { + uint sig = m_sigWriter.AddMethodSpec (GetMethodSpecSig (gim)); + MethodSpecTable msTable = m_tableWriter.GetMethodSpecTable (); + + MetadataToken meth = GetMemberRefToken (gim.ElementMethod); + + for (int i = 0; i < msTable.Rows.Count; i++) { + MethodSpecRow row = msTable [i]; + if (row.Method == meth && row.Instantiation == sig) + return MetadataToken.FromMetadataRow (TokenType.MethodSpec, i); + } + + MethodSpecRow msRow = m_rowWriter.CreateMethodSpecRow ( + meth, + sig); + msTable.Rows.Add (msRow); + gim.MetadataToken = new MetadataToken (TokenType.MethodSpec, (uint) msTable.Rows.Count); + return gim.MetadataToken; + } + + public override void VisitModuleDefinition (ModuleDefinition mod) + { + mod.FullLoad (); + } + + public override void VisitTypeDefinitionCollection (TypeDefinitionCollection types) + { + TypeDefTable tdTable = m_tableWriter.GetTypeDefTable (); + + if (types [Constants.ModuleType] == null) + types.Add (new TypeDefinition ( + Constants.ModuleType, string.Empty, TypeAttributes.NotPublic)); + + foreach (TypeDefinition t in types) + m_typeDefStack.Add (t); + + m_typeDefStack.Sort (TableComparers.TypeDef.Instance); + + for (int i = 0; i < m_typeDefStack.Count; i++) { + TypeDefinition t = (TypeDefinition) m_typeDefStack [i]; + if (t.Module.Assembly != m_mod.Assembly) + throw new ReflectionException ("A type as not been correctly imported"); + + t.MetadataToken = new MetadataToken (TokenType.TypeDef, (uint) (i + 1)); + } + + foreach (TypeDefinition t in m_typeDefStack) { + TypeDefRow tdRow = m_rowWriter.CreateTypeDefRow ( + t.Attributes, + m_mdWriter.AddString (t.Name), + m_mdWriter.AddString (t.Namespace), + GetTypeDefOrRefToken (t.BaseType), + 0, + 0); + + tdTable.Rows.Add (tdRow); + } + } + + public void CompleteTypeDefinitions () + { + TypeDefTable tdTable = m_tableWriter.GetTypeDefTable (); + + for (int i = 0; i < m_typeDefStack.Count; i++) { + TypeDefRow tdRow = tdTable [i]; + TypeDefinition t = (TypeDefinition) m_typeDefStack [i]; + tdRow.FieldList = m_fieldIndex; + tdRow.MethodList = m_methodIndex; + foreach (FieldDefinition field in t.Fields) + VisitFieldDefinition (field); + foreach (MethodDefinition ctor in t.Constructors) + VisitMethodDefinition (ctor); + foreach (MethodDefinition meth in t.Methods) + VisitMethodDefinition (meth); + + if (t.HasLayoutInfo) + WriteLayout (t); + } + + foreach (FieldDefinition field in m_fieldStack) { + VisitCustomAttributeCollection (field.CustomAttributes); + if (field.MarshalSpec != null) + VisitMarshalSpec (field.MarshalSpec); + } + + foreach (MethodDefinition meth in m_methodStack) { + VisitCustomAttributeCollection (meth.ReturnType.CustomAttributes); + foreach (ParameterDefinition param in meth.Parameters) + VisitCustomAttributeCollection (param.CustomAttributes); + VisitGenericParameterCollection (meth.GenericParameters); + VisitOverrideCollection (meth.Overrides); + VisitCustomAttributeCollection (meth.CustomAttributes); + VisitSecurityDeclarationCollection (meth.SecurityDeclarations); + if (meth.PInvokeInfo != null) { + meth.Attributes |= MethodAttributes.PInvokeImpl; + VisitPInvokeInfo (meth.PInvokeInfo); + } + } + + foreach (TypeDefinition t in m_typeDefStack) + t.Accept (this); + } + + public override void VisitTypeReferenceCollection (TypeReferenceCollection refs) + { + ArrayList orderedTypeRefs = new ArrayList (refs.Count); + foreach (TypeReference tr in refs) + orderedTypeRefs.Add (tr); + + orderedTypeRefs.Sort (TableComparers.TypeRef.Instance); + + TypeRefTable trTable = m_tableWriter.GetTypeRefTable (); + foreach (TypeReference t in orderedTypeRefs) { + MetadataToken scope; + + if (t.Module.Assembly != m_mod.Assembly) + throw new ReflectionException ("A type as not been correctly imported"); + + if (t.Scope == null) + continue; + + if (t.DeclaringType != null) + scope = new MetadataToken (TokenType.TypeRef, GetRidFor (t.DeclaringType)); + else if (t.Scope is AssemblyNameReference) + scope = new MetadataToken (TokenType.AssemblyRef, + GetRidFor ((AssemblyNameReference) t.Scope)); + else if (t.Scope is ModuleDefinition) + scope = new MetadataToken (TokenType.Module, + GetRidFor ((ModuleDefinition) t.Scope)); + else if (t.Scope is ModuleReference) + scope = new MetadataToken (TokenType.ModuleRef, + GetRidFor ((ModuleReference) t.Scope)); + else + scope = new MetadataToken (TokenType.ExportedType, 0); + + TypeRefRow trRow = m_rowWriter.CreateTypeRefRow ( + scope, + m_mdWriter.AddString (t.Name), + m_mdWriter.AddString (t.Namespace)); + + trTable.Rows.Add (trRow); + t.MetadataToken = new MetadataToken (TokenType.TypeRef, (uint) trTable.Rows.Count); + } + } + + public override void VisitGenericParameterCollection (GenericParameterCollection parameters) + { + if (parameters.Count == 0) + return; + + foreach (GenericParameter gp in parameters) + m_genericParamStack.Add (gp); + } + + public override void VisitInterfaceCollection (InterfaceCollection interfaces) + { + if (interfaces.Count == 0) + return; + + InterfaceImplTable iiTable = m_tableWriter.GetInterfaceImplTable (); + foreach (TypeReference interf in interfaces) { + InterfaceImplRow iiRow = m_rowWriter.CreateInterfaceImplRow ( + GetRidFor (interfaces.Container), + GetTypeDefOrRefToken (interf)); + + iiTable.Rows.Add (iiRow); + } + } + + public override void VisitExternTypeCollection (ExternTypeCollection externs) + { + VisitCollection (externs); + } + + public override void VisitExternType (TypeReference externType) + { + // TODO + } + + public override void VisitOverrideCollection (OverrideCollection meths) + { + if (meths.Count == 0) + return; + + MethodImplTable miTable = m_tableWriter.GetMethodImplTable (); + foreach (MethodReference ov in meths) { + MethodImplRow miRow = m_rowWriter.CreateMethodImplRow ( + GetRidFor (meths.Container.DeclaringType as TypeDefinition), + new MetadataToken (TokenType.Method, GetRidFor (meths.Container)), + GetMemberRefToken (ov)); + + miTable.Rows.Add (miRow); + } + } + + public override void VisitNestedTypeCollection (NestedTypeCollection nestedTypes) + { + if (nestedTypes.Count == 0) + return; + + NestedClassTable ncTable = m_tableWriter.GetNestedClassTable (); + foreach (TypeDefinition nested in nestedTypes) { + NestedClassRow ncRow = m_rowWriter.CreateNestedClassRow ( + nested.MetadataToken.RID, + GetRidFor (nestedTypes.Container)); + + ncTable.Rows.Add (ncRow); + } + } + + public override void VisitParameterDefinitionCollection (ParameterDefinitionCollection parameters) + { + if (parameters.Count == 0) + return; + + ushort seq = 1; + ParamTable pTable = m_tableWriter.GetParamTable (); + foreach (ParameterDefinition param in parameters) + InsertParameter (pTable, param, seq++); + } + + void InsertParameter (ParamTable pTable, ParameterDefinition param, ushort seq) + { + ParamRow pRow = m_rowWriter.CreateParamRow ( + param.Attributes, + seq, + m_mdWriter.AddString (param.Name)); + + pTable.Rows.Add (pRow); + param.MetadataToken = new MetadataToken (TokenType.Param, (uint) pTable.Rows.Count); + + if (param.MarshalSpec != null) + param.MarshalSpec.Accept (this); + + if (param.HasConstant) + WriteConstant (param, param.ParameterType); + + m_paramIndex++; + } + + static bool RequiresParameterRow (MethodReturnType mrt) + { + return mrt.HasConstant || mrt.MarshalSpec != null || + mrt.CustomAttributes.Count > 0 || mrt.Parameter.Attributes != (ParameterAttributes) 0; + } + + public override void VisitMethodDefinition (MethodDefinition method) + { + MethodTable mTable = m_tableWriter.GetMethodTable (); + MethodRow mRow = m_rowWriter.CreateMethodRow ( + RVA.Zero, + method.ImplAttributes, + method.Attributes, + m_mdWriter.AddString (method.Name), + m_sigWriter.AddMethodDefSig (GetMethodDefSig (method)), + m_paramIndex); + + mTable.Rows.Add (mRow); + m_methodStack.Add (method); + method.MetadataToken = new MetadataToken (TokenType.Method, (uint) mTable.Rows.Count); + m_methodIndex++; + + if (RequiresParameterRow (method.ReturnType)) + InsertParameter (m_tableWriter.GetParamTable (), method.ReturnType.Parameter, 0); + + VisitParameterDefinitionCollection (method.Parameters); + } + + public override void VisitPInvokeInfo (PInvokeInfo pinvk) + { + ImplMapTable imTable = m_tableWriter.GetImplMapTable (); + ImplMapRow imRow = m_rowWriter.CreateImplMapRow ( + pinvk.Attributes, + new MetadataToken (TokenType.Method, GetRidFor (pinvk.Method)), + m_mdWriter.AddString (pinvk.EntryPoint), + GetRidFor (pinvk.Module)); + + imTable.Rows.Add (imRow); + } + + public override void VisitEventDefinitionCollection (EventDefinitionCollection events) + { + if (events.Count == 0) + return; + + EventMapTable emTable = m_tableWriter.GetEventMapTable (); + EventMapRow emRow = m_rowWriter.CreateEventMapRow ( + GetRidFor (events.Container), + m_eventIndex); + + emTable.Rows.Add (emRow); + VisitCollection (events); + } + + public override void VisitEventDefinition (EventDefinition evt) + { + EventTable eTable = m_tableWriter.GetEventTable (); + EventRow eRow = m_rowWriter.CreateEventRow ( + evt.Attributes, + m_mdWriter.AddString (evt.Name), + GetTypeDefOrRefToken (evt.EventType)); + + eTable.Rows.Add (eRow); + evt.MetadataToken = new MetadataToken (TokenType.Event, (uint) eTable.Rows.Count); + + if (evt.AddMethod != null) + WriteSemantic (MethodSemanticsAttributes.AddOn, evt, evt.AddMethod); + + if (evt.InvokeMethod != null) + WriteSemantic (MethodSemanticsAttributes.Fire, evt, evt.InvokeMethod); + + if (evt.RemoveMethod != null) + WriteSemantic (MethodSemanticsAttributes.RemoveOn, evt, evt.RemoveMethod); + + m_eventIndex++; + } + + public override void VisitFieldDefinition (FieldDefinition field) + { + FieldTable fTable = m_tableWriter.GetFieldTable (); + FieldRow fRow = m_rowWriter.CreateFieldRow ( + field.Attributes, + m_mdWriter.AddString (field.Name), + m_sigWriter.AddFieldSig (GetFieldSig (field))); + + fTable.Rows.Add (fRow); + field.MetadataToken = new MetadataToken (TokenType.Field, (uint) fTable.Rows.Count); + m_fieldIndex++; + + if (field.HasConstant) + WriteConstant (field, field.FieldType); + + if (field.HasLayoutInfo) + WriteLayout (field); + + m_fieldStack.Add (field); + } + + public override void VisitPropertyDefinitionCollection (PropertyDefinitionCollection properties) + { + if (properties.Count == 0) + return; + + PropertyMapTable pmTable = m_tableWriter.GetPropertyMapTable (); + PropertyMapRow pmRow = m_rowWriter.CreatePropertyMapRow ( + GetRidFor (properties.Container), + m_propertyIndex); + + pmTable.Rows.Add (pmRow); + VisitCollection (properties); + } + + public override void VisitPropertyDefinition (PropertyDefinition property) + { + PropertyTable pTable = m_tableWriter.GetPropertyTable (); + PropertyRow pRow = m_rowWriter.CreatePropertyRow ( + property.Attributes, + m_mdWriter.AddString (property.Name), + m_sigWriter.AddPropertySig (GetPropertySig (property))); + + pTable.Rows.Add (pRow); + property.MetadataToken = new MetadataToken (TokenType.Property, (uint) pTable.Rows.Count); + + if (property.GetMethod != null) + WriteSemantic (MethodSemanticsAttributes.Getter, property, property.GetMethod); + + if (property.SetMethod != null) + WriteSemantic (MethodSemanticsAttributes.Setter, property, property.SetMethod); + + if (property.HasConstant) + WriteConstant (property, property.PropertyType); + + m_propertyIndex++; + } + + public override void VisitSecurityDeclarationCollection (SecurityDeclarationCollection secDecls) + { + if (secDecls.Count == 0) + return; + + DeclSecurityTable dsTable = m_tableWriter.GetDeclSecurityTable (); + foreach (SecurityDeclaration secDec in secDecls) { + DeclSecurityRow dsRow = m_rowWriter.CreateDeclSecurityRow ( + secDec.Action, + secDecls.Container.MetadataToken, + m_mdWriter.AddBlob (secDec.Resolved ? + m_mod.GetAsByteArray (secDec) : secDec.Blob)); + + dsTable.Rows.Add (dsRow); + } + } + + public override void VisitCustomAttributeCollection (CustomAttributeCollection customAttrs) + { + if (customAttrs.Count == 0) + return; + + CustomAttributeTable caTable = m_tableWriter.GetCustomAttributeTable (); + foreach (CustomAttribute ca in customAttrs) { + MetadataToken parent; + if (customAttrs.Container is AssemblyDefinition) + parent = new MetadataToken (TokenType.Assembly, 1); + else if (customAttrs.Container is ModuleDefinition) + parent = new MetadataToken (TokenType.Module, 1); + else if (customAttrs.Container is IMetadataTokenProvider) + parent = ((IMetadataTokenProvider) customAttrs.Container).MetadataToken; + else + throw new ReflectionException ("Unknown Custom Attribute parent"); + + uint value = ca.Resolved ? + m_sigWriter.AddCustomAttribute (GetCustomAttributeSig (ca), ca.Constructor) : + m_mdWriter.AddBlob (m_mod.GetAsByteArray (ca)); + CustomAttributeRow caRow = m_rowWriter.CreateCustomAttributeRow ( + parent, + GetMemberRefToken (ca.Constructor), + value); + + caTable.Rows.Add (caRow); + } + } + + public override void VisitMarshalSpec (MarshalSpec marshalSpec) + { + FieldMarshalTable fmTable = m_tableWriter.GetFieldMarshalTable (); + FieldMarshalRow fmRow = m_rowWriter.CreateFieldMarshalRow ( + marshalSpec.Container.MetadataToken, + m_sigWriter.AddMarshalSig (GetMarshalSig (marshalSpec))); + + fmTable.Rows.Add (fmRow); + } + + void WriteConstant (IHasConstant hc, TypeReference type) + { + ConstantTable cTable = m_tableWriter.GetConstantTable (); + ElementType et; + if (type is TypeDefinition && (type as TypeDefinition).IsEnum) { + Type t = hc.Constant.GetType (); + if (t.IsEnum) + t = Enum.GetUnderlyingType (t); + + et = GetCorrespondingType (string.Concat (t.Namespace, '.', t.Name)); + } else + et = GetCorrespondingType (type.FullName); + + if (et == ElementType.Object) + et = hc.Constant == null ? + ElementType.Class : + GetCorrespondingType (hc.Constant.GetType ().FullName); + + ConstantRow cRow = m_rowWriter.CreateConstantRow ( + et, + hc.MetadataToken, + m_mdWriter.AddBlob (EncodeConstant (et, hc.Constant))); + + cTable.Rows.Add (cRow); + } + + void WriteLayout (FieldDefinition field) + { + FieldLayoutTable flTable = m_tableWriter.GetFieldLayoutTable (); + FieldLayoutRow flRow = m_rowWriter.CreateFieldLayoutRow ( + field.Offset, + GetRidFor (field)); + + flTable.Rows.Add (flRow); + } + + void WriteLayout (TypeDefinition type) + { + ClassLayoutTable clTable = m_tableWriter.GetClassLayoutTable (); + ClassLayoutRow clRow = m_rowWriter.CreateClassLayoutRow ( + type.PackingSize, + type.ClassSize, + GetRidFor (type)); + + clTable.Rows.Add (clRow); + } + + void WriteSemantic (MethodSemanticsAttributes attrs, + IMetadataTokenProvider member, MethodDefinition meth) + { + MethodSemanticsTable msTable = m_tableWriter.GetMethodSemanticsTable (); + MethodSemanticsRow msRow = m_rowWriter.CreateMethodSemanticsRow ( + attrs, + GetRidFor (meth), + member.MetadataToken); + + msTable.Rows.Add (msRow); + } + + void SortTables () + { + TablesHeap th = m_mdWriter.GetMetadataRoot ().Streams.TablesHeap; + th.Sorted = 0; + + if (th.HasTable (NestedClassTable.RId)) + m_tableWriter.GetNestedClassTable ().Rows.Sort ( + TableComparers.NestedClass.Instance); + th.Sorted |= ((long) 1 << NestedClassTable.RId); + + if (th.HasTable (InterfaceImplTable.RId)) + m_tableWriter.GetInterfaceImplTable ().Rows.Sort ( + TableComparers.InterfaceImpl.Instance); + th.Sorted |= ((long) 1 << InterfaceImplTable.RId); + + if (th.HasTable (ConstantTable.RId)) + m_tableWriter.GetConstantTable ().Rows.Sort ( + TableComparers.Constant.Instance); + th.Sorted |= ((long) 1 << ConstantTable.RId); + + if (th.HasTable (MethodSemanticsTable.RId)) + m_tableWriter.GetMethodSemanticsTable ().Rows.Sort ( + TableComparers.MethodSem.Instance); + th.Sorted |= ((long) 1 << MethodSemanticsTable.RId); + + if (th.HasTable (FieldMarshalTable.RId)) + m_tableWriter.GetFieldMarshalTable ().Rows.Sort ( + TableComparers.FieldMarshal.Instance); + th.Sorted |= ((long) 1 << FieldMarshalTable.RId); + + if (th.HasTable (ClassLayoutTable.RId)) + m_tableWriter.GetClassLayoutTable ().Rows.Sort ( + TableComparers.TypeLayout.Instance); + th.Sorted |= ((long) 1 << ClassLayoutTable.RId); + + if (th.HasTable (FieldLayoutTable.RId)) + m_tableWriter.GetFieldLayoutTable ().Rows.Sort ( + TableComparers.FieldLayout.Instance); + th.Sorted |= ((long) 1 << FieldLayoutTable.RId); + + if (th.HasTable (ImplMapTable.RId)) + m_tableWriter.GetImplMapTable ().Rows.Sort ( + TableComparers.PInvoke.Instance); + th.Sorted |= ((long) 1 << ImplMapTable.RId); + + if (th.HasTable (FieldRVATable.RId)) + m_tableWriter.GetFieldRVATable ().Rows.Sort ( + TableComparers.FieldRVA.Instance); + th.Sorted |= ((long) 1 << FieldRVATable.RId); + + if (th.HasTable (MethodImplTable.RId)) + m_tableWriter.GetMethodImplTable ().Rows.Sort ( + TableComparers.Override.Instance); + th.Sorted |= ((long) 1 << MethodImplTable.RId); + + if (th.HasTable (CustomAttributeTable.RId)) + m_tableWriter.GetCustomAttributeTable ().Rows.Sort ( + TableComparers.CustomAttribute.Instance); + th.Sorted |= ((long) 1 << CustomAttributeTable.RId); + + if (th.HasTable (DeclSecurityTable.RId)) + m_tableWriter.GetDeclSecurityTable ().Rows.Sort ( + TableComparers.SecurityDeclaration.Instance); + th.Sorted |= ((long) 1 << DeclSecurityTable.RId); + } + + void CompleteGenericTables () + { + if (m_genericParamStack.Count == 0) + return; + + TablesHeap th = m_mdWriter.GetMetadataRoot ().Streams.TablesHeap; + GenericParamTable gpTable = m_tableWriter.GetGenericParamTable (); + GenericParamConstraintTable gpcTable = m_tableWriter.GetGenericParamConstraintTable (); + + m_genericParamStack.Sort (TableComparers.GenericParam.Instance); + + foreach (GenericParameter gp in m_genericParamStack) { + GenericParamRow gpRow = m_rowWriter.CreateGenericParamRow ( + (ushort) gp.Owner.GenericParameters.IndexOf (gp), + gp.Attributes, + gp.Owner.MetadataToken, + m_mdWriter.AddString (gp.Name)); + + gpTable.Rows.Add (gpRow); + gp.MetadataToken = new MetadataToken (TokenType.GenericParam, (uint) gpTable.Rows.Count); + + VisitCustomAttributeCollection (gp.CustomAttributes); + + if (gp.Constraints.Count == 0) + continue; + + foreach (TypeReference constraint in gp.Constraints) { + GenericParamConstraintRow gpcRow = m_rowWriter.CreateGenericParamConstraintRow ( + (uint) gpTable.Rows.Count, + GetTypeDefOrRefToken (constraint)); + + gpcTable.Rows.Add (gpcRow); + } + } + + th.Sorted |= ((long) 1 << GenericParamTable.RId); + th.Sorted |= ((long) 1 << GenericParamConstraintTable.RId); + } + + public override void TerminateModuleDefinition (ModuleDefinition module) + { + VisitCustomAttributeCollection (module.Assembly.CustomAttributes); + VisitSecurityDeclarationCollection (module.Assembly.SecurityDeclarations); + VisitCustomAttributeCollection (module.CustomAttributes); + + CompleteGenericTables (); + SortTables (); + + MethodTable mTable = m_tableWriter.GetMethodTable (); + for (int i = 0; i < m_methodStack.Count; i++) { + MethodDefinition meth = (MethodDefinition) m_methodStack [i]; + if (meth.HasBody) + mTable [i].RVA = m_codeWriter.WriteMethodBody (meth); + } + + if (m_fieldStack.Count > 0) { + FieldRVATable frTable = null; + foreach (FieldDefinition field in m_fieldStack) { + if (field.InitialValue != null && field.InitialValue.Length > 0) { + if (frTable == null) + frTable = m_tableWriter.GetFieldRVATable (); + + FieldRVARow frRow = m_rowWriter.CreateFieldRVARow ( + m_mdWriter.GetDataCursor (), + field.MetadataToken.RID); + + m_mdWriter.AddData (field.InitialValue.Length + 3 & (~3)); + m_mdWriter.AddFieldInitData (field.InitialValue); + + frTable.Rows.Add (frRow); + } + } + } + + if (m_symbolWriter != null) + m_symbolWriter.Dispose (); + + if (m_mod.Assembly.EntryPoint != null) + m_mdWriter.EntryPointToken = + ((uint) TokenType.Method) | GetRidFor (m_mod.Assembly.EntryPoint); + + m_mod.Image.MetadataRoot.Accept (m_mdWriter); + } + + public static ElementType GetCorrespondingType (string fullName) + { + switch (fullName) { + case Constants.Boolean : + return ElementType.Boolean; + case Constants.Char : + return ElementType.Char; + case Constants.SByte : + return ElementType.I1; + case Constants.Int16 : + return ElementType.I2; + case Constants.Int32 : + return ElementType.I4; + case Constants.Int64 : + return ElementType.I8; + case Constants.Byte : + return ElementType.U1; + case Constants.UInt16 : + return ElementType.U2; + case Constants.UInt32 : + return ElementType.U4; + case Constants.UInt64 : + return ElementType.U8; + case Constants.Single : + return ElementType.R4; + case Constants.Double : + return ElementType.R8; + case Constants.String : + return ElementType.String; + case Constants.Type : + return ElementType.Type; + case Constants.Object : + return ElementType.Object; + default: + return ElementType.Class; + } + } + + byte [] EncodeConstant (ElementType et, object value) + { + m_constWriter.Empty (); + + if (value == null) + et = ElementType.Class; + + IConvertible ic = value as IConvertible; + IFormatProvider fp = CultureInfo.CurrentCulture.NumberFormat; + + switch (et) { + case ElementType.Boolean : + m_constWriter.Write ((byte) (ic.ToBoolean (fp) ? 1 : 0)); + break; + case ElementType.Char : + m_constWriter.Write ((ushort) ic.ToChar (fp)); + break; + case ElementType.I1 : + m_constWriter.Write (ic.ToSByte (fp)); + break; + case ElementType.I2 : + m_constWriter.Write (ic.ToInt16 (fp)); + break; + case ElementType.I4 : + m_constWriter.Write (ic.ToInt32 (fp)); + break; + case ElementType.I8 : + m_constWriter.Write (ic.ToInt64 (fp)); + break; + case ElementType.U1 : + m_constWriter.Write (ic.ToByte (fp)); + break; + case ElementType.U2 : + m_constWriter.Write (ic.ToUInt16 (fp)); + break; + case ElementType.U4 : + m_constWriter.Write (ic.ToUInt32 (fp)); + break; + case ElementType.U8 : + m_constWriter.Write (ic.ToUInt64 (fp)); + break; + case ElementType.R4 : + m_constWriter.Write (ic.ToSingle (fp)); + break; + case ElementType.R8 : + m_constWriter.Write (ic.ToDouble (fp)); + break; + case ElementType.String : + m_constWriter.Write (Encoding.Unicode.GetBytes ((string) value)); + break; + case ElementType.Class : + m_constWriter.Write (new byte [4]); + break; + default : + throw new ArgumentException ("Non valid element for a constant"); + } + + return m_constWriter.ToArray (); + } + + public SigType GetSigType (TypeReference type) + { + string name = type.FullName; + + switch (name) { + case Constants.Void : + return new SigType (ElementType.Void); + case Constants.Object : + return new SigType (ElementType.Object); + case Constants.Boolean : + return new SigType (ElementType.Boolean); + case Constants.String : + return new SigType (ElementType.String); + case Constants.Char : + return new SigType (ElementType.Char); + case Constants.SByte : + return new SigType (ElementType.I1); + case Constants.Byte : + return new SigType (ElementType.U1); + case Constants.Int16 : + return new SigType (ElementType.I2); + case Constants.UInt16 : + return new SigType (ElementType.U2); + case Constants.Int32 : + return new SigType (ElementType.I4); + case Constants.UInt32 : + return new SigType (ElementType.U4); + case Constants.Int64 : + return new SigType (ElementType.I8); + case Constants.UInt64 : + return new SigType (ElementType.U8); + case Constants.Single : + return new SigType (ElementType.R4); + case Constants.Double : + return new SigType (ElementType.R8); + case Constants.IntPtr : + return new SigType (ElementType.I); + case Constants.UIntPtr : + return new SigType (ElementType.U); + case Constants.TypedReference : + return new SigType (ElementType.TypedByRef); + } + + if (type is GenericParameter) { + GenericParameter gp = type as GenericParameter; + int pos = gp.Owner.GenericParameters.IndexOf (gp); + if (gp.Owner is TypeReference) + return new VAR (pos); + else if (gp.Owner is MethodReference) + return new MVAR (pos); + else + throw new ReflectionException ("Unkown generic parameter type"); + } else if (type is GenericInstanceType) { + GenericInstanceType git = type as GenericInstanceType; + GENERICINST gi = new GENERICINST (); + gi.ValueType = git.IsValueType; + gi.Type = GetTypeDefOrRefToken (git.ElementType); + gi.Signature = new GenericInstSignature (); + gi.Signature.Arity = git.GenericArguments.Count; + gi.Signature.Types = new GenericArg [gi.Signature.Arity]; + for (int i = 0; i < git.GenericArguments.Count; i++) + gi.Signature.Types [i] = GetGenericArgSig (git.GenericArguments [i]); + + return gi; + } else if (type is ArrayType) { + ArrayType aryType = type as ArrayType; + if (aryType.IsSizedArray) { + SZARRAY szary = new SZARRAY (); + szary.CustomMods = GetCustomMods (aryType.ElementType); + szary.Type = GetSigType (aryType.ElementType); + return szary; + } + + // not optimized + ArrayShape shape = new ArrayShape (); + shape.Rank = aryType.Dimensions.Count; + shape.NumSizes = 0; + + for (int i = 0; i < shape.Rank; i++) { + ArrayDimension dim = aryType.Dimensions [i]; + if (dim.UpperBound > 0) + shape.NumSizes++; + } + + shape.Sizes = new int [shape.NumSizes]; + shape.NumLoBounds = shape.Rank; + shape.LoBounds = new int [shape.NumLoBounds]; + + for (int i = 0; i < shape.Rank; i++) { + ArrayDimension dim = aryType.Dimensions [i]; + shape.LoBounds [i] = dim.LowerBound; + if (dim.UpperBound > 0) + shape.Sizes [i] = dim.UpperBound - dim.LowerBound + 1; + } + + ARRAY ary = new ARRAY (); + ary.Shape = shape; + ary.CustomMods = GetCustomMods (aryType.ElementType); + ary.Type = GetSigType (aryType.ElementType); + return ary; + } else if (type is PointerType) { + PTR p = new PTR (); + TypeReference elementType = (type as PointerType).ElementType; + p.Void = elementType.FullName == Constants.Void; + if (!p.Void) { + p.CustomMods = GetCustomMods (elementType); + p.PtrType = GetSigType (elementType); + } + return p; + } else if (type is FunctionPointerType) { + FNPTR fp = new FNPTR (); + FunctionPointerType fptr = type as FunctionPointerType; + + int sentinel = fptr.GetSentinel (); + if (sentinel < 0) + fp.Method = GetMethodDefSig (fptr); + else + fp.Method = GetMethodRefSig (fptr); + + return fp; + } else if (type is TypeSpecification) { + return GetSigType ((type as TypeSpecification).ElementType); + } else if (type.IsValueType) { + VALUETYPE vt = new VALUETYPE (); + vt.Type = GetTypeDefOrRefToken (type); + return vt; + } else { + CLASS c = new CLASS (); + c.Type = GetTypeDefOrRefToken (type); + return c; + } + } + + public GenericArg GetGenericArgSig (TypeReference type) + { + GenericArg arg = new GenericArg (GetSigType (type)); + arg.CustomMods = GetCustomMods (type); + return arg; + } + + public CustomMod [] GetCustomMods (TypeReference type) + { + ModType modifier = type as ModType; + if (modifier == null) + return new CustomMod [0]; + + ArrayList cmods = new ArrayList (); + do { + CustomMod cmod = new CustomMod (); + cmod.TypeDefOrRef = GetTypeDefOrRefToken (modifier.ModifierType); + + if (modifier is ModifierOptional) + cmod.CMOD = CustomMod.CMODType.OPT; + else if (modifier is ModifierRequired) + cmod.CMOD = CustomMod.CMODType.REQD; + + cmods.Add (cmod); + modifier = modifier.ElementType as ModType; + } while (modifier != null); + + return cmods.ToArray (typeof (CustomMod)) as CustomMod []; + } + + public Signature GetMemberRefSig (MemberReference member) + { + if (member is FieldReference) + return GetFieldSig (member as FieldReference); + else + return GetMemberRefSig (member as MethodReference); + } + + public FieldSig GetFieldSig (FieldReference field) + { + FieldSig sig = new FieldSig (); + sig.CallingConvention |= 0x6; + sig.Field = true; + sig.CustomMods = GetCustomMods (field.FieldType); + sig.Type = GetSigType (field.FieldType); + return sig; + } + + Param [] GetParametersSig (ParameterDefinitionCollection parameters) + { + Param [] ret = new Param [parameters.Count]; + for (int i = 0; i < ret.Length; i++) { + ParameterDefinition pDef = parameters [i]; + Param p = new Param (); + p.CustomMods = GetCustomMods (pDef.ParameterType); + if (pDef.ParameterType.FullName == Constants.TypedReference) + p.TypedByRef = true; + else if (IsByReferenceType (pDef.ParameterType)) { + p.ByRef = true; + p.Type = GetSigType (pDef.ParameterType); + } else + p.Type = GetSigType (pDef.ParameterType); + ret [i] = p; + } + return ret; + } + + void CompleteMethodSig (IMethodSignature meth, MethodSig sig) + { + sig.HasThis = meth.HasThis; + sig.ExplicitThis = meth.ExplicitThis; + if (sig.HasThis) + sig.CallingConvention |= 0x20; + if (sig.ExplicitThis) + sig.CallingConvention |= 0x40; + + if ((meth.CallingConvention & MethodCallingConvention.VarArg) != 0) + sig.CallingConvention |= 0x5; + + sig.ParamCount = meth.Parameters.Count; + sig.Parameters = GetParametersSig (meth.Parameters); + + RetType rtSig = new RetType (); + rtSig.CustomMods = GetCustomMods (meth.ReturnType.ReturnType); + + if (meth.ReturnType.ReturnType.FullName == Constants.Void) + rtSig.Void = true; + else if (meth.ReturnType.ReturnType.FullName == Constants.TypedReference) + rtSig.TypedByRef = true; + else if (IsByReferenceType (meth.ReturnType.ReturnType)) { + rtSig.ByRef = true; + rtSig.Type = GetSigType (meth.ReturnType.ReturnType); + } else + rtSig.Type = GetSigType (meth.ReturnType.ReturnType); + + sig.RetType = rtSig; + } + + static bool IsByReferenceType (TypeReference type) + { + TypeSpecification ts = type as TypeSpecification; + while (ts != null) { + if (ts is ReferenceType) + return true; + ts = ts.ElementType as TypeSpecification; + } + return false; + } + + public MethodRefSig GetMethodRefSig (IMethodSignature meth) + { + MethodReference methodRef = meth as MethodReference; + if (methodRef != null && methodRef.GenericParameters.Count > 0) + return GetMethodDefSig (meth); + + MethodRefSig methSig = new MethodRefSig (); + + CompleteMethodSig (meth, methSig); + + int sentinel = meth.GetSentinel (); + if (sentinel >= 0) + methSig.Sentinel = sentinel; + + if ((meth.CallingConvention & MethodCallingConvention.C) != 0) + methSig.CallingConvention |= 0x1; + else if ((meth.CallingConvention & MethodCallingConvention.StdCall) != 0) + methSig.CallingConvention |= 0x2; + else if ((meth.CallingConvention & MethodCallingConvention.ThisCall) != 0) + methSig.CallingConvention |= 0x3; + else if ((meth.CallingConvention & MethodCallingConvention.FastCall) != 0) + methSig.CallingConvention |= 0x4; + + return methSig; + } + + public MethodDefSig GetMethodDefSig (IMethodSignature meth) + { + MethodDefSig sig = new MethodDefSig (); + + CompleteMethodSig (meth, sig); + + MethodReference methodRef = meth as MethodReference; + if (methodRef != null && methodRef.GenericParameters.Count > 0) { + sig.CallingConvention |= 0x10; + sig.GenericParameterCount = methodRef.GenericParameters.Count; + } + + return sig; + } + + public PropertySig GetPropertySig (PropertyDefinition prop) + { + PropertySig ps = new PropertySig (); + ps.CallingConvention |= 0x8; + + bool hasThis; + bool explicitThis; + MethodCallingConvention mcc; + ParameterDefinitionCollection parameters = prop.Parameters; + + MethodDefinition meth; + if (prop.GetMethod != null) + meth = prop.GetMethod; + else if (prop.SetMethod != null) + meth = prop.SetMethod; + else + meth = null; + + if (meth != null) { + hasThis = meth.HasThis; + explicitThis = meth.ExplicitThis; + mcc = meth.CallingConvention; + } else { + hasThis = explicitThis = false; + mcc = MethodCallingConvention.Default; + } + + if (hasThis) + ps.CallingConvention |= 0x20; + if (explicitThis) + ps.CallingConvention |= 0x40; + + if ((mcc & MethodCallingConvention.VarArg) != 0) + ps.CallingConvention |= 0x5; + + int paramCount = parameters != null ? parameters.Count : 0; + + ps.ParamCount = paramCount; + ps.Parameters = GetParametersSig (parameters); + ps.CustomMods = GetCustomMods (prop.PropertyType); + ps.Type = GetSigType (prop.PropertyType); + + return ps; + } + + public TypeSpec GetTypeSpecSig (TypeReference type) + { + TypeSpec ts = new TypeSpec (); + ts.CustomMods = GetCustomMods (type); + ts.Type = GetSigType (type); + return ts; + } + + public MethodSpec GetMethodSpecSig (GenericInstanceMethod gim) + { + GenericInstSignature gis = new GenericInstSignature (); + gis.Arity = gim.GenericArguments.Count; + gis.Types = new GenericArg [gis.Arity]; + for (int i = 0; i < gis.Arity; i++) + gis.Types [i] = GetGenericArgSig (gim.GenericArguments [i]); + + return new MethodSpec (gis); + } + + static string GetObjectTypeName (object o) + { + Type t = o.GetType (); + return string.Concat (t.Namespace, ".", t.Name); + } + + static CustomAttrib.Elem CreateElem (TypeReference type, object value) + { + CustomAttrib.Elem elem = new CustomAttrib.Elem (); + elem.Value = value; + elem.ElemType = type; + elem.FieldOrPropType = GetCorrespondingType (type.FullName); + + switch (elem.FieldOrPropType) { + case ElementType.Boolean : + case ElementType.Char : + case ElementType.R4 : + case ElementType.R8 : + case ElementType.I1 : + case ElementType.I2 : + case ElementType.I4 : + case ElementType.I8 : + case ElementType.U1 : + case ElementType.U2 : + case ElementType.U4 : + case ElementType.U8 : + elem.Simple = true; + break; + case ElementType.String: + elem.String = true; + break; + case ElementType.Type: + elem.Type = true; + break; + case ElementType.Object: + elem.BoxedValueType = true; + if (value == null) + elem.FieldOrPropType = ElementType.String; + else + elem.FieldOrPropType = GetCorrespondingType ( + GetObjectTypeName (value)); + break; + } + + return elem; + } + + static CustomAttrib.FixedArg CreateFixedArg (TypeReference type, object value) + { + CustomAttrib.FixedArg fa = new CustomAttrib.FixedArg (); + if (value is object []) { + fa.SzArray = true; + object [] values = value as object []; + TypeReference obj = ((ArrayType) type).ElementType; + fa.NumElem = (uint) values.Length; + fa.Elems = new CustomAttrib.Elem [values.Length]; + for (int i = 0; i < values.Length; i++) + fa.Elems [i] = CreateElem (obj, values [i]); + } else { + fa.Elems = new CustomAttrib.Elem [1]; + fa.Elems [0] = CreateElem (type, value); + } + + return fa; + } + + static CustomAttrib.NamedArg CreateNamedArg (TypeReference type, string name, + object value, bool field) + { + CustomAttrib.NamedArg na = new CustomAttrib.NamedArg (); + na.Field = field; + na.Property = !field; + + na.FieldOrPropName = name; + na.FieldOrPropType = GetCorrespondingType (type.FullName); + na.FixedArg = CreateFixedArg (type, value); + + return na; + } + + public static CustomAttrib GetCustomAttributeSig (CustomAttribute ca) + { + CustomAttrib cas = new CustomAttrib (ca.Constructor); + cas.Prolog = CustomAttrib.StdProlog; + + cas.FixedArgs = new CustomAttrib.FixedArg [ca.Constructor.Parameters.Count]; + + for (int i = 0; i < cas.FixedArgs.Length; i++) + cas.FixedArgs [i] = CreateFixedArg ( + ca.Constructor.Parameters [i].ParameterType, ca.ConstructorParameters [i]); + + int nn = ca.Fields.Count + ca.Properties.Count; + cas.NumNamed = (ushort) nn; + cas.NamedArgs = new CustomAttrib.NamedArg [nn]; + + if (cas.NamedArgs.Length > 0) { + int curs = 0; + foreach (DictionaryEntry entry in ca.Fields) { + string field = (string) entry.Key; + cas.NamedArgs [curs++] = CreateNamedArg ( + ca.GetFieldType (field), field, entry.Value, true); + } + + foreach (DictionaryEntry entry in ca.Properties) { + string property = (string) entry.Key; + cas.NamedArgs [curs++] = CreateNamedArg ( + ca.GetPropertyType (property), property, entry.Value, false); + } + } + + return cas; + } + + static MarshalSig GetMarshalSig (MarshalSpec mSpec) + { + MarshalSig ms = new MarshalSig (mSpec.NativeIntrinsic); + + if (mSpec is ArrayMarshalSpec) { + ArrayMarshalSpec amd = mSpec as ArrayMarshalSpec; + MarshalSig.Array ar = new MarshalSig.Array (); + ar.ArrayElemType = amd.ElemType; + ar.NumElem = amd.NumElem; + ar.ParamNum = amd.ParamNum; + ar.ElemMult = amd.ElemMult; + ms.Spec = ar; + } else if (mSpec is CustomMarshalerSpec) { + CustomMarshalerSpec cmd = mSpec as CustomMarshalerSpec; + MarshalSig.CustomMarshaler cm = new MarshalSig.CustomMarshaler (); + cm.Guid = cmd.Guid.ToString (); + cm.UnmanagedType = cmd.UnmanagedType; + cm.ManagedType = cmd.ManagedType; + cm.Cookie = cmd.Cookie; + ms.Spec = cm; + } else if (mSpec is FixedArraySpec) { + FixedArraySpec fad = mSpec as FixedArraySpec; + MarshalSig.FixedArray fa = new MarshalSig.FixedArray (); + fa.ArrayElemType = fad.ElemType; + fa.NumElem = fad.NumElem; + ms.Spec = fa; + } else if (mSpec is FixedSysStringSpec) { + MarshalSig.FixedSysString fss = new MarshalSig.FixedSysString (); + fss.Size = (mSpec as FixedSysStringSpec).Size; + ms.Spec = fss; + } else if (mSpec is SafeArraySpec) { + MarshalSig.SafeArray sa = new MarshalSig.SafeArray (); + sa.ArrayElemType = (mSpec as SafeArraySpec).ElemType; + ms.Spec = sa; + } + + return ms; + } + + public void WriteSymbols (ModuleDefinition module) + { + if (!m_saveSymbols) + return; + + if (m_asmOutput == null) + m_asmOutput = module.Assembly.Name.Name + "." + (module.Assembly.Kind == AssemblyKind.Dll ? "dll" : "exe"); + + if (m_symbolWriter == null) + m_symbolWriter = SymbolStoreHelper.GetWriter (module, m_asmOutput); + + foreach (TypeDefinition type in module.Types) { + foreach (MethodDefinition method in type.Methods) + WriteSymbols (method); + foreach (MethodDefinition ctor in type.Constructors) + WriteSymbols (ctor); + } + + m_symbolWriter.Dispose (); + } + + void WriteSymbols (MethodDefinition meth) + { + if (!meth.HasBody) + return; + + m_symbolWriter.Write (meth.Body, GetVariablesSig (meth)); + } + + byte [][] GetVariablesSig (MethodDefinition meth) + { + VariableDefinitionCollection variables = meth.Body.Variables; + byte [][] signatures = new byte [variables.Count][]; + for (int i = 0; i < variables.Count; i++) { + signatures [i] = GetVariableSig (variables [i]); + } + return signatures; + } + + byte [] GetVariableSig (VariableDefinition var) + { + return m_sigWriter.CompressLocalVar (m_codeWriter.GetLocalVariableSig (var)); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Resource.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Resource.cs new file mode 100644 index 0000000..9790803 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/Resource.cs @@ -0,0 +1,91 @@ +// +// Resource.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System.Collections; + + public abstract class Resource : IAnnotationProvider, IReflectionStructureVisitable { + + string m_name; + ManifestResourceAttributes m_attributes; + IDictionary m_annotations; + + public string Name { + get { return m_name; } + set { m_name = value; } + } + + public ManifestResourceAttributes Flags { + get { return m_attributes; } + set { m_attributes = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { + if (m_annotations == null) + m_annotations = new Hashtable (); + return m_annotations; + } + } + + #region ManifestResourceAttributes + + public bool IsPublic { + get { return (m_attributes & ManifestResourceAttributes.VisibilityMask) == ManifestResourceAttributes.Public; } + set { + if (value) { + m_attributes &= ~ManifestResourceAttributes.VisibilityMask; + m_attributes |= ManifestResourceAttributes.Public; + } else + m_attributes &= ~(ManifestResourceAttributes.VisibilityMask & ManifestResourceAttributes.Public); + } + } + + public bool IsPrivate { + get { return (m_attributes & ManifestResourceAttributes.VisibilityMask) == ManifestResourceAttributes.Private; } + set { + if (value) { + m_attributes &= ~ManifestResourceAttributes.VisibilityMask; + m_attributes |= ManifestResourceAttributes.Private; + } else + m_attributes &= ~(ManifestResourceAttributes.VisibilityMask & ManifestResourceAttributes.Private); + } + } + + #endregion + + internal Resource (string name, ManifestResourceAttributes attributes) + { + m_name = name; + m_attributes = attributes; + } + + public abstract void Accept (IReflectionStructureVisitor visitor); + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ResourceCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ResourceCollection.cs new file mode 100644 index 0000000..5a9696a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/ResourceCollection.cs @@ -0,0 +1,93 @@ +// +// ResourceCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Wed Sep 27 12:46:54 CEST 2006 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Cil; + + public sealed class ResourceCollection : CollectionBase, IReflectionStructureVisitable { + + ModuleDefinition m_container; + + public Resource this [int index] { + get { return List [index] as Resource; } + set { List [index] = value; } + } + + public ModuleDefinition Container { + get { return m_container; } + } + + public ResourceCollection (ModuleDefinition container) + { + m_container = container; + } + + public void Add (Resource value) + { + List.Add (value); + } + + public bool Contains (Resource value) + { + return List.Contains (value); + } + + public int IndexOf (Resource value) + { + return List.IndexOf (value); + } + + public void Insert (int index, Resource value) + { + List.Insert (index, value); + } + + public void Remove (Resource value) + { + List.Remove (value); + } + + protected override void OnValidate (object o) + { + if (! (o is Resource)) + throw new ArgumentException ("Must be of type " + typeof (Resource).FullName); + } + + public void Accept (IReflectionStructureVisitor visitor) + { + visitor.VisitResourceCollection (this); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityAction.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityAction.cs new file mode 100644 index 0000000..b1ac330 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityAction.cs @@ -0,0 +1,48 @@ +// +// SecurityAction.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public enum SecurityAction : short { + Request = 1, + Demand = 2, + Assert = 3, + Deny = 4, + PermitOnly = 5, + LinkDemand = 6, + InheritDemand = 7, + RequestMinimum = 8, + RequestOptional = 9, + RequestRefuse = 10, + PreJitGrant = 11, + PreJitDeny = 12, + NonCasDemand = 13, + NonCasLinkDemand = 14, + NonCasInheritance = 15 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs new file mode 100644 index 0000000..b9feca6 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclaration.cs @@ -0,0 +1,114 @@ +// +// SecurityDeclaration.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + using System.Security; + + public sealed class SecurityDeclaration : IRequireResolving, IAnnotationProvider, IReflectionVisitable { + + SecurityAction m_action; + IDictionary m_annotations; + +#if !CF_1_0 && !CF_2_0 + PermissionSet m_permSet; +#endif + + bool m_resolved; + byte [] m_blob; + + public SecurityAction Action { + get { return m_action; } + set { m_action = value; } + } + +#if !CF_1_0 && !CF_2_0 + public PermissionSet PermissionSet { + get { return m_permSet; } + set { m_permSet = value; } + } +#endif + + public bool Resolved { + get { return m_resolved; } + set { m_resolved = value; } + } + + public byte [] Blob { + get { return m_blob; } + set { m_blob = value; } + } + + IDictionary IAnnotationProvider.Annotations { + get { + if (m_annotations == null) + m_annotations = new Hashtable (); + return m_annotations; + } + } + + public SecurityDeclaration (SecurityAction action) + { + m_action = action; + m_resolved = true; + } + + public SecurityDeclaration Clone () + { + return Clone (this); + } + + internal static SecurityDeclaration Clone (SecurityDeclaration sec) + { + SecurityDeclaration sd = new SecurityDeclaration (sec.Action); + if (!sec.Resolved) { + sd.Resolved = false; + sd.Blob = sec.Blob; + return sd; + } + +#if !CF_1_0 && !CF_2_0 + sd.PermissionSet = sec.PermissionSet.Copy (); +#endif + return sd; + } + + public bool Resolve () + { + throw new NotImplementedException (); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitSecurityDeclaration (this); + } + } +} + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclarationCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclarationCollection.cs new file mode 100644 index 0000000..9aa14e7 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclarationCollection.cs @@ -0,0 +1,157 @@ +// +// SecurityDeclarationCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + public sealed class SecurityDeclarationCollection : IReflectionVisitable { + + IDictionary m_items; + IHasSecurity m_container; + + public SecurityDeclaration this [int index] { + get { return m_items [index] as SecurityDeclaration; } + set { m_items [index] = value; } + } + + public SecurityDeclaration this [SecurityAction action] { + get { return m_items [action] as SecurityDeclaration; } + set { m_items [action] = value; } + } + + public IHasSecurity Container { + get { return m_container; } + } + + public int Count { + get { return m_items.Count; } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + public SecurityDeclarationCollection (IHasSecurity container) + { + m_container = container; + m_items = new Hashtable (); + } + + public void Add (SecurityDeclaration value) + { + if (value == null) + throw new ArgumentNullException ("value"); + + // Each action can only be added once so... + SecurityDeclaration current = (SecurityDeclaration) m_items[value.Action]; + if (current != null) { + // ... further additions are transformed into unions +#if !CF_1_0 && !CF_2_0 + current.PermissionSet = current.PermissionSet.Union (value.PermissionSet); +#endif + } else { + m_items.Add (value.Action, value); + SetHasSecurity (true); + } + } + + public void Clear () + { + m_items.Clear (); + SetHasSecurity (false); + } + + public bool Contains (SecurityAction action) + { + return (m_items [action] != null); + } + + public bool Contains (SecurityDeclaration value) + { + if (value == null) + return (m_items.Count == 0); + + SecurityDeclaration item = (SecurityDeclaration) m_items[value.Action]; + if (item == null) + return false; + +#if !CF_1_0 && !CF_2_0 + return value.PermissionSet.IsSubsetOf (item.PermissionSet); +#else + // XXX For CF, this concept does not exist--so always be true + return true; +#endif + } + + public void Remove (SecurityAction action) + { + m_items.Remove (action); + SetHasSecurity (this.Count > 0); + } + + public void CopyTo (Array ary, int index) + { + m_items.Values.CopyTo (ary, index); + } + + public IEnumerator GetEnumerator () + { + return m_items.Values.GetEnumerator (); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitSecurityDeclarationCollection (this); + } + + private void SetHasSecurity (bool value) + { + TypeDefinition td = (m_container as TypeDefinition); + if (td != null) { + if (value) + td.Attributes |= TypeAttributes.HasSecurity; + else + td.Attributes &= ~TypeAttributes.HasSecurity; + return; + } + MethodDefinition md = (m_container as MethodDefinition); + if (md != null) { + if (value) + md.Attributes |= MethodAttributes.HasSecurity; + else + md.Attributes &= ~MethodAttributes.HasSecurity; + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclarationReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclarationReader.cs new file mode 100644 index 0000000..512b493 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SecurityDeclarationReader.cs @@ -0,0 +1,160 @@ +// +// SecurityDeclarationReader.cs +// +// Author: +// Sebastien Pouliot <sebastien@ximian.com> +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.IO; + using System.Reflection; + using System.Security; + using SSP = System.Security.Permissions; + using System.Text; + + using Mono.Cecil.Metadata; + using Mono.Cecil.Signatures; + using Mono.Xml; + + internal class SecurityDeclarationReader { + + private SecurityParser m_parser; + private SignatureReader sr; + + public SecurityDeclarationReader (MetadataRoot root, ReflectionReader reader) + { + sr = new SignatureReader (root, reader); + } + + public SecurityParser Parser { + get { + if (m_parser == null) + m_parser = new SecurityParser (); + return m_parser; + } + } + + public SecurityDeclaration FromByteArray (SecurityAction action, byte [] declaration) + { + return FromByteArray (action, declaration, false); + } + + static bool IsEmptyDeclaration (byte [] declaration) + { + return declaration == null || declaration.Length == 0 || + (declaration.Length == 1 && declaration [0] == 0); + } + + public SecurityDeclaration FromByteArray (SecurityAction action, byte [] declaration, bool resolve) + { + SecurityDeclaration dec = new SecurityDeclaration (action); +#if !CF_1_0 && !CF_2_0 + dec.PermissionSet = new PermissionSet (SSP.PermissionState.None); + + if (IsEmptyDeclaration (declaration)) + return dec; + + if (declaration[0] == 0x2e) { + // new binary format introduced in 2.0 + int pos = 1; + int start; + int numattr = Utilities.ReadCompressedInteger (declaration, pos, out start); + if (numattr == 0) + return dec; + + BinaryReader br = new BinaryReader (new MemoryStream (declaration)); + for (int i = 0; i < numattr; i++) { + pos = start; + SSP.SecurityAttribute sa = CreateSecurityAttribute (action, br, declaration, pos, out start, resolve); + if (sa == null) { + dec.Resolved = false; + dec.Blob = declaration; + return dec; + } + + IPermission p = sa.CreatePermission (); + dec.PermissionSet.AddPermission (p); + } + } else { + Parser.LoadXml (Encoding.Unicode.GetString (declaration)); + try { + dec.PermissionSet.FromXml (Parser.ToXml ()); + dec.PermissionSet.ToXml (); + } catch { + dec.Resolved = false; + dec.Blob = declaration; + } + } +#endif + return dec; + } + +#if !CF_1_0 && !CF_2_0 + private SSP.SecurityAttribute CreateSecurityAttribute (SecurityAction action, BinaryReader br, byte [] permset, int pos, out int start, bool resolve) + { + string cname = SignatureReader.ReadUTF8String (permset, pos, out start); + Type secattr = null; + + // note: the SecurityAction parameter isn't important to generate the XML + SSP.SecurityAttribute sa = null; + try { + secattr = Type.GetType (cname, false); + if (secattr == null) + return null; + + sa = Activator.CreateInstance (secattr, new object [] {(SSP.SecurityAction) action}) as SSP.SecurityAttribute; + } catch {} + + if (sa == null) + return null; + + // encoded length of all parameters (we don't need the value - except the updated pos) + Utilities.ReadCompressedInteger (permset, start, out pos); + int numparams = Utilities.ReadCompressedInteger (permset, pos, out start); + if (numparams == 0) + return sa; + + br.BaseStream.Position = start; + for (int j = 0; j < numparams; j++) { + bool read = false; + CustomAttrib.NamedArg na = sr.ReadNamedArg (permset, br, ref read, resolve); + if (!read) + return null; + + if (na.Field) { + FieldInfo fi = secattr.GetField (na.FieldOrPropName); + fi.SetValue (sa, na.FixedArg.Elems[0].Value); + } else if (na.Property) { + PropertyInfo pi = secattr.GetProperty (na.FieldOrPropName); + pi.SetValue (sa, na.FixedArg.Elems[0].Value, null); + } + } + + return sa; + } +#endif + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SentinelType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SentinelType.cs new file mode 100644 index 0000000..1aed160 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/SentinelType.cs @@ -0,0 +1,37 @@ +// +// SentinelType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2007 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class SentinelType : TypeSpecification { + + public SentinelType (TypeReference elementType) : base (elementType) + { + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/StructureReader.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/StructureReader.cs new file mode 100644 index 0000000..4dc5423 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/StructureReader.cs @@ -0,0 +1,274 @@ +// +// StructureReader.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.IO; + + using Mono.Cecil.Binary; + using Mono.Cecil.Metadata; + + internal sealed class StructureReader : BaseStructureVisitor { + + ImageReader m_ir; + Image m_img; + bool m_manifestOnly; + AssemblyDefinition m_asmDef; + ModuleDefinition m_module; + MetadataStreamCollection m_streams; + TablesHeap m_tHeap; + MetadataTableReader m_tableReader; + + public bool ManifestOnly { + get { return m_manifestOnly; } + } + + public ImageReader ImageReader { + get { return m_ir; } + } + + public Image Image { + get { return m_img; } + } + + public StructureReader (ImageReader ir) + { + if (ir.Image.CLIHeader == null) + throw new ImageFormatException ("The image is not a managed assembly"); + + m_ir = ir; + m_img = ir.Image; + m_streams = m_img.MetadataRoot.Streams; + m_tHeap = m_streams.TablesHeap; + m_tableReader = ir.MetadataReader.TableReader; + } + + public StructureReader (ImageReader ir, bool manifestOnly) : this (ir) + { + m_manifestOnly = manifestOnly; + } + + byte [] ReadBlob (uint pointer) + { + if (pointer == 0) + return new byte [0]; + + return m_streams.BlobHeap.Read (pointer); + } + + string ReadString (uint pointer) + { + return m_streams.StringsHeap [pointer]; + } + + public override void VisitAssemblyDefinition (AssemblyDefinition asm) + { + if (!m_tHeap.HasTable (AssemblyTable.RId)) + throw new ReflectionException ("No assembly manifest"); + + asm.MetadataToken = new MetadataToken (TokenType.Assembly, 1); + m_asmDef = asm; + + switch (m_img.MetadataRoot.Header.Version) { + case "v1.0.3705" : + asm.Runtime = TargetRuntime.NET_1_0; + break; + case "v1.1.4322" : + asm.Runtime = TargetRuntime.NET_1_1; + break; + default : + asm.Runtime = TargetRuntime.NET_2_0; + break; + } + + if ((m_img.PEFileHeader.Characteristics & ImageCharacteristics.Dll) != 0) + asm.Kind = AssemblyKind.Dll; + else if (m_img.PEOptionalHeader.NTSpecificFields.SubSystem == SubSystem.WindowsGui || + m_img.PEOptionalHeader.NTSpecificFields.SubSystem == SubSystem.WindowsCeGui) + asm.Kind = AssemblyKind.Windows; + else + asm.Kind = AssemblyKind.Console; + } + + public override void VisitAssemblyNameDefinition (AssemblyNameDefinition name) + { + AssemblyTable atable = m_tableReader.GetAssemblyTable (); + AssemblyRow arow = atable [0]; + name.Name = ReadString (arow.Name); + name.Flags = arow.Flags; + name.PublicKey = ReadBlob (arow.PublicKey); + + name.Culture = ReadString (arow.Culture); + name.Version = new Version ( + arow.MajorVersion, arow.MinorVersion, + arow.BuildNumber, arow.RevisionNumber); + name.HashAlgorithm = arow.HashAlgId; + name.MetadataToken = new MetadataToken (TokenType.Assembly, 1); + } + + public override void VisitAssemblyNameReferenceCollection (AssemblyNameReferenceCollection names) + { + if (!m_tHeap.HasTable (AssemblyRefTable.RId)) + return; + + AssemblyRefTable arTable = m_tableReader.GetAssemblyRefTable (); + for (int i = 0; i < arTable.Rows.Count; i++) { + AssemblyRefRow arRow = arTable [i]; + AssemblyNameReference aname = new AssemblyNameReference ( + ReadString (arRow.Name), + ReadString (arRow.Culture), + new Version (arRow.MajorVersion, arRow.MinorVersion, + arRow.BuildNumber, arRow.RevisionNumber)); + aname.PublicKeyToken = ReadBlob (arRow.PublicKeyOrToken); + aname.Hash = ReadBlob (arRow.HashValue); + aname.Flags = arRow.Flags; + aname.MetadataToken = new MetadataToken (TokenType.AssemblyRef, (uint) i + 1); + names.Add (aname); + } + } + + public override void VisitResourceCollection (ResourceCollection resources) + { + if (!m_tHeap.HasTable (ManifestResourceTable.RId)) + return; + + ManifestResourceTable mrTable = m_tableReader.GetManifestResourceTable (); + FileTable fTable = m_tableReader.GetFileTable (); + + for (int i = 0; i < mrTable.Rows.Count; i++) { + ManifestResourceRow mrRow = mrTable [i]; + if (mrRow.Implementation.RID == 0) { + EmbeddedResource eres = new EmbeddedResource ( + ReadString (mrRow.Name), mrRow.Flags); + + BinaryReader br = m_ir.MetadataReader.GetDataReader ( + m_img.CLIHeader.Resources.VirtualAddress); + br.BaseStream.Position += mrRow.Offset; + + eres.Data = br.ReadBytes (br.ReadInt32 ()); + + resources.Add (eres); + continue; + } + + switch (mrRow.Implementation.TokenType) { + case TokenType.File : + FileRow fRow = fTable [(int) mrRow.Implementation.RID - 1]; + LinkedResource lres = new LinkedResource ( + ReadString (mrRow.Name), mrRow.Flags, + ReadString (fRow.Name)); + lres.Hash = ReadBlob (fRow.HashValue); + resources.Add (lres); + break; + case TokenType.AssemblyRef : + AssemblyNameReference asm = + m_module.AssemblyReferences [(int) mrRow.Implementation.RID - 1]; + AssemblyLinkedResource alr = new AssemblyLinkedResource ( + ReadString (mrRow.Name), + mrRow.Flags, asm); + resources.Add (alr); + break; + } + } + } + + public override void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules) + { + ModuleTable mt = m_tableReader.GetModuleTable (); + if (mt == null || mt.Rows.Count != 1) + throw new ReflectionException ("Can not read main module"); + + ModuleRow mr = mt [0]; + string name = ReadString (mr.Name); + ModuleDefinition main = new ModuleDefinition (name, m_asmDef, this, true); + main.Mvid = m_streams.GuidHeap [mr.Mvid]; + main.MetadataToken = new MetadataToken (TokenType.Module, 1); + modules.Add (main); + m_module = main; + m_module.Accept (this); + + FileTable ftable = m_tableReader.GetFileTable (); + if (ftable == null || ftable.Rows.Count == 0) + return; + + foreach (FileRow frow in ftable.Rows) { + if (frow.Flags != FileAttributes.ContainsMetaData) + continue; + + name = ReadString (frow.Name); + FileInfo location = new FileInfo ( + m_img.FileInformation != null ? Path.Combine (m_img.FileInformation.DirectoryName, name) : name); + if (!File.Exists (location.FullName)) + throw new FileNotFoundException ("Module not found : " + name); + + try { + ImageReader module = ImageReader.Read (location.FullName); + mt = module.Image.MetadataRoot.Streams.TablesHeap [ModuleTable.RId] as ModuleTable; + if (mt == null || mt.Rows.Count != 1) + throw new ReflectionException ("Can not read module : " + name); + + mr = mt [0]; + ModuleDefinition modext = new ModuleDefinition (name, m_asmDef, + new StructureReader (module, m_manifestOnly), false); + modext.Mvid = module.Image.MetadataRoot.Streams.GuidHeap [mr.Mvid]; + + modules.Add (modext); + modext.Accept (this); + } catch (ReflectionException) { + throw; + } catch (Exception e) { + throw new ReflectionException ("Can not read module : " + name, e); + } + } + } + + public override void VisitModuleReferenceCollection (ModuleReferenceCollection modules) + { + if (!m_tHeap.HasTable (ModuleRefTable.RId)) + return; + + ModuleRefTable mrTable = m_tableReader.GetModuleRefTable (); + for (int i = 0; i < mrTable.Rows.Count; i++) { + ModuleRefRow mrRow = mrTable [i]; + ModuleReference mod = new ModuleReference (ReadString (mrRow.Name)); + mod.MetadataToken = MetadataToken.FromMetadataRow (TokenType.ModuleRef, i); + modules.Add (mod); + } + } + + public override void TerminateAssemblyDefinition (AssemblyDefinition asm) + { + if (m_manifestOnly) + return; + + foreach (ModuleDefinition mod in asm.Modules) + mod.Controller.Reader.VisitModuleDefinition (mod); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/StructureWriter.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/StructureWriter.cs new file mode 100644 index 0000000..6c24aac --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/StructureWriter.cs @@ -0,0 +1,246 @@ +// +// StructureWriter.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.IO; + + using Mono.Cecil.Binary; + using Mono.Cecil.Metadata; + + internal sealed class StructureWriter : BaseStructureVisitor { + + MetadataWriter m_mdWriter; + MetadataTableWriter m_tableWriter; + MetadataRowWriter m_rowWriter; + + AssemblyDefinition m_asm; + BinaryWriter m_binaryWriter; + + public AssemblyDefinition Assembly { + get { return m_asm; } + } + + static void ResetImage (ModuleDefinition mod) + { + Image ni = Image.CreateImage (); + ni.Accept (new CopyImageVisitor (mod.Image)); + mod.Image = ni; + } + + public StructureWriter (AssemblyDefinition asm, BinaryWriter writer) + { + m_asm = asm; + m_binaryWriter = writer; + } + + public BinaryWriter GetWriter () + { + return m_binaryWriter; + } + + public override void VisitAssemblyDefinition (AssemblyDefinition asm) + { + if (asm.Kind != AssemblyKind.Dll && asm.EntryPoint == null) + throw new ReflectionException ("Assembly does not have an entry point defined"); + + if ((asm.MainModule.Image.CLIHeader.Flags & RuntimeImage.ILOnly) == 0) + throw new NotSupportedException ("Can not write a mixed mode assembly"); + + foreach (ModuleDefinition module in asm.Modules) + if (module.Image.CLIHeader.Metadata.VirtualAddress != RVA.Zero) + ResetImage (module); + + ReflectionWriter rw = asm.MainModule.Controller.Writer; + rw.StructureWriter = this; + + m_mdWriter = rw.MetadataWriter; + m_tableWriter = rw.MetadataTableWriter; + m_rowWriter = rw.MetadataRowWriter; + + if (!rw.SaveSymbols) + return; + + FileStream fs = m_binaryWriter.BaseStream as FileStream; + if (fs != null) + rw.OutputFile = fs.Name; + } + + public override void VisitAssemblyNameDefinition (AssemblyNameDefinition name) + { + AssemblyTable asmTable = m_tableWriter.GetAssemblyTable (); + + if (name.PublicKey != null && name.PublicKey.Length > 0) + name.Flags |= AssemblyFlags.PublicKey; + + AssemblyRow asmRow = m_rowWriter.CreateAssemblyRow ( + name.HashAlgorithm, + (ushort) name.Version.Major, + (ushort) name.Version.Minor, + (ushort) name.Version.Build, + (ushort) name.Version.Revision, + name.Flags, + m_mdWriter.AddBlob (name.PublicKey), + m_mdWriter.AddString (name.Name), + m_mdWriter.AddString (name.Culture)); + + asmTable.Rows.Add (asmRow); + } + + public override void VisitAssemblyNameReferenceCollection (AssemblyNameReferenceCollection references) + { + foreach (AssemblyNameReference name in references) + VisitAssemblyNameReference (name); + } + + public override void VisitAssemblyNameReference (AssemblyNameReference name) + { + byte [] pkortoken; + if (name.PublicKey != null && name.PublicKey.Length > 0) + pkortoken = name.PublicKey; + else if (name.PublicKeyToken != null && name.PublicKeyToken.Length > 0) + pkortoken = name.PublicKeyToken; + else + pkortoken = new byte [0]; + + AssemblyRefTable arTable = m_tableWriter.GetAssemblyRefTable (); + AssemblyRefRow arRow = m_rowWriter.CreateAssemblyRefRow ( + (ushort) name.Version.Major, + (ushort) name.Version.Minor, + (ushort) name.Version.Build, + (ushort) name.Version.Revision, + name.Flags, + m_mdWriter.AddBlob (pkortoken), + m_mdWriter.AddString (name.Name), + m_mdWriter.AddString (name.Culture), + m_mdWriter.AddBlob (name.Hash)); + + arTable.Rows.Add (arRow); + } + + public override void VisitResourceCollection (ResourceCollection resources) + { + VisitCollection (resources); + } + + public override void VisitEmbeddedResource (EmbeddedResource res) + { + AddManifestResource ( + m_mdWriter.AddResource (res.Data), + res.Name, res.Flags, + new MetadataToken (TokenType.ManifestResource, 0)); + } + + public override void VisitLinkedResource (LinkedResource res) + { + FileTable fTable = m_tableWriter.GetFileTable (); + FileRow fRow = m_rowWriter.CreateFileRow ( + Mono.Cecil.FileAttributes.ContainsNoMetaData, + m_mdWriter.AddString (res.File), + m_mdWriter.AddBlob (res.Hash)); + + fTable.Rows.Add (fRow); + + AddManifestResource ( + 0, res.Name, res.Flags, + new MetadataToken (TokenType.File, (uint) fTable.Rows.IndexOf (fRow) + 1)); + } + + public override void VisitAssemblyLinkedResource (AssemblyLinkedResource res) + { + MetadataToken impl = new MetadataToken (TokenType.AssemblyRef, + (uint) m_asm.MainModule.AssemblyReferences.IndexOf (res.Assembly) + 1); + + AddManifestResource (0, res.Name, res.Flags, impl); + } + + void AddManifestResource (uint offset, string name, ManifestResourceAttributes flags, MetadataToken impl) + { + ManifestResourceTable mrTable = m_tableWriter.GetManifestResourceTable (); + ManifestResourceRow mrRow = m_rowWriter.CreateManifestResourceRow ( + offset, + flags, + m_mdWriter.AddString (name), + impl); + + mrTable.Rows.Add (mrRow); + } + + public override void VisitModuleDefinitionCollection (ModuleDefinitionCollection modules) + { + VisitCollection (modules); + } + + public override void VisitModuleDefinition (ModuleDefinition module) + { + if (module.Main) { + ModuleTable modTable = m_tableWriter.GetModuleTable (); + ModuleRow modRow = m_rowWriter.CreateModuleRow ( + 0, + m_mdWriter.AddString (module.Name), + m_mdWriter.AddGuid (module.Mvid), + 0, + 0); + + modTable.Rows.Add (modRow); + } else { + // multiple module assemblies + throw new NotImplementedException (); + } + } + + public override void VisitModuleReferenceCollection (ModuleReferenceCollection modules) + { + VisitCollection (modules); + } + + public override void VisitModuleReference (ModuleReference module) + { + ModuleRefTable mrTable = m_tableWriter.GetModuleRefTable (); + ModuleRefRow mrRow = m_rowWriter.CreateModuleRefRow ( + m_mdWriter.AddString (module.Name)); + + mrTable.Rows.Add (mrRow); + } + + public override void TerminateAssemblyDefinition (AssemblyDefinition asm) + { + foreach (ModuleDefinition mod in asm.Modules) { + ReflectionWriter writer = mod.Controller.Writer; + writer.VisitModuleDefinition (mod); + writer.VisitTypeReferenceCollection (mod.TypeReferences); + writer.VisitTypeDefinitionCollection (mod.Types); + writer.VisitMemberReferenceCollection (mod.MemberReferences); + writer.CompleteTypeDefinitions (); + + writer.TerminateModuleDefinition (mod); + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TableComparers.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TableComparers.cs new file mode 100644 index 0000000..88b76ba --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TableComparers.cs @@ -0,0 +1,276 @@ +// +// TableComparers.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + + using Mono.Cecil.Metadata; + + class TableComparers { + + public sealed class TypeDef : IComparer { + + public static readonly TypeDef Instance = new TypeDef (); + + public int Compare (object x, object y) + { + TypeDefinition a = x as TypeDefinition; + TypeDefinition b = y as TypeDefinition; + + if (a == null || b == null) + throw new ReflectionException ("TypeDefComparer can only compare TypeDefinition"); + + if (a.Name == Constants.ModuleType && b.Name == Constants.ModuleType) + return 0; + else if (a.Name == Constants.ModuleType) + return -1; + else if (b.Name == Constants.ModuleType) + return 1; + + return Comparer.Default.Compare (a.FullName, b.FullName); + } + } + + public class TypeRef : IComparer { + + public static readonly TypeRef Instance = new TypeRef (); + + public int Compare (object x, object y) + { + TypeReference a = x as TypeReference; + TypeReference b = y as TypeReference; + + if (a == null || b == null) + throw new ReflectionException ("TypeRefComparer can only compare TypeReference"); + + if (b.DeclaringType == a) + return -1; + else if (a.DeclaringType == b) + return 1; + + return Comparer.Default.Compare (a.FullName, b.FullName); + } + } + + public class NestedClass : IComparer { + + public static readonly NestedClass Instance = new NestedClass (); + + public int Compare (object x, object y) + { + NestedClassRow a = x as NestedClassRow; + NestedClassRow b = y as NestedClassRow; + + return Comparer.Default.Compare (a.NestedClass, b.NestedClass); + } + } + + public class Constant : IComparer { + + public static readonly Constant Instance = new Constant (); + + public int Compare (object x, object y) + { + ConstantRow a = x as ConstantRow; + ConstantRow b = y as ConstantRow; + + return Comparer.Default.Compare ( + Utilities.CompressMetadataToken (CodedIndex.HasConstant, a.Parent), + Utilities.CompressMetadataToken (CodedIndex.HasConstant, b.Parent)); + } + + } + + public class InterfaceImpl : IComparer { + + public static readonly InterfaceImpl Instance = new InterfaceImpl (); + + public int Compare (object x, object y) + { + InterfaceImplRow a = x as InterfaceImplRow; + InterfaceImplRow b = y as InterfaceImplRow; + + int klass = Comparer.Default.Compare (a.Class, b.Class); + + if (klass == 0) + return Comparer.Default.Compare ( + Utilities.CompressMetadataToken (CodedIndex.TypeDefOrRef, a.Interface), + Utilities.CompressMetadataToken (CodedIndex.TypeDefOrRef, b.Interface)); + + return klass; + } + } + + public class MethodSem : IComparer { + + public static readonly MethodSem Instance = new MethodSem (); + + public int Compare (object x, object y) + { + MethodSemanticsRow a = x as MethodSemanticsRow; + MethodSemanticsRow b = y as MethodSemanticsRow; + + return Comparer.Default.Compare ( + Utilities.CompressMetadataToken (CodedIndex.HasSemantics, a.Association), + Utilities.CompressMetadataToken (CodedIndex.HasSemantics, b.Association)); + } + } + + public class CustomAttribute : IComparer { + + public static readonly CustomAttribute Instance = new CustomAttribute (); + + public int Compare (object x, object y) + { + CustomAttributeRow a = x as CustomAttributeRow; + CustomAttributeRow b = y as CustomAttributeRow; + + return Comparer.Default.Compare ( + Utilities.CompressMetadataToken (CodedIndex.HasCustomAttribute, a.Parent), + Utilities.CompressMetadataToken (CodedIndex.HasCustomAttribute, b.Parent)); + } + } + + public class SecurityDeclaration : IComparer { + + public static readonly SecurityDeclaration Instance = new SecurityDeclaration (); + + public int Compare (object x, object y) + { + DeclSecurityRow a = x as DeclSecurityRow; + DeclSecurityRow b = y as DeclSecurityRow; + + return Comparer.Default.Compare ( + Utilities.CompressMetadataToken (CodedIndex.HasDeclSecurity, a.Parent), + Utilities.CompressMetadataToken (CodedIndex.HasDeclSecurity, b.Parent)); + } + } + + public class Override : IComparer { + + public static readonly Override Instance = new Override (); + + public int Compare (object x, object y) + { + MethodImplRow a = x as MethodImplRow; + MethodImplRow b = y as MethodImplRow; + + return Comparer.Default.Compare (a.Class, b.Class); + } + } + + public class PInvoke : IComparer { + + public static readonly PInvoke Instance = new PInvoke (); + + public int Compare (object x, object y) + { + ImplMapRow a = x as ImplMapRow; + ImplMapRow b = y as ImplMapRow; + + return Comparer.Default.Compare (a.MemberForwarded.RID, b.MemberForwarded.RID); + } + } + + public class FieldRVA : IComparer { + + public static readonly FieldRVA Instance = new FieldRVA (); + + public int Compare (object x, object y) + { + FieldRVARow a = x as FieldRVARow; + FieldRVARow b = y as FieldRVARow; + + return Comparer.Default.Compare (a.Field, b.Field); + } + } + + public class FieldLayout : IComparer { + + public static readonly FieldLayout Instance = new FieldLayout (); + + public int Compare (object x, object y) + { + FieldLayoutRow a = x as FieldLayoutRow; + FieldLayoutRow b = y as FieldLayoutRow; + + return Comparer.Default.Compare (a.Field, b.Field); + } + } + + public class FieldMarshal : IComparer { + + public static readonly FieldMarshal Instance = new FieldMarshal (); + + public int Compare (object x, object y) + { + FieldMarshalRow a = x as FieldMarshalRow; + FieldMarshalRow b = y as FieldMarshalRow; + + return Comparer.Default.Compare ( + Utilities.CompressMetadataToken (CodedIndex.HasFieldMarshal, a.Parent), + Utilities.CompressMetadataToken (CodedIndex.HasFieldMarshal, b.Parent)); + } + } + + public class TypeLayout : IComparer { + + public static readonly TypeLayout Instance = new TypeLayout (); + + public int Compare (object x, object y) + { + ClassLayoutRow a = x as ClassLayoutRow; + ClassLayoutRow b = y as ClassLayoutRow; + + return Comparer.Default.Compare (a.Parent, b.Parent); + } + } + + public class GenericParam : IComparer { + + public static readonly GenericParam Instance = new GenericParam (); + + public int Compare (object x, object y) + { + GenericParameter a = x as GenericParameter; + GenericParameter b = y as GenericParameter; + + int token = Comparer.Default.Compare ( + Utilities.CompressMetadataToken (CodedIndex.TypeOrMethodDef, a.Owner.MetadataToken), + Utilities.CompressMetadataToken (CodedIndex.TypeOrMethodDef, b.Owner.MetadataToken)); + + if (token == 0) + return Comparer.Default.Compare (a.Position, b.Position); + + return token; + } + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TargetRuntime.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TargetRuntime.cs new file mode 100644 index 0000000..38bdf6e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TargetRuntime.cs @@ -0,0 +1,36 @@ +// +// TargetRuntime.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public enum TargetRuntime { + NET_1_0, + NET_1_1, + NET_2_0 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeAttributes.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeAttributes.cs new file mode 100644 index 0000000..e35f2ce --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeAttributes.cs @@ -0,0 +1,79 @@ +// +// TypeAttributes.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + [Flags] + public enum TypeAttributes : uint { + // Visibility attributes + VisibilityMask = 0x00000007, // Use this mask to retrieve visibility information + NotPublic = 0x00000000, // Class has no public scope + Public = 0x00000001, // Class has public scope + NestedPublic = 0x00000002, // Class is nested with public visibility + NestedPrivate = 0x00000003, // Class is nested with private visibility + NestedFamily = 0x00000004, // Class is nested with family visibility + NestedAssembly = 0x00000005, // Class is nested with assembly visibility + NestedFamANDAssem = 0x00000006, // Class is nested with family and assembly visibility + NestedFamORAssem = 0x00000007, // Class is nested with family or assembly visibility + + // Class layout attributes + LayoutMask = 0x00000018, // Use this mask to retrieve class layout information + AutoLayout = 0x00000000, // Class fields are auto-laid out + SequentialLayout = 0x00000008, // Class fields are laid out sequentially + ExplicitLayout = 0x00000010, // Layout is supplied explicitly + + // Class semantics attributes + ClassSemanticMask = 0x00000020, // Use this mask to retrieve class semantics information + Class = 0x00000000, // Type is a class + Interface = 0x00000020, // Type is an interface + + // Special semantics in addition to class semantics + Abstract = 0x00000080, // Class is abstract + Sealed = 0x00000100, // Class cannot be extended + SpecialName = 0x00000400, // Class name is special + + // Implementation attributes + Import = 0x00001000, // Class/Interface is imported + Serializable = 0x00002000, // Class is serializable + + // String formatting attributes + StringFormatMask = 0x00030000, // Use this mask to retrieve string information for native interop + AnsiClass = 0x00000000, // LPSTR is interpreted as ANSI + UnicodeClass = 0x00010000, // LPSTR is interpreted as Unicode + AutoClass = 0x00020000, // LPSTR is interpreted automatically + + // Class initialization attributes + BeforeFieldInit = 0x00100000, // Initialize the class before first static field access + + // Additional flags + RTSpecialName = 0x00000800, // CLI provides 'special' behavior, depending upon the name of the Type + HasSecurity = 0x00040000 // Type has security associate with it + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeDefinition.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeDefinition.cs new file mode 100644 index 0000000..ea34d9f --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeDefinition.cs @@ -0,0 +1,499 @@ +// +// TypeDefinition.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public sealed class TypeDefinition : TypeReference, IMemberDefinition, IHasSecurity { + + TypeAttributes m_attributes; + TypeReference m_baseType; + + bool m_hasInfo; + ushort m_packingSize; + uint m_classSize; + + InterfaceCollection m_interfaces; + NestedTypeCollection m_nestedTypes; + MethodDefinitionCollection m_methods; + ConstructorCollection m_ctors; + FieldDefinitionCollection m_fields; + EventDefinitionCollection m_events; + PropertyDefinitionCollection m_properties; + SecurityDeclarationCollection m_secDecls; + + public TypeAttributes Attributes { + get { return m_attributes; } + set { m_attributes = value; } + } + + public TypeReference BaseType { + get { return m_baseType; } + set { m_baseType = value; } + } + + public bool HasLayoutInfo { + get { return m_hasInfo; } + } + + public ushort PackingSize { + get { return m_packingSize; } + set { + m_hasInfo = true; + m_packingSize = value; + } + } + + public uint ClassSize { + get { return m_classSize; } + set { + m_hasInfo = true; + m_classSize = value; + } + } + + public InterfaceCollection Interfaces { + get { + if (m_interfaces == null) + m_interfaces = new InterfaceCollection (this); + + return m_interfaces; + } + } + + public NestedTypeCollection NestedTypes { + get { + if (m_nestedTypes == null) + m_nestedTypes = new NestedTypeCollection (this); + + return m_nestedTypes; + } + } + + public MethodDefinitionCollection Methods { + get { + if (m_methods == null) + m_methods = new MethodDefinitionCollection (this); + + return m_methods; + } + } + + public ConstructorCollection Constructors { + get { + if (m_ctors == null) + m_ctors = new ConstructorCollection (this); + + return m_ctors; + } + } + + public FieldDefinitionCollection Fields { + get { + if (m_fields == null) + m_fields = new FieldDefinitionCollection (this); + + return m_fields; + } + } + + public EventDefinitionCollection Events { + get { + if (m_events == null) + m_events = new EventDefinitionCollection (this); + + return m_events; + } + } + + public PropertyDefinitionCollection Properties { + get { + if (m_properties == null) + m_properties = new PropertyDefinitionCollection (this); + + return m_properties; + } + } + + public SecurityDeclarationCollection SecurityDeclarations { + get { + if (m_secDecls == null) + m_secDecls = new SecurityDeclarationCollection (this); + + return m_secDecls; + } + } + + #region TypeAttributes + + public bool IsNotPublic { + get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic; } + set { + if (value) { + m_attributes &= ~TypeAttributes.VisibilityMask; + m_attributes |= TypeAttributes.NotPublic; + } else + m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NotPublic); + } + } + + public bool IsPublic { + get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public; } + set { + if (value) { + m_attributes &= ~TypeAttributes.VisibilityMask; + m_attributes |= TypeAttributes.Public; + } else + m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.Public); + } + } + + public bool IsNestedPublic { + get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic; } + set { + if (value) { + m_attributes &= ~TypeAttributes.VisibilityMask; + m_attributes |= TypeAttributes.NestedPublic; + } else + m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedPublic); + } + } + + public bool IsNestedPrivate { + get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate; } + set { + if (value) { + m_attributes &= ~TypeAttributes.VisibilityMask; + m_attributes |= TypeAttributes.NestedPrivate; + } else + m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedPrivate); + } + } + + public bool IsNestedFamily { + get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily; } + set { + if (value) { + m_attributes &= ~TypeAttributes.VisibilityMask; + m_attributes |= TypeAttributes.NestedFamily; + } else + m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedFamily); + } + } + + public bool IsNestedAssembly { + get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly; } + set { + if (value) { + m_attributes &= ~TypeAttributes.VisibilityMask; + m_attributes |= TypeAttributes.NestedAssembly; + } else + m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedAssembly); + } + } + + public bool IsNestedFamilyAndAssembly { + get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem; } + set { + if (value) { + m_attributes &= ~TypeAttributes.VisibilityMask; + m_attributes |= TypeAttributes.NestedFamANDAssem; + } else + m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedFamANDAssem); + } + } + + public bool IsNestedFamilyOrAssembly { + get { return (m_attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem; } + set { + if (value) { + m_attributes &= ~TypeAttributes.VisibilityMask; + m_attributes |= TypeAttributes.NestedFamORAssem; + } else + m_attributes &= ~(TypeAttributes.VisibilityMask & TypeAttributes.NestedFamORAssem); + } + } + + public bool IsAutoLayout { + get { return (m_attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout; } + set { + if (value) { + m_attributes &= ~TypeAttributes.LayoutMask; + m_attributes |= TypeAttributes.AutoLayout; + } else + m_attributes &= ~(TypeAttributes.LayoutMask & TypeAttributes.AutoLayout); + } + } + + public bool IsSequentialLayout { + get { return (m_attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout; } + set { + if (value) { + m_attributes &= ~TypeAttributes.LayoutMask; + m_attributes |= TypeAttributes.SequentialLayout; + } else + m_attributes &= ~(TypeAttributes.LayoutMask & TypeAttributes.SequentialLayout); + } + } + + public bool IsExplicitLayout { + get { return (m_attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout; } + set { + if (value) { + m_attributes &= ~TypeAttributes.LayoutMask; + m_attributes |= TypeAttributes.ExplicitLayout; + } else + m_attributes &= ~(TypeAttributes.LayoutMask & TypeAttributes.ExplicitLayout); + } + } + + public bool IsClass { + get { return (m_attributes & TypeAttributes.ClassSemanticMask) == TypeAttributes.Class; } + set { + if (value) { + m_attributes &= ~TypeAttributes.ClassSemanticMask; + m_attributes |= TypeAttributes.Class; + } else + m_attributes &= ~(TypeAttributes.ClassSemanticMask & TypeAttributes.Class); + } + } + + public bool IsInterface { + get { return (m_attributes & TypeAttributes.ClassSemanticMask) == TypeAttributes.Interface; } + set { + if (value) { + m_attributes &= ~TypeAttributes.ClassSemanticMask; + m_attributes |= TypeAttributes.Interface; + } else + m_attributes &= ~(TypeAttributes.ClassSemanticMask & TypeAttributes.Interface); + } + } + + public bool IsAbstract { + get { return (m_attributes & TypeAttributes.Abstract) != 0; } + set { + if (value) + m_attributes |= TypeAttributes.Abstract; + else + m_attributes &= ~TypeAttributes.Abstract; + } + } + + public bool IsSealed { + get { return (m_attributes & TypeAttributes.Sealed) != 0; } + set { + if (value) + m_attributes |= TypeAttributes.Sealed; + else + m_attributes &= ~TypeAttributes.Sealed; + } + } + + public bool IsSpecialName { + get { return (m_attributes & TypeAttributes.SpecialName) != 0; } + set { + if (value) + m_attributes |= TypeAttributes.SpecialName; + else + m_attributes &= ~TypeAttributes.SpecialName; + } + } + + public bool IsImport { + get { return (m_attributes & TypeAttributes.Import) != 0; } + set { + if (value) + m_attributes |= TypeAttributes.Import; + else + m_attributes &= ~TypeAttributes.Import; + } + } + + public bool IsSerializable { + get { return (m_attributes & TypeAttributes.Serializable) != 0; } + set { + if (value) + m_attributes |= TypeAttributes.Serializable; + else + m_attributes &= ~TypeAttributes.Serializable; + } + } + + public bool IsAnsiClass { + get { return (m_attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AnsiClass; } + set { + if (value) { + m_attributes &= ~TypeAttributes.StringFormatMask; + m_attributes |= TypeAttributes.AnsiClass; + } else + m_attributes &= ~(TypeAttributes.StringFormatMask & TypeAttributes.AnsiClass); + } + } + + public bool IsUnicodeClass { + get { return (m_attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass; } + set { + if (value) { + m_attributes &= ~TypeAttributes.StringFormatMask; + m_attributes |= TypeAttributes.UnicodeClass; + } else + m_attributes &= ~(TypeAttributes.StringFormatMask & TypeAttributes.UnicodeClass); + } + } + + public bool IsAutoClass { + get { return (m_attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass; } + set { + if (value) { + m_attributes &= ~TypeAttributes.StringFormatMask; + m_attributes |= TypeAttributes.AutoClass; + } else + m_attributes &= ~(TypeAttributes.StringFormatMask & TypeAttributes.AutoClass); + } + } + + public bool IsBeforeFieldInit { + get { return (m_attributes & TypeAttributes.BeforeFieldInit) != 0; } + set { + if (value) + m_attributes |= TypeAttributes.BeforeFieldInit; + else + m_attributes &= ~TypeAttributes.BeforeFieldInit; + } + } + + public bool IsRuntimeSpecialName { + get { return (m_attributes & TypeAttributes.RTSpecialName) != 0; } + set { + if (value) + m_attributes |= TypeAttributes.RTSpecialName; + else + m_attributes &= ~TypeAttributes.RTSpecialName; + } + } + + public bool HasSecurity { + get { return (m_attributes & TypeAttributes.HasSecurity) != 0; } + set { + if (value) + m_attributes |= TypeAttributes.HasSecurity; + else + m_attributes &= ~TypeAttributes.HasSecurity; + } + } + + #endregion + + public bool IsEnum { + get { return m_baseType != null && m_baseType.FullName == Constants.Enum; } + } + + public override bool IsValueType { + get { + return m_baseType != null && ( + this.IsEnum || m_baseType.FullName == Constants.ValueType); + } + } + + internal TypeDefinition (string name, string ns, TypeAttributes attrs) : + base (name, ns) + { + m_hasInfo = false; + m_attributes = attrs; + } + + public TypeDefinition (string name, string ns, + TypeAttributes attributes, TypeReference baseType) : + this (name, ns, attributes) + { + this.BaseType = baseType; + } + + public TypeDefinition Clone () + { + return Clone (this, new ImportContext (NullReferenceImporter.Instance, this)); + } + + internal static TypeDefinition Clone (TypeDefinition type, ImportContext context) + { + TypeDefinition nt = new TypeDefinition ( + type.Name, + type.Namespace, + type.Attributes); + + context.GenericContext.Type = nt; + + foreach (GenericParameter p in type.GenericParameters) + nt.GenericParameters.Add (GenericParameter.Clone (p, context)); + + if (type.BaseType != null) + nt.BaseType = context.Import (type.BaseType); + + if (type.HasLayoutInfo) { + nt.ClassSize = type.ClassSize; + nt.PackingSize = type.PackingSize; + } + + foreach (FieldDefinition field in type.Fields) + nt.Fields.Add (FieldDefinition.Clone (field, context)); + foreach (MethodDefinition ctor in type.Constructors) + nt.Constructors.Add (MethodDefinition.Clone (ctor, context)); + foreach (MethodDefinition meth in type.Methods) + nt.Methods.Add (MethodDefinition.Clone (meth, context)); + foreach (EventDefinition evt in type.Events) + nt.Events.Add (EventDefinition.Clone (evt, context)); + foreach (PropertyDefinition prop in type.Properties) + nt.Properties.Add (PropertyDefinition.Clone (prop, context)); + foreach (TypeReference intf in type.Interfaces) + nt.Interfaces.Add (context.Import (intf)); + foreach (TypeDefinition nested in type.NestedTypes) + nt.NestedTypes.Add (Clone (nested, context)); + foreach (CustomAttribute ca in type.CustomAttributes) + nt.CustomAttributes.Add (CustomAttribute.Clone (ca, context)); + foreach (SecurityDeclaration dec in type.SecurityDeclarations) + nt.SecurityDeclarations.Add (SecurityDeclaration.Clone (dec)); + + return nt; + } + + public override void Accept (IReflectionVisitor visitor) + { + visitor.VisitTypeDefinition (this); + + this.GenericParameters.Accept (visitor); + this.Interfaces.Accept (visitor); + this.Constructors.Accept (visitor); + this.Methods.Accept (visitor); + this.Fields.Accept (visitor); + this.Properties.Accept (visitor); + this.Events.Accept (visitor); + this.NestedTypes.Accept (visitor); + this.CustomAttributes.Accept (visitor); + this.SecurityDeclarations.Accept (visitor); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs new file mode 100644 index 0000000..6bd233b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeDefinitionCollection.cs @@ -0,0 +1,216 @@ +// +// TypeDefinitionCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:56 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + using System.Collections.Specialized; + + using Mono.Cecil.Cil; + + using Hcp = Mono.Cecil.HashCodeProvider; + using Cmp = System.Collections.Comparer; + + public sealed class TypeDefinitionCollection : NameObjectCollectionBase, IList, IReflectionVisitable { + + ModuleDefinition m_container; + + public TypeDefinition this [int index] { + get { return this.BaseGet (index) as TypeDefinition; } + set { this.BaseSet (index, value); } + } + + public TypeDefinition this [string fullName] { + get { return this.BaseGet (fullName) as TypeDefinition; } + set { this.BaseSet (fullName, value); } + } + + public ModuleDefinition Container { + get { return m_container; } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + bool IList.IsReadOnly { + get { return false; } + } + + bool IList.IsFixedSize { + get { return false; } + } + + object IList.this [int index] { + get { return BaseGet (index); } + set { + Check (value); + BaseSet (index, value); + } + } + + public TypeDefinitionCollection (ModuleDefinition container) : + base (Hcp.Instance, Cmp.Default) + { + m_container = container; + } + + public void Add (TypeDefinition value) + { + if (value == null) + throw new ArgumentNullException ("value"); + + Attach (value); + + this.BaseAdd (value.FullName, value); + } + + public void Clear () + { + foreach (TypeDefinition item in this) + Detach (item); + + this.BaseClear (); + } + + public bool Contains (TypeDefinition value) + { + return Contains (value.FullName); + } + + public bool Contains (string fullName) + { + return this.BaseGet (fullName) != null; + } + + public int IndexOf (TypeDefinition value) + { + string [] keys = this.BaseGetAllKeys (); + return Array.IndexOf (keys, value.FullName, 0, keys.Length); + } + + public void Remove (TypeDefinition value) + { + this.BaseRemove (value.FullName); + + Detach (value); + } + + public void RemoveAt (int index) + { + TypeDefinition item = this [index]; + Remove (item); + + Detach (item); + } + + public void CopyTo (Array ary, int index) + { + this.BaseGetAllValues ().CopyTo (ary, index); + } + + public new IEnumerator GetEnumerator () + { + return this.BaseGetAllValues ().GetEnumerator (); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitTypeDefinitionCollection (this); + } + +#if CF_1_0 || CF_2_0 + internal object [] BaseGetAllValues () + { + object [] values = new object [this.Count]; + for (int i=0; i < values.Length; ++i) { + values [i] = this.BaseGet (i); + } + return values; + } +#endif + + void Check (object value) + { + if (!(value is TypeDefinition)) + throw new ArgumentException (); + } + + int IList.Add (object value) + { + Check (value); + Add (value as TypeDefinition); + return 0; + } + + bool IList.Contains (object value) + { + Check (value); + return Contains (value as TypeDefinition); + } + + int IList.IndexOf (object value) + { + throw new NotSupportedException (); + } + + void IList.Insert (int index, object value) + { + throw new NotSupportedException (); + } + + void IList.Remove (object value) + { + Check (value); + Remove (value as TypeDefinition); + } + + void Detach (TypeReference type) + { + type.Module = null; + } + + void Attach (TypeReference type) + { + if (type.Module != null) + throw new ReflectionException ("Type is already attached, clone it instead"); + + type.Module = m_container; + type.AttachToScope (m_container); + + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeReference.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeReference.cs new file mode 100644 index 0000000..9e373ee --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeReference.cs @@ -0,0 +1,153 @@ +// +// TypeReference.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public class TypeReference : MemberReference, IGenericParameterProvider, ICustomAttributeProvider { + + string m_namespace; + bool m_fullNameDiscarded; + string m_fullName; + protected bool m_isValueType; + IMetadataScope m_scope; + ModuleDefinition m_module; + + CustomAttributeCollection m_customAttrs; + GenericParameterCollection m_genparams; + + public override string Name { + get { return base.Name; } + set { + base.Name = value; + m_fullNameDiscarded = true; + } + } + + public virtual string Namespace { + get { return m_namespace; } + set { + m_namespace = value; + m_fullNameDiscarded = true; + } + } + + public virtual bool IsValueType { + get { return m_isValueType; } + set { m_isValueType = value; } + } + + public virtual ModuleDefinition Module { + get { return m_module; } + set { m_module = value; } + } + + public CustomAttributeCollection CustomAttributes { + get { + if (m_customAttrs == null) + m_customAttrs = new CustomAttributeCollection (this); + + return m_customAttrs; + } + } + + public GenericParameterCollection GenericParameters { + get { + if (m_genparams == null) + m_genparams = new GenericParameterCollection (this); + return m_genparams; + } + } + + public virtual IMetadataScope Scope { + get { + if (this.DeclaringType != null) + return this.DeclaringType.Scope; + + return m_scope; + } + } + + public bool IsNested { + get { return this.DeclaringType != null; } + } + + public virtual string FullName { + get { + if (m_fullName != null && !m_fullNameDiscarded) + return m_fullName; + + if (this.IsNested) + return string.Concat (this.DeclaringType.FullName, "/", this.Name); + + if (m_namespace == null || m_namespace.Length == 0) + return this.Name; + + m_fullName = string.Concat (m_namespace, ".", this.Name); + m_fullNameDiscarded = false; + return m_fullName; + } + } + + protected TypeReference (string name, string ns) : base (name) + { + m_namespace = ns; + m_fullNameDiscarded = false; + } + + internal TypeReference (string name, string ns, IMetadataScope scope) : this (name, ns) + { + m_scope = scope; + } + + public TypeReference (string name, string ns, IMetadataScope scope, bool valueType) : + this (name, ns, scope) + { + this.IsValueType = valueType; + } + + public virtual TypeReference GetOriginalType () + { + return this; + } + + internal void AttachToScope (IMetadataScope scope) + { + m_scope = scope; + } + + public override void Accept (IReflectionVisitor visitor) + { + visitor.VisitTypeReference (this); + } + + public override string ToString () + { + return this.FullName; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeReferenceCollection.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeReferenceCollection.cs new file mode 100644 index 0000000..2482e38 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeReferenceCollection.cs @@ -0,0 +1,214 @@ +// +// TypeReferenceCollection.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// Generated by /CodeGen/cecil-gen.rb do not edit +// Fri Mar 30 18:43:56 +0200 2007 +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + using System.Collections; + using System.Collections.Specialized; + + using Mono.Cecil.Cil; + + using Hcp = Mono.Cecil.HashCodeProvider; + using Cmp = System.Collections.Comparer; + + public sealed class TypeReferenceCollection : NameObjectCollectionBase, IList, IReflectionVisitable { + + ModuleDefinition m_container; + + public TypeReference this [int index] { + get { return this.BaseGet (index) as TypeReference; } + set { this.BaseSet (index, value); } + } + + public TypeReference this [string fullName] { + get { return this.BaseGet (fullName) as TypeReference; } + set { this.BaseSet (fullName, value); } + } + + public ModuleDefinition Container { + get { return m_container; } + } + + public bool IsSynchronized { + get { return false; } + } + + public object SyncRoot { + get { return this; } + } + + bool IList.IsReadOnly { + get { return false; } + } + + bool IList.IsFixedSize { + get { return false; } + } + + object IList.this [int index] { + get { return BaseGet (index); } + set { + Check (value); + BaseSet (index, value); + } + } + + public TypeReferenceCollection (ModuleDefinition container) : + base (Hcp.Instance, Cmp.Default) + { + m_container = container; + } + + public void Add (TypeReference value) + { + if (value == null) + throw new ArgumentNullException ("value"); + + Attach (value); + + this.BaseAdd (value.FullName, value); + } + + public void Clear () + { + foreach (TypeReference item in this) + Detach (item); + + this.BaseClear (); + } + + public bool Contains (TypeReference value) + { + return Contains (value.FullName); + } + + public bool Contains (string fullName) + { + return this.BaseGet (fullName) != null; + } + + public int IndexOf (TypeReference value) + { + string [] keys = this.BaseGetAllKeys (); + return Array.IndexOf (keys, value.FullName, 0, keys.Length); + } + + public void Remove (TypeReference value) + { + this.BaseRemove (value.FullName); + + Detach (value); + } + + public void RemoveAt (int index) + { + TypeReference item = this [index]; + Remove (item); + + Detach (item); + } + + public void CopyTo (Array ary, int index) + { + this.BaseGetAllValues ().CopyTo (ary, index); + } + + public new IEnumerator GetEnumerator () + { + return this.BaseGetAllValues ().GetEnumerator (); + } + + public void Accept (IReflectionVisitor visitor) + { + visitor.VisitTypeReferenceCollection (this); + } + +#if CF_1_0 || CF_2_0 + internal object [] BaseGetAllValues () + { + object [] values = new object [this.Count]; + for (int i=0; i < values.Length; ++i) { + values [i] = this.BaseGet (i); + } + return values; + } +#endif + + void Check (object value) + { + if (!(value is TypeReference)) + throw new ArgumentException (); + } + + int IList.Add (object value) + { + Check (value); + Add (value as TypeReference); + return 0; + } + + bool IList.Contains (object value) + { + Check (value); + return Contains (value as TypeReference); + } + + int IList.IndexOf (object value) + { + throw new NotSupportedException (); + } + + void IList.Insert (int index, object value) + { + throw new NotSupportedException (); + } + + void IList.Remove (object value) + { + Check (value); + Remove (value as TypeReference); + } + + void Detach (TypeReference type) + { + type.Module = null; + } + + void Attach (TypeReference type) + { + if (type.Module != null) + throw new ReflectionException ("Type is already attached, clone it instead"); + + type.Module = m_container; + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeSpecification.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeSpecification.cs new file mode 100644 index 0000000..9648a4b --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/TypeSpecification.cs @@ -0,0 +1,80 @@ +// +// TypeSpecification.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + using System; + + public abstract class TypeSpecification : TypeReference { + + private TypeReference m_elementType; + + public override string Name { + get { return m_elementType.Name; } + set { throw new NotSupportedException (); } + } + + public override string Namespace { + get { return m_elementType.Namespace; } + set { throw new NotSupportedException (); } + } + + public override bool IsValueType { + get { return m_elementType.IsValueType; } + set { throw new InvalidOperationException (); } + } + + public override IMetadataScope Scope { + get { return m_elementType.Scope; } + } + + public override ModuleDefinition Module { + get { return m_elementType.Module; } + set { throw new InvalidOperationException (); } + } + + public TypeReference ElementType { + get { return m_elementType; } + set { m_elementType = value; } + } + + public override string FullName { + get { return m_elementType.FullName; } + } + + internal TypeSpecification (TypeReference elementType) : base (string.Empty, string.Empty) + { + m_elementType = elementType; + } + + public override TypeReference GetOriginalType () + { + return m_elementType.GetOriginalType (); + } + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/VariantType.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/VariantType.cs new file mode 100644 index 0000000..eeeff2a --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Cecil/VariantType.cs @@ -0,0 +1,52 @@ +// +// VariantType.cs +// +// Author: +// Jb Evain (jbevain@gmail.com) +// +// (C) 2005 Jb Evain +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +namespace Mono.Cecil { + + public enum VariantType { + I2 = 2, + I4 = 3, + R4 = 4, + R8 = 5, + CY = 6, + DATE = 7, + BSTR = 8, + DISPATCH = 9, + ERROR = 10, + BOOL = 11, + VARIANT = 12, + UNKNOWN = 13, + DECIMAL = 14, + I1 = 16, + UI1 = 17, + UI2 = 18, + UI4 = 19, + INT = 22, + UINT = 23 + } +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/ChangeLog b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/ChangeLog new file mode 100644 index 0000000..6fc2a0c --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/ChangeLog @@ -0,0 +1,34 @@ +2008-02-06 Lluis Sanchez Gual <lluis@novell.com> + + * ChangeLog, SecurityParser.cs, SmallXmlParser.cs, MiniParser.cs: Added + support for pluggable add-in assembly reflectors. Implemented an add-in + assembly reflector based on Cecil. + +2005-06-15 Atsushi Enomoto <atsushi@ximian.com> + + * SmallXmlParser.cs, SecurityParser.cs : they can be CLSCompliant now. + +2005-05-12 Atsushi Enomoto <atsushi@ximian.com> + + * SmallXmlParser.cs, + SecurityParser.cs : Use new SmallXmlParser.cs instead of MiniParser. + +2004-09-16 Sebastien Pouliot <sebastien@ximian.com> + + * MiniParser.cs: Fixed warning (l4) for unused variables. Removed + duplicate (and identical) license. + +2004-05-14 Marek Safar <marek.safar@seznam.cz> + + * MiniParser.cs, SecurityParser.cs: [CLSCompliant (false)] + only for public mode. + +2003-07-05 Sebastien Pouliot <spouliot@videotron.ca> + + * SecurityParser.cs: Parse an XML string and convert it to a + SecurityElement object. + +2003-02-08 Sebastien Pouliot <spouliot@videotron.ca> + + * MiniParser.cs: Renamed namespace to match new location. + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/MiniParser.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/MiniParser.cs new file mode 100644 index 0000000..4c3da2d --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/MiniParser.cs @@ -0,0 +1,621 @@ +// +// System.Security.Cryptography.MiniParser: Internal XML parser implementation +// +// Authors: +// Sergey Chaban +// +// Copyright (c) 2001, 2002 Wild West Software +// Copyright (c) 2002 Sergey Chaban +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Text; +using System.Collections; +using System.Globalization; + +namespace Mono.Xml { + + internal class MiniParser { + + public interface IReader { + int Read(); + } + + public interface IAttrList { + int Length {get;} + bool IsEmpty {get;} + string GetName(int i); + string GetValue(int i); + string GetValue(string name); + void ChangeValue(string name, string newValue); + string[] Names {get;} + string[] Values {get;} + } + + public interface IMutableAttrList : IAttrList { + void Clear(); + void Add(string name, string value); + void CopyFrom(IAttrList attrs); + void Remove(int i); + void Remove(string name); + } + + public interface IHandler { + void OnStartParsing(MiniParser parser); + void OnStartElement(string name, IAttrList attrs); + void OnEndElement(string name); + void OnChars(string ch); + void OnEndParsing(MiniParser parser); + } + + public class HandlerAdapter : IHandler { + public HandlerAdapter() {} + public void OnStartParsing(MiniParser parser) {} + public void OnStartElement(string name, IAttrList attrs) {} + public void OnEndElement(string name) {} + public void OnChars(string ch) {} + public void OnEndParsing(MiniParser parser) {} + } + + private enum CharKind : byte { + LEFT_BR = 0, + RIGHT_BR = 1, + SLASH = 2, + PI_MARK = 3, + EQ = 4, + AMP = 5, + SQUOTE = 6, + DQUOTE = 7, + BANG = 8, + LEFT_SQBR = 9, + SPACE = 0xA, + RIGHT_SQBR = 0xB, + TAB = 0xC, + CR = 0xD, + EOL = 0xE, + CHARS = 0xF, + UNKNOWN = 0x1F + } + + private enum ActionCode : byte { + START_ELEM = 0, + END_ELEM = 1, + END_NAME = 2, + SET_ATTR_NAME = 3, + SET_ATTR_VAL = 4, + SEND_CHARS = 5, + START_CDATA = 6, + END_CDATA = 7, + ERROR = 8, + STATE_CHANGE = 9, + FLUSH_CHARS_STATE_CHANGE = 0xA, + ACC_CHARS_STATE_CHANGE = 0xB, + ACC_CDATA = 0xC, + PROC_CHAR_REF = 0xD, + UNKNOWN = 0xF + } + + public class AttrListImpl : IMutableAttrList { + protected ArrayList names; + protected ArrayList values; + + public AttrListImpl() : this(0) {} + + public AttrListImpl(int initialCapacity) { + if (initialCapacity <= 0) { + names = new ArrayList(); + values = new ArrayList(); + } else { + names = new ArrayList(initialCapacity); + values = new ArrayList(initialCapacity); + } + } + + public AttrListImpl(IAttrList attrs) + : this(attrs != null ? attrs.Length : 0) { + if (attrs != null) this.CopyFrom(attrs); + } + + public int Length { + get {return names.Count;} + } + + public bool IsEmpty { + get {return this.Length != 0;} + } + + public string GetName(int i) { + string res = null; + if (i >= 0 && i < this.Length) { + res = names[i] as string; + } + return res; + } + + public string GetValue(int i) { + string res = null; + if (i >= 0 && i < this.Length) { + res = values[i] as string; + } + return res; + } + + public string GetValue(string name) { + return this.GetValue(names.IndexOf(name)); + } + + public void ChangeValue(string name, string newValue) { + int i = names.IndexOf(name); + if (i >= 0 && i < this.Length) { + values[i] = newValue; + } + } + + public string[] Names { + get {return names.ToArray(typeof(string)) as string[];} + } + + public string[] Values { + get {return values.ToArray(typeof(string)) as string[];} + } + + public void Clear() { + names.Clear(); + values.Clear(); + } + + public void Add(string name, string value) { + names.Add(name); + values.Add(value); + } + + public void Remove(int i) { + if (i >= 0) { + names.RemoveAt(i); + values.RemoveAt(i); + } + } + + public void Remove(string name) { + this.Remove(names.IndexOf(name)); + } + + public void CopyFrom(IAttrList attrs) { + if (attrs != null && ((object)this == (object)attrs)) { + this.Clear(); + int n = attrs.Length; + for (int i = 0; i < n; i++) { + this.Add(attrs.GetName(i), attrs.GetValue(i)); + } + } + } + } + + public class XMLError : Exception { + protected string descr; + protected int line, column; + public XMLError() : this("Unknown") {} + public XMLError(string descr) : this(descr, -1, -1) {} + public XMLError(string descr, int line, int column) + : base(descr) { + this.descr = descr; + this.line = line; + this.column = column; + } + public int Line {get {return line;}} + public int Column {get {return column;}} + public override string ToString() { + return (String.Format("{0} @ (line = {1}, col = {2})", descr, line, column)); + } + } + + private static readonly int INPUT_RANGE = 13; + private static readonly ushort[] tbl = { + (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 1), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 0), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 128), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 128), + (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 2), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 133), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 16), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.FLUSH_CHARS_STATE_CHANGE << 8) | 4), + (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.END_ELEM << 8) | 0), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 2), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 2), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), + (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 5), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), + (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 4), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.END_NAME << 8) | 6), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.END_NAME << 8) | 7), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.END_NAME << 8) | 8), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), + (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 0), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 3), + (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 0), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ERROR << 8) | 129), + (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.FLUSH_CHARS_STATE_CHANGE << 8) | 1), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.PROC_CHAR_REF << 8) | 10), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 7), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), + (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 9), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.START_ELEM << 8) | 6), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.START_ELEM << 8) | 7), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 8), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), + (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 9), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.SET_ATTR_NAME << 8) | 11), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 12), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 130), + (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 13), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.PROC_CHAR_REF << 8) | 10), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 10), + (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 11), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 132), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ERROR << 8) | 132), + (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.SET_ATTR_NAME << 8) | 11), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 12), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 130), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ERROR << 8) | 130), + (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.SEND_CHARS << 8) | 2), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 16), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 134), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ERROR << 8) | 134), + (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.SET_ATTR_VAL << 8) | 17), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.PROC_CHAR_REF << 8) | 14), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 14), + (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.SET_ATTR_VAL << 8) | 17), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.PROC_CHAR_REF << 8) | 15), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 15), + (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.START_CDATA << 8) | 18), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 0), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.START_CDATA << 8) | 19), + (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.START_ELEM << 8) | 6), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.START_ELEM << 8) | 7), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.STATE_CHANGE << 8) | 17), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CHARS_STATE_CHANGE << 8) | 9), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ERROR << 8) | 129), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ERROR << 8) | 129), + (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.END_CDATA << 8) | 10), (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 18), + (ushort)(((ushort)CharKind.LEFT_BR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.SLASH << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.RIGHT_BR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.PI_MARK << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.EQ << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.AMP << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.SQUOTE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.BANG << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.LEFT_SQBR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.SPACE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.RIGHT_SQBR << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.DQUOTE << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.ACC_CDATA << 8) | 19), + (ushort)(((ushort)CharKind.CHARS << 12) | ((ushort)ActionCode.UNKNOWN << 8) | 255), + 0xFFFF + }; + + protected static string[] errors = { + /* 0 */ "Expected element", + /* 1 */ "Invalid character in tag", + /* 2 */ "No '='", + /* 3 */ "Invalid character entity", + /* 4 */ "Invalid attr value", + /* 5 */ "Empty tag", + /* 6 */ "No end tag", + /* 7 */ "Bad entity ref" + }; + + protected int line; + protected int col; + protected int[] twoCharBuff; + protected bool splitCData; + + public MiniParser() { + twoCharBuff = new int[2]; + splitCData = false; + Reset(); + } + + public void Reset() { + line = 0; + col = 0; + } + + protected static bool StrEquals(string str, StringBuilder sb, int sbStart, int len) { + if (len != str.Length) return false; + for (int i = 0; i < len; i++) { + if (str[i] != sb[sbStart + i]) return false; + } + return true; + } + + protected void FatalErr(string descr) { + throw new XMLError(descr, this.line, this.col); + } + + protected static int Xlat(int charCode, int state) { + int p = state * INPUT_RANGE; + int n = System.Math.Min(tbl.Length - p, INPUT_RANGE); + for (;--n >= 0;) { + ushort code = tbl[p]; + if (charCode == (code >> 12)) return (code & 0xFFF); + p++; + } + return 0xFFF; + } + + public void Parse(IReader reader, IHandler handler) { + if (reader == null) throw new ArgumentNullException("reader"); + if (handler == null) handler = new HandlerAdapter(); + + AttrListImpl attrList = new AttrListImpl(); + string lastAttrName = null; + Stack tagStack = new Stack(); + string elementName = null; + line = 1; + col = 0; + int currCh = 0; + int stateCode = 0; + StringBuilder sbChars = new StringBuilder(); + bool seenCData = false; + bool isComment = false; + bool isDTD = false; + int bracketSwitch = 0; + + handler.OnStartParsing(this); + + while (true) { + ++this.col; + + currCh = reader.Read(); + + if (currCh == -1) { + if (stateCode != 0) { + FatalErr("Unexpected EOF"); + } + break; + } + + int charCode = "<>/?=&'\"![ ]\t\r\n".IndexOf((char)currCh) & 0xF; + if (charCode == (int)CharKind.CR) continue; // ignore + // whitepace ::= (#x20 | #x9 | #xd | #xa)+ + if (charCode == (int)CharKind.TAB) charCode = (int)CharKind.SPACE; // tab == space + if (charCode == (int)CharKind.EOL) { + this.col = 0; + this.line++; + charCode = (int)CharKind.SPACE; + } + + int actionCode = MiniParser.Xlat(charCode, stateCode); + stateCode = actionCode & 0xFF; + // Ignore newline inside attribute value. + if (currCh == '\n' && (stateCode == 0xE || stateCode == 0xF)) continue; + actionCode >>= 8; + + if (stateCode >= 0x80) { + if (stateCode == 0xFF) { + FatalErr("State dispatch error."); + } else { + FatalErr(errors[stateCode ^ 0x80]); + } + } + + switch (actionCode) { + case (int)ActionCode.START_ELEM: + handler.OnStartElement(elementName, attrList); + if (currCh != '/') { + tagStack.Push(elementName); + } else { + handler.OnEndElement(elementName); + } + attrList.Clear(); + break; + + case (int)ActionCode.END_ELEM: + elementName = sbChars.ToString(); + sbChars = new StringBuilder(); + string endName = null; + if (tagStack.Count == 0 || + elementName != (endName = tagStack.Pop() as string)) { + if (endName == null) { + FatalErr("Tag stack underflow"); + } else { + FatalErr(String.Format("Expected end tag '{0}' but found '{1}'", elementName, endName)); + } + } + handler.OnEndElement(elementName); + break; + + case (int)ActionCode.END_NAME: + elementName = sbChars.ToString(); + sbChars = new StringBuilder(); + if (currCh != '/' && currCh != '>') break; + goto case (int)ActionCode.START_ELEM; + + case (int)ActionCode.SET_ATTR_NAME: + lastAttrName = sbChars.ToString(); + sbChars = new StringBuilder(); + break; + + case (int)ActionCode.SET_ATTR_VAL: + if (lastAttrName == null) FatalErr("Internal error."); + attrList.Add(lastAttrName, sbChars.ToString()); + sbChars = new StringBuilder(); + lastAttrName = null; + break; + + case (int)ActionCode.SEND_CHARS: + handler.OnChars(sbChars.ToString()); + sbChars = new StringBuilder(); + break; + + case (int)ActionCode.START_CDATA: + string cdata = "CDATA["; + isComment = false; + isDTD = false; + + if (currCh == '-') { + currCh = reader.Read(); + + if (currCh != '-') FatalErr("Invalid comment"); + + this.col++; + isComment = true; + twoCharBuff[0] = -1; + twoCharBuff[1] = -1; + } else { + if (currCh != '[') { + isDTD = true; + bracketSwitch = 0; + break; + } + + for (int i = 0; i < cdata.Length; i++) { + if (reader.Read() != cdata[i]) { + this.col += i+1; + break; + } + } + this.col += cdata.Length; + seenCData = true; + } + break; + + case (int)ActionCode.END_CDATA: + int n = 0; + currCh = ']'; + + while (currCh == ']') { + currCh = reader.Read(); + n++; + } + + if (currCh != '>') { + for (int i = 0; i < n; i++) sbChars.Append(']'); + sbChars.Append((char)currCh); + stateCode = 0x12; + } else { + for (int i = 0; i < n-2; i++) sbChars.Append(']'); + seenCData = false; + } + + this.col += n; + break; + + case (int)ActionCode.ERROR: + FatalErr(String.Format("Error {0}", stateCode)); + break; + + case (int)ActionCode.STATE_CHANGE: + break; + + case (int)ActionCode.FLUSH_CHARS_STATE_CHANGE: + sbChars = new StringBuilder(); + if (currCh != '<') goto case (int)ActionCode.ACC_CHARS_STATE_CHANGE; + break; + + case (int)ActionCode.ACC_CHARS_STATE_CHANGE: + sbChars.Append((char)currCh); + break; + + case (int)ActionCode.ACC_CDATA: + if (isComment) { + if (currCh == '>' + && twoCharBuff[0] == '-' + && twoCharBuff[1] == '-') { + isComment = false; + stateCode = 0; + } else { + twoCharBuff[0] = twoCharBuff[1]; + twoCharBuff[1] = currCh; + } + } else if (isDTD) { + if (currCh == '<' || currCh == '>') bracketSwitch ^= 1; + if (currCh == '>' && bracketSwitch != 0) { + isDTD = false; + stateCode = 0; + } + } else { + if (this.splitCData + && sbChars.Length > 0 + && seenCData) { + handler.OnChars(sbChars.ToString()); + sbChars = new StringBuilder(); + } + seenCData = false; + sbChars.Append((char)currCh); + } + break; + + case (int)ActionCode.PROC_CHAR_REF: + currCh = reader.Read(); + int cl = this.col + 1; + if (currCh == '#') { // character reference + int r = 10; + int chCode = 0; + int nDigits = 0; + currCh = reader.Read(); + cl++; + + if (currCh == 'x') { + currCh = reader.Read(); + cl++; + r=16; + } + + NumberStyles style = r == 16 ? NumberStyles.HexNumber : NumberStyles.Integer; + + while (true) { + int x = -1; + if (Char.IsNumber((char)currCh) || "abcdef".IndexOf(Char.ToLower((char)currCh)) != -1) { + try { + x = Int32.Parse(new string((char)currCh, 1), style); + } catch (FormatException) {x = -1;} + } + if (x == -1) break; + chCode *= r; + chCode += x; + nDigits++; + currCh = reader.Read(); + cl++; + } + + if (currCh == ';' && nDigits > 0) { + sbChars.Append((char)chCode); + } else { + FatalErr("Bad char ref"); + } + } else { + // entity reference + string entityRefChars = "aglmopqstu"; // amp | apos | quot | gt | lt + string entities = "&'\"><"; + + int pos = 0; + int entIdx = 0xF; + int predShift = 0; + + int sbLen = sbChars.Length; + + while (true) { + if (pos != 0xF) pos = entityRefChars.IndexOf((char)currCh) & 0xF; + if (pos == 0xF) FatalErr(errors[7]); + sbChars.Append((char)currCh); + + int path = "\uFF35\u3F8F\u4F8F\u0F5F\uFF78\uE1F4\u2299\uEEFF\uEEFF\uFF4F"[pos]; + int lBr = (path >> 4) & 0xF; + int rBr = path & 0xF; + int lPred = path >> 12; + int rPred = (path >> 8) & 0xF; + currCh = reader.Read(); + cl++; + pos = 0xF; + if (lBr != 0xF && currCh == entityRefChars[lBr]) { + if (lPred < 0xE) entIdx = lPred; +// pred = lPred; + predShift = 12; // left + } else if (rBr != 0xF && currCh == entityRefChars[rBr]) { + if (rPred < 0xE) entIdx = rPred; +// pred = rPred; + predShift = 8; // right + } else if (currCh == ';') { + if (entIdx != 0xF + && predShift != 0 + && ((path >> predShift) & 0xF) == 0xE) break; + continue; // pos == 0xF + } + + pos=0; + + } + + int l = cl - this.col - 1; + + if ((l > 0 && l < 5) + &&(StrEquals("amp", sbChars, sbLen, l) + || StrEquals("apos", sbChars, sbLen, l) + || StrEquals("quot", sbChars, sbLen, l) + || StrEquals("lt", sbChars, sbLen, l) + || StrEquals("gt", sbChars, sbLen, l)) + ) { + sbChars.Length = sbLen; + sbChars.Append(entities[entIdx]); + } else FatalErr(errors[7]); + } + + this.col = cl; + break; + + default: + FatalErr(String.Format("Unexpected action code - {0}.", actionCode)); + break; + } + } // while (true) + + handler.OnEndParsing(this); + + } // Parse + + } + +} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/SecurityParser.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/SecurityParser.cs new file mode 100644 index 0000000..ec53830 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/SecurityParser.cs @@ -0,0 +1,109 @@ +// +// Mono.Xml.SecurityParser.cs class implementation +// +// Author: +// Sebastien Pouliot (spouliot@motus.com) +// +// (C) 2003 Motus Technologies Inc. (http://www.motus.com) +// + +// +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; +using System.IO; +using System.Security; + +namespace Mono.Xml { + + // convert an XML document into SecurityElement objects + internal class SecurityParser : SmallXmlParser, SmallXmlParser.IContentHandler { + + private SecurityElement root; + + public SecurityParser () : base () + { + stack = new Stack (); + } + + public void LoadXml (string xml) + { + root = null; +#if CF_1_0 + stack = new Stack (); +#else + stack.Clear (); +#endif + Parse (new StringReader (xml), this); + } + + public SecurityElement ToXml () + { + return root; + } + + // IContentHandler + + private SecurityElement current; + private Stack stack; + + public void OnStartParsing (SmallXmlParser parser) {} + + public void OnProcessingInstruction (string name, string text) {} + + public void OnIgnorableWhitespace (string s) {} + + public void OnStartElement (string name, SmallXmlParser.IAttrList attrs) + { + SecurityElement newel = new SecurityElement (name); + if (root == null) { + root = newel; + current = newel; + } + else { + SecurityElement parent = (SecurityElement) stack.Peek (); + parent.AddChild (newel); + } + stack.Push (newel); + current = newel; + // attributes + int n = attrs.Length; + for (int i=0; i < n; i++) + current.AddAttribute (attrs.GetName (i), attrs.GetValue (i)); + } + + public void OnEndElement (string name) + { + current = (SecurityElement) stack.Pop (); + } + + public void OnChars (string ch) + { + current.Text = ch; + } + + public void OnEndParsing (SmallXmlParser parser) {} + } +} + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/SmallXmlParser.cs b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/SmallXmlParser.cs new file mode 100644 index 0000000..4a492ef --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/Mono.Xml/SmallXmlParser.cs @@ -0,0 +1,637 @@ +// +// SmallXmlParser.cs +// +// Author: +// Atsushi Enomoto <atsushi@ximian.com> +// +// Copyright (C) 2005 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +// +// small xml parser that is mostly compatible with +// + +using System; +using System.Collections; +using System.Globalization; +using System.IO; +using System.Text; + +namespace Mono.Xml +{ + internal class DefaultHandler : SmallXmlParser.IContentHandler + { + public void OnStartParsing (SmallXmlParser parser) + { + } + + public void OnEndParsing (SmallXmlParser parser) + { + } + + public void OnStartElement (string name, SmallXmlParser.IAttrList attrs) + { + } + + public void OnEndElement (string name) + { + } + + public void OnChars (string s) + { + } + + public void OnIgnorableWhitespace (string s) + { + } + + public void OnProcessingInstruction (string name, string text) + { + } + } + + internal class SmallXmlParser + { + public interface IContentHandler + { + void OnStartParsing (SmallXmlParser parser); + void OnEndParsing (SmallXmlParser parser); + void OnStartElement (string name, IAttrList attrs); + void OnEndElement (string name); + void OnProcessingInstruction (string name, string text); + void OnChars (string text); + void OnIgnorableWhitespace (string text); + } + + public interface IAttrList + { + int Length { get; } + bool IsEmpty { get; } + string GetName (int i); + string GetValue (int i); + string GetValue (string name); + string [] Names { get; } + string [] Values { get; } + } + + class AttrListImpl : IAttrList + { + public int Length { + get { return attrNames.Count; } + } + public bool IsEmpty { + get { return attrNames.Count == 0; } + } + public string GetName (int i) + { + return (string) attrNames [i]; + } + public string GetValue (int i) + { + return (string) attrValues [i]; + } + public string GetValue (string name) + { + for (int i = 0; i < attrNames.Count; i++) + if ((string) attrNames [i] == name) + return (string) attrValues [i]; + return null; + } + public string [] Names { + get { return (string []) attrNames.ToArray (typeof (string)); } + } + public string [] Values { + get { return (string []) attrValues.ToArray (typeof (string)); } + } + + ArrayList attrNames = new ArrayList (); + ArrayList attrValues = new ArrayList (); + + internal void Clear () + { + attrNames.Clear (); + attrValues.Clear (); + } + + internal void Add (string name, string value) + { + attrNames.Add (name); + attrValues.Add (value); + } + } + + IContentHandler handler; + TextReader reader; + Stack elementNames = new Stack (); + Stack xmlSpaces = new Stack (); + string xmlSpace; + StringBuilder buffer = new StringBuilder (200); + char [] nameBuffer = new char [30]; + bool isWhitespace; + + AttrListImpl attributes = new AttrListImpl (); + int line = 1, column; + bool resetColumn; + + public SmallXmlParser () + { + } + + private Exception Error (string msg) + { + return new SmallXmlParserException (msg, line, column); + } + + private Exception UnexpectedEndError () + { + string [] arr = new string [elementNames.Count]; + // COMPACT FRAMEWORK NOTE: CopyTo is not visible through the Stack class + (elementNames as ICollection).CopyTo (arr, 0); + return Error (String.Format ( + "Unexpected end of stream. Element stack content is {0}", String.Join (",", arr))); + } + + + private bool IsNameChar (char c, bool start) + { + switch (c) { + case ':': + case '_': + return true; + case '-': + case '.': + return !start; + } + if (c > 0x100) { // optional condition for optimization + switch (c) { + case '\u0559': + case '\u06E5': + case '\u06E6': + return true; + } + if ('\u02BB' <= c && c <= '\u02C1') + return true; + } + switch (Char.GetUnicodeCategory (c)) { + case UnicodeCategory.LowercaseLetter: + case UnicodeCategory.UppercaseLetter: + case UnicodeCategory.OtherLetter: + case UnicodeCategory.TitlecaseLetter: + case UnicodeCategory.LetterNumber: + return true; + case UnicodeCategory.SpacingCombiningMark: + case UnicodeCategory.EnclosingMark: + case UnicodeCategory.NonSpacingMark: + case UnicodeCategory.ModifierLetter: + case UnicodeCategory.DecimalDigitNumber: + return !start; + default: + return false; + } + } + + private bool IsWhitespace (int c) + { + switch (c) { + case ' ': + case '\r': + case '\t': + case '\n': + return true; + default: + return false; + } + } + + + public void SkipWhitespaces () + { + SkipWhitespaces (false); + } + + private void HandleWhitespaces () + { + while (IsWhitespace (Peek ())) + buffer.Append ((char) Read ()); + if (Peek () != '<' && Peek () >= 0) + isWhitespace = false; + } + + public void SkipWhitespaces (bool expected) + { + while (true) { + switch (Peek ()) { + case ' ': + case '\r': + case '\t': + case '\n': + Read (); + if (expected) + expected = false; + continue; + } + if (expected) + throw Error ("Whitespace is expected."); + return; + } + } + + + private int Peek () + { + return reader.Peek (); + } + + private int Read () + { + int i = reader.Read (); + if (i == '\n') + resetColumn = true; + if (resetColumn) { + line++; + resetColumn = false; + column = 1; + } + else + column++; + return i; + } + + public void Expect (int c) + { + int p = Read (); + if (p < 0) + throw UnexpectedEndError (); + else if (p != c) + throw Error (String.Format ("Expected '{0}' but got {1}", (char) c, (char) p)); + } + + private string ReadUntil (char until, bool handleReferences) + { + while (true) { + if (Peek () < 0) + throw UnexpectedEndError (); + char c = (char) Read (); + if (c == until) + break; + else if (handleReferences && c == '&') + ReadReference (); + else + buffer.Append (c); + } + string ret = buffer.ToString (); + buffer.Length = 0; + return ret; + } + + public string ReadName () + { + int idx = 0; + if (Peek () < 0 || !IsNameChar ((char) Peek (), true)) + throw Error ("XML name start character is expected."); + for (int i = Peek (); i >= 0; i = Peek ()) { + char c = (char) i; + if (!IsNameChar (c, false)) + break; + if (idx == nameBuffer.Length) { + char [] tmp = new char [idx * 2]; + // COMPACT FRAMEWORK NOTE: Array.Copy(sourceArray, destinationArray, count) is not available. + Array.Copy (nameBuffer, 0, tmp, 0, idx); + nameBuffer = tmp; + } + nameBuffer [idx++] = c; + Read (); + } + if (idx == 0) + throw Error ("Valid XML name is expected."); + return new string (nameBuffer, 0, idx); + } + + + public void Parse (TextReader input, IContentHandler handler) + { + this.reader = input; + this.handler = handler; + + handler.OnStartParsing (this); + + while (Peek () >= 0) + ReadContent (); + HandleBufferedContent (); + if (elementNames.Count > 0) + throw Error (String.Format ("Insufficient close tag: {0}", elementNames.Peek ())); + + handler.OnEndParsing (this); + + Cleanup (); + } + + private void Cleanup () + { + line = 1; + column = 0; + handler = null; + reader = null; +#if CF_1_0 + elementNames = new Stack (); + xmlSpaces = new Stack (); +#else + elementNames.Clear (); + xmlSpaces.Clear (); +#endif + attributes.Clear (); + buffer.Length = 0; + xmlSpace = null; + isWhitespace = false; + } + + public void ReadContent () + { + string name; + if (IsWhitespace (Peek ())) { + if (buffer.Length == 0) + isWhitespace = true; + HandleWhitespaces (); + } + if (Peek () == '<') { + Read (); + switch (Peek ()) { + case '!': // declarations + Read (); + if (Peek () == '[') { + Read (); + if (ReadName () != "CDATA") + throw Error ("Invalid declaration markup"); + Expect ('['); + ReadCDATASection (); + return; + } + else if (Peek () == '-') { + ReadComment (); + return; + } + else if (ReadName () != "DOCTYPE") + throw Error ("Invalid declaration markup."); + else + throw Error ("This parser does not support document type."); + case '?': // PIs + HandleBufferedContent (); + Read (); + name = ReadName (); + SkipWhitespaces (); + string text = String.Empty; + if (Peek () != '?') { + while (true) { + text += ReadUntil ('?', false); + if (Peek () == '>') + break; + text += "?"; + } + } + handler.OnProcessingInstruction ( + name, text); + Expect ('>'); + return; + case '/': // end tags + HandleBufferedContent (); + if (elementNames.Count == 0) + throw UnexpectedEndError (); + Read (); + name = ReadName (); + SkipWhitespaces (); + string expected = (string) elementNames.Pop (); + xmlSpaces.Pop (); + if (xmlSpaces.Count > 0) + xmlSpace = (string) xmlSpaces.Peek (); + else + xmlSpace = null; + if (name != expected) + throw Error (String.Format ("End tag mismatch: expected {0} but found {1}", expected, name)); + handler.OnEndElement (name); + Expect ('>'); + return; + default: // start tags (including empty tags) + HandleBufferedContent (); + name = ReadName (); + while (Peek () != '>' && Peek () != '/') + ReadAttribute (attributes); + handler.OnStartElement (name, attributes); + attributes.Clear (); + SkipWhitespaces (); + if (Peek () == '/') { + Read (); + handler.OnEndElement (name); + } + else { + elementNames.Push (name); + xmlSpaces.Push (xmlSpace); + } + Expect ('>'); + return; + } + } + else + ReadCharacters (); + } + + private void HandleBufferedContent () + { + if (buffer.Length == 0) + return; + if (isWhitespace) + handler.OnIgnorableWhitespace (buffer.ToString ()); + else + handler.OnChars (buffer.ToString ()); + buffer.Length = 0; + isWhitespace = false; + } + + private void ReadCharacters () + { + isWhitespace = false; + while (true) { + int i = Peek (); + switch (i) { + case -1: + return; + case '<': + return; + case '&': + Read (); + ReadReference (); + continue; + default: + buffer.Append ((char) Read ()); + continue; + } + } + } + + private void ReadReference () + { + if (Peek () == '#') { + // character reference + Read (); + ReadCharacterReference (); + } else { + string name = ReadName (); + Expect (';'); + switch (name) { + case "amp": + buffer.Append ('&'); + break; + case "quot": + buffer.Append ('"'); + break; + case "apos": + buffer.Append ('\''); + break; + case "lt": + buffer.Append ('<'); + break; + case "gt": + buffer.Append ('>'); + break; + default: + throw Error ("General non-predefined entity reference is not supported in this parser."); + } + } + } + + private int ReadCharacterReference () + { + int n = 0; + if (Peek () == 'x') { // hex + Read (); + for (int i = Peek (); i >= 0; i = Peek ()) { + if ('0' <= i && i <= '9') + n = n << 4 + i - '0'; + else if ('A' <= i && i <='F') + n = n << 4 + i - 'A' + 10; + else if ('a' <= i && i <='f') + n = n << 4 + i - 'a' + 10; + else + break; + Read (); + } + } else { + for (int i = Peek (); i >= 0; i = Peek ()) { + if ('0' <= i && i <= '9') + n = n << 4 + i - '0'; + else + break; + Read (); + } + } + return n; + } + + private void ReadAttribute (AttrListImpl a) + { + SkipWhitespaces (true); + if (Peek () == '/' || Peek () == '>') + // came here just to spend trailing whitespaces + return; + + string name = ReadName (); + string value; + SkipWhitespaces (); + Expect ('='); + SkipWhitespaces (); + switch (Read ()) { + case '\'': + value = ReadUntil ('\'', true); + break; + case '"': + value = ReadUntil ('"', true); + break; + default: + throw Error ("Invalid attribute value markup."); + } + if (name == "xml:space") + xmlSpace = value; + a.Add (name, value); + } + + private void ReadCDATASection () + { + int nBracket = 0; + while (true) { + if (Peek () < 0) + throw UnexpectedEndError (); + char c = (char) Read (); + if (c == ']') + nBracket++; + else if (c == '>' && nBracket > 1) { + for (int i = nBracket; i > 2; i--) + buffer.Append (']'); + break; + } + else { + for (int i = 0; i < nBracket; i++) + buffer.Append (']'); + nBracket = 0; + buffer.Append (c); + } + } + } + + private void ReadComment () + { + Expect ('-'); + Expect ('-'); + while (true) { + if (Read () != '-') + continue; + if (Read () != '-') + continue; + if (Read () != '>') + throw Error ("'--' is not allowed inside comment markup."); + break; + } + } + } + + internal class SmallXmlParserException : SystemException + { + int line; + int column; + + public SmallXmlParserException (string msg, int line, int column) + : base (String.Format ("{0}. At ({1},{2})", msg, line, column)) + { + this.line = line; + this.column = column; + } + + public int Line { + get { return line; } + } + + public int Column { + get { return column; } + } + } +} + + + diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/NEWS b/Mono.Addins.CecilReflector/Mono.Cecil/NEWS new file mode 100644 index 0000000..a8518da --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/NEWS @@ -0,0 +1,3 @@ +2005-10-31 Jb Evain <jbevain@gmail.com> + + * Release of Mono.Cecil 0.1 "Trick or Treat" diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/README b/Mono.Addins.CecilReflector/Mono.Cecil/README new file mode 100644 index 0000000..b95c65e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/README @@ -0,0 +1,78 @@ +Cecil is a library to generate and inspect programs and libraries in the ECMA CIL format. + +* Building + + The standard Makefile works inside /mcs (SVN or tarball). If you want to build + Cecil as a standalone library (e.g. in /cecil SVN) you'll need to: + + ./configure --prefix=/your/prefix + make -f standalone.make + make -f standalone.make install + +* Bugs + + Please report bugs at: + http://bugzilla.novell.com, + Product: Mono: Class Library + Component: Cecil + +* Layout + + CodeGen/ + Here is a ruby code generation script. Do not modify generated files. + Please modify template then run: + + ./cecil-gen.rb + + in this folder. If you add or remove files, please run: + + ./cecil-gen-sources.rb + + to update the file Mono.Cecil.dll.sources + + Mono.Cecil/ + General implementation of Cecil. + + Mono.Cecil.Binary/ + Here are files dealing with PE format. + + Mono.Cecil.Metadata/ + Here lies files dealing with the format of metadata. + + Mono.Cecil.Cil/ + Files dealing with CIL intermediate code. + + Mono.Cecil.Signatures/ + Here are files dealing with signatures in blobs. + +* Acknowledgements + + Thanks to: + - Sébastien Pouliot, + - Todd Berman, + - Martin Baulig, + - Sébastien Ros, + - Thomas Gil + +* License + + Copyright (C) 2005 Jb Evain + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/TODO b/Mono.Addins.CecilReflector/Mono.Cecil/TODO new file mode 100644 index 0000000..d373d8e --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/TODO @@ -0,0 +1,19 @@ +Cecil TODO + +* debugs infos + + Cecil should be able to emit debug infos along with assemblies. + +* strong name + + For the moment, Cecil only create space for strong name signatures. + Can we do better ? + +* win32 resource + + Cecil does not suppport win32 resources and globaly the .rsrc section + into PE files. + +* verify + + Cecil does absolutely no verification on what it emits. diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/configure b/Mono.Addins.CecilReflector/Mono.Cecil/configure new file mode 100755 index 0000000..28f12e1 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/configure @@ -0,0 +1,43 @@ +#!/bin/sh + +help() +{ + echo "" + echo "Usage is: configure [--prefix=PREFIX]" + echo "" +} + +prefix=/usr/local +profile=default + +while [ $# -ne 0 ]; do + case $1 in + --help) + help + exit 0 + ;; + --prefix=*) + prefix=`echo $1 | sed 's/--prefix=//'`; + shift + ;; + --prefix) + shift + prefix="$1" + shift + ;; + *) + echo Unknown option: $1 + help + shift + esac +done + +echo "prefix=$prefix" > config.make + +echo "" +echo "Mono.Cecil module configured" +echo "" +echo " Prefix: $prefix" +echo "" + +exit 0; diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/default.build b/Mono.Addins.CecilReflector/Mono.Cecil/default.build new file mode 100644 index 0000000..73f7d84 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/default.build @@ -0,0 +1,84 @@ +<?xml version="1.0"?> +<project name="Cecil" default="cecil" basedir="."> + + <property name="debug" value="false" /> + <property name="optimize" value="true" /> + <property name="build.dir" value="${path::get-full-path('bin')}" /> + <property name="keyfile" value="../mono.snk" /> + <property name="csc.defines" value="NO_DEFINE" /> + + <!-- allow properties to be customized in external file" --> + <include buildfile="build.properties" if="${file::exists('build.properties')}" /> + + <fileset id="all-files"> + <include name="./**/*.cs" /> + <exclude name="CodeGen/**/*.*" /> + </fileset> + + <target name="clean"> + <delete failonerror="false"> + <fileset> + <include name="**/bin/**" /> + <include name="**/obj/**" /> + <include name="${build.dir}/**" /> + </fileset> + </delete> + </target> + + <target name="init"> + <mkdir dir="${build.dir}" /> + </target> + + <target name="cecil" depends="init"> + <csc output="${build.dir}/Mono.Cecil.dll" + target="library" debug="${debug}" + unsafe="false" optimize="${optimize}" + keyfile="${keyfile}" + define="${csc.defines}"> + <sources refid="all-files"/> + </csc> + </target> + + <target name="compactframework" depends="init" description="compiles cecil to run on the CompactFramework 1.0"> + <property name="compactframework.defines" value="CF_1_0;${csc.defines}" /> + <property name="compactframework.dir" value="${compactframework.v1.dir}" /> + <call target="compactframework-compilation" /> + </target> + + <target name="compactframework2" depends="init" description="compiles cecil to run on the CompactFramework 2.0"> + <property name="compactframework.defines" value="CF_2_0;${csc.defines}" /> + <property name="compactframework.dir" value="${compactframework.v2.dir}" /> + <call target="compactframework-compilation" /> + </target> + + <target name="compactframework-compilation"> + <property name="temp.dir" value="${path::combine(path::get-temp-path(), 'cecil')}" /> + <delete dir="${temp.dir}" if="${directory::exists(temp.dir)}" /> + <mkdir dir="${temp.dir}" /> + + <property name="framework.dir" value="${framework::get-framework-directory(framework::get-target-framework())}" /> + <property name="csc.exe" value="${path::combine(framework.dir, 'csc.exe')}" /> + + <copy todir="${temp.dir}"> + <fileset refid="all-files" /> + </copy> + + <exec program="${csc.exe}" workingdir="${temp.dir}" failonerror="true"> + <arg value="/optimize" /> + <arg value="/debug-" /> + <arg value="/define:${compactframework.defines}" /> + <arg value="/out:${build.dir}/Mono.Cecil.dll" /> + <arg value="/target:library" /> + <arg value="/warn:0" /> + <arg value="/noconfig" /> + <arg value="/nostdlib+" /> + <arg value="/reference:${compactframework.dir}/mscorlib.dll" /> + <arg value="/reference:${compactframework.dir}/System.dll" /> + <arg value="/recurse:*.cs" /> + </exec> + </target> + + <target name="codegen"> + <exec program="ruby" commandline="cecil-gen.rb" workingdir="CodeGen" /> + </target> +</project> diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/mono-cecil.pc.in b/Mono.Addins.CecilReflector/Mono.Cecil/mono-cecil.pc.in new file mode 100644 index 0000000..c2829d9 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/mono-cecil.pc.in @@ -0,0 +1,8 @@ +prefix=@prefix@ +assemblies_dir=${prefix}/lib/Mono.Cecil +Libraries=${assemblies_dir}/Mono.Cecil.dll + +Name: Mono.Cecil +Description: Mono.Cecil Library +Version: 0.6 +Libs: -r:${Libraries} diff --git a/Mono.Addins.CecilReflector/Mono.Cecil/standalone.make b/Mono.Addins.CecilReflector/Mono.Cecil/standalone.make new file mode 100644 index 0000000..075be29 --- /dev/null +++ b/Mono.Addins.CecilReflector/Mono.Cecil/standalone.make @@ -0,0 +1,23 @@ +include config.make + +MCS = mcs +KEY_FILE = ../../mcs/class/mono.snk +MCS_FLAGS = -keyfile:$(KEY_FILE) + +all: Mono.Cecil.dll mono-cecil.pc + +Mono.Cecil.dll: Mono.Cecil.dll.sources */*.cs + $(MCS) $(MCS_FLAGS) @Mono.Cecil.dll.sources /target:library /out:Mono.Cecil.dll + +clean: + rm -f Mono.Cecil.dll + rm -f mono-cecil.pc + +mono-cecil.pc: mono-cecil.pc.in + sed -e 's,@prefix@,$(prefix),g' mono-cecil.pc.in > $@.tmp + mv $@.tmp $@ + +install: all mono-cecil.pc + mkdir -p $(prefix)/lib/Mono.Cecil + cp Mono.Cecil.dll $(prefix)/lib/Mono.Cecil + cp mono-cecil.pc $(prefix)/lib/pkgconfig/mono-cecil.pc diff --git a/Mono.Addins.Gui/AssemblyInfo.cs b/Mono.Addins.Gui/AssemblyInfo.cs index 251fe14..57f68bc 100644 --- a/Mono.Addins.Gui/AssemblyInfo.cs +++ b/Mono.Addins.Gui/AssemblyInfo.cs @@ -17,4 +17,4 @@ using System.Runtime.CompilerServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyVersion("0.4.0.0")] diff --git a/Mono.Addins.Gui/ChangeLog b/Mono.Addins.Gui/ChangeLog index 6e6b70b..14a56c0 100644 --- a/Mono.Addins.Gui/ChangeLog +++ b/Mono.Addins.Gui/ChangeLog @@ -1,3 +1,8 @@ +2008-02-06 Lluis Sanchez Gual <lluis@novell.com> + + * AssemblyInfo.cs: Added support for pluggable add-in assembly reflectors. + Implemented an add-in assembly reflector based on Cecil. + 2008-01-17 Lluis Sanchez Gual <lluis@novell.com> * gtk-gui/Mono.Addins.Gui.ManageSitesDialog.cs, diff --git a/Mono.Addins.Setup/AssemblyInfo.cs b/Mono.Addins.Setup/AssemblyInfo.cs index 273b2c8..397d63f 100644 --- a/Mono.Addins.Setup/AssemblyInfo.cs +++ b/Mono.Addins.Setup/AssemblyInfo.cs @@ -17,4 +17,4 @@ using System.Runtime.CompilerServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyVersion("0.4.0.0")] diff --git a/Mono.Addins.Setup/ChangeLog b/Mono.Addins.Setup/ChangeLog index c040ec7..7d03cd9 100644 --- a/Mono.Addins.Setup/ChangeLog +++ b/Mono.Addins.Setup/ChangeLog @@ -1,3 +1,8 @@ +2008-02-06 Lluis Sanchez Gual <lluis@novell.com> + + * AssemblyInfo.cs: Added support for pluggable add-in assembly reflectors. + Implemented an add-in assembly reflector based on Cecil. + 2008-01-18 Lluis Sanchez Gual <lluis@novell.com> * Mono.Addins.Setup/RepositoryRegistry.cs: Don't break the api. diff --git a/Mono.Addins.mds b/Mono.Addins.mds index cc3beb7..b00a63f 100644 --- a/Mono.Addins.mds +++ b/Mono.Addins.mds @@ -9,6 +9,7 @@ <Entry build="True" name="Mono.Addins.Setup" configuration="Debug" /> <Entry build="True" name="Samples" configuration="Debug" /> <Entry build="True" name="Packages" configuration="" /> + <Entry build="True" name="Mono.Addins.CecilReflector" configuration="Debug" /> </Configuration> </Configurations> <StartMode startupentry="Mono.Addins" single="True"> @@ -23,6 +24,7 @@ <Execute type="None" entry="Mono.Addins.Setup" /> <Execute type="None" entry="Samples" /> <Execute type="None" entry="Packages" /> + <Execute type="None" entry="Mono.Addins.CecilReflector" /> </StartMode> <Entries> <Entry filename="Mono.Addins/Mono.Addins.mdp" /> @@ -33,5 +35,6 @@ <Entry filename="Mono.Addins.Setup/Mono.Addins.Setup.mdp" /> <Entry filename="Samples/Samples.mds" /> <Entry filename="Packages.mdse" /> + <Entry filename="Mono.Addins.CecilReflector/Mono.Addins.CecilReflector.mdp" /> </Entries> </Combine>
\ No newline at end of file diff --git a/Mono.Addins/AssemblyInfo.cs b/Mono.Addins/AssemblyInfo.cs index cd6c671..51c4364 100644 --- a/Mono.Addins/AssemblyInfo.cs +++ b/Mono.Addins/AssemblyInfo.cs @@ -17,4 +17,4 @@ using System.Runtime.CompilerServices; // You can specify all values by your own or you can build default build and revision // numbers with the '*' character (the default): -[assembly: AssemblyVersion("0.3.0.0")] +[assembly: AssemblyVersion("0.4.0.0")] diff --git a/Mono.Addins/ChangeLog b/Mono.Addins/ChangeLog index 761e80f..c842ff5 100644 --- a/Mono.Addins/ChangeLog +++ b/Mono.Addins/ChangeLog @@ -1,3 +1,17 @@ +2008-02-06 Lluis Sanchez Gual <lluis@novell.com> + + * AssemblyInfo.cs, Mono.Addins.mdp, Mono.Addins/NodeAttributeAttribute.cs, + Mono.Addins/TypeExtensionPointAttribute.cs, + Mono.Addins/ExtensionPointAttribute.cs, + Mono.Addins/ExtensionNodeChildAttribute.cs, Makefile.am, + Mono.Addins.Database/IAssemblyReflector.cs, + Mono.Addins.Database/AddinScanResult.cs, + Mono.Addins.Database/AddinDatabase.cs, + Mono.Addins.Database/AddinScanner.cs, + Mono.Addins.Database/DefaultAssemblyReflector.cs: Added support for + pluggable add-in assembly reflectors. Implemented an add-in assembly + reflector based on Cecil. + 2008-01-21 Lluis Sanchez Gual <lluis@novell.com> * Mono.Addins/ExtensionTree.cs: Since Mono r93079, GetFields don't return diff --git a/Mono.Addins/Makefile.am b/Mono.Addins/Makefile.am index 33d6e63..d2dac9d 100644 --- a/Mono.Addins/Makefile.am +++ b/Mono.Addins/Makefile.am @@ -21,7 +21,9 @@ FILES = \ Mono.Addins.Database/AddinScanResult.cs \ Mono.Addins.Database/AddinUpdateData.cs \ Mono.Addins.Database/DatabaseConfiguration.cs \ + Mono.Addins.Database/DefaultAssemblyReflector.cs \ Mono.Addins.Database/FileDatabase.cs \ + Mono.Addins.Database/IAssemblyReflector.cs \ Mono.Addins.Database/ProcessProgressStatus.cs \ Mono.Addins.Database/SetupProcess.cs \ Mono.Addins.Database/Util.cs \ diff --git a/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs b/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs index 0b153fb..81b2946 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs @@ -941,7 +941,7 @@ namespace Mono.Addins.Database scanResult.RegenerateAllData = true; } - AddinScanner scanner = new AddinScanner (this); + AddinScanner scanner = new AddinScanner (this, scanResult, monitor); // Check if any of the previously scanned folders has been deleted @@ -1046,8 +1046,8 @@ namespace Mono.Addins.Database } } - - AddinScanner scanner = new AddinScanner (this); + AddinScanResult sr = new AddinScanResult (); + AddinScanner scanner = new AddinScanner (this, sr, progressStatus); SingleFileAssemblyResolver res = new SingleFileAssemblyResolver (progressStatus, registry, scanner); ResolveEventHandler resolver = new ResolveEventHandler (res.Resolve); @@ -1058,7 +1058,7 @@ namespace Mono.Addins.Database AppDomain.CurrentDomain.AssemblyResolve += resolver; if (einfo != null) einfo.AddEventHandler (AppDomain.CurrentDomain, resolver); - AddinDescription desc = scanner.ScanSingleFile (progressStatus, file, new AddinScanResult ()); + AddinDescription desc = scanner.ScanSingleFile (progressStatus, file, sr); if (desc != null) desc.Save (outFile); } @@ -1080,7 +1080,7 @@ namespace Mono.Addins.Database Assembly OnResolveAddinAssembly (object s, ResolveEventArgs args) { - string file = currentScanResult.GetAssemblyLocation (args.Name); + string file = currentScanResult != null ? currentScanResult.GetAssemblyLocation (args.Name) : null; if (file != null) return Util.LoadAssemblyForReflection (file); else { diff --git a/Mono.Addins/Mono.Addins.Database/AddinScanResult.cs b/Mono.Addins/Mono.Addins.Database/AddinScanResult.cs index ea03531..731c88f 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinScanResult.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinScanResult.cs @@ -36,7 +36,7 @@ using Mono.Addins.Description; namespace Mono.Addins.Database { - internal class AddinScanResult: MarshalByRefObject + internal class AddinScanResult: MarshalByRefObject, IAssemblyLocator { internal ArrayList AddinsToScan = new ArrayList (); internal ArrayList AddinsToUpdateRelations = new ArrayList (); diff --git a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs index ee8606b..b17d156 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs @@ -43,10 +43,27 @@ namespace Mono.Addins.Database class AddinScanner: MarshalByRefObject { AddinDatabase database; + IAssemblyReflector reflector; + object coreAssembly; - public AddinScanner (AddinDatabase database) + public AddinScanner (AddinDatabase database, AddinScanResult scanResult, IProgressStatus monitor) { this.database = database; + if (!scanResult.CheckOnly) { + string refName = GetType().Assembly.FullName; + int i = refName.IndexOf (','); + refName = "Mono.Addins.CecilReflector.Reflector, Mono.Addins.CecilReflector" + refName.Substring (i); + Type t = Type.GetType (refName, false); + if (t != null) + reflector = (IAssemblyReflector) Activator.CreateInstance (t); + else + reflector = new DefaultAssemblyReflector (); + + if (monitor.LogLevel > 1) + monitor.Log ("Using assembly reflector: " + reflector.GetType ()); + reflector.Initialize (scanResult); + coreAssembly = reflector.LoadAssembly (GetType().Assembly.Location); + } } public void ScanFolder (IProgressStatus monitor, string path, string domain, AddinScanResult scanResult) @@ -521,12 +538,12 @@ namespace Mono.Addins.Database foreach (string s in config.MainModule.Assemblies) { string asmFile = Path.Combine (config.BasePath, s); asmFiles.Add (asmFile); - Assembly asm = Util.LoadAssemblyForReflection (asmFile); + object asm = reflector.LoadAssembly (asmFile); assemblies.Add (asm); scanResult.AddFileToIgnore (Util.GetFullPath (asmFile)); } - foreach (Assembly asm in assemblies) + foreach (object asm in assemblies) ScanAssemblyAddinHeaders (config, asm, scanResult); // The add-in id and version must be already assigned at this point @@ -535,7 +552,7 @@ namespace Mono.Addins.Database if (scanResult.HostIndex != null) scanResult.HostIndex.RemoveHostData (config.AddinId, config.AddinFile); - foreach (Assembly asm in assemblies) + foreach (object asm in assemblies) ScanAssemblyContents (config, asm, hostExtensionClasses, scanResult); } catch (Exception ex) { @@ -543,7 +560,7 @@ namespace Mono.Addins.Database return false; } - foreach (Type t in hostExtensionClasses) { + foreach (object t in hostExtensionClasses) { RegisterHostTypeNode (config, t, assemblies); } @@ -570,11 +587,11 @@ namespace Mono.Addins.Database foreach (string s in mod.Assemblies) { string asmFile = Path.Combine (config.BasePath, s); asmFiles.Add (asmFile); - Assembly asm = Util.LoadAssemblyForReflection (asmFile); + object asm = reflector.LoadAssembly (asmFile); assemblies.Add (asm); scanResult.AddFileToIgnore (Util.GetFullPath (asmFile)); } - foreach (Assembly asm in assemblies) + foreach (object asm in assemblies) ScanAssemblyContents (config, asm, null, scanResult); } catch (Exception ex) { @@ -601,10 +618,10 @@ namespace Mono.Addins.Database } } - void ScanAssemblyAddinHeaders (AddinDescription config, Assembly asm, AddinScanResult scanResult) + void ScanAssemblyAddinHeaders (AddinDescription config, object asm, AddinScanResult scanResult) { // Get basic add-in information - AddinAttribute att = (AddinAttribute) Attribute.GetCustomAttribute (asm, typeof(AddinAttribute), false); + AddinAttribute att = (AddinAttribute) reflector.GetCustomAttribute (asm, typeof(AddinAttribute), false); if (att != null) { if (att.Id.Length > 0) config.LocalId = att.Id; @@ -618,11 +635,11 @@ namespace Mono.Addins.Database } } - void ScanAssemblyContents (AddinDescription config, Assembly asm, ArrayList hostExtensionClasses, AddinScanResult scanResult) + void ScanAssemblyContents (AddinDescription config, object asm, ArrayList hostExtensionClasses, AddinScanResult scanResult) { // Get dependencies - object[] deps = asm.GetCustomAttributes (typeof(AddinDependencyAttribute), false); + object[] deps = reflector.GetCustomAttributes (asm, typeof(AddinDependencyAttribute), false); foreach (AddinDependencyAttribute dep in deps) { AddinDependency adep = new AddinDependency (); adep.AddinId = dep.Id; @@ -632,18 +649,21 @@ namespace Mono.Addins.Database // Get extension points - object[] extPoints = asm.GetCustomAttributes (typeof(ExtensionPointAttribute), false); + object[] extPoints = reflector.GetCustomAttributes (asm, typeof(ExtensionPointAttribute), false); foreach (ExtensionPointAttribute ext in extPoints) { ExtensionPoint ep = config.AddExtensionPoint (ext.Path); ep.Description = ext.Description; ep.Name = ext.Name; - ep.AddExtensionNode (ext.NodeName, ext.NodeType.FullName); + ep.AddExtensionNode (ext.NodeName, ext.NodeTypeName); } - foreach (Type t in asm.GetTypes ()) { + foreach (object t in reflector.GetAssemblyTypes (asm)) { + + string typeFullName = reflector.GetTypeFullName (t); - if (Attribute.IsDefined (t, typeof(ExtensionAttribute))) { - foreach (ExtensionAttribute eatt in t.GetCustomAttributes (typeof(ExtensionAttribute), false)) { + object[] extensionAtts = reflector.GetCustomAttributes (t, typeof(ExtensionAttribute), false); + if (extensionAtts.Length > 0) { + foreach (ExtensionAttribute eatt in extensionAtts) { string path; string nodeName; @@ -659,7 +679,7 @@ namespace Mono.Addins.Database if (path == "$") { // The type does not implement any interface and has no superclass. // Will be reported later as an error. - path = "$" + t.FullName; + path = "$" + typeFullName; } nodeName = "Type"; } @@ -671,9 +691,9 @@ namespace Mono.Addins.Database ExtensionNodeDescription elem = config.MainModule.AddExtensionNode (path, nodeName); if (eatt.Id.Length > 0) { elem.SetAttribute ("id", eatt.Id); - elem.SetAttribute ("type", t.FullName); + elem.SetAttribute ("type", typeFullName); } else { - elem.SetAttribute ("id", t.FullName); + elem.SetAttribute ("id", typeFullName); } if (eatt.InsertAfter.Length > 0) elem.SetAttribute ("insertafter", eatt.InsertAfter); @@ -681,8 +701,8 @@ namespace Mono.Addins.Database elem.SetAttribute ("insertbefore", eatt.InsertAfter); } } - else if (Attribute.IsDefined (t, typeof(TypeExtensionPointAttribute))) { - foreach (TypeExtensionPointAttribute epa in t.GetCustomAttributes (typeof(TypeExtensionPointAttribute), false)) { + else { + foreach (TypeExtensionPointAttribute epa in reflector.GetCustomAttributes (t, typeof(TypeExtensionPointAttribute), false)) { ExtensionPoint ep; ExtensionNodeType nt = new ExtensionNodeType (); @@ -691,8 +711,8 @@ namespace Mono.Addins.Database ep = config.AddExtensionPoint (epa.Path); } else { - ep = config.AddExtensionPoint (GetDefaultTypeExtensionPath (config, t)); - nt.ObjectTypeName = t.FullName; + ep = config.AddExtensionPoint (GetDefaultTypeExtensionPath (config, typeFullName)); + nt.ObjectTypeName = typeFullName; } nt.Id = epa.NodeName; nt.TypeName = epa.NodeType.FullName; @@ -717,12 +737,12 @@ namespace Mono.Addins.Database if (nt.TypeName.Length == 0) nt.TypeName = "Mono.Addins.TypeExtensionNode"; - Type ntype = FindAddinType (nt.TypeName, assemblies); + object ntype = FindAddinType (nt.TypeName, assemblies); if (ntype == null) return; // Add type information declared with attributes in the code - ExtensionNodeAttribute nodeAtt = (ExtensionNodeAttribute) Attribute.GetCustomAttribute (ntype, typeof(ExtensionNodeAttribute), true); + ExtensionNodeAttribute nodeAtt = (ExtensionNodeAttribute) reflector.GetCustomAttribute (ntype, typeof(ExtensionNodeAttribute), true); if (nodeAtt != null) { if (nt.Id.Length == 0 && nodeAtt.NodeName.Length > 0) nt.Id = nodeAtt.NodeName; @@ -731,34 +751,34 @@ namespace Mono.Addins.Database } else { // Use the node type name as default name if (nt.Id.Length == 0) - nt.Id = ntype.Name; + nt.Id = reflector.GetTypeName (ntype); } // Add information about attributes - object[] fieldAtts = ntype.GetCustomAttributes (typeof(NodeAttributeAttribute), true); + object[] fieldAtts = reflector.GetCustomAttributes (ntype, typeof(NodeAttributeAttribute), true); foreach (NodeAttributeAttribute fatt in fieldAtts) { NodeTypeAttribute natt = new NodeTypeAttribute (); natt.Name = fatt.Name; natt.Required = fatt.Required; - if (fatt.Type != null) - natt.Type = fatt.Type.FullName; + if (fatt.TypeName != null) + natt.Type = fatt.TypeName; if (fatt.Description.Length > 0) natt.Description = fatt.Description; nt.Attributes.Add (natt); } // Check if the type has NodeAttribute attributes applied to fields. - foreach (FieldInfo field in ntype.GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { - NodeAttributeAttribute fatt = (NodeAttributeAttribute) Attribute.GetCustomAttribute (field, typeof(NodeAttributeAttribute)); + foreach (object field in reflector.GetFields (ntype)) { + NodeAttributeAttribute fatt = (NodeAttributeAttribute) reflector.GetCustomAttribute (field, typeof(NodeAttributeAttribute), false); if (fatt != null) { NodeTypeAttribute natt = new NodeTypeAttribute (); if (fatt.Name.Length > 0) natt.Name = fatt.Name; else - natt.Name = field.Name; + natt.Name = reflector.GetFieldName (field); if (fatt.Description.Length > 0) natt.Description = fatt.Description; - natt.Type = field.FieldType.FullName; + natt.Type = reflector.GetFieldTypeFullName (field); natt.Required = fatt.Required; nt.Attributes.Add (natt); } @@ -770,17 +790,17 @@ namespace Mono.Addins.Database string childSet = (string) internalNodeSets [nt.TypeName]; if (childSet == null) { - object[] ats = ntype.GetCustomAttributes (typeof(ExtensionNodeChildAttribute), true); + object[] ats = reflector.GetCustomAttributes (ntype, typeof(ExtensionNodeChildAttribute), true); if (ats.Length > 0) { // Create a new node set for this type. It is necessary to create a new node set // instead of just adding child ExtensionNodeType objects to the this node type // because child types references can be recursive. ExtensionNodeSet internalSet = new ExtensionNodeSet (); - internalSet.Id = ntype.Name + "_" + Guid.NewGuid().ToString (); + internalSet.Id = reflector.GetTypeName (ntype) + "_" + Guid.NewGuid().ToString (); foreach (ExtensionNodeChildAttribute at in ats) { ExtensionNodeType internalType = new ExtensionNodeType (); internalType.Id = at.NodeName; - internalType.TypeName = at.ExtensionNodeType.FullName; + internalType.TypeName = at.ExtensionNodeTypeName; internalSet.NodeTypes.Add (internalType); } config.ExtensionNodeSets.Add (internalSet); @@ -789,7 +809,7 @@ namespace Mono.Addins.Database // Register the new set in a hashtable, to allow recursive references to the // same internal set. internalNodeSets [nt.TypeName] = internalSet.Id; - internalNodeSets [ntype.AssemblyQualifiedName] = internalSet.Id; + internalNodeSets [reflector.GetTypeAssemblyQualifiedName (ntype)] = internalSet.Id; ScanNodeSet (config, internalSet, assemblies, internalNodeSets); } } @@ -807,25 +827,19 @@ namespace Mono.Addins.Database ScanNodeSet (config, nt, assemblies, internalNodeSets); } - string GetBaseTypeNameList (Type type) + string GetBaseTypeNameList (object type) { StringBuilder sb = new StringBuilder ("$"); - Type btype = type.BaseType; - while (btype != typeof(object)) { - sb.Append (btype.FullName).Append (','); - btype = btype.BaseType; - } - foreach (Type iterf in type.GetInterfaces ()) { - sb.Append (iterf.FullName).Append (','); - } + foreach (string tn in reflector.GetBaseTypeFullNameList (type)) + sb.Append (tn).Append (','); if (sb.Length > 0) sb.Remove (sb.Length - 1, 1); return sb.ToString (); } - void RegisterHostTypeNode (AddinDescription config, Type t, ArrayList assemblies) + void RegisterHostTypeNode (AddinDescription config, object t, ArrayList assemblies) { - foreach (ExtensionAttribute eatt in t.GetCustomAttributes (typeof(ExtensionAttribute), false)) { + foreach (ExtensionAttribute eatt in reflector.GetCustomAttributes (t, typeof(ExtensionAttribute), false)) { if (eatt.Path.Length > 0) continue; @@ -833,9 +847,9 @@ namespace Mono.Addins.Database foreach (ExtensionNodeType nt in ep.NodeSet.NodeTypes) { if (nt.ObjectTypeName.Length == 0) continue; - Type etype = FindAddinType (nt.ObjectTypeName, assemblies); - if (etype != null && etype.IsAssignableFrom (t)) { - RegisterTypeNode (config, eatt, ep.Path, nt.Id, t); + object etype = FindAddinType (nt.ObjectTypeName, assemblies); + if (etype != null && reflector.TypeIsAssignableFrom (etype, t)) { + RegisterTypeNode (config, eatt, ep.Path, nt.Id, reflector.GetTypeFullName (t)); return; } } @@ -843,16 +857,16 @@ namespace Mono.Addins.Database } } - Type FindAddinType (string typeName, ArrayList assemblies) + object FindAddinType (string typeName, ArrayList assemblies) { // Look in the current assembly - Type etype = Type.GetType (typeName, false); + object etype = reflector.GetType (coreAssembly, typeName); if (etype != null) return etype; // Look in referenced assemblies - foreach (Assembly asm in assemblies) { - etype = asm.GetType (typeName); + foreach (object asm in assemblies) { + etype = reflector.GetType (asm, typeName); if (etype != null) return etype; } @@ -860,28 +874,30 @@ namespace Mono.Addins.Database Hashtable visited = new Hashtable (); // Look in indirectly referenced assemblies - foreach (Assembly asm in assemblies) { - foreach (AssemblyName aref in asm.GetReferencedAssemblies ()) { + foreach (object asm in assemblies) { + foreach (object aref in reflector.GetAssemblyReferences (asm)) { if (visited.Contains (aref)) continue; visited.Add (aref, aref); - Assembly rasm = Assembly.Load (aref); - etype = rasm.GetType (typeName); - if (etype != null) - return etype; + object rasm = reflector.LoadAssemblyFromReference (aref); + if (rasm != null) { + etype = reflector.GetType (rasm, typeName); + if (etype != null) + return etype; + } } } return null; } - void RegisterTypeNode (AddinDescription config, ExtensionAttribute eatt, string path, string nodeName, Type t) + void RegisterTypeNode (AddinDescription config, ExtensionAttribute eatt, string path, string nodeName, string typeFullName) { ExtensionNodeDescription elem = config.MainModule.AddExtensionNode (path, nodeName); if (eatt.Id.Length > 0) { elem.SetAttribute ("id", eatt.Id); - elem.SetAttribute ("type", t.FullName); + elem.SetAttribute ("type", typeFullName); } else { - elem.SetAttribute ("id", t.FullName); + elem.SetAttribute ("id", typeFullName); } if (eatt.InsertAfter.Length > 0) elem.SetAttribute ("insertafter", eatt.InsertAfter); @@ -889,9 +905,9 @@ namespace Mono.Addins.Database elem.SetAttribute ("insertbefore", eatt.InsertAfter); } - internal string GetDefaultTypeExtensionPath (AddinDescription desc, Type type) + internal string GetDefaultTypeExtensionPath (AddinDescription desc, string typeFullName) { - return "/" + Addin.GetIdName (desc.AddinId) + "/TypeExtensions/" + type.FullName; + return "/" + Addin.GetIdName (desc.AddinId) + "/TypeExtensions/" + typeFullName; } } } diff --git a/Mono.Addins/Mono.Addins.Database/DefaultAssemblyReflector.cs b/Mono.Addins/Mono.Addins.Database/DefaultAssemblyReflector.cs new file mode 100644 index 0000000..4e69d68 --- /dev/null +++ b/Mono.Addins/Mono.Addins.Database/DefaultAssemblyReflector.cs @@ -0,0 +1,133 @@ +// DefaultAssemblyReflector.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2007 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// + +using System; +using System.Reflection; +using System.Collections; + +namespace Mono.Addins.Database +{ + + + public class DefaultAssemblyReflector: IAssemblyReflector + { + public void Initialize (IAssemblyLocator locator) + { + } + + public object LoadAssembly (string file) + { + return Util.LoadAssemblyForReflection (file); + } + + public object[] GetCustomAttributes (object obj, Type type, bool inherit) + { + ICustomAttributeProvider aprov = obj as ICustomAttributeProvider; + if (aprov != null) + return aprov.GetCustomAttributes (type, inherit); + else + return new object [0]; + } + + public object GetCustomAttribute (object obj, Type type, bool inherit) + { + foreach (object att in GetCustomAttributes (obj, type, inherit)) + if (type.IsInstanceOfType (obj)) + return att; + return null; + } + + public string GetTypeName (object type) + { + return ((Type)type).Name; + } + + public IEnumerable GetFields (object type) + { + return ((Type)type).GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + } + + public string GetFieldName (object field) + { + return ((FieldInfo)field).Name; + } + + public string GetFieldTypeFullName (object field) + { + return ((FieldInfo)field).FieldType.FullName; + } + + public IEnumerable GetAssemblyTypes (object asm) + { + return ((Assembly)asm).GetTypes (); + } + + public IEnumerable GetBaseTypeFullNameList (object type) + { + ArrayList list = new ArrayList (); + Type btype = ((Type)type).BaseType; + while (btype != typeof(object)) { + list.Add (btype.FullName); + btype = btype.BaseType; + } + foreach (Type iterf in ((Type)type).GetInterfaces ()) { + list.Add (iterf.FullName); + } + return list; + } + + public object LoadAssemblyFromReference (object asmReference) + { + return Assembly.Load ((AssemblyName)asmReference); + } + + public IEnumerable GetAssemblyReferences (object asm) + { + return ((Assembly)asm).GetReferencedAssemblies (); + } + + public object GetType (object asm, string typeName) + { + return ((Assembly)asm).GetType (typeName); + } + + public string GetTypeFullName (object type) + { + return ((Type)type).FullName; + } + + public bool TypeIsAssignableFrom (object baseType, object type) + { + return ((Type)baseType).IsAssignableFrom ((Type)type); + } + + public string GetTypeAssemblyQualifiedName (object type) + { + return ((Type)type).AssemblyQualifiedName; + } + } +} diff --git a/Mono.Addins/Mono.Addins.Database/IAssemblyReflector.cs b/Mono.Addins/Mono.Addins.Database/IAssemblyReflector.cs new file mode 100644 index 0000000..ed38c92 --- /dev/null +++ b/Mono.Addins/Mono.Addins.Database/IAssemblyReflector.cs @@ -0,0 +1,61 @@ +// IAssemblyReflector.cs +// +// Author: +// Lluis Sanchez Gual <lluis@novell.com> +// +// Copyright (c) 2007 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +// + +using System; +using System.Collections; + +namespace Mono.Addins.Database +{ + public interface IAssemblyReflector + { + void Initialize (IAssemblyLocator locator); + + object[] GetCustomAttributes (object obj, Type type, bool inherit); + + object LoadAssembly (string file); + object LoadAssemblyFromReference (object asmReference); + IEnumerable GetAssemblyTypes (object asm); + IEnumerable GetAssemblyReferences (object asm); + + object GetType (object asm, string typeName); + object GetCustomAttribute (object obj, Type type, bool inherit); + string GetTypeName (object type); + string GetTypeFullName (object type); + string GetTypeAssemblyQualifiedName (object type); + IEnumerable GetBaseTypeFullNameList (object type); + bool TypeIsAssignableFrom (object baseType, object type); + + IEnumerable GetFields (object type); + string GetFieldName (object field); + string GetFieldTypeFullName (object field); + } + + public interface IAssemblyLocator + { + string GetAssemblyLocation (string fullName); + } +} diff --git a/Mono.Addins/Mono.Addins.mdp b/Mono.Addins/Mono.Addins.mdp index 31409e6..887d08d 100644 --- a/Mono.Addins/Mono.Addins.mdp +++ b/Mono.Addins/Mono.Addins.mdp @@ -91,6 +91,8 @@ <File name="Mono.Addins.Localization/GettextLocalizer.cs" subtype="Code" buildaction="Compile" /> <File name="Mono.Addins.Localization/GettextDomain.cs" subtype="Code" buildaction="Compile" /> <File name="Mono.Addins.Localization/IPluralAddinLocalizer.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Addins.Database/IAssemblyReflector.cs" subtype="Code" buildaction="Compile" /> + <File name="Mono.Addins.Database/DefaultAssemblyReflector.cs" subtype="Code" buildaction="Compile" /> </Contents> <References> <ProjectReference type="Gac" localcopy="True" refto="System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> diff --git a/Mono.Addins/Mono.Addins/ExtensionNodeChildAttribute.cs b/Mono.Addins/Mono.Addins/ExtensionNodeChildAttribute.cs index 88125e4..53581ea 100644 --- a/Mono.Addins/Mono.Addins/ExtensionNodeChildAttribute.cs +++ b/Mono.Addins/Mono.Addins/ExtensionNodeChildAttribute.cs @@ -36,6 +36,7 @@ namespace Mono.Addins { string nodeName; Type extensionNodeType; + string extensionNodeTypeName; public ExtensionNodeChildAttribute (string nodeName) : this (typeof(TypeExtensionNode), nodeName) @@ -60,7 +61,12 @@ namespace Mono.Addins public Type ExtensionNodeType { get { return extensionNodeType; } - set { extensionNodeType = value; } + set { extensionNodeType = value; extensionNodeTypeName = value.FullName; } + } + + internal string ExtensionNodeTypeName { + get { return extensionNodeTypeName; } + set { extensionNodeTypeName = value; extensionNodeType = null; } } } } diff --git a/Mono.Addins/Mono.Addins/ExtensionPointAttribute.cs b/Mono.Addins/Mono.Addins/ExtensionPointAttribute.cs index 5d8fe31..b40023c 100644 --- a/Mono.Addins/Mono.Addins/ExtensionPointAttribute.cs +++ b/Mono.Addins/Mono.Addins/ExtensionPointAttribute.cs @@ -40,6 +40,8 @@ namespace Mono.Addins string desc; string name; Type objectType; + string nodeTypeName; + string objectTypeName; public ExtensionPointAttribute () { @@ -75,12 +77,22 @@ namespace Mono.Addins public Type NodeType { get { return nodeType != null ? nodeType : typeof(TypeExtensionNode); } - set { nodeType = value; } + set { nodeType = value; nodeTypeName = value.FullName; } } public Type ObjectType { get { return objectType; } - set { objectType = value; } + set { objectType = value; objectTypeName = value.FullName; } + } + + internal string NodeTypeName { + get { return nodeTypeName != null ? nodeTypeName : typeof(TypeExtensionNode).FullName; } + set { nodeTypeName = value; } + } + + internal string ObjectTypeName { + get { return objectTypeName; } + set { objectTypeName = value; } } public string NodeName { diff --git a/Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs b/Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs index 9a5fc70..2bccb74 100644 --- a/Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs +++ b/Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs @@ -38,6 +38,7 @@ namespace Mono.Addins bool required; bool localizable; Type type; + string typeName; string description; public NodeAttributeAttribute () @@ -101,7 +102,12 @@ namespace Mono.Addins public Type Type { get { return type; } - set { type = value; } + set { type = value; typeName = type.FullName; } + } + + internal string TypeName { + get { return typeName; } + set { typeName = value; type = null; } } public string Description { diff --git a/Mono.Addins/Mono.Addins/TypeExtensionPointAttribute.cs b/Mono.Addins/Mono.Addins/TypeExtensionPointAttribute.cs index e858194..f349f55 100644 --- a/Mono.Addins/Mono.Addins/TypeExtensionPointAttribute.cs +++ b/Mono.Addins/Mono.Addins/TypeExtensionPointAttribute.cs @@ -37,6 +37,7 @@ namespace Mono.Addins string path; string nodeName; Type nodeType; + string nodeTypeName; string desc; string name; @@ -71,7 +72,12 @@ namespace Mono.Addins public Type NodeType { get { return nodeType != null ? nodeType : typeof(TypeExtensionNode); } - set { nodeType = value; } + set { nodeType = value; nodeTypeName = value.FullName; } + } + + internal string NodeTypeName { + get { return nodeTypeName != null ? nodeTypeName : typeof(TypeExtensionNode).FullName; } + set { nodeTypeName = value; nodeType = null; } } } } diff --git a/configure.ac b/configure.ac index 6a8b9be..1d44af3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ dnl Warning: This is an automatically generated file, do not edit! dnl Process this file with autoconf to produce a configure script. AC_PREREQ([2.54]) -AC_INIT([mono-addins], [0.3.1]) +AC_INIT([mono-addins], [0.4]) AM_INIT_AUTOMAKE([foreign]) dnl pkg-config @@ -10,9 +10,9 @@ if test "x$PKG_CONFIG" = "xno"; then AC_MSG_ERROR([You need to install pkg-config]) fi -API_VERSION=0.3.0.0 +API_VERSION=0.4.0.0 AC_SUBST(API_VERSION) -POLICY_VERSIONS="0.2" +POLICY_VERSIONS="0.2 0.3" AC_SUBST(POLICY_VERSIONS) AC_PROG_INSTALL @@ -80,6 +80,7 @@ AC_CONFIG_FILES([ ./Mono.Addins.Gui/Makefile ./Mono.Addins.Setup/Makefile ./Mono.Addins/Makefile +./Mono.Addins.CecilReflector/Makefile ./mautil/Makefile ./mautil/mautil ./Test/HelloWorldExtension/Makefile |