public IEnumerable<AddressRange> Parse(Stream stream) { StreamReader reader = new StreamReader(stream); string result = null; Regex r = new Regex(@"([0-9]{1,3}\.){3,3}[0-9]{1,3}"); while ((result = reader.ReadLine()) != null) { MatchCollection collection = r.Matches(result); if (collection.Count == 1) { AddressRange range = new AddressRange(); string[] s = collection[0].Captures[0].Value.Split('.'); range.Start = (int.Parse(s[0]) << 24) | (int.Parse(s[1]) << 16) | (int.Parse(s[2]) << 8) | (int.Parse(s[3])); range.End = range.Start; yield return range; } else if (collection.Count == 2) { string[] s = collection[0].Captures[0].Value.Split('.'); int start = (int.Parse(s[0]) << 24) | (int.Parse(s[1]) << 16) | (int.Parse(s[2]) << 8) | (int.Parse(s[3])); s = collection[1].Captures[0].Value.Split('.'); int end = (int.Parse(s[0]) << 24) | (int.Parse(s[1]) << 16) | (int.Parse(s[2]) << 8) | (int.Parse(s[3])); AddressRange range = new AddressRange(); range.Start = start; range.End = end; yield return range; } } yield break; }
private ulong VisibleYToAddress(AddressRange r, int y) { int relativeY = graphPanel.Size.Height - bottomMargin - y + graphPanel.Top; if (relativeY < 0) relativeY = 0; return r.loAddr + (ulong)relativeY * (ulong)(heapWidth * bytesPerPixel); }
private AddressRange AddressRangeOfObject(ref LiveObjectTable.LiveObject o, AddressRange hint) { if (hint != null && hint.loAddr <= o.id && o.id < hint.hiAddr) return hint; return AddressRangeOfObject(ref o); }
void BuildAddressRangesTypeTable() { rangeList = null; rangeCount = 0; if (typeIndexToTypeDesc == null || typeIndexToTypeDesc.Length < typeName.Length) typeIndexToTypeDesc = new TypeDesc[typeName.Length]; else { foreach (TypeDesc t in typeIndexToTypeDesc) { if (t != null) { t.totalSize = 0; t.selectedSize = 0; } } } ulong totalAllocated = 0; ulong totalSelected = 0; LiveObjectTable.LiveObject o; bool prevLOH = false; for (liveObjectTable.GetNextObject(0, ulong.MaxValue, out o); o.id < ulong.MaxValue; liveObjectTable.GetNextObject(o.id + o.size, ulong.MaxValue, out o)) { int gen = liveObjectTable.GenerationOfObject(ref o); if (gen > generations-1) gen = generations-1; bool thisLOH = gen == generations-1; // Check whether we can fit this object into the last range we created. // We assume the liveObjectList is sorted, so the object can only attach // at the end of this range. if (rangeList != null && o.id - rangeList.hiAddr <= allowableGap && prevLOH == thisLOH) { Debug.Assert(o.id >= rangeList.hiAddr); rangeList.hiAddr = o.id + o.size; } else { rangeList = new AddressRange(o.id, o.id + o.size, rangeList, rangeCount++); } prevLOH = thisLOH; TypeDesc t = typeIndexToTypeDesc[o.typeIndex]; if (t == null) { t = new TypeDesc(o.typeIndex, typeName[o.typeIndex]); typeIndexToTypeDesc[o.typeIndex] = t; } t.totalSize += o.size; totalAllocated += o.size; if (InsideSelection(o.id) != 0) { t.selectedSize += o.size; totalSelected += o.size; } if (rangeList.genLoAddr[gen] > o.id) rangeList.genLoAddr[gen] = o.id; if (rangeList.genHiAddr[gen] < o.id + o.size) rangeList.genHiAddr[gen] = o.id + o.size; } sortedTypeTable = new ArrayList(); foreach (TypeDesc t in typeIndexToTypeDesc) if (t != null) sortedTypeTable.Add(t); sortedTypeTable.Sort(); foreach (TypeDesc t in sortedTypeTable) { t.percentage = 0.0; if (totalAllocated > 0) t.percentage = 100.0*t.totalSize/totalAllocated; t.selectedPercentage = 0.0; if (totalSelected > 0) t.selectedPercentage = 100*t.selectedSize/totalSelected; } }
internal AddressRange(ulong loAddr, ulong hiAddr, AddressRange next, int index) { this.loAddr = loAddr; this.hiAddr = hiAddr; this.next = next; this.index = index; }
private void BuildAddressRangesTypeTable(SampleObjectTable.SampleObject[][] masterTable) { rangeList = null; rangeCount = 0; if (typeIndexToTypeDesc == null || typeIndexToTypeDesc.Length < typeName.Length) typeIndexToTypeDesc = new TypeDesc[typeName.Length]; else { foreach (TypeDesc t in typeIndexToTypeDesc) { if (t != null) t.totalSize = 0; } } for (uint i = 0; i < masterTable.Length; i++) { SampleObjectTable.SampleObject[] soa = masterTable[i]; if (soa != null) { for (uint j = 0; j < soa.Length; j++) { SampleObjectTable.SampleObject so = soa[j]; if (so != null) { AddAddress(((ulong)i<<SampleObjectTable.firstLevelShift) + (j<<SampleObjectTable.secondLevelShift)); ProcessChangeList(so); } } } } sortedTypeTable = new ArrayList(); foreach (TypeDesc t in typeIndexToTypeDesc) if (t != null) sortedTypeTable.Add(t); sortedTypeTable.Sort(); }
/// <summary> /// Instantiates a new program memory region. /// </summary> /// <param name="traits">The memory traits (characteristics).</param> /// <param name="sRegion">The region's name.</param> /// <param name="regnAddr">The region memory address range.</param> /// <param name="memSubDomain">The memory sub-domain code.</param> public ProgMemRegion(MemTraits traits, string sRegion, AddressRange regnAddr, PICMemorySubDomain memSubDomain) : base(traits, sRegion, regnAddr, PICMemoryDomain.Prog, memSubDomain) { }
void Remove(AddressRange addressRange) { _addresses.Remove(addressRange); }
/// <summary> /// Create request wrapper /// </summary> /// <param name="request"></param> /// <param name="networkClass"></param> /// <param name="isScan"></param> public DiscoveryRequest(DiscoveryRequestModel request, NetworkClass networkClass = NetworkClass.Wired, bool isScan = false) { Request = request?.Clone() ?? throw new ArgumentNullException(nameof(request)); _cts = new CancellationTokenSource(); NetworkClass = networkClass; IsScan = isScan; if (request == null) { request = new DiscoveryRequestModel { Discovery = DiscoveryMode.Off }; } if (request.Configuration == null) { request.Configuration = new DiscoveryConfigModel(); } if (!string.IsNullOrEmpty(request.Configuration.AddressRangesToScan)) { if (AddressRange.TryParse(request.Configuration.AddressRangesToScan, out var addresses)) { AddressRanges = addresses; } } if (AddressRanges == null) { switch (request.Discovery) { case DiscoveryMode.Local: AddressRanges = NetworkInformationEx.GetAllNetInterfaces(NetworkClass) .Select(t => new AddressRange(t, true)).Distinct(); break; case DiscoveryMode.Fast: var interfaces = NetworkInformationEx.GetAllNetInterfaces(NetworkClass.Wired); AddressRanges = interfaces.Select(t => new AddressRange(t, false, 24)); AddressRanges = AddressRanges.Concat(interfaces .Where(t => t.Gateway != null && !t.Gateway.Equals(System.Net.IPAddress.Any) && !t.Gateway.Equals(System.Net.IPAddress.None)) .Select(i => new AddressRange(i.Gateway, 32))); break; case DiscoveryMode.Off: AddressRanges = Enumerable.Empty <AddressRange>(); break; case DiscoveryMode.Scan: AddressRanges = NetworkInformationEx.GetAllNetInterfaces(NetworkClass) .Select(t => new AddressRange(t, false)).Distinct(); break; default: AddressRanges = Enumerable.Empty <AddressRange>(); break; } } request.Configuration.AddressRangesToScan = AddressRange.Format(AddressRanges); if (!string.IsNullOrEmpty(request.Configuration.PortRangesToScan)) { if (PortRange.TryParse(request.Configuration.PortRangesToScan, out var ports)) { PortRanges = ports; } } if (PortRanges == null) { switch (request.Discovery) { case DiscoveryMode.Local: PortRanges = PortRange.All; break; case DiscoveryMode.Fast: PortRanges = PortRange.WellKnown; break; case DiscoveryMode.Scan: PortRanges = PortRange.Unassigned; break; case DiscoveryMode.Off: PortRanges = Enumerable.Empty <PortRange>(); break; default: PortRanges = PortRange.OpcUa; break; } } request.Configuration.PortRangesToScan = PortRange.Format(PortRanges); request.Configuration.IdleTimeBetweenScans ??= kDefaultIdleTime; request.Configuration.PortProbeTimeout ??= kDefaultPortProbeTimeout; request.Configuration.NetworkProbeTimeout ??= kDefaultNetworkProbeTimeout; TotalAddresses = AddressRanges?.Sum(r => r.Count) ?? 0; TotalPorts = PortRanges?.Sum(r => r.Count) ?? 0; }
/// <summary> /// Create request wrapper /// </summary> /// <param name="request"></param> /// <param name="networkClass"></param> /// <param name="isScan"></param> public DiscoveryRequest(DiscoveryRequestModel request, NetworkClass networkClass = NetworkClass.Wired, bool isScan = false) { Request = request?.Clone() ?? throw new ArgumentNullException(nameof(request)); _cts = new CancellationTokenSource(); NetworkClass = networkClass; IsScan = isScan; if (!string.IsNullOrEmpty(request.Configuration?.AddressRangesToScan)) { if (AddressRange.TryParse(request.Configuration?.AddressRangesToScan, out var addresses)) { AddressRanges = addresses; } } if (AddressRanges == null) { if (request.Discovery == DiscoveryMode.Fast) { var interfaces = NetworkInformationEx.GetAllNetInterfaces(NetworkClass.Wired); AddressRanges = interfaces.Select(t => new AddressRange(t, false, 24)); AddressRanges = AddressRanges.Concat(interfaces .Where(t => t.Gateway != null && !t.Gateway.Equals(System.Net.IPAddress.Any) && !t.Gateway.Equals(System.Net.IPAddress.None)) .Select(i => new AddressRange(i.Gateway, 32))); } } if (!string.IsNullOrEmpty(request.Configuration?.PortRangesToScan)) { if (PortRange.TryParse(request.Configuration?.PortRangesToScan, out var ports)) { PortRanges = ports; } } if (PortRanges == null) { switch (request.Discovery) { case DiscoveryMode.Local: PortRanges = PortRange.All; break; case DiscoveryMode.Fast: PortRanges = PortRange.WellKnown; break; case DiscoveryMode.Scan: PortRanges = PortRange.Unassigned; break; default: PortRanges = PortRange.OpcUa; break; } } TotalAddresses = AddressRanges?.Sum(r => r.Count) ?? 0; TotalPorts = PortRanges?.Sum(r => r.Count) ?? 0; }
public static BootMemoryEntry SetMemoryMap(AddressRange range, BootMemoryType type) { return(SetMemoryMap(range.Address, range.Size, type)); }
protected override void PerformOperation() { // Get the source data we need to reconstruct and signal we're about to start StackSourceData sourceData = base.SourceData; // Get the output data sink StackOutputData outputData = base.OutputData; outputData.Clear(); outputData.AlgorithmName = Name; // Get the address range of the stack pointer data AddressRange pointerRange = base.Engine.AddressInfo.StackPointerRange; AddressRange pointerRangeExtended = base.Engine.AddressInfo.StackPointerRangeWithExtensionArea; // Indicates if we added LR and PC to the call stack bool addedLRandPC = false; // Get registers ArmRegisterCollection regs = base.Engine.Registers; foreach (DataBufferUint sourceEntry in sourceData.GetUintEnumerator()) { // Check if it is within the stack domain, taking into account // our extended range if (pointerRangeExtended.Contains(sourceEntry.Address)) { StackOutputEntry outputEntry = new StackOutputEntry(sourceEntry.Address, sourceEntry.Uint); // Is it the element tht corresponds to the current value of SP? bool isCurrentSPEntry = (outputEntry.AddressRange.Contains(base.Engine.AddressInfo.Pointer)); outputEntry.IsCurrentStackPointerEntry = isCurrentSPEntry; // Is it within the pure 'stack pointer' address range? bool outsidePureStackPointerRange = !pointerRange.Contains(sourceEntry.Address); outputEntry.IsOutsideCurrentStackRange = outsidePureStackPointerRange; // These are never accurate, but neither are they ghosts outputEntry.IsAccurate = false; outputEntry.IsGhost = false; // Save entry EmitElement(outputEntry); // If we're inside the stack address range, then poke in the PC and LR values if (isCurrentSPEntry) { System.Diagnostics.Debug.Assert(!addedLRandPC); addedLRandPC = AddLRAndPC(); } } else { // Nope, ignore it... } NotifyEvent(TEvent.EReadingProgress); ++iDWordIndex; } // If the stack overflowed, then SP might be outside of the stack range. Therefore // LR and PC will not be added yet. if (!addedLRandPC) { AddLRAndPC(); } }
internal void Finalise() { int size = InstructionSize; iAddressRange = new AddressRange(iFirstInstructionAddress, iFirstInstructionAddress + (iInstructions.Count * size) - 1); }
public RVCTDisassemblyFunction(uint aAddress) { iName = string.Empty; iBaseAddress = aAddress; iAddressRange = new AddressRange(aAddress, aAddress); }
/// <summary> /// Instantiates a new data memory region. /// </summary> /// <param name="traits">The memory traits (characteristics).</param> /// <param name="sRegion">The region's name.</param> /// <param name="regnAddr">The region memory address range.</param> /// <param name="memSubDomain">The memory sub-domain code.</param> /// <param name="bankSel">The memory bank selector.</param> public DataMemRegion(MemTraits traits, string sRegion, AddressRange regnAddr, PICMemorySubDomain memSubDomain, Constant bankSel) : base(traits, sRegion, regnAddr, PICMemoryDomain.Data, memSubDomain) { BankSelector = bankSel; }
public void Add(AddressRange addressRange) { _addresses.Add(addressRange); }
public SelectionChangedEventArgs(AddressRange range) { this.range = range; }
private void versionTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (font != MainForm.instance.font) { font = MainForm.instance.font; graphPanel.Invalidate(); typeLegendPanel.Invalidate(); } ReadLogResult lastLogResult = MainForm.instance.lastLogResult; if (lastLogResult != null && lastLogResult.sampleObjectTable != sampleObjectTable) { sampleObjectTable = lastLogResult.sampleObjectTable; lastLog = sampleObjectTable.readNewLog; typeName = lastLog.typeName; lastTickIndex = sampleObjectTable.lastTickIndex; rangeList = null; rangeCount = 0; graphPanel.Invalidate(); typeLegendPanel.Invalidate(); } }
public AuthorizationResult WriteMultipleRegisters(byte unitId, AddressRange range, string role) { return(AuthorizationResult.NotAuthorized); }
private void AddAddress(ulong addr) { if (rangeList != null && addr - rangeList.hiAddr <= allowableGap) { Debug.Assert(addr >= rangeList.hiAddr); rangeList.hiAddr = addr; } else { rangeList = new AddressRange(addr, addr, rangeList, rangeCount++); } }
public AuthorizationResult ReadDiscreteInputs(byte unitId, AddressRange range, string role) { return(AuthorizationResult.Authorized); }
private void DrawAddressLabel(Graphics g, Brush brush, Pen pen, AddressRange r, int y, ulong addr) { y += (int)((r.hiAddr - addr)/(uint)verticalScale); string s = FormatAddress(addr); int width = (int)g.MeasureString(s, font).Width + 2; g.DrawString(s, font, brush, leftMargin + addressLabelWidth - width, y - font.Height / 2); g.DrawLine(pen, leftMargin + addressLabelWidth - 3, y, leftMargin + addressLabelWidth, y); }
public AuthorizationResult ReadInputRegisters(byte unitId, AddressRange range, string role) { return(AuthorizationResult.Authorized); }
internal AddressRange(ulong loAddr, ulong hiAddr, AddressRange next, int index) { this.loAddr = loAddr; this.hiAddr = hiAddr; this.next = next; this.index = index; this.genLoAddr = new ulong[generations]; this.genHiAddr = new ulong[generations]; for (int i = 0; i < generations; i++) { this.genLoAddr[i] = ulong.MaxValue; this.genHiAddr[i] = ulong.MinValue; } }
/// <summary> /// Checks if a buffer can be created within a given set of pages described by pageInfo /// satisfying the given size, minimum and maximum memory location. /// </summary> /// <param name="pageInfo">Contains the information about a singular memory page.</param> /// <param name="bufferSize">The size that a <see cref="MemoryBuffer"/> would occupy. Pre-aligned to page-size.</param> /// <param name="minimumPtr">The maximum pointer a <see cref="MemoryBuffer"/> can occupy.</param> /// <param name="maximumPtr">The minimum pointer a <see cref="MemoryBuffer"/> can occupy.</param> /// <returns>Zero if the operation fails; otherwise positive value.</returns> private IntPtr GetBufferPointerInPageRange(ref MEMORY_BASIC_INFORMATION pageInfo, int bufferSize, IntPtr minimumPtr, IntPtr maximumPtr) { // Fast return if page is not free. if (pageInfo.State != (uint)MEM_ALLOCATION_TYPE.MEM_FREE) { return(IntPtr.Zero); } // This is valid in both 32bit and 64bit Windows. // We can call GetSystemInfo to get this but that's a waste; these are constant for x86 and x64. int allocationGranularity = 65536; // Do not align page start/end to allocation granularity yet. // Align it when we map the possible buffer ranges in the pages. long pageStart = (long)pageInfo.BaseAddress; long pageEnd = (long)pageInfo.BaseAddress + (long)pageInfo.RegionSize; // Get range for page and min-max region. var minMaxRange = new AddressRange((long)minimumPtr, (long)maximumPtr); var pageRange = new AddressRange(pageStart, pageEnd); if (!pageRange.Overlaps(ref minMaxRange)) { return(IntPtr.Zero); } /* Three possible cases here: * 1. Page fits entirely inside min-max range and is smaller. * 2. Min-max range is inside page (i.e. page is bigger than the range) * 3. Page and min-max intersect, e.g. first half of pages in end of min-max * or second half of pages in start of min-max. * * Below we will build a set of possible buffer allocation ranges * and check if they satisfy our conditions. */ /* Try placing range at start and end of page boundaries. * Since we are allocating in page boundaries, we must compare against Min-Max. */ // Note: We are rounding page boundary addresses up/down, possibly beyond the original ends/starts of page. // We need to validate that we are still in the bounds of the actual page itself. var allocPtrPageMaxAligned = Mathematics.RoundDown(pageRange.EndPointer - bufferSize, allocationGranularity); var allocRangePageMaxStart = new AddressRange(allocPtrPageMaxAligned, allocPtrPageMaxAligned + bufferSize); if (pageRange.Contains(ref allocRangePageMaxStart) && minMaxRange.Contains(ref allocRangePageMaxStart)) { return((IntPtr)allocRangePageMaxStart.StartPointer); } var allocPtrPageMinAligned = Mathematics.RoundUp(pageRange.StartPointer, allocationGranularity); var allocRangePageMinStart = new AddressRange(allocPtrPageMinAligned, allocPtrPageMinAligned + bufferSize); if (pageRange.Contains(ref allocRangePageMinStart) && minMaxRange.Contains(ref allocRangePageMinStart)) { return((IntPtr)allocRangePageMinStart.StartPointer); } /* Try placing range at start and end of given minimum-maximum. * Since we are allocating in Min-Max, we must compare against Page Boundaries. */ // Note: Remember that rounding is dangerous and could potentially cause max and min to cross as usual, // must check proposed page range against both given min-max and page memory range. var allocPtrMaxAligned = Mathematics.RoundDown((long)maximumPtr - bufferSize, allocationGranularity); var allocRangeMaxStart = new AddressRange(allocPtrMaxAligned, allocPtrMaxAligned + bufferSize); if (pageRange.Contains(ref allocRangeMaxStart) && minMaxRange.Contains(ref allocRangeMaxStart)) { return((IntPtr)allocRangeMaxStart.StartPointer); } var allocPtrMinAligned = Mathematics.RoundUp((long)minimumPtr, allocationGranularity); var allocRangeMinStart = new AddressRange(allocPtrMinAligned, allocPtrMinAligned + bufferSize); if (pageRange.Contains(ref allocRangeMinStart) && minMaxRange.Contains(ref allocRangeMinStart)) { return((IntPtr)allocRangeMinStart.StartPointer); } return(IntPtr.Zero); }
private AddressRange AddressRangeOfObject(ref LiveObjectTable.LiveObject o) { AddressRange r = AddressRangeOf(o.id); if (r != null) return r; Debug.Assert(false); rangeList = new AddressRange(o.id, o.id + o.size, rangeList, rangeCount++); return rangeList; }
public RtlInstructionCluster InlineInstructions(AddressRange addrCaller, EndianImageReader rdrProcedureNody, IStorageBinder binder) { throw new NotImplementedException(); }
private void FillSpace(Graphics g, AddressRange r, Pen pen, ulong start, ulong end) { // and a relative address of the object in this range ulong relativeStartAddr = start - r.loAddr; ulong relativeEndAddr = end - r.loAddr; // divide the relative address by bytesPerPixel to get a pixelAddress int pixelStartAddr = (int)(relativeStartAddr / bytesPerPixel); int pixelEndAddr = (int)(relativeEndAddr / bytesPerPixel); // pixelAddress / heapWidth gives y more or less int yAddr = pixelStartAddr / heapWidth; // figure out base x for this range int baseX = leftMargin + r.index*(heapWidth + gap); // figure out how many pixels to draw - there's going to be some rounding error int pixelsRemaining = (pixelEndAddr - pixelStartAddr); // pixelAddress % heapWidth + baseX gives x int xAddr = pixelStartAddr % heapWidth; // now draw a line o.size / bytesPerPixel in length at x, y // taking care to handle wraparound. int x = baseX + xAddr; int y = graphPanel.Size.Height - bottomMargin - yAddr; while (pixelsRemaining > 0) { if (xAddr + pixelsRemaining > heapWidth) { DrawHorizontalLine(g, pen, x, baseX + heapWidth, y); pixelsRemaining -= heapWidth - xAddr; x = baseX; xAddr = 0; y--; } else { DrawHorizontalLine(g, pen, x, x + pixelsRemaining, y); break; } } }
/// <summary> /// Create request wrapper /// </summary> /// <param name="request"></param> /// <param name="networkClass"></param> /// <param name="isScan"></param> public DiscoveryRequest(DiscoveryRequestModel request, NetworkClass networkClass = NetworkClass.Wired, bool isScan = false) { Request = request?.Clone() ?? throw new ArgumentNullException(nameof(request)); _cts = new CancellationTokenSource(); NetworkClass = networkClass; IsScan = isScan; if (Request.Configuration == null) { Request.Configuration = new DiscoveryConfigModel(); } if (Request.Discovery == null || Request.Discovery == DiscoveryMode.Off) { // Report empty configuration if off, but keep the // discovery urls details from the original request Request.Configuration = new DiscoveryConfigModel() { ActivationFilter = Request.Configuration.ActivationFilter?.Clone(), DiscoveryUrls = Request.Configuration.DiscoveryUrls?.ToList(), Locales = Request.Configuration.Locales?.ToList() }; Request.Discovery = DiscoveryMode.Off; return; } // Parse whatever provided if (!string.IsNullOrEmpty(Request.Configuration.PortRangesToScan)) { if (PortRange.TryParse(Request.Configuration.PortRangesToScan, out var ports)) { PortRanges = ports; if (Request.Discovery == null) { Request.Discovery = DiscoveryMode.Fast; } } } if (!string.IsNullOrEmpty(Request.Configuration.AddressRangesToScan)) { if (AddressRange.TryParse(Request.Configuration.AddressRangesToScan, out var addresses)) { AddressRanges = addresses; if (Request.Discovery == null) { Request.Discovery = DiscoveryMode.Fast; } } } // Set default ranges if (AddressRanges == null) { IEnumerable <NetInterface> interfaces; switch (Request.Discovery) { case DiscoveryMode.Local: interfaces = NetworkInformationEx.GetAllNetInterfaces(NetworkClass); AddressRanges = AddLocalHost(interfaces .Select(t => new AddressRange(t, true))) .Distinct(); break; case DiscoveryMode.Fast: interfaces = NetworkInformationEx.GetAllNetInterfaces(NetworkClass.Wired); AddressRanges = AddLocalHost(interfaces .Select(t => new AddressRange(t, false, 24)) .Concat(interfaces .Where(t => t.Gateway != null && !t.Gateway.Equals(IPAddress.Any) && !t.Gateway.Equals(IPAddress.None)) .Select(i => new AddressRange(i.Gateway, 32))) .Distinct()); break; case DiscoveryMode.Network: case DiscoveryMode.Scan: interfaces = NetworkInformationEx.GetAllNetInterfaces(NetworkClass); AddressRanges = AddLocalHost(interfaces .Select(t => new AddressRange(t, false)) .Concat(interfaces .Where(t => t.Gateway != null && !t.Gateway.Equals(IPAddress.Any) && !t.Gateway.Equals(IPAddress.None)) .Select(i => new AddressRange(i.Gateway, 32))) .Distinct()); break; case DiscoveryMode.Off: case DiscoveryMode.Url: default: AddressRanges = Enumerable.Empty <AddressRange>(); break; } } if (PortRanges == null) { switch (Request.Discovery) { case DiscoveryMode.Local: PortRanges = PortRange.All; break; case DiscoveryMode.Fast: PortRanges = PortRange.WellKnown; break; case DiscoveryMode.Scan: PortRanges = PortRange.Unassigned; break; case DiscoveryMode.Network: PortRanges = PortRange.OpcUa; break; case DiscoveryMode.Off: case DiscoveryMode.Url: default: PortRanges = Enumerable.Empty <PortRange>(); break; } } // Update reported configuration with used settings if (AddressRanges != null && AddressRanges.Any()) { Request.Configuration.AddressRangesToScan = AddressRange.Format(AddressRanges); TotalAddresses = AddressRanges?.Sum(r => r.Count) ?? 0; } if (PortRanges != null && PortRanges.Any()) { Request.Configuration.PortRangesToScan = PortRange.Format(PortRanges); TotalPorts = PortRanges?.Sum(r => r.Count) ?? 0; } Request.Configuration.IdleTimeBetweenScans ??= kDefaultIdleTime; Request.Configuration.PortProbeTimeout ??= kDefaultPortProbeTimeout; Request.Configuration.NetworkProbeTimeout ??= kDefaultNetworkProbeTimeout; }
private void DrawHeapAddress(Graphics g, Brush brush, Pen pen, AddressRange r, ulong addr) { int baseX = leftMargin + r.index*(heapWidth + gap); int baseY = graphPanel.Size.Height - bottomMargin; // and a relative address of the object in this range ulong relativeAddr = addr - r.loAddr; // divide the relative address by bytesPerPixel and heapWidth int yAddr = (int)(relativeAddr / (ulong)(bytesPerPixel*heapWidth)); string label = FormatAddress(addr); int width = (int)g.MeasureString(label, font).Width+2; int y = baseY - yAddr; g.DrawString(label, font, brush, baseX - width, y - font.Height/2); g.DrawLine(pen, baseX-3, y, baseX-2, y); }
public static List <ulong> FindPatternAddresses(Process process, AddressRange addressRange, BytePattern pattern, bool stopAfterFirst) { List <ulong> matchAddresses = new List <ulong>(); ulong currentAddress = addressRange.Start; while (currentAddress < addressRange.End && !process.HasExited) { WindowsApi.MEMORY_BASIC_INFORMATION64 memoryRegion; if (WindowsApi.VirtualQueryEx(process.Handle, (IntPtr)currentAddress, out memoryRegion, (uint)Marshal.SizeOf(typeof(WindowsApi.MEMORY_BASIC_INFORMATION64))) > 0 && memoryRegion.RegionSize > 0 && memoryRegion.State == (uint)WindowsApi.RegionPageState.MEM_COMMIT && CheckProtection(pattern, memoryRegion.Protect)) { var regionStartAddress = memoryRegion.BaseAddress; if (addressRange.Start > regionStartAddress) { regionStartAddress = addressRange.Start; } var regionEndAddress = memoryRegion.BaseAddress + memoryRegion.RegionSize; if (addressRange.End < regionEndAddress) { regionEndAddress = addressRange.End; } ulong regionBytesToRead = regionEndAddress - regionStartAddress; byte[] regionBytes = new byte[regionBytesToRead]; if (process.HasExited) { break; } int lpNumberOfBytesRead = 0; WindowsApi.ReadProcessMemory(process.Handle, (IntPtr)regionStartAddress, regionBytes, regionBytes.Length, ref lpNumberOfBytesRead); var matchIndices = FindPatternMatchIndices(regionBytes, pattern, stopAfterFirst); if (matchIndices.Any() && stopAfterFirst) { var matchAddress = regionStartAddress + (ulong)matchIndices.First(); matchAddresses.Add(matchAddress); break; } else { foreach (var matchIndex in matchIndices) { var matchAddress = regionStartAddress + (ulong)matchIndex; matchAddresses.Add(matchAddress); } } } currentAddress = memoryRegion.BaseAddress + memoryRegion.RegionSize; } return(matchAddresses); }