示例#1
0
        static bool WriteFile(IntPtr fileHandle, IntPtr buffer, uint numberOfBytesToWrite, out uint numberOfBytesWritten, IntPtr overlapped)
        {
            DumpContext dc = GetDumpContextFromHandle(fileHandle);

            if (dc == null)
            {
                return(WriteFile_orig(fileHandle, buffer, numberOfBytesToWrite, out numberOfBytesWritten, overlapped));
            }

            if (dc.Limit != 0 && dc.CurrentOffset + numberOfBytesToWrite > dc.Limit)
            {
                SetLastError(ERROR_DISK_FULL);
                numberOfBytesWritten = 0;
                return(false);
            }
            else if (dc.CurrentOffset + numberOfBytesToWrite > dc.Data.Length)
            {
                Console.Write(".");
                dc.Resize(dc.CurrentOffset + numberOfBytesToWrite);
            }

            Marshal.Copy(buffer, dc.Data, (int)dc.CurrentOffset, (int)numberOfBytesToWrite);
            dc.CurrentOffset    += numberOfBytesToWrite;
            numberOfBytesWritten = numberOfBytesToWrite;

            int growth = (int)dc.CurrentOffset - (int)dc.Size;

            if (growth > 0)
            {
                dc.Size += (uint)growth;
            }

            return(true);
        }