public void InitMemorySectionList(ProcessInfo pi) { mapped_section_list.Clear(); TotalMemorySize = 0; for (int i = 0; i < pi.entries.Length; i++) { MemoryEntry entry = pi.entries[i]; if ((entry.prot & 0x1) == 0x1) { ulong length = entry.end - entry.start; ulong start = entry.start; string name = entry.name; int idx = 0; ulong block_length = 1024 * 1024 * 128; if ((entry.prot & 0x5) == 0x5) { block_length = length; } while (length != 0) { ulong cur_length = block_length; if (cur_length > length) { cur_length = length; length = 0; } else { length -= cur_length; } MappedSection section_info = new MappedSection(); section_info.Start = start; section_info.Length = (int)cur_length; section_info.Name = entry.name + "[" + idx + "]"; section_info.Check = false; section_info.Prot = entry.prot; mapped_section_list.Add(section_info); start += cur_length; ++idx; } } } }
private void sectionView_Click(object sender, EventArgs e) { int sectionID = -1; int offset = 0; sectionID = section_list_box.SelectedIndex; if (sectionID >= 0) { MappedSection section = processManager.MappedSectionList[sectionID]; HexEditor hexEdit = new HexEditor(memoryHelper, offset, section); hexEdit.Show(this); } }
private void cmsSectionMenuHex_Click(object sender, EventArgs e) { int sectionID = -1; int offset = 0; sectionID = lstSection.SelectedIndex; if (sectionID >= 0) { MappedSection section = processManager.MappedSectionList[sectionID]; FrmHexEditor hexEdit = new FrmHexEditor(memoryHelper, offset, section); hexEdit.Show(this); } }
private void save_address_btn_Click(object sender, EventArgs e) { try { string save_buf = "1.2|" + (string)processes_comboBox.SelectedItem + "\n"; for (int i = 0; i < cheat_list_view.RowCount; ++i) { DataGridViewRow row = cheat_list_view.Rows[i]; string address_str = (string)row.Cells[CHEAT_LIST_ADDRESS].Value; ulong address = ulong.Parse(address_str, NumberStyles.HexNumber); string type = (string)row.Cells[CHEAT_LIST_TYPE].Value; string value = (string)row.Cells[CHEAT_LIST_VALUE].Value; string lock_ = ((bool)row.Cells[CHEAT_LIST_LOCK].Value) ? "1" : "0"; string description = (string)row.Cells[CHEAT_LIST_DESC].Value; int sectionID = processManager.GetSectionInfoIdx(address); if (sectionID < 0) { continue; } MappedSection sectionInfo = processManager.mapped_section_list[sectionID]; save_buf += "data|"; save_buf += sectionID + "|"; save_buf += String.Format("{0:X}", (address - sectionInfo.Start)) + "|"; save_buf += type + "|"; save_buf += value + "|"; save_buf += lock_ + "|"; save_buf += description + "|\n"; } save_file_dialog.Filter = "Cheat files (*.cht)|*.cht"; save_file_dialog.FilterIndex = 1; save_file_dialog.RestoreDirectory = true; if (save_file_dialog.ShowDialog() == DialogResult.OK) { StreamWriter myStream = new StreamWriter(save_file_dialog.FileName); myStream.Write(save_buf); myStream.Close(); } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public override string Save() { ulong addressDec = ulong.Parse(Address, NumberStyles.HexNumber); MappedSection mappedSection = processManager.GetMappedSection(addressDec); string save_buf = ""; save_buf += "hex|"; save_buf += SectionID + "|"; save_buf += String.Format("{0:X}", addressDec - mappedSection.Start) + "|"; save_buf += MemoryHelper.GetStringOfValueType(Type) + "|"; save_buf += Value + "|"; save_buf += "0"; save_buf += Description + "|\n"; return(save_buf); }
public string GetSectionName(int section_idx) { if (section_idx < 0) { return("sectioni wrong!"); } MappedSection sectionInfo = mapped_section_list[section_idx]; StringBuilder section_name = new StringBuilder(); section_name.Append(sectionInfo.Name + "-"); section_name.Append(String.Format("{0:X}", sectionInfo.Prot) + "-"); section_name.Append(String.Format("{0:X}", sectionInfo.Start) + "-"); section_name.Append((sectionInfo.Length / 1024).ToString() + "KB"); return(section_name.ToString()); }
public HexEdit(MemoryHelper memoryHelper, int offset, MappedSection section) { InitializeComponent(); this.memoryHelper = memoryHelper; this.section = section; this.changed = false; this.offset = offset; this.page = offset / page_size; this.page_count = divup((int)section.Length, page_size); for (int i = 0; i < page_count; ++i) { page_list.Items.Add((i + 1).ToString()); } }
private void next_scan_worker_DoWork(object sender, DoWorkEventArgs e) { ulong percent_len = 0; for (int section_idx = 0; section_idx < processManager.MappedSectionList.Count; ++section_idx) { MappedSection mappedSection = processManager.MappedSectionList[section_idx]; AddressList addressList = mappedSection.AddressList; AddressList filtered_list = mappedSection.getFilteredAddressList(processManager, memoryHelper, value_box.Text, next_scan_worker, ref percent_len, 0, 0.5f); mappedSection.AddressList = addressList.Intersect(memoryHelper, filtered_list, value_box.Text); } WorkerArgs args = (WorkerArgs)e.Argument; update_result_list_view(next_scan_worker, args.ValueType, false, 50, 0.5f); }
private void next_scan_worker_DoWork(object sender, DoWorkEventArgs e) { ulong percent_len = 0; for (int section_idx = 0; section_idx < processManager.mapped_section_list.Count; ++section_idx) { MappedSection mappedSection = processManager.mapped_section_list[section_idx]; AddressList addressList = mappedSection.AddressList; if (mappedSection.AddressList.Count < 50) { for (int address_idx = 0; address_idx < addressList.Count; ++address_idx) { Address address = addressList[address_idx]; byte[] compare_value = processManager.MemoryHelper.GetCompareBytes(address, value_box.Text); byte[] value = processManager.MemoryHelper.GetBytesByType(address.AddressOffset + mappedSection.Start); if (!processManager.MemoryHelper.Compare(compare_value, value)) { addressList.RemoveAt(address_idx); --address_idx; } else { Address address_tmp = new Address(); address_tmp.AddressOffset = addressList[address_idx].AddressOffset; address_tmp.MemoryValue = processManager.MemoryHelper.BytesToUint(value); addressList[address_idx] = address_tmp; } } } else { AddressList filtered_list = mappedSection.getFilteredAddressList(processManager, value_box.Text, next_scan_worker, ref percent_len, 0, 0.5f); mappedSection.AddressList = addressList.Intersect(processManager.MemoryHelper, filtered_list, value_box.Text); } } WorkerArgs args = (WorkerArgs)e.Argument; update_result_list_view(next_scan_worker, args.ValueType, false, 50, 0.5f); }
private void next_pointer_finder_worker_DoWork(object sender, DoWorkEventArgs e) { PointerFinderWorkerArgs pointerFinderWorkerArgs = (PointerFinderWorkerArgs)e.Argument; result_counter = 0; pointerList.Clear(); next_pointer_finder_worker.ReportProgress(0); for (int section_idx = 0; section_idx < processManager.MappedSectionList.Count; ++section_idx) { if (next_pointer_finder_worker.CancellationPending) { break; } if (isFastNextScanBox.Checked && mappedSections.Count > 0 && !mappedSections.Contains(section_idx)) { continue; } MappedSection mappedSection = processManager.MappedSectionList[section_idx]; if (isFilterBox.Checked && Util.SectionIsFilter(mappedSection.Name)) { continue; } if (!isFilterBox.Checked && mappedSection.Name.StartsWith("libSce")) { continue; } mappedSection.PointerSearchInit(processManager, MemoryHelper, pointerList); next_pointer_finder_worker.ReportProgress((int)(((float)section_idx / processManager.MappedSectionList.Count) * 65), "Init scanning pointer..." + pointerList.Count + " (" + (section_idx + 1) + "/" + processManager.MappedSectionList.Count + "), " + mappedSection.ToString()); } if (next_pointer_finder_worker.CancellationPending) { return; } next_pointer_finder_worker.ReportProgress(65); pointerList.Init(); next_pointer_finder_worker.ReportProgress(70); NextFinderEvent?.Invoke(pointerList, pointerFinderWorkerArgs); }
public FrmHexEditor(MemoryHelper memoryHelper, int offset, MappedSection section) { InitializeComponent(); this.memoryHelper = memoryHelper; this.section = section; this.page = offset / page_size; this.line = (offset - page * page_size) / hexBox.BytesPerLine; this.column = (offset - page * page_size) % hexBox.BytesPerLine; this.page_count = divup((int)section.Length, page_size); for (int i = 0; i < page_count; ++i) { ulong start = section.Start + (ulong)i * page_size; ulong end = section.Start + (ulong)(i + 1) * page_size; page_list.Items.Add((i + 1).ToString() + String.Format(" {0:X}-{1:X}", start, end)); } }
private void new_scan_worker_DoWork(object sender, DoWorkEventArgs e) { //scan_worker_DoWorker(sender, e, true); long processed_memory_len = 0; ulong total_memory_size = processManager.MappedSectionList.TotalMemorySize + 1; string value_0 = value_box.Text; string value_1 = value_1_box.Text; new_scan_worker.ReportProgress(0); for (int section_idx = 0; section_idx < processManager.MappedSectionList.Count; ++section_idx) { if (new_scan_worker.CancellationPending) break; MappedSection mappedSection = processManager.MappedSectionList[section_idx]; mappedSection.UpdateResultList(processManager, memoryHelper, value_0, value_1, hex_box.Checked, true); if (mappedSection.Check) processed_memory_len += mappedSection.Length; new_scan_worker.ReportProgress((int)(((float)processed_memory_len / total_memory_size) * 80)); } new_scan_worker.ReportProgress(80); update_result_list_view(new_scan_worker, false, 80, 0.2f); }
public void Peek() { for (int section_idx = 0; section_idx < processManager.MappedSectionList.Count; ++section_idx) { MappedSection mappedSection = processManager.MappedSectionList[section_idx]; if (!mappedSection.Check) { mappedSection.ResultList = null; continue; } ulong address = mappedSection.Start; int length = mappedSection.Length; while (length != 0) { int cur_length = CONSTANT.PEEK_BUFFER_LENGTH; if (cur_length > length) { cur_length = length; length = 0; } else { length -= cur_length; } if (worker.CancellationPending) { break; } producer_mutex.WaitOne(); //buffer_queue[productor_idx] = memoryHelper.ReadMemory(address, (int)cur_length); productor_idx = (productor_idx + 1) % CONSTANT.MAX_PEEK_QUEUE; consumer_mutex.Release(); address += (ulong)cur_length; } } }
private void sectionDump_Click(object sender, EventArgs e) { if (section_list_box.SelectedIndex >= 0) { MappedSection section = processManager.mapped_section_list[section_list_box.SelectedIndex]; save_file_dialog.Filter = "Binary files (*.bin)|*.bin|All files (*.*)|*.*"; save_file_dialog.FilterIndex = 1; save_file_dialog.RestoreDirectory = true; save_file_dialog.FileName = (string)section_list_box.Items[section_list_box.SelectedIndex]; if (save_file_dialog.ShowDialog() == DialogResult.OK) { byte[] buffer = processManager.MemoryHelper.ReadMemory(section.Start, (int)section.Length); FileStream myStream = new FileStream(save_file_dialog.FileName, FileMode.OpenOrCreate); myStream.Write(buffer, 0, buffer.Length); myStream.Close(); } } }
private void dump_dialog(int sectionID) { if (sectionID >= 0) { MappedSection section = processManager.MappedSectionList[sectionID]; sfdSaveFile.Filter = "Binary files (*.bin)|*.bin|All files (*.*)|*.*"; sfdSaveFile.FilterIndex = 1; sfdSaveFile.RestoreDirectory = true; sfdSaveFile.FileName = (string)lstSection.Items[lstSection.SelectedIndex]; if (sfdSaveFile.ShowDialog() == DialogResult.OK) { byte[] buffer = memoryHelper.ReadMemory(section.Start, (int)section.Length); FileStream myStream = new FileStream(sfdSaveFile.FileName, FileMode.OpenOrCreate); myStream.Write(buffer, 0, buffer.Length); myStream.Close(); } } }
private void cmsResultMenuHex_Click(object sender, EventArgs e) { if (lvResult.SelectedItems.Count == 1) { ListView.SelectedListViewItemCollection items = lvResult.SelectedItems; ulong address = ulong.Parse(lvResult.SelectedItems[0]. SubItems[RESULT_LIST_ADDRESS].Text, NumberStyles.HexNumber); int sectionID = processManager.MappedSectionList.GetMappedSectionID(address); if (sectionID >= 0) { int offset = 0; MappedSection section = processManager.MappedSectionList[sectionID]; offset = (int)(address - section.Start); FrmHexEditor hexEdit = new FrmHexEditor(memoryHelper, offset, section); hexEdit.Show(this); } } }
void new_scan_thread(string value_0, string value_1, int thread_id, int num_threads, ref long processed_memory_len, ulong total_memory_size) { for (int section_idx = 0; section_idx < processManager.MappedSectionList.Count; ++section_idx) { // Split work up between threads. if (section_idx % num_threads != thread_id) { continue; } if (new_scan_worker.CancellationPending) { break; } MappedSection mappedSection = processManager.MappedSectionList[section_idx]; mappedSection.UpdateResultList(processManager, memoryHelper, value_0, value_1, hex_box.Checked, true, thread_id); if (mappedSection.Check) { processed_memory_len += mappedSection.Length; } new_scan_worker.ReportProgress((int)(((float)processed_memory_len / total_memory_size) * 80)); } }
private void pointer_finder_worker_DoWork(object sender, DoWorkEventArgs e) { pointer_finder_worker.ReportProgress(0); for (int section_idx = 0; section_idx < processManager.MappedSectionList.Count; ++section_idx) { if (pointer_finder_worker.CancellationPending) { break; } MappedSection mappedSection = processManager.MappedSectionList[section_idx]; if (isFilterBox.Checked && Util.SectionIsFilter(mappedSection.Name)) { continue; } if (!isFilterBox.Checked && mappedSection.Name.StartsWith("libSce")) { continue; } mappedSection.PointerSearchInit(processManager, MemoryHelper, pointerList); pointer_finder_worker.ReportProgress((int)(((float)section_idx / processManager.MappedSectionList.Count) * 80), "Init scanning pointer..." + pointerList.Count + " (" + (section_idx + 1) + "/" + processManager.MappedSectionList.Count + "), " + mappedSection.ToString()); } if (pointer_finder_worker.CancellationPending) { return; } pointer_finder_worker.ReportProgress(80); pointerList.Init(); pointer_finder_worker.ReportProgress(90); PointerFinderWorkerArgs pointerFinderWorkerArgs = (PointerFinderWorkerArgs)e.Argument; pointerList.FindPointerList(pointerFinderWorkerArgs.Address, pointerFinderWorkerArgs.Range); pointer_finder_worker.ReportProgress(100); }
private void cheat_list_item_hex_view_Click(object sender, EventArgs e) { if (cheat_list_view.SelectedRows == null) return; if (cheat_list_view.SelectedRows.Count != 1) return; DataGridViewSelectedRowCollection items = cheat_list_view.SelectedRows; ulong address = ulong.Parse((string)items[0].Cells[CHEAT_LIST_ADDRESS].Value, NumberStyles.HexNumber); int sectionID = processManager.MappedSectionList.GetMappedSectionID(address); if (sectionID >= 0) { int offset = 0; MappedSection section = processManager.MappedSectionList[sectionID]; offset = (int)(address - section.Start); HexEditor hexEdit = new HexEditor(memoryHelper, offset, section); hexEdit.Show(this); } }
private void next_pointer_finder_worker_DoWork(object sender, DoWorkEventArgs e) { PointerFinderWorkerArgs pointerFinderWorkerArgs = (PointerFinderWorkerArgs)e.Argument; result_counter = 0; pointerList.Clear(); next_pointer_finder_worker.ReportProgress(0); for (int section_idx = 0; section_idx < processManager.MappedSectionList.Count; ++section_idx) { if (next_pointer_finder_worker.CancellationPending) { break; } MappedSection mappedSection = processManager.MappedSectionList[section_idx]; if (mappedSection.Name.StartsWith("libSce")) { continue; } mappedSection.PointerSearchInit(processManager, MemoryHelper, pointerList); next_pointer_finder_worker.ReportProgress((int)(((float)section_idx / processManager.MappedSectionList.Count) * 30)); } if (next_pointer_finder_worker.CancellationPending) { return; } next_pointer_finder_worker.ReportProgress(30); pointerList.Init(); next_pointer_finder_worker.ReportProgress(50); List <PointerResult> newPointerResultList = new List <PointerResult>(); pointer_list_view.Rows.Clear(); for (int i = 0; i < pointerResults.Count; ++i) { if (i % 100 == 0) { next_pointer_finder_worker.ReportProgress((int)(50 * (float)(i) / pointerResults.Count) + 50); } PointerResult pointerResult = pointerResults[i]; if (pointerList.GetTailAddress(pointerResult, processManager.MappedSectionList) == pointerFinderWorkerArgs.Address) { newPointerResultList.Add(pointerResult); ++result_counter; if (result_counter < 2000) { int row_index = pointer_list_view.Rows.Add(); DataGridViewCellCollection row = pointer_list_view.Rows[row_index].Cells; for (int j = 0; j < pointerResult.Offsets.Length; ++j) { row[j].Value = (pointerResult.Offsets[j].ToString("X")); //offset } if (pointerResult.Offsets.Length > 0) { row[row.Count - 2].Value = (pointerResult.GetBaseAddress(processManager.MappedSectionList).ToString("X")); //address row[row.Count - 1].Value = (processManager.MappedSectionList.GetSectionName(pointerResult.BaseSectionID)); //section } } } } pointerResults = newPointerResultList; next_pointer_finder_worker.ReportProgress(100); }
private void update_result_list_view(BackgroundWorker worker, string value_type, bool refresh, int start, float percent) { worker.ReportProgress(start, 0); List <ListViewItem> listViewItems = new List <ListViewItem>(); HashSet <int> mappedSectionCheckeSet = new HashSet <int>(); ulong totalAddressCount = processManager.TotalAddressCount(); ulong curAddressCount = 0; for (int idx = 0; idx < processManager.mapped_section_list.Count; ++idx) { MappedSection mapped_section = processManager.mapped_section_list[idx]; AddressList address_list = mapped_section.AddressList; if (address_list.Count > 0) { mappedSectionCheckeSet.Add(idx); } for (int i = 0; i < address_list.Count; i++) { if (curAddressCount >= 0x10000) { break; } curAddressCount++; ListViewItem lvi = new ListViewItem(); lvi.Text = String.Format("{0:X}", address_list[i].AddressOffset + mapped_section.Start); byte[] match_bytes = BitConverter.GetBytes(address_list[i].MemoryValue); if (refresh) { match_bytes = processManager.MemoryHelper.GetBytesByType(address_list[i].AddressOffset + mapped_section.Start); Address address_tmp = new Address(); address_tmp.AddressOffset = address_list[i].AddressOffset; address_tmp.MemoryValue = processManager.MemoryHelper.BytesToUint(match_bytes); address_list[i] = address_tmp; } string value_output = processManager.MemoryHelper.BytesToString(match_bytes); lvi.SubItems.Add(value_type); lvi.SubItems.Add(value_output); lvi.SubItems.Add(processManager.MemoryHelper.PrintBytesByHex(match_bytes)); lvi.SubItems.Add(processManager.GetSectionName(idx)); listViewItems.Add(lvi); if (i % 500 == 0) { worker.ReportProgress(start + (int)(i / (float)curAddressCount * 100 * percent)); } } } WorkerReturn workerReturn = new WorkerReturn(); workerReturn.ListViewItems = listViewItems; workerReturn.MappedSectionCheckeSet = mappedSectionCheckeSet; workerReturn.Results = totalAddressCount; worker.ReportProgress(start + (int)(100 * percent), workerReturn); }
public void ResultListOfNextScan() { long processed_memory_len = 0; ulong total_memory_size = processManager.MappedSectionList.TotalMemorySize + 1; for (int section_idx = 0; section_idx < processManager.MappedSectionList.Count; ++section_idx) { if (worker.CancellationPending) { break; } MappedSection mappedSection = processManager.MappedSectionList[section_idx]; if (!mappedSection.Check) { mappedSection.ResultList = null; continue; } ResultList new_result_list = new ResultList(memoryHelper.Length, memoryHelper.Alignment); ulong address = mappedSection.Start; uint base_address_offset = 0; int length = mappedSection.Length; ResultList old_result_list = mappedSection.ResultList; old_result_list.Begin(); while (length != 0) { int cur_length = CONSTANT.PEEK_BUFFER_LENGTH; if (cur_length > length) { cur_length = length; length = 0; } else { length -= cur_length; } if (worker.CancellationPending) { break; } consumer_mutex.WaitOne(); int element_alignment = memoryHelper.Alignment; int element_length = memoryHelper.Length; byte[] buffer = buffer_queue[consumer_idx]; int buffer_len = buffer.Length; Byte[] new_value = new byte[element_length]; if (default_value_0.Length == 0) { for (; !old_result_list.End(); old_result_list.Next()) { uint address_offset = 0; Byte[] old_value = null; old_result_list.Get(ref address_offset, ref old_value); if (address_offset - base_address_offset + length >= buffer_len) { break; } Buffer.BlockCopy(buffer, (int)(address_offset - base_address_offset), new_value, 0, length); if (memoryHelper.Comparer(default_value_0, default_value_1, old_value, new_value)) { new_result_list.Add(address_offset, new_value); } } } consumer_idx = (consumer_idx + 1) % CONSTANT.MAX_PEEK_QUEUE; producer_mutex.Release(); address += (ulong)cur_length; base_address_offset += (uint)cur_length; } mappedSection.ResultList = new_result_list; if (mappedSection.Check) { processed_memory_len += mappedSection.Length; } worker.ReportProgress((int)(((float)processed_memory_len / total_memory_size) * 80)); } }
private void update_result_list_view(BackgroundWorker worker, bool refresh, int start, float percent) { worker.ReportProgress(start); List <ListViewItem> listViewItems = new List <ListViewItem>(); bool[] mappedSectionCheckeSet = new bool[processManager.MappedSectionList.Count]; ulong totalResultCount = processManager.MappedSectionList.TotalResultCount(); ulong curResultCount = 0; string value_type = MemoryHelper.GetStringOfValueType(memoryHelper.ValueType); const int MAX_RESULTS_NUM = 0x1000; for (int idx = 0; idx < processManager.MappedSectionList.Count; ++idx) { MappedSection mapped_section = processManager.MappedSectionList[idx]; ResultList result_list = mapped_section.ResultList; if (result_list == null) { continue; } if (!mapped_section.Check) { continue; } mappedSectionCheckeSet[idx] = result_list.Count > 0; for (result_list.Begin(); !result_list.End(); result_list.Next()) { if (curResultCount >= MAX_RESULTS_NUM) { break; } uint memory_address_offset = 0; byte[] memory_value = null; result_list.Get(ref memory_address_offset, ref memory_value); curResultCount++; ListViewItem lvi = new ListViewItem(); lvi.Text = String.Format("{0:X}", memory_address_offset + mapped_section.Start); if (refresh && !worker.CancellationPending) { memory_value = memoryHelper.GetBytesByType(memory_address_offset + mapped_section.Start); result_list.Set(memory_value); worker.ReportProgress(start + (int)(100.0f * curResultCount / MAX_RESULTS_NUM)); } lvi.SubItems.Add(value_type); lvi.SubItems.Add(memoryHelper.BytesToString(memory_value)); lvi.SubItems.Add(memoryHelper.BytesToHexString(memory_value)); lvi.SubItems.Add(processManager.MappedSectionList.GetSectionName(idx)); listViewItems.Add(lvi); } } WorkerReturn workerReturn = new WorkerReturn(); workerReturn.ListViewItems = listViewItems; workerReturn.MappedSectionCheckeSet = mappedSectionCheckeSet; workerReturn.Results = totalResultCount; worker.ReportProgress(start + (int)(100 * percent), workerReturn); }