# [CH] Rev C 2 ###### tags:`Writeup` `Reverse` `Chinese` > [name=FlyDragon] ## Step.1 觀察 `output.txt` 以及執行程式碼 可猜測 `flag.exe` 會將flag打亂後輸出 ## Step.2 使用ghidra查看 `main()` 可以發現這個程式會讀入flag.txt、照特定的順序交換後輸出 ![](https://i.imgur.com/ZRqeAbn.png) ![](https://i.imgur.com/2i5qB2F.png) order = [5, 13, 0, 12, 1, 16, 3, 2, 8, 7, 15, 4, 6, 17, 11, 10, 9] 不過 for loop 的判斷式是 `local_20 < 0x12` 但 `order[]` 的長度只有 0x11 (少了14),所以在最後補一個零 order = [5, 13, 0, 12, 1, 16, 3, 2, 8, 7, 15, 4, 6, 17, 11, 10, 9, 0] ## Step.3 撰寫程式逆推交換順序得到flag ```py= output = list("4_e_foyeXE__ouryCs") order = [5, 13, 0, 12, 1, 16, 3, 2, 8, 7, 15, 4, 6, 17, 11, 10, 9, 0] for i in reversed(range(len(order))): temp = output[i] output[i] = output[order[i]] output[order[i]] = temp print("".join(output)) ``` {%hackmd M1bgOPoiQbmM0JRHWaYA1g %}