コード例 #1
0
ファイル: CilBodyVM.cs プロジェクト: cynecx/dnSpy
        public CilBodyOptions CopyTo(CilBodyOptions options)
        {
            var ops = new Dictionary <object, object>();

            foreach (var vm in LocalsListVM)
            {
                ops.Add(vm, vm.CreateLocalOptions().Create());
            }
            foreach (var vm in InstructionsListVM)
            {
                ops.Add(vm, new Instruction());
            }

            options.KeepOldMaxStack = KeepOldMaxStack;
            options.InitLocals      = InitLocals;
            options.MaxStack        = MaxStack.Value;
            options.LocalVarSigTok  = LocalVarSigTok.Value;
            options.HeaderSize      = HeaderSize.Value;
            options.Locals.Clear();
            options.Locals.AddRange(LocalsListVM.Select(a => (Local)ops[a]));
            options.Instructions.Clear();
            options.Instructions.AddRange(InstructionsListVM.Select(a => a.CreateInstructionOptions().CopyTo(ops, (Instruction)ops[a])));
            options.ExceptionHandlers.Clear();
            options.ExceptionHandlers.AddRange(ExceptionHandlersListVM.Select(a => a.CreateExceptionHandlerOptions().Create(ops)));
            return(options);
        }
コード例 #2
0
ファイル: CilBodyVM.cs プロジェクト: BahNahNah/dnSpy
        public CilBodyVM(CilBodyOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType, MethodDef ownerMethod)
        {
            this.ownerModule = ownerModule;
            this.ownerMethod = ownerMethod;
            this.origOptions = options;

            typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language) {
                CanAddGenericTypeVar = ownerType.HasGenericParameters,
                CanAddGenericMethodVar = ownerMethod.MethodSig.GetGenParamCount() > 0,
                OwnerType = ownerType,
                OwnerMethod = ownerMethod,
            };

            this.localsListVM = new IndexObservableCollection<LocalVM>(() => new LocalVM(typeSigCreatorOptions, new LocalOptions(new Local(ownerModule.CorLibTypes.Int32))));
            this.instructionsListVM = new IndexObservableCollection<InstructionVM>(() => CreateInstructionVM());
            this.exceptionHandlersListVM = new IndexObservableCollection<ExceptionHandlerVM>(() => new ExceptionHandlerVM(typeSigCreatorOptions, new ExceptionHandlerOptions()));
            this.LocalsListVM.UpdateIndexesDelegate = LocalsUpdateIndexes;
            this.InstructionsListVM.UpdateIndexesDelegate = InstructionsUpdateIndexes;
            this.ExceptionHandlersListVM.UpdateIndexesDelegate = ExceptionHandlersUpdateIndexes;
            this.InstructionsListVM.CollectionChanged += InstructionsListVM_CollectionChanged;
            this.LocalsListVM.CollectionChanged += LocalsListVM_CollectionChanged;
            this.ExceptionHandlersListVM.CollectionChanged += ExceptionHandlersListVM_CollectionChanged;
            this.maxStack = new UInt16VM(a => CallHasErrorUpdated());
            this.localVarSigTok = new UInt32VM(a => CallHasErrorUpdated());
            this.headerSize = new ByteVM(a => CallHasErrorUpdated());
            this.headerRVA = new UInt32VM(a => CallHasErrorUpdated());
            this.headerFileOffset = new UInt64VM(a => CallHasErrorUpdated());
            this.rva = new UInt32VM(a => CallHasErrorUpdated());
            this.fileOffset = new UInt64VM(a => CallHasErrorUpdated());

            Reinitialize();
        }
