public static void Ctor_Empty() { var exception = new AccessViolationException(); Assert.NotNull(exception); Assert.NotEmpty(exception.Message); Assert.Equal(COR_E_ACCESSVIOLATION, exception.HResult); }
public static void Ctor_String() { string message = "Created AccessViolationException"; var exception = new AccessViolationException(message); Assert.Equal(message, exception.Message); Assert.Equal(COR_E_ACCESSVIOLATION, exception.HResult); }
static StackObject *Ctor_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *__ret = ILIntepreter.Minus(__esp, 0); var result_of_this_method = new System.AccessViolationException(); return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; var uploads = new List<UploadFileInfo>(); var basePath = HttpContext.Current.Request.Form["path"]; if (!basePath.StartsWith(SiteSettings.Instance.FilePath)) { var exception = new AccessViolationException(string.Format("Wrong path for uploads! {0}", basePath)); Logger.Write(exception, Logger.Severity.Major); throw exception; } basePath = HttpContext.Current.Server.MapPath(basePath); foreach (string file in context.Request.Files) { var postedFile = context.Request.Files[file]; string fileName; if (postedFile.ContentLength == 0) { continue; } if (postedFile.FileName.Contains("\\")) { string[] parts = postedFile.FileName.Split(new[] {'\\'}); fileName = parts[parts.Length - 1]; } else { fileName = postedFile.FileName; } if (IsFileExtensionBlocked(fileName)) { Logger.Write(string.Format("Upload of {0} blocked since file type is not allowed.", fileName), Logger.Severity.Major); uploads.Add(new UploadFileInfo { name = Path.GetFileName(fileName), size = postedFile.ContentLength, type = postedFile.ContentType, error = "Filetype not allowed!" }); continue; } var savedFileName = GetUniqueFileName(basePath, fileName); postedFile.SaveAs(savedFileName); uploads.Add(new UploadFileInfo { name = Path.GetFileName(savedFileName), size = postedFile.ContentLength, type = postedFile.ContentType }); } var uploadResult = new UploadResult(uploads); var serializedUploadInfo = Serialization.JsonSerialization.SerializeJson(uploadResult); context.Response.Write(serializedUploadInfo); }
public static void Ctor_String_Exception() { string message = "Created AccessViolationException"; var innerException = new Exception("Created inner exception"); var exception = new AccessViolationException(message, innerException); Assert.Equal(message, exception.Message); Assert.Equal(COR_E_ACCESSVIOLATION, exception.HResult); Assert.Equal(innerException, exception.InnerException); Assert.Equal(innerException.HResult, exception.InnerException.HResult); }
public void Constructor_CallStackIsRecordedIfStackTraceNotPresent(bool? isRunningFlag) { // Arrange var noTraceException = new AccessViolationException("Manually Created, no trace"); // Act Event actEvent = null; if (isRunningFlag.HasValue) actEvent = new Event(noTraceException, isRunningFlag.Value); else actEvent = new Event(noTraceException); // Assert Assert.NotNull(actEvent.CallTrace); #if DEBUG // We can only be certain of this frame when in Debug mode. Optimisers are enabled in Release mode Assert.Equal("Constructor_CallStackIsRecordedIfStackTraceNotPresent", actEvent.CallTrace.GetFrame(0).GetMethod().Name); #endif }
// ************************************** // Download // ************************************** public virtual ActionResult Download(int id) { try { var user = Account.User(); var content = user != null ? SearchService.GetContent(id, user) : null; if (content != null) { var downloadName = String.Concat(content.UserDownloadableName, SystemConfig.MediaDefaultExtension); var contentType = "application/unknown"; Response.ContentType = contentType; //if (SystemConfig.UseRemoteMedia) { // var mediaUrl = _mediaService.GetContentMediaPath(id, MediaVersion.Full); // return base.File(mediaUrl, contentType, downloadName); //} else { byte[] media = MediaService.GetContentMedia(content.ContentMedia.FullVersion(), user); media = MediaService.WriteMediaSignature(media, content, user); return base.File(media, contentType, downloadName); //} } else { var msg = "You do not have access to this file"; this.FeedbackError(msg); var ex = new AccessViolationException(msg); Log.Error(ex); return RedirectToAction(MVC.Error.Problem()); } } catch (Exception ex) { Log.Error(ex); this.FeedbackInfo("There was an error downloading this item. Please try again in a bit."); return RedirectToAction(MVC.Search.Index()); } }
public void TestTransforException() { var msg = "Message"; var msgInner = "InnerMessage"; var exc = new AccessViolationException(msg, new ExternalException(msgInner)); try { throw exc; } catch (Exception e) { var node = (DDNode)e; CompareNodeWithException(node, e); } }
public void TestExceptionGood() { BuildRequest request = CreateNewBuildRequest(1, new string[0]); BuildResult result = new BuildResult(request); Assert.IsNull(result.Exception); AccessViolationException e = new AccessViolationException(); result = new BuildResult(request, e); Assert.AreEqual(e, result.Exception); }
private void injectMemory(int procId, byte[] buffer, out IntPtr hndProc, out IntPtr lpAddress) { // open process and get handle // hndProc = NativeMethods.OpenProcess(ProcessAccessFlags.All, true, procId); hndProc = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.All, true, procId); if (hndProc == (IntPtr)0) { AccessViolationException ex = new AccessViolationException("Unable to attach to process with an id " + procId); ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); } // allocate memory for object to be injected lpAddress = NativeMethods.VirtualAllocEx(hndProc, (IntPtr)null, (uint)buffer.Length, // AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite); NativeMethods.AllocationType.Commit | NativeMethods.AllocationType.Reserve, NativeMethods.MemoryProtection.ExecuteReadWrite); if (lpAddress == (IntPtr)0) { AccessViolationException ex = new AccessViolationException("Unable to allocate memory to proces with an id " + procId); ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); } // write data to process const uint wrotelen = 0; // uint wrotelen = 0; NativeMethods.WriteProcessMemory(hndProc, lpAddress, buffer, (uint)buffer.Length, (UIntPtr)wrotelen); if (Marshal.GetLastWin32Error() == 0) return; AccessViolationException ex2 = new AccessViolationException("Unable to write memory to process with an id " + procId); ThrowTerminatingError(new ErrorRecord(ex2, "AccessDenined", ErrorCategory.SecurityError, null)); /* if (Marshal.GetLastWin32Error() != 0) { AccessViolationException ex = new AccessViolationException("Unable to write memory to process with an id " + procId); ThrowTerminatingError(new ErrorRecord(ex, "AccessDenined", ErrorCategory.SecurityError, null)); } */ }
private static void bar() { try { var a = 1; var b = 0; a = a / b; } catch( System.Exception ex ) { var e = new AccessViolationException( "Exception bar", ex ); e.Data.Add( "Test item 1", new string[]{ "AAA","BBB","CCC" } ); e.Data.Add( "Test item 2", 12345 ); e.Data.Add( "Test EOL 1", "\n" ); e.Data.Add( "Test EOL 2", "\r\n" ); e.Data.Add( "Test EOL 3", "\n\r" ); e.Data.Add( "Test EOL 4", '\n' ); e.Data.Add( "Test EOL 5", '\r' ); e.Data.Add( "Test null", null ); throw e; } }
public void AccessViolation() { var ex = new AccessViolationException(); Assert.IsTrue(ex.IsCorruptedStateException()); }
public virtual ActionResult StreamUrl(int id, MediaVersion version = MediaVersion.Preview) { try { var contentType = "application/mp3"; Response.ContentType = contentType; var mediaUrl = GetUrl(id, version); if (mediaUrl != null){ return Redirect(mediaUrl); } else { var msg = "You do not have access to this file"; this.FeedbackError(msg); var ex = new AccessViolationException(msg); Log.Error(ex); return RedirectToAction(MVC.Error.Problem()); } } catch (Exception ex) { Log.Error(ex); this.FeedbackError("There was an error loading this page. Please try again in a bit."); return RedirectToAction(MVC.Search.Index()); } }
//// ************************************** //// Download //// ************************************** //public virtual ActionResult DownloadUrl(int id) { // try { // var contentType = "application/unknown"; // Response.ContentType = contentType; // var mediaUrl = GetUrl(id, MediaVersion.Full); // if (mediaUrl != null) { // return Redirect(mediaUrl); // } else { // var msg = "You do not have access to this file"; // this.FeedbackError(msg); // return RedirectToAction(MVC.Error.Index(new AccessViolationException(msg), msg, "Media", "Stream")); // } // } // catch { // this.FeedbackError("There was an error loading this page. Please try again in a bit."); // return RedirectToAction(MVC.Search.Index()); // } //} //// ************************************** //// Download //// ************************************** ////[OutputCache(Duration = 60, VaryByParam = "id;version")] //public virtual ActionResult Get(int id, MediaVersion version = MediaVersion.Preview) { // var user = Account.User(); // var content = SearchService.GetContent(id, user); // if (content != null) { // var downloadName = String.Concat(content.UserDownloadableName, SystemConfig.MediaDefaultExtension); // var contentType = "application/unknown"; // Response.ContentType = contentType; // if (SystemConfig.UseRemoteMedia) { // var url = GetUrl(id, version); // return base.File(url, contentType, downloadName); // } else { // var media = _mediaService.GetContentMedia(id, (MediaVersion)version, user); // return base.File(media, contentType, downloadName); // } // } else { // var msg = "You do not have access to this file"; // this.FeedbackError(msg); // return RedirectToAction(MVC.Error.Index(new AccessViolationException(msg), msg, "Media", "Download" )); // } //} // ************************************** // Stream // ************************************** //[OutputCache(Duration = 60, VaryByParam = "id;version")] public virtual ActionResult Stream(int id, MediaVersion version = MediaVersion.Preview) { try { var content = SearchService.GetContent(id, Account.User()); var contentMedia = content.ContentMedia.SingleOrDefault(x => x.MediaVersion == (int)version); if (content != null) { if (SystemConfig.UseRemoteMedia && content.IsMediaOnRemoteServer) { return RedirectToAction(Actions.StreamUrl(id, version)); } else { var mediaPath = MediaService.GetContentMediaPath(contentMedia); var contentType = "application/mp3"; Response.ContentType = contentType; return new FileStreamResult(new FileStream(mediaPath, System.IO.FileMode.Open), contentType); } } else { var msg = "You do not have access to this file"; this.FeedbackError(msg); var ex = new AccessViolationException(msg); Log.Error(ex); return RedirectToAction(MVC.Error.Problem()); } } catch (Exception ex) { Log.Error(ex); this.FeedbackError("There was an error loading this page. Please try again in a bit."); return RedirectToAction(MVC.Search.Index()); } }