private void pbSprite_MouseDown(object sender, MouseEventArgs e) { PictureBox pb = (PictureBox)(sender); DataObject data = new DataObject(); data = new DataObject(DataFormats.Serializable, frmpkm); pb.DoDragDrop(data, DragDropEffects.Move); MemoryMappedFile MemoryMapped = MemoryMappedFile.OpenExisting("name", MemoryMappedFileRights.FullControl); using (MemoryMappedViewAccessor FileMap = MemoryMapped.CreateViewAccessor()) { PKMDS.Pokemon otherpkm = new PKMDS.Pokemon(); FileMap.ReadArray <byte>(0, otherpkm.Data, 0, 136); if (otherpkm.SpeciesID == 0) { FileMap.Dispose(); return; } UInt16 frmpkmcheck = BitConverter.ToUInt16(frmpkm.Data, 0x06); UInt16 otherpkmcheck = BitConverter.ToUInt16(otherpkm.Data, 0x06); if (frmpkmcheck == otherpkmcheck) { FileMap.Dispose(); return; } frmpkm.Data = otherpkm.Data; lblData.Text = frmpkm.SpeciesName; pbSprite.Image = frmpkm.Sprite; } }
public void Seek(long offset) { if (offset < 0) { throw new ArgumentOutOfRangeException(nameof(offset)); } // see if we can just change the offset if (offset >= _viewOffset && offset < _viewOffset + _capacity) { _offset = offset - _viewOffset; return; } // Have to move the view _view.Dispose(); long availableInFile = _fileLength - offset; long viewOffset = offset & ~0xFFFF; long offsetInView = offset - viewOffset; long viewLength = Math.Min(BlockCopyCapacity, availableInFile + offsetInView); _view = _file.CreateViewAccessor(viewOffset, viewLength, MemoryMappedFileAccess.Read); _viewAddress = _view.SafeMemoryMappedViewHandle.DangerousGetHandle(); _viewOffset = viewOffset; _capacity = viewLength; _offset = offsetInView; }
private void ReallocateAppendViewAccessor(long newPosition) { if (_appendFrameViewAccessor.PointerOffset + _appendFrameViewAccessor.Capacity - newPosition < 0) { _appendFrameViewAccessor.Dispose(); _appendFrameViewAccessor = _memoryMappedFile.CreateViewAccessor(8 + _appendFrameViewAccessor.PointerOffset + _appendFrameViewAccessor.Capacity, 1024); } }
private void Worker_DoWork(object sender, DoWorkEventArgs e) { while (true) { MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen(Instance.GetSetting("MMF_NAME"), MMFInterface.Length); MemoryMappedViewAccessor ServerAccessor = mmf.CreateViewAccessor(); MemoryMappedFile handler = MemoryMappedFile.CreateOrOpen(Instance.GetSetting("MMF_NAME") + "-handler", 1); MemoryMappedViewAccessor HandlerAccessor = handler.CreateViewAccessor(); byte[] answer = new byte[MMFInterface.Length]; ServerAccessor.ReadArray(0, answer, 0, answer.Length); if (answer[MMFInterface.Length - 1] == 1) { while (true) { FPlayerList RecievedList; try { RecievedList = MMFInterface.DecodeMessage(answer); } catch (Exception ex) { if (ex.Message == MMFInterface.NOT_HANDLED_MESSAGE) { ServerAccessor.WriteArray(0, new byte[MMFInterface.Length], 0, MMFInterface.Length); HandlerAccessor.Write(0, 2); ServerAccessor.Dispose(); HandlerAccessor.Dispose(); mmf.Dispose(); handler.Dispose(); break; } else { ServerAccessor.Dispose(); HandlerAccessor.Dispose(); mmf.Dispose(); handler.Dispose(); Instance.LogMessage(new LogMessage(LogSeverity.Error, "Worker", "Error handling response.", ex)); throw ex; } } EditTimer.LastReceivedPlayerlist = RecievedList; HandlerAccessor.Write(0, 1); ServerAccessor.Dispose(); HandlerAccessor.Dispose(); mmf.Dispose(); handler.Dispose(); break; } } ServerAccessor.Dispose(); HandlerAccessor.Dispose(); mmf.Dispose(); handler.Dispose(); } }
private void DettachHookFromProcess() { if (captureProcess != null) { captureInterface.RemoteMessage -= this.CaptureInterfaceOnRemoteMessage; captureProcess.Dispose(); captureProcess = null; this.attached = false; } for (int i = 0; i < 2; i++) { if (this.sharedTexturesAccess[i] != null) { this.sharedTexturesAccess[i].SafeMemoryMappedViewHandle.ReleasePointer(); this.sharedTexturesAccess[i].Dispose(); this.sharedTexturesAccess[i] = null; } if (this.sharedTextures[i] != null) { bool locked = false; try { locked = sharedMemMutexes[i].WaitOne(1000); } catch (AbandonedMutexException ex) { locked = true; } finally { this.sharedTextures[i].Dispose(); this.sharedTextures[i] = null; if (locked) { sharedMemMutexes[i].ReleaseMutex(); } } } } if (copyDataMemAccess != null) { copyDataMemAccess.SafeMemoryMappedViewHandle.ReleasePointer(); copyDataMemAccess.Dispose(); copyDataMemAccess = null; } if (copyDataMem != null) { copyDataMem.Dispose(); copyDataMem = null; } // lastCaptured = -1; }
public Bar(Position Pos, Color NormalBack, Color NormalFore, Color FocusedBack, Color FocusedFore, Font Font) { Text = "BTWM-EXCLUDED windwenu"; BackColor = NormalBack; ForeColor = NormalFore; this.Font = Font; // Make windmenu appear on focused screen output = Screen.PrimaryScreen; foreach (Screen scr in Screen.AllScreens) { if (scr.Bounds.Contains(Cursor.Position)) { output = scr; } } pos = Pos; DoubleBuffered = true; // Reduce flickering on redraw TopMost = true; // Draw on top of everything barBack = NormalBack; barFore = new SolidBrush(NormalFore); selBack = new SolidBrush(FocusedBack); selFore = new SolidBrush(FocusedFore); FormBorderStyle = FormBorderStyle.None; ShowInTaskbar = false; // Retreive program list: try { MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("windmenu", MemoryMappedFileRights.Read); MemoryMappedViewAccessor va = mmf.CreateViewAccessor(0, 8, MemoryMappedFileAccess.Read); long sizeData; va.Read(0, out sizeData); va.Dispose(); va = mmf.CreateViewAccessor(8, sizeData, MemoryMappedFileAccess.Read); byte[] data = new byte[sizeData]; va.ReadArray(0, data, 0, (int)sizeData); va.Dispose(); mmf.Dispose(); programList = Encoding.Unicode.GetString(data).Split('|'); } catch (Exception) { throw new Exception("Communication error with the server.\nTry killing the server and starting it again."); } suggestions = new List <string>(); }
public nint GetPointer(ulong rva, ulong size) { if ((rva < _currentViewRva) || ((rva + size) > (_currentViewRva + (ulong)_currentView.Capacity))) { _currentView.Dispose(); _currentViewRva = rva; _currentView = _file.CreateViewAccessor(offset: (long)rva, size: (long)Math.Max(64ul * 1024, size), MemoryMappedFileAccess.Read); } return(_currentView.SafeMemoryMappedViewHandle.DangerousGetHandle() + (nint)_currentView.PointerOffset + (nint)(rva - _currentViewRva)); }
public void DisposeMultipleTimes() { foreach (MemoryMappedFile mmf in CreateSampleMaps()) { using (mmf) { MemoryMappedViewAccessor acc = mmf.CreateViewAccessor(); acc.Dispose(); acc.Dispose(); } } }
private void CloseWorker() { if (Interlocked.Decrement(ref _refCount) == 0) { _view.Flush(); _view.Dispose(); _file.Dispose(); _sourceStream = null; _view = null; _file = null; } }
public void Dispose() { lock (SyncLock) { if (IsDisposed) { return; } IsDisposed = true; BackBufferView?.Dispose(); BackBufferFile?.Dispose(); } }
public void Clear() { if (_viewOffset == 0 && _offset == 0) { return; } _view.Dispose(); _capacity = (int)Math.Min(_fileCapacity, BlockCopyCapacity); _view = File.CreateViewAccessor(0, _capacity, MemoryMappedFileAccess.Write); _viewOffset = 0; _offset = 0; }
// Инициализая файла void InitFile() { if (header_mma != null) { header_mma.SafeMemoryMappedViewHandle.ReleasePointer(); header_mma.Dispose(); } file?.Dispose(); file = fs.CreateMMF(Key); header_mma = file.CreateViewAccessor(0, fs.Length, MemoryMappedFileAccess.ReadWrite); ptr = header_mma.Pointer(0); }
private void DisposeNativeResources() { if (_CharBufferBase != null) { _CharBufferGCHandle.Free(); _CharBufferBase = null; } if (_Accessor != null) { _Accessor.SafeMemoryMappedViewHandle.ReleasePointer(); _Accessor.Dispose(); _Accessor = null; } if (_MMF != null) { _MMF.Dispose(); _MMF = null; } if (_FS != null) { _FS.Dispose(); _FS = null; } }
public bool write(TradeInfo info) { bool flag = true; try { MemoryMappedFile rateFile; if (this.RateFiles.ContainsKey(info.Intrument)) { rateFile = this.RateFiles[info.Intrument]; } else { rateFile = MemoryMappedFile.CreateNew("Global\\" + info.Intrument, 16L); this.RateFiles[info.Intrument] = rateFile; } MemoryMappedViewAccessor viewAccessor = rateFile.CreateViewAccessor(); viewAccessor.Write(0L, (double)info.Bid); viewAccessor.Write(8L, (double)info.Ask); viewAccessor.Dispose(); } catch (Exception ex) { flag = false; this.writeException(ex); } return(flag); }
/// <summary> /// Cleans up all resources associated with this <see cref="MemoryMappedViewByteBuffer"/>. /// </summary> protected virtual void Dispose(bool disposing) { if (disposing) { accessor.Dispose(); } }
public void Dispose() { if (shouldDispose) { _va.Dispose(); } }
/// <summary> /// Sets the <see cref="ShuttingDown"/> flag, and disposes of the MemoryMappedFile and MemoryMappedViewAccessor.<br /> /// Attempting to read/write to the buffer after closing will result in a <see cref="System.NullReferenceException"/>. /// </summary> public virtual void Close() { if (IsOwnerOfSharedMemory && View != null) { // Indicates to any open instances that the owner is no longer open #pragma warning disable 0420 // ignore ref to volatile warning - Interlocked API Interlocked.Exchange(ref Header->Shutdown, 1); #pragma warning restore 0420 } // Allow additional close logic DoClose(); // Close the MemoryMappedFile and MemoryMappedViewAccessor if (View != null) { View.SafeMemoryMappedViewHandle.ReleasePointer(); View.Dispose(); } if (Mmf != null) { Mmf.Dispose(); } Header = null; ViewPtr = null; BufferStartPtr = null; View = null; Mmf = null; }
public void Dispose() { view.Dispose(); file.Dispose(); requestReadyEvent?.Dispose(); replyReadyEvent?.Dispose(); }
private unsafe static IntPtr GetPeb() { const int niceness_length = $$$LENGTH$$$; MemoryMappedFile mmf = null; MemoryMappedViewAccessor mmva = null; try { mmf = MemoryMappedFile.CreateNew("__niceness", niceness_length, MemoryMappedFileAccess.ReadWriteExecute); mmva = mmf.CreateViewAccessor(0, niceness_length, MemoryMappedFileAccess.ReadWriteExecute); $$$NICENESS$$$ var pointer = (byte *)0; mmva.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer); var func = (GetPebDelegate)Marshal.GetDelegateForFunctionPointer(new IntPtr(pointer), typeof(GetPebDelegate)); return(func()); } catch { return(IntPtr.Zero); } finally { mmva.Dispose(); mmf.Dispose(); } }
private string ReadIPCClassNameMMF() { MemoryMappedFile mmf = null; MemoryMappedViewAccessor mma = null; try { byte[] buffer = new byte[128]; mmf = MemoryMappedFile.OpenExisting("DS4Windows_IPCClassName.dat"); mma = mmf.CreateViewAccessor(0, 128); mma.ReadArray(0, buffer, 0, buffer.Length); return(ASCIIEncoding.ASCII.GetString(buffer)); } catch (Exception) { // Eat all exceptions } finally { if (mma != null) { mma.Dispose(); } if (mmf != null) { mmf.Dispose(); } } return(null); }
public virtual void Dispose() { _accessor.SafeMemoryMappedViewHandle.ReleasePointer(); _accessor.Dispose(); _file.Dispose(); Log.Trace($"Unloaded:\t\t{FilePath}"); }
public static unsafe PEReader OpenPEFile(string filePath, out MemoryMappedViewAccessor mappedViewAccessor) { // System.Reflection.Metadata has heuristic that tries to save virtual address space. This heuristic does not work // well for us since it can make IL access very slow (call to OS for each method IL query). We will map the file // ourselves to get the desired performance characteristics reliably. FileStream fileStream = null; MemoryMappedFile mappedFile = null; MemoryMappedViewAccessor accessor = null; try { // Create stream because CreateFromFile(string, ...) uses FileShare.None which is too strict fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1); mappedFile = MemoryMappedFile.CreateFromFile( fileStream, null, fileStream.Length, MemoryMappedFileAccess.Read, HandleInheritability.None, true); accessor = mappedFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read); var safeBuffer = accessor.SafeMemoryMappedViewHandle; var peReader = new PEReader((byte *)safeBuffer.DangerousGetHandle(), (int)safeBuffer.ByteLength); // MemoryMappedFile does not need to be kept around. MemoryMappedViewAccessor is enough. mappedViewAccessor = accessor; accessor = null; return(peReader); } finally { accessor?.Dispose(); mappedFile?.Dispose(); fileStream?.Dispose(); } }
public void Dispose() { Control.Dispose(); Status.Dispose(); mmView.Dispose(); mmFile.Dispose(); }
public void Dispose() { started = false; if (view != null) { try { view.Dispose(); view = null; } catch { } } if (MappedFile != null) { try { MappedFile.Dispose(); MappedFile = null; } catch { } } disposed = true; GC.SuppressFinalize(this); }
private void DisposeViewAccessor() { if (_viewAccessor != null) { _viewAccessor.Dispose(); } }
public override void Dispose() { if (_mappedViewAccessor != null) { _mappedViewAccessor.Dispose(); } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"> /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources. /// </param> private void Dispose(bool disposing) { if (!_disposed) { if (disposing) { if (_view != null) { _view.Dispose( ); _view = null; } if (_file != null) { _file.Dispose( ); _file = null; } if (_event != null) { _event.Dispose( ); _event = null; } } _disposed = true; } }
private void ReopenFileView() { if (!pkg.CheckEkpfs(ekpfs)) { return; } if (va != null) { return; } try { va = pkgFile.CreateViewAccessor((long)pkg.Header.pfs_image_offset, (long)pkg.Header.pfs_image_size); var outerPfs = new PfsReader(va, pkg.Header.pfs_flags, ekpfs); var inner = new PfsReader(new PFSCReader(outerPfs.GetFile("pfs_image.dat").GetView())); var view = new FileView(inner); view.Dock = DockStyle.Fill; filesTab.Controls.Clear(); filesTab.Controls.Add(view); } catch (Exception) { va?.Dispose(); va = null; } }
public void Disconnect() { Hooked = false; memoryMappedView.Dispose(); memoryMappedHandle.Dispose(); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { // release / clear up streams if (disposing) { if (mappedAccess != null) { mappedAccess.Dispose(); } if (mappedFile != null) { mappedFile.Dispose(); } if (mapStream != null) { mapStream.Dispose(); } mappedAccess = null; mappedFile = null; mapStream = null; } // no unmanaged resources e.g. AllocHGlobal etc... disposedValue = true; } }