コード例 #3
0
ファイル: CilBodyVM.cs プロジェクト: cynecx/dnSpy
        public CilBodyVM(CilBodyOptions options, ModuleDef ownerModule, Language language, TypeDef ownerType, MethodDef ownerMethod)
        {
            this.ownerModule = ownerModule;
            this.ownerMethod = ownerMethod;
            this.origOptions = options;

            typeSigCreatorOptions = new TypeSigCreatorOptions(ownerModule, language)
            {
                CanAddGenericTypeVar   = ownerType.HasGenericParameters,
                CanAddGenericMethodVar = ownerMethod.MethodSig.GetGenParamCount() > 0,
                OwnerType   = ownerType,
                OwnerMethod = ownerMethod,
            };

            this.localsListVM                                  = new IndexObservableCollection <LocalVM>(() => new LocalVM(typeSigCreatorOptions, new LocalOptions(new Local(ownerModule.CorLibTypes.Int32))));
            this.instructionsListVM                            = new IndexObservableCollection <InstructionVM>(() => CreateInstructionVM());
            this.exceptionHandlersListVM                       = new IndexObservableCollection <ExceptionHandlerVM>(() => new ExceptionHandlerVM(typeSigCreatorOptions, new ExceptionHandlerOptions()));
            this.LocalsListVM.UpdateIndexesDelegate            = LocalsUpdateIndexes;
            this.InstructionsListVM.UpdateIndexesDelegate      = InstructionsUpdateIndexes;
            this.ExceptionHandlersListVM.UpdateIndexesDelegate = ExceptionHandlersUpdateIndexes;
            this.InstructionsListVM.CollectionChanged         += InstructionsListVM_CollectionChanged;
            this.LocalsListVM.CollectionChanged               += LocalsListVM_CollectionChanged;
            this.ExceptionHandlersListVM.CollectionChanged    += ExceptionHandlersListVM_CollectionChanged;
            this.maxStack         = new UInt16VM(a => CallHasErrorUpdated());
            this.localVarSigTok   = new UInt32VM(a => CallHasErrorUpdated());
            this.headerSize       = new ByteVM(a => CallHasErrorUpdated());
            this.headerRVA        = new UInt32VM(a => CallHasErrorUpdated());
            this.headerFileOffset = new UInt64VM(a => CallHasErrorUpdated());
            this.rva        = new UInt32VM(a => CallHasErrorUpdated());
            this.fileOffset = new UInt64VM(a => CallHasErrorUpdated());

            Reinitialize();
        }
コード例 #4
0
ファイル: CilBodyVM.cs プロジェクト: cynecx/dnSpy
        public void InitializeFrom(CilBodyOptions options)
        {
            try {
                LocalsListVM.DisableAutoUpdateProps            = true;
                InstructionsListVM.DisableAutoUpdateProps      = true;
                ExceptionHandlersListVM.DisableAutoUpdateProps = true;
                HasError_disabled = true;

                var ops = new Dictionary <object, object>();
                foreach (var local in options.Locals)
                {
                    ops.Add(local, new LocalVM(typeSigCreatorOptions, new LocalOptions(local)));
                }
                foreach (var instr in options.Instructions)
                {
                    ops.Add(instr, new InstructionVM(ownerModule));
                }
                foreach (var instr in options.Instructions)
                {
                    ((InstructionVM)ops[instr]).Initialize(new InstructionOptions(ops, instr));
                }

                KeepOldMaxStack        = options.KeepOldMaxStack;
                InitLocals             = options.InitLocals;
                MaxStack.Value         = options.MaxStack;
                LocalVarSigTok.Value   = options.LocalVarSigTok;
                HeaderSize.Value       = options.HeaderSize;
                HeaderRVA.Value        = (uint)options.HeaderRVA;
                HeaderFileOffset.Value = unchecked ((ulong)(long)options.HeaderFileOffset);
                RVA.Value        = (uint)options.RVA;
                FileOffset.Value = unchecked ((ulong)(long)options.FileOffset);
                LocalsListVM.Clear();
                LocalsListVM.AddRange(options.Locals.Select(a => (LocalVM)ops[a]));
                InstructionsListVM.Clear();
                InstructionsListVM.AddRange(options.Instructions.Select(a => (InstructionVM)ops[a]));
                ExceptionHandlersListVM.Clear();
                ExceptionHandlersListVM.AddRange(options.ExceptionHandlers.Select(a => new ExceptionHandlerVM(typeSigCreatorOptions, new ExceptionHandlerOptions(ops, a))));
            }
            finally {
                HasError_disabled = false;
                LocalsListVM.DisableAutoUpdateProps            = false;
                InstructionsListVM.DisableAutoUpdateProps      = false;
                ExceptionHandlersListVM.DisableAutoUpdateProps = false;
            }
            LocalsUpdateIndexes(0);
            InstructionsUpdateIndexes(0);
            ExceptionHandlersUpdateIndexes(0);
        }
