Example #1
0
        public unsafe static byte[] GetSha1(byte[] path)
        {
            var ps    = PenguinSanitizer.Extensions.ToBytePtr(path);
            var newFd = LibC.open(ps, LibC.O_RDONLY);

            // Tap the stream so we can get a hash on it.

            var hash = HashAlgorithm.Create("SHA1");

            var buf = new Byte[32 * 1024 * 1024];

            while (true)
            {
                ssize_t rd = 0;
                fixed(void *b = buf)
                {
                    rd = LibC.read(newFd, b, buf.Length);

                    hash.TransformBlock(buf, 0, (int)rd, buf, 0);
                }

                if (rd < 1)
                {
                    break;
                }
            }

            LibC.close(newFd);
            buf = null;

            hash.TransformFinalBlock(buf, 0, 0);
            return(hash.Hash);
        }
Example #2
0
        internal static int Read(int fd, ulong offset, Span <byte> buffer)
        {
            if (fd == -1)
            {
                return(LibC.EACCES);
            }

            LibC.lseek(fd, (long)offset, LibC.SEEK_SET);
            if (LibC.errno != 0)
            {
                return(-LibC.errno);
            }

            ssize_t rd;

            fixed(void *bp = buffer)
            {
                rd = LibC.read(fd, bp, buffer.Length);
            }

            if (rd >= 0)
            {
                return((int)rd);
            }

            return(-LibC.errno);
        }
Example #3
0
        private void CallRead()
        {
            IntPtr dataPtr = Marshal.AllocHGlobal((int)bufferSize.Value);
            int    readed  = LibC.read((int)fd.Value, dataPtr, (int)bufferSize.Value);

            if (readed == -1)
            {
                SetErrorNumber();
            }
            else
            {
                byte[] data = new byte[readed];
                Marshal.Copy(dataPtr, data, 0, readed);
                machine.SystemBus.WriteBytes(data, (ulong)buffer.Value, readed);
                Marshal.FreeHGlobal(dataPtr);
            }
            status.Value = (uint)readed;
            call         = Call.Done;
        }