public static Task<Binary> Load(string filename, BinaryLoadOptions loadOptions = BinaryLoadOptions.DelayLoad) { filename = filename.GetFullPath(); lock (typeof (Binary)) { if (LoadingTasks.ContainsKey(filename)) { return LoadingTasks[filename]; } if (LoadedFiles.ContainsKey(filename)) { return LoadedFiles[filename].AsResultTask(); } var result = Task<Binary>.Factory.StartNew(() => new Binary(filename, loadOptions)); LoadingTasks.Add(filename, result); return result; } }
/// <summary> /// Synchronously loads the binary /// </summary> /// <param name="filename"> </param> /// <param name="loadOptions"> </param> private Binary(string filename, BinaryLoadOptions loadOptions) { _loadOptions = loadOptions; Filename = filename; IsPEFile = new Prerequisite<bool>(LoadPEInfo); Is64Bit = Is64BitPE = new Prerequisite<bool>(LoadPEInfo); Is32BitPE = new Prerequisite<bool>(LoadPEInfo); IsManaged = new Prerequisite<bool>(LoadPEInfo); IsNative = new Prerequisite<bool>(LoadPEInfo); Is32Bit = new Prerequisite<bool>(LoadPEInfo); IsAnyCpu = new Prerequisite<bool>(LoadPEInfo, () => IsPEFile && (Is32BitPE && IsManaged && ((CorHeader.Flags & 0x0002) == 0))); IsConsoleApp = new Prerequisite<bool>(LoadPEInfo, () => IsPEFile && (NtHeader.SubSystem & 1) == 1); ExecutableInformation = new Prerequisite<ExecutableInfo>(LoadPEInfo, () => { var result = IsManaged ? ExecutableInfo.managed : ExecutableInfo.native; if (IsAnyCpu) { result |= ExecutableInfo.any; } else { switch (CoffHeader.Machine) { case 0x01c0: result |= ExecutableInfo.arm; break; case 0x014c: result |= ExecutableInfo.x86; break; case 0x0200: result |= ExecutableInfo.ia64; break; case 0x8664: result |= ExecutableInfo.x64; break; default: throw new CoAppException("Unrecognized Executable Machine Type."); } } return result; }); VersionInfo = new Prerequisite<FileVersionInfo>(LoadVersionInfo); MD5 = new Prerequisite<string>(LoadMD5); ILOnly = new Prerequisite<bool>(LoadManagedData); NativeResources = new Prerequisite<ResourceInfo>(LoadResourceData); Manifest = new Prerequisite<NativeManifest>(LoadManifestData); IsSigned = new Prerequisite<bool>(LoadSignature); IsValidSigned = new Prerequisite<bool>(LoadSignature); IsStrongNamed = new Prerequisite<bool>(LoadManagedData); AssemblyCulture = new Prerequisite<string>(LoadManagedData); AssemblyVersion = new Prerequisite<FourPartVersion>(LoadManagedData); IsDelaySigned = new Prerequisite<bool>(LoadManagedData); LoadData(); }