I want to scan only files in my app. The user can choose any file, e.g. from the download directory. Such a file can be large, and it can be any compressed file, e.g. zip, rar, etc. The virus scanner can scan the contents of such a compressed file for viruses. With the AmsiScanBuffer() function this would not be possible if only a part of the large file was passed to the function, because then the split parts of a compressed file would no longer be consistent compressed data that the AmsiScanBuffer() function could decompress.
If it is not a compressed file, you would probably have to read the file overlapping, since the virus pattern can theoretically be above the split position. So, for example, you would have to read from offset 0 to 1000 and check for viruses, then read and check from offset 900 to 1900, then from 1800 to 2800, and so on. Here you would need to know how large a virus pattern can be. Reading overlapping can be done, but what if it is a compressed file, in a format I don't know, but the virus scanner could extract it and check its contents?
I saw the AmsiScanBuffer() function, but then had the thoughts I just described and thought to myself, you need a function that can stream, and then I came across the IAmsiStream interface and its sample implementation from Microsoft, only to find after much testing that the virus scanner supports the IAmsiStream interface, but not streaming.
I think that AmsiScanBuffer(), AmsiScanString() and IAmsiStream are not primarily intended for scanning files, but for data that is in RAM and that an app has received from some stream. Large files, especially compressed files, can probably only be read and checked efficiently by the virus scanner itself. Such a feature, which is supported by all scanners, is missing to me. On the other hand, a virus scanner automatically checks every file when it is created. However, this does not apply to the contents of a compressed file. Here, the use of IAmsiStream would be justified, since it detects and checks compressed data.