Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public static string GetFilename(string url) {
  2. string filename = url.Substring(url.LastIndexOf("/") + 1);
  3. if(filename.Contains(".")) {
  4. string extension = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
  5.  
  6. string[] blacklisted_extensions = new string[]
  7. {
  8. "exe",
  9. "msi",
  10. "msp",
  11. "msu",
  12. "p2"
  13. };
  14.  
  15. for (int i = 0; i < blacklisted_extensions.Length; i++)
  16. {
  17. if (blacklisted_extensions[i] == extension)
  18. {
  19. throw new Exception("Blacklisted extension");
  20. }
  21. }
  22.  
  23. bool found_whitelisted_extension = false;
  24. for (int i = 0; i < whitelisted_hashes.Length; i++)
  25. {
  26. if (whitelisted_hashes[i] == extension)
  27. {
  28. found_whitelisted_extension = true;
  29. break;
  30. }
  31. }
  32.  
  33. if(!found_whitelisted_extension)
  34. throw new Exception("Invalid extension");
  35. }
  36.  
  37. foreach (char oldChar in Path.GetInvalidFileNameChars())
  38. {
  39. filename = filename.Replace(oldChar, ' ');
  40. }
  41.  
  42. return filename;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement