Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
LogAPI.cpp
Package: apispy32.zip [view]
Upload User: tzh4061
Upload Date: 2007-01-08
Package Size: 309k
Code Size: 5k
Category:
Hook api
Development Platform:
Visual C++
- // ----------------------------------- //
- // APISpy32 v2.0 //
- // Copyright 1999 Yariv Kaplan //
- // WWW.INTERNALS.COM //
- // ----------------------------------- //
- #include <windows.h>
- #include "LogAPI.h"
- #ifdef WINNT
- #pragma comment(linker, "/section:.sdata,RWS")
- #pragma data_seg(".sdata")
- #endif
- bool CaptureEvents = false;
- DWORD dwAPISpy32ProcessId = 0;
- #ifdef WINNT
- #pragma data_seg()
- #endif
- #ifdef WINNT
- bool AddLogEntry(DWORD dwProcessId, PSTR pszAPIName, DWORD dwReturnValue, PVOID pvOriginAddress)
- {
- HANDLE hMailslot;
- DWORD dwBytesWritten;
- tagLogEntry LogEntry;
- BOOL Result;
- if (CaptureEvents == false || dwProcessId == dwAPISpy32ProcessId)
- return true;
- hMailslot = CreateFile("\\.\mailslot\APISpy32_Mailslot", GENERIC_WRITE,
- FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
- if (hMailslot == INVALID_HANDLE_VALUE)
- return false;
- LogEntry.dwProcessId = dwProcessId;
- LogEntry.dwReturnValue = dwReturnValue;
- LogEntry.pvOriginAddress = pvOriginAddress;
- strcpy(LogEntry.szAPIName, pszAPIName);
- Result = WriteFile(hMailslot, &LogEntry, sizeof(tagLogEntry), &dwBytesWritten, NULL);
- CloseHandle(hMailslot);
- return Result!=0;
- }
- #endif
- #ifdef WIN95
- tagLogEntry LogBuffer[MAX_LOG_ENTRIES];
- DWORD dwReadLogIndex = 0, dwWriteLogIndex = 0;
- bool AddLogEntry(DWORD dwProcessId, PSTR pszAPIName, DWORD dwReturnValue, PVOID pvOriginAddress)
- {
- HANDLE hOverflowEvent;
- HANDLE hLogEvent;
- HANDLE hLogMutex;
- if (CaptureEvents == false || dwProcessId == dwAPISpy32ProcessId)
- return true;
- hLogMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "APISpy32_LogMutex");
- if (hLogMutex == NULL)
- return false;
- WaitForSingleObject(hLogMutex, INFINITE);
- LogBuffer[dwWriteLogIndex].dwProcessId = dwProcessId;
- LogBuffer[dwWriteLogIndex].dwReturnValue = dwReturnValue;
- LogBuffer[dwWriteLogIndex].pvOriginAddress = pvOriginAddress;
- if (strlen(pszAPIName) > MAX_API_LEN)
- {
- memcpy(LogBuffer[dwWriteLogIndex].szAPIName, pszAPIName, MAX_API_LEN - 3);
- LogBuffer[dwWriteLogIndex].szAPIName[MAX_API_LEN - 3] = '.';
- LogBuffer[dwWriteLogIndex].szAPIName[MAX_API_LEN - 2] = '.';
- LogBuffer[dwWriteLogIndex].szAPIName[MAX_API_LEN - 1] = '.';
- LogBuffer[dwWriteLogIndex].szAPIName[MAX_API_LEN] = '';
- }
- else
- strcpy(LogBuffer[dwWriteLogIndex].szAPIName, pszAPIName);
- if ((dwReadLogIndex != 0 && dwWriteLogIndex == dwReadLogIndex - 1) ||
- (dwReadLogIndex == 0 && dwWriteLogIndex == MAX_LOG_ENTRIES - 1 ))
- {
- hOverflowEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, "APISpy32_OverflowEvent");
- if (hOverflowEvent == NULL)
- {
- ReleaseMutex(hLogMutex);
- CloseHandle(hLogMutex);
- return false;
- }
- hLogEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, "APISpy32_LogEvent");
- if (hLogEvent == NULL)
- {
- CloseHandle(hOverflowEvent);
- ReleaseMutex(hLogMutex);
- CloseHandle(hLogMutex);
- return false;
- }
- SetEvent(hOverflowEvent);
- WaitForSingleObject(hLogEvent, INFINITE);
- ResetEvent(hLogEvent);
- CloseHandle(hOverflowEvent);
- CloseHandle(hLogEvent);
- }
- dwWriteLogIndex++;
- if (dwWriteLogIndex == MAX_LOG_ENTRIES)
- dwWriteLogIndex = 0;
- ReleaseMutex(hLogMutex);
- CloseHandle(hLogMutex);
- return true;
- }
- extern "C" __declspec(dllexport) bool GetLogParameters(DWORD *pdwNumLogEntries, DWORD *pdwReadLogIndex, tagLogEntry **ppLogBuffer)
- {
- HANDLE hLogMutex;
- DWORD Result;
- hLogMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "APISpy32_LogMutex");
- if (hLogMutex == NULL)
- return false;
- Result = WaitForSingleObject(hLogMutex, INFINITE);
- if (Result == WAIT_FAILED)
- {
- CloseHandle(hLogMutex);
- return false;
- }
- *ppLogBuffer = &LogBuffer[0];
- *pdwReadLogIndex = dwReadLogIndex;
- if (dwWriteLogIndex >= dwReadLogIndex)
- *pdwNumLogEntries = dwWriteLogIndex - dwReadLogIndex;
- else
- *pdwNumLogEntries = dwWriteLogIndex + (MAX_LOG_ENTRIES - dwReadLogIndex);
- ReleaseMutex(hLogMutex);
- CloseHandle(hLogMutex);
- return true;
- }
- extern "C" __declspec(dllexport) void AdvanceToNextLogEntry()
- {
- dwReadLogIndex++;
- if (dwReadLogIndex == MAX_LOG_ENTRIES)
- dwReadLogIndex = 0;
- }
- #endif
- extern "C" __declspec(dllexport) void SetCaptureEventsFlag(bool bNewValue)
- {
- CaptureEvents = bNewValue;
- }
- extern "C" __declspec(dllexport) void SetAPISpy32ProcessId(DWORD dwProcessId)
- {
- dwAPISpy32ProcessId = dwProcessId;
- }