Can I adjust my legal status even if I failed to maintain it during my stay?

///Can I adjust my legal status even if I failed to maintain it during my stay?

Generally yes, but you must still qualify for adjustmet of status.  However, if you violated the terms of a visa, like working on a student visa or being convicted of a disqualifying crime then you can’t.  Each case is unique and befor you file for adjustment of status you should have your applicated reviewed by an immigration attorney