X-mas CTF 2019 Emulator - Emu 2.0 Problem write -up

http://xmas.htsp.ro/

 

 

English Write-up

 

This problem is categorized as "Emulator". Following the link provided, there are a rom file and Emu2.0 spec document pdf file.

 

https://drive.google.com/drive/folders/1O2cPJq56G0APoBIAOhXuxJsXE11WCmu-?usp=sharing

 

Emu 2.0 - Google 드라이브

 

drive.google.com

Maybe rom file is binary file which can be executed the machine Emu 2.0, pdf file contains the information about the Emu 2.0 Machine.

 

This problem is actually programming challenge.

 

There is no special solution, just implementing the Emu2.0 with the pdf file specification and insert the rom data to the emulator.

 

I tried to implement Emu 2.0 machine, but I did some trial and error with some cases.

1. Instruction size of 2byte, thus hex code "2X XX" denotes, upper 4bit is opcode, the other 12bit is operand. But I misunderstood as 8bit opcode and 8bit operand. T.T

 

 

2. Endianness.

My machine is little endian. But the document assumes reader will know that it is big-endian.

I/O instruction which is mandatory to print the flag, is denoted as 13 37 itself when I check the rom binary with "xxd" command, that's why I can certain this rom is aligned as big-endian.

Then, I should program the Emu 2.0 fit to the big-endian

 

 

3. Instruction memory and data memory is combined.

I implemented both as separated ones, but something goes wrong when I executed the semi-final version Emu2.0, I re-inspect the document. 

In the memory part, it inform us that memory is unique, which can be used as instruction memory and also as data memory.

 

"including storing the instructions it needs to execute and the data it needs to process."

There is no segmentation!

 

4. Undefined Instruction

There is a sentence about the undefined instruction handling.

 

 

Conclusion => You should read document carefully. There is all you need!

 

Emulator source code is attached below.

 

한글 풀이

 

Emulator 카테고리에 있는 문제이다. 링크가 제공된 구글 드라이브로 이동해 보니, rom이라는 파일과 docs pdf 파일이 있다.

 

https://drive.google.com/drive/folders/1O2cPJq56G0APoBIAOhXuxJsXE11WCmu-?usp=sharing

 

Emu 2.0 - Google 드라이브

 

drive.google.com

 

rom 파일은 아마 에뮬레이터 스펙대로 동작하는 바이너리 파일일 것이고, pdf파일에는 에뮬레이터 작성에 필요한 정보들이 들어있을 것이다.

 

사실상 코딩문제에 가깝다고 볼 수 있다.

 

문제 풀이법은 특별한 내용은 없고, 단지 pdf에 있는 스펙대로 에뮬레이터를 작성해서 rom을 넣어버리면 된다.

 

 

직접 구현하면서 문서를 제대로 안읽어서, 혹은 이해를 제대로 안해서 몇번의 삽질을 했는데 대충 다음과 같은 부분에서 삽질을 좀 했다.

1. instruction이 2바이트인데, Hex Code가 2X XX 와같은 방식인 경우, 최상단 4bit가 Instruction opcode을 나타내고, 나머지 12bit가 operand를 나타낸다. 근데, 8bit / 8bit이 opcode / operand인줄 알고 다시 짯다.

 

2. endianness 때문에 햇갈렸었다. 근데 xxd 커맨드로 롬을 확인해보니, I/O때문에 필수적인 instruction인 13 37라는 Hex Code가 그대로 나오는 것으로 보이서, Hex code가 xxd 커맨드로 보이는 것 기준이라는 것을 알게 되었다. 따라서 little endian인 내 머신에서는 위치를 맞추어 주어야 했다.

3. Instruction Memory와 Data Memory가 따로 분리되어 있지 않았다. 맨처음에 분리해서 구현했다가, 합쳐줘야지 한다는 것을 2.2 Memory 파트를 보고 알았다.

including storing the instructions it needs to execute and the data it needs to process.

같은 메모리에 적재되어야 했다.

 

4. Undefined instruction을 어떻게 처리하느냐에 대한 내용을 구현안해서 거의 다 짜놓고도 삽질을 좀 했다.

 

 

결론은 문서를 잘 읽자! 라는 결론이 나왔다.

 

 

Flag: X-MAS{S4nt4_U5e5_An_Emu_2.0_M4ch1n3}

+ Recent posts