コード例 #5
0
ファイル: MethodBodyOptions.cs プロジェクト: BahNahNah/dnSpy
 public MethodBodyOptions(MethodDef method)
 {
     this.CodeType = method.CodeType;
     if (method.MethodBody is CilBody) {
         var headerRva = method.RVA;
         var headerFileOffset = (FileOffset)method.Module.ToFileOffset((uint)headerRva);
         var rva = (RVA)((uint)headerRva + method.Body.HeaderSize);
         var fileOffset = (FileOffset)((long)headerFileOffset + method.Body.HeaderSize);
         this.CilBodyOptions = new CilBodyOptions((CilBody)method.MethodBody, headerRva, headerFileOffset, rva, fileOffset);
         this.BodyType = MethodBodyType.Cil;
     }
     else if (method.MethodBody is NativeMethodBody) {
         this.NativeMethodBodyOptions = new NativeMethodBodyOptions((NativeMethodBody)method.MethodBody);
         this.BodyType = MethodBodyType.Native;
     }
     else
         this.BodyType = MethodBodyType.None;
 }
コード例 #6
0
ファイル: MethodBodyOptions.cs プロジェクト: lisong521/dnSpy
		public MethodBodyOptions(MethodDef method)
		{
			this.CodeType = method.CodeType;
			if (method.MethodBody is CilBody) {
				FileOffset fileOffset = 0;
				var mod = method.Module as ModuleDefMD;
				if (mod != null)
					fileOffset = mod.MetaData.PEImage.ToFileOffset(method.RVA);
				this.CilBodyOptions = new CilBodyOptions((CilBody)method.MethodBody, method.RVA, fileOffset);
				this.BodyType = MethodBodyType.Cil;
			}
			else if (method.MethodBody is NativeMethodBody) {
				this.NativeMethodBodyOptions = new NativeMethodBodyOptions((NativeMethodBody)method.MethodBody);
				this.BodyType = MethodBodyType.Native;
			}
			else
				this.BodyType = MethodBodyType.None;
		}
コード例 #7
0
ファイル: MethodBodyOptions.cs プロジェクト: cynecx/dnSpy
 public MethodBodyOptions(MethodDef method)
 {
     this.CodeType = method.CodeType;
     if (method.MethodBody is CilBody)
     {
         var headerRva        = method.RVA;
         var headerFileOffset = (FileOffset)method.Module.ToFileOffset((uint)headerRva);
         var rva        = (RVA)((uint)headerRva + method.Body.HeaderSize);
         var fileOffset = (FileOffset)((long)headerFileOffset + method.Body.HeaderSize);
         this.CilBodyOptions = new CilBodyOptions((CilBody)method.MethodBody, headerRva, headerFileOffset, rva, fileOffset);
         this.BodyType       = MethodBodyType.Cil;
     }
     else if (method.MethodBody is NativeMethodBody)
     {
         this.NativeMethodBodyOptions = new NativeMethodBodyOptions((NativeMethodBody)method.MethodBody);
         this.BodyType = MethodBodyType.Native;
     }
     else
     {
         this.BodyType = MethodBodyType.None;
     }
 }
コード例 #8
0
ファイル: MethodBodyOptions.cs プロジェクト: jorik041/dnSpy
 public MethodBodyOptions(MethodDef method)
 {
     this.CodeType = method.CodeType;
     if (method.MethodBody is CilBody)
     {
         FileOffset fileOffset = 0;
         var        mod        = method.Module as ModuleDefMD;
         if (mod != null)
         {
             fileOffset = mod.MetaData.PEImage.ToFileOffset(method.RVA);
         }
         this.CilBodyOptions = new CilBodyOptions((CilBody)method.MethodBody, method.RVA, fileOffset);
         this.BodyType       = MethodBodyType.Cil;
     }
     else if (method.MethodBody is NativeMethodBody)
     {
         this.NativeMethodBodyOptions = new NativeMethodBodyOptions((NativeMethodBody)method.MethodBody);
         this.BodyType = MethodBodyType.Native;
     }
     else
     {
         this.BodyType = MethodBodyType.None;
     }
 }
