This is as simple as it gets.
Publish the extension.
Call the method GetFileMimeTypes sending the sole input of the Binary of the file and check for the output list where you will receive a list of Name, Extension and Mime Type.
The binary file must have a minimum size in order to have magic number information.