コード例 #1
0
        private void ParseConstructors()
        {
            Regex methodRegex = new Regex(".method (?<modifiers>.*?)\\ constructor.*?\\((?<params>.*)\\)V");
            var   collection  = methodRegex.Matches(SmaliText);

            foreach (Match m in collection)
            {
                SmaliConstructor constructor = new SmaliConstructor();
                constructor.Modifiers = m.Groups["modifiers"].Value.Trim().Replace("synthetic", "/* synthetic */");
                if (constructor.Modifiers.Contains("static"))
                {
                    continue;
                }
                constructor.ClassName = this.ClassName;
                string   paramString = m.Groups["params"].Value.Trim();
                Regex    paramSplit  = new Regex("([ZBSCIJFD]|\\[[ZBSCIJFD]|L.*?;|\\[L.*?;)");
                string[] parms       = paramSplit.Split(paramString).Where(s => s != String.Empty).ToArray();
                for (var x = 0; x < parms.Length; x++)
                {
                    DecodeType(ref parms[x]);
                }

                int    endMethodLocation = SmaliText.IndexOf(".end method", m.Index);
                string methodText        = SmaliText.Substring(m.Index, endMethodLocation - m.Index);

                Regex         paramRegex   = new Regex(".param.*?,\\ \"(?<paramName>.*?)\"");
                var           paramMatches = paramRegex.Matches(methodText);
                List <string> paramNames   = new List <string>();

                foreach (Match p in paramMatches)
                {
                    paramNames.Add(p.Groups["paramName"].Value.Trim());
                }

                for (var x = 0; x < parms.Length; x++)
                {
                    SmaliParameter param = new SmaliParameter();
                    if (x >= paramNames.Count)
                    {
                        param.Name = "param" + (x + 1);
                    }
                    else
                    {
                        param.Name = paramNames[x];
                    }
                    param.Type = parms[x];
                    constructor.Parameters.Add(param);
                }
                Constructors.Add(constructor);
            }
        }
コード例 #2
0
        private void ParseMethods()
        {
            Regex methodRegex = new Regex(".method\\ (?<modifiers>.*)\\ (?<name>[a-zA-Z0-9$_]*)\\((?<params>.*)\\)(?<return>.*)");
            var   collection  = methodRegex.Matches(SmaliText);

            foreach (Match m in collection)
            {
                SmaliMethod method = new SmaliMethod();
                method.Modifiers  = m.Groups["modifiers"].Value.Trim().Replace("synthetic", "/* synthetic */");
                method.ReturnType = m.Groups["return"].Value.Trim();
                DecodeType(ref method.ReturnType);
                string paramString = m.Groups["params"].Value.Trim();
                method.MethodName = m.Groups["name"].Value.Trim();
                Regex    paramSplit = new Regex("([ZBSCIJFD]|\\[[ZBSCIJFD]|L.*?;|\\[L.*?;)");
                string[] parms      = paramSplit.Split(paramString).Where(s => s != String.Empty).ToArray();
                for (var x = 0; x < parms.Length; x++)
                {
                    DecodeType(ref parms[x]);
                }

                /* lets find the ".end-method" and then extract this string to pull out the .params */

                int    endMethodLocation = SmaliText.IndexOf(".end method", m.Index);
                string methodText        = SmaliText.Substring(m.Index, endMethodLocation - m.Index);

                Regex         paramRegex   = new Regex(".param.*?,\\ \"(?<paramName>.*?)\"");
                var           paramMatches = paramRegex.Matches(methodText);
                List <string> paramNames   = new List <string>();

                foreach (Match p in paramMatches)
                {
                    paramNames.Add(p.Groups["paramName"].Value.Trim());
                }

                for (var x = 0; x < parms.Length; x++)
                {
                    SmaliParameter param = new SmaliParameter();
                    if (x >= paramNames.Count)
                    {
                        param.Name = "param" + (x + 1);
                    }
                    else
                    {
                        param.Name = paramNames[x];
                    }
                    param.Type = parms[x];
                    method.Parameters.Add(param);
                }
                Methods.Add(method);
            }
        }