Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions llluiop/0007/Code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#include "stdafx.h"
#include "CoreHook_Unity.h"
#include <TlHelp32.h>

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;
}
28 changes: 28 additions & 0 deletions llluiop/0007/CodeLine.py
Original file line number Diff line number Diff line change
@@ -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()