(转)api.hook使用
By
admin
at 2018-10-19 • 0人收藏 • 1429人看过
import raw.apiHook; HookMessageBox = function (hwnd, text, caption, flag) { hook.callApi(hwnd, text, "APIHOOK成功: " + caption, flag); return 999; } hook = raw.apiHook("user32.dll", "MessageBoxW", "int(int,ustring,ustring,int)", HookMessageBox).install(); ::User32.MessageBoxW(0,"提示信息","测试",0)
2 个回复 | 最后更新于 2018-10-19
//--------------------------------------------------------- // Name : SkinSB_GetScrollInfo() // Desc : Overload API GetScrollInfo() //--------------------------------------------------------- BOOL WINAPI SkinSB_GetScrollInfo(HWND hwnd, int fnBar, LPSCROLLINFO lpsi) { LPSB psb; LPSCROLLINFO psi; BOOL fCopied = FALSE; if( !lpsi || lpsi->cbSize != sizeof(SCROLLINFO) ) return FALSE; // Is initialized ? if( (psb = SkinSB_GetSB(hwnd)) == NULL ) return FALSE; // If be scrollbar control then call failed if( fnBar == SB_HORZ ) psi = &psb->Horz; else if( fnBar == SB_VERT ) psi = &psb->Vert; else if( fnBar == SB_CTL ) return FALSE; if( lpsi->fMask & SIF_PAGE ) { lpsi->nPage = psi->nPage; fCopied = TRUE; } if( lpsi->fMask & SIF_POS ) { lpsi->nPos = psi->nPos; fCopied = TRUE; } if( lpsi->fMask & SIF_TRACKPOS ) { lpsi->nTrackPos = psi->nTrackPos; fCopied = TRUE; } if( lpsi->fMask & SIF_RANGE ) { lpsi->nMin = psi->nMin; lpsi->nMax = psi->nMax; fCopied = TRUE; } return fCopied; } //--------------------------------------------------------- // Name : SkinSB_SetScrollInfo() // Desc : Overload API SetScrollInfo() //--------------------------------------------------------- int WINAPI SkinSB_SetScrollInfo(HWND hwnd, int fnBar, LPCSCROLLINFO psi, BOOL fRedraw) { LPSB psb; LPSCROLLINFO mysi; int nRet; DWORD dwStyle; BOOL fVert; UINT wScroll; BOOL fScroll; BOOL fOldScroll; BOOL bReturnOldPos; // if be scrollbar control the call failed if( fnBar == SB_CTL ) return 0; if( (psb = SkinSB_GetSB(hwnd)) == NULL ) return 0; if( fRedraw ) fRedraw = IsWindowVisible(hwnd); fVert = (fnBar == SB_VERT); bReturnOldPos = (psi->fMask & SIF_POS); dwStyle = GetWindowLong(hwnd, GWL_STYLE); wScroll = fVert ? WS_VSCROLL : WS_HSCROLL; fScroll = fOldScroll = (dwStyle & wScroll) ? TRUE : FALSE; // Don't do anything if we're setting position of a nonexistent scroll bar. if( !(psi->fMask & SIF_RANGE) && !fOldScroll ) return 0; mysi = (fVert ? &psb->Vert : &psb->Horz); if( !SkinSB_SetSBParms(mysi, *psi, &fScroll, &nRet, bReturnOldPos) && !(psi->fMask & SIF_DISABLENOSCROLL) ) { if( fOldScroll && fRedraw ) goto redrawAfterSet; return nRet; } if( fScroll ) psb->style |= wScroll; else psb->style &= ~wScroll; // Keep the owner window scroll style SetWindowLong(hwnd, GWL_STYLE, dwStyle | wScroll); if( psi->fMask & SIF_DISABLENOSCROLL ) { if( fOldScroll ) { fScroll = ((int)mysi->nPage <= (mysi->nMax - mysi->nMin)); psb->style |= wScroll; SetWindowLong(hwnd, GWL_STYLE, dwStyle | wScroll); SkinSB_EnableArrows(psb, fnBar, fScroll ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH); } } else if( fOldScroll ^ fScroll ) { SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_DRAWFRAME); return nRet; } if( fScroll && fRedraw ) { redrawAfterSet: if(dwStyle & wScroll) { HDC hDC = GetWindowDC(hwnd); SkinSB_DrawThumb(psb, hDC, fVert); ReleaseDC(hwnd, hDC); } else { if( SkinSB_IsScrollInfoActive(psi) ) SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_DRAWFRAME); } } return mysi->nPos; //lres; } //--------------------------------------------------------- // Name : SkinSB_GetScrollPos() // Desc : Overload API GetScrollPos() //--------------------------------------------------------- int WINAPI SkinSB_GetScrollPos(HWND hwnd, int nBar) { LPSB psb; int nPos; if( !(psb = SkinSB_GetSB(hwnd)) ) return FALSE; if( nBar == SB_HORZ ) nPos = psb->Horz.nPos; else if( nBar == SB_VERT ) nPos = psb->Vert.nPos; return nPos; } //--------------------------------------------------------- // Name : SkinSB_SetScrollPos() // Desc : Overload API SetScrollPos() //--------------------------------------------------------- int WINAPI SkinSB_SetScrollPos(HWND hwnd, int nBar, int nPos, BOOL fRedraw) { LPSB psb; LPSCROLLINFO psi; int nOldPos; if( (psb = SkinSB_GetSB(hwnd)) == NULL) return FALSE; if( nBar == SB_HORZ ) psi = &psb->Horz; else if( nBar == SB_VERT ) psi = &psb->Vert; else return FALSE; nOldPos = psi->nPos; psi->nPos = nPos; if( fRedraw ) { HDC hDC = GetWindowDC(hwnd); SkinSB_DrawScrollBar(psb, hDC, (nBar == SB_VERT) ); ReleaseDC(hwnd, hDC); } return nOldPos; } //--------------------------------------------------------- // Name : SkinSB_GetScrollRange() // Desc : Overload API GetScrollRange() //--------------------------------------------------------- BOOL WINAPI SkinSB_GetScrollRange(HWND hwnd, int nBar, LPINT lpMinPos, LPINT lpMaxPos) { LPSB psb; LPSCROLLINFO psi; if( !lpMinPos || !lpMaxPos ) return FALSE; if( (psb = SkinSB_GetSB(hwnd)) == NULL ) return FALSE; if( nBar == SB_HORZ ) psi = &psb->Horz; else if( nBar == SB_VERT ) psi = &psb->Vert; *lpMinPos = psi->nMin; *lpMaxPos = psi->nMax; return TRUE; } //--------------------------------------------------------- // Name : SkinSB_SetScrollRange() // Desc : Overload API SetScrollRange() //--------------------------------------------------------- BOOL WINAPI SkinSB_SetScrollRange(HWND hwnd, int nBar, int nMinPos, int nMaxPos, BOOL fRedraw) { LPSB psb; LPSCROLLINFO psi; if( !(psb = SkinSB_GetSB(hwnd)) ) return FALSE; if( nBar == SB_HORZ ) psi = &psb->Horz; else if( nBar == SB_VERT ) psi = &psb->Vert; psi->nMin = nMinPos; psi->nMax = nMaxPos; if(nMinPos == 0 && nMaxPos == 0) SkinSB_ShowScrollBar(hwnd, nBar, FALSE); if( fRedraw ) { HDC hDC = GetWindowDC(hwnd); SkinSB_DrawScrollBar(psb, hDC, (nBar == SB_VERT) ); ReleaseDC(hwnd, hDC); } return TRUE; } //--------------------------------------------------------- // Name : SkinSB_ShowScrollBar() // Desc : Overload API ShowScrollBar() //--------------------------------------------------------- BOOL WINAPI SkinSB_ShowScrollBar(HWND hwnd, int wBar, BOOL fShow) { BOOL fChanged = FALSE; DWORD dwStyle, dwNew; switch( wBar ) { case SB_CTL: ShowWindow(hwnd, fShow ? SW_SHOW : SW_HIDE); break; case SB_HORZ: dwNew = WS_HSCROLL; break; case SB_VERT: dwNew = WS_VSCROLL; break; case SB_BOTH: dwNew = WS_HSCROLL | WS_VSCROLL; break; } dwStyle = GetWindowLong(hwnd, GWL_STYLE); if( !fShow ) { if( dwStyle & dwNew ) { fChanged = TRUE; dwStyle &= ~dwNew; } } else { if( (dwStyle & dwNew) != dwNew ) { fChanged = TRUE; dwStyle |= dwNew; } } if( fChanged ) { SetWindowLong(hwnd, GWL_STYLE, dwStyle); SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_DRAWFRAME); } return TRUE; } //--------------------------------------------------------- // Name : SkinSB_EnableScrollBar() // Desc : Overload API EnableScrollBar() //--------------------------------------------------------- BOOL WINAPI SkinSB_EnableScrollBar(HWND hwnd, UINT wSBflags, UINT wArrows) { LPSB psb; if( !(psb = SkinSB_GetSB(hwnd)) ) return FALSE; if( wSBflags == SB_CTL ) return FALSE; return SkinSB_EnableArrows(psb, wSBflags, wArrows); }
登录后方可回帖
hook 滚动条
之前遇到的问题:
滚动条拖动到任意位置总是会回到原始位置...? 是哪个参数不对吗?
解决办法: 每个hook前加了return