Figure out how it is compressed? - c#

I have a archive (I know its a game compression) and I am trying to figure out how it is compressed so I can add files to it using C#. It opens/works in 7zip, and winrar. But when I use ZipForge/ComponentAce archive reference it says Invalid File.
Any help?
Steve

Have you opened the file up in a binary editor to see if the first few bytes denote the format?
For example ZIP files have the header format given on here http://www.ta7.de/txt/computer/computer016.htm
What extension does the file have?

Related

See when the zip file has been zipped?

I have googled without any luck.
My question is if there is a way to see when the file has been zipped? I am not asking for when the file has been created or modified rather to see when it has been zipped.
Is there a byte I can read from the zipped file somehow to find out this in code (C#)?
Best regards
As far as I can tell,that information is not stored in the zip file. The only info you can get is the last time that file inside the zip was modified. That datetime could or could not be the first time that file was included in the zip file.
If you want to get the last time the entry in the zip archive was changed, you can use the ZipArchiveEntry.LastWriteTime in the System.IO.Compression Namespace.
If you have any doubt of what info is availble in a zip file, you can check this wikipedia article : Zip File Format

How to identify the original file extensions or mimetype of a file

There are possibilities of an .exe file being renamed to a .txt file to bypass any file type validations. I am looking for a way to find out the actual file type by reading the header of a file without using dlls like urlmon.dll.
MimeMapping.GetMimeMapping doesn't solve the problem, it just extracts the mime type based on the extensions.
Is there a dictionary which says what combinations of bytes represents atleast the very common file types such as txt, doc, docx, pdf, xls or xlsx , an exe etc?
I think you sort of answered your own question.
This is a little bit of a pickle.
Read the file-header signature, and see if it matches that of its extension. Using a FileStream or similar.
Combine this with Tommy DDD's answer, and i think you are set.
This isn't the most elegant solution but check out this answer. How can I determine if a file is binary or text in c#? you can psudo check for if the file is binary or text.
In the comments someone checked for 4 zero bytes in a row. \0\0\0\0 which tends to indicate binary file because we don't type NULL characters too often.

C# - Checking whether byte array is a valid video file, and of what type

I am working on a system that saves temporary files in windows\temp. These files take on a .tmp file extension.
I am working on functionality that needs to read one of these files, identify whether it is an image or video file, and the filetype. Since the files are saved as .tmp, I can not use the file extension.
I've already written code that identifies whether the file is a valid image file, and it's filetype - This was actually quite easy, to my surprise!
My question is this: How can I identify whether an array of bytes is a valid video file, and if it is, how can I identify it's filetype?
As I understand, this is in general not an easy task as there are hundreds of formats. But I guess if you learn about binary signatures, or file signatures, you'll get a step forward with this question.
Here is an idea:
http://www.den4b.com/wiki/ReNamer:Binary_Signatures
And here more information:
http://en.wikipedia.org/wiki/List_of_file_signatures
Good luck :-)

How do you check a file type when there is no extension in c#

How do you check a file type when there is no extension in c#
For instance, I have files with no extension, that are either .mp4 or .flv format (just no extension). I plan on converting these video files to audio files however I would like to determine the file type before I start converting it. Is there a way to do this in C#?
I was thinking that maybe I could just rename the file to name.mp4, then perform some task on the file that would either
A) succeed, meaning that the file was indeed .mp4, or
B) fail, in which case I could then rename it to .flv
then convert the file as the appropriate extension. Is there a native process in c# that can look at .mp4 properties or .flv properties? I do not want to rename the file to .mp4 and then open it in a third party application, such as Windows Media Player, in order to see if I named it correctly.
I've heard of reading the first few bytes of a file's contents and making an educated guess at the file's format. This link seems promising:
Using .NET, how can you find the mime type of a file based on the file signature not the extension
I had played this utility (TrID - File Identifier) and seems quite accurate. File type defination package (TrIDDefs) is also up to date.
And Here is a list of file type signature table if you interest. The list is continuing work-in-process.

How to remove zip compression from an XML file?

I have an XML file format .zfo that is compressed using zip algorithm. I need to remove this compression from the file, so that it is in usable XML form. Here is the file.
How can I remove this compression, or decompress this XML file?
It's not like you might imagine i.e: .zip file containing an xml file. Instead the byte[] that's written to the file is zip compressed.
Thanks in advance.
That file isn't zip compressed at all. It appears to be some xml that's embedded in a certificate, issued by the Czech Post Office. The actual message looks to be encoded in some kind of base64 variant.
Call your post office.
Check out DotNetZip (http://www.codeplex.com/DotNetZip)--it probably does what you need (e.g., DeflateStream).
A zip file contains meta-data (file and directory structure) as well as the actually compressed data. It sounds like your file only has the compressed data. DotNetZip should be able to handle both.

Categories

Resources