I'm working with a memory dump of a protected win32 program. Something causing me a lot of pain is the program being split into roughly 3,000 contiguous small segments (i.e. instead of just .text and .data). This confuses IDA and causes functions to be randomly cut off, confusing the decompiler and causing various other issues. I have tried the method from this answer, but it seems to work only through the UI, idapython refuses to merge. It also takes a long time even for one merge. I tried a variant, where I, starting with the second segment, go through the segments, deleting the current segment and resizing the previous, but while small tests seemed promising, my database was messed up after several hours of running.
How can I merge these segments into one big segment?
Note: By "contiguous" I mean that every segment after the first has a start address equal to the previous segment's end address. Also, I do not care if comments and such are lost in the merging.