Skip to content

Commit

Permalink
NRT updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Sep 22, 2020
1 parent 4aaccb6 commit 4c8c338
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public MethodSigCreatorVM(MethodSigCreatorOptions options) {
if (!IsMethodSig)
throw new InvalidOperationException();
CallingConvention = (CallingConvention & ~dnlib.DotNet.CallingConvention.Mask) |
(dnlib.DotNet.CallingConvention)(MethodCallingConv)MethodCallingConv.SelectedItem!;
(dnlib.DotNet.CallingConvention)(MethodCallingConv)MethodCallingConv!.SelectedItem!;
});
if (!CanHaveSentinel) {
MethodCallingConv.Items.RemoveAt(MethodCallingConv.GetIndex(DnlibDialogs.MethodCallingConv.VarArg));
Expand Down
4 changes: 2 additions & 2 deletions Extensions/dnSpy.AsmEditor/Module/ModuleOptionsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,10 @@ public ModuleOptionsVM(ModuleDef module, ModuleOptions options, IDecompilerServi
this.options = new ModuleOptions();
origOptions = options;
ModuleKind = new EnumListVM(SaveModule.SaveModuleOptionsVM.moduleKindList, (a, b) => {
Characteristics = SaveModule.CharacteristicsHelper.GetCharacteristics(Characteristics, (dnlib.DotNet.ModuleKind)ModuleKind.SelectedItem!);
Characteristics = SaveModule.CharacteristicsHelper.GetCharacteristics(Characteristics, (dnlib.DotNet.ModuleKind)ModuleKind!.SelectedItem!);
});
Machine = new EnumListVM(SaveModule.PEHeadersOptionsVM.machineList, (a, b) => {
Characteristics = SaveModule.CharacteristicsHelper.GetCharacteristics(Characteristics, (dnlib.PE.Machine)Machine.SelectedItem!);
Characteristics = SaveModule.CharacteristicsHelper.GetCharacteristics(Characteristics, (dnlib.PE.Machine)Machine!.SelectedItem!);
});
Mvid = new NullableGuidVM(a => HasErrorUpdated());
EncId = new NullableGuidVM(a => HasErrorUpdated());
Expand Down
4 changes: 2 additions & 2 deletions Extensions/dnSpy.AsmEditor/SaveModule/SaveModuleOptionsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public SaveModuleOptionsVM(IDsDocument document) {

ModuleKind = new EnumListVM(moduleKindList, (a, b) => {
OnPropertyChanged(nameof(Extension));
PEHeadersOptions.Subsystem.SelectedItem = GetSubsystem((ModuleKind)ModuleKind.SelectedItem!);
PEHeadersOptions.Subsystem.SelectedItem = GetSubsystem((ModuleKind)ModuleKind!.SelectedItem!);
PEHeadersOptions.Characteristics = CharacteristicsHelper.GetCharacteristics(PEHeadersOptions.Characteristics ?? 0, (ModuleKind)ModuleKind.SelectedItem!);
});

Expand Down Expand Up @@ -288,7 +288,7 @@ public PEHeadersOptionsVM(Machine defaultMachine, Subsystem defaultSubsystem) {
this.defaultMachine = defaultMachine;
this.defaultSubsystem = defaultSubsystem;
Machine = new EnumListVM(machineList, (a, b) => {
Characteristics = CharacteristicsHelper.GetCharacteristics(Characteristics ?? 0, (dnlib.PE.Machine)Machine.SelectedItem!);
Characteristics = CharacteristicsHelper.GetCharacteristics(Characteristics ?? 0, (dnlib.PE.Machine)Machine!.SelectedItem!);
});
TimeDateStamp = new NullableUInt32VM(a => HasErrorUpdated());
PointerToSymbolTable = new NullableUInt32VM(a => HasErrorUpdated());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ DmdCustomAttributeData[] ReadSecurityAttributesCore(uint token) {
return COMThread(() => ReadSecurityAttributesCore_COMThread(token));
}

#pragma warning disable SYSLIB0003 // SecurityAction
internal DmdCustomAttributeData[] ReadSecurityAttributesCore_COMThread(uint token) {
dispatcher.VerifyAccess();
var tokens = MDAPI.GetPermissionSetTokens(MetaDataImport, token);
Expand Down Expand Up @@ -1166,6 +1167,7 @@ internal DmdCustomAttributeData[] ReadSecurityAttributesCore_COMThread(uint toke
throw new InvalidOperationException();
return sas;
}
#pragma warning restore SYSLIB0003 // SecurityAction

internal DmdMarshalType? ReadFieldMarshalType_COMThread(int metadataToken, DmdModule module, IList<DmdType>? genericTypeArguments) {
dispatcher.VerifyAccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License
along with dnSpy. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma warning disable SYSLIB0003 // SecurityAction

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ DmdCustomAttributeData[] ReadCustomAttributesCore(Table table, uint rid) {
protected override DmdCustomAttributeData[] ReadTypeDefSecurityAttributes(uint rid) => ReadSecurityAttributesCore(Table.TypeDef, rid);
protected override DmdCustomAttributeData[] ReadMethodSecurityAttributes(uint rid) => ReadSecurityAttributesCore(Table.Method, rid);

#pragma warning disable SYSLIB0003 // SecurityAction
DmdCustomAttributeData[] ReadSecurityAttributesCore(Table table, uint rid) {
var ridList = Metadata.GetDeclSecurityRidList(table, rid);
if (ridList.Count == 0)
Expand Down Expand Up @@ -670,6 +671,7 @@ DmdCustomAttributeData[] ReadSecurityAttributesCore(Table table, uint rid) {
throw new InvalidOperationException();
return sas;
}
#pragma warning restore SYSLIB0003 // SecurityAction

internal DmdMarshalType? ReadMarshalType(int metadataToken, DmdModule module, IList<DmdType>? genericTypeArguments) {
if (!TablesStream.TryReadFieldMarshalRow(Metadata.GetFieldMarshalRid((Table)((uint)metadataToken >> 24), (uint)metadataToken & 0x00FFFFFF), out var row))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ public void Read(string filename) {
return;
var doc = XDocument.Load(filename, LoadOptions.None);
var root = doc.Root;
if (root.Name == "Exceptions") {
if (root?.Name == "Exceptions") {
foreach (var categoryDefElem in root.Elements("CategoryDef")) {
var name = (string)categoryDefElem.Attribute("Name");
var displayName = (string)categoryDefElem.Attribute("DisplayName");
var shortDisplayName = (string)categoryDefElem.Attribute("ShortDisplayName");
var flagsAttr = (string)categoryDefElem.Attribute("Flags");
if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(displayName) || string.IsNullOrWhiteSpace(shortDisplayName))
var name = (string?)categoryDefElem.Attribute("Name");
var displayName = (string?)categoryDefElem.Attribute("DisplayName");
var shortDisplayName = (string?)categoryDefElem.Attribute("ShortDisplayName");
var flagsAttr = (string?)categoryDefElem.Attribute("Flags");
if (string2.IsNullOrWhiteSpace(name) || string2.IsNullOrWhiteSpace(displayName) || string2.IsNullOrWhiteSpace(shortDisplayName))
continue;
var flags = ParseCategoryFlags(flagsAttr);
CategoryDefinitions.Add(new DbgExceptionCategoryDefinition(flags, name, displayName, shortDisplayName));
}
foreach (var exDefCollElem in root.Elements("ExceptionDefs")) {
var category = (string)exDefCollElem.Attribute("Category");
if (string.IsNullOrWhiteSpace(category))
var category = (string?)exDefCollElem.Attribute("Category");
if (string2.IsNullOrWhiteSpace(category))
continue;
foreach (var exDefElem in exDefCollElem.Elements("Exception")) {
var name = (string)exDefElem.Attribute("Name");
var code = (string)exDefElem.Attribute("Code");
string? description = (string)exDefElem.Attribute("Description");
if (string.IsNullOrWhiteSpace(description))
var name = (string?)exDefElem.Attribute("Name");
var code = (string?)exDefElem.Attribute("Code");
string? description = (string?)exDefElem.Attribute("Description");
if (string2.IsNullOrWhiteSpace(description))
description = null;
var flagsAttr = (string)exDefElem.Attribute("Flags");
var flagsAttr = (string?)exDefElem.Attribute("Flags");
DbgExceptionId id;
if (code is null) {
if (string.IsNullOrWhiteSpace(name))
if (string2.IsNullOrWhiteSpace(name))
continue;
id = new DbgExceptionId(category, name);
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public void Read(string filename) {
}

static readonly char[] flagsSeparators = new char[] { ',' };
static DbgExceptionCategoryDefinitionFlags ParseCategoryFlags(string flagsAttr) {
static DbgExceptionCategoryDefinitionFlags ParseCategoryFlags(string? flagsAttr) {
var flags = DbgExceptionCategoryDefinitionFlags.None;
if (!(flagsAttr is null)) {
foreach (var name in flagsAttr.Split(flagsSeparators, StringSplitOptions.RemoveEmptyEntries)) {
Expand All @@ -109,7 +109,7 @@ static DbgExceptionCategoryDefinitionFlags ParseCategoryFlags(string flagsAttr)
return flags;
}

static DbgExceptionDefinitionFlags ParseExceptionFlags(string flagsAttr) {
static DbgExceptionDefinitionFlags ParseExceptionFlags(string? flagsAttr) {
var flags = DbgExceptionDefinitionFlags.None;
if (!(flagsAttr is null)) {
foreach (var name in flagsAttr.Split(flagsSeparators, StringSplitOptions.RemoveEmptyEntries)) {
Expand Down
6 changes: 3 additions & 3 deletions dnSpy/dnSpy.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ sealed class DnSpyDecompiler : IMSBuildProjectWriterLogger {
readonly DecompilationContext decompilationContext;
readonly ModuleContext moduleContext;
readonly AssemblyResolver assemblyResolver;
readonly IBamlDecompiler bamlDecompiler;
readonly IBamlDecompiler? bamlDecompiler;
readonly HashSet<string> reservedOptions;
#if NETCOREAPP
readonly dnSpy.MainApp.NetCoreAssemblyLoader netCoreAssemblyLoader = new dnSpy.MainApp.NetCoreAssemblyLoader(System.Runtime.Loader.AssemblyLoadContext.Default);
Expand Down Expand Up @@ -245,7 +245,7 @@ static IEnumerable<IDecompiler> GetLanguagesInAssembly(string asmName) {
}
}

static IBamlDecompiler TryLoadBamlDecompiler() => TryCreateType<IBamlDecompiler>("dnSpy.BamlDecompiler.x", "dnSpy.BamlDecompiler.BamlDecompiler");
static IBamlDecompiler? TryLoadBamlDecompiler() => TryCreateType<IBamlDecompiler>("dnSpy.BamlDecompiler.x", "dnSpy.BamlDecompiler.BamlDecompiler");

static Assembly? TryLoad(string asmName) {
try {
Expand All @@ -256,7 +256,7 @@ static IEnumerable<IDecompiler> GetLanguagesInAssembly(string asmName) {
return null;
}

static T TryCreateType<T>(string asmName, string typeFullName) {
static T? TryCreateType<T>(string asmName, string typeFullName) where T : class {
var asm = TryLoad(asmName);
var type = asm?.GetType(typeFullName);
return type is null ? default! : (T)Activator.CreateInstance(type)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public DontDeserializeType(SerializationInfo info, StreamingContext context) {
public static Dictionary<string, DeserializedDataInfo> Deserialize(string asmName, string typeName, byte[] data) {
var fmt = new BinaryFormatter();
fmt.Binder = new MyBinder(asmName, typeName);
#pragma warning disable SYSLIB0011
var obj = fmt.Deserialize(new MemoryStream(data)) as DeserializedType;
#pragma warning restore SYSLIB0011
Debug2.Assert(!(obj is null));
if (obj is null)
return new Dictionary<string, DeserializedDataInfo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public static byte[] Serialize(object obj) {
// module is eg. a .NET 2.0 asm, you should replace the versions from 4.0.0.0 to 2.0.0.0.
var formatter = new BinaryFormatter();
var outStream = new MemoryStream();
#pragma warning disable SYSLIB0011
formatter.Serialize(outStream, obj);
#pragma warning restore SYSLIB0011
return outStream.ToArray();
}

Expand All @@ -84,7 +86,9 @@ public static byte[] Serialize(object obj) {
/// <returns></returns>
public static string Deserialize(byte[] data, out object? obj) {
try {
#pragma warning disable SYSLIB0011
obj = new BinaryFormatter().Deserialize(new MemoryStream(data));
#pragma warning restore SYSLIB0011
return string.Empty;
}
catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public void Deserialize() {
var serializedData = ((BinaryResourceData)ResourceElement.ResourceData).Data;
var formatter = new BinaryFormatter();
try {
#pragma warning disable SYSLIB0011
deserializedData = formatter.Deserialize(new MemoryStream(serializedData));
#pragma warning restore SYSLIB0011
}
catch {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -185,8 +186,8 @@ static void AddXmlDocumentation(IXmlDocOutput output, XmlReader xml) {
/// </summary>
/// <param name="cref"></param>
/// <returns></returns>
public static string GetCref(string cref) {
if (string.IsNullOrWhiteSpace(cref))
public static string GetCref(string? cref) {
if (string2.IsNullOrWhiteSpace(cref))
return string.Empty;
if (cref.Length < 2) {
return cref.Trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,26 @@ public XmlDocumentationProvider(string fileName)
using (XmlTextReader xmlReader = new XmlTextReader(fs)) {
xmlReader.XmlResolver = null; // no DTD resolving
xmlReader.MoveToContent();
if (string.IsNullOrEmpty(xmlReader.GetAttribute("redirect"))) {
var redirectAttr = (string?)xmlReader.GetAttribute("redirect");
if (string2.IsNullOrEmpty(redirectAttr)) {
this.fileName = fileName;
encoding = GetEncoding(xmlReader.Encoding);
encoding = GetEncoding(xmlReader.Encoding ?? throw new InvalidOperationException());
ReadXmlDoc(xmlReader);
} else {
string? redirectionTarget = GetRedirectionTarget(fileName, xmlReader.GetAttribute("redirect"));
var redirectionTarget = GetRedirectionTarget(fileName, redirectAttr);
if (!(redirectionTarget is null)) {
//Debug.WriteLine("XmlDoc " + fileName + " is redirecting to " + redirectionTarget);
using (FileStream redirectedFs = new FileStream(redirectionTarget, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) {
using (XmlTextReader redirectedXmlReader = new XmlTextReader(redirectedFs)) {
redirectedXmlReader.XmlResolver = null; // no DTD resolving
redirectedXmlReader.MoveToContent();
this.fileName = redirectionTarget;
encoding = GetEncoding(redirectedXmlReader.Encoding);
encoding = GetEncoding(redirectedXmlReader.Encoding ?? throw new InvalidOperationException());
ReadXmlDoc(redirectedXmlReader);
}
}
} else {
throw new XmlException("XmlDoc " + fileName + " is redirecting to " + xmlReader.GetAttribute("redirect") + ", but that file was not found.");
throw new XmlException("XmlDoc " + fileName + " is redirecting to " + redirectAttr + ", but that file was not found.");
}
}
}
Expand Down Expand Up @@ -301,7 +302,7 @@ static void ReadMembersSection(XmlTextReader reader, LinePositionMapper linePosM
case XmlNodeType.Element:
if (reader.LocalName == "member") {
int pos = linePosMapper.GetPositionForLine(reader.LineNumber) + Math.Max(reader.LinePosition - 2, 0);
string memberAttr = reader.GetAttribute("name");
var memberAttr = (string?)reader.GetAttribute("name");
if (!(memberAttr is null))
indexList.Add(new IndexEntry(GetHashCode(memberAttr), pos));
reader.Skip();
Expand Down Expand Up @@ -421,7 +422,7 @@ static int GetHashCode(string key)
r.XmlResolver = null; // no DTD resolving
while (r.Read()) {
if (r.NodeType == XmlNodeType.Element) {
string memberAttr = r.GetAttribute("name");
var memberAttr = (string?)r.GetAttribute("name");
if (memberAttr == key) {
return r.ReadInnerXml();
} else {
Expand Down
6 changes: 3 additions & 3 deletions dnSpy/dnSpy.Decompiler/MSBuild/SettingsProjectFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ void InitializeConnectionStringDesignTimeValues() {
var doc = XDocument.Load(configFile, LoadOptions.None);
var prefix = type.ReflectionFullName + ".";
foreach (var e in doc.XPathSelectElements("/configuration/connectionStrings/add")) {
var name = (string)e.Attribute("name");
var name = (string?)e.Attribute("name");
if (name is null || !name.StartsWith(prefix, StringComparison.Ordinal))
continue;

var connectionString = (string)e.Attribute("connectionString");
var providerName = (string)e.Attribute("providerName");
var connectionString = (string?)e.Attribute("connectionString");
var providerName = (string?)e.Attribute("providerName");
if (connectionString is null || providerName is null)
continue;

Expand Down
Loading

0 comments on commit 4c8c338

Please sign in to comment.