Exemplo n.º 1
0
        public unsafe void AtualizarCRC()
        {
            Byte[] dados = toByteArray();

            fixed(byte *pSrc = dados)
            {
                FormatoListaArquivos *formatoListaArquivos = (FormatoListaArquivos *)pSrc;

                this.crc = CalcularCRC(dados);
            }
        }
Exemplo n.º 2
0
        private unsafe UInt16 CalcularCRC(Byte[] dados)
        {
            int tamanho;

            Byte[] dadosCRC = new byte[sizeof(FormatoListaArquivos) - sizeof(UInt16)];

            fixed(byte *pSrc = dados)
            {
                FormatoListaArquivos *regiao = (FormatoListaArquivos *)pSrc;

                Array.Copy(dados, 0, dadosCRC, 0, (int)&regiao->crc - (int)pSrc);
                Array.Copy(dados, ((int)&regiao->crc - (int)pSrc + sizeof(UInt16)), dadosCRC,
                           (int)&regiao->crc - (int)pSrc,
                           sizeof(FormatoListaArquivos) - ((int)&regiao->crc - (int)pSrc + sizeof(UInt16)));

                return(CRC16CCITT.Calcular(dadosCRC));
            }
        }
Exemplo n.º 3
0
        public bool VerificarCRC(byte[] dados)
        {
            byte[] temp   = new byte[2];
            byte[] dados2 = new byte[(int)dados.Length];

            unsafe
            {
                fixed(byte *pSrc = dados)
                {
                    FormatoListaArquivos *vid = (FormatoListaArquivos *)pSrc;

                    dados2 = Util.Util.CalcularCRC2(dados);

                    temp[0] = dados2[Util.Util.CRCPosition1];
                    temp[1] = dados2[Util.Util.CRCPosition2];

                    return(vid->crc == BitConverter.ToUInt16(temp, 0));
                }
            }
        }
Exemplo n.º 4
0
        private byte[] toByteArray()
        {
            unsafe
            {
                Byte[] resultado = new Byte[sizeof(FormatoListaArquivos) + (this.QTDArquivos * Util.Util.ARQUIVO_LST_PATH_SIZE)];

                fixed(byte *pSrc = resultado)
                {
                    FormatoListaArquivos *listaArquivos = (FormatoListaArquivos *)pSrc;

                    paths.CopyTo(resultado, sizeof(FormatoListaArquivos));

                    listaArquivos->versao = this.versao;

                    listaArquivos->qtdArquivos = this.qtdArquivos;

                    listaArquivos->crc = this.crc;

                    return(resultado);
                }
            }
        }
Exemplo n.º 5
0
        private void FromBytesToFormatoPainelCfg(byte[] dados)
        {
            unsafe
            {
                fixed(byte *pSrc = dados)
                {
                    FormatoListaArquivos *listaArquivos = (FormatoListaArquivos *)pSrc;

                    Byte[] temporario = new byte[listaArquivos->qtdArquivos];

                    this.versao = listaArquivos->versao;

                    this.qtdArquivos = listaArquivos->qtdArquivos;

                    this.crc = listaArquivos->crc;
                    for (int i = 0; i < this.qtdArquivos; i++)
                    {
                        this.listaPaths.Add(string.Empty);
                        this.listaPaths[i] = ArrayLDX2.ByteArrayToString(pSrc + sizeof(FormatoListaArquivos) + (i * Util.Util.ARQUIVO_LST_PATH_SIZE), Util.Util.ARQUIVO_LST_PATH_SIZE);
                    }
                }
            }
        }