Example #1
0
        public void Initialize()
        {
            CodeLines = new List <NuGenCodeLine>();

            CodeLines.Add(new NuGenCodeLine(0, ".module " + Name));
            CodeLines.Add(new NuGenCodeLine(0, "// MVID: {" + Mvid.ToString() + "}"));
            CodeLines.Add(new NuGenCodeLine(0, ".imagebase 0x" + NuGenHelperFunctions.FormatAsHexNumber(Assembly.ImageBase, 8)));
            CodeLines.Add(new NuGenCodeLine(0, ".file alignment 0x" + NuGenHelperFunctions.FormatAsHexNumber(Assembly.FileAlignment, 8)));

            if (Assembly.IsPe32)
            {
                CodeLines.Add(new NuGenCodeLine(0, ".stackreserve 0x" + NuGenHelperFunctions.FormatAsHexNumber(Assembly.StackReserve, 8)));
            }
            else
            {
                CodeLines.Add(new NuGenCodeLine(0, ".stackreserve 0x" + NuGenHelperFunctions.FormatAsHexNumber(Assembly.StackReserve, 16)));
            }

            CodeLines.Add(new NuGenCodeLine(0, string.Format(".subsystem 0x{0} //{1}", NuGenHelperFunctions.FormatAsHexNumber(Assembly.Subsystem, 4), (Assembly.Subsystem == 2 ? "WINDOWS_CE" : "WINDOWS_GUI"))));
            CodeLines.Add(new NuGenCodeLine(0, ".corflags 0x" + NuGenHelperFunctions.FormatAsHexNumber(Assembly.CorFlags, 8)));

            string peFormat = "//PE Format: ";

            if (Assembly.IsPe32)
            {
                peFormat += "PE32 (32 bit assembly)";
            }
            else
            {
                peFormat += "PE32+ (64 bit assembly)";
            }
            CodeLines.Add(new NuGenCodeLine(0, peFormat));
        }
Example #2
0
        public override void DecodeParameter()
        {
            StringBuilder fullInstructionBuilder = new StringBuilder();

            fullInstructionBuilder.Append("switch (");

            for (int index = 0; index < Parameter.Length; index++)
            {
                fullInstructionBuilder.AppendFormat("IL_{0}", NuGenHelperFunctions.FormatAsHexNumber(RelativeTargetAddress(Parameter[index]), 4));

                if (index == Parameter.Length - 1)
                {
                    fullInstructionBuilder.Append(")");
                }
                else
                {
                    fullInstructionBuilder.Append(", ");
                }
            }

            Text = fullInstructionBuilder.ToString();
        }
        public void Initialize()
        {
            ReadMetadata();
            CodeLines = new List <NuGenCodeLine>();
            StringBuilder definition = new StringBuilder();

            definition.Append(".field ");
            definition.Append(ContractAttributesAsString());
            definition.Append(MemberAccessAsString());
            definition.Append(ReservedFlagsAsString());
            definition.Append(FieldTypeName);
            definition.Append(" ");
            definition.Append(Name);

            if ((Flags & CorFieldAttr.fdHasDefault) == CorFieldAttr.fdHasDefault)
            {
                definition.Append(" = ");
                definition.Append(DefaultValueAsString);
            }

            if (((Flags & CorFieldAttr.fdReservedMask) & CorFieldAttr.fdHasFieldRVA) == CorFieldAttr.fdHasFieldRVA)
            {
                definition.Append(" at D_");
                definition.Append(NuGenHelperFunctions.FormatAsHexNumber(Rva, 8));
            }

            CodeLines.Add(new NuGenCodeLine(0, definition.ToString()));

            if (CustomAttributes != null)
            {
                NuGenAssembly assembly = BaseTypeDefinition.ModuleScope.Assembly;

                foreach (NuGenCustomAttribute customAttribute in CustomAttributes)
                {
                    customAttribute.SetText(assembly.AllTokens);
                    CodeLines.Add(new NuGenCodeLine(0, customAttribute.Name));
                }
            }
        }
Example #4
0
        public void SetText(Dictionary <uint, NuGenTokenBase> allTokens)
        {
            NameBuilder.Length = 0;
            NameBuilder.Append(".custom ");
            NameBuilder.Append(allTokens[type]);

            NameBuilder.Append(" = (");
            uint lastByte = BlobLength - 1;

            for (int blobIndex = 0; blobIndex < BlobLength; blobIndex++)
            {
                NameBuilder.Append(NuGenHelperFunctions.FormatAsHexNumber(Marshal.ReadByte(Blob), 2));

                if (blobIndex < lastByte)
                {
                    NameBuilder.Append(" ");
                    NuGenHelperFunctions.StepIntPtr(ref blob);
                }
            }
            NameBuilder.Append(")");

            Name = NameBuilder.ToString();
        }
        public override void DecodeParameter()
        {
            int targetAddress = Offset + (typeof(LocationType) == typeof(sbyte) ? 2 : 5);

            Text = string.Format("{0} IL_{1}", OpCode.Name, NuGenHelperFunctions.FormatAsHexNumber(Convert.ToInt32(DecodedParameter) + targetAddress, 4));
        }
        public void Initialize()
        {
            CodeLines = new List <NuGenCodeLine>();

            StringBuilder definitionBuilder = new StringBuilder(".mresource ");

            if ((Flags & CorManifestResourceFlags.mrPublic) == CorManifestResourceFlags.mrPublic)
            {
                definitionBuilder.Append("public ");
            }
            else
            {
                definitionBuilder.Append("private ");
            }

            definitionBuilder.Append(Name);

            NuGenCodeLine definition = new NuGenCodeLine(0, definitionBuilder.ToString());

            CodeLines.Add(definition);

            CodeLines.Add(new NuGenCodeLine(0, "{"));

            CodeLines.Add(new NuGenCodeLine(1, string.Format(".file {0} at 0x{1}", Name, NuGenHelperFunctions.FormatAsHexNumber(Offset, 8))));

            CodeLines.Add(new NuGenCodeLine(0, "}"));
        }