Exemple #1
0
        protected unsafe void StringToProperByteStar(string strOutput, byte *lpOutBuffer, ref int rnOutLen)
        {
            // if the output is legacy, then we need to shrink it from wide to narrow
            if (m_bLegacy)
            {
                byte[] baOut = EncConverters.GetBytesFromEncoding(CodePageOutput, strOutput, true);

                if (baOut.Length > rnOutLen)
                {
                    EncConverters.ThrowError(ErrStatus.OutputBufferFull);
                }
                rnOutLen = baOut.Length;
                ECNormalizeData.ByteArrToByteStar(baOut, lpOutBuffer);
            }
            else
            {
                int nLen = strOutput.Length * 2;
                if (nLen > (int)rnOutLen)
                {
                    EncConverters.ThrowError(ErrStatus.OutputBufferFull);
                }
                rnOutLen = nLen;
                ECNormalizeData.StringToByteStar(strOutput, lpOutBuffer, rnOutLen);
            }
        }
Exemple #2
0
        protected override unsafe void DoConvert
        (
            byte *lpInBuffer,
            int nInLen,
            byte *lpOutBuffer,
            ref int rnOutLen
        )
        {
            rnOutLen = 0;
            if (!String.IsNullOrEmpty(WorkingDir))
            {
                // we need to put it *back* into a string because the StreamWriter that will
                // ultimately write to the StandardInput uses a string. Use the correct codepg.
                byte [] baDst = new byte [nInLen];
                ECNormalizeData.ByteStarToByteArr(lpInBuffer, nInLen, baDst);
                Encoding enc;
                try
                {
                    enc = Encoding.GetEncoding(this.CodePageInput);
                }
                catch
                {
                    enc = Encoding.GetEncoding(EncConverters.cnIso8859_1CodePage);
                }
                string strInput = enc.GetString(baDst);

                // call the helper that calls the exe
                string strOutput = DoExeCall(strInput);

                // if there's a response...
                if (!String.IsNullOrEmpty(strOutput))
                {
                    // ... put it in the output buffer
                    // if the output is legacy, then we need to shrink it from wide to narrow
                    // it'll be legacy either if (the direction is forward and the rhs=eLegacy)
                    // or if (the direction is reverse and the rhs=eLegacy)
                    bool bLegacyOutput =
                        (
                            ((this.DirectionForward == true) &&
                             (EncConverter.NormalizeRhsConversionType(this.ConversionType) == NormConversionType.eLegacy)
                            ) ||
                            ((this.DirectionForward == false) &&
                             (EncConverter.NormalizeLhsConversionType(this.ConversionType) == NormConversionType.eLegacy)
                            )
                        );

                    if (bLegacyOutput)
                    {
                        try
                        {
                            enc = Encoding.GetEncoding(this.CodePageOutput);
                        }
                        catch
                        {
                            enc = Encoding.GetEncoding(EncConverters.cnIso8859_1CodePage);
                        }
                        byte [] baOut = enc.GetBytes(strOutput);
                        ECNormalizeData.ByteArrToByteStar(baOut, lpOutBuffer);
                        rnOutLen = baOut.Length;
                    }
                    else
                    {
                        rnOutLen = strOutput.Length * 2;
                        ECNormalizeData.StringToByteStar(strOutput, lpOutBuffer, rnOutLen);
                    }
                }
            }
            else
            {
                EncConverters.ThrowError(ErrStatus.RegistryCorrupt);
            }
        }