浅谈Windows CE中的未公开函数

开发
本文将介绍Windows CE中的未公开函数,包括PerformCallBack4、RegisterAPISet、QueryAPISetID、GetAPIAddress等多个函数。

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

进程的序号

【编辑推荐】

  1. WinCE编译过程的四个阶段
  2. WinCE中触摸屏驱动开发详解
  3. Windows Mobile和WinCE的区别
  4. WinCE中串口驱动及接口函数介绍
  5. WinCE中nandflash驱动开发介绍
责任编辑:彭凡 来源: 百度空间
相关推荐

2010-07-26 16:26:56

MS SQL Serv

2010-07-23 15:52:52

MS SQL Serv

2022-04-13 16:48:51

CPU网络安全

2015-05-22 11:33:08

2009-07-31 13:48:34

C# eval()函数

2009-05-28 13:39:13

Windows CE

2010-01-06 10:08:16

Boot Loader

2009-07-23 14:08:46

Windows Emb

2010-03-31 16:36:35

Windows CE

2009-08-17 09:57:00

C# Windows

2011-06-27 09:49:53

Windows CEAndroid

2011-08-01 16:52:42

Windows CE 嵌入式

2009-04-11 15:12:24

Windows CE串行通信GPS

2011-06-17 14:16:21

ListBoxWindows Pho

2009-07-31 16:06:50

成员函数构造函数C#

2010-11-08 14:47:02

Powershell函数

2010-03-17 14:21:47

Windows Emb

2011-07-14 10:58:26

JavaScript强制类型转换函数

2009-07-16 14:52:00

修改Windows C平台类型

2009-07-16 15:02:39

Windows CE平台类型
点赞
收藏

51CTO技术栈公众号