コード例 #9
0
ファイル: CilBodyVM.cs プロジェクト: BahNahNah/dnSpy
        public void InitializeFrom(CilBodyOptions options)
        {
            try {
                LocalsListVM.DisableAutoUpdateProps = true;
                InstructionsListVM.DisableAutoUpdateProps = true;
                ExceptionHandlersListVM.DisableAutoUpdateProps = true;
                HasError_disabled = true;

                var ops = new Dictionary<object, object>();
                foreach (var local in options.Locals)
                    ops.Add(local, new LocalVM(typeSigCreatorOptions, new LocalOptions(local)));
                foreach (var instr in options.Instructions)
                    ops.Add(instr, new InstructionVM(ownerModule));
                foreach (var instr in options.Instructions)
                    ((InstructionVM)ops[instr]).Initialize(new InstructionOptions(ops, instr));

                KeepOldMaxStack = options.KeepOldMaxStack;
                InitLocals = options.InitLocals;
                MaxStack.Value = options.MaxStack;
                LocalVarSigTok.Value = options.LocalVarSigTok;
                HeaderSize.Value = options.HeaderSize;
                HeaderRVA.Value = (uint)options.HeaderRVA;
                HeaderFileOffset.Value = unchecked((ulong)(long)options.HeaderFileOffset);
                RVA.Value = (uint)options.RVA;
                FileOffset.Value = unchecked((ulong)(long)options.FileOffset);
                LocalsListVM.Clear();
                LocalsListVM.AddRange(options.Locals.Select(a => (LocalVM)ops[a]));
                InstructionsListVM.Clear();
                InstructionsListVM.AddRange(options.Instructions.Select(a => (InstructionVM)ops[a]));
                ExceptionHandlersListVM.Clear();
                ExceptionHandlersListVM.AddRange(options.ExceptionHandlers.Select(a => new ExceptionHandlerVM(typeSigCreatorOptions, new ExceptionHandlerOptions(ops, a))));
            }
            finally {
                HasError_disabled = false;
                LocalsListVM.DisableAutoUpdateProps = false;
                InstructionsListVM.DisableAutoUpdateProps = false;
                ExceptionHandlersListVM.DisableAutoUpdateProps = false;
            }
            LocalsUpdateIndexes(0);
            InstructionsUpdateIndexes(0);
            ExceptionHandlersUpdateIndexes(0);
        }
コード例 #10
0
ファイル: CilBodyVM.cs プロジェクト: BahNahNah/dnSpy
        public CilBodyOptions CopyTo(CilBodyOptions options)
        {
            var ops = new Dictionary<object, object>();
            foreach (var vm in LocalsListVM)
                ops.Add(vm, vm.CreateLocalOptions().Create());
            foreach (var vm in InstructionsListVM)
                ops.Add(vm, new Instruction());

            options.KeepOldMaxStack = KeepOldMaxStack;
            options.InitLocals = InitLocals;
            options.MaxStack = MaxStack.Value;
            options.LocalVarSigTok = LocalVarSigTok.Value;
            options.HeaderSize = HeaderSize.Value;
            options.Locals.Clear();
            options.Locals.AddRange(LocalsListVM.Select(a => (Local)ops[a]));
            options.Instructions.Clear();
            options.Instructions.AddRange(InstructionsListVM.Select(a => a.CreateInstructionOptions().CopyTo(ops, (Instruction)ops[a])));
            options.ExceptionHandlers.Clear();
            options.ExceptionHandlers.AddRange(ExceptionHandlersListVM.Select(a => a.CreateExceptionHandlerOptions().Create(ops)));
            return options;
        }