识别文件编码
admin | win32 | 2013-04-04
C++
bool TextEncode(const char *fPath)
{
char srcBuff[1024];
char header[2];
unsigned char uniTxt[] = {0xFF, 0xFE}; // Unicode file header
unsigned char endianTxt[] = {0xFE, 0xFF}; // Unicode big endian file header
unsigned char utf8Txt[] = {0xEF, 0xBB, 0xBF}; // UTF_8 file header
int l... [阅读全文]
强制关机
admin | win32 | 2013-04-04
C++
#include<stdio.h>
#include<windows.h>
int main(void)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// 取得系统版本
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osvi) == 0)
return false;
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{... [阅读全文]
C++获取系统的Mac地址
admin | win32 | 2013-04-04
C++
[cce_cpp]
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/*
Dev C++ -> include libnetapi32.a
BCC 5.5 or VC++ -> #pragma comment(lib,"netapi32.lib")
*/
typedef struct _ASTAT_
{
ADAPT... [阅读全文]
用户态下HOOK API隐藏文件
admin | win32 | 2013-04-02
突然想写个RING3下隐藏文件的程序,于是花了一天的时间,把我以前写的一个HOOK send的程序改了。
要实现Ring3下隐藏文件,最简单的方法就是HOOK掉Explorer进程里的FindFirstFile和FindNextFile函数,考虑到A和W两个版本,我们应该要HOOK四个函数,但是事实上,我们只要HOOK掉W版本的两个函数就可以了,因为用Dependency看下就能发现Explorer.exe并没有... [阅读全文]
判断某一进程是否在运行
admin | win32 | 2013-03-20
C++
#include "tlhelp32.h"
int GetProcessCount(const TCHAR* szExeName)
{
TCHAR sztarget[MAX_PATH];
lstrcpy(sztarget, szExeName);
CharLowerBuff(sztarget, MAX_PATH);
int count = 0;
PROCESSENTRY32 my;
HANDLE l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (((i... [阅读全文]
开启停止服务,强杀进程
admin | win32 | 2013-03-20
C++
查服务状态
DWORD DetectServiceStats( LPCTSTR pszName )
{
SC_HANDLE schSCManager = ::OpenSCManager(NULL,NULL,SC_MANAGER_ENUMERATE_SERVICE);
if( schSCManager == NULL )
{
return -1;
}
SC_HANDLE schService = ::OpenService(schSCManager,pszName,SERVICE_QUERY_STATUS);
if(schService == NUL... [阅读全文]
C++ 单实例运行
admin | win32 | 2013-03-20
C++
m_hSingletonMutex = ::CreateMutex(NULL, FALSE, _T("{CC123A53-2A16-4222-BAF1-066213211324}"));
if (ERROR_ALREADY_EXISTS == ::GetLastError())
{
return true;
}
else if(ERROR_ACCESS_DENIED == ::GetLastError())
{
m_hSingletonMutex = ::OpenMutex(NULL, FALSE, _T("... [阅读全文]
杀死进程
admin | win32 | 2013-03-20
C++
DWORD CXDictApp::StopProcess( LPCTSTR pszName )
{
PROCESSENTRY32 pe;
HANDLE hProcess;
CString filepath;
HANDLE hShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
pe.dwSize=sizeof(PROCESSENTRY32);
int n = 0;
if(Process32First(hShot,&pe))
{
do
{
if(wcscmp(pe.szExeFil... [阅读全文]
解决系统注册服务的状态查询、启动、停止及执行文件路径查询
admin | win32 | 2013-03-20
C++
// ServiceHlpr.h:
#if !defined(AFX_SERVICEHLPR_H__58594DB7_DD67_44B1_AE76_EDB403437972__INCLUDED_)
#define AFX_SERVICEHLPR_H__58594DB7_DD67_44B1_AE76_EDB403437972__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class ServiceHlpr
{
public:
static DWORD ... [阅读全文]
先判断服务是否启动,如果说是停止的话,那么就启动这个服务,然后等待它完成初始化
admin | win32 | 2013-03-20
C++
#include "Winsvc.h"
#pragma comment(lib,"Advapi32.lib")
// 打开服务管理对象
SC_HANDLE hSC = ::OpenSCManager( NULL,
NULL, GENERIC_EXECUTE);
if( hSC == NULL)
{
TRACE( _T("open SCManager error"));
return FALSE;
}
// 打开W32Time... [阅读全文]