示例#1
0
 public HexBoxUndoCommand(HexBox hexBox, HexBoxPosition origCaretPos, ulong offset, byte[] origData, string descr)
 {
     this.doc = hexBox.Document;
     this.hexBoxWeakRef = new WeakReference(hexBox);
     this.origCaretPos = origCaretPos;
     this.newCaretPos = hexBox.CaretPosition;
     this.offset = offset;
     this.origData = origData;
     this.newData = doc.Read(offset, origData.Length);
     this.descr = descr;
     this.canExecute = false;
 }
示例#2
0
        static void Write(HexDocument doc, Stream target, ulong start, ulong end)
        {
            const int MAX_BUFFER_LENGTH = 1024 * 64;
            byte[] buffer = new byte[end - start >= MAX_BUFFER_LENGTH ? MAX_BUFFER_LENGTH : (int)(end - start + 1)];
            ulong offs = start;
            while (offs <= end) {
                ulong bytesLeft = offs == 0 && end == ulong.MaxValue ? ulong.MaxValue : end - offs + 1;
                int bytesToRead = bytesLeft >= (ulong)buffer.Length ? buffer.Length : (int)bytesLeft;

                doc.Read(offs, buffer, 0, bytesToRead);
                target.Write(buffer, 0, bytesToRead);

                ulong nextOffs = offs + (ulong)bytesToRead;
                if (nextOffs < offs)
                    break;
                offs = nextOffs;
            }
        }