Example #1
0
        public void KphQueryInformationDriver(
            DriverHandle driverHandle,
            DriverInformationClass driverInformationClass,
            IntPtr driverInformation,
            int driverInformationLength,
            out int returnLength
            )
        {
            byte *inData = stackalloc byte[0x14];
            int   returnLengthLocal;

            *(int *)inData          = driverHandle;
            *(int *)(inData + 0x4)  = (int)driverInformationClass;
            *(int *)(inData + 0x8)  = driverInformation.ToInt32();
            *(int *)(inData + 0xc)  = driverInformationLength;
            *(int *)(inData + 0x10) = (int)&returnLengthLocal;

            try
            {
                _fileHandle.IoControl(CtlCode(Control.KphQueryInformationDriver), inData, 0x14, null, 0);
            }
            finally
            {
                returnLength = returnLengthLocal;
            }
        }
 public ActionResult DriverInfo()
 {
     if (Session["Identity"] == null) { return RedirectToAction("login"); }
     int employee_id = int.Parse(Request.QueryString.Get("EMID"));
     Driver driver = new Driver();
     driver = new DriverHandle().GetDriverByEmployeeID(employee_id);
     ViewData["Driver"] = driver;
     return View();
 }
        public ActionResult DriverList()
        {
            if (Session["Identity"] == null) { return RedirectToAction("login"); }
            int page1 = int.Parse(Request.QueryString.Get("page"));
            string type = Request.QueryString.Get("type");
            MyPage page = new MyPage();
            if (type.Equals("search"))   //搜索类型
            {
                string NameID = Request.QueryString.Get("NameID");
                try
                {
                    int id = int.Parse(NameID);
                    Driver driver = new DriverHandle().GetDriverByEmployeeID(id);
                    List<Driver> drivers = new List<Driver>();
                    if (driver.name != null && !driver.Equals(""))
                    {
                        drivers.Add(driver);
                    }
                    ViewData["type"] = "search";
                    ViewData["drivers"] = drivers;
                    page.CurrentPage = page1;
                    page.CountPerPage = 10;
                    page.WholePage = 1;
                    ViewData["page"] = page;
                    ViewData["NameID"] = NameID;
                }
                catch
                {
                    page.CurrentPage = page1;
                    List<Employee> employees = new EmployeeHandle().GetEmployeeByNameByPage(page, NameID);
                    List<Driver> drivers = new List<Driver>();
                    ViewData["type"] = "search";
                    drivers = new DriverHandle().EmployeesToDrivers(employees);
                    ViewData["drivers"] = drivers;
                    ViewData["page"] = page;
                    ViewData["NameID"] = NameID;
                }
            }
            else
            {
                page.CurrentPage = page1;
                page.PageWidth = 10;
                page.WholePage = (int)context.getDriverPageCount(10);
                List<Driver> drivers = new DriverHandle().getDriverByPage(page);
                ViewData["type"] = "common";
                ViewData["drivers"] = drivers;
                ViewData["page"] = page;
            }

            return View();
        }
        public ActionResult EmployeeList()
        {
            if (Session["Identity"] == null) { return RedirectToAction("login"); }
            string type = Request.QueryString.Get("type");
            if (Request.QueryString.Get("subtype") != null)
            {
                Session["subtype"] = Request.QueryString.Get("subtype");
                if (Request.QueryString.Get("subtype").Equals("AddDriver"))
                {
                    Driver driver = new Driver();
                    DriverHandle driverHandler = new DriverHandle();
                    ViewData["EM_DriverHandler"] = driverHandler;
                }
            }

            MyPage page = new MyPage();
            if (type.Equals("search"))   //搜索类型
            {
                int page1 = int.Parse(Request.QueryString.Get("page"));
                string NameID = Request.QueryString.Get("NameID");
                try
                {
                    int id = int.Parse(NameID);
                    Employee employee = new EmployeeHandle().getEmployeeById(id);
                    List<Employee> employees = new List<Employee>();
                    if (employee.Name != null && !employee.Equals(""))
                    {
                        employees.Add(employee);
                    }
                    ViewData["type"] = "search";
                    ViewData["employees"] = employees;

                    page.CurrentPage = page1;
                    page.CountPerPage = 10;
                    page.WholePage = 1;
                    ViewData["page"] = page;
                    ViewData["NameID"] = NameID;
                }
                catch
                {
                    page.CurrentPage = page1;
                    List<Employee> employees = new EmployeeHandle().GetEmployeeByNameByPage(page, NameID);
                    ViewData["type"] = "search";
                    ViewData["employees"] = employees;
                    ViewData["page"] = page;
                    ViewData["NameID"] = NameID;
                }
            }
            else
            {
                int page1 = int.Parse(Request.QueryString.Get("page"));
                page.CurrentPage = page1;
                List<Employee> employees = new EmployeeHandle().GetEmployeeByPage(page);
                ViewData["type"] = "common";
                ViewData["employees"] = employees;
                ViewData["page"] = page;
            }
            return View();
        }
        public RedirectResult SaveDriver(string Driver_Condition, string Driver_LicenseID, string License_Date)
        {
            if (Session["Identity"] == null) { return Redirect("/Home/Login"); }
            try
            {
                int em_id = int.Parse(Request.QueryString.Get("EMID"));


                StringBuilder info = new StringBuilder();
                String bas = "";

                foreach (string file in Request.Files)
                {
                    HttpPostedFileBase postFile = Request.Files[file];
                    if (postFile.ContentLength == 0)
                        continue;
                    string newFilePath = Server.MapPath("/Content/picture/drivers/");
                    postFile.SaveAs(newFilePath + em_id);
                    bas = "/Content/picture/drivers/" + em_id;
                    info.AppendFormat("Upload File: {0}/r/n", postFile.FileName);
                }
                ViewData["Info"] = info;


                string photo_path = bas;
                Driver driver = new Driver();
                DriverHandle handler = new DriverHandle();
                if (handler.isDriver(em_id))
                {
                    return Redirect("DriverInfo?EMID=" + em_id);
                }
                driver = new DriverHandle().GetDriverByEmployeeID(em_id);
                int health = int.Parse(Driver_Condition);
                DateTime license_date = DateTime.Parse(License_Date);
                context.addLicense(Driver_LicenseID, license_date, driver.birthday, photo_path);
                context.addDriver(em_id, health, Driver_LicenseID);
                //             context.setDriverHealth(em_id,health);
                int result = context.setLicenseToDriver(em_id, Driver_LicenseID, license_date, driver.birthday, photo_path);
                driver = new DriverHandle().GetDriverByEmployeeID(em_id);
                ViewData["Driver"] = driver;
                return Redirect("DriverInfo?EMID=" + em_id);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return Redirect("DriverList?type=drivers&subtype=Info&page=1");
        }
 //分页转到经理页面
 public RedirectResult DeleteDriver()
 {
     if (Session["Identity"] == null) { return Redirect("/Home/Login"); }
     int employee_id = int.Parse(Request.QueryString.Get("id"));
     DriverHandle handler = new DriverHandle();
     if (handler.deleteDriver(employee_id))
     {
         return Redirect("/Home/EmployeeList?type=common&page=1");
     }
     return Redirect("/Home");
 }
Example #7
0
        private void unloadMenuItem_Click(object sender, EventArgs e)
        {
            if (!PhUtils.ShowConfirmMessage(
                    "Unload",
                    _pid != 4 ? "the selected module" : "the selected driver",
                    _pid != 4 ?
                    "Unloading a module may cause the process to crash." :
                    "Unloading a driver may cause system instability.",
                    true
                    ))
            {
                return;
            }

            if (_pid == 4)
            {
                try
                {
                    var    moduleItem  = (ModuleItem)listModules.SelectedItems[0].Tag;
                    string serviceName = null;

                    // Try to find the name of the service key for the driver by
                    // looping through the objects in the Driver directory and
                    // opening each one.
                    using (var dhandle = new DirectoryHandle("\\Driver", DirectoryAccess.Query))
                    {
                        foreach (var obj in dhandle.GetObjects())
                        {
                            try
                            {
                                using (var driverHandle = new DriverHandle("\\Driver\\" + obj.Name))
                                {
                                    if (driverHandle.GetBasicInformation().DriverStart == moduleItem.BaseAddress)
                                    {
                                        serviceName = driverHandle.GetServiceKeyName();
                                        break;
                                    }
                                }
                            }
                            catch
                            { }
                        }
                    }

                    // If we didn't find the service name, use the driver base name.
                    if (serviceName == null)
                    {
                        if (moduleItem.Name.ToLower().EndsWith(".sys"))
                        {
                            serviceName = moduleItem.Name.Remove(moduleItem.Name.Length - 4, 4);
                        }
                        else
                        {
                            serviceName = moduleItem.Name;
                        }
                    }

                    RegistryKey servicesKey =
                        Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services", true);
                    bool        serviceKeyCreated;
                    RegistryKey serviceKey;

                    // Check if the service key exists so that we don't delete it
                    // later if it does.
                    if (Array.Exists <string>(servicesKey.GetSubKeyNames(),
                                              (keyName) => (string.Compare(keyName, serviceName, true) == 0)))
                    {
                        serviceKeyCreated = false;
                    }
                    else
                    {
                        serviceKeyCreated = true;
                        // Create the service key.
                        serviceKey = servicesKey.CreateSubKey(serviceName);

                        serviceKey.SetValue("ErrorControl", 1, RegistryValueKind.DWord);
                        serviceKey.SetValue("ImagePath", "\\??\\" + moduleItem.FileName, RegistryValueKind.ExpandString);
                        serviceKey.SetValue("Start", 1, RegistryValueKind.DWord);
                        serviceKey.SetValue("Type", 1, RegistryValueKind.DWord);
                        serviceKey.Close();
                        servicesKey.Flush();
                    }

                    try
                    {
                        Windows.UnloadDriver(serviceName);
                    }
                    finally
                    {
                        if (serviceKeyCreated)
                        {
                            servicesKey.DeleteSubKeyTree(serviceName);
                        }

                        servicesKey.Close();
                    }

                    listModules.SelectedItems.Clear();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to unload the driver. Make sure Process Hacker " +
                                    "is running with administrative privileges. Error:\n\n" +
                                    ex.Message, "Process Hacker", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                try
                {
                    using (ProcessHandle phandle = new ProcessHandle(_pid,
                                                                     Program.MinProcessQueryRights | ProcessAccess.VmOperation |
                                                                     ProcessAccess.VmRead | ProcessAccess.VmWrite | ProcessAccess.CreateThread))
                    {
                        IntPtr baseAddress = ((ModuleItem)listModules.SelectedItems[0].Tag).BaseAddress;

                        phandle.SetModuleReferenceCount(baseAddress, 1);

                        ThreadHandle thread;

                        if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista))
                        {
                            // Use RtlCreateUserThread to bypass session boundaries. Since
                            // LdrUnloadDll is a native function we don't need to notify CSR.
                            thread = phandle.CreateThread(
                                Loader.GetProcedure("ntdll.dll", "LdrUnloadDll"),
                                baseAddress
                                );
                        }
                        else
                        {
                            // On XP it seems we need to notify CSR...
                            thread = phandle.CreateThreadWin32(
                                Loader.GetProcedure("kernel32.dll", "FreeLibrary"),
                                baseAddress
                                );
                        }

                        thread.Wait(1000 * Win32.TimeMsTo100Ns);

                        NtStatus exitStatus = thread.GetExitStatus();

                        if (exitStatus == NtStatus.DllNotFound)
                        {
                            if (IntPtr.Size == 8)
                            {
                                PhUtils.ShowError("Unable to find the module to unload. This may be caused " +
                                                  "by an attempt to unload a mapped file or a 32-bit module.");
                            }
                            else
                            {
                                PhUtils.ShowError("Unable to find the module to unload. This may be caused " +
                                                  "by an attempt to unload a mapped file.");
                            }
                        }
                        else
                        {
                            exitStatus.ThrowIf();
                        }

                        thread.Dispose();
                    }

                    listModules.SelectedItems.Clear();
                }
                catch (Exception ex)
                {
                    PhUtils.ShowException("Unable to unload the module", ex);
                }
            }
        }