This article is a mirror article of machine translation, please click here to jump to the original article.

View: 3936|Reply: 4

[Source] .NET/C# Uploads files based on byte[] in the file header

[Copy link]
Posted on 5/23/2023 10:35:24 PM | | | |
Requirements: Today I browsed an article written by a colleague before, according to "C# gets image extensions based on the first two bytes", and I have also learned about identifying file formats based on TrID.

First, the file format is obtained by reading the first 2 bytes of the file header (In fact, you can't fully trust the file header, after all, the document can be forged at will), as shown below:



TrID is a utility designed to identify file types based on binary signatures. While there are similar hard-coded logic utilities, TrID has no fixed rules. Instead, it is scalable and can be trained to recognize new formats in a fast and automated way.
View file type URLs:The hyperlink login is visible.

Or take the jpg type as an example, try to read a local QQ screenshot, Header Hexdump (The hyperlink login is visible.As shown in the figure below:



Test another file of type exe, as shown below:



The code is as follows:

The method of reading the file header can be used to easily filter whether the file type submitted by the user meets the requirementsFor example, only word documents are allowed to be uploaded, and others can change the .txt file format to .docx format and upload it to verify it???

(End)





Previous:Aspose(1)Aspose.Words populates the table into a word document
Next:.NET/C# syntax goto statement
 Landlord| Posted on 6/9/2023 10:30:06 PM |
.NET/C# Stream Read disk file memory optimization
https://www.itsvse.com/thread-10608-1-1.html
 Landlord| Posted on 9/9/2023 9:29:51 PM |
Document signature verification
The signature of a document is determined by the first few bytes in the beginning of the file. These bytes can be used to indicate whether the extension matches the file content. The sample app checks for file signatures for some common file types. In the following example, check the file signature of a JPEG image on the file:

Reference links:The hyperlink login is visible.

 Landlord| Posted on 4/24/2025 8:41:23 AM |
Online TrID File Identifier:https://mark0.net/onlinetrid.html
 Landlord| Posted on 4/24/2025 8:45:22 AM |
TrID Tool Download:The hyperlink login is visible.

Tool and Data Merging:

trid.zip (2.38 MB, Number of downloads: 0, 售价: 5 粒MB)

Test

Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com