Every item has display ID.
Every displayID has textures used set in its DBC data (in ItemDisplayInfo.dbc)
Every texture for texture item has added behind its name one of following: "_U", "_M", "_F". For example Generic_OrWr_01_Belt_LU_F and Generic_OrWr_01_Belt_LU_M. Its quite obvious that F texture is for female characters, M texture for male characters. U means unisex.
So how to achieve that some leggings will have male textures on female characters? Simple, extract both their male and female textures and replace female one by male one. So in the end you will have 2 textures, one with F, one with M, but both will be the same. You can also have only one texture with U, but I am not entirely sure what happens if you have combination of all three U, M and F in your patches, I don't know which texture would be preffered in such case. You can check that out, if you want to.