# Path: windows/generated_def/ntstatus.py
# class NtStatusException(Exception):
#     ALL_STATUS = {}
#     def __init__(self , code):
#         try:
#             x = self.ALL_STATUS[code]
#         except KeyError:
#             x = (code, 'UNKNOW_ERROR', 'Error non documented in ntstatus.py')
#         self.code = x[0]
#         self.name = x[1]
#         self.descr = x[2]
#             
#         return super(NtStatusException, self).__init__(*x)
# 
#     def __str__(self):
#         return "{e.name}(0x{e.code:x}): {e.descr}".format(e=self)
# 
#     @classmethod
#     def register_ntstatus(cls, code, name, descr):
#         if code in cls.ALL_STATUS:
#             return # Use the first def
#         cls.ALL_STATUS[code] = (code, name, descr)
# 
# Path: windows/dbgprint.py
# def get_stack_func_name(lvl):
# def do_dbgprint(msg, type=None):
# def do_nothing(*args, **kwargs):
# def parse_option(s):


import ctypes
import functools
import windows.generated_def.winfuncs as winfuncs
from ctypes.wintypes import *
from windows.generated_def.winstructs import *
from windows.generated_def.windef import *
from windows.generated_def.ntstatus import NtStatusException
from windows.dbgprint import dbgprint
    default_error_check = staticmethod(kernel32_error_check)


class IphlpapiProxy(ApiProxy):
    APIDLL = iphlpapi
    default_error_check = staticmethod(iphlpapi_error_check)


class NtdllProxy(ApiProxy):
    APIDLL = ntdll
    default_error_check = staticmethod(kernel32_zero_check)


class OptionalExport(object):
    """used 'around' a Proxy decorator
       Should be used for export that are not available everywhere (ntdll internals | 32/64 bits stuff)
       If the export is not found the function will be None

       Example:
            @OptionalExport(NtdllProxy('NtWow64ReadVirtualMemory64'))
            def NtWow64ReadVirtualMemory64(...)
            ...
    """
    def __init__(self, subdecorator):
        self.subdecorator = subdecorator

    def __call__(self, f):
        try:
            return self.subdecorator(f)
        except ExportNotFound as e:

# Path: windows/generated_def/ntstatus.py
# class NtStatusException(Exception):
#     ALL_STATUS = {}
#     def __init__(self , code):
#         try:
#             x = self.ALL_STATUS[code]
#         except KeyError:
#             x = (code, 'UNKNOW_ERROR', 'Error non documented in ntstatus.py')
#         self.code = x[0]
#         self.name = x[1]
#         self.descr = x[2]
#             
#         return super(NtStatusException, self).__init__(*x)
# 
#     def __str__(self):
#         return "{e.name}(0x{e.code:x}): {e.descr}".format(e=self)
# 
#     @classmethod
#     def register_ntstatus(cls, code, name, descr):
#         if code in cls.ALL_STATUS:
#             return # Use the first def
#         cls.ALL_STATUS[code] = (code, name, descr)
# 
# Path: windows/dbgprint.py
# def get_stack_func_name(lvl):
# def do_dbgprint(msg, type=None):
# def do_nothing(*args, **kwargs):
# def parse_option(s):


# Path: windows/winproxy.py
import ctypes
import functools
import windows.generated_def.winfuncs as winfuncs
from ctypes.wintypes import *
from windows.generated_def.winstructs import *
from windows.generated_def.windef import *
from windows.generated_def.ntstatus import NtStatusException
from windows.dbgprint import dbgprint

    default_error_check = staticmethod(kernel32_error_check)


class IphlpapiProxy(ApiProxy):
    APIDLL = iphlpapi
    default_error_check = staticmethod(iphlpapi_error_check)


class NtdllProxy(ApiProxy):
    APIDLL = ntdll
    default_error_check = staticmethod(kernel32_zero_check)


class OptionalExport(object):
    """used 'around' a Proxy decorator
       Should be used for export that are not available everywhere (ntdll internals | 32/64 bits stuff)
       If the export is not found the function will be None

       Example:
            @OptionalExport(NtdllProxy('NtWow64ReadVirtualMemory64'))
            def NtWow64ReadVirtualMemory64(...)
            ...
    """
    def __init__(self, subdecorator):
        self.subdecorator = subdecorator

    def __call__(self, f):
        try:
            return self.subdecorator(f)
        except ExportNotFound as e:

            dbgprint("Export <{e.func_name}> not found in <{e.api_name}>".format(e=e), "EXPORTNOTFOUND")