문제
HDD를 CD-Rom으로 인식시키기 위해서는 GetDriveTypeA의 리턴값이 무엇이 되어야 하는가
풀이
![](https://t1.daumcdn.net/cfile/tistory/99BBC3365C5FB80C05)
<그림 1> MessageBox
우선, 파일을 실행시키면 <그림 1>과 같이 메시지 창이 뜬다.
![](https://t1.daumcdn.net/cfile/tistory/999DA7365C5FB80C06)
<그림 2> Error
확인버튼을 클릭하면 <그림 2>와 같이 에러 메시지 창이 든다. 이제 x32로 열어 파일 안의 내용을 살펴보자.
![](https://t1.daumcdn.net/cfile/tistory/99C466345C5FB89102)
<그림 3> x32
EAX와 ESI를 비교하여 같지 않으면 <그림 2>와 같은 메시지가 출력됨을 볼 수 있다. 만약 두 값이 같으면 <그림 3>에서 표시 되었듯 “OK, I really think that your HD is a CD-ROM! :p” 가 출력될 것이다.
![](https://t1.daumcdn.net/cfile/tistory/994A8D345C5FB8920D)
<그림 4> Before
![](https://t1.daumcdn.net/cfile/tistory/99ADDE345C5FB8920A)
<그림 5> After
<그림 6>과 같은 메시지 박스를 출력하기 위하여 위의 <그림 4,5>에서 보다시피 같아야 넘어가는 조건문을 달라도 넘어갈 수 있도록 바꾸었다. 그 후 F8을 눌러 한줄 씩 실행해 보니 <그림 6>과 같은 메시지 박스가 출력되었다.
![](https://t1.daumcdn.net/cfile/tistory/994C3F3D5C5FB91A0B)
<그림 6> Success
하지만, 이를 출력해도 CodeEngn의 Basic1 의 문제 GetDriveTypeA의 리턴값을 구하는 것이 아니므로 다시 구조를 살펴보기로 하자.
![](https://t1.daumcdn.net/cfile/tistory/9980F4395C5FB8EC0D)
<그림 7> GetDriveTypeA
코드를 한 줄씩 실행해 보면 <그림 8>과 같이 EAX는 3 -> 1, ESI는 0 -> 3임을 볼 수 있다.
![](https://t1.daumcdn.net/cfile/tistory/99D934395C5FB8ED09)
<그림 8> Before Register
이를 참고하여 EAX와 ESI의 값이 같기 위해선 EAX값을 5로 주면 2번의 감소가 되어 ESI의 값과 동일해 진다는 것을 알 수 있다.
![](https://t1.daumcdn.net/cfile/tistory/99ACEF395C5FB8ED0A)
<그림 9> After Register
즉, GetDriveTypeA의 리턴값은 5가 되어야 함을 알 수 있다.
GetDriveTypeA 함수란?
Return code/value | Description |
DRIVE_UNKNOWN 0 | The drive type cannot be determined. |
DRIVE_NO_ROOT_DIR 1 | The root path is invalid; for example, there is no volume mounted at the specified path. |
DRIVE_REMOVABLE 2 | The drive has removable media; for example, a floppy drive, thumb drive, or flash card reader. |
DRIVE_FIXED 3 | The drive has fixed media; for example, a hard disk drive or flash drive. |
DRIVE_REMOTE 4 | The drive is a remote (network) drive. |
DRIVE_CDROM 5 | The drive is a CD-ROM drive. |