Simple the companies use or hire other companies to use the p-2-p networks to see what is being shared and by whome, hence why file encryption for supposed anonymity will not work, after all why donwload an encryptied file if you can't use it there has to be a decrypter built into the client.
They can modify the clients to show the person IP, infact there are somemods that do this as some people wanted them so as to exclude IP ranges they see from certain countries. Hence why if you choose to break the law, you must accept the risk of getting caught and wither live with it or don't do it.
The actuality of the availability of the type of stuff you are talking about is rare in the extreme, and always take any filenames that say so with an extremely large pinch of salt. People who do deal with the stuff you are thinking of have no need to use the p-2-p networks at all when there are more secure ways of transfering that type of material.
By the way given the nature of this forum, even "normal" porn is illegal in some places.