반응형

 

Windows 7에서는 Unicode 형태로 지원하고 있어서 문자열을 유니코드 또는 바이너리 형으로

변환하여 호출 해야 된다.

 

 

def Get_DLL_Function(self, dll, function)

        handle = kernel32.GetModuleHandleW(dll)

        if handle <= 0:
            print ("[##] GetModuleHandle False\n")
            return False

        print ("[##] \"%s\" GetModudleHandle : 0x%08x\n" % (dll, handle))

        address = kernel32.GetProcAddress(handle,function)

        if address <= 0:
            print ("[*] Error: 0x%08x." % kernel32.GetLastError())

            print ("[##] GetProcAddress \"%s\" False\n" % function)
            kernel32.CloseHandle(handle)
            return False

        print ("[##] \"%s\" GetProcAddress : 0x%08x\n" % (function, address))
        kernel32.CloseHandle(handle)
        return address

 

해당 코드는 크게 다를 것이 없다.

그러나 호출하는 과정에서 문자열을 b"..." 형태로 변환하여 사용하지 않으면 호출되지 않는다.

(u"..." 형태도 있지만 python 3.x 에서부터는 사용하지 못하고 있다.)

http://docs.python.org/3.0/whatsnew/3.0.html

 You can no longer use u"..." literals for Unicode text. However, you must use b"..." literals for binary data.

 

위 내용을 기반으로 b"..."로 변환하니 결과가 나오게 된다.

 

Get_DLL_Function("msvcrt.dll",b"printf") 

 

[결과 값]

 

[##] "msvcrt.dll" GetModudleHandle : 0x77250000

[##] "b'printf'" GetProcAddress : 0x7726c5b9 

 

이걸 얻기 위해 얼마나 삽질을 했던가...

비로소 해결을 했다.~!!!

반응형

'프로그래밍 > Python' 카테고리의 다른 글

python 3.x has_key 없어짐!!!!  (0) 2013.07.23
문자열 타입 확인  (0) 2013.07.23
Windows 7에서 GetModuleHandle 사용하기  (0) 2013.07.12
64bit debugger 만들기  (0) 2013.07.02
python thread context 보기(win7 64bit)  (2) 2013.07.02

+ Recent posts