exe file upload prevention - c#

In my project i have created a file upload.Now it is required that any exe file or exe file in a zip folder having .zip as extension, be prevented from being uploaded.
Can someoe suggest me a solution?

For each of your task, you have to implement separate algorithm for check.
Check extension before upload (see possible duplicate question)
Check that uploaded zip is really an archive (mime type, libmagic, etc)
Check that uploaded archive doesn't contain exe (unzip it, see previous paragraph)

Related

Cannot access Zip File located in Assets folder in Windows Runtime Apps

I'm trying to get the zip file that is located inside the Assets folder of Solution Explorer with the following code. It works well for other types of file like: .txt, .jpg, .png. But it gives error when trying to get the zip file. The system cannot find the file specified.
var zipFile = await Package.Current.InstalledLocation.GetFileAsync("Assets\\Test.zip");
Zip files aren't included in the appx package by default (.txt, .jpg, and .png are). Select your file in the solution explorer, look at the zip file's properties, and make sure the build action is set to "Content" so that the file will be included in the Appx:
You can confirm that the file was (or was not) copied to the Appx after deploying from Visual Studio by looking in the (by default) \bin\x86\Release\AppX\Assets directory (or whichever architecture and configuration you deployed).

Extract .zip Archive to .jar file

I'm using System.IO and ZipFile, I was wondering if anyone could give me a snippet of code that extracts files from a .zip archive and puts them into a .jar file, or atleast helps get me started with doing something like that.
JARs are ZIPs just with a different extension, just copy and rename the file.
Jar and zip has exactly same format.
You can add meta-inf to that jar if you want to add some manifest (can be done via JarFile etc)

Adding a whole folder (with subfolders) as embedded resource?

I have an application that upon execution It copies two folders with subfolders that are in the same location to another windows location %AppData%
Now I have the following files :
MyApp.exe , Folder1, Folder2
In each folder there are subfolders. How to embed these two folders as resources inside the application so after compiling the program, I get only one executable file. And when I click on it, it extract the two folders to the same location then do the rest of job.
I know how to add a file as embedded resource then retrieve it using reflection,
but how about a folder Is that even possible??
I had to solve this problem recently. I embedded a ZIP file, and then decompressed it at runtime.
.NET 4.5 includes ZIP functionality. If not, use SharpZipLib or DotNetZip.

Running exe file with its attached file from zip without extracting

I have a video file and an exe file which only runs when both of them are in the same directory. Both video and exe files are zip compressed (.zip) and I have to write a program which would properly run exe file (and the video file it needs) without extracting them to the hard drive.
I know how to convert the contents of the zip file into streams (using dotNetZip) and run the exe file through that stream without extraction on hard (using Assembly.Load()), but I don’t know how to give the streamed video file to the exe file. Note: I don’t have access to exe file source code.
You can unzip 2 files into memory but still your exe will not be able to find the movie file, you can try to inject different code using reflection
Assuming the exe will accept the video stream as input and not just the video file - take your video stream and write it to your exe's process's StandardInput property.
If the exe does not have this capability you may have to use reflection and probe deeper into your loaded assembly to find an interface that takes a stream instead of a filename.

ZipPackage interaction with a shortcut

I have a folder structure containing a number of documents, as well as a shortcut link to another file in the folder structure. (essentially the file structure maps like a graph). If I zip up these files in Windows, the shortcut will point to the right file when the archive is uncompressed somewhere else.
Now, I want to be able to do this using the System.IO.Packaging stuff... this requires that I put the each file in a stream to tie it to the zip file. The problem is shortcut files (.lnk) apparently aren't actually files (if you do a file.exist on it, its not there). My normal method of...
System.IO.FileStream(shortcut, System.IO.FileMode.Open)
...will not work. So how would I add a shortcut to a zip package?
A ZipPackage isn't a regular Zip file, but a file meant to be used by new Office XML-based file format (docx, xlsx, etc).
If you want to zip something, you should to use another library, like #ziplib

Categories

Resources