public DescEditor(DescModel desc, string descPach = null) { InitializeComponent(); this.desc = desc; this.descPach = descPach; }
public override string Execute(params string[] args) { FileInfo npdmFile = new FileInfo(GetValue <string>(args, 0, "npdmFilePath")); string descFilePath = GetValue <string>(args, 1); FileInfo descFile = new FileInfo(string.IsNullOrEmpty(descFilePath) ? Path.ChangeExtension(npdmFile.FullName, ".desc") : descFilePath); if (!npdmFile.Exists) { throw new CommandException("Npdm Not Found"); } if (!descFile.Exists && Directory.Exists(descFile.FullName) && descFile.Attributes.HasFlag(FileAttributes.Directory)) { descFile = new FileInfo(Path.Combine(descFile.FullName, Path.ChangeExtension(npdmFile.Name, ".desc"))); } try { DescModel desc = DescModel.FromNpdm(npdmFile.FullName).Result; File.WriteAllText(descFile.FullName, desc.XMLSerialize()); } catch (Exception ex) { throw new CommandException(ex.Message); } return($"Done {descFile.FullName}"); }
private void MB_CreateDesc_Click(object sender, EventArgs e) { DescModel desc = new DescModel(true); new DescEditor(desc).Show(); this.Hide(); }
public override string Execute(params string[] args) { FileInfo descFile = new FileInfo(GetValue <string>(args, 0, "descFile")); FileInfo metaFile = new FileInfo(GetValue <string>(args, 1, "metaFile")); string npdmFilePath = GetValue <string>(args, 2); FileInfo npdmFile = new FileInfo(string.IsNullOrEmpty(npdmFilePath) ? Path.ChangeExtension(descFile.FullName, ".npdm") : npdmFilePath); bool forceGenerateAcid = false; // GetValue<bool>(args, 3); if (!descFile.Exists) { throw new CommandException("Desc Not Found"); } if (!metaFile.Exists) { throw new CommandException("Meta Not Found"); } if (!npdmFile.Exists && Directory.Exists(npdmFile.FullName) && npdmFile.Attributes.HasFlag(FileAttributes.Directory)) { npdmFile = new FileInfo(Path.Combine(npdmFile.FullName, Path.ChangeExtension(descFile.Name, ".npdm"))); } try { DescModel desc = DescModel.FromXml(descFile.FullName); MetaModel meta = MetaModel.FromXml(metaFile.FullName); NpdmGenerator.CreateNpdm(desc, meta, forceGenerateAcid, npdmFile.FullName); } catch (Exception ex) { throw new CommandException(ex.Message); } return($"Done {npdmFile.FullName}"); }
public override string Execute(params string[] args) { FileInfo descFile = new FileInfo(GetValue <string>(args, 0, "descFile")); string metaFilePath = GetValue <string>(args, 1); if (!descFile.Exists) { throw new CommandException("Desc Not Found"); } try { DescModel desc = DescModel.FromXml(descFile.FullName); MetaModel meta = (File.Exists(metaFilePath)) ? MetaModel.FromXml(metaFilePath) : null; desc.Acid = Convert.ToBase64String(NpdmGenerator.GetAcidBytes(desc, meta)); File.WriteAllText(descFile.FullName, desc.XMLSerialize()); } catch (Exception ex) { throw new CommandException(ex.Message); } return($"Done {descFile.FullName}"); }
public static string CreateScenario(string name, string path, string desc = "") { DescModel model = new DescModel(); model.title = name; model.desc = desc; return(CreateFolder(name, path, JsonConvert.SerializeObject(model), true)); }
public HistoryScenarioVersion SetScenarioVersion(string scenario_id, string version_number, string ticket = "", string topic_id = "") { HistoryScenarioVersion model = new HistoryScenarioVersion(); string folder = ApiHelper.FindFolderById(scenario_id, PathHelper.GetRepoPath()); if (folder == null) { model.errors = ApiHelper.JsonError(400, new string[] { "scenario not exist" }); return(model); } string topicInfoFile = string.Empty; if (!string.IsNullOrEmpty(topic_id)) { List <TopicModel> topics = ApiHelper.GetTopicsOrigin(scenario_id); foreach (TopicModel t in topics) { if (t.index.ToString() == topic_id) { folder = t.vmpPath; topicInfoFile = t.infoPath; break; } } } int version = int.Parse(version_number); SVNManager.RevertToRevision(version, folder, (res) => { try { List <TopicObject> topics = ApiHelper.GetTopics(scenario_id); topics = topics.OrderBy(t => t.id).ToList(); string ret = ApiHelper.FindFolderById(scenario_id, PathHelper.GetRepoPath()); string folderr = new DirectoryInfo(ret).Name; DescModel modell = JsonConvert.DeserializeObject <DescModel>(IOFile.ReadAllText(Path.Combine(ret, folderr + ".info"))); model.topics = topics; model.scenario = modell; } catch { } if (string.IsNullOrEmpty(topicInfoFile)) { SVNManager.RevertToRevision(version, topicInfoFile, (r) => { }); } model.current_version = version; model.message = res; }); return(model); }
public static MetaModel MergeMeta(DescModel desc, MetaModel meta, bool replace = false) { if (desc == null) { throw new ApplicationException("File .desc was not specified."); } if (meta == null) { throw new ApplicationException("File .nmeta was not specified."); } if (desc.Default == null) { throw new ApplicationException("Default was not specified within the file .desc."); } desc.Default.CheckReadSuccess(); MetaModel mMeta = replace ? meta : (MetaModel)meta.Clone(); if (string.IsNullOrEmpty(mMeta.Core.Is64BitInstruction)) { mMeta.Core.Is64BitInstruction = desc.Default.Is64BitInstruction; } if (string.IsNullOrEmpty(mMeta.Core.ProcessAddressSpace)) { mMeta.Core.ProcessAddressSpace = desc.Default.ProcessAddressSpace; } if (string.IsNullOrEmpty(mMeta.Core.MainThreadPriority)) { mMeta.Core.MainThreadPriority = desc.Default.MainThreadPriority; } if (string.IsNullOrEmpty(mMeta.Core.MainThreadCoreNumber)) { mMeta.Core.MainThreadCoreNumber = desc.Default.MainThreadCoreNumber; } if (string.IsNullOrEmpty(mMeta.Core.MainThreadStackSize)) { mMeta.Core.MainThreadStackSize = desc.Default.MainThreadStackSize; } if (string.IsNullOrEmpty(mMeta.Core.SystemResourceSize)) { mMeta.Core.SystemResourceSize = "0x0"; } if (string.IsNullOrEmpty(mMeta.Core.Version)) { mMeta.Core.Version = "0"; } if (string.IsNullOrEmpty(mMeta.Core.Name)) { mMeta.Core.Name = "Application"; } //if (string.IsNullOrEmpty(meta.Core.ProductCode)) meta.Core.ProductCode = string.Empty; return(mMeta); }
public static byte[] GetNpdmBytes(DescModel desc, MetaModel meta, bool forceGenerateAcid = false) { if (desc == null) { throw new ApplicationException("File .desc was not specified."); } if (meta?.Core == null) { throw new ApplicationException("File .nmeta was not specified."); } if (meta.Core.ProgramIdValue == 0) { throw new ApplicationException("Core/ProgramId was not specified within the file .nmeta."); } MetaModel mMeta = MergeMeta(desc, meta); mMeta.Header.Fill(mMeta); if (mMeta.Core.SystemResourceSizeValue != 0 && (desc.KernelCapabilityDescriptor.MiscParams == null || desc.KernelCapabilityDescriptor.MiscParams.ProgramTypeValue != ProgramTypeEnum.Application || mMeta.Core.ProcessAddressSpaceValue != ProcessAddressSpacesEnum.AddressSpace64Bit)) { throw new ApplicationException("Core/SystemResourceSize can only be specified for 64 - bit applications."); } desc.AciHeader.ProgramId = mMeta.Core.ProgramIdValue; byte[] aciBytes = GetAciBytes(desc, mMeta); byte[] acidBytes = (string.IsNullOrEmpty(desc.Acid) || forceGenerateAcid) ? GetAcidBytes(desc, mMeta) : Convert.FromBase64String(desc.Acid); mMeta.Header.AciSize = (uint)aciBytes.Length; mMeta.Header.AcidSize = (uint)acidBytes.Length; uint headerSize = (uint)Marshal.SizeOf(typeof(NpdmHeader)); uint align = 16; mMeta.Header.AcidOffset = headerSize; mMeta.Header.AciOffset = mMeta.Header.AcidOffset + Utils.RoundUp(mMeta.Header.AcidSize, align); uint acidSize = Utils.RoundUp(mMeta.Header.AcidSize, align); byte[] npdmBytes = new byte[headerSize + acidSize + mMeta.Header.AciSize]; byte[] headerBytes = Utils.ToBytes(mMeta.Header, headerSize); Array.Copy(headerBytes, 0, npdmBytes, 0, headerSize); Array.Copy(acidBytes, 0, npdmBytes, mMeta.Header.AcidOffset, mMeta.Header.AcidSize); Array.Copy(aciBytes, 0, npdmBytes, mMeta.Header.AciOffset, mMeta.Header.AciSize); return(npdmBytes); }
public static byte[] GetAcidBytes(DescModel desc, MetaModel meta = null) { AcidHeader header = desc.AcidHeader; DescModel mDesc = (meta != null) ? MergeDesc(desc, meta) : desc; header.Fill(desc); if (header.ProgramIdMin == 0 || header.ProgramIdMax == 0) { throw new ArgumentException("ProgramIdMin/ProgramIdMax is incorrect"); } mDesc.KernelCapabilityDescriptor.CheckCapabilities(mDesc.Default.KernelCapabilityData); mDesc.SrvAccessControlDescriptor.CheckCapabilities(mDesc.Default.SrvAccessControlData); uint headerSize = (uint)Marshal.SizeOf(typeof(AcidHeader)); byte[] faBinary = mDesc.FsAccessControlDescriptor?.ExportBinary(true); byte[] saBinary = mDesc.SrvAccessControlDescriptor?.ExportBinary(); byte[] kcBinary = mDesc.KernelCapabilityDescriptor?.ExportBinary(); header.FacOffset = headerSize; header.FacSize = (uint)(faBinary?.Length ?? 0); header.SacOffset = header.FacOffset + Utils.RoundUp(header.FacSize, 16); header.SacSize = (uint)(saBinary?.Length ?? 0); header.KcOffset = header.SacOffset + Utils.RoundUp(header.SacSize, 16); header.KcSize = (uint)(kcBinary?.Length ?? 0); uint facSize = Utils.RoundUp(header.FacSize, 16); uint sacSize = Utils.RoundUp(header.SacSize, 16); uint kacSize = Utils.RoundUp(header.KcSize, 16); byte[] aciBytes = new byte[headerSize + facSize + sacSize + kacSize]; byte[] headerBytes = Utils.ToBytes(header, headerSize); Array.Copy(headerBytes, 0, aciBytes, 0, headerSize); if (faBinary != null && header.FacSize > 0) { Array.Copy(faBinary, 0, aciBytes, header.FacOffset, header.FacSize); } if (saBinary != null && header.SacSize > 0) { Array.Copy(saBinary, 0, aciBytes, header.SacOffset, header.SacSize); } if (kcBinary != null && header.KcSize > 0) { Array.Copy(kcBinary, 0, aciBytes, header.KcOffset, header.KcSize); } return(aciBytes); }
public static byte[] GetAciBytes(DescModel desc, MetaModel meta) { desc.AciHeader.Fill(); if (desc.AciHeader.ProgramId == 0) { throw new ArgumentException("Not Found ProgramId"); } DescModel mDesc = MergeDesc(desc, meta); mDesc.KernelCapabilityDescriptor.CheckCapabilities(mDesc.Default.KernelCapabilityData); mDesc.SrvAccessControlDescriptor.CheckCapabilities(mDesc.Default.SrvAccessControlData); uint headerSize = (uint)Marshal.SizeOf(typeof(AciHeader)); byte[] faBinary = mDesc.FsAccessControlDescriptor?.ExportBinary(); byte[] saBinary = mDesc.SrvAccessControlDescriptor?.ExportBinary(); byte[] kcBinary = mDesc.KernelCapabilityDescriptor?.ExportBinary(); mDesc.AciHeader.FacOffset = headerSize; mDesc.AciHeader.FacSize = (uint)(faBinary?.Length ?? 0); mDesc.AciHeader.SacOffset = mDesc.AciHeader.FacOffset + Utils.RoundUp(mDesc.AciHeader.FacSize, 16); mDesc.AciHeader.SacSize = (uint)(saBinary?.Length ?? 0); mDesc.AciHeader.KcOffset = mDesc.AciHeader.SacOffset + Utils.RoundUp(mDesc.AciHeader.SacSize, 16); mDesc.AciHeader.KcSize = (uint)(kcBinary?.Length ?? 0); uint facSize = (mDesc.AciHeader.SacSize > 0 || mDesc.AciHeader.KcSize > 0) ? Utils.RoundUp(mDesc.AciHeader.FacSize, 16) : mDesc.AciHeader.FacSize; uint sacSize = (mDesc.AciHeader.KcSize > 0) ? Utils.RoundUp(mDesc.AciHeader.SacSize, 16) : mDesc.AciHeader.SacSize; byte[] aciBytes = new byte[headerSize + facSize + sacSize + mDesc.AciHeader.KcSize]; byte[] headerBytes = Utils.ToBytes(mDesc.AciHeader, headerSize); Array.Copy(headerBytes, 0, aciBytes, 0, headerSize); if (faBinary != null && mDesc.AciHeader.FacSize > 0) { Array.Copy(faBinary, 0, aciBytes, mDesc.AciHeader.FacOffset, mDesc.AciHeader.FacSize); } if (saBinary != null && mDesc.AciHeader.SacSize > 0) { Array.Copy(saBinary, 0, aciBytes, mDesc.AciHeader.SacOffset, mDesc.AciHeader.SacSize); } if (kcBinary != null && mDesc.AciHeader.KcSize > 0) { Array.Copy(kcBinary, 0, aciBytes, mDesc.AciHeader.KcOffset, mDesc.AciHeader.KcSize); } return(aciBytes); }
void EditInfo(string path, string newName, string newDesc) { string pathToInfo = Path.Combine(path, new DirectoryInfo(path).Name + ".info"); if (IOFile.Exists(pathToInfo)) { DescModel model = JsonConvert.DeserializeObject <DescModel>(IOFile.ReadAllText(pathToInfo)); if (!string.IsNullOrEmpty(newName)) { model.title = newName; } if (!string.IsNullOrEmpty(newDesc)) { model.desc = newDesc; } IOFile.WriteAllText(pathToInfo, JsonConvert.SerializeObject(model)); } }
public void Fill(DescModel desc) { Signature = new byte[0x100]; if (!string.IsNullOrEmpty(desc.Signature)) { byte[] signature = Convert.FromBase64String(desc.Signature); Array.Copy(signature, Signature, signature.Length); } Modulus = new byte[0x100]; if (desc.RSAKeyValue.Modulus != null) { Array.Copy(desc.RSAKeyValue.Modulus, Modulus, desc.RSAKeyValue.Modulus.Length); } Magic = Encoding.ASCII.GetBytes("ACID"); FieldSize = new byte[0x4]; Reserved1 = new byte[0x4]; Flags = new byte[] { (byte)(desc.IsRetail ? 1 : 0), // Is retail 0, 0, 0 // Unknown }; switch (desc.KernelCapabilityDescriptor.MiscParams.ProgramTypeValue) { case ProgramTypeEnum.Applet: Flags[2] = 0x0B; Flags[3] = 0x01; break; case ProgramTypeEnum.System: Flags[2] = 0x0B; Flags[3] = 0x10; break; } ProgramIdMin = (string.IsNullOrEmpty(desc.ProgramIdMin)) ? 0x0100000000010000UL : desc.ProgramIdMinValue; ProgramIdMax = (string.IsNullOrEmpty(desc.ProgramIdMax)) ? 0x01FFFFFFFFFFFFFFUL : desc.ProgramIdMaxValue; Padding = new byte[0x8]; }
private async void MB_NpdmToDesc_Click(object sender, EventArgs e) { using (OpenFileDialog oFD = new OpenFileDialog { Filter = "NPDM files|*.npdm", RestoreDirectory = true }) { if (oFD.ShowDialog() == DialogResult.OK) { FileInfo inputFile = new FileInfo(oFD.FileName); if (inputFile.Extension == ".npdm") { DescModel desc = await DescModel.FromNpdm(oFD.FileName); using (SaveFileDialog sFD = new SaveFileDialog { Filter = "DESC files|*.desc|All Files|*.*", RestoreDirectory = true, FileName = Path.ChangeExtension(inputFile.FullName, ".desc") }) { if (sFD.ShowDialog() == DialogResult.OK) { File.WriteAllText(sFD.FileName, desc.XMLSerialize()); } } } else { MessageBox.Show("The file format is not yet supported"); } } } }
/*public static string GetScenarioInfo(string id, string path) * { * string folder = new DirectoryInfo(path).Name; * //string topicsPath = Path.Combine(path, "topics"); * DescModel scenario = JsonConvert.DeserializeObject<DescModel>(File.ReadAllText(Path.Combine(path, folder + ".info"))); * ScenarioObject sc = new ScenarioObject(); * sc.id = id; * sc.name = scenario.title; * sc.topics = GetTopics(id); * sc.description = scenario.desc;// Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(scenario.desc)); * string json = "{ scenario:" + JsonConvert.SerializeObject(sc) + "}"; * return json; * }*/ public static ScenarioModel GetScenarioInfoModel(string id, string path) { string folder = new DirectoryInfo(path).Name; //string topicsPath = Path.Combine(path, "topics"); DescModel scenario = JsonConvert.DeserializeObject <DescModel>(File.ReadAllText(Path.Combine(path, folder + ".info"))); ScenarioObject sc = new ScenarioObject(); sc.id = id; sc.name = scenario.title; sc.topics = GetTopics(id); sc.description = scenario.desc; // Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(scenario.desc)); /*foreach (string topic in Directory.GetFiles(topicsPath)) * { * sc.topics.Add(new FileInfo(topic).Name); * }*/ ScenarioModel model = new ScenarioModel(); model.scenario = sc; return(model); }
private void MB_EditDesc_Click(object sender, EventArgs e) { using (OpenFileDialog oFD = new OpenFileDialog() { Filter = "DESC files|*.desc", RestoreDirectory = true }) { if (oFD.ShowDialog() == DialogResult.OK) { try { DescModel desc = DescModel.FromXml(oFD.FileName); new DescEditor(desc, oFD.FileName).Show(); this.Hide(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
public static DescModel MergeDesc(DescModel desc, MetaModel meta, bool replace = false) { if (desc == null) { throw new ApplicationException("File .desc was not specified."); } if (meta == null) { throw new ApplicationException("File .nmeta was not specified."); } DescModel mDesc = replace ? desc : (DescModel)desc.Clone(); if (meta.Core?.FsAccessControlData != null) { mDesc.FsAccessControlDescriptor = new FaDescriptorModel(meta.Core.FsAccessControlData); } else if (mDesc.FsAccessControlDescriptor == null && mDesc.Default?.FsAccessControlData != null) { mDesc.FsAccessControlDescriptor = new FaDescriptorModel(mDesc.Default.FsAccessControlData); } if (meta.Core?.SrvAccessControlData != null) { mDesc.SrvAccessControlDescriptor = new SaDescriptorModel(meta.Core.SrvAccessControlData); } else if (mDesc.SrvAccessControlDescriptor == null && mDesc.Default?.SrvAccessControlData != null) { mDesc.SrvAccessControlDescriptor = new SaDescriptorModel(mDesc.Default.SrvAccessControlData); } if (meta.Core?.KernelCapabilityData != null && mDesc.KernelCapabilityDescriptor != null) { if (meta.Core.KernelCapabilityData.ThreadInfo != null) { mDesc.KernelCapabilityDescriptor.ThreadInfo = meta.Core.KernelCapabilityData.ThreadInfo; } if (meta.Core.KernelCapabilityData.EnableSystemCalls != null) { mDesc.KernelCapabilityDescriptor.EnableSystemCalls = meta.Core.KernelCapabilityData.EnableSystemCalls; } if (meta.Core.KernelCapabilityData.AllMemoryMap != null) { mDesc.KernelCapabilityDescriptor.AllMemoryMap = meta.Core.KernelCapabilityData.AllMemoryMap; } if (meta.Core.KernelCapabilityData.EnableInterrupts != null) { mDesc.KernelCapabilityDescriptor.EnableInterrupts = meta.Core.KernelCapabilityData.EnableInterrupts; } if (meta.Core.KernelCapabilityData.MiscParams != null) { mDesc.KernelCapabilityDescriptor.MiscParams = meta.Core.KernelCapabilityData.MiscParams; } if (meta.Core.KernelCapabilityData.KernelVersion != null) { mDesc.KernelCapabilityDescriptor.KernelVersion = meta.Core.KernelCapabilityData.KernelVersion; } if (meta.Core.KernelCapabilityData.HandleTableSize != null) { mDesc.KernelCapabilityDescriptor.HandleTableSize = meta.Core.KernelCapabilityData.HandleTableSize; } if (meta.Core.KernelCapabilityData.MiscFlags != null) { mDesc.KernelCapabilityDescriptor.MiscFlags = meta.Core.KernelCapabilityData.MiscFlags; } } else if (meta.Core?.KernelCapabilityData != null) { mDesc.KernelCapabilityDescriptor = new KcDescriptorModel(meta.Core.KernelCapabilityData); } else if (mDesc.KernelCapabilityDescriptor == null && mDesc.Default?.KernelCapabilityData != null) { mDesc.KernelCapabilityDescriptor = new KcDescriptorModel(mDesc.Default.KernelCapabilityData); } return(mDesc); }
public static void CreateNpdm(DescModel desc, MetaModel meta, bool forceGenerateAcid, string saveFilePach) { byte[] bytes = GetNpdmBytes(desc, meta, forceGenerateAcid); File.WriteAllBytes(saveFilePach, bytes); }