Inheritance: BlobConstant
Example #1
0
 /*----------------------------- internal functions ------------------------------*/
 internal void DecodeCustomAttributeBlob()
 {
     MemoryStream caBlob = new MemoryStream(byteVal);
     BinaryReader blob = new BinaryReader(caBlob,System.Text.Encoding.UTF8);
     if (blob.ReadUInt16() != CustomAttribute.prolog) throw new PEFileException("Invalid Custom Attribute Blob");
     Type[] parTypes = type.GetParTypes();
     argVals = new Constant[parTypes.Length];
     for (int i=0; i < parTypes.Length; i++) {
         Type argType = parTypes[i];
         bool arrayConst = argType is Array;
         if (arrayConst) argType = ((ZeroBasedArray)(parTypes[i])).ElemType();
         bool boxed = argType is SystemClass;
         int eType = argType.GetTypeIndex();
         if (arrayConst) {
             Constant[] elems = new Constant[blob.ReadUInt32()];
             for (int j=0; j < elems.Length; j++) {
                 if (boxed) {
                     eType = blob.ReadByte();
                     elems[j] = new BoxedSimpleConst((SimpleConstant)PEReader.ReadConst(eType,blob));
                 } else {
                     elems[j] = PEReader.ReadConst(eType,blob);
                 }
             }
             argVals[i] = new ArrayConst(elems);
         } else if (boxed) {
             argVals[i] = new BoxedSimpleConst((SimpleConstant)PEReader.ReadConst(blob.ReadByte(),blob));
         } else {
             argVals[i] = PEReader.ReadConst(eType,blob);
         }
     }
     uint numNamed = 0;
     if (blob.BaseStream.Position != byteVal.Length)
         numNamed = blob.ReadUInt16();
     if (numNamed > 0) {
         names = new string[numNamed];
         vals = new Constant[numNamed];
         isField = new bool[numNamed];
         for (int i=0; i < numNamed; i++) {
             isField[i] = blob.ReadByte() == 0x53;
             int eType = blob.ReadByte();
             names[i] = blob.ReadString();
             vals[i] = PEReader.ReadConst(eType,blob);
         }
     }
 }