淺談Windows CE中的未公開函數

PerformCallBack4

強制令別的進程調用某個API,如果這個API是LoadLibrary的話,就相當於線程注入了,由coredll.dll提供

PerformCallBack4函數的定義:

  1. [DllImport("coredll.dll")]  
  2. public static extern uint PerformCallBack4(ref CallBackInfo CallBackInfo,  
  3. IntPtr ni_pVoid1,IntPtr ni_pVoid2,IntPtr ni_pVoid3); 

其中函數的參數CallBackInfo結構定義:

  1. public struct CallBackInfo  
  2. {  
  3. public IntPtr hProc; //遠程的目標進程  
  4. public IntPtr pfn; //指向遠程目標進程的函數地址的指針  
  5. public IntPtr pvArg0; //函數的需要的第一個參數  

而PerformCallback4的 ni_pVoid1、ni_pVoid2、ni_pVoid3爲傳遞到遠程目標進程執行函數的其它三個參數。

例子:

  1. /*-------------------------------------------------------------------  
  2.    FUNCTION: CallCoredllInProc  
  3.    PURPOSE: CallCoredllInProc uses undocumented method   
  4.     PerformCallBack4 to call exported methods from coredll.dll in   
  5.     the specified process.  
  6.    PARAMETERS:  
  7.     HANDLE p_hProcess - handle to the process, where the call should  
  8.         be made  
  9.     LPCTSTR p_pszMethodName - name of method exported from coredll,   
  10.         such as VirtualAlloc, VirtualFree, etc.  
  11.     DWORD p_dwParam1, p_dwParam2, p_dwParam3, p_dwParam4 - arguments  
  12.     DWORD * p_pdwResult - pointer to the return value  
  13.    RETURNS:  
  14.     TRUE on success, FALSE on failure  
  15. -------------------------------------------------------------------*/  
  16. BOOL CallCoredllInProc  
  17. (  
  18.     HANDLE p_hProcess,  
  19.     LPCTSTR p_pszMethodName,  
  20.     DWORD   p_dwParam1, DWORD p_dwParam2,   
  21.     DWORD   p_dwParam3, DWORD p_dwParam4,  
  22.     DWORD * p_pdwResult)  
  23. {  
  24.     HINSTANCE l_hCoreDll = NULL;  
  25.     BOOL l_bReturn = FALSE;  
  26.     __try  
  27.     {  
  28.         //Use undocumented method PerformCallBack4   
  29.         //to call method in NK.EXE.  
  30.         CALLBACKINFO CallbackInfo;  
  31.         CallbackInfo.m_hDestinationProcessHandle = p_hProcess;  
  32.         l_hCoreDll = LoadLibrary(_T("COREDLL"));  
  33.         CallbackInfo.m_pFunction =   
  34.             (FARPROC)GetProcAddress(l_hCoreDll, p_pszMethodName);  
  35.         if(!CallbackInfo.m_pFunction)  
  36.         {  
  37.             /*HTRACE(TG_Error,   
  38.                 _T("GetProcAddress(%x, %s) failed. Err %d"),   
  39.                 l_hCoreDll, p_pszMethodName, GetLastError());  
  40.             */  
  41.         }  
  42.         else  
  43.         {  
  44.             CallbackInfo.m_pFirstArgument = (LPVOID)p_dwParam1;  
  45.             DWORD l_dwResult = PerformCallBack4 
  46.                 (&CallbackInfo, p_dwParam2, p_dwParam3, p_dwParam4);  
  47.             if(p_pdwResult)  
  48.             {  
  49.                 *p_pdwResult = l_dwResult;  
  50.             }  
  51.             l_bReturn = TRUE;  
  52.         }  
  53.     }  
  54.     __except(1)  
  55.     {  
  56.         /*  
  57.         HTRACE(TG_Error, _T("Exception in CallCoredllInProc(%s)"),   
  58.             p_pszMethodName);  
  59.         */  
  60.         l_bReturn = FALSE;  
  61.     }  
  62.     if(l_hCoreDll)  
  63.     {  
  64.         FreeLibrary(l_hCoreDll);  
  65.     }  
  66.     return l_bReturn;  
  67. }//BOOL CallCoredllInProc 

CreateAPISet

CE6.0以前是個未公開API,不過6.0以後就公開了

This function creates an API set from the list of functions passed as a parameter.

Syntax

  1. HANDLE CreateAPISet(  
  2. char acName[4],  
  3. USHORT cFunctions,  
  4. const PFNVOID *ppfnMethods,  
  5. const ULONGLONG *pu64Sig  
  6. );  
  7. Parameters   
  8. acName   
  9. [in] Name of the API set.  
  10.  
  11. cFunctions   
  12. [in] Number of functions for this API set.  
  13.  
  14. ppfnMethods   
  15. [in] Array of functions for the API set.  
  16.  
  17. pu64Sig   
  18. [in] Array of signatures for the functions.  
  19.  
  20.  
  21. Return Value   
  22. A handle to the API set.  
  23.  
  24. Remarks   
  25. Before any process can become a handle server, the process must create and register a handle-based API set with this function and RegisterAPISet.  
  26.  
  27. Requirements   
  28. Header pkfuncs.h   
  29. Library coredll.lib   
  30. Windows Embedded CE Windows Embedded CE 6.0 and later  

CE6.0以前在coredll.dll裏面有這個函數


RegisterAPISet

CE6.0以前是個未公開API,不過6.0以後就公開了

This function registers an API set.

Syntax

  1. BOOL RegisterAPISet(  
  2. HANDLE hASet,  
  3. DWORD dwSetID  
  4. );  
  5.  
  6. Parameters   
  7. hASet   
  8. [in] Handle to API set created by the CreateAPISet function.  
  9.  
  10. dwSetID   
  11. [in] Type of API set. You must perform a bitwise OR operation on this parameter with REGISTER_APISET_TYPE to create a handle-based API set.  
  12.  
  13. Return Value   
  14. TRUE indicates success. FALSE indicates failure. Call GetLastError to get extended error information.  
  15.  
  16. Remarks   
  17. Before any process can become a handle server, the process must create and register a handle-based API set with CreateAPISet and RegisterAPISet.  
  18.  
  19. Requirements   
  20. Header pkfuncs.h   
  21. Library coredll.lib   
  22. Windows Embedded CE Windows Embedded CE 6.0 and later  

CE6.0以前在coredll.dll裏面有這個函數

QueryAPISetID

根據名字查詢該API的ID,由coredll.dll提供

Syntax

  1. int QueryAPISetID(  
  2. char *pName  
  3. );  
  4.  
  5. Parameters  
  6. pName   
  7. [in] API的名字  
  8.  
  9. Return Value   
  10. API的ID 

GetAPIAddress
獲取特定API的特定Method的地址,由coredll.dll提供

  1. FARPROC GetAPIAddress(  
  2. int setId,  
  3. int iMethod  
  4. );  
  5.  
  6. Parameters   
  7. setId   
  8. [in] API的ID  
  9.  
  10. iMethod   
  11. [in] Method的ID  
  12.  
  13. Return Value   
  14. 該Method的地址 

GetProcessIndexFromID

根據進程的ID計算出進程的序號(這個序號就是進程處於第幾個slot),由coredll.dll提供

Syntax

  1. DWORD GetProcessIndexFromID(  
  2. HANDLE hProc  
  3. ); 

Parameters

hProc

[in] 進程的句柄,這裏爲什麼不是進程的ID而是進程的句柄呢?非常簡單,因爲在CE中進程的句柄就是進程的ID!

Return Value

進程的序號

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章