BOOL kull_m_rpc_bkrp_generic(LPCWSTR NetworkAddr, const GUID * pGuid, PVOID DataIn, DWORD dwDataIn, PVOID *pDataOut, DWORD *pdwDataOut) { BOOL status = FALSE; RPC_BINDING_HANDLE hBinding; NET_API_STATUS netStatus; PBYTE out = NULL; *pDataOut = NULL; *pdwDataOut = 0; if(kull_m_rpc_bkrp_createBinding(NetworkAddr, &hBinding)) { RpcTryExcept { netStatus = BackuprKey(hBinding, (GUID *) pGuid, (PBYTE) DataIn, dwDataIn, &out, pdwDataOut, 0); if(status = (netStatus == 0)) { if(*pDataOut = LocalAlloc(LPTR, *pdwDataOut)) RtlCopyMemory(*pDataOut, out, *pdwDataOut); MIDL_user_free(out); } else PRINT_ERROR(L"BackuprKey: 0x%08x (%u)\n", netStatus, netStatus); } RpcExcept(RPC_EXCEPTION) PRINT_ERROR(L"RPC Exception: 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept kull_m_rpc_deleteBinding(&hBinding); }
BOOL kull_m_rpc_drsr_getDCBind(RPC_BINDING_HANDLE *hBinding, GUID *NtdsDsaObjectGuid, DRS_HANDLE *hDrs) { BOOL status = FALSE; ULONG drsStatus; DRS_EXTENSIONS_INT DrsExtensionsInt;// = {0}; DRS_EXTENSIONS *pDrsExtensionsOutput = NULL; DrsExtensionsInt.cb = sizeof(DRS_EXTENSIONS_INT) - sizeof(DWORD); DrsExtensionsInt.dwFlags = DRS_EXT_GETCHGREPLY_V6 | DRS_EXT_STRONG_ENCRYPTION; RpcTryExcept { drsStatus = IDL_DRSBind(*hBinding, NtdsDsaObjectGuid, (DRS_EXTENSIONS *) &DrsExtensionsInt, &pDrsExtensionsOutput, hDrs); // to free ? if(drsStatus == 0) { if(pDrsExtensionsOutput) { if(((DRS_EXTENSIONS_INT *) pDrsExtensionsOutput)->dwFlags & (DRS_EXT_GETCHGREQ_V8 | DRS_EXT_STRONG_ENCRYPTION)) status = TRUE; else PRINT_ERROR(L"Incorrect DRS Extensions Output (%08x)\n", ((DRS_EXTENSIONS_INT *) pDrsExtensionsOutput)->dwFlags); MIDL_user_free(pDrsExtensionsOutput); } else PRINT_ERROR(L"No DRS Extensions Output\n"); if(!status) IDL_DRSUnbind(hDrs); } else PRINT_ERROR(L"IDL_DRSBind: %u\n", drsStatus); } RpcExcept(DRS_EXCEPTION) PRINT_ERROR(L"RPC Exception 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept return status; }
BOOL kull_m_rpc_Generic_Decode(PVOID data, DWORD size, PVOID pObject, PGENERIC_RPC_DECODE fDecode) { BOOL status = FALSE; RPC_STATUS rpcStatus; PVOID buffer; KULL_M_RPC_FCNSTRUCT UserState ; handle_t pHandle; if(buffer = UserState.addr = LocalAlloc(LPTR, size)) { UserState.size = size; RtlCopyMemory(UserState.addr, data, size); // avoid data alteration rpcStatus = MesDecodeIncrementalHandleCreate(&UserState, ReadFcn, &pHandle); if(NT_SUCCESS(rpcStatus)) { rpcStatus = MesIncrementalHandleReset(pHandle, NULL, NULL, NULL, NULL, MES_DECODE); if(NT_SUCCESS(rpcStatus)) { RpcTryExcept { fDecode(pHandle, pObject); status = TRUE; } RpcExcept(EXCEPTION_EXECUTE_HANDLER) PRINT_ERROR(L"RPC Exception: 0x%08x (%u)\n", RpcExceptionCode(), RpcExceptionCode()); RpcEndExcept } else PRINT_ERROR(L"MesIncrementalHandleReset: %08x\n", rpcStatus); MesHandleFree(pHandle); }
NET_API_STATUS NET_API_FUNCTION NetGetJoinInformation( LPCWSTR Server, LPWSTR *Name, PNETSETUP_JOIN_STATUS type) { NET_API_STATUS status; TRACE("NetGetJoinInformation(%s %p %p)\n", debugstr_w(Server), Name, type); if (Name == NULL || type == NULL) return ERROR_INVALID_PARAMETER; RpcTryExcept { status = NetrGetJoinInformation((LPWSTR)Server, Name, type); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
BOOL WINAPI EnumPortsW(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) { DWORD dwErrorCode; TRACE("EnumPortsW(%S, %lu, %p, %lu, %p, %p)\n", pName, Level, pPorts, cbBuf, pcbNeeded, pcReturned); // Do the RPC call RpcTryExcept { dwErrorCode = _RpcEnumPorts(pName, Level, pPorts, cbBuf, pcbNeeded, pcReturned); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { dwErrorCode = RpcExceptionCode(); ERR("_RpcEnumPorts failed with exception code %lu!\n", dwErrorCode); } RpcEndExcept; if (dwErrorCode == ERROR_SUCCESS) { // Replace relative offset addresses in the output by absolute pointers. ASSERT(Level >= 1 && Level <= 2); MarshallUpStructuresArray(cbBuf, pPorts, *pcReturned, pPortInfoMarshalling[Level]->pInfo, pPortInfoMarshalling[Level]->cbStructureSize, TRUE); } SetLastError(dwErrorCode); return (dwErrorCode == ERROR_SUCCESS); }
BOOL WINAPI GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded) { DWORD dwErrorCode; PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter; if (!pHandle) { dwErrorCode = ERROR_INVALID_HANDLE; goto Cleanup; } // Do the RPC call RpcTryExcept { dwErrorCode = _RpcGetJob(pHandle->hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { dwErrorCode = RpcExceptionCode(); ERR("_RpcGetJob failed with exception code %lu!\n", dwErrorCode); } RpcEndExcept; if (dwErrorCode == ERROR_SUCCESS) { // Replace relative offset addresses in the output by absolute pointers. _MarshallUpJobInfo(pJob, Level); } Cleanup: SetLastError(dwErrorCode); return (dwErrorCode == ERROR_SUCCESS); }
BOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command) { DWORD dwErrorCode; PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter; WINSPOOL_JOB_CONTAINER JobContainer; if (!pHandle) { dwErrorCode = ERROR_INVALID_HANDLE; goto Cleanup; } // pJobContainer->JobInfo is a union of pointers, so we can just set any element to our BYTE pointer. JobContainer.Level = Level; JobContainer.JobInfo.Level1 = (WINSPOOL_JOB_INFO_1*)pJobInfo; // Do the RPC call RpcTryExcept { dwErrorCode = _RpcSetJob(pHandle->hPrinter, JobId, &JobContainer, Command); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { dwErrorCode = RpcExceptionCode(); ERR("_RpcSetJob failed with exception code %lu!\n", dwErrorCode); } RpcEndExcept; Cleanup: SetLastError(dwErrorCode); return (dwErrorCode == ERROR_SUCCESS); }
NET_API_STATUS WINAPI NetWkstaUserSetInfo( LPWSTR reserved, DWORD level, LPBYTE buf, LPDWORD parm_err) { NET_API_STATUS status; TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n", debugstr_w(reserved), level, buf, parm_err); if (reserved != NULL) return ERROR_INVALID_PARAMETER; RpcTryExcept { status = NetrWkstaUserSetInfo(NULL, level, (LPWKSTA_USER_INFO)&buf, parm_err); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
NET_API_STATUS WINAPI NetWkstaTransportAdd( LPWSTR servername, DWORD level, LPBYTE buf, LPDWORD parm_err) { NET_API_STATUS status; TRACE("NetWkstaTransportAdd(%s, %d, %p, %p)\n", debugstr_w(servername), level, buf, parm_err); RpcTryExcept { status = NetrWkstaTransportAdd(servername, level, (LPWKSTA_TRANSPORT_INFO_0)buf, parm_err); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
NET_API_STATUS WINAPI NetUseGetInfo( LMSTR UncServerName, LMSTR UseName, DWORD Level, LPBYTE *BufPtr) { NET_API_STATUS status; TRACE("NetUseGetInfo(%s, %s, %d, %p)\n", debugstr_w(UncServerName), debugstr_w(UseName), Level, BufPtr); *BufPtr = NULL; RpcTryExcept { status = NetrUseGetInfo(UncServerName, UseName, Level, (LPUSE_INFO)BufPtr); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
NET_API_STATUS WINAPI NetScheduleJobDel( LPCWSTR ServerName, DWORD MinJobId, DWORD MaxJobId) { NET_API_STATUS status; TRACE("NetScheduleJobDel(%s, %d, %d)\n", debugstr_w(ServerName), MinJobId, MaxJobId); RpcTryExcept { status = NetrJobDel(ServerName, MinJobId, MaxJobId); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
/********************************************************************** * SetServiceStatus * * @implemented */ BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus) { DWORD dwError; TRACE("SetServiceStatus() called\n"); TRACE("hServiceStatus %lu\n", hServiceStatus); RpcTryExcept { /* Call to services.exe using RPC */ dwError = RSetServiceStatus((RPC_SERVICE_STATUS_HANDLE)hServiceStatus, lpServiceStatus); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { dwError = ScmRpcStatusToWinError(RpcExceptionCode()); } RpcEndExcept; if (dwError != ERROR_SUCCESS) { ERR("ScmrSetServiceStatus() failed (Error %lu)\n", dwError); SetLastError(dwError); return FALSE; } TRACE("SetServiceStatus() done (ret %lu)\n", dwError); return TRUE; }
/********************************************************************** * I_ScSetServiceBitsW * * Undocumented * * @implemented */ BOOL WINAPI I_ScSetServiceBitsW(SERVICE_STATUS_HANDLE hServiceStatus, DWORD dwServiceBits, BOOL bSetBitsOn, BOOL bUpdateImmediately, LPWSTR lpString) { BOOL bResult; RpcTryExcept { /* Call to services.exe using RPC */ bResult = RI_ScSetServiceBitsW((RPC_SERVICE_STATUS_HANDLE)hServiceStatus, dwServiceBits, bSetBitsOn, bUpdateImmediately, lpString); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { SetLastError(ScmRpcStatusToWinError(RpcExceptionCode())); bResult = FALSE; } RpcEndExcept; return bResult; }
/****************************************************************************** * RegisterEventSourceW [ADVAPI32.@] * Returns a registered handle to an event log * * PARAMS * lpUNCServerName [I] Server name for source * lpSourceName [I] Source name for registered handle * * RETURNS * Success: Handle * Failure: NULL */ HANDLE WINAPI RegisterEventSourceW(IN LPCWSTR lpUNCServerName, IN LPCWSTR lpSourceName) { UNICODE_STRING SourceName; IELF_HANDLE LogHandle; NTSTATUS Status; TRACE("%s, %s\n", debugstr_w(lpUNCServerName), debugstr_w(lpSourceName)); RtlInitUnicodeString(&SourceName, lpSourceName); RpcTryExcept { Status = ElfrRegisterEventSourceW((LPWSTR)lpUNCServerName, (PRPC_UNICODE_STRING)&SourceName, &EmptyStringU, 1, 1, &LogHandle); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { Status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; if (!NT_SUCCESS(Status)) { SetLastError(RtlNtStatusToDosError(Status)); return NULL; } return (HANDLE)LogHandle; }
/****************************************************************************** * DeregisterEventSource [ADVAPI32.@] * Closes a handle to the specified event log * * PARAMS * hEventLog [I] Handle to event log * * RETURNS STD */ BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog) { NTSTATUS Status; TRACE("%p\n", hEventLog); RpcTryExcept { Status = ElfrDeregisterEventSource(&hEventLog); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { Status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; if (!NT_SUCCESS(Status)) { SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } return TRUE; }
BOOL WINAPI AddJobW(HANDLE hPrinter, DWORD Level, PBYTE pData, DWORD cbBuf, PDWORD pcbNeeded) { DWORD dwErrorCode; PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter; if (!pHandle) { dwErrorCode = ERROR_INVALID_HANDLE; goto Cleanup; } // Do the RPC call RpcTryExcept { dwErrorCode = _RpcAddJob(pHandle->hPrinter, Level, pData, cbBuf, pcbNeeded); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { dwErrorCode = RpcExceptionCode(); ERR("_RpcAddJob failed with exception code %lu!\n", dwErrorCode); } RpcEndExcept; if (dwErrorCode == ERROR_SUCCESS) _MarshallUpAddJobInfo((PADDJOB_INFO_1W)pData); Cleanup: SetLastError(dwErrorCode); return (dwErrorCode == ERROR_SUCCESS); }
NET_API_STATUS WINAPI NetUseAdd( LMSTR UncServerName, DWORD Level, LPBYTE Buf, LPDWORD ParmError) { NET_API_STATUS status; TRACE("NetUseAdd(%s %d %p %p)\n", debugstr_w(UncServerName), Level, Buf, ParmError); RpcTryExcept { status = NetrUseAdd(UncServerName, Level, (LPUSE_INFO)Buf, ParmError); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
NET_API_STATUS WINAPI NetScheduleJobGetInfo( LPCWSTR ServerName, DWORD JobId, LPBYTE *PointerToBuffer) { NET_API_STATUS status; TRACE("NetScheduleJobGetInfo(%s, %d, %p)\n", debugstr_w(ServerName), JobId, PointerToBuffer); RpcTryExcept { status = NetrJobGetInfo(ServerName, JobId, (LPAT_INFO *)PointerToBuffer); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
NET_API_STATUS WINAPI NetUseDel( LMSTR UncServerName, LMSTR UseName, DWORD ForceCond) { NET_API_STATUS status; TRACE("NetUseDel(%s %s %d)\n", debugstr_w(UncServerName), debugstr_w(UseName), ForceCond); RpcTryExcept { status = NetrUseDel(UncServerName, UseName, ForceCond); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
NET_API_STATUS WINAPI NetScheduleJobAdd( LPCWSTR ServerName, LPBYTE Buffer, LPDWORD JobId) { NET_API_STATUS status; TRACE("NetScheduleJobAdd(%s, %p, %p)\n", debugstr_w(ServerName), Buffer, JobId); RpcTryExcept { status = NetrJobAdd(ServerName, (LPAT_INFO)Buffer, JobId); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
NET_API_STATUS WINAPI NetWkstaGetInfo( LPWSTR servername, DWORD level, LPBYTE *bufptr) { NET_API_STATUS status; TRACE("NetWkstaGetInfo(%s, %d, %p)\n", debugstr_w(servername), level, bufptr); if (bufptr == NULL) return ERROR_INVALID_PARAMETER; *bufptr = NULL; RpcTryExcept { status = NetrWkstaGetInfo(servername, level, (LPWKSTA_INFO)bufptr); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
HRESULT RemoteDebuggerProxy::RemoveBreakpoint( ICoreProcess* process, Address64 address ) { _ASSERT( process != NULL ); if ( process == NULL ) return E_INVALIDARG; if ( process->GetProcessType() != CoreProcess_Remote ) return E_INVALIDARG; HRESULT hr = S_OK; __try { hr = MagoRemoteCmd_RemoveBreakpoint( GetContextHandle(), process->GetPid(), address ); } __except ( CommonRpcExceptionFilter( RpcExceptionCode() ) ) { hr = HRESULT_FROM_WIN32( RpcExceptionCode() ); } return hr; }
NET_API_STATUS WINAPI NetWkstaTransportDel( LPWSTR servername, LPWSTR transportname, DWORD ucond) { NET_API_STATUS status; TRACE("NetWkstaTransportDel(%s, %s, %d)\n", debugstr_w(servername), debugstr_w(transportname), ucond); RpcTryExcept { status = NetrWkstaTransportDel(servername, transportname, ucond); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
HRESULT RemoteDebuggerProxy::Execute( ICoreProcess* process, bool handleException ) { _ASSERT( process != NULL ); if ( process == NULL ) return E_INVALIDARG; if ( process->GetProcessType() != CoreProcess_Remote ) return E_INVALIDARG; HRESULT hr = S_OK; __try { hr = MagoRemoteCmd_Execute( GetContextHandle(), process->GetPid(), handleException ); } __except ( CommonRpcExceptionFilter( RpcExceptionCode() ) ) { hr = HRESULT_FROM_WIN32( RpcExceptionCode() ); } return hr; }
HRESULT RemoteDebuggerProxy::WriteMemory( ICoreProcess* process, Address64 address, uint32_t length, uint32_t& lengthWritten, uint8_t* buffer ) { _ASSERT( process != NULL ); if ( process == NULL || buffer == NULL ) return E_INVALIDARG; if ( process->GetProcessType() != CoreProcess_Remote ) return E_INVALIDARG; HRESULT hr = S_OK; __try { hr = MagoRemoteCmd_WriteMemory( GetContextHandle(), process->GetPid(), address, length, &lengthWritten, buffer ); } __except ( CommonRpcExceptionFilter( RpcExceptionCode() ) ) { hr = HRESULT_FROM_WIN32( RpcExceptionCode() ); } return hr; }
BOOL WINAPI ScheduleJob(HANDLE hPrinter, DWORD dwJobID) { DWORD dwErrorCode; PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter; if (!pHandle) { dwErrorCode = ERROR_INVALID_HANDLE; goto Cleanup; } // Do the RPC call RpcTryExcept { dwErrorCode = _RpcScheduleJob(pHandle->hPrinter, dwJobID); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { dwErrorCode = RpcExceptionCode(); ERR("_RpcScheduleJob failed with exception code %lu!\n", dwErrorCode); } RpcEndExcept; Cleanup: SetLastError(dwErrorCode); return (dwErrorCode == ERROR_SUCCESS); }
HRESULT RemoteDebuggerProxy::StepRange( ICoreProcess* process, bool stepIn, AddressRange64 range, bool handleException ) { _ASSERT( process != NULL ); if ( process == NULL ) return E_INVALIDARG; if ( process->GetProcessType() != CoreProcess_Remote ) return E_INVALIDARG; HRESULT hr = S_OK; __try { MagoRemote_AddressRange cmdRange = { range.Begin, range.End }; hr = MagoRemoteCmd_StepRange( GetContextHandle(), process->GetPid(), stepIn, cmdRange, handleException ); } __except ( CommonRpcExceptionFilter( RpcExceptionCode() ) ) { hr = HRESULT_FROM_WIN32( RpcExceptionCode() ); } return hr; }
NET_API_STATUS WINAPI NetRemoteTOD( LPCWSTR UncServerName, LPBYTE *BufferPtr) { NET_API_STATUS status; TRACE("NetRemoteTOD(%s, %p)\n", debugstr_w(UncServerName), BufferPtr); *BufferPtr = NULL; RpcTryExcept { status = NetrRemoteTOD((SRVSVC_HANDLE)UncServerName, (LPTIME_OF_DAY_INFO *)BufferPtr); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return status; }
HRESULT GetThreadContextNoException( ICoreProcess* process, ICoreThread* thread, HCTXCMD hCtx, const ArchThreadContextSpec& spec, BYTE* contextBuf ) { HRESULT hr = S_OK; __try { uint32_t sizeRead = 0; hr = MagoRemoteCmd_GetThreadContext( hCtx, process->GetPid(), thread->GetTid(), spec.FeatureMask, spec.ExtFeatureMask, spec.Size, &sizeRead, (byte*) contextBuf ); } __except ( CommonRpcExceptionFilter( RpcExceptionCode() ) ) { hr = HRESULT_FROM_WIN32( RpcExceptionCode() ); } return hr; }
/* * @implemented */ NTSTATUS WINAPI LsaRemoveAccountRights(IN LSA_HANDLE PolicyHandle, IN PSID AccountSid, IN BOOLEAN AllRights, IN PLSA_UNICODE_STRING UserRights, IN ULONG CountOfRights) { LSAPR_USER_RIGHT_SET UserRightSet; NTSTATUS Status; TRACE("(%p,%p,%d,%p,0x%08x) stub\n", PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights); UserRightSet.Entries = CountOfRights; UserRightSet.UserRights = (PRPC_UNICODE_STRING)UserRights; RpcTryExcept { Status = LsarRemoveAccountRights((LSAPR_HANDLE)PolicyHandle, (PRPC_SID)AccountSid, AllRights, &UserRightSet); } RpcExcept(EXCEPTION_EXECUTE_HANDLER) { Status = I_RpcMapWin32Status(RpcExceptionCode()); } RpcEndExcept; return STATUS_SUCCESS; }