IsUrwigo() публичный статический Метод

Determines whether this Lua code is from Urwigo.
public static IsUrwigo ( string lua ) : bool
lua string Lua code.
Результат bool
Пример #1
0
        /// <summary>
        /// Converts the Cartridge object in a format valid for the given engine.
        /// </summary>
        /// <remarks>
        /// - Convert Lua code
        /// - Convert strings in special format and insert any special code
        /// - Convert medias
        /// </remarks>
        /// <returns>Cartridge object in for this engine correct format.</returns>
        /// <param name="cartridge">Cartridge object to convert.</param>
        public Cartridge ConvertCartridge(Cartridge cartridge)
        {
            cartridge.Activity    = ConvertString(cartridge.Activity);
            cartridge.Name        = ConvertString(cartridge.Name);
            cartridge.Description = ConvertString(cartridge.Description);
            cartridge.StartingLocationDescription = ConvertString(cartridge.StartingLocationDescription);
            cartridge.Author       = ConvertString(cartridge.Author);
            cartridge.Company      = ConvertString(cartridge.Company);
            cartridge.TargetDevice = ConvertString(cartridge.TargetDevice);

            foreach (Media m in cartridge.Medias)
            {
                m.Resource = ConvertMedia(m);
            }

            string luaCode = cartridge.LuaCode;

            // Now make special operations with the source code for different builders
            if (Builders.IsUrwigo(cartridge.LuaCode))
            {
                luaCode = ReplaceSpecialCharacters(luaCode);
            }

            cartridge.LuaCode = ConvertCode(luaCode, cartridge.Variable);

            return(cartridge);
        }
Пример #2
0
        /// <summary>
        /// Converts the original Lua code to a plain version.
        /// </summary>
        /// <remarks>
        /// Replace all
        /// - <BR>\n with \n
        /// - <BR> with \n
        /// - long strings with only a \n with short strings containing \n
        /// This works although for Urwigo and Earwigo encoded strings.
        /// They are decoded, changed and encoded again.
        /// </remarks>
        /// <returns>The to plain.</returns>
        /// <param name="luaCode">Lua code.</param>
        static string ConvertToPlain(string luaCode)
        {
            string result = luaCode;

            // Replace all the <BR> constructions
            //			result = Regex.Replace(result, "\r\n|\n\r", "\n");
            result = result.Replace(@"<BR>\n", @"\n");
            result = result.Replace(@"\0+60BR\0+62\n", @"\n");
            result = result.Replace(@"\0+60BR\0+62\010", @"\n");
            result = result.Replace(@"\0+60BR\0+62", @"\n");

            // Replace long strings containing only a newline with a short string with a newline
            result = Regex.Replace(result, @"\[(=*)\[\n\]\1\]", "\"\\n\"");
            result = Regex.Replace(result, @"\[(=*)\[(\r\n|\n\r)\]\1\]", "\"\\n\"");

            if (Builders.IsUrwigo(result))
            {
                // Ok, it is a Lua file created by Urwigo.
                // Here we don't check, if the string is encoded or not. We assume, that this escape
                // sequences only in the code where strings are obfuscated.
                // Get the dtable of the obfuscatition function
                List <int> dtable = Builders.GetUrwigoObfuscationTable(result);
                // Get the escape sequences for <, >, BR and \n
                // This only works, if the obfuscated string is coded by escape sequences with three valid digits.
                string lt = String.Format("{0:000}", dtable.IndexOf('<'));
                string gt = String.Format("{0:000}", dtable.IndexOf('>'));
                string cr = String.Format("{0:000}", dtable.IndexOf('\r'));
                string nl = String.Format("{0:000}", dtable.IndexOf('\n'));
                string br = String.Format("{0:000}\\{1:000}", dtable.IndexOf('B'), dtable.IndexOf('R'));
                // Replace all the different occurences of <BR>
                result = Regex.Replace(result, "\\\\" + cr + "\\\\" + nl + "|" + "\\\\" + nl + "\\\\" + cr, "\\" + nl);
                result = result.Replace("\\\\" + lt + "\\\\" + br + "\\\\" + gt + "\\\\" + nl, "\\" + nl);
            }

            if (Builders.IsEarwigo(result))
            {
                // Ok, it is a Lua file created by Earwigo
                // Search for all obfuscated strings
                result = Regex.Replace(result, @"WWB_deobf\((""|')(.*?)\1\)", delegate(Match match) {
//					string encoded = match.Groups[2].Value;
//					string decoded = Builders.GetEarwigoDecodedString(encoded);
//					decoded = decoded.Replace(@"<BR>\n", @"\n");
//					decoded = decoded.Replace(@"\0+60BR\0+62\n", @"\n");
//					decoded = decoded.Replace(@"\0+60BR\0+62\010", @"\n");
//					decoded = decoded.Replace(@"\0+60BR\0+62", @"\n");
//					encoded = Builders.GetEarwigoEncodedString(decoded);
                    return(String.Format(@"WWB_deobf({0}{1}{0})", match.Groups[1].Value, match.Groups[2].Value.Replace(@"\060\001\002\062\010\003\003\003\003", @"\010")));
                }, RegexOptions.Singleline);
            }

            return(result);
        }