Ejemplo n.º 1
0
        bool FindIVT(RidList rids, out bool foundIVT, out uint ivtBlobDataOffset)
        {
            ivtBlobDataOffset = 0;
            foundIVT          = false;
            uint otherIVTBlobOffset = uint.MaxValue;

            using (var blobStream = md.BlobStream.GetClonedImageStream()) {
                var  tbl         = md.TablesStream.CustomAttributeTable;
                uint baseOffset  = (uint)tbl.StartOffset;
                var  columnType  = tbl.Columns[1];
                var  columnValue = tbl.Columns[2];
                for (int i = 0; i < rids.Count; i++)
                {
                    uint rid    = rids[i];
                    uint offset = baseOffset + (rid - 1) * tbl.RowSize;
                    uint type   = ReadColumn(columnType, offset);
                    if (!IsIVTCtor(type))
                    {
                        continue;
                    }
                    foundIVT = true;
                    uint blobOffset = ReadColumn(columnValue, offset);
                    if (blobOffset + ivtBlob.Length > blobStream.Length)
                    {
                        continue;
                    }
                    blobStream.Position = blobOffset;
                    if (!blobStream.ReadCompressedUInt32(out uint len))
                    {
                        continue;
                    }
                    var compressedSize = blobStream.Position - blobOffset;
                    if (compressedSize + len < ivtBlob.Length)
                    {
                        continue;
                    }
                    if (!ParseIVTBlob(blobStream, blobStream.Position + len, out var publicKeyString))
                    {
                        continue;
                    }
                    if (StringComparer.OrdinalIgnoreCase.Equals(publicKeyString, ROSLYN_OPEN_SOURCE_PUBLIC_KEY))
                    {
                        ivtBlobDataOffset = (uint)md.BlobStream.StartOffset + blobOffset;
                        return(true);
                    }
                    else
                    {
                        otherIVTBlobOffset = (uint)md.BlobStream.StartOffset + blobOffset;
                    }
                }
            }
            if (otherIVTBlobOffset != uint.MaxValue)
            {
                ivtBlobDataOffset = otherIVTBlobOffset;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
 void ReadConstants(SymbolScopeImpl scope, RidList rids)
 {
     if (rids.Count == 0)
     {
         return;
     }
     scope.SetConstants(pdbMetadata, rids);
 }
Ejemplo n.º 3
0
        private void Button2_Click(object sender, EventArgs e)
        {
            //打开.NET程序集/模块
            ModuleDefMD module = ModuleDefMD.Load(this.textBox1.Text);

            RidList typeDef = module.Metadata.GetTypeDefRidList();

            for (int i = 0; i < module.Types.Count; i++)
            {
                var t = module.Types[i];
                if (t.Name == "TestAction")
                {
                    for (int j = 0; j < t.Methods.Count; j++)
                    {
                        if (t.Methods[j].Name == "Check")
                        {
                            var method = t.Methods[j];

                            Instruction[] opCodes =
                            {
                                Instruction.Create(OpCodes.Ldc_I4_1),
                                Instruction.Create(OpCodes.Ret)
                            };
                            for (int l = 0; l < opCodes.Length; l++)
                            {
                                method.Body.Instructions[l] = opCodes[l];
                            }
                        }
                    }
                }
            }

            //保存程序集
            module.Write(@"C:\Users\tchivs\source\repos\ComponentOneCrack\TestLibrary\bin\Debug\TestLibraryCrack.dll", new ModuleWriterOptions(module)
            {
                MetadataOptions = { Flags = MetadataFlags.KeepOldMaxStack }
            });
        }
Ejemplo n.º 4
0
        void ReadVariables(SymbolScopeImpl scope, GenericParamContext gpContext, RidList rids)
        {
            if (rids.Count == 0)
            {
                return;
            }
            var table     = pdbMetadata.TablesStream.LocalVariableTable;
            var custInfos = ListCache <PdbCustomDebugInfo> .AllocList();

            for (int i = 0; i < rids.Count; i++)
            {
                var rid   = rids[i];
                int token = new MDToken(Table.LocalVariable, rid).ToInt32();
                custInfos.Clear();
                GetCustomDebugInfos(token, gpContext, custInfos);
                var  customDebugInfos = custInfos.Count == 0 ? Array2.Empty <PdbCustomDebugInfo>() : custInfos.ToArray();
                bool b = pdbMetadata.TablesStream.TryReadLocalVariableRow(rid, out var row);
                Debug.Assert(b);
                var name = pdbMetadata.StringsStream.Read(row.Name);
                scope.localsList.Add(new SymbolVariableImpl(name, ToSymbolVariableAttributes(row.Attributes), row.Index, customDebugInfos));
            }
            ListCache <PdbCustomDebugInfo> .Free(ref custInfos);
        }
Ejemplo n.º 5
0
 internal void SetConstants(Metadata metadata, RidList rids)
 {
     constantsMetadata = metadata;
     constantRidList   = rids;
 }