Let $A,B \in \mathcal{M_{n}}(\mathbb{C})$. Does it always hold that $$n-\operatorname{rank}(A)=\operatorname{rank}(I_n-BA)-\operatorname{rank}(A(I_n-BA))\ ?$$
Attempt: Begin by noticing that $$\ker(A)\subseteq\operatorname{Im}(I_n-BA)$$ so $$n-\operatorname{rank}(A)\leq \operatorname{rank}(I_n-BA).$$
Also we know $$\mathrm{Im}(A(I_n-BA)) \subseteq \operatorname{Im}(I_n-BA)$$ and $$\operatorname{Im}(A(I_n-BA)) \subseteq \operatorname{Im}(A)$$ which implies $$\operatorname{rank}(A(I_n-BA)) \leq \operatorname{rank}(I_n-BA)$$ and $$\operatorname{rank}(A(I_n-BA)) \leq \operatorname{rank}(A)$$ respectively.
Using dimension theorem (rank + nullity =n), it suffices to show that $$\dim \ker(A-ABA)=\dim\ker(A)+\dim \ker(I-BA).$$ Note that $\ker(I-BA)\subset \ker(A-ABA)$, we can consider the map $$T: \ker(A-ABA)/\ker(I-BA)\to \ker(A)$$ defined by $$T(\bar x)=(I-BA)x,$$ where $\bar x=x+\ker(I-BA)$. This map is clearly well-defined and injective. It suffices to show it is surjective. But it is easy. For $y\in \ker(A)$, note that $T(\bar y)=(I-BA)y=y$, and thus $y\in \mathrm{Im}(T)$. This shows that it is surjective. We are done.