аналог GetProcAddress

Тема в разделе "WASM.NT.KERNEL", создана пользователем sn0w, 1 май 2021.

  1. sn0w

    sn0w Active Member

    Публикаций:
    0
    Регистрация:
    27 фев 2010
    Сообщения:
    956
    призываю тебя, о великий Indy_ ! подскажи матчасти, как реализовать GetProcAddress рандомного подгруженного модуля с irql driver entry
     
  2. Indy_

    Indy_ Well-Known Member

    Публикаций:
    4
    Регистрация:
    29 апр 2011
    Сообщения:
    4.775
    sn0w,

    Код (Text):
    1. NTKERNELAPI
    2. PVOID
    3. MmGetSystemRoutineAddress (
    4.     __in PUNICODE_STRING SystemRoutineName
    5.     )
    6.  
    7. /*++
    8.  
    9. Routine Description:
    10.  
    11.     This function returns the address of the argument function pointer if
    12.     it is in the kernel or HAL, NULL if it is not.
    13.  
    14. Arguments:
    15.  
    16.     SystemRoutineName - Supplies the name of the desired routine.
    17.  
    18. Return Value:
    19.  
    20.     Non-NULL function pointer if successful.  NULL if not.
    21.  
    22. Environment:
    23.  
    24.     Kernel mode, PASSIVE_LEVEL, arbitrary process context.
     
    sn0w и Mikl___ нравится это.
  3. sn0w

    sn0w Active Member

    Публикаций:
    0
    Регистрация:
    27 фев 2010
    Сообщения:
    956
    да про неё я знаю, но мне надо с модулем, с которого экспорт
     
  4. Indy_

    Indy_ Well-Known Member

    Публикаций:
    4
    Регистрация:
    29 апр 2011
    Сообщения:
    4.775
    sn0w,

    Так в чём трудность, копипасть экспортный парсер он на си. wrk.

    Код (Text):
    1. PVOID
    2. MiLocateExportName (
    3.     IN PVOID DllBase,
    4.     IN PCHAR FunctionName
    5.     )
    6.  
    7. /*++
    8.  
    9. Routine Description:
    10.  
    11.     This function is invoked to locate a function name in an export directory.
    12.  
    13. Arguments:
    14.  
    15.     DllBase - Supplies the image base.
    16.  
    17.     FunctionName - Supplies the the name to be located.
    18.  
    19. Return Value:
    20.  
    21.     The address of the located function or NULL.
    22.  
    23. --*/
    24.  
    25. {
    26.     PVOID Func;
    27.     PULONG NameTableBase;
    28.     PUSHORT NameOrdinalTableBase;
    29.     PIMAGE_EXPORT_DIRECTORY ExportDirectory;
    30.     PULONG Addr;
    31.     ULONG ExportSize;
    32.     LONG Low;
    33.     LONG Middle;
    34.     LONG High;
    35.     LONG Result;
    36.     USHORT OrdinalNumber;
    37.  
    38.     PAGED_CODE();
    39.  
    40.     Func = NULL;
    41.  
    42.     //
    43.     // Locate the DLL's export directory.
    44.     //
    45.  
    46.     ExportDirectory = (PIMAGE_EXPORT_DIRECTORY) RtlImageDirectoryEntryToData (
    47.                                 DllBase,
    48.                                 TRUE,
    49.                                 IMAGE_DIRECTORY_ENTRY_EXPORT,
    50.                                 &ExportSize);
    51.  
    52.     if (ExportDirectory) {
    53.  
    54.         NameTableBase =  (PULONG)((PCHAR)DllBase + (ULONG)ExportDirectory->AddressOfNames);
    55.         NameOrdinalTableBase = (PUSHORT)((PCHAR)DllBase + (ULONG)ExportDirectory->AddressOfNameOrdinals);
    56.  
    57.         //
    58.         // Look in the export name table for the specified function name.
    59.         //
    60.  
    61.         Low = 0;
    62.         Middle = 0;
    63.         High = ExportDirectory->NumberOfNames - 1;
    64.  
    65.         while (High >= Low) {
    66.  
    67.             //
    68.             // Compute the next probe index and compare the export name entry
    69.             // with the specified function name.
    70.             //
    71.  
    72.             Middle = (Low + High) >> 1;
    73.             Result = strcmp(FunctionName,
    74.                             (PCHAR)((PCHAR)DllBase + NameTableBase[Middle]));
    75.  
    76.             if (Result < 0) {
    77.                 High = Middle - 1;
    78.             }
    79.             else if (Result > 0) {
    80.                 Low = Middle + 1;
    81.             }
    82.             else {
    83.                 break;
    84.             }
    85.         }
    86.  
    87.         //
    88.         // If the high index is less than the low index, then a matching table
    89.         // entry was not found.  Otherwise, get the ordinal number from the
    90.         // ordinal table and location the function address.
    91.         //
    92.  
    93.         if (High >= Low) {
    94.  
    95.             OrdinalNumber = NameOrdinalTableBase[Middle];
    96.             Addr = (PULONG)((PCHAR)DllBase + (ULONG)ExportDirectory->AddressOfFunctions);
    97.             Func = (PVOID)((ULONG_PTR)DllBase + Addr[OrdinalNumber]);
    98.  
    99.             //
    100.             // If the function address is w/in range of the export directory,
    101.             // then the function is forwarded, which is not allowed, so ignore
    102.             // it.
    103.             //
    104.  
    105.             if ((ULONG_PTR)Func > (ULONG_PTR)ExportDirectory &&
    106.                 (ULONG_PTR)Func < ((ULONG_PTR)ExportDirectory + ExportSize)) {
    107.                 Func = NULL;
    108.             }
    109.         }
    110.     }
    111.  
    112.     return Func;
    113. }
     
    sn0w нравится это.
  5. sn0w

    sn0w Active Member

    Публикаций:
    0
    Регистрация:
    27 фев 2010
    Сообщения:
    956
    о, мучас грасиас! протрезвею как посмотрю.