Giter VIP home page Giter VIP logo

servicecall's Introduction

ServiceCall

Interprocess communication library, providing the ability to call functions from each other.
进程间通信库,提供相互调用函数的能力.

LICENSE HitCount

Usage (用法)

提示:详细定义请参阅ServiceCall.h
Tip: For detailed definitions, please refer to ServiceCall.h

1.Initialize the service process (初始化服务进程):

//注册服务例程前必须调用, 客户端不需要.
//Must be called before registering the service program, the client does not need.
/*
 * return:
 *  STATUS_SUCCESS
		成功
		Function call succeeded
*/
NTSTATUS BSAPI ScInitializeService();

2.Register a service routine that allows external calls (注册一个允许外部调用的服务例程):

32位版本服务例程必须声明为__stdcall
32-bit version service routines must be declared as __stdcall

//注册服务例程
//Registration service routine
/*
 * return:
 *	STATUS_SUCCESS
		成功
		Function call succeeded
 *	STATUS_ACCESS_VIOLATION
		参数中包含不可访问的内存地址
		The parameter contains an inaccessible memory address
 *	STATUS_INVALID_PARAMETER_3
		参数3错误
		Parameter 3 error
 *	STATUS_OBJECT_NAME_EXISTS
		该服务例程名称已存在
		The service routine name already exists
 *	STATUS_NO_MEMORY
		无法创建新的线程
		Unable to create new thread
 *	STATUS_NOT_SUPPORTED
		没有调用初始化函数
		No initialization function called
 * 
*/
NTSTATUS BSAPI ScRegisterServiceRoutineA(
	OUT PHANDLE hServiceRoutine,
	IN LPVOID lpServiceRoutine,
	IN PSERVICE_ROUTINE_PARAMETER lpParameters,
	IN LPCSTR lpRoutineName);

NTSTATUS BSAPI ScRegisterServiceRoutineW(
	OUT PHANDLE hServiceRoutine,
	IN LPVOID lpServiceRoutine,
	IN PSERVICE_ROUTINE_PARAMETER lpParameters,
	IN LPCWSTR lpRoutineName);

3.Unregister the service routine (取消注册服务例程)

注意:成功调用后客户端的调用请求将立即失败(STATUS_UNSUCCESSFUL),服务例程立即停止,不会等待相关调用结束.
Note: The client's call request will fail(STATUS_UNSUCCESSFUL) immediately after a successful call, the service routine will stop immediately, and will not wait for the relevant call to end.

//取消注册服务例程
//Unregister the service routine
/*
 * return:
 *	STATUS_SUCCESS
		成功
		Function call succeeded
 *	STATUS_ACCESS_VIOLATION
		参数中包含不可访问的内存地址
		The parameter contains an inaccessible memory address
 *	STATUS_INVALID_PARAMETER
		参数错误
		Parameter error
 *
*/
NTSTATUS BSAPI ScUnregisterServiceRoutine(HANDLE hServiceRoutine);

4.Client call service routine (客户端调用服务例程):

指针参数将会根据自动映射到服务例程的进程空间中, 服务例程返回后会同步到客户端.
The pointer parameters will be automatically mapped to the process space of the service routine, and will be synchronized to the client after the service routine returns.

  • 指针中如果包含多级指针,需要使用WINDOWS提供的虚拟内存操作API读取和写入客户端进程,RtlClientId()函数可以获得客户端的进程句柄和进程id.
  • If the pointer contains multiple levels of pointers, you need to use the virtual memory operation API provided by WINDOWS to read and write to the client process. The RtlClientId() function can get the client's process handle and process id.
//客户端调用服务例程
//Client call service routine
/*
 * return:
 *	STATUS_SUCCESS
		成功
		Function call succeeded
 *	STATUS_ACCESS_VIOLATION
		参数中包含不可访问的内存地址
		The parameter contains an inaccessible memory address
 *	STATUS_INVALID_PARAMETER_1
		参数1错误(服务例程不存在)
		Parameter 1 error(Service routine does not exist)
 *	STATUS_INVALID_PARAMETER_2
		参数2错误
		Parameter 2 error
 *	STATUS_UNSUCCESSFUL
		与服务例程建立连接不成功,或者服务例程主动断开了连接
		Connection to service routine was unsuccessful, or the service routine actively disconnected

 * lpServiceStatus: 
	服务例程返回的状态码(用户定义).
	Service returned status code(user define).
 *
*/
NTSTATUS BSAPI ScServiceCallA(
	IN LPCSTR lpServiceName,
	IN PSERVICE_ROUTINE_PARAMETER lpParameters,
	OUT PNTSTATUS lpServiceStatus OPTIONAL);

NTSTATUS BSAPI ScServiceCallW(
	IN LPCWSTR lpServiceName,
	IN PSERVICE_ROUTINE_PARAMETER lpParameters,
	OUT PNTSTATUS lpServiceStatus OPTIONAL);

5.Query the ID of the calling client (查询调用客户端id)

//查询调用客户端id, 只能由服务例程调用, 进程句柄将在服务例程返回后失效.
//Get the id of the calling client, which can only be called by the service routine,
//	and the process handle will be invalidated after the service routine returns.
//进程句柄以查询进程信息,复制句柄,创建线程,虚拟内存操作的权限打开.
//The process handle is opened with the permission of
//	query process information, dup handle, create thread, virtual memory operation.
bool BSAPI RtlClientId(PHANDLE hClientProcess, PDWORD lpdwClientProcessId);

Test screenshots (测试截图)

alt text

servicecall's People

Contributors

bb107 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.