protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { #region Script Resource ScriptReference scriptReference = new ScriptReference(); scriptReference.Path = ConfigurationManager.AppSettings["MaintJsPath"].ToString().TrimEnd('/') + "/ScriptResources/WorkGroupInfoScriptResource.js"; string[] cultures = ConfigurationManager.AppSettings["SupportLanguages"].ToString().Split(','); scriptReference.ResourceUICultures = CommonBLL.GetCultures(cultures, scriptReference.Path); scriptManager.Scripts.Add(scriptReference); #endregion int siteID = CommonBLL.ValidateSiteID(Request); if (siteID == 0) { Response.Redirect(ConfigurationManager.AppSettings["NoAccessPage"].ToString()); } int userID = this.CurrentUser.UserID; int accessLevelID = CommonBLL.GetAccessLevelID(this.CurrentUser.AccessLevel); ValidateUserPrivileges(siteID, accessLevelID); string basePath = ConfigurationManager.AppSettings["MaintBasePath"].ToString().TrimEnd('/'); string webServicePath = ConfigurationManager.AppSettings["MaintWebServicePath"].Trim(); string imagePath = ConfigurationManager.AppSettings["MaintImagePath"].TrimEnd('/') + "/Styles/Images"; UserControls.PagerData workGroupPagerData = new UserControls.PagerData(); workGroupPagerData.PageIndex = 0; workGroupPagerData.PageSize = int.Parse(hdnWorkGroupPageSize.Value.ToString()); workGroupPagerData.CurrentPage = currentPage; workGroupPagerData.SelectMethod = "LoadWorkGroupList"; workGroupPagerData.ServicePath = webServicePath; workGroupPagerData.SiteID = siteID; workGroupPagerData.UserID = userID; workGroupPagerData.LoadControlID = btnUploadExcel.ClientID; workGroupPagerData.AccessLevelID = accessLevelID; workGroupPagerData.PageAccessRights = PageAccessRights.ToString(); if (PageAccessRights.ToString() == AccessType.FULL_ACCESS.ToString()) { uploadFile.Attributes.Add("onchange", "javascript:UploadWorkGroupInfo();return false;"); } else { btnUploadExcel.Attributes.Add("disabled", "disabled"); } sortWorkGroup.Attributes.Add("onclick", "javascript:SortByWorkGroupName('" + sortWorkGroup.ClientID + "','MasterDataName');"); Page.ClientScript.RegisterStartupScript(GetType(), "LoadWorkGroupInfo", "LoadWorkGroupInfo(" + (new JavaScriptSerializer()).Serialize(workGroupPagerData) + ",'" + basePath + "','" + imagePath + "');", true); } }
private static bool WriteProtectedAddress(IntPtr address, IntPtr value) { ProcessAccessRights rights = ProcessAccessRights.PROCESS_VM_OPERATION | ProcessAccessRights.PROCESS_VM_READ | ProcessAccessRights.PROCESS_VM_WRITE; int pid = Process.GetCurrentProcess().Id; IntPtr hHandle = IntPtr.Zero; PageAccessRights dwOldProtect = PageAccessRights.NONE; try { hHandle = NativeMethods.OpenProcess(rights, false, pid); if (hHandle == IntPtr.Zero) { return(false); } #pragma warning disable IDE0059 // Unnecessary assignment of a value if (NativeMethods.VirtualProtectEx(hHandle, address, new UIntPtr((uint)IntPtr.Size), PageAccessRights.PAGE_EXECUTE_READWRITE, out dwOldProtect) == false) #pragma warning restore IDE0059 // Unnecessary assignment of a value { return(false); } if (IntPtr.Size == 4) { address.WriteInt32(value.ToInt32()); } else { address.WriteInt64(value.ToInt64()); } NativeMethods.FlushInstructionCache(hHandle, address, new UIntPtr((uint)IntPtr.Size)); return(true); } finally { if (dwOldProtect != PageAccessRights.NONE) { NativeMethods.VirtualProtectEx(hHandle, address, new UIntPtr((uint)IntPtr.Size), dwOldProtect, out PageAccessRights _); } if (hHandle != IntPtr.Zero) { NativeMethods.CloseHandle(hHandle); } } }
byte[] OverwriteCode(IntPtr codeAddress, byte[] code) { byte[] oldCode = codeAddress.ReadBytes(code.Length); ProcessAccessRights rights = ProcessAccessRights.PROCESS_VM_OPERATION | ProcessAccessRights.PROCESS_VM_READ | ProcessAccessRights.PROCESS_VM_WRITE; PageAccessRights dwOldProtect = PageAccessRights.NONE; IntPtr hHandle = IntPtr.Zero; try { int pid = Process.GetCurrentProcess().Id; hHandle = NativeMethods.OpenProcess(rights, false, pid); if (hHandle == IntPtr.Zero) { return(null); } #pragma warning disable IDE0059 // Unnecessary assignment of a value if (NativeMethods.VirtualProtectEx(hHandle, codeAddress, new UIntPtr((uint)IntPtr.Size), PageAccessRights.PAGE_EXECUTE_READWRITE, out dwOldProtect) == false) #pragma warning restore IDE0059 // Unnecessary assignment of a value { return(null); } codeAddress.WriteBytes(code); NativeMethods.FlushInstructionCache(hHandle, codeAddress, new UIntPtr((uint)code.Length)); return(oldCode); } finally { if (dwOldProtect != PageAccessRights.NONE) { NativeMethods.VirtualProtectEx(hHandle, codeAddress, new UIntPtr((uint)IntPtr.Size), dwOldProtect, out PageAccessRights _); } if (hHandle != IntPtr.Zero) { NativeMethods.CloseHandle(hHandle); } } }
internal static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, PageAccessRights flNewProtect, out PageAccessRights lpflOldProtect);
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { #region Script Resource ScriptReference scriptReference = new ScriptReference(); scriptReference.Path = ConfigurationManager.AppSettings["MaintJsPath"].ToString().TrimEnd('/') + "/ScriptResources/MeasuringPointScriptResource.js"; string[] cultures = ConfigurationManager.AppSettings["SupportLanguages"].ToString().Split(','); scriptReference.ResourceUICultures = CommonBLL.GetCultures(cultures, scriptReference.Path); scriptManager.Scripts.Add(scriptReference); #endregion int siteID = CommonBLL.ValidateSiteID(Request); int equipmentID = 0; int fLocationID = 0; int measuringPointID = 0; string mptDataType = Request.QueryString["type"];//E : Equipment, L:Location, M: Master if (Request.QueryString["flid"] != null && Request.QueryString["flid"].Trim().Length > 0) { fLocationID = Convert.ToInt32(Request.QueryString["flid"].Trim()); } if (Request.QueryString["eid"] != null && Request.QueryString["eid"].Trim().Length > 0) { equipmentID = Convert.ToInt32(Request.QueryString["eid"].Trim()); } if (Request.QueryString["mpid"] != null && Request.QueryString["mpid"].Trim().Length > 0) { measuringPointID = Convert.ToInt32(Request.QueryString["mpid"].Trim()); } if (siteID == 0 && string.IsNullOrEmpty(mptDataType) && equipmentID < 0) { Response.Redirect(ConfigurationManager.AppSettings["NoAccessPage"].ToString()); } int userID = this.CurrentUser.UserID; int accessLevelID = CommonBLL.GetAccessLevelID(this.CurrentUser.AccessLevel); ValidateUserPrivileges(siteID, accessLevelID, mptDataType); Vegam_MaintenanceService.BasicParam basicParam = new Vegam_MaintenanceService.BasicParam(); basicParam.SiteID = siteID; basicParam.UserID = userID; basicParam.AccessLevelID = accessLevelID; string basePath = ConfigurationManager.AppSettings["MaintBasePath"].ToString().TrimEnd('/'); string webServicePath = ConfigurationManager.AppSettings["MaintWebServicePath"].Trim(); string uploaderPath = ConfigurationManager.AppSettings["uploaderPath"].ToString().Trim('/'); string restAPIPath = ConfigurationManager.AppSettings["VegamViewServicePath"].TrimEnd('/'); string measuringPointImgPath = ConfigurationManager.AppSettings["MeasuringPointImagePath"].ToString().Trim('/') + "/" + basicParam.SiteID + "/" + "Thumbnail"; string imagePath = ConfigurationManager.AppSettings["MaintImagePath"].TrimEnd('/') + "/Styles/Images/Measuring_Point.png"; UserControls.PagerData measuringPointpagerData = new UserControls.PagerData(); measuringPointpagerData.PageIndex = 0; measuringPointpagerData.PageSize = int.Parse(hdnMeasuringPointPageSize.Value.ToString()); measuringPointpagerData.CurrentPage = currentPage; measuringPointpagerData.SelectMethod = "LoadMeasuringPointList"; measuringPointpagerData.ServicePath = webServicePath; measuringPointpagerData.SiteID = siteID; measuringPointpagerData.UserID = userID; measuringPointpagerData.AccessLevelID = accessLevelID; measuringPointpagerData.PageAccessRights = PageAccessRights.ToString(); if (measuringPointpagerData.PageAccessRights == AccessType.FULL_ACCESS.ToString()) { btnSaveMeasuringPoint.Attributes.Add("onclick", "javascript:InsertOrUpdateMeasuringPointInfo(" + (new JavaScriptSerializer()).Serialize(0) + ");return false;"); } else { btnSaveMeasuringPoint.Attributes.Add("disabled", "disabled"); btnGenerateCode.Attributes.Add("disabled", "disabled"); } if (measuringPointpagerData.PageAccessRights == AccessType.FULL_ACCESS.ToString() || measuringPointpagerData.PageAccessRights == AccessType.EDIT_ONLY.ToString()) { uploadImageAccess = true; } else { uploadImageAccess = false; } //using pager for displaying master data in configure maintenance types modal popup UserControls.PagerData maintTypePagerData = new UserControls.PagerData(); maintTypePagerData.PageIndex = 0; maintTypePagerData.PageSize = int.Parse(hdnModelPageSize.Value.ToString()); maintTypePagerData.CurrentPage = currentPage; maintTypePagerData.SelectMethod = "LoadMaintTypesInfo"; maintTypePagerData.ServicePath = webServicePath; maintTypePagerData.SiteID = siteID; maintTypePagerData.UserID = userID; maintTypePagerData.AccessLevelID = accessLevelID; maintTypePagerData.PageAccessRights = PageAccessRights.ToString(); if (maintTypePagerData.PageAccessRights == AccessType.FULL_ACCESS.ToString()) { btnAddMaintType.Attributes.Add("onclick", "javascript:InsertOrUpdateMaintType(" + (new JavaScriptSerializer()).Serialize(0) + ");return false;"); } else { btnAddMaintType.Attributes.Add("disabled", "disabled"); } thMaintTypes.Attributes.Add("onclick", "javascript:SortMaintenanceTypeTabs('" + thMaintTypes.ClientID + "','MasterDataName');"); sortMeasuringPoint.Attributes.Add("onclick", "javascript:SortByMeasuringPointName('" + sortMeasuringPoint.ClientID + "','MeasuringPointName');"); Page.ClientScript.RegisterStartupScript(GetType(), "LoadMeasuringPointInfo", "LoadMeasuringPointInfo(" + (new JavaScriptSerializer()).Serialize(basicParam) + ",'" + basePath + "','" + imagePath + "','" + uploaderPath + "','" + measuringPointImgPath + "','" + restAPIPath + "','" + btnSaveMeasuringPoint.ClientID + "','" + mptDataType + "'," + equipmentID + "," + fLocationID + "," + measuringPointID + "," + (new JavaScriptSerializer()).Serialize(measuringPointpagerData) + "," + (new JavaScriptSerializer()).Serialize(maintTypePagerData) + ");", true); } }