Strict Standards: Non-static method Soojung::addReferer() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/settings.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/lifthrasiir/sites/sapzil.info/soojung/settings.php:79) in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Counter.class.php on line 63

Strict Standards: Non-static method Entry::getEntry() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/entry.php on line 51

Strict Standards: Non-static method Soojung::entryIdToFilename() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Entry.class.php on line 182

Strict Standards: Non-static method Soojung::queryFilenameMatch() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Soojung.class.php on line 55
TokigunStudio3 | 블로그: 가상 함수 디스어셈블하기

내용으로 바로 넘어 가기


TokigunStudio3

228 / 3282   


더 이상 이 블로그는 운영되지 않습니다. 새 블로그로 가 주세요.

가상 함수 디스어셈블하기

2004/11/26 PM 02:25 | 개발/역공학 | 0 comments | 0 trackbacks | AllBlog: vote, to pocket

이것 때문에 잠시 삽질한 적이 있는데, 도대체 class->(class->something)(); 이런 꼴의 코드가 왜 나오는 건지 혼란을 겪었었다. 지금 생각해 보니까 가상 함수 쓰면 충분히 그럴 것이라는 생각에 한 번 가상 함수 쓴 코드 컴파일해서 살펴 보았다. 역시나 맞더만-_-; (왜 삽질한 거지 orz) 가상 함수를 쓴 코드는 대충 요렇게 생겼다고 생각하면 된다.

; 여기부터 생성자 호출 코드
lea ecx, [esp+Instance]
call Constructor
mov [esp+Instance+VFunctionOffset], offset VirtualFunctionPointer ; 인스턴스에다가 실제 가상 함수를 나타내는 포인터 저장
; 일반 함수 호출 (__thiscall)
lea ecx, [esp+Instance]
call NormalFunction
; 가상 함수 호출
mov eax, [esp+Instance+VFunctionOffset]
lea ecx, [esp+Instance]
call [eax]
; 데이터 영역에는...
VirtualFunctionPointer offset VirtualFunction

뭐 아는 사람은 알지만 가상 함수 호출할 때는 따로 가상 함수를 위한 테이블이 만들어져서 저장된다. 때문에 생성자가 호출될 때 가상 함수의 실제 위치를 가리키는 포인터가 객체에 저장되는 것이다. 한 마디로 이런 스타일의 코드 분석할 때는 꼭 생성자 확인해 봐야 한다. 쐩 -_-;

TrackBack URL: http://sapzil.info/soojung/trackback.php?blogid=224

Copyright (c) 1995-2005, Kang Seonghoon (Tokigun).