Running exe file with its attached file from zip without extracting - c#

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.

Related

How to open a resource pdf file in its native browser from within a c# application?

I have a pdf file for example C:\myfile.Pdf
Currently I can launch the file from C# code using
System.Diagnostics.Process.Start("C:\myfile.pdf")
However i will prefer to embed this file as a resource.
How do i accomplish the same result.
Process.Start(new ProcessStartInfo(nameof(MyNamespace.Properties.Resources.myfile)));//This will not work
If I copy the pdf file into the projects Bin\Release folder then I can simply use the same line of code above.

Accessing StreamingAssets resources from C++ DLL in Unity on Android

I have developed a C# application in Unity for Android. Additionally, I built a custom external C++ DLL which is properly loaded and accessible from the C# code. I have also added some .xml files into the StreamingAssets folder which works as expected as I can see those files loaded into the .apk.
Currently my problem is that I'm not able to access such xml files from my C++ library. On one hand I'm not sure how to do it correctly, on the other I tried multiple unsuccessful approaches including trying to understand in which cwd was my DLL loaded and then navigate to the files I needed (which didn't work as I constantly receive an access denied error).
EDIT:
Your replies actually put me on the right track and I solved the issue as follow:
During the OnStart() phase of my application, I use the UnityWebRequest class to extract from the JAR file the required files and then I save them in the Application.persistentDataPath
After that, I pass to my DLL the new path to each file which allows me to access them without any issue.
On Android the StreamingAssets are in a jar. That may well be the reason why you can't access them, but as you can see in the manual you can use the WWW class to retrieve files there.
On Android, the files are contained within a compressed .jar file
(which is essentially the same format as standard zip-compressed
files). This means that if you do not use Unity’s WWW class to
retrieve the file, you need to use additional software to see inside
the .jar archive and obtain the file.
(https://docs.unity3d.com/Manual/StreamingAssets.html)
On Android, the files are contained within a compressed .jar file
(which is essentially the same format as standard zip-compressed
files). This means that if you do not use Unity’s WWW class to
retrieve the file, you need to use additional software to see inside
the .jar archive and obtain the file.
A JAR is a package file format typically used to aggregate many Java class files and associated metadata and resources into one file for distribution. JAR files are archive files that include a Java-specific manifest file. They are built on the ZIP format and typically have a .jar file extension.
This means that you can work with jar files the same way as you do with zip files.
There is a fork for minizip with examples on how to use it.

How to compile batch file with resources to exe and run it with its exe in C#?

I have batch file and a folder with resources which include one executable file. This file in its turn uses these resources. I want to compile these resources (batch file, executable file and folder with resources) to one executable one. And after launch of this exe, my batch file inside should run with all the ensuing consequences.
I'd like to make it on C#. What should I begin with?
If you want to do it exactly as stated then a reasonable approach would be to package all your resources into one zip file, embed it as a binary resource in your C# executable and have the executable extract the resource, unzip the file into a temporary directory and run it from there with Process.Create.
#Jon's answer is correct, but you can save yourself the coding entirely - that's what self extractors do. Check out the WinZip Self Extractor for instance. It can do exactly what you want.

exe file upload prevention

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)

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