예제 #1
0
        public void MultiLineDecode()
        {
            TextDecoder decoder = initDecoder();

            decoder.SetHexBlock(new byte[] { 0, 3, 1, 3, 2 });
            var decodedStrings = decoder.GetDecodedStrings("0");

            Assert.Equal(3, decodedStrings.Count());
        }
예제 #2
0
        public void NormalFixedLengthDecode()
        {
            TextDecoder decoder = initDecoder();

            decoder.SetHexBlock(new byte[] { 3, 2, 1, 0 });
            List <String> decodeResult = decoder.GetDecodedFixedLengthStrings().ToList();

            Assert.Equal(1, decodeResult.First().Length);
            Assert.Equal(4, decodeResult.Count());
        }
예제 #3
0
        public void NormalDecode(byte[] encodedString, string endString, int readBytes, string expectedString, bool stopOnUndefinedChar)
        {
            TextDecoder decoder = initDecoder();

            decoder.StopOnUndefinedCharacter = stopOnUndefinedChar;
            decoder.SetHexBlock(encodedString);
            string decodedString    = string.Empty;
            int    parsedCharacters = decoder.DecodeString(ref decodedString, endString);

            Assert.Equal(readBytes, parsedCharacters);
            Assert.Equal(expectedString, decodedString);
        }
예제 #4
0
        public void FixedLengthDecodeOffsetAndPartialCheck()
        {
            TextDecoder decoder = initDecoder();

            decoder.StringLength = 2;
            decoder.StringOffset = 3;
            decoder.SetHexBlock(new byte[] { 1, 2, 0xff, 0 });
            string results = decoder.DecodeFixedLengthString();

            Assert.Equal("st", results);
            results = decoder.DecodeFixedLengthString();
            Assert.Equal("e", results);
        }
예제 #5
0
        static void Main(string[] args)
        {
            string   romName           = string.Empty;
            string   tableName         = string.Empty;
            int      validStringLength = 5;
            string   encodingName      = "utf-8";
            string   outputName        = "output.txt";
            bool     showHelp          = false;
            Encoding encoding;

            var options = new OptionSet()
            {
                { "l|length=", "the minimum length for a valid string.  Default is 5", l => validStringLength = Convert.ToInt32(l) },
                { "e|encoding=", "the encoding of the table file (e.g. shift-jis).  Default is utf-8", e => encodingName = e },
                { "o|output=", "the name of the file to write the text to.  Default is output.txt", o => outputName = o },
                { "h|help", "show this message", h => showHelp = h != null }
            };

            List <string> unparsedOptions;

            try
            {
                unparsedOptions = options.Parse(args);
            }
            catch (OptionException ex)
            {
                Console.Write("Text Scanner");
                Console.WriteLine(ex.Message);
                Console.WriteLine("Try 'TextScanner --help' for more information");
                return;
            }

            if (showHelp)
            {
                showUsage(options);
                return;
            }

            if (unparsedOptions.Count < 2)
            {
                showUsage(options);
                return;
            }

            if (!checkFile(unparsedOptions[0], "rom"))
            {
                return;
            }

            romName = unparsedOptions[0];

            if (!checkFile(unparsedOptions[1], "table"))
            {
                return;
            }

            tableName = unparsedOptions[1];

            if (validStringLength <= 0)
            {
                Console.WriteLine("Error: Invalid string length");
                return;
            }

            try
            {
                encoding = Encoding.GetEncoding(encodingName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            var decoder = new TextDecoder();

            decoder.OpenTable(tableName, encodingName);
            decoder.SetHexBlock(File.ReadAllBytes(romName));
            decoder.StopOnUndefinedCharacter = true;
            scanFile(decoder, validStringLength, outputName, encoding);
        }