Ejemplo n.º 1
0
        private int ReadCore(byte[] buffer, int offset, int count)
        {
            int num2 = f.Read(buffer, offset, count);

            if (num2 == -1)
            {
                throw new IOException();
            }
            _pos += (ulong)num2;
            VerifyOSHandlePosition();
            return(num2);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Copies a file from the remote device to the local system.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="deviceFileName">The name of the remote file to copy.</param>
        /// <param name="desktopFileName">The name of the local destination file.</param>
        /// <param name="overwrite">true if the destination file can be overwritten; otherwise, false.</param>
        public static void CopyFileFromDevice(RemoteDevice device, string deviceFileName, string desktopFileName, bool overwrite)
        {
            using var remoteFile = new RemoteDevice.DeviceFile(device.ISession, deviceFileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);
            using var localFile  = new FileStream(desktopFileName, overwrite ? FileMode.Create : FileMode.CreateNew, FileAccess.Write);
            // read data from remote file into buffer
            byte[] buffer    = new byte[FileBufferSize];
            int    bytesread = 0;

            while ((bytesread = remoteFile.Read(buffer, 0, FileBufferSize)) > 0)
            {
                // write it into local file
                localFile.Write(buffer, 0, bytesread);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Reads the contents of a file on a remote device into a array of bytes.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="path">A file to open for reading.</param>
 /// <returns>
 /// A byte array containing the contents of the file.
 /// </returns>
 public static byte[] ReadAllBytes(RemoteDevice device, string path)
 {
     byte[] ret = new byte[0];
     using (RemoteDevice.DeviceFile remoteFile = new RemoteDevice.DeviceFile(device.ISession, path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL))
     {
         using MemoryStream mem = new MemoryStream(10240);
         // read data from remote file into buffer
         byte[] buffer    = new byte[FileBufferSize];
         int    bytesread = 0;
         while ((bytesread = remoteFile.Read(buffer, 0, FileBufferSize)) > 0)
         {
             // write it into local file
             mem.Write(buffer, 0, bytesread);
         }
         ret = mem.ToArray();
     }
     return(ret);
 }