Neither word is suitable with all meanings of "to slog through".
"Sich durchschlagen" in first case means to physically work your way through something, so it would work well with your second example.
It can also be used to describe something like doing some low-level job to earn money to survive when you don't find a well-paid job in the profession you are trained and experienced in ("ich musste mich mit Gelegenheitsjobs durchschlagen").
It can, however, not be used for doing something difficult like in your first example. There is a similar word that can be used, "ich musste mich durch die Aufgabe durchbeißen" (literally "I had to byte my way through it"), but that is very colloquial und should only be used in informal speech.
"Abplagen" is usable with the first example, but it has to be used with "mit", not with "durch". It can not be used to describe the difficulty of the terrain as in your second example, though it can be used to describe a heavy object you carried on that way ("Ich musste mich durch den Wald nach Hause durchschlagen und dabei noch mit dem schweren Koffer abplagen").