private void btnSaveVmd_Click(object sender, EventArgs e) { if (lbLoadedVmdList.SelectedIndex == -1) { return; } string vmdName = lbLoadedVmdList.SelectedItem.ToString(); VirtualMemoryDomain vmd = MemoryDomains.VmdPool[vmdName]; SaveFileDialog saveFileDialog1 = new SaveFileDialog { DefaultExt = "vmd", Title = "Save VMD to File", Filter = "VMD file|*.vmd", RestoreDirectory = true }; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string filename = saveFileDialog1.FileName; //creater stockpile.xml to temp folder from stockpile object using (FileStream fs = File.Open(filename, FileMode.Create)) { JsonHelper.Serialize(vmd.Proto, fs); } } }
private string DisplayVMD(VirtualMemoryDomain vmd) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append($"===Singles==={Environment.NewLine}"); foreach (var i in vmd.Proto.AddSingles) { sb.Append($"{i.ToHexString()}{Environment.NewLine}"); } foreach (var i in vmd.Proto.RemoveSingles) { sb.Append($"-{i.ToHexString()}{Environment.NewLine}"); } sb.Append($"{Environment.NewLine}"); sb.Append($"===Ranges==={Environment.NewLine}"); foreach (var i in vmd.Proto.AddRanges) { sb.Append($"{i[0].ToHexString()}-{i[1].ToHexString()}{Environment.NewLine}"); } foreach (var i in vmd.Proto.RemoveRanges) { sb.Append($"-{i[0].ToHexString()}-{i[1].ToHexString()}{Environment.NewLine}"); } return(sb.ToString()); }
private bool GenerateVMD() { if (string.IsNullOrWhiteSpace(cbSelectedMemoryDomain.SelectedItem?.ToString()) || !MemoryDomains.MemoryInterfaces.ContainsKey(cbSelectedMemoryDomain.SelectedItem.ToString())) { cbSelectedMemoryDomain.Items.Clear(); return(false); } if (!string.IsNullOrWhiteSpace(tbVmdName.Text) && MemoryDomains.VmdPool.ContainsKey($"[V]{tbVmdName.Text}")) { MessageBox.Show("There is already a VMD with this name in the VMD Pool"); return(false); } MemoryInterface mi = MemoryDomains.MemoryInterfaces[cbSelectedMemoryDomain.SelectedItem.ToString()]; VirtualMemoryDomain VMD = new VirtualMemoryDomain(); VmdPrototype proto = new VmdPrototype { GenDomain = cbSelectedMemoryDomain.SelectedItem.ToString() }; if (string.IsNullOrWhiteSpace(tbVmdName.Text)) { proto.VmdName = CorruptCore.RtcCore.GetRandomKey(); } else { proto.VmdName = tbVmdName.Text; } proto.BigEndian = mi.BigEndian; proto.WordSize = mi.WordSize; proto.Padding = 0; foreach (string line in tbRangeExpression.Lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } string trimmedLine = line.Trim(); bool remove = false; if (trimmedLine[0] == '-') { remove = true; trimmedLine = trimmedLine.Substring(1); } string[] lineParts = trimmedLine.Split('-'); if (lineParts.Length > 1) { long start = SafeStringToLong(lineParts[0]); long end = SafeStringToLong(lineParts[1]); if (end < start) { continue; } if (end >= currentDomainSize) { end = Convert.ToInt64(currentDomainSize - 1); } if (remove) { proto.RemoveRanges.Add(new long[] { start, end }); } else { proto.AddRanges.Add(new long[] { start, end }); } } else { long address = SafeStringToLong(lineParts[0]); if (address > 0 && address < currentDomainSize) { if (remove) { proto.RemoveSingles.Add(address); } else { proto.AddSingles.Add(address); } } } } if (proto.AddRanges.Count == 0 && proto.AddSingles.Count == 0) { //No add range was specified, use entire domain proto.AddRanges.Add(new long[] { 0, (currentDomainSize > long.MaxValue ? long.MaxValue : Convert.ToInt64(currentDomainSize)) }); } //Precalc the size of the vmd //Ignore the fact that addranges and subtractranges can overlap. Only account for add long size = 0; foreach (var v in proto.AddSingles) { size++; } foreach (var v in proto.AddRanges) { long x = v[1] - v[0]; size += x; } //If the size is still 0 and we have removals, we're gonna use the entire range then sub from it so size is now the size of the domain if (size == 0 && (proto.RemoveSingles.Count > 0 || proto.RemoveRanges.Count > 0) || (proto.RemoveSingles.Count == 0 && proto.RemoveRanges.Count == 0 && size == 0)) { size = currentDomainSize; } foreach (var v in proto.RemoveSingles) { size--; } foreach (var v in proto.RemoveRanges) { long x = v[1] - v[0]; size -= x; } //Verify they want to continue if the domain is larger than 32MB and they didn't manually set ranges if (size > 0x2000000) { DialogResult result = MessageBox.Show("The VMD you're trying to generate is larger than 32MB\n The VMD size is " + ((size / 1024 / 1024) + 1) + " MB (" + size / 1024f / 1024f / 1024f + " GB).\n Are you sure you want to continue?", "VMD Detected", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return(false); } } VMD = proto.Generate(); if (VMD.Size == 0) { MessageBox.Show("The resulting VMD had no pointers so the operation got cancelled."); return(false); } MemoryDomains.AddVMD(VMD); tbVmdName.Text = ""; cbSelectedMemoryDomain.SelectedIndex = -1; cbSelectedMemoryDomain.Items.Clear(); currentDomainSize = 0; tbRangeExpression.Text = ""; lbDomainSizeValue.Text = "######"; lbEndianTypeValue.Text = "######"; lbWordSizeValue.Text = "######"; //send to vmd pool menu S.GET <RTC_VmdPool_Form>().RefreshVMDs(); //Selects back the VMD Pool menu foreach (var item in UICore.mtForm.cbSelectBox.Items) { if (((dynamic)item).value is RTC_VmdPool_Form) { UICore.mtForm.cbSelectBox.SelectedItem = item; break; } } return(true); }
private static void RenameVMD(string vmdName) { if (!MemoryDomains.VmdPool.ContainsKey(vmdName)) { return; } string name = ""; string value = ""; if (UI_Extensions.GetInputBox("BlastLayer to VMD", "Enter the new VMD name:", ref value) == DialogResult.OK) { name = value.Trim(); } else { return; } if (string.IsNullOrWhiteSpace(name)) { name = CorruptCore.RtcCore.GetRandomKey(); } if (MemoryDomains.VmdPool.ContainsKey(name)) { MessageBox.Show("There's already a VMD with this name. Aborting rename."); return; } VirtualMemoryDomain VMD = MemoryDomains.VmdPool[vmdName]; MemoryDomains.RemoveVMD(VMD); VMD.Name = name; VMD.Proto.VmdName = name; MemoryDomains.AddVMD(VMD); foreach (BlastUnit bu in StepActions.GetRawBlastLayer().Layer) { if (bu.Domain == vmdName) { bu.Domain = "[V]" + name; } if (bu.SourceDomain == vmdName) { bu.SourceDomain = "[V]" + name; } } //Go through the stash history and update any references foreach (StashKey sk in S.GET <RTC_StashHistory_Form>().lbStashHistory.Items) { foreach (var bu in sk.BlastLayer.Layer) { if (bu.Domain == vmdName) { bu.Domain = "[V]" + name; } if (bu.SourceDomain == vmdName) { bu.SourceDomain = "[V]" + name; } } } //CurrentStashKey can be separate if (StockpileManager_UISide.CurrentStashkey != null) { foreach (var bu in StockpileManager_UISide.CurrentStashkey.BlastLayer.Layer.Where(x => x.Domain == vmdName || x.SourceDomain == vmdName)) { if (bu.Domain == vmdName) { bu.Domain = "[V]" + name; } if (bu.SourceDomain == vmdName) { bu.SourceDomain = "[V]" + name; } } } }
private static void RenameVMD(VirtualMemoryDomain VMD) { RenameVMD(VMD.ToString()); }
private void btnSendToMyVMDs_Click(object sender, EventArgs e) { if (lbLoadedVmdList.SelectedIndex == -1) { return; } if (lbLoadedVmdList.SelectedItems.Count == 1) { string vmdName = lbLoadedVmdList.SelectedItem.ToString(); VirtualMemoryDomain vmd = MemoryDomains.VmdPool[vmdName]; string value = lbLoadedVmdList.SelectedItem.ToString().Trim().Replace("[V]", ""); if (GetInputBox("Add to My VMDs", "Confirm VMD name:", ref value) == DialogResult.OK) { if (string.IsNullOrWhiteSpace(value.Trim())) { MessageBox.Show("Invalid name"); return; } string targetPath = Path.Combine(RtcCore.vmdsDir, value.Trim() + ".vmd"); if (File.Exists(targetPath)) { var result = MessageBox.Show("This file already exists in your VMDs folder, do you want to overwrite it?", "Overwrite file?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return; } File.Delete(targetPath); } //creates json file for vmd using (FileStream fs = File.Open(targetPath, FileMode.Create)) { JsonHelper.Serialize(vmd.Proto, fs); } } } else //multiple selected { foreach (var item in lbLoadedVmdList.SelectedItems) { string vmdName = item.ToString(); VirtualMemoryDomain vmd = MemoryDomains.VmdPool[vmdName]; string itemValue = item.ToString().Trim().Replace("[V]", ""); //string targetPath = Path.Combine(RtcCore.vmdsDir, value.Trim() + ".vmd"); string itemTargetPath = Path.Combine(RtcCore.vmdsDir, itemValue.Trim() + ".vmd"); if (File.Exists(itemTargetPath)) { var result = MessageBox.Show("This file already exists in your VMDs folder, do you want to overwrite it?", "Overwrite file?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return; } File.Delete(itemTargetPath); } using (FileStream fs = File.Open(itemTargetPath, FileMode.Create)) { JsonHelper.Serialize(vmd.Proto, fs); } } } S.GET <RTC_MyVMDs_Form>().RefreshVMDs(); //switch to My VMDs foreach (var item in UICore.mtForm.cbSelectBox.Items) { if (((dynamic)item).value is RTC_MyVMDs_Form) { UICore.mtForm.cbSelectBox.SelectedItem = item; break; } } }
private bool GenerateVMD() { if (string.IsNullOrWhiteSpace(cbSelectedMemoryDomain.SelectedItem?.ToString()) || !MemoryDomains.MemoryInterfaces.ContainsKey(cbSelectedMemoryDomain.SelectedItem.ToString())) { cbSelectedMemoryDomain.Items.Clear(); return(false); } if (!string.IsNullOrWhiteSpace(tbVmdName.Text) && MemoryDomains.VmdPool.ContainsKey($"[V]{tbVmdName.Text}")) { MessageBox.Show("There is already a VMD with this name in the VMD Pool"); return(false); } MemoryInterface mi = MemoryDomains.MemoryInterfaces[cbSelectedMemoryDomain.SelectedItem.ToString()]; VirtualMemoryDomain VMD = new VirtualMemoryDomain(); VmdPrototype proto = new VmdPrototype { GenDomain = cbSelectedMemoryDomain.SelectedItem.ToString() }; if (string.IsNullOrWhiteSpace(tbVmdName.Text)) { proto.VmdName = CorruptCore.RtcCore.GetRandomKey(); } else { proto.VmdName = tbVmdName.Text; } proto.BigEndian = mi.BigEndian; proto.WordSize = mi.WordSize; proto.Padding = 0; var sk = S.GET <RTC_SavestateManager_Form>().CurrentSaveStateStashKey; if (sk == null && cbLoadBeforeGenerate.Checked && (AllSpec.VanguardSpec[VSPEC.SUPPORTS_SAVESTATES] as bool? ?? false)) { MessageBox.Show("Load before generate is checked but no Savestate is selected in the Glitch Harvester!"); return(false); } var legalAdresses = LocalNetCoreRouter.QueryRoute <long[]>(NetcoreCommands.CORRUPTCORE, NetcoreCommands.REMOTE_LONGARRAY_FILTERDOMAIN, new object[] { mi.Name, LimiterListHash, cbLoadBeforeGenerate.Checked ? sk : null }); if (legalAdresses == null) { return(false); } proto.AddSingles.AddRange(legalAdresses); if (proto.AddRanges.Count == 0 && proto.AddSingles.Count == 0) { //No add range was specified, use entire domain proto.AddRanges.Add(new long[] { 0, (currentDomainSize > long.MaxValue ? long.MaxValue : Convert.ToInt64(currentDomainSize)) }); } //Precalc the size of the vmd //Ignore the fact that addranges and subtractranges can overlap. Only account for add long size = 0; foreach (var v in proto.AddSingles) { size++; } foreach (var v in proto.AddRanges) { long x = v[1] - v[0]; size += x; } //If the size is still 0 and we have removals, we're gonna use the entire range then sub from it so size is now the size of the domain if (size == 0 && (proto.RemoveSingles.Count > 0 || proto.RemoveRanges.Count > 0) || (proto.RemoveSingles.Count == 0 && proto.RemoveRanges.Count == 0 && size == 0)) { size = currentDomainSize; } foreach (var v in proto.RemoveSingles) { size--; } foreach (var v in proto.RemoveRanges) { long x = v[1] - v[0]; size -= x; } //Verify they want to continue if the domain is larger than 32MB and they didn't manually set ranges if (size > 0x2000000) { DialogResult result = MessageBox.Show("The VMD you're trying to generate is larger than 32MB\n The VMD size is " + ((size / 1024 / 1024) + 1) + " MB (" + size / 1024f / 1024f / 1024f + " GB).\n Are you sure you want to continue?", "VMD Detected", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return(false); } } VMD = proto.Generate(); if (VMD.Size == 0) { MessageBox.Show("The resulting VMD had no pointers so the operation got cancelled."); return(false); } MemoryDomains.AddVMD(VMD); tbVmdName.Text = ""; cbSelectedMemoryDomain.SelectedIndex = -1; cbSelectedMemoryDomain.Items.Clear(); currentDomainSize = 0; lbDomainSizeValue.Text = "######"; lbEndianTypeValue.Text = "######"; lbWordSizeValue.Text = "######"; //send to vmd pool menu S.GET <RTC_VmdPool_Form>().RefreshVMDs(); //Selects back the VMD Pool menu foreach (var item in UICore.mtForm.cbSelectBox.Items) { if (((dynamic)item).value is RTC_VmdPool_Form) { UICore.mtForm.cbSelectBox.SelectedItem = item; break; } } return(true); }
private void generateVMD() { if (ActiveTableGenerated == null || ActiveTableGenerated.Length == 0) { return; } try { MemoryInterface mi = MemoryDomains.MemoryInterfaces[cbSelectedMemoryDomain.SelectedItem.ToString()]; VirtualMemoryDomain VMD = new VirtualMemoryDomain(); VmdPrototype proto = new VmdPrototype(); int lastaddress = -1; proto.GenDomain = cbSelectedMemoryDomain.SelectedItem.ToString(); proto.VmdName = mi.Name + " " + CorruptCore.RtcCore.GetRandomKey(); proto.BigEndian = mi.BigEndian; proto.WordSize = mi.WordSize; proto.PointerSpacer = 1; if (UseCorePrecision) { foreach (int address in ActiveTableGenerated) { int safeaddress = (address - (address % mi.WordSize)); if (safeaddress != lastaddress) { lastaddress = safeaddress; for (int i = 0; i < mi.WordSize; i++) { proto.AddSingles.Add(safeaddress + i); } //[] _addresses = { safeaddress, safeaddress + mi.WordSize }; // proto.addRanges.Add(_addresses); } } } else { foreach (int address in ActiveTableGenerated) { proto.AddSingles.Add(address); } } VMD = proto.Generate(); if (VMD.Compacted ? VMD.CompactPointerAddresses.Length == 0 : VMD.PointerAddresses.Count == 0) { MessageBox.Show("The resulting VMD had no pointers so the operation got cancelled."); return; } MemoryDomains.AddVMD(VMD); S.GET <RTC_VmdPool_Form>().RefreshVMDs(); return; } catch (Exception ex) { string additionalInfo = "Something went wrong in when generating the VMD table. \n" + "This is an RTC error, so you should probably send this to the RTC devs with instructions on what you did to cause it.\n\n"; var ex2 = new CustomException(ex.Message, additionalInfo + ex.StackTrace); if (CloudDebug.ShowErrorDialog(ex2, true) == DialogResult.Abort) { throw new RTCV.NetCore.AbortEverythingException(); } return; } finally { } }