Browse Source

Add support for mscorlib: Compact Framework v2.0 and v3.5.

pull/1347/head
Siegfried Pammer 7 years ago
parent
commit
6a1181c496
  1. 2
      ICSharpCode.Decompiler/Metadata/MetadataExtensions.cs
  2. 65
      ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

2
ICSharpCode.Decompiler/Metadata/MetadataExtensions.cs

@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.Metadata
$"PublicKeyToken={publicKey}{properties}"; $"PublicKeyToken={publicKey}{properties}";
} }
static string ToHexString(this IEnumerable<byte> bytes, int estimatedLength) public static string ToHexString(this IEnumerable<byte> bytes, int estimatedLength)
{ {
StringBuilder sb = new StringBuilder(estimatedLength * 2); StringBuilder sb = new StringBuilder(estimatedLength * 2);
foreach (var b in bytes) foreach (var b in bytes)

65
ICSharpCode.Decompiler/Metadata/UniversalAssemblyResolver.cs

@ -374,7 +374,7 @@ namespace ICSharpCode.Decompiler.Metadata
if (DetectMono()) { if (DetectMono()) {
path = GetMonoMscorlibBasePath(version); path = GetMonoMscorlibBasePath(version);
} else { } else {
path = GetMscorlibBasePath(version); path = GetMscorlibBasePath(version, reference.PublicKeyToken.ToHexString(8));
} }
if (path == null) if (path == null)
@ -387,39 +387,8 @@ namespace ICSharpCode.Decompiler.Metadata
return null; return null;
} }
string GetMscorlibBasePath(Version version) string GetMscorlibBasePath(Version version, string publicKeyToken)
{ {
string rootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Microsoft.NET");
string[] frameworkPaths = new[] {
Path.Combine(rootPath, "Framework"),
Path.Combine(rootPath, "Framework64")
};
string folder = GetSubFolderForVersion();
if (folder != null) {
foreach (var path in frameworkPaths) {
var basePath = Path.Combine(path, folder);
if (Directory.Exists(basePath))
return basePath;
}
}
if (version.Major == 3 && version.Minor == 5) {
string cfBasePath = Path.Combine((Environment.Is64BitOperatingSystem ?
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) :
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)),
@"Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\");
if (Directory.Exists(cfBasePath)) {
return cfBasePath;
}
}
if (throwOnError)
throw new NotSupportedException("Version not supported: " + version);
return null;
string GetSubFolderForVersion() string GetSubFolderForVersion()
{ {
switch (version.Major) { switch (version.Major) {
@ -437,6 +406,36 @@ namespace ICSharpCode.Decompiler.Metadata
return null; return null;
} }
} }
if (publicKeyToken == "969db8053d3322ac") {
string programFiles = Environment.Is64BitOperatingSystem ?
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) :
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
string cfPath = $@"Microsoft.NET\SDK\CompactFramework\v{version.Major}.{version.Minor}\WindowsCE\";
string cfBasePath = Path.Combine(programFiles, cfPath);
if (Directory.Exists(cfBasePath))
return cfBasePath;
} else {
string rootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Microsoft.NET");
string[] frameworkPaths = new[] {
Path.Combine(rootPath, "Framework"),
Path.Combine(rootPath, "Framework64")
};
string folder = GetSubFolderForVersion();
if (folder != null) {
foreach (var path in frameworkPaths) {
var basePath = Path.Combine(path, folder);
if (Directory.Exists(basePath))
return basePath;
}
}
}
if (throwOnError)
throw new NotSupportedException("Version not supported: " + version);
return null;
} }
string GetMonoMscorlibBasePath(Version version) string GetMonoMscorlibBasePath(Version version)

Loading…
Cancel
Save