2016-07-29 21:32:06 +00:00
|
|
|
/* Benjamin DELPY `gentilkiwi`
|
2020-09-17 01:17:11 +00:00
|
|
|
https://blog.gentilkiwi.com
|
2016-07-29 21:32:06 +00:00
|
|
|
benjamin@gentilkiwi.com
|
|
|
|
Licence : https://creativecommons.org/licenses/by/4.0/
|
|
|
|
*/
|
|
|
|
#include "kull_m_rpc.h"
|
|
|
|
|
|
|
|
void __RPC_FAR * __RPC_USER midl_user_allocate(size_t cBytes)
|
|
|
|
{
|
2016-07-31 00:02:19 +00:00
|
|
|
return LocalAlloc(LPTR, cBytes);
|
2016-07-29 21:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __RPC_USER midl_user_free(void __RPC_FAR * p)
|
|
|
|
{
|
2016-07-31 00:02:19 +00:00
|
|
|
LocalFree(p);
|
2016-07-29 21:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __RPC_USER ReadFcn(void *State, char **pBuffer, unsigned int *pSize)
|
|
|
|
{
|
|
|
|
*pBuffer = (char *) ((PKULL_M_RPC_FCNSTRUCT) State)->addr;
|
|
|
|
((PKULL_M_RPC_FCNSTRUCT) State)->addr = *pBuffer + *pSize;
|
|
|
|
((PKULL_M_RPC_FCNSTRUCT) State)->size -= *pSize;
|
|
|
|
}
|
|
|
|
|
2016-07-31 00:02:19 +00:00
|
|
|
BOOL kull_m_rpc_Generic_Decode(PVOID data, DWORD size, PVOID pObject, PGENERIC_RPC_DECODE fDecode)
|
2016-07-29 21:32:06 +00:00
|
|
|
{
|
|
|
|
BOOL status = FALSE;
|
|
|
|
RPC_STATUS rpcStatus;
|
2016-07-31 00:02:19 +00:00
|
|
|
PVOID buffer;
|
|
|
|
KULL_M_RPC_FCNSTRUCT UserState;
|
2016-07-29 21:32:06 +00:00
|
|
|
handle_t pHandle;
|
|
|
|
|
2016-07-31 00:02:19 +00:00
|
|
|
if(buffer = UserState.addr = LocalAlloc(LPTR, size))
|
2016-07-29 21:32:06 +00:00
|
|
|
{
|
2016-07-31 00:02:19 +00:00
|
|
|
UserState.size = size;
|
|
|
|
RtlCopyMemory(UserState.addr, data, size); // avoid data alteration
|
|
|
|
rpcStatus = MesDecodeIncrementalHandleCreate(&UserState, ReadFcn, &pHandle);
|
2016-07-29 21:32:06 +00:00
|
|
|
if(NT_SUCCESS(rpcStatus))
|
|
|
|
{
|
2016-07-31 00:02:19 +00:00
|
|
|
rpcStatus = MesIncrementalHandleReset(pHandle, NULL, NULL, NULL, NULL, MES_DECODE);
|
|
|
|
if(NT_SUCCESS(rpcStatus))
|
|
|
|
{
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
fDecode(pHandle, pObject);
|
|
|
|
status = TRUE;
|
|
|
|
}
|
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
dprintf("[ERROR] [RPC Decode] Exception 0x%08x: (%u)\n", RpcExceptionCode(), RpcExceptionCode());
|
|
|
|
RpcEndExcept
|
|
|
|
}
|
|
|
|
else dprintf("[ERROR] [RPC Decode] MesIncrementalHandleReset: %08x\n", rpcStatus);
|
|
|
|
MesHandleFree(pHandle);
|
2016-07-29 21:32:06 +00:00
|
|
|
}
|
2016-07-31 00:02:19 +00:00
|
|
|
else dprintf("[ERROR] [RPC Decode] MesDecodeIncrementalHandleCreate: %08x\n", rpcStatus);
|
|
|
|
LocalFree(buffer);
|
2016-07-29 21:32:06 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-07-31 00:02:19 +00:00
|
|
|
void kull_m_rpc_Generic_Free(PVOID pObject, PGENERIC_RPC_FREE fFree)
|
2016-07-29 21:32:06 +00:00
|
|
|
{
|
|
|
|
RPC_STATUS rpcStatus;
|
|
|
|
KULL_M_RPC_FCNSTRUCT UserState = {NULL, 0};
|
|
|
|
handle_t pHandle;
|
|
|
|
|
|
|
|
rpcStatus = MesDecodeIncrementalHandleCreate(&UserState, ReadFcn, &pHandle); // for legacy
|
|
|
|
if(NT_SUCCESS(rpcStatus))
|
|
|
|
{
|
2016-07-31 00:02:19 +00:00
|
|
|
RpcTryExcept
|
|
|
|
fFree(pHandle, pObject);
|
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
dprintf("[ERROR] [RPC Free] Exception 0x%08x: (%u)\n", RpcExceptionCode(), RpcExceptionCode());
|
|
|
|
RpcEndExcept
|
2016-07-29 21:32:06 +00:00
|
|
|
MesHandleFree(pHandle);
|
|
|
|
}
|
|
|
|
else dprintf("[ERROR] [RPC Free] MesDecodeIncrementalHandleCreate: %08x\n", rpcStatus);
|
|
|
|
}
|