void Scm_FlushUnsafe(ScmPort *p) #endif { VMDECL; SHORTCUT(p, Scm_FlushUnsafe(p); return); WALKER_CHECK(p); LOCK(p); CLOSE_CHECK(p); switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: SAFE_CALL(p, bufport_flush(p, 0, TRUE)); UNLOCK(p); break; case SCM_PORT_OSTR: UNLOCK(p); break; case SCM_PORT_PROC: SAFE_CALL(p, p->src.vt.Flush(p)); UNLOCK(p); break; default: UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_OUTPUT, "bad port type for output: %S", p); } }
int Scm_CharReadyUnsafe(ScmPort *p) #endif { int r = 0; VMDECL; SHORTCUT(p, return Scm_CharReadyUnsafe(p)); if (!SCM_IPORTP(p)) Scm_Error("input port required, but got %S", p); LOCK(p); if (p->ungotten != SCM_CHAR_INVALID) r = TRUE; else { switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: if (p->src.buf.current < p->src.buf.end) r = TRUE; else if (p->src.buf.ready == NULL) r = TRUE; else { SAFE_CALL(p, r = (p->src.buf.ready(p) != SCM_FD_WOULDBLOCK)); } break; case SCM_PORT_PROC: SAFE_CALL(p, r = p->src.vt.Ready(p, TRUE)); break; default: r = TRUE; } } UNLOCK(p); return r; }
void Scm_PutbUnsafe(ScmByte b, ScmPort *p) #endif { VMDECL; SHORTCUT(p, Scm_PutbUnsafe(b, p); return); WALKER_CHECK(p); LOCK(p); CLOSE_CHECK(p); switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: if (p->src.buf.current >= p->src.buf.end) { SAFE_CALL(p, bufport_flush(p, (int)(p->src.buf.current - p->src.buf.buffer), FALSE)); } SCM_ASSERT(p->src.buf.current < p->src.buf.end); *p->src.buf.current++ = b; if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_NONE) { SAFE_CALL(p, bufport_flush(p, 1, FALSE)); } UNLOCK(p); break; case SCM_PORT_OSTR: SCM_DSTRING_PUTB(&p->src.ostr, b); UNLOCK(p); break; case SCM_PORT_PROC: SAFE_CALL(p, p->src.vt.Putb(b, p)); UNLOCK(p); break; default: UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_OUTPUT, "bad port type for output: %S", p); } }
KVOID Kylin::PhyX::PhysicalSystem::Tick( KFLOAT fElapsed ) { if (!m_bEnable) return; SAFE_CALL(m_pMotionSimulator,Tick(fElapsed)); SAFE_CALL(m_pCollisionMonitor,Tick(fElapsed)); SAFE_CALL(m_pCoverMonitor,Tick(fElapsed)); }
Kylin::PhyX::PhysicalSystem::~PhysicalSystem() { SAFE_CALL(m_pMotionSimulator,Destroy()); SAFE_DEL(m_pMotionSimulator); //------------------------------------------------------------------------- SAFE_CALL(m_pCollisionMonitor,Destroy()); SAFE_DEL(m_pCollisionMonitor); //------------------------------------------------------------------------- SAFE_CALL(m_pCoverMonitor,Destroy()); SAFE_DEL(m_pCoverMonitor); }
KVOID Kylin::Scene::Tick( KFLOAT fElapsed ) { SAFE_CALL(m_pEventManager,HandleEvents(fElapsed)); SAFE_CALL(m_pEntityManager,Tick(fElapsed)); if (PhyX::PhysicalSystem::Initialized()) PhyX::PhysicalSystem::GetSingletonPtr()->Tick(fElapsed); if (OgreOggSound::OgreOggSoundManager::getSingletonPtr()) OgreOggSound::OgreOggSoundManager::getSingletonPtr()->update(fElapsed); SAFE_CALL(m_pSceneLoader,Tick(fElapsed)); }
int Scm_GetzUnsafe(char *buf, int buflen, ScmPort *p) #endif { VMDECL; SHORTCUT(p, return Scm_GetzUnsafe(buf, buflen, p)); LOCK(p); CLOSE_CHECK(p); if (p->scrcnt) { int r = GETZ_SCRATCH(buf, buflen, p); UNLOCK(p); return r; } if (p->ungotten != SCM_CHAR_INVALID) { p->scrcnt = SCM_CHAR_NBYTES(p->ungotten); SCM_CHAR_PUT(p->scratch, p->ungotten); p->ungotten = SCM_CHAR_INVALID; int r = GETZ_SCRATCH(buf, buflen, p); UNLOCK(p); return r; } switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: { int siz = 0; SAFE_CALL(p, siz = bufport_read(p, buf, buflen)); p->bytes += siz; UNLOCK(p); if (siz == 0) return EOF; else return siz; } case SCM_PORT_ISTR: { int r = GETZ_ISTR(p, buf, buflen); p->bytes += r; UNLOCK(p); return r; } case SCM_PORT_PROC: { int r = 0; SAFE_CALL(p, r = p->src.vt.Getz(buf, buflen, p)); p->bytes += r; UNLOCK(p); return r; } default: UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_INPUT, "bad port type for input: %S", p); } return -1; /* dummy */ }
static int getc_scratch_unsafe(ScmPort *p) #endif { char tbuf[SCM_CHAR_MAX_BYTES]; int nb = SCM_CHAR_NFOLLOWS(p->scratch[0]); int curr = p->scrcnt; memcpy(tbuf, p->scratch, curr); p->scrcnt = 0; for (int i=curr; i<=nb; i++) { int r = EOF; SAFE_CALL(p, r = Scm_Getb(p)); if (r == EOF) { UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_INPUT, "encountered EOF in middle of a multibyte character from port %S", p); } tbuf[i] = (char)r; } int ch; SCM_CHAR_GET(tbuf, ch); if (ch == SCM_CHAR_INVALID) { /* This can happen if the input contains invalid byte sequence. We return the stray byte (which would eventually result an incomplete string when accumulated), while keeping the remaining bytes in the scrach buffer. */ ch = (ScmChar)(tbuf[0] & 0xff); memcpy(p->scratch, tbuf+1, nb); p->scrcnt = nb; } return ch; }
NTSTATUS ProcessCore::Init() { // Detect x86 OS SYSTEM_INFO info = {{0}}; GetNativeSystemInfo(&info); if(info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) { _native.reset(new x86Native(_hProcess)); } else { // Detect wow64 barrier BOOL wowSrc = FALSE; IsWow64Process(GetCurrentProcess(), &wowSrc); if(wowSrc == TRUE) _native.reset(new NativeWow64(_hProcess)); else _native.reset(new Native(_hProcess)); } // Get DEP info // For native x64 processes DEP is always enabled if(_native->GetWow64Barrier().targetWow64 == false) { _dep = true; } else { DWORD flags = 0; BOOL perm = 0; if(SAFE_CALL(GetProcessDEPPolicy, _hProcess, &flags, &perm)) _dep = (flags & PROCESS_DEP_ENABLE) != 0; } return STATUS_SUCCESS; }
/// <summary> /// Manually map PE image /// </summary> /// <param name="pid">Target PID</param> /// <param name="path">Full qualified image path</param> /// <param name="flags">Mapping flags</param> /// <param name="initRVA">Init routine RVA</param> /// <param name="initArg">Init routine argument</param> /// <returns>Status code</returns> NTSTATUS DriverControl::MmapDll( DWORD pid, const std::wstring& path, KMmapFlags flags, uint32_t initRVA /*= 0*/, const std::wstring& initArg /*= L"" */ ) { DWORD bytes = 0; INJECT_DLL data = { IT_MMap }; UNICODE_STRING ustr = { 0 }; // Convert path to native format SAFE_NATIVE_CALL( RtlDosPathNameToNtPathName_U, path.c_str(), &ustr, nullptr, nullptr ); wcscpy_s( data.FullDllPath, ustr.Buffer ); SAFE_CALL( RtlFreeUnicodeString, &ustr ); wcscpy_s( data.initArg, initArg.c_str() ); data.pid = pid; data.initRVA = initRVA; data.wait = true; data.unlink = false; data.erasePE = false; data.flags = flags; data.imageBase = 0; data.imageSize = 0; data.asImage = false; if (!DeviceIoControl( _hDriver, IOCTL_BLACKBONE_INJECT_DLL, &data, sizeof( data ), nullptr, 0, &bytes, NULL )) return LastNtStatus(); return STATUS_SUCCESS; }
Kylin::Factor* Kylin::ActionDispatcher::Fire( KUINT uGID,const KPoint3& kPos ) { Factor* pFactor = Fire(uGID); SAFE_CALL(pFactor,SetTranslate(kPos)); return pFactor; }
/// <summary> /// Check if thread is suspended /// </summary> /// <returns>true if suspended</returns> bool Thread::Suspended() { auto count = (_core->isWow64() && !_core->native()->GetWow64Barrier().x86OS) ? SAFE_CALL( Wow64SuspendThread, _handle ) : SuspendThread( _handle ); ResumeThread( _handle ); return count > 0; }
int Scm_GetbUnsafe(ScmPort *p) #endif { int b = 0; VMDECL; SHORTCUT(p, return Scm_GetbUnsafe(p)); LOCK(p); CLOSE_CHECK(p); /* check if there's "pushed back" stuff */ if (p->scrcnt) { b = getb_scratch(p); } else if (p->ungotten != SCM_CHAR_INVALID) { b = getb_ungotten(p); } else { switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: if (p->src.buf.current >= p->src.buf.end) { int r = 0; SAFE_CALL(p, r = bufport_fill(p, 1, FALSE)); if (r == 0) { UNLOCK(p); return EOF; } } b = (unsigned char)*p->src.buf.current++; break; case SCM_PORT_ISTR: if (p->src.istr.current >= p->src.istr.end) b = EOF; else b = (unsigned char)*p->src.istr.current++; break; case SCM_PORT_PROC: SAFE_CALL(p, b = p->src.vt.Getb(p)); break; default: UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_INPUT, "bad port type for input: %S", p); } p->bytes++; } UNLOCK(p); return b; }
void Scm_PutsUnsafe(ScmString *s, ScmPort *p) #endif { VMDECL; SHORTCUT(p, Scm_PutsUnsafe(s, p); return); WALKER_CHECK(p); LOCK(p); CLOSE_CHECK(p); switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: { u_int size; const char *ss = Scm_GetStringContent(s, &size, NULL, NULL); SAFE_CALL(p, bufport_write(p, ss, size)); if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_LINE) { const char *cp = p->src.buf.current; while (cp-- > p->src.buf.buffer) { if (*cp == '\n') { SAFE_CALL(p, bufport_flush(p, (int)(cp - p->src.buf.current), FALSE)); break; } } } else if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_NONE) { SAFE_CALL(p, bufport_flush(p, 0, TRUE)); } UNLOCK(p); break; } case SCM_PORT_OSTR: Scm_DStringAdd(&p->src.ostr, s); UNLOCK(p); break; case SCM_PORT_PROC: SAFE_CALL(p, p->src.vt.Puts(s, p)); UNLOCK(p); break; default: UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_OUTPUT, "bad port type for output: %S", p); } }
KVOID Kylin::KitbagMenu::NotifyClick_Item( MyGUI::WidgetPtr _sender, int _left, int _top, MyGUI::MouseButton _id ) { if (_id != MyGUI::MouseButton::Right) return; KINT nIndex = -1; if ( _sender == m_pItem_1_1) nIndex = 0; else if ( _sender == m_pItem_1_2) nIndex = 1; else if ( _sender == m_pItem_1_3) nIndex = 2; else if ( _sender == m_pItem_1_4) nIndex = 3; else if ( _sender == m_pItem_1_5) nIndex = 4; else if ( _sender == m_pItem_1_6) nIndex = 5; else if ( _sender == m_pItem_1_7) nIndex = 6; else if ( _sender == m_pItem_2_1) nIndex = 7; else if ( _sender == m_pItem_2_2) nIndex = 8; else if ( _sender == m_pItem_2_3) nIndex = 9; else if ( _sender == m_pItem_2_4) nIndex = 10; else if ( _sender == m_pItem_2_5) nIndex = 11; else if ( _sender == m_pItem_2_6) nIndex = 12; else if ( _sender == m_pItem_2_7) nIndex = 13; else if ( _sender == m_pItem_3_1) nIndex = 14; else if ( _sender == m_pItem_3_2) nIndex = 15; else if ( _sender == m_pItem_3_3) nIndex = 16; else if ( _sender == m_pItem_3_4) nIndex = 17; else if ( _sender == m_pItem_3_5) nIndex = 18; else if ( _sender == m_pItem_3_6) nIndex = 19; else if ( _sender == m_pItem_3_7) nIndex = 20; if (nIndex != -1) { SAFE_CALL(m_pKitbagListener,OnUsed(nIndex)); Refresh(); } }
static byte TranslateKey(SDLKey _key, dword& _flags) { bool ui_focused = Handler()->VideoDataUI(); switch(_key) { case DINGOO_BUTTON_UP: return 'u'; case DINGOO_BUTTON_DOWN: return 'd'; case DINGOO_BUTTON_LEFT: return 'l'; case DINGOO_BUTTON_RIGHT: return 'r'; case DINGOO_BUTTON_A: return 'f'; case DINGOO_BUTTON_B: return 'e'; case DINGOO_BUTTON_X: return '1'; case DINGOO_BUTTON_Y: return ' '; case DINGOO_BUTTON_SELECT: b_select = _flags&KF_DOWN; if(b_select && b_start) OpQuit(true); return 'm'; case DINGOO_BUTTON_START: b_start = _flags&KF_DOWN; if(b_select && b_start) OpQuit(true); return 'k'; case DINGOO_BUTTON_L: l_shift = _flags&KF_DOWN; if(!ui_focused) Handler()->OnAction(A_RESET); break; case DINGOO_BUTTON_R: r_shift = _flags&KF_DOWN; if(!ui_focused) { xOptions::eOption<int>* op_sound = xOptions::eOption<int>::Find("sound"); SAFE_CALL(op_sound)->Change(); } break; default: break; } if(b_select && b_start) OpQuit(true); return 0; }
void Scm_PutcUnsafe(ScmChar c, ScmPort *p) #endif { VMDECL; SHORTCUT(p, Scm_PutcUnsafe(c, p); return); WALKER_CHECK(p); LOCK(p); CLOSE_CHECK(p); switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: { int nb = SCM_CHAR_NBYTES(c); if (p->src.buf.current+nb > p->src.buf.end) { SAFE_CALL(p, bufport_flush(p, (int)(p->src.buf.current - p->src.buf.buffer), FALSE)); } SCM_ASSERT(p->src.buf.current+nb <= p->src.buf.end); SCM_CHAR_PUT(p->src.buf.current, c); p->src.buf.current += nb; if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_LINE) { if (c == '\n') { SAFE_CALL(p, bufport_flush(p, nb, FALSE)); } } else if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_NONE) { SAFE_CALL(p, bufport_flush(p, nb, FALSE)); } UNLOCK(p); break; } case SCM_PORT_OSTR: SCM_DSTRING_PUTC(&p->src.ostr, c); UNLOCK(p); break; case SCM_PORT_PROC: SAFE_CALL(p, p->src.vt.Putc(c, p)); UNLOCK(p); break; default: UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_OUTPUT, "bad port type for output: %S", p); } }
KVOID AppFrame::OnIdle( KFLOAT fElapsed ) { //PROFILE("OnIdle"); if (m_bStartTick) StartTick(); SAFE_CALL(EffectManager::GetSingletonPtr(),Render(fElapsed)); m_pGuiMgr->Update(fElapsed);
KBOOL AppFrame::frameEnded( const Ogre::FrameEvent& evt ) { if(m_pWindow->isClosed()) return false; if (m_bShutDown) return false; SAFE_CALL(m_pRenderableMgr,OnRenderEnded(evt.timeSinceLastFrame)); return FrameListener::frameEnded(evt);
ScmObj Scm_ReadLineUnsafe(ScmPort *p) #endif { ScmObj r = SCM_UNDEFINED; VMDECL; SHORTCUT(p, return Scm_ReadLineUnsafe(p)); LOCK(p); SAFE_CALL(p, r = readline_body(p)); UNLOCK(p); return r; }
/// <summary> /// Suspend thread /// </summary> /// <returns>true on success</returns> bool Thread::Suspend() { // Prevent deadlock if (_id == GetCurrentThreadId()) return true; // Target process is x86 and not running on x86 OS if (_core->isWow64() && !_core->native()->GetWow64Barrier().x86OS) return (SAFE_CALL(Wow64SuspendThread, _handle ) != -1); else return (SuspendThread( _handle ) != -1); }
/// <summary> /// Unload arbitrary driver /// </summary> /// <param name="svcName">Driver service name</param> /// <returns>Status</returns> NTSTATUS DriverControl::UnloadDriver( const std::wstring& svcName ) { UNICODE_STRING Ustr = { 0 }; std::wstring regPath = L"\\registry\\machine\\SYSTEM\\CurrentControlSet\\Services\\" + svcName; SAFE_CALL( RtlInitUnicodeString, &Ustr, regPath.c_str() ); // Remove previously loaded instance, if any NTSTATUS status = SAFE_NATIVE_CALL( NtUnloadDriver, &Ustr ); RegDeleteTreeW( HKEY_LOCAL_MACHINE, (L"SYSTEM\\CurrentControlSet\\Services\\" + svcName).c_str() ); return status; }
/// <summary> /// Load arbitrary driver /// </summary> /// <param name="svcName">Driver service name</param> /// <param name="path">Driver file path</param> /// <returns>Status</returns> NTSTATUS DriverControl::LoadDriver( const std::wstring& svcName, const std::wstring& path ) { UNICODE_STRING Ustr; // If no file provided, try to start existing service if (!path.empty() && PrepareDriverRegEntry( svcName, path ) != 0) return LastNtStatus(); std::wstring regPath = L"\\registry\\machine\\SYSTEM\\CurrentControlSet\\Services\\" + svcName; SAFE_CALL( RtlInitUnicodeString, &Ustr, regPath.c_str() ); return SAFE_NATIVE_CALL( NtLoadDriver, &Ustr ); }
Kylin::Factor* Kylin::ActionDispatcher::Fire( KUINT uGID,KUINT uTarget ) { Kylin::Entity* pEnt = KylinRoot::GetSingletonPtr()->GetEntity(uTarget); if (pEnt) { Factor* pFactor = Fire(uGID); SAFE_CALL(pFactor,SetTarget(uTarget)); return pFactor; } return NULL; }
void Scm_PutzUnsafe(const char *s, int siz, ScmPort *p) #endif { VMDECL; SHORTCUT(p, Scm_PutzUnsafe(s, siz, p); return); WALKER_CHECK(p); LOCK(p); CLOSE_CHECK(p); if (siz < 0) siz = (int)strlen(s); switch (SCM_PORT_TYPE(p)) { case SCM_PORT_FILE: SAFE_CALL(p, bufport_write(p, s, siz)); if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_LINE) { const char *cp = p->src.buf.current; while (cp-- > p->src.buf.buffer) { if (*cp == '\n') { SAFE_CALL(p, bufport_flush(p, (int)(cp - p->src.buf.current), FALSE)); break; } } } else if (SCM_PORT_BUFFER_MODE(p) == SCM_PORT_BUFFER_NONE) { SAFE_CALL(p, bufport_flush(p, 0, TRUE)); } UNLOCK(p); break; case SCM_PORT_OSTR: Scm_DStringPutz(&p->src.ostr, s, siz); UNLOCK(p); break; case SCM_PORT_PROC: SAFE_CALL(p, p->src.vt.Putz(s, siz, p)); UNLOCK(p); break; default: UNLOCK(p); Scm_PortError(p, SCM_PORT_ERROR_OUTPUT, "bad port type for output: %S", p); } }
/// <summary> /// Set WOW64 thread context /// </summary> /// <param name="hThread">Thread handle.</param> /// <param name="ctx">Thread context</param> /// <returns>Status code</returns> NTSTATUS Native::SetThreadContextT( HANDLE hThread, _CONTEXT32& ctx ) { // Target process is x64. 32bit CONTEXT is not available. if (_wowBarrier.targetWow64 == false) { return 0; } else { SetLastNtStatus( STATUS_SUCCESS ); SAFE_CALL( Wow64SetThreadContext, hThread, reinterpret_cast<PWOW64_CONTEXT>(&ctx)); return LastNtStatus(); } }
//============================================================================= // eFdd::Open //----------------------------------------------------------------------------- bool eFdd::Open(const char* type, const void* data, size_t data_size) { Motor(0); bool ok = false; if(!strcmp(type, "trd")) ok = ReadTrd(data, data_size); else if(!strcmp(type, "scl")) ok = ReadScl(data, data_size); else if(!strcmp(type, "fdi")) ok = ReadFdi(data, data_size); else if(!strcmp(type, "udi")) ok = ReadUdi(data, data_size); else if(!strcmp(type, "td0")) ok = ReadTd0(data, data_size); SAFE_CALL(disk)->Changed(false); return ok; }
static int getz_scratch_unsafe(char *buf, int buflen, ScmPort *p) #endif { if (p->scrcnt >= (u_int)buflen) { memcpy(buf, p->scratch, buflen); p->scrcnt -= buflen; shift_scratch(p, buflen); return buflen; } else { memcpy(buf, p->scratch, p->scrcnt); int i = p->scrcnt; p->scrcnt = 0; int n = 0; SAFE_CALL(p, n = Scm_Getz(buf+i, buflen-i, p)); return i + n; } }
/// <summary> /// Manually map another system driver into system space /// </summary> /// <param name="path">Fully quialified path to the drver</param> /// <returns>Status code</returns> NTSTATUS DriverControl::MMapDriver( const std::wstring& path ) { DWORD bytes = 0; MMAP_DRIVER data = { { 0 } }; UNICODE_STRING ustr = { 0 }; // Not loaded if (_hDriver == INVALID_HANDLE_VALUE) return STATUS_DEVICE_DOES_NOT_EXIST; // Convert path to native format SAFE_NATIVE_CALL( RtlDosPathNameToNtPathName_U, path.c_str(), &ustr, nullptr, nullptr); wcscpy_s( data.FullPath, ustr.Buffer ); SAFE_CALL( RtlFreeUnicodeString, &ustr); if (!DeviceIoControl( _hDriver, IOCTL_BLACKBONE_MAP_DRIVER, &data, sizeof( data ), nullptr, 0, &bytes, NULL )) return LastNtStatus(); return STATUS_SUCCESS; }
KVOID Kylin::Scene::LeaveScene( KVOID ) { if (OgreOggSound::OgreOggSoundManager::getSingletonPtr()) { OgreOggSound::OgreOggSoundManager::getSingletonPtr()->stopAllSounds(); //OgreOggSound::OgreOggSoundManager::getSingletonPtr()->destroyAllSounds(); } m_pEntityManager->Destroy(); m_pEventManager->RemoveAllEvents(); SAFE_CALL(m_pSceneLoader,Unload(&m_kSceneHag)); SAFE_DEL(m_pSceneLoader); if (PhyX::PhysicalSystem::Initialized()) { PhyX::PhysicalSystem::GetSingletonPtr()->Clear(); } }