From b29f9b4dd93e6c59c87d506de079fcfb7db36e71 Mon Sep 17 00:00:00 2001 From: llluiop <290522165@qq.com> Date: Wed, 20 May 2015 15:48:30 +0800 Subject: [PATCH] add 0007 --- llluiop/0007/Code.cpp | 157 +++++++++++++++++++++++++++++++++++++++ llluiop/0007/CodeLine.py | 28 +++++++ 2 files changed, 185 insertions(+) create mode 100644 llluiop/0007/Code.cpp create mode 100644 llluiop/0007/CodeLine.py diff --git a/llluiop/0007/Code.cpp b/llluiop/0007/Code.cpp new file mode 100644 index 00000000..bdbe8f2f --- /dev/null +++ b/llluiop/0007/Code.cpp @@ -0,0 +1,157 @@ +#include "stdafx.h" +#include "CoreHook_Unity.h" +#include + +using namespace CoreHook; + +LPVOID Unity::GetVirtualCall(LPVOID pObject, int nIndex) +{ + if (NULL == pObject) + return NULL; + + PDWORD_PTR pVirTable = (PDWORD_PTR)*(PDWORD_PTR)pObject; + return (PDWORD_PTR)*(pVirTable + nIndex); +} + +//test +LPVOID Unity::ScanCode(LPVOID pStart, DWORD dwLen, const BYTE pChar[], DWORD dwCharLen) +{ + if(!pStart || !dwLen || !dwCharLen) + { + return NULL; + } + DWORD i = 0; + for(char * p = (char *)pStart; i < dwLen; i++, p++) + { + if(i + dwCharLen > dwLen) + { + break; + } + if(memcmp(p, pChar, dwCharLen) == 0) + { + return p; + } + } + return NULL; +} + +HMODULE Unity::GetModuleByPrefix( LPCWSTR lpPrefix ) +{ + HMODULE hModule = NULL; + HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0); + if (INVALID_HANDLE_VALUE != hSnapShot) + { + MODULEENTRY32* moduleInfo = new MODULEENTRY32; + moduleInfo->dwSize = sizeof(MODULEENTRY32); + + while (Module32Next(hSnapShot, moduleInfo) != FALSE) + { + std::wstring s = moduleInfo->szModule; + if(-1 != s.find(lpPrefix)) + { + hModule = moduleInfo->hModule; + break; + } + + } + + CloseHandle(hSnapShot); + delete moduleInfo; + } + + return hModule; +} + +/*test*/ +WORD Unity::FileMachineType( LPCTSTR lpExecuteFile ) +{ + FILE *pfile = _tfopen(lpExecuteFile, L"rb"); + if (NULL == pfile) + return (WORD)(0); + + IMAGE_DOS_HEADER idh; + fread(&idh, sizeof(idh), 1, pfile); + + IMAGE_FILE_HEADER ifh; + fseek(pfile, idh.e_lfanew + 4, SEEK_SET); + fread(&ifh, sizeof(ifh), 1, pfile); + fclose(pfile); + + return ifh.Machine; +} + +CString Unity::GetFileNameByFullPath(LPCTSTR lpFileFullPath) +{ + TCHAR szPath[MAX_PATH] = {0}; + + lstrcpyn(szPath, lpFileFullPath, Tsizeof(szPath)); + PathStripPath(szPath); + + return szPath; +} + + +BOOL Unity::ExeIsWebBrowser(LPCTSTR szExeFileName) +{ + if(lstrcmpi(szExeFileName, _T("iexplore.exe")) == 0 + || lstrcmpi(szExeFileName, _T("firefox.exe")) == 0 + || lstrcmpi(szExeFileName, _T("chrome.exe")) == 0 + || lstrcmpi(szExeFileName, _T("opera.exe")) == 0 + || lstrcmpi(szExeFileName, _T("Safari.exe")) == 0 + || lstrcmpi(szExeFileName, _T("dxsetup.exe")) == 0) + + { + return TRUE; + } + return FALSE; +} + +CString Unity::GetCreateProcessFileFullPath( LPCTSTR szApplicationName, LPCTSTR szCommandLine ) +{ + TCHAR szPath[MAX_PATH] = {0}; + if(szApplicationName) + { + lstrcpyn(szPath, szApplicationName, Tsizeof(szPath)); + } + else if(szCommandLine[0] == _T('\"')) + { + int nFind = 1; + for(; szCommandLine[nFind] && szCommandLine[nFind] != _T('\"'); nFind++); + lstrcpyn(szPath, &szCommandLine[1], nFind); + } + return szPath; +} + +CString Unity::GetCreateProcessFileName( LPCTSTR szApplicationName, LPCTSTR szCommandLine ) +{ + return GetFileNameByFullPath(GetCreateProcessFileFullPath(szApplicationName, szCommandLine)); +} + + +bool CoreHook::Unity::IsWindowsVersionOrGreater( WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor ) +{ + + OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 }; + DWORDLONG const dwlConditionMask = VerSetConditionMask( + VerSetConditionMask( + VerSetConditionMask( + 0, VER_MAJORVERSION, VER_GREATER_EQUAL), + VER_MINORVERSION, VER_GREATER_EQUAL), + VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); + + osvi.dwMajorVersion = wMajorVersion; + osvi.dwMinorVersion = wMinorVersion; + osvi.wServicePackMajor = wServicePackMajor; + + return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE; + +} + +CString CoreHook::Unity::GetCurModuelName() +{ + TCHAR szName[MAX_PATH]={0}; + GetModuleFileName(NULL,szName,MAX_PATH); + PathStripPath(szName); + + return szName; +} \ No newline at end of file diff --git a/llluiop/0007/CodeLine.py b/llluiop/0007/CodeLine.py new file mode 100644 index 00000000..b122fbae --- /dev/null +++ b/llluiop/0007/CodeLine.py @@ -0,0 +1,28 @@ +#!/usr/bin.env python + +import os + + +def main(): + f = open('code.cpp') + blanks = 0 + comments = 0 + lines = 0 + + for line in f.readlines(): + if len(line.split()) == 0: + blanks += 1 + elif line.startswith("//"): + comments += 1 + elif line.startswith("/*"): + comments += 1 + + lines += 1 + + print 'blank lines', blanks + print 'comment lines', comments + print 'all lines', lines + + +if __name__ == '__main__': + main() \ No newline at end of file