public PatchRangeConflict(PatchRange range, AsmPatch conflictPatch, PatchRange conflictRange, bool isInFreeSpace) { this.Range = range; this.ConflictPatch = conflictPatch; this.ConflictRange = conflictRange; this.IsInFreeSpace = isInFreeSpace; }
public static bool IsContainedWithinFreeSpace(PatchRange range, FreeSpaceMode mode) { foreach (PatchRange freeSpaceRange in GetRanges(mode)) { if (range.IsContainedWithin(freeSpaceRange)) { return(true); } } return(false); }
public static bool HasFreeSpaceOverlap(PatchRange range, FreeSpaceMode mode) { foreach (PatchRange freeSpaceRange in GetRanges(mode)) { if (range.HasOverlap(freeSpaceRange)) { return(true); } } return(false); }
public static bool IsContainedWithinPsxFreeSpace(PatchRange range) { foreach (PatchRange freeSpaceRange in PsxRanges) { if (range.IsContainedWithin(freeSpaceRange)) { return(true); } } return(false); }
public static bool HasPsxFreeSpaceOverlap(PatchRange range) { foreach (PatchRange freeSpaceRange in PsxRanges) { if (range.HasOverlap(freeSpaceRange)) { return(true); } } return(false); }
private void LoadItems(int freeSpacePositionIndex) { lbl_NumberOfPatches.Text = "0"; lbl_NumberOfWrites.Text = "0"; if (freeSpacePositionIndex < 0) { return; } dgv_FreeSpace.Rows.Clear(); txtAddress.Clear(); rowPatchMap = new Dictionary <DataGridViewRow, PatchedByteArray>(); PatchRange range = FreeSpace.GetRanges(mode)[freeSpacePositionIndex]; if (!freeSpaceMaps.PatchRangeMap.ContainsKey(range)) { return; } //long positionEndOffset = position.StartLocation + position.Length - 1; List <PatchedByteArray> patchedByteArrayList = freeSpaceMaps.PatchRangeMap[range]; HashSet <AsmPatch> asmPatchSet = freeSpaceMaps.OuterPatchRangeMap[range]; for (int index = 0; index < patchedByteArrayList.Count; index++) { PatchedByteArray patchedByteArray = patchedByteArrayList[index]; AsmPatch asmPatch = freeSpaceMaps.InnerPatchMap[patchedByteArray]; // Column order: Number, Address, Length, Next Address, Space to Next Patch, File, Name int length = patchedByteArray.GetBytes().Length; long nextAddress = patchedByteArray.Offset + length; long nextPatchLocation = (index < (patchedByteArrayList.Count - 1)) ? patchedByteArrayList[index + 1].Offset : range.EndOffset; long spaceToNextPatch = nextPatchLocation - nextAddress; bool isSpaceToNextPatchNegative = (spaceToNextPatch < 0); //string strSpaceToNextPatch = isSpaceToNextPatchNegative ? ("-" + (-spaceToNextPatch).ToString("X")) : spaceToNextPatch.ToString("X"); //dgv_FreeSpace.Rows.Add(index, patchedByteArray.Offset.ToString("X"), length.ToString("X"), nextAddress.ToString("X"), strSpaceToNextPatch, asmPatch.Filename, asmPatch.Name); dgv_FreeSpace.Rows.Add(index, patchedByteArray.Offset, length, nextAddress, spaceToNextPatch, asmPatch.Filename, asmPatch.Name); if (isSpaceToNextPatchNegative) { dgv_FreeSpace.Rows[index].Cells[4].Style.BackColor = Color.FromArgb(225, 125, 125); } rowPatchMap.Add(dgv_FreeSpace.Rows[index], patchedByteArray); } lbl_NumberOfPatches.Text = asmPatchSet.Count.ToString(); lbl_NumberOfWrites.Text = patchedByteArrayList.Count.ToString(); }
public static FreeSpaceAnalyzeResult Analyze(List <PatchedByteArray> innerPatches, PatchRange freeSpaceRange, bool isSorted = true) { if (!isSorted) { innerPatches = new List <PatchedByteArray>(innerPatches); innerPatches.Sort( delegate(PatchedByteArray patchedByteArray1, PatchedByteArray patchedByteArray2) { return(patchedByteArray1.Offset.CompareTo(patchedByteArray2.Offset)); } ); } FreeSpaceAnalyzeResult result = new FreeSpaceAnalyzeResult(); result.ConflictIndexes = new HashSet <int>(); if (innerPatches.Count == 0) { return(result); } result.LargestGapOffset = (int)freeSpaceRange.StartOffset; result.LargestGapSize = (int)(innerPatches[0].Offset - freeSpaceRange.StartOffset); int endIndex = innerPatches.Count - 1; for (int index = 0; index < endIndex; index++) { PatchedByteArray patchedByteArray = innerPatches[index]; int length = patchedByteArray.GetBytes().Length; long nextAddress = patchedByteArray.Offset + length; long nextPatchLocation = innerPatches[index + 1].Offset; long spaceToNextPatch = nextPatchLocation - nextAddress; if (spaceToNextPatch > result.LargestGapSize) { result.LargestGapOffset = (int)nextAddress; result.LargestGapSize = (int)spaceToNextPatch; } if ((innerPatches[index + 1].Offset - nextAddress) < 0) { if (innerPatches[index].HasConflict(innerPatches[index + 1])) { result.HasConflicts = true; result.ConflictIndexes.Add(index); } } } int finalNextAddress = (int)(innerPatches[endIndex].Offset + innerPatches[endIndex].GetBytes().Length); int endGapSize = (int)(freeSpaceRange.EndOffset - finalNextAddress); if (endGapSize > result.LargestGapSize) { result.LargestGapOffset = finalNextAddress; result.LargestGapSize = endGapSize; } return(result); }
private ConflictCheckResult CheckConflicts(List <AsmPatch> patchList) { List <AsmPatch> resultPatchList = new List <AsmPatch>(); Dictionary <AsmPatch, List <PatchRangeConflict> > conflictMap = new Dictionary <AsmPatch, List <PatchRangeConflict> >(); Dictionary <AsmPatch, List <PatchedByteArray> > combinedPatchListMap = new Dictionary <AsmPatch, List <PatchedByteArray> >(); foreach (AsmPatch patch in patchList) { combinedPatchListMap[patch] = patch.GetCombinedPatchList(); } for (int patchIndex = 0; patchIndex < patchList.Count; patchIndex++) { AsmPatch patch = patchList[patchIndex]; List <PatchedByteArray> combinedPatchList = combinedPatchListMap[patch]; foreach (PatchedByteArray patchedByteArray in combinedPatchList) { if (patchedByteArray is InputFilePatch) { continue; } PatchRange range = new PatchRange(patchedByteArray); for (int conflictPatchIndex = patchIndex + 1; conflictPatchIndex < patchList.Count; conflictPatchIndex++) { AsmPatch conflictPatch = patchList[conflictPatchIndex]; List <PatchedByteArray> conflictCombinedPatchList = combinedPatchListMap[conflictPatch]; foreach (PatchedByteArray conflictPatchedByteArray in conflictCombinedPatchList) { if (conflictPatchedByteArray is InputFilePatch) { continue; } //if (patchedByteArray.IsPatchEqual(conflictPatchedByteArray)) if (!patchedByteArray.HasConflict(conflictPatchedByteArray)) { continue; } PatchRange conflictRange = new PatchRange(conflictPatchedByteArray); if (range.HasOverlap(conflictRange)) { bool isInFreeSpace = FreeSpace.IsContainedWithinPsxFreeSpace(range); PatchRangeConflict patchConflict = new PatchRangeConflict(range, conflictPatch, conflictRange, isInFreeSpace); PatchRangeConflict reversePatchConflict = new PatchRangeConflict(conflictRange, patch, range, isInFreeSpace); if (conflictMap.ContainsKey(patch)) { conflictMap[patch].Add(patchConflict); } else { conflictMap.Add(patch, new List <PatchRangeConflict> { patchConflict }); } if (conflictMap.ContainsKey(conflictPatch)) { conflictMap[conflictPatch].Add(reversePatchConflict); } else { conflictMap.Add(conflictPatch, new List <PatchRangeConflict> { reversePatchConflict }); } } } } } if (conflictMap.ContainsKey(patch)) { resultPatchList.Add(patch); } } return(new ConflictCheckResult(resultPatchList, conflictMap)); }