├── tests ├── 001.out ├── 001.exp ├── 001.diff ├── stdafx.h ├── test.cpp ├── .DS_Store ├── stdafx.cpp ├── targetver.h ├── test2.cpp ├── embed │ ├── embed.cpp │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ ├── ReadMe.txt │ ├── embed.vcxproj.filters │ └── embed.vcxproj ├── setjump │ ├── stdafx.h │ ├── stdafx.cpp │ ├── setjump.cpp │ ├── targetver.h │ ├── ReadMe.txt │ ├── setjump.vcxproj.filters │ └── setjump.vcxproj ├── signal │ ├── stdafx.h │ ├── stdafx.cpp │ ├── targetver.h │ ├── ReadMe.txt │ ├── signal.cpp │ ├── signal.vcxproj.filters │ └── signal.vcxproj ├── string │ ├── .DS_Store │ ├── string │ │ ├── .DS_Store │ │ └── main.cpp │ └── string.xcodeproj │ │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── yuyi.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ ├── xcuserdata │ │ └── yuyi.xcuserdatad │ │ │ ├── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ └── string.xcscheme │ │ │ └── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── project.pbxproj ├── Release │ ├── stdafx.obj │ ├── test2.obj │ ├── test2.pch │ ├── vc140.pdb │ └── test2.tlog │ │ ├── CL.read.1.tlog │ │ ├── CL.command.1.tlog │ │ ├── CL.write.1.tlog │ │ ├── link.read.1.tlog │ │ ├── link.write.1.tlog │ │ ├── link.command.1.tlog │ │ └── test2.lastbuildstate ├── wing_test │ ├── stdafx.h │ ├── stdafx.cpp │ ├── targetver.h │ ├── wing_test.cpp │ ├── ReadMe.txt │ ├── wing_test.vcxproj.filters │ └── wing_test.vcxproj ├── set_process_title.cpp ├── 1 2.php ├── linux.php ├── version.php ├── 1.php ├── test │ └── test.xcodeproj │ │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── yuyi.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ ├── xcuserdata │ │ └── yuyi.xcuserdatad │ │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ └── test.xcscheme │ │ └── project.pbxproj ├── test1 │ ├── test1.xcodeproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ │ └── yuyi.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ ├── xcuserdata │ │ │ └── yuyi.xcuserdatad │ │ │ │ └── xcschemes │ │ │ │ ├── xcschememanagement.plist │ │ │ │ └── test1.xcscheme │ │ └── project.pbxproj │ └── test1 │ │ └── main.cpp ├── process.php ├── runner.php ├── read.php ├── write.php ├── 001.php ├── wait.php ├── 001.phpt ├── wing_process_test.php ├── 001.sh ├── ReadMe.txt ├── test2.vcxproj.filters ├── wing_process.php └── read.c ├── dll ├── wing-process-php-7.0-vc14-x86-nts.dll ├── wing-process-php-7.0-vc14-x86-ts.dll ├── wing-process-php-7.1-vc14-x64-nts.dll ├── wing-process-php-7.1-vc14-x64-ts.dll ├── wing-process-php-7.1-vc14-x86-nts.dll └── wing-process-php-7.1-vc14-x86-ts.dll ├── win32 ├── win_api.h ├── WingWmic.class.h ├── wing_ntdll.h ├── WingString.class.h ├── win_api.c ├── WingWmic.class.c └── ntdll.c ├── linux ├── linux_api.h └── linux_api.c ├── config.w32 ├── .gitignore ├── LICENSE ├── wing_api.h ├── config.m4 ├── README.md ├── php_wing_process.h ├── wing_api.c └── wing_process.c /tests/001.out: -------------------------------------------------------------------------------- 1 | Termsig=11 -------------------------------------------------------------------------------- /tests/001.exp: -------------------------------------------------------------------------------- 1 | wing_process extension is available -------------------------------------------------------------------------------- /tests/001.diff: -------------------------------------------------------------------------------- 1 | 001+ Termsig=11 2 | 001- wing_process extension is available -------------------------------------------------------------------------------- /tests/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/stdafx.h -------------------------------------------------------------------------------- /tests/test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/test.cpp -------------------------------------------------------------------------------- /tests/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/.DS_Store -------------------------------------------------------------------------------- /tests/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/stdafx.cpp -------------------------------------------------------------------------------- /tests/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/targetver.h -------------------------------------------------------------------------------- /tests/test2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/test2.cpp -------------------------------------------------------------------------------- /tests/embed/embed.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/embed/embed.cpp -------------------------------------------------------------------------------- /tests/embed/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/embed/stdafx.cpp -------------------------------------------------------------------------------- /tests/embed/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/embed/stdafx.h -------------------------------------------------------------------------------- /tests/setjump/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/setjump/stdafx.h -------------------------------------------------------------------------------- /tests/signal/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/signal/stdafx.h -------------------------------------------------------------------------------- /tests/string/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/string/.DS_Store -------------------------------------------------------------------------------- /tests/Release/stdafx.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/Release/stdafx.obj -------------------------------------------------------------------------------- /tests/Release/test2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/Release/test2.obj -------------------------------------------------------------------------------- /tests/Release/test2.pch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/Release/test2.pch -------------------------------------------------------------------------------- /tests/Release/vc140.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/Release/vc140.pdb -------------------------------------------------------------------------------- /tests/embed/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/embed/targetver.h -------------------------------------------------------------------------------- /tests/setjump/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/setjump/stdafx.cpp -------------------------------------------------------------------------------- /tests/signal/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/signal/stdafx.cpp -------------------------------------------------------------------------------- /tests/signal/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/signal/targetver.h -------------------------------------------------------------------------------- /tests/wing_test/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/wing_test/stdafx.h -------------------------------------------------------------------------------- /tests/set_process_title.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/set_process_title.cpp -------------------------------------------------------------------------------- /tests/setjump/setjump.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/setjump/setjump.cpp -------------------------------------------------------------------------------- /tests/setjump/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/setjump/targetver.h -------------------------------------------------------------------------------- /tests/wing_test/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/wing_test/stdafx.cpp -------------------------------------------------------------------------------- /tests/wing_test/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/wing_test/targetver.h -------------------------------------------------------------------------------- /tests/string/string/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/string/string/.DS_Store -------------------------------------------------------------------------------- /tests/wing_test/wing_test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/wing_test/wing_test.cpp -------------------------------------------------------------------------------- /tests/Release/test2.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/Release/test2.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /dll/wing-process-php-7.0-vc14-x86-nts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/dll/wing-process-php-7.0-vc14-x86-nts.dll -------------------------------------------------------------------------------- /dll/wing-process-php-7.0-vc14-x86-ts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/dll/wing-process-php-7.0-vc14-x86-ts.dll -------------------------------------------------------------------------------- /dll/wing-process-php-7.1-vc14-x64-nts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/dll/wing-process-php-7.1-vc14-x64-nts.dll -------------------------------------------------------------------------------- /dll/wing-process-php-7.1-vc14-x64-ts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/dll/wing-process-php-7.1-vc14-x64-ts.dll -------------------------------------------------------------------------------- /dll/wing-process-php-7.1-vc14-x86-nts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/dll/wing-process-php-7.1-vc14-x86-nts.dll -------------------------------------------------------------------------------- /dll/wing-process-php-7.1-vc14-x86-ts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/dll/wing-process-php-7.1-vc14-x86-ts.dll -------------------------------------------------------------------------------- /tests/1 2.php: -------------------------------------------------------------------------------- 1 | getCommandLine(),"\r\n"; 4 | echo $process->getMemory(),"\r\n"; 5 | -------------------------------------------------------------------------------- /tests/version.php: -------------------------------------------------------------------------------- 1 | run(); -------------------------------------------------------------------------------- /tests/test/test.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /win32/win_api.h: -------------------------------------------------------------------------------- 1 | #ifndef WING_PROCESS_WIN_API_H 2 | #define WING_PROCESS_WIN_API_H 3 | #include "wing_ntdll.h" 4 | #include "Shlwapi.h" 5 | #pragma comment(lib, "Shlwapi.lib") 6 | #include "Psapi.h" 7 | #pragma comment(lib, "Psapi.lib") 8 | #endif -------------------------------------------------------------------------------- /tests/string/string.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/test1/test1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/process.php: -------------------------------------------------------------------------------- 1 | 1000) break; 12 | } 13 | exit(999); -------------------------------------------------------------------------------- /tests/test/test.xcodeproj/project.xcworkspace/xcuserdata/yuyi.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/test/test.xcodeproj/project.xcworkspace/xcuserdata/yuyi.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /tests/test1/test1.xcodeproj/project.xcworkspace/xcuserdata/yuyi.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/test1/test1.xcodeproj/project.xcworkspace/xcuserdata/yuyi.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /tests/string/string.xcodeproj/project.xcworkspace/xcuserdata/yuyi.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilieryuyi/wing-process/HEAD/tests/string/string.xcodeproj/project.xcworkspace/xcuserdata/yuyi.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /tests/Release/test2.tlog/test2.lastbuildstate: -------------------------------------------------------------------------------- 1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1 2 | Release|Win32|D:\php\php7-sdk\phpdev\vc14\x86\php-7.0.12\ext\wing_process\| 3 | -------------------------------------------------------------------------------- /tests/runner.php: -------------------------------------------------------------------------------- 1 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #endif -------------------------------------------------------------------------------- /tests/read.php: -------------------------------------------------------------------------------- 1 | 15 | -------------------------------------------------------------------------------- /tests/wait.php: -------------------------------------------------------------------------------- 1 | run(1); 11 | //如果这里的参数是1 process.php的输出全部会被写到 log.txt,如果是0,全部输出将被输出到终端 12 | 13 | //得到 process.php 的退出码 14 | //$exit = $process->wait(); 15 | 16 | //echo $exit,"\r\n"; 17 | // 18 | //$process = new \wing\wing_process("D:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe", __DIR__."/log.txt"); 19 | //echo $process->run(0); 20 | 21 | echo $process->getCommandLine(); -------------------------------------------------------------------------------- /win32/WingWmic.class.h: -------------------------------------------------------------------------------- 1 | #ifndef __WING_WMIC_H__ 2 | #define __WING_WMIC_H__ 3 | #define _WIN32_DCOM 4 | #include "Windows.h" 5 | #include 6 | #include 7 | #include "WingString.class.h" 8 | #pragma comment(lib, "wbemuuid.lib") 9 | 10 | class WingWmic 11 | { 12 | private: 13 | IWbemServices *pSvc; 14 | int has_error; 15 | IEnumWbemClassObject* pEnumerator; 16 | IWbemLocator *pLoc; 17 | char *query_table; 18 | IWbemClassObject *pclsObj; 19 | public: 20 | WingWmic(); 21 | ~WingWmic(); 22 | void query( const char *sql ); 23 | BOOL next(); 24 | char* get( const char *key); 25 | }; 26 | #endif -------------------------------------------------------------------------------- /tests/test/test.xcodeproj/xcuserdata/yuyi.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | test.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | FE84450C1F4E491B0022A2D4 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/test1/test1.xcodeproj/xcuserdata/yuyi.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | test1.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | FEAA57AC1F6EC3F500029325 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/string/string.xcodeproj/xcuserdata/yuyi.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | string.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | FE6260291F5AAC48001404F0 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for wing_process presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 20 | --EXPECT-- 21 | wing_process extension is available 22 | -------------------------------------------------------------------------------- /tests/wing_process_test.php: -------------------------------------------------------------------------------- 1 | run(__DIR__."/log.log"),"\r\n";// 13 | //echo $process->getProcessId(),"\r\n"; 14 | //echo \wing\wing_process::getCurrentProcessId(),"\r\n"; 15 | //echo $process->getCommandLine(),"\r\n"; 16 | //$process->kill(); 17 | //echo $process->wait(),"\r\n"; 18 | 19 | 20 | 21 | //$process = new \wing\wing_process("ls"); 22 | //echo $process->run(__DIR__."/log.log"),"\r\n"; 23 | //echo $process->wait(),"\r\n"; 24 | //echo \wing\wing_process::getCurrentProcessId(),"\r\n"; 25 | //echo $process->getCommandLine(),"\r\n"; 26 | //$process->kill(); 27 | -------------------------------------------------------------------------------- /tests/001.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | /usr/local/Cellar/php70/7.0.12_5/bin/php -n -c '/Users/yuyi/phpsdk/php-7.1.8/ext/wing-process/tmp-php.ini' -d "output_handler=" -d "open_basedir=" -d "safe_mode=0" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=1" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "memory_limit=128M" -d "log_errors_max_len=0" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "extension_dir=/Users/yuyi/phpsdk/php-7.1.8/ext/wing-process/modules/" -d "extension=wing_process.so" -d "session.auto_start=0" -d "zlib.output_compression=Off" -d "mbstring.func_overload=0" -f "/Users/yuyi/phpsdk/php-7.1.8/ext/wing-process/tests/001.php" 2>&1 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /win32/.DS_Store 2 | .deps 3 | *.lo 4 | *.la 5 | .libs 6 | acinclude.m4 7 | aclocal.m4 8 | autom4te.cache 9 | build 10 | config.guess 11 | config.h 12 | config.h.in 13 | config.log 14 | config.nice 15 | config.status 16 | config.sub 17 | configure 18 | configure.in 19 | include 20 | install-sh 21 | libtool 22 | ltmain.sh 23 | Makefile 24 | Makefile.fragments 25 | Makefile.global 26 | Makefile.objects 27 | missing 28 | mkinstalldirs 29 | modules 30 | run-tests.php 31 | tests/*/*.diff 32 | tests/*/*.out 33 | tests/*/*.php 34 | tests/*/*.exp 35 | tests/*/*.log 36 | tests/*/*.sh 37 | Release/tests/*.log 38 | Release/tests/*.pid 39 | /Release 40 | /x64 41 | /Debug 42 | /.vs 43 | /*.opendb 44 | /*.db 45 | /*.sln 46 | /*.vcxproj 47 | */*.vcxproj 48 | /*.filters 49 | /*.user 50 | /ipch 51 | /*/*/x64 52 | *.sdf 53 | /.idea/ 54 | /tests/.idea/ 55 | /tests/log.txt 56 | /tests/*.log 57 | /.DS_Store 58 | /EXPERIMENTAL 59 | /CREDITS 60 | /wing_process.php 61 | /configure.ac 62 | -------------------------------------------------------------------------------- /tests/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:test2 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 test2 应用程序。 6 | 7 | 本文件概要介绍组成 test2 应用程序的每个文件的内容。 8 | 9 | 10 | test2.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | test2.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | test2.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 test2.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /tests/embed/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:embed 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 embed 应用程序。 6 | 7 | 本文件概要介绍组成 embed 应用程序的每个文件的内容。 8 | 9 | 10 | embed.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | embed.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | embed.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 embed.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /tests/signal/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:signal 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 signal 应用程序。 6 | 7 | 本文件概要介绍组成 signal 应用程序的每个文件的内容。 8 | 9 | 10 | signal.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | signal.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | signal.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 signal.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /tests/setjump/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:setjump 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 setjump 应用程序。 6 | 7 | 本文件概要介绍组成 setjump 应用程序的每个文件的内容。 8 | 9 | 10 | setjump.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | setjump.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | setjump.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 setjump.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /tests/wing_test/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:wing_test 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 wing_test 应用程序。 6 | 7 | 本文件概要介绍组成 wing_test 应用程序的每个文件的内容。 8 | 9 | 10 | wing_test.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | wing_test.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | wing_test.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 wing_test.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 yuyi <297341015@qq.com> 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/test1/test1/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // test1 4 | // 5 | // Created by yuyi on 17/9/17. 6 | // Copyright © 2017年 yuyi. All rights reserved. 7 | // 8 | 9 | #include 10 | 11 | static inline void float4store(unsigned char *T, float A) 12 | { *(T)= ((unsigned char *) &A)[3]; 13 | *((T)+1)=(char) ((unsigned char *) &A)[2]; 14 | *((T)+2)=(char) ((unsigned char *) &A)[1]; 15 | *((T)+3)=(char) ((unsigned char *) &A)[0]; 16 | } 17 | 18 | int main(int argc, const char * argv[]) { 19 | // insert code here... 20 | int a = 1|1; 21 | 22 | unsigned char t4[5]; 23 | memset(t4, 0, 5); 24 | float ab= 1.001; 25 | float4store(t4, ab); 26 | 27 | float def_temp; 28 | ((unsigned char *) &def_temp)[0]=(t4)[3]; 29 | ((unsigned char *) &def_temp)[1]=(t4)[2]; 30 | ((unsigned char *) &def_temp)[2]=(t4)[1]; 31 | ((unsigned char *) &def_temp)[3]=(t4)[0]; 32 | 33 | 34 | 35 | //unsigned long aa= ((unsigned long) ~0); 36 | std::cout << def_temp << "\r\n"; 37 | 38 | char *tt = (char*)t4; 39 | while(*tt) { 40 | printf("%d-", *tt++); 41 | } 42 | 43 | short aaa = 1; 44 | printf("-----%d", sizeof(aaa)); 45 | 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /win32/wing_ntdll.h: -------------------------------------------------------------------------------- 1 | #ifndef __WING_QUERY_PROCESS__ 2 | #define __WING_QUERY_PROCESS__ 3 | 4 | #define WING_ERROR_NT -1 5 | 6 | #define WING_WINDOWS_ANCIENT 0 7 | #define WING_WINDOWS_XP 51 8 | #define WING_WINDOWS_SERVER_2003 52 9 | #define WING_WINDOWS_VISTA 60 10 | #define WING_WINDOWS_7 61 11 | #define WING_WINDOWS_8 62 12 | #define WING_WINDOWS_8_1 63 13 | #define WING_WINDOWS_10 100 14 | #define WING_WINDOWS_NEW MAXLONG 15 | 16 | #include "windows.h" 17 | 18 | typedef struct _PROCESSINFO { 19 | char *process_name; 20 | char *command_line; 21 | char *file_name; 22 | char *file_path; 23 | int process_id; 24 | //int thread_id; 25 | int parent_process_id; 26 | unsigned long working_set_size; 27 | unsigned long base_priority; 28 | unsigned long thread_count ; 29 | unsigned long handle_count ; 30 | unsigned long cpu_time; 31 | } PROCESSINFO; 32 | 33 | unsigned long WingQueryProcess(PROCESSINFO *&all_process, int max_count); 34 | unsigned long WingQueryProcessByProcessID(PROCESSINFO *process_item, unsigned long process_id); 35 | int WingQueryObject(HANDLE handle); 36 | int WingWindowsVersion(); 37 | 38 | #endif -------------------------------------------------------------------------------- /tests/signal/signal.cpp: -------------------------------------------------------------------------------- 1 | // signal.cpp : 定义控制台应用程序的入口点。 2 | // https://stackoverflow.com/questions/813086/can-i-send-a-ctrl-c-sigint-to-an-application-on-windows 3 | 4 | #include "stdafx.h" 5 | #include "windows.h" 6 | #include "signal.h" 7 | 8 | void SignalHandler(int signal) 9 | { 10 | printf("thread id = %d, signal = %d\r\n", GetCurrentThreadId(), signal); 11 | } 12 | 13 | BOOL CtrlHandler(DWORD fdwCtrlType) 14 | { 15 | //CTRL_C_EVENT 16 | printf("thread id = %d, event = %d\r\n", GetCurrentThreadId(), fdwCtrlType); 17 | printf("==>%d<==\r\n", fdwCtrlType); 18 | return false; 19 | } 20 | 21 | int main() 22 | { 23 | signal(SIGABRT, SignalHandler); // 22 调用abort导致, 同一个线程内部执行 24 | signal(SIGINT, SignalHandler); // 2 Ctrl+C中断,回调函数在新的线程中执行 25 | signal(SIGTERM, SignalHandler); // 15 kill发出的软件终止 同一个线程 26 | signal(SIGBREAK, SignalHandler); // 21 Ctrl+Break中断 新的线程中执行 27 | signal(SIGILL, SignalHandler); // 4 非法指令 同一个线程内执行回调函数 28 | signal(SIGFPE, SignalHandler); // 8 浮点异常 同一个线程内执行回调函数 29 | signal(SIGSEGV, SignalHandler); // 11 段错误, 非法指针访问 同一个线程内执行回调函数 30 | 31 | //Ctrl+C 等事件均在新的线程中执行 32 | SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE); // add to list 33 | 34 | printf("thread id = %d\r\n", GetCurrentThreadId()); 35 | //abort(); 36 | //raise(8); 37 | //raise(11); 38 | 39 | while (1){ 40 | Sleep(100); 41 | } 42 | return 0; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/test2.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/embed/embed.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/signal/signal.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/setjump/setjump.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/wing_test/wing_test.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/wing_process.php: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /wing_api.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef PHP_WING_API_H 3 | #define PHP_WING_API_H 4 | 5 | #ifdef PHP_WIN32 6 | #include "php.h" 7 | #include "php_ini.h" 8 | #include "ext/standard/info.h" 9 | #include "php_wing_process.h" 10 | #endif 11 | 12 | #define MAX_ARGC 8 13 | 14 | #ifdef __APPLE__ 15 | #include 16 | #include 17 | #include 18 | #include 19 | #define pid_of(pproc) pproc->kp_proc.p_pid 20 | #include 21 | #endif 22 | 23 | char* wing_get_command_path(const char* command); 24 | int wing_file_is_php(const char *file); 25 | unsigned long wing_create_process(const char *command, char* output_file); 26 | int wing_get_process_id(); 27 | unsigned long wing_get_memory(int process_id); 28 | int wing_kill(int process_id); 29 | zval *wing_zend_read_property(zend_class_entry *scope, zval *object, const char *name); 30 | void wing_get_tmp_dir(char *buffer); 31 | void wing_get_cmdline(int process_id, char **buffer); 32 | 33 | /** 34 | * 判断文件是否存在、是否可读、可写等等 35 | * @param const char* file 文件路径 36 | * @param int mode 可直接使用系统定义的常量,可以组合使用,比如判断是否可读并且可写,传入 R_OK|W_OK 37 | 在头文件unistd.h中的预定义如下: 38 | #define R_OK 4 39 | #define W_OK 2 40 | #define X_OK 1 41 | #define F_OK 0 42 | 具体含义如下: 43 | R_OK 只判断是否有读权限 44 | W_OK 只判断是否有写权限 45 | X_OK 判断是否有执行权限 46 | F_OK 只判断是否存在 47 | 在宏定义里面分别对应: 48 | 00 只存在 49 | 02 写权限 50 | 04 读权限 51 | 06 读和写权限 52 | * @return int 0代表成功 -1代表失败,使用的时候判断 == 0 或者 == -1 、!= 0 即可 53 | */ 54 | int wing_access(const char* file, int mode) 55 | { 56 | #ifdef PHP_WIN32 57 | return _access(file, mode); 58 | #else 59 | return access(file, mode); 60 | #endif 61 | } 62 | 63 | #ifdef PHP_WIN32 64 | #include "win32/win_api.c" 65 | #else 66 | #include "linux/linux_api.c" 67 | #endif 68 | #include "wing_api.c" 69 | #endif -------------------------------------------------------------------------------- /tests/string/string/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // string 4 | // 5 | // Created by yuyi on 17/9/2. 6 | // Copyright © 2017年 yuyi. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "../../../win32/WingString.class.h" 18 | #include "../../../win32/WingString.class.cpp" 19 | 20 | int main(int argc, const char * argv[]) { 21 | // std::locale::global(std::locale("")); 22 | // setlocale(LC_CTYPE, ""); // MinGW gcc. 23 | // std::wcout.imbue(std::locale("")); 24 | // insert code here... 25 | // 根据环境变量设置locale 26 | setlocale(LC_CTYPE, "zh_CN.utf8"); 27 | std::cout << "Hello, World!\n"; 28 | 29 | WingString str1; 30 | str1.append("123"); 31 | str1.print(); 32 | 33 | // WingString str2("123",0,1); 34 | // str2.append("456"); 35 | // str2.print(); 36 | 37 | // str1.append(str2); 38 | // str1.print(); 39 | // / 40 | /* char *_str = " 123456789 "; 41 | WingString str(_str, 0, 1); 42 | printf("length:%zu\r\n", str.length()); 43 | // printf(">%s<\r\n", str.rtrim()); 44 | // printf("length:%zu\r\n", str.length()); 45 | // printf(">%s<\r\n", str.ltrim()); 46 | // printf("length:%zu\r\n", str.length()); 47 | printf(">%s<\r\n", str.trim()); 48 | printf("length:%zu\r\n", str.length()); 49 | 50 | 51 | str.append("0001", 4); 52 | str.print(); 53 | printf("length:%zu\r\n", str.length()); 54 | //printf(">%s<\r\n", str.substr(2, 2)); 55 | 56 | 57 | 58 | // wchar_t zh[100] = L"你好中国"; 59 | // std::wcsncpy(zh, L"你好中国", 100); 60 | 61 | // std::wcout << L"$$$" <%s<==", strn); 86 | 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension wing_process 3 | 4 | dnl Comments in this file start with the string 'dnl'. 5 | dnl Remove where necessary. This file will not work 6 | dnl without editing. 7 | 8 | dnl If your extension references something external, use with: 9 | 10 | PHP_ARG_WITH(wing_process, for wing_process support, 11 | dnl Make sure that the comment is aligned: 12 | [ --with-wing_process Include wing_process support]) 13 | 14 | dnl Otherwise use enable: 15 | 16 | dnl PHP_ARG_ENABLE(wing_process, whether to enable wing_process support, 17 | dnl Make sure that the comment is aligned: 18 | dnl [ --enable-wing_process Enable wing_process support]) 19 | 20 | if test "$PHP_WING_PROCESS" != "no"; then 21 | dnl Write more examples of tests here... 22 | 23 | dnl # --with-wing_process -> check with-path 24 | dnl SEARCH_PATH="/usr/local /usr" # you might want to change this 25 | dnl SEARCH_FOR="/include/wing_process.h" # you most likely want to change this 26 | dnl if test -r $PHP_WING_PROCESS/$SEARCH_FOR; then # path given as parameter 27 | dnl WING_PROCESS_DIR=$PHP_WING_PROCESS 28 | dnl else # search default path list 29 | dnl AC_MSG_CHECKING([for wing_process files in default path]) 30 | dnl for i in $SEARCH_PATH ; do 31 | dnl if test -r $i/$SEARCH_FOR; then 32 | dnl WING_PROCESS_DIR=$i 33 | dnl AC_MSG_RESULT(found in $i) 34 | dnl fi 35 | dnl done 36 | dnl fi 37 | dnl 38 | dnl if test -z "$WING_PROCESS_DIR"; then 39 | dnl AC_MSG_RESULT([not found]) 40 | dnl AC_MSG_ERROR([Please reinstall the wing_process distribution]) 41 | dnl fi 42 | 43 | dnl # --with-wing_process -> add include path 44 | dnl PHP_ADD_INCLUDE($WING_PROCESS_DIR/include) 45 | 46 | dnl # --with-wing_process -> check for lib and symbol presence 47 | dnl LIBNAME=wing_process # you may want to change this 48 | dnl LIBSYMBOL=wing_process # you most likely want to change this 49 | 50 | dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 51 | dnl [ 52 | dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $WING_PROCESS_DIR/$PHP_LIBDIR, WING_PROCESS_SHARED_LIBADD) 53 | dnl AC_DEFINE(HAVE_WING_PROCESSLIB,1,[ ]) 54 | dnl ],[ 55 | dnl AC_MSG_ERROR([wrong wing_process lib version or lib not found]) 56 | dnl ],[ 57 | dnl -L$WING_PROCESS_DIR/$PHP_LIBDIR -lm 58 | dnl ]) 59 | dnl 60 | dnl PHP_SUBST(WING_PROCESS_SHARED_LIBADD) 61 | 62 | PHP_REQUIRE_CXX() 63 | PHP_SUBST(WING_PROCESS_SHARED_LIBADD) 64 | PHP_ADD_LIBRARY(stdc++,1,WING_PROCESS_SHARED_LIBADD) 65 | PHP_NEW_EXTENSION(wing_process, wing_process.c, $ext_shared) 66 | fi 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wing\wing_process 2 | 3 | This library provides a better API to work with daemon processes on windows、mac and linux systems using PHP. 4 | 5 | 6 | ## Prototype 7 | namespace wing; 8 | class wing_process 9 | { 10 | /** 11 | * __construct only support full path like "C:/php/runer.php" or "C:/exe/some.exe" 12 | * @param string|int $mixed command or process_id 13 | */ 14 | public function __construct($mixed); 15 | 16 | /** 17 | * run as deamon process 18 | * @param string $output_file if $output_file is not empty and is a file, process will run as a daemon process 19 | * @return int process id 20 | */ 21 | public function run($output_file = ''); 22 | 23 | public function wait(); 24 | public function getProcessId(); 25 | public function getThreadId(); 26 | public function getCommandLine(); 27 | public function kill(); 28 | 29 | /** 30 | * return memory useage, unit k 31 | * @return int 32 | */ 33 | public function getMemory(); 34 | public static function getCurrentProcessId(); 35 | } 36 | 37 | ## Demo 38 | 39 | #### run.php 40 | $count = 0; 41 | while (1) { 42 | echo $count, "\r\n"; 43 | sleep(1); 44 | $count++; 45 | } 46 | 47 | #### process.php 48 | //run .php file as a deamon process 49 | $process = new \wing\wing_process(__DIR__."/run.php"); 50 | 51 | echo "process_id = ", $process->run(__DIR__."/process.log"), "\r\n"; 52 | echo "process_id = ", $process->getProcessId(), "\r\n"; 53 | echo "thread_id = ", $process->getThreadId(), "\r\n"; 54 | echo "command line = ", $process->getCommandLine(), "\r\n"; 55 | 56 | file_put_contents("process.pid", $process->getProcessId()); 57 | 58 | //var_dump($process->kill()); 59 | //$exit_code = $process->wait(); 60 | //echo "process exit code=", $exit_code, "\r\n"; 61 | 62 | /* 63 | //create process in windows by using a binary exe file 64 | $process = new wing_process("D:/Wing/Release/Wing.exe"); 65 | echo "process_id = ", $process->run(__DIR__."/Wing.log"), "\r\n"; 66 | */ 67 | 68 | 69 | #### create_process_by_pid.php 70 | //create a process by an exists process pid 71 | $process_id = file_get_contents("process.pid"); 72 | $process = new \wing\wing_process($process_id); 73 | 74 | echo "process_id = ", $process->getProcessId(), "\r\n"; 75 | echo "thread_id = ", $process->getThreadId(), "\r\n"; 76 | echo "command line = ", $process->getCommandLine(),"\r\n"; 77 | //$process->kill(); 78 | 79 | build in linux/unix/mac 80 | ```` 81 | phpize 82 | ./configure 83 | make 84 | make install 85 | ```` 86 | ### Release Dll 87 | release dlls is in the root dir /dll 88 | -------------------------------------------------------------------------------- /php_wing_process.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2016 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifndef PHP_WING_PROCESS_H 22 | #define PHP_WING_PROCESS_H 23 | 24 | extern zend_module_entry wing_process_module_entry; 25 | #define phpext_wing_process_ptr &wing_process_module_entry 26 | 27 | #define PHP_WING_PROCESS_VERSION "2.0.0" /* Replace with version number for your extension */ 28 | 29 | #ifdef PHP_WIN32 30 | # define PHP_WING_PROCESS_API __declspec(dllexport) 31 | #elif defined(__GNUC__) && __GNUC__ >= 4 32 | # define PHP_WING_PROCESS_API __attribute__ ((visibility("default"))) 33 | #else 34 | # define PHP_WING_PROCESS_API 35 | #endif 36 | 37 | #ifdef ZTS 38 | #include "TSRM.h" 39 | #endif 40 | 41 | /* 42 | Declare any global variables you may need between the BEGIN 43 | and END macros here: 44 | 45 | ZEND_BEGIN_MODULE_GLOBALS(wing_process) 46 | zend_long global_value; 47 | char *global_string; 48 | ZEND_END_MODULE_GLOBALS(wing_process) 49 | */ 50 | 51 | /* Always refer to the globals in your function as WING_PROCESS_G(variable). 52 | You are encouraged to rename these macros something shorter, see 53 | examples in any other php module directory. 54 | */ 55 | 56 | #if PHP_MAJOR_VERSION >= 7 57 | //php7 58 | #define WING_PROCESS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(wing_process, v) 59 | #if defined(ZTS) && defined(COMPILE_DL_WING_PROCESS) 60 | ZEND_TSRMLS_CACHE_EXTERN() 61 | #endif 62 | //end-php7 63 | #else 64 | 65 | //php5 66 | #ifdef ZTS 67 | #define WING_PROCESS_G(v) TSRMG(wing_process_globals_id, zend_wing_process_globals *, v) 68 | #else 69 | #define WING_PROCESS_G(v) (wing_process_globals.v) 70 | #endif 71 | //end-php5 72 | #endif 73 | 74 | #endif /* PHP_WING_PROCESS_H */ 75 | 76 | 77 | /* 78 | * Local variables: 79 | * tab-width: 4 80 | * c-basic-offset: 4 81 | * End: 82 | * vim600: noet sw=4 ts=4 fdm=marker 83 | * vim<600: noet sw=4 ts=4 84 | */ -------------------------------------------------------------------------------- /win32/WingString.class.h: -------------------------------------------------------------------------------- 1 | #ifndef __WING_STRING_H__ 2 | #define __WING_STRING_H__ 3 | #ifdef _WIN32 4 | #include "Windows.h" 5 | #endif 6 | #include 7 | #include "math.h" 8 | 9 | #define WING_STR_IS_CHAR 1 10 | #define WING_STR_IS_WCHAR 2 11 | #define WING_STR_IS_UNKNOW 3 12 | 13 | #define WING_CHAR_SIZE(str) (strlen((char*)str)+1)*sizeof(char) 14 | #define WING_WCHAR_SIZE(str) (wcslen((wchar_t*)str)+1)*sizeof(wchar_t) 15 | 16 | void wing_str_trim(char* str ,size_t size = 0); 17 | /** 18 | * need free the return value if not null 19 | */ 20 | char* wing_str_wchar_to_char(const wchar_t* str); 21 | /** 22 | * need free the return value if not null 23 | */ 24 | wchar_t* wing_str_char_to_wchar(const char* str); 25 | /** 26 | * need free the return value if not null 27 | */ 28 | char* wing_str_char_to_utf8(const char* str); 29 | /** 30 | * need free the return value if not null 31 | */ 32 | char* wing_str_wchar_to_utf8(const wchar_t* str); 33 | 34 | /** 35 | * ---- WingString ---- 36 | */ 37 | class WingString{ 38 | 39 | private: 40 | void *str; 41 | size_t str_size; 42 | unsigned int str_type; 43 | 44 | public: 45 | 46 | WingString(char *_str, size_t _size = 0); 47 | WingString(wchar_t *_str, size_t _size = 0); 48 | WingString(); 49 | ~WingString(); 50 | 51 | size_t size(); 52 | unsigned int length(); 53 | 54 | /** 55 | * need free the return value if not null 56 | */ 57 | void* copy(); 58 | 59 | void* data(); 60 | int type(); 61 | 62 | /** 63 | * need free the return value if not null 64 | */ 65 | char* c_str(); 66 | /** 67 | * need free the return value if not null 68 | */ 69 | wchar_t* w_str(); 70 | 71 | void append(const char *_str, size_t size = 0); 72 | void append(WingString &_str); 73 | void append(const wchar_t *_str,size_t size = 0); 74 | 75 | int toUTF8(); 76 | char* trim(); 77 | char* ltrim(); 78 | char* rtrim(); 79 | 80 | void print(); 81 | void savePrint(); 82 | double toNumber(); 83 | void* substr(int start,size_t length); 84 | 85 | WingString& operator=(WingString &_str); 86 | WingString& operator=(const char* _str); 87 | WingString& operator=(const wchar_t* _str); 88 | WingString& operator+(WingString &_str); 89 | WingString& operator+(const char* _str); 90 | WingString& operator+(const wchar_t* _str); 91 | WingString& operator+=(WingString &_str); 92 | WingString& operator+=(const char* _str); 93 | WingString& operator+=(const wchar_t* _str); 94 | int operator==(WingString &_str)const; 95 | int operator==(const char* _str)const; 96 | int operator==(const wchar_t* _str)const; 97 | int operator!=(WingString &_str)const; 98 | int operator!=(const char* _str)const; 99 | int operator!=(const wchar_t* _str)const; 100 | int operator>(WingString &_str)const; 101 | int operator>=(WingString &_str)const; 102 | int operator>(const char* _str)const; 103 | int operator>=(const char* _str)const; 104 | int operator>(const wchar_t* _str)const; 105 | int operator>=(const wchar_t* _str)const; 106 | int operator<(WingString &_str)const; 107 | int operator<=(WingString &_str)const; 108 | int operator<(const char* _str)const; 109 | int operator<=(const char* _str)const; 110 | int operator<(const wchar_t* _str)const; 111 | int operator<=(const wchar_t* _str)const; 112 | 113 | }; 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /tests/test/test.xcodeproj/xcuserdata/yuyi.xcuserdatad/xcschemes/test.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /tests/test1/test1.xcodeproj/xcuserdata/yuyi.xcuserdatad/xcschemes/test1.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /tests/string/string.xcodeproj/xcuserdata/yuyi.xcuserdatad/xcschemes/string.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /win32/win_api.c: -------------------------------------------------------------------------------- 1 | #include "win_api.h" 2 | /** 3 | * 获取系统临时路径 4 | * 5 | * @param char *buffer 输出结果,这里的buffer使用char数组,如: 6 | * char buffer[MAX_PATH]; 7 | * wing_get_tmp_dir(buffer); 8 | */ 9 | void wing_get_tmp_dir(char *buffer) 10 | { 11 | GetTempPath(MAX_PATH, buffer); 12 | if (0 != wing_access(buffer, W_OK)) { 13 | buffer = NULL; 14 | return; 15 | } 16 | 17 | strcpy((char*)(buffer+strlen(buffer)), "/wing_process"); 18 | 19 | if (0 == wing_access(buffer, F_OK)) { 20 | return; 21 | } 22 | 23 | if (0 == mkdir(buffer, 0777)) { 24 | return; 25 | } 26 | buffer = NULL; 27 | return; 28 | } 29 | 30 | /** 31 | * @todo 获取进程占用内存 32 | * @param int process_id 33 | * @return int 单位为k 34 | */ 35 | unsigned long get_memory(int process_id) 36 | { 37 | return 0; 38 | } 39 | 40 | /** 41 | * 获取php完整的路径 42 | * 43 | * @param const char* command(这里的参数只是一个伪参数,仅为了与各平台的api统一) 44 | * @return char* 堆内存,需要手动free,如: 45 | * char *pap_path = wing_get_command_path("php"); 46 | * ... //其他操作 47 | * free(php_path); 48 | */ 49 | char* wing_get_command_path(const char* command) 50 | { 51 | char *PHP_PATH = (char*)malloc(MAX_PATH); 52 | memset(PHP_PATH, 0, MAX_PATH); 53 | GetModuleFileName(NULL, PHP_PATH, MAX_PATH); 54 | 55 | return PHP_PATH; 56 | } 57 | 58 | /** 59 | * 获取当前进程id 60 | * 61 | * @return int 62 | */ 63 | int wing_get_process_id() 64 | { 65 | return GetCurrentProcessId(); 66 | } 67 | 68 | /** 69 | * @todo 杀死进程 70 | * @param int process_id 71 | * @return int 0成功 -1失败 72 | */ 73 | int wing_kill(int process_id) 74 | { 75 | return 0; 76 | } 77 | 78 | /** 79 | * 创建一个新的进程 80 | * 81 | * @param const char *command 需要以守护进程运行的指令 82 | * @param char* output_file 输出重定向到文件,如果不等于NULL,则认为是以守护方式运行 83 | * @return unsigned long PROCESS_INFORMATION结构体指针(linux下返回进程id) 84 | */ 85 | unsigned long wing_create_process(const char *command, char* output_file) 86 | { 87 | int redirect_output = output_file == NULL ? 0 : 1; 88 | STARTUPINFO sui; 89 | PROCESS_INFORMATION *pi = new PROCESS_INFORMATION(); 90 | SECURITY_ATTRIBUTES sa; 91 | 92 | sa.bInheritHandle = TRUE; 93 | sa.lpSecurityDescriptor = NULL; 94 | sa.nLength = sizeof(SECURITY_ATTRIBUTES); 95 | 96 | SECURITY_ATTRIBUTES *psa = NULL; 97 | DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; 98 | OSVERSIONINFO osVersion = { 0 }; 99 | osVersion.dwOSVersionInfoSize = sizeof(osVersion); 100 | 101 | if (GetVersionEx(&osVersion)) { 102 | if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) { 103 | psa = &sa; 104 | dwShareMode |= FILE_SHARE_DELETE; 105 | } 106 | } 107 | 108 | HANDLE hConsoleRedirect = CreateFile( 109 | output_file, 110 | GENERIC_WRITE, 111 | dwShareMode, 112 | psa, 113 | OPEN_ALWAYS, 114 | FILE_ATTRIBUTE_NORMAL, 115 | NULL 116 | ); 117 | SetLastError(0); 118 | ZeroMemory(&sui, sizeof(STARTUPINFO)); // ???????????????????ZeroMemory, ????????????memset 119 | 120 | sui.cb = sizeof(STARTUPINFO); 121 | sui.dwFlags = STARTF_USESTDHANDLES; 122 | sui.hStdInput = NULL;//m_hRead; 123 | sui.hStdOutput = hConsoleRedirect;//m_hWrite; 124 | sui.hStdError = hConsoleRedirect;//GetStdHandle(STD_ERROR_HANDLE); 125 | //sui.wShowWindow = SW_SHOW; 126 | if (!redirect_output) { 127 | sui.dwFlags = STARTF_USESHOWWINDOW;// | STARTF_USESTDHANDLES;; 128 | } 129 | 130 | /* 131 | if (params_len >0) { 132 | DWORD byteWrite = 0; 133 | if (::WriteFile( m_hWrite, params, params_len, &byteWrite, NULL ) == FALSE) { 134 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "write data to process error"); 135 | } 136 | } 137 | */ 138 | 139 | if (!CreateProcessA(NULL, (LPSTR)command, NULL, NULL, TRUE, 0, NULL, NULL, &sui, pi)) { 140 | CloseHandle(hConsoleRedirect); 141 | return 0; 142 | } 143 | 144 | CloseHandle(hConsoleRedirect); 145 | return (unsigned long)pi; 146 | } -------------------------------------------------------------------------------- /tests/read.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #define MAX_PATH 255 7 | 8 | void wing_get_tmp_dir(char *buffer) 9 | { 10 | const char* tmp = "/tmp"; 11 | if(0 != access(tmp, W_OK)) { 12 | buffer = NULL; 13 | return; 14 | } 15 | 16 | const char* tmp_wing = "/tmp/wing_process"; 17 | if (0 == access(tmp_wing, F_OK)) { 18 | strcpy(buffer, tmp_wing); 19 | return; 20 | } 21 | 22 | if (0 == mkdir(tmp_wing, 0777)) { 23 | strcpy(buffer, tmp_wing); 24 | return; 25 | } 26 | buffer = NULL; 27 | return; 28 | } 29 | void wing_get_cmdline(int process_id, char **buffer) 30 | { 31 | *buffer = NULL; 32 | char file[MAX_PATH] = {0}; 33 | sprintf(file, "/proc/%d/cmdline", process_id); 34 | if (access(file, R_OK) != 0) { 35 | return; 36 | } 37 | 38 | 39 | FILE *handle = fopen((const char*)file, "r"); 40 | if (!handle) { 41 | *buffer = NULL; 42 | return; 43 | } 44 | 45 | // fseek(handle, 0L, SEEK_END); 46 | int filesize = 0;//ftell(handle); 47 | while(!feof(handle)){ 48 | getc(handle);filesize++; 49 | } 50 | // if (filesize <= 0) { 51 | // fclose(handle); 52 | // return; 53 | // } 54 | rewind(handle); 55 | 56 | *buffer = (char*)malloc(filesize+1); 57 | if (*buffer == NULL) { 58 | fclose(handle); 59 | return; 60 | } 61 | memset(*buffer,0,filesize+1); 62 | 63 | int c; 64 | char *cs; 65 | cs = *buffer; 66 | 67 | while(!feof(handle)) { 68 | c = getc(handle); 69 | if (!c || c == NULL || c < 32) { 70 | c = ' '; 71 | } 72 | *cs++ = c; 73 | } 74 | *cs='\0'; 75 | fclose(handle); 76 | 77 | } 78 | 79 | int wing_file_is_php(const char *file) 80 | { 81 | 82 | char find_str[] = " "; 83 | char path[MAX_PATH] = {0}; 84 | 85 | char *find = strstr(file, find_str); 86 | if (find != NULL) 87 | strncpy((char*)path, file, (size_t)(find-file)); 88 | else 89 | strcpy((char*)path, file); 90 | 91 | FILE *handle = fopen(path, "r"); 92 | if (!handle) { 93 | return 0; 94 | } 95 | //char *find = NULL; 96 | char line[8] = { 0 }; 97 | memset(line, 0, 8); 98 | fgets(line, 7, handle); 99 | 100 | find = strstr(line, " 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {15A46431-013F-4BD2-8528-03E04563B4C3} 23 | Win32Proj 24 | signal 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Use 87 | Level3 88 | Disabled 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Use 100 | Level3 101 | Disabled 102 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 103 | true 104 | 105 | 106 | Console 107 | true 108 | 109 | 110 | 111 | 112 | Level3 113 | Use 114 | MaxSpeed 115 | true 116 | true 117 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | true 124 | true 125 | 126 | 127 | 128 | 129 | Level3 130 | Use 131 | MaxSpeed 132 | true 133 | true 134 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 135 | true 136 | 137 | 138 | Console 139 | true 140 | true 141 | true 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | Create 155 | Create 156 | Create 157 | Create 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /tests/wing_test/wing_test.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {B4CA3D7D-1654-4518-868D-D8927E5A2292} 23 | Win32Proj 24 | wing_test 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Use 87 | Level3 88 | Disabled 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Use 100 | Level3 101 | Disabled 102 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 103 | true 104 | 105 | 106 | Console 107 | true 108 | 109 | 110 | 111 | 112 | Level3 113 | Use 114 | MaxSpeed 115 | true 116 | true 117 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | true 124 | true 125 | 126 | 127 | 128 | 129 | Level3 130 | Use 131 | MaxSpeed 132 | true 133 | true 134 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 135 | true 136 | CompileAsCpp 137 | /D _CRT_SECURE_NO_WARNINGS %(AdditionalOptions) 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | Create 156 | Create 157 | Create 158 | Create 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /tests/setjump/setjump.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {4EBFA65C-DAD4-483A-B734-EB77E1612103} 23 | Win32Proj 24 | setjump 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Use 87 | Level3 88 | Disabled 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Use 100 | Level3 101 | Disabled 102 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 103 | true 104 | /D "_CRT_SECURE_NO_DEPRECATE" %(AdditionalOptions) 105 | 106 | 107 | Console 108 | true 109 | 110 | 111 | 112 | 113 | Level3 114 | Use 115 | MaxSpeed 116 | true 117 | true 118 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 119 | true 120 | 121 | 122 | Console 123 | true 124 | true 125 | true 126 | 127 | 128 | 129 | 130 | TurnOffAllWarnings 131 | Use 132 | MaxSpeed 133 | true 134 | true 135 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | true 137 | /D "_CRT_SECURE_NO_DEPRECATE" %(AdditionalOptions) 138 | 139 | 140 | Console 141 | true 142 | true 143 | true 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | Create 157 | Create 158 | Create 159 | Create 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /tests/test/test.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | FE8445111F4E491B0022A2D4 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE8445101F4E491B0022A2D4 /* main.cpp */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | FE84450B1F4E491B0022A2D4 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = /usr/share/man/man1/; 18 | dstSubfolderSpec = 0; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 1; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | FE84450D1F4E491B0022A2D4 /* test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | FE8445101F4E491B0022A2D4 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | FE84450A1F4E491B0022A2D4 /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | FE8445041F4E491B0022A2D4 = { 42 | isa = PBXGroup; 43 | children = ( 44 | FE84450F1F4E491B0022A2D4 /* test */, 45 | FE84450E1F4E491B0022A2D4 /* Products */, 46 | ); 47 | sourceTree = ""; 48 | }; 49 | FE84450E1F4E491B0022A2D4 /* Products */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | FE84450D1F4E491B0022A2D4 /* test */, 53 | ); 54 | name = Products; 55 | sourceTree = ""; 56 | }; 57 | FE84450F1F4E491B0022A2D4 /* test */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | FE8445101F4E491B0022A2D4 /* main.cpp */, 61 | ); 62 | path = test; 63 | sourceTree = ""; 64 | }; 65 | /* End PBXGroup section */ 66 | 67 | /* Begin PBXNativeTarget section */ 68 | FE84450C1F4E491B0022A2D4 /* test */ = { 69 | isa = PBXNativeTarget; 70 | buildConfigurationList = FE8445141F4E491B0022A2D4 /* Build configuration list for PBXNativeTarget "test" */; 71 | buildPhases = ( 72 | FE8445091F4E491B0022A2D4 /* Sources */, 73 | FE84450A1F4E491B0022A2D4 /* Frameworks */, 74 | FE84450B1F4E491B0022A2D4 /* CopyFiles */, 75 | ); 76 | buildRules = ( 77 | ); 78 | dependencies = ( 79 | ); 80 | name = test; 81 | productName = test; 82 | productReference = FE84450D1F4E491B0022A2D4 /* test */; 83 | productType = "com.apple.product-type.tool"; 84 | }; 85 | /* End PBXNativeTarget section */ 86 | 87 | /* Begin PBXProject section */ 88 | FE8445051F4E491B0022A2D4 /* Project object */ = { 89 | isa = PBXProject; 90 | attributes = { 91 | LastUpgradeCheck = 0810; 92 | ORGANIZATIONNAME = yuyi; 93 | TargetAttributes = { 94 | FE84450C1F4E491B0022A2D4 = { 95 | CreatedOnToolsVersion = 8.1; 96 | ProvisioningStyle = Automatic; 97 | }; 98 | }; 99 | }; 100 | buildConfigurationList = FE8445081F4E491B0022A2D4 /* Build configuration list for PBXProject "test" */; 101 | compatibilityVersion = "Xcode 3.2"; 102 | developmentRegion = English; 103 | hasScannedForEncodings = 0; 104 | knownRegions = ( 105 | en, 106 | ); 107 | mainGroup = FE8445041F4E491B0022A2D4; 108 | productRefGroup = FE84450E1F4E491B0022A2D4 /* Products */; 109 | projectDirPath = ""; 110 | projectRoot = ""; 111 | targets = ( 112 | FE84450C1F4E491B0022A2D4 /* test */, 113 | ); 114 | }; 115 | /* End PBXProject section */ 116 | 117 | /* Begin PBXSourcesBuildPhase section */ 118 | FE8445091F4E491B0022A2D4 /* Sources */ = { 119 | isa = PBXSourcesBuildPhase; 120 | buildActionMask = 2147483647; 121 | files = ( 122 | FE8445111F4E491B0022A2D4 /* main.cpp in Sources */, 123 | ); 124 | runOnlyForDeploymentPostprocessing = 0; 125 | }; 126 | /* End PBXSourcesBuildPhase section */ 127 | 128 | /* Begin XCBuildConfiguration section */ 129 | FE8445121F4E491B0022A2D4 /* Debug */ = { 130 | isa = XCBuildConfiguration; 131 | buildSettings = { 132 | ALWAYS_SEARCH_USER_PATHS = NO; 133 | CLANG_ANALYZER_NONNULL = YES; 134 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 135 | CLANG_CXX_LIBRARY = "libc++"; 136 | CLANG_ENABLE_MODULES = YES; 137 | CLANG_ENABLE_OBJC_ARC = YES; 138 | CLANG_WARN_BOOL_CONVERSION = YES; 139 | CLANG_WARN_CONSTANT_CONVERSION = YES; 140 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 141 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 142 | CLANG_WARN_EMPTY_BODY = YES; 143 | CLANG_WARN_ENUM_CONVERSION = YES; 144 | CLANG_WARN_INFINITE_RECURSION = YES; 145 | CLANG_WARN_INT_CONVERSION = YES; 146 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 147 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 148 | CLANG_WARN_UNREACHABLE_CODE = YES; 149 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 150 | CODE_SIGN_IDENTITY = "-"; 151 | COPY_PHASE_STRIP = NO; 152 | DEBUG_INFORMATION_FORMAT = dwarf; 153 | ENABLE_STRICT_OBJC_MSGSEND = YES; 154 | ENABLE_TESTABILITY = YES; 155 | GCC_C_LANGUAGE_STANDARD = gnu99; 156 | GCC_DYNAMIC_NO_PIC = NO; 157 | GCC_NO_COMMON_BLOCKS = YES; 158 | GCC_OPTIMIZATION_LEVEL = 0; 159 | GCC_PREPROCESSOR_DEFINITIONS = ( 160 | "DEBUG=1", 161 | "$(inherited)", 162 | ); 163 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 164 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 165 | GCC_WARN_UNDECLARED_SELECTOR = YES; 166 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 167 | GCC_WARN_UNUSED_FUNCTION = YES; 168 | GCC_WARN_UNUSED_VARIABLE = YES; 169 | MACOSX_DEPLOYMENT_TARGET = 10.11; 170 | MTL_ENABLE_DEBUG_INFO = YES; 171 | ONLY_ACTIVE_ARCH = YES; 172 | SDKROOT = macosx; 173 | }; 174 | name = Debug; 175 | }; 176 | FE8445131F4E491B0022A2D4 /* Release */ = { 177 | isa = XCBuildConfiguration; 178 | buildSettings = { 179 | ALWAYS_SEARCH_USER_PATHS = NO; 180 | CLANG_ANALYZER_NONNULL = YES; 181 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 182 | CLANG_CXX_LIBRARY = "libc++"; 183 | CLANG_ENABLE_MODULES = YES; 184 | CLANG_ENABLE_OBJC_ARC = YES; 185 | CLANG_WARN_BOOL_CONVERSION = YES; 186 | CLANG_WARN_CONSTANT_CONVERSION = YES; 187 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 188 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 189 | CLANG_WARN_EMPTY_BODY = YES; 190 | CLANG_WARN_ENUM_CONVERSION = YES; 191 | CLANG_WARN_INFINITE_RECURSION = YES; 192 | CLANG_WARN_INT_CONVERSION = YES; 193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 194 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 195 | CLANG_WARN_UNREACHABLE_CODE = YES; 196 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 197 | CODE_SIGN_IDENTITY = "-"; 198 | COPY_PHASE_STRIP = NO; 199 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 200 | ENABLE_NS_ASSERTIONS = NO; 201 | ENABLE_STRICT_OBJC_MSGSEND = YES; 202 | GCC_C_LANGUAGE_STANDARD = gnu99; 203 | GCC_NO_COMMON_BLOCKS = YES; 204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 205 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 206 | GCC_WARN_UNDECLARED_SELECTOR = YES; 207 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 208 | GCC_WARN_UNUSED_FUNCTION = YES; 209 | GCC_WARN_UNUSED_VARIABLE = YES; 210 | MACOSX_DEPLOYMENT_TARGET = 10.11; 211 | MTL_ENABLE_DEBUG_INFO = NO; 212 | SDKROOT = macosx; 213 | }; 214 | name = Release; 215 | }; 216 | FE8445151F4E491B0022A2D4 /* Debug */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | PRODUCT_NAME = "$(TARGET_NAME)"; 220 | }; 221 | name = Debug; 222 | }; 223 | FE8445161F4E491B0022A2D4 /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | PRODUCT_NAME = "$(TARGET_NAME)"; 227 | }; 228 | name = Release; 229 | }; 230 | /* End XCBuildConfiguration section */ 231 | 232 | /* Begin XCConfigurationList section */ 233 | FE8445081F4E491B0022A2D4 /* Build configuration list for PBXProject "test" */ = { 234 | isa = XCConfigurationList; 235 | buildConfigurations = ( 236 | FE8445121F4E491B0022A2D4 /* Debug */, 237 | FE8445131F4E491B0022A2D4 /* Release */, 238 | ); 239 | defaultConfigurationIsVisible = 0; 240 | defaultConfigurationName = Release; 241 | }; 242 | FE8445141F4E491B0022A2D4 /* Build configuration list for PBXNativeTarget "test" */ = { 243 | isa = XCConfigurationList; 244 | buildConfigurations = ( 245 | FE8445151F4E491B0022A2D4 /* Debug */, 246 | FE8445161F4E491B0022A2D4 /* Release */, 247 | ); 248 | defaultConfigurationIsVisible = 0; 249 | }; 250 | /* End XCConfigurationList section */ 251 | }; 252 | rootObject = FE8445051F4E491B0022A2D4 /* Project object */; 253 | } 254 | -------------------------------------------------------------------------------- /tests/test1/test1.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | FEAA57B11F6EC3F500029325 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEAA57B01F6EC3F500029325 /* main.cpp */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | FEAA57AB1F6EC3F500029325 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = /usr/share/man/man1/; 18 | dstSubfolderSpec = 0; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 1; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | FEAA57AD1F6EC3F500029325 /* test1 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test1; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | FEAA57B01F6EC3F500029325 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | FEAA57AA1F6EC3F500029325 /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | FEAA57A41F6EC3F500029325 = { 42 | isa = PBXGroup; 43 | children = ( 44 | FEAA57AF1F6EC3F500029325 /* test1 */, 45 | FEAA57AE1F6EC3F500029325 /* Products */, 46 | ); 47 | sourceTree = ""; 48 | }; 49 | FEAA57AE1F6EC3F500029325 /* Products */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | FEAA57AD1F6EC3F500029325 /* test1 */, 53 | ); 54 | name = Products; 55 | sourceTree = ""; 56 | }; 57 | FEAA57AF1F6EC3F500029325 /* test1 */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | FEAA57B01F6EC3F500029325 /* main.cpp */, 61 | ); 62 | path = test1; 63 | sourceTree = ""; 64 | }; 65 | /* End PBXGroup section */ 66 | 67 | /* Begin PBXNativeTarget section */ 68 | FEAA57AC1F6EC3F500029325 /* test1 */ = { 69 | isa = PBXNativeTarget; 70 | buildConfigurationList = FEAA57B41F6EC3F500029325 /* Build configuration list for PBXNativeTarget "test1" */; 71 | buildPhases = ( 72 | FEAA57A91F6EC3F500029325 /* Sources */, 73 | FEAA57AA1F6EC3F500029325 /* Frameworks */, 74 | FEAA57AB1F6EC3F500029325 /* CopyFiles */, 75 | ); 76 | buildRules = ( 77 | ); 78 | dependencies = ( 79 | ); 80 | name = test1; 81 | productName = test1; 82 | productReference = FEAA57AD1F6EC3F500029325 /* test1 */; 83 | productType = "com.apple.product-type.tool"; 84 | }; 85 | /* End PBXNativeTarget section */ 86 | 87 | /* Begin PBXProject section */ 88 | FEAA57A51F6EC3F500029325 /* Project object */ = { 89 | isa = PBXProject; 90 | attributes = { 91 | LastUpgradeCheck = 0810; 92 | ORGANIZATIONNAME = yuyi; 93 | TargetAttributes = { 94 | FEAA57AC1F6EC3F500029325 = { 95 | CreatedOnToolsVersion = 8.1; 96 | ProvisioningStyle = Automatic; 97 | }; 98 | }; 99 | }; 100 | buildConfigurationList = FEAA57A81F6EC3F500029325 /* Build configuration list for PBXProject "test1" */; 101 | compatibilityVersion = "Xcode 3.2"; 102 | developmentRegion = English; 103 | hasScannedForEncodings = 0; 104 | knownRegions = ( 105 | en, 106 | ); 107 | mainGroup = FEAA57A41F6EC3F500029325; 108 | productRefGroup = FEAA57AE1F6EC3F500029325 /* Products */; 109 | projectDirPath = ""; 110 | projectRoot = ""; 111 | targets = ( 112 | FEAA57AC1F6EC3F500029325 /* test1 */, 113 | ); 114 | }; 115 | /* End PBXProject section */ 116 | 117 | /* Begin PBXSourcesBuildPhase section */ 118 | FEAA57A91F6EC3F500029325 /* Sources */ = { 119 | isa = PBXSourcesBuildPhase; 120 | buildActionMask = 2147483647; 121 | files = ( 122 | FEAA57B11F6EC3F500029325 /* main.cpp in Sources */, 123 | ); 124 | runOnlyForDeploymentPostprocessing = 0; 125 | }; 126 | /* End PBXSourcesBuildPhase section */ 127 | 128 | /* Begin XCBuildConfiguration section */ 129 | FEAA57B21F6EC3F500029325 /* Debug */ = { 130 | isa = XCBuildConfiguration; 131 | buildSettings = { 132 | ALWAYS_SEARCH_USER_PATHS = NO; 133 | CLANG_ANALYZER_NONNULL = YES; 134 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 135 | CLANG_CXX_LIBRARY = "libc++"; 136 | CLANG_ENABLE_MODULES = YES; 137 | CLANG_ENABLE_OBJC_ARC = YES; 138 | CLANG_WARN_BOOL_CONVERSION = YES; 139 | CLANG_WARN_CONSTANT_CONVERSION = YES; 140 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 141 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 142 | CLANG_WARN_EMPTY_BODY = YES; 143 | CLANG_WARN_ENUM_CONVERSION = YES; 144 | CLANG_WARN_INFINITE_RECURSION = YES; 145 | CLANG_WARN_INT_CONVERSION = YES; 146 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 147 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 148 | CLANG_WARN_UNREACHABLE_CODE = YES; 149 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 150 | CODE_SIGN_IDENTITY = "-"; 151 | COPY_PHASE_STRIP = NO; 152 | DEBUG_INFORMATION_FORMAT = dwarf; 153 | ENABLE_STRICT_OBJC_MSGSEND = YES; 154 | ENABLE_TESTABILITY = YES; 155 | GCC_C_LANGUAGE_STANDARD = gnu99; 156 | GCC_DYNAMIC_NO_PIC = NO; 157 | GCC_NO_COMMON_BLOCKS = YES; 158 | GCC_OPTIMIZATION_LEVEL = 0; 159 | GCC_PREPROCESSOR_DEFINITIONS = ( 160 | "DEBUG=1", 161 | "$(inherited)", 162 | ); 163 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 164 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 165 | GCC_WARN_UNDECLARED_SELECTOR = YES; 166 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 167 | GCC_WARN_UNUSED_FUNCTION = YES; 168 | GCC_WARN_UNUSED_VARIABLE = YES; 169 | MACOSX_DEPLOYMENT_TARGET = 10.11; 170 | MTL_ENABLE_DEBUG_INFO = YES; 171 | ONLY_ACTIVE_ARCH = YES; 172 | SDKROOT = macosx; 173 | }; 174 | name = Debug; 175 | }; 176 | FEAA57B31F6EC3F500029325 /* Release */ = { 177 | isa = XCBuildConfiguration; 178 | buildSettings = { 179 | ALWAYS_SEARCH_USER_PATHS = NO; 180 | CLANG_ANALYZER_NONNULL = YES; 181 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 182 | CLANG_CXX_LIBRARY = "libc++"; 183 | CLANG_ENABLE_MODULES = YES; 184 | CLANG_ENABLE_OBJC_ARC = YES; 185 | CLANG_WARN_BOOL_CONVERSION = YES; 186 | CLANG_WARN_CONSTANT_CONVERSION = YES; 187 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 188 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 189 | CLANG_WARN_EMPTY_BODY = YES; 190 | CLANG_WARN_ENUM_CONVERSION = YES; 191 | CLANG_WARN_INFINITE_RECURSION = YES; 192 | CLANG_WARN_INT_CONVERSION = YES; 193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 194 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 195 | CLANG_WARN_UNREACHABLE_CODE = YES; 196 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 197 | CODE_SIGN_IDENTITY = "-"; 198 | COPY_PHASE_STRIP = NO; 199 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 200 | ENABLE_NS_ASSERTIONS = NO; 201 | ENABLE_STRICT_OBJC_MSGSEND = YES; 202 | GCC_C_LANGUAGE_STANDARD = gnu99; 203 | GCC_NO_COMMON_BLOCKS = YES; 204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 205 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 206 | GCC_WARN_UNDECLARED_SELECTOR = YES; 207 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 208 | GCC_WARN_UNUSED_FUNCTION = YES; 209 | GCC_WARN_UNUSED_VARIABLE = YES; 210 | MACOSX_DEPLOYMENT_TARGET = 10.11; 211 | MTL_ENABLE_DEBUG_INFO = NO; 212 | SDKROOT = macosx; 213 | }; 214 | name = Release; 215 | }; 216 | FEAA57B51F6EC3F500029325 /* Debug */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | PRODUCT_NAME = "$(TARGET_NAME)"; 220 | }; 221 | name = Debug; 222 | }; 223 | FEAA57B61F6EC3F500029325 /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | PRODUCT_NAME = "$(TARGET_NAME)"; 227 | }; 228 | name = Release; 229 | }; 230 | /* End XCBuildConfiguration section */ 231 | 232 | /* Begin XCConfigurationList section */ 233 | FEAA57A81F6EC3F500029325 /* Build configuration list for PBXProject "test1" */ = { 234 | isa = XCConfigurationList; 235 | buildConfigurations = ( 236 | FEAA57B21F6EC3F500029325 /* Debug */, 237 | FEAA57B31F6EC3F500029325 /* Release */, 238 | ); 239 | defaultConfigurationIsVisible = 0; 240 | defaultConfigurationName = Release; 241 | }; 242 | FEAA57B41F6EC3F500029325 /* Build configuration list for PBXNativeTarget "test1" */ = { 243 | isa = XCConfigurationList; 244 | buildConfigurations = ( 245 | FEAA57B51F6EC3F500029325 /* Debug */, 246 | FEAA57B61F6EC3F500029325 /* Release */, 247 | ); 248 | defaultConfigurationIsVisible = 0; 249 | }; 250 | /* End XCConfigurationList section */ 251 | }; 252 | rootObject = FEAA57A51F6EC3F500029325 /* Project object */; 253 | } 254 | -------------------------------------------------------------------------------- /tests/string/string.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | FE62602E1F5AAC48001404F0 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE62602D1F5AAC48001404F0 /* main.cpp */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | FE6260281F5AAC48001404F0 /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = /usr/share/man/man1/; 18 | dstSubfolderSpec = 0; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 1; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | FE62602A1F5AAC48001404F0 /* string */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = string; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | FE62602D1F5AAC48001404F0 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | FE6260271F5AAC48001404F0 /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | FE6260211F5AAC47001404F0 = { 42 | isa = PBXGroup; 43 | children = ( 44 | FE62602C1F5AAC48001404F0 /* string */, 45 | FE62602B1F5AAC48001404F0 /* Products */, 46 | ); 47 | sourceTree = ""; 48 | }; 49 | FE62602B1F5AAC48001404F0 /* Products */ = { 50 | isa = PBXGroup; 51 | children = ( 52 | FE62602A1F5AAC48001404F0 /* string */, 53 | ); 54 | name = Products; 55 | sourceTree = ""; 56 | }; 57 | FE62602C1F5AAC48001404F0 /* string */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | FE62602D1F5AAC48001404F0 /* main.cpp */, 61 | ); 62 | path = string; 63 | sourceTree = ""; 64 | }; 65 | /* End PBXGroup section */ 66 | 67 | /* Begin PBXNativeTarget section */ 68 | FE6260291F5AAC48001404F0 /* string */ = { 69 | isa = PBXNativeTarget; 70 | buildConfigurationList = FE6260311F5AAC48001404F0 /* Build configuration list for PBXNativeTarget "string" */; 71 | buildPhases = ( 72 | FE6260261F5AAC48001404F0 /* Sources */, 73 | FE6260271F5AAC48001404F0 /* Frameworks */, 74 | FE6260281F5AAC48001404F0 /* CopyFiles */, 75 | ); 76 | buildRules = ( 77 | ); 78 | dependencies = ( 79 | ); 80 | name = string; 81 | productName = string; 82 | productReference = FE62602A1F5AAC48001404F0 /* string */; 83 | productType = "com.apple.product-type.tool"; 84 | }; 85 | /* End PBXNativeTarget section */ 86 | 87 | /* Begin PBXProject section */ 88 | FE6260221F5AAC47001404F0 /* Project object */ = { 89 | isa = PBXProject; 90 | attributes = { 91 | LastUpgradeCheck = 0810; 92 | ORGANIZATIONNAME = yuyi; 93 | TargetAttributes = { 94 | FE6260291F5AAC48001404F0 = { 95 | CreatedOnToolsVersion = 8.1; 96 | ProvisioningStyle = Automatic; 97 | }; 98 | }; 99 | }; 100 | buildConfigurationList = FE6260251F5AAC47001404F0 /* Build configuration list for PBXProject "string" */; 101 | compatibilityVersion = "Xcode 3.2"; 102 | developmentRegion = English; 103 | hasScannedForEncodings = 0; 104 | knownRegions = ( 105 | en, 106 | ); 107 | mainGroup = FE6260211F5AAC47001404F0; 108 | productRefGroup = FE62602B1F5AAC48001404F0 /* Products */; 109 | projectDirPath = ""; 110 | projectRoot = ""; 111 | targets = ( 112 | FE6260291F5AAC48001404F0 /* string */, 113 | ); 114 | }; 115 | /* End PBXProject section */ 116 | 117 | /* Begin PBXSourcesBuildPhase section */ 118 | FE6260261F5AAC48001404F0 /* Sources */ = { 119 | isa = PBXSourcesBuildPhase; 120 | buildActionMask = 2147483647; 121 | files = ( 122 | FE62602E1F5AAC48001404F0 /* main.cpp in Sources */, 123 | ); 124 | runOnlyForDeploymentPostprocessing = 0; 125 | }; 126 | /* End PBXSourcesBuildPhase section */ 127 | 128 | /* Begin XCBuildConfiguration section */ 129 | FE62602F1F5AAC48001404F0 /* Debug */ = { 130 | isa = XCBuildConfiguration; 131 | buildSettings = { 132 | ALWAYS_SEARCH_USER_PATHS = NO; 133 | CLANG_ANALYZER_NONNULL = YES; 134 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 135 | CLANG_CXX_LIBRARY = "libc++"; 136 | CLANG_ENABLE_MODULES = YES; 137 | CLANG_ENABLE_OBJC_ARC = YES; 138 | CLANG_WARN_BOOL_CONVERSION = YES; 139 | CLANG_WARN_CONSTANT_CONVERSION = YES; 140 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 141 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 142 | CLANG_WARN_EMPTY_BODY = YES; 143 | CLANG_WARN_ENUM_CONVERSION = YES; 144 | CLANG_WARN_INFINITE_RECURSION = YES; 145 | CLANG_WARN_INT_CONVERSION = YES; 146 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 147 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 148 | CLANG_WARN_UNREACHABLE_CODE = YES; 149 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 150 | CODE_SIGN_IDENTITY = "-"; 151 | COPY_PHASE_STRIP = NO; 152 | DEBUG_INFORMATION_FORMAT = dwarf; 153 | ENABLE_STRICT_OBJC_MSGSEND = YES; 154 | ENABLE_TESTABILITY = YES; 155 | GCC_C_LANGUAGE_STANDARD = gnu99; 156 | GCC_DYNAMIC_NO_PIC = NO; 157 | GCC_NO_COMMON_BLOCKS = YES; 158 | GCC_OPTIMIZATION_LEVEL = 0; 159 | GCC_PREPROCESSOR_DEFINITIONS = ( 160 | "DEBUG=1", 161 | "$(inherited)", 162 | ); 163 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 164 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 165 | GCC_WARN_UNDECLARED_SELECTOR = YES; 166 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 167 | GCC_WARN_UNUSED_FUNCTION = YES; 168 | GCC_WARN_UNUSED_VARIABLE = YES; 169 | MACOSX_DEPLOYMENT_TARGET = 10.11; 170 | MTL_ENABLE_DEBUG_INFO = YES; 171 | ONLY_ACTIVE_ARCH = YES; 172 | SDKROOT = macosx; 173 | }; 174 | name = Debug; 175 | }; 176 | FE6260301F5AAC48001404F0 /* Release */ = { 177 | isa = XCBuildConfiguration; 178 | buildSettings = { 179 | ALWAYS_SEARCH_USER_PATHS = NO; 180 | CLANG_ANALYZER_NONNULL = YES; 181 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 182 | CLANG_CXX_LIBRARY = "libc++"; 183 | CLANG_ENABLE_MODULES = YES; 184 | CLANG_ENABLE_OBJC_ARC = YES; 185 | CLANG_WARN_BOOL_CONVERSION = YES; 186 | CLANG_WARN_CONSTANT_CONVERSION = YES; 187 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 188 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 189 | CLANG_WARN_EMPTY_BODY = YES; 190 | CLANG_WARN_ENUM_CONVERSION = YES; 191 | CLANG_WARN_INFINITE_RECURSION = YES; 192 | CLANG_WARN_INT_CONVERSION = YES; 193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 194 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 195 | CLANG_WARN_UNREACHABLE_CODE = YES; 196 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 197 | CODE_SIGN_IDENTITY = "-"; 198 | COPY_PHASE_STRIP = NO; 199 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 200 | ENABLE_NS_ASSERTIONS = NO; 201 | ENABLE_STRICT_OBJC_MSGSEND = YES; 202 | GCC_C_LANGUAGE_STANDARD = gnu99; 203 | GCC_NO_COMMON_BLOCKS = YES; 204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 205 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 206 | GCC_WARN_UNDECLARED_SELECTOR = YES; 207 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 208 | GCC_WARN_UNUSED_FUNCTION = YES; 209 | GCC_WARN_UNUSED_VARIABLE = YES; 210 | MACOSX_DEPLOYMENT_TARGET = 10.11; 211 | MTL_ENABLE_DEBUG_INFO = NO; 212 | SDKROOT = macosx; 213 | }; 214 | name = Release; 215 | }; 216 | FE6260321F5AAC48001404F0 /* Debug */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | PRODUCT_NAME = "$(TARGET_NAME)"; 220 | }; 221 | name = Debug; 222 | }; 223 | FE6260331F5AAC48001404F0 /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | PRODUCT_NAME = "$(TARGET_NAME)"; 227 | }; 228 | name = Release; 229 | }; 230 | /* End XCBuildConfiguration section */ 231 | 232 | /* Begin XCConfigurationList section */ 233 | FE6260251F5AAC47001404F0 /* Build configuration list for PBXProject "string" */ = { 234 | isa = XCConfigurationList; 235 | buildConfigurations = ( 236 | FE62602F1F5AAC48001404F0 /* Debug */, 237 | FE6260301F5AAC48001404F0 /* Release */, 238 | ); 239 | defaultConfigurationIsVisible = 0; 240 | defaultConfigurationName = Release; 241 | }; 242 | FE6260311F5AAC48001404F0 /* Build configuration list for PBXNativeTarget "string" */ = { 243 | isa = XCConfigurationList; 244 | buildConfigurations = ( 245 | FE6260321F5AAC48001404F0 /* Debug */, 246 | FE6260331F5AAC48001404F0 /* Release */, 247 | ); 248 | defaultConfigurationIsVisible = 0; 249 | }; 250 | /* End XCConfigurationList section */ 251 | }; 252 | rootObject = FE6260221F5AAC47001404F0 /* Project object */; 253 | } 254 | -------------------------------------------------------------------------------- /tests/embed/embed.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {02442810-694E-442C-891E-E3FC9F1E2728} 23 | Win32Proj 24 | embed 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | Use 87 | Level3 88 | Disabled 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | 92 | 93 | Console 94 | true 95 | 96 | 97 | 98 | 99 | Use 100 | Level3 101 | Disabled 102 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 103 | true 104 | 105 | 106 | Console 107 | true 108 | 109 | 110 | 111 | 112 | Level3 113 | Use 114 | MaxSpeed 115 | true 116 | true 117 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 118 | true 119 | 120 | 121 | Console 122 | true 123 | true 124 | true 125 | 126 | 127 | 128 | 129 | Level3 130 | Use 131 | MaxSpeed 132 | true 133 | true 134 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions);ZEND_WIN32;PHP_WIN32;_CRT_SECURE_NO_WARNINGS 135 | true 136 | D:\php\php7-sdk\phpdev\vc14\x64\php-7.1.8\TSRM;D:\php\php7-sdk\phpdev\vc14\x64\php-7.1.8\Zend;D:\php\php7-sdk\phpdev\vc14\x64\php-7.1.8\main;D:\php\php7-sdk\phpdev\vc14\x64\php-7.1.8;%(AdditionalIncludeDirectories) 137 | 138 | 139 | Console 140 | true 141 | true 142 | true 143 | D:\php\php7-sdk\phpdev\vc14\x64\php-7.1.8\x64\Release\php7.lib;D:\php\php7-sdk\phpdev\vc14\x64\php-7.1.8\x64\Release\php7embed.lib;%(AdditionalDependencies) 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | Create 157 | Create 158 | Create 159 | Create 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /win32/WingWmic.class.c: -------------------------------------------------------------------------------- 1 | #include "WingWmic.class.h" 2 | #include "OleAuto.h" 3 | #pragma comment(lib,"OleAut32.lib") 4 | 5 | WingWmic::WingWmic() 6 | { 7 | this->pSvc = NULL; 8 | this->pEnumerator = NULL; 9 | this->has_error = 0; 10 | this->pLoc = NULL; 11 | this->query_table = NULL; 12 | this->pclsObj = NULL; 13 | 14 | HRESULT hres; 15 | hres = CoInitializeEx(0, COINIT_MULTITHREADED); 16 | if (FAILED(hres)) { 17 | this->has_error = 1; 18 | return; 19 | } 20 | 21 | hres = CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL ); 22 | 23 | if (FAILED(hres)) { 24 | this->has_error = 1; 25 | return ; 26 | } 27 | 28 | hres = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc ); 29 | 30 | if (FAILED(hres)) { 31 | this->has_error = 1; 32 | return ; 33 | } 34 | 35 | hres = pLoc->ConnectServer( _bstr_t(L"ROOT\\CIMV2"), NULL, NULL, 0, NULL, 0, 0, &this->pSvc ); 36 | 37 | if (FAILED(hres)) { 38 | this->has_error = 1; 39 | return ; 40 | } 41 | 42 | hres = CoSetProxyBlanket( pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE ); 43 | 44 | if (FAILED(hres)) { 45 | this->has_error = 1; 46 | return; 47 | } 48 | } 49 | 50 | WingWmic::~WingWmic() 51 | { 52 | if (pSvc != NULL) { 53 | pSvc->Release(); 54 | } 55 | 56 | if (pLoc != NULL) { 57 | pLoc->Release(); 58 | } 59 | 60 | if (pEnumerator != NULL) { 61 | pEnumerator->Release(); 62 | } 63 | 64 | if (this->query_table != NULL) { 65 | delete[] this->query_table; 66 | } 67 | 68 | if (this->pclsObj != NULL) { 69 | this->pclsObj->Release(); 70 | } 71 | 72 | CoUninitialize(); 73 | } 74 | 75 | void WingWmic::query(const char* _sql){ 76 | 77 | if (this->has_error) { 78 | return; 79 | } 80 | /*char *sql = _strdup(_sql); 81 | 82 | int i = 0; 83 | while(sql[i] != '\0'){ 84 | sql[i] = tolower(sql[i]); 85 | i++; 86 | } 87 | 88 | char *from = strstr(sql , "from")+4; 89 | while(1) { 90 | char c = *from; 91 | if (!isspace(c)) break; 92 | from++; 93 | } 94 | 95 | this->query_table = new char[32]; 96 | memset(this->query_table , 0 , 32); 97 | int index = 0; 98 | while(1) { 99 | char c = *from; 100 | if (isspace(c) || c == '\0') break; 101 | this->query_table[index] = c; 102 | index++; 103 | from++; 104 | }*/ 105 | 106 | HRESULT hres = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(_sql),WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL,&this->pEnumerator); 107 | 108 | if (FAILED(hres)) { 109 | this->has_error = 1; 110 | } 111 | //delete[] sql; 112 | } 113 | 114 | BOOL WingWmic::next() 115 | { 116 | 117 | if (pclsObj != NULL) { 118 | pclsObj->Release(); 119 | pclsObj=NULL; 120 | } 121 | 122 | ULONG uReturn = 0; 123 | HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); 124 | 125 | return uReturn; 126 | } 127 | 128 | void DecimalToString(VARIANT var,char *&buf) 129 | { 130 | UINT64 u64 = (UINT64)var.decVal.Lo64; 131 | UINT64 iMod = 1; 132 | UINT64 ui = (UINT64)var.decVal.Lo64; 133 | int _min = min(var.decVal.signscale,var.decVal.scale); 134 | 135 | for(int i = 0; i < _min ; i++) { 136 | ui /= 10; 137 | iMod *= 10; 138 | } 139 | 140 | UINT64 ud = (UINT64)var.decVal.Lo64 % iMod; 141 | char sz0[64] = {0}; 142 | 143 | _ui64toa(ui, sz0, 10); 144 | 145 | char sz1[64] = {0}; 146 | char sz2[64] = {0}; 147 | 148 | _ui64toa(ud, sz1, 10); 149 | 150 | buf = (char*)malloc(128); 151 | memset(buf,0,128); 152 | 153 | int zeroSize = var.decVal.scale-strlen(sz1); 154 | 155 | for(int i = 0; i < zeroSize; i++) { 156 | sprintf(sz2, "0%s", sz1); 157 | memcpy(sz1, sz2,64); 158 | } 159 | 160 | if (var.decVal.sign < 128) { 161 | if (var.decVal.signscale > 0) { 162 | sprintf(buf, "%s.%s" , sz0, sz1); 163 | } else { 164 | sprintf(buf, "%s" , sz0); 165 | } 166 | } else { 167 | if (var.decVal.signscale > 0) { 168 | sprintf(buf, "-%s.%s" , sz0, sz1); 169 | } else { 170 | sprintf(buf, "-%s" , sz0); 171 | } 172 | } 173 | } 174 | 175 | /** 176 | * 获取指定key的值,返回堆内存,需要手动free 177 | */ 178 | char* WingWmic::get(const char *key) 179 | { 180 | if (this->has_error) { 181 | pEnumerator->Release(); 182 | pEnumerator = NULL; 183 | return NULL; 184 | } 185 | 186 | 187 | VARIANT vtProp; 188 | 189 | wchar_t *wkey = wing_str_char_to_wchar(key); 190 | HRESULT hr = pclsObj->Get(wkey , 0, &vtProp, 0, 0); 191 | char *res = NULL; 192 | 193 | if (SUCCEEDED(hr) && vtProp.bstrVal) { 194 | switch (V_VT(&vtProp)) { 195 | case VT_BSTR: 196 | res = wing_str_wchar_to_utf8((const wchar_t*)vtProp.bstrVal); 197 | break; 198 | case VT_LPSTR: { 199 | int size = sizeof(strlen((char*)vtProp.pvRecord)+1); 200 | res = (char*)malloc(size); 201 | memset(res, 0, size); 202 | memcpy(res, vtProp.pvRecord, size-1); 203 | } 204 | break; 205 | case VT_LPWSTR: { 206 | res = wing_str_wchar_to_utf8((const wchar_t*)vtProp.pvRecord); 207 | } 208 | break; 209 | case VT_I1: 210 | case VT_UI1: { 211 | res = (char*)malloc(32); 212 | memset(res,0,32); 213 | sprintf(res, "%d", vtProp.bVal); 214 | } 215 | break; 216 | case VT_I2: { 217 | res = (char*)malloc(32); 218 | memset(res,0,32); 219 | sprintf(res, "%d", vtProp.iVal); 220 | } 221 | break; 222 | case VT_UI2: { 223 | res = (char*)malloc(32); 224 | memset(res,0,32); 225 | sprintf(res, "%d", vtProp.uiVal); 226 | } 227 | break; 228 | case VT_INT: { 229 | res = (char*)malloc(32); 230 | memset(res,0,32); 231 | sprintf(res, "%d", vtProp.intVal); 232 | } 233 | break; 234 | case VT_I4: { 235 | res = (char*)malloc(32); 236 | memset(res,0,32); 237 | sprintf(res, "%d", vtProp.lVal); 238 | } 239 | break; 240 | case VT_I8: { 241 | res = (char*)malloc(32); 242 | memset(res,0,32); 243 | sprintf(res,"%ld", vtProp.bVal); 244 | } 245 | break; 246 | case VT_UINT: { 247 | res = (char*)malloc(32); 248 | memset(res,0,32); 249 | sprintf(res, "%u", vtProp.uintVal); 250 | } 251 | break; 252 | case VT_UI4: { 253 | res = (char*)malloc(32); 254 | memset(res,0,32); 255 | sprintf(res, "%u", vtProp.ulVal); 256 | } 257 | break; 258 | case VT_UI8: { 259 | res = (char*)malloc(32); 260 | memset(res,0,32); 261 | sprintf(res, "%u", vtProp.ulVal); 262 | } 263 | break; 264 | case VT_VOID: { 265 | res = (char*)malloc(32); 266 | memset(res,0,32); 267 | sprintf(res, "%8x", (unsigned int)vtProp.byref); 268 | } 269 | break; 270 | case VT_R4: { 271 | res = (char*)malloc(32); 272 | memset(res,0,32); 273 | sprintf(res, "%.4f", vtProp.fltVal); 274 | } 275 | break; 276 | case VT_R8: { 277 | res = (char*)malloc(32); 278 | memset(res,0,32); 279 | sprintf(res, "%.8f", vtProp.dblVal); 280 | } 281 | break; 282 | case VT_DECIMAL: 283 | DecimalToString(vtProp,res); 284 | break; 285 | case VT_CY: { 286 | //vtProp.cyVal.Hi 287 | //COleCurrency cy = vtProp.cyVal; 288 | //strValue = cy.Format(); 289 | } 290 | break; 291 | case VT_BLOB: 292 | case VT_BLOB_OBJECT: 293 | case 0x2011: 294 | //strValue = "[BLOB]"; 295 | break; 296 | case VT_BOOL: { 297 | res = (char*)malloc(5); 298 | memset(res,0,5); 299 | sprintf(res,"%s",vtProp.boolVal ? "TRUE" : "FASLE"); 300 | } 301 | break; 302 | case VT_DATE: { 303 | SYSTEMTIME st = {0}; 304 | res = (char*)malloc(32); 305 | memset(res,0,32); 306 | VariantTimeToSystemTime(vtProp.date,&st); 307 | sprintf(res,"%04d-%02d-%02d %02d:%02d:%02d",st.wYear,st.wMonth,st.wDay, st.wHour, st.wMinute, st.wSecond); 308 | } 309 | break; 310 | case VT_NULL: 311 | //strValue = "VT_NULL"; 312 | break; 313 | case VT_EMPTY: 314 | //strValue = ""; 315 | break; 316 | case VT_UNKNOWN: 317 | default: 318 | //strValue = "UN_KNOWN"; 319 | break; 320 | 321 | } 322 | 323 | } 324 | 325 | VariantClear(&vtProp); 326 | if(wkey) { 327 | free(wkey); 328 | } 329 | 330 | return res; 331 | } 332 | -------------------------------------------------------------------------------- /wing_api.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 读取类的属性,这里为了兼容php7和其他版本所做的简单的条件编译封装 3 | */ 4 | zval *wing_zend_read_property(zend_class_entry *scope, zval *object, const char *name) 5 | { 6 | TSRMLS_FETCH(); 7 | #if PHP_MAJOR_VERSION >= 7 8 | return zend_read_property(scope, object, name, strlen(name), 0, 0 TSRMLS_CC); 9 | #else 10 | return zend_read_property(scope, object, name, strlen(name), 0 TSRMLS_CC); 11 | #endif 12 | } 13 | 14 | 15 | /** 16 | * 判断文件是否为php文件 17 | * 18 | * @param const char* file 19 | * @return BOOL 20 | */ 21 | int wing_file_is_php(const char *file) 22 | { 23 | char path[MAX_PATH] = {0}; 24 | 25 | 26 | if (strstr(file, "'") != NULL) { 27 | char *st = (char*)file; 28 | st++; 29 | char *f = strstr(st, "'"); 30 | strncpy(path, st, f - st); 31 | } 32 | 33 | else if (strstr(file, "\"") != NULL) { 34 | char *st = (char*)file; 35 | st++; 36 | char *f = strstr(st, "\""); 37 | strncpy(path, st, f - st); 38 | } 39 | 40 | else if (strstr(file, "`") != NULL) { 41 | char *st = (char*)file; 42 | st++; 43 | char *f = strstr(st, "`"); 44 | strncpy(path, st, f - st); 45 | } 46 | 47 | else if(strstr(file, " ") != NULL) { 48 | char *st = (char*)file; 49 | st++; 50 | char *f = strstr(st, " "); 51 | strncpy(path, st, f - st); 52 | } 53 | 54 | else { 55 | strcpy(path, file); 56 | } 57 | 58 | char *ext = strrchr(path, '.'); 59 | if (ext) { 60 | ext++; 61 | if (strcmp(ext, "php") == 0 && wing_access(path, R_OK) == 0) { 62 | return 1; 63 | } 64 | } 65 | 66 | if (wing_access(path, R_OK) != 0) { 67 | return 0; 68 | } 69 | 70 | FILE *handle = fopen(path, "r"); 71 | if (!handle) { 72 | return 0; 73 | } 74 | char *find = NULL; 75 | char line[8] = { 0 }; 76 | fgets(line, 7, handle); 77 | 78 | find = strstr(line, "= (env+len) ) { 44 | break; 45 | } 46 | 47 | start++; 48 | } 49 | 50 | size = env+len - pos; 51 | memset(temp, 0, MAX_PATH); 52 | strncpy(temp, (char*)pos, size); 53 | 54 | char *base = (char*)(temp + strlen(temp)); 55 | strcpy(base, "/"); 56 | strcpy((char*)(base + 1), command); 57 | 58 | if (access(temp, F_OK) == 0) { 59 | res = (char *)malloc(size+command_len); 60 | memset(res, 0, size+command_len); 61 | strcpy(res, temp); 62 | return res; 63 | } 64 | return NULL; 65 | } 66 | 67 | /** 68 | * 启用守护进程模式 69 | * 70 | * @param const char* dir 工作目录 71 | */ 72 | void init_daemon(const char* dir) 73 | { 74 | int pid = fork(); 75 | int i; 76 | if (pid > 0) { 77 | exit(0);//是父进程,结束父进程 78 | } 79 | if (pid < 0) { 80 | exit(1);//fork失败,退出 81 | } 82 | //是第一子进程,后台继续执行 83 | setsid();//第一子进程成为新的会话组长和进程组长 84 | //并与控制终端分离 85 | pid = fork(); 86 | if (pid > 0) { 87 | exit(0);//是第一子进程,结束第一子进程 88 | } 89 | if (pid < 0) { 90 | exit(1);//fork失败,退出 91 | } 92 | //是第二子进程,继续 93 | //第二子进程不再是会话组长 94 | //for (i = 0; i < NOFILE; ++i) {//关闭打开的文件描述符 95 | // close(i); 96 | //} 97 | chdir(dir);//改变工作目录到/tmp 98 | umask(0);//重设文件创建掩模 99 | return; 100 | } 101 | 102 | /** 103 | * 创建一个新的进程 104 | * 105 | * @param const char *command 需要以守护进程运行的指令 106 | * @param char* output_file 输出重定向到文件,如果不等于NULL,则认为是以守护方式运行 107 | * @return unsigned long 进程id 108 | */ 109 | unsigned long wing_create_process(const char *command, char* output_file) 110 | { 111 | TSRMLS_FETCH(); 112 | 113 | int daemon = output_file == NULL ? 0 : 1; 114 | if (daemon) { 115 | const char *str = zend_get_executed_filename(TSRMLS_C); 116 | char find_str[] = "/"; 117 | char *find = strstr((const char*)str, find_str); 118 | char *last_pos = NULL; 119 | while(find) { 120 | last_pos = find; 121 | find++; 122 | find = strstr((const char*)find, find_str); 123 | } 124 | char path[MAX_PATH] = {0}; 125 | 126 | strncpy((char*)path, (const char*)str, (size_t)(last_pos-str)); 127 | 128 | init_daemon((const char*)path); 129 | 130 | FILE *handle = fopen(output_file, "a+"); 131 | 132 | if (handle) { 133 | fclose(handle); 134 | fclose((FILE*)stdout); 135 | stdout = fopen(output_file, "a+"); 136 | 137 | fclose((FILE*)stderr); 138 | stderr = fopen(output_file, "a+"); 139 | } else { 140 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "无法打开文件(could not open file):%s", output_file); 141 | } 142 | 143 | } 144 | pid_t childpid = fork(); 145 | 146 | if (childpid == 0) { 147 | 148 | //命令解析 149 | char *st = (char*)command; 150 | char *et = (char*)(st + strlen(command)); 151 | char _args[MAX_ARGC][MAX_PATH]; 152 | int pos = 0; 153 | int ac = 0; 154 | int cc = 0; 155 | int start = 0; 156 | int next_s = 0; 157 | int na = 0; 158 | int i; 159 | for (i = 0; i < MAX_ARGC; i++) { 160 | memset(*_args, 0, MAX_PATH); 161 | } 162 | 163 | //命令行参数解析算法 主要是为了解决带空格路径和带空格参数的问题 164 | //可以使用 单引号 双引号 和 ` 符号包含带空格的额参数 165 | //如下算法只是为了将如 "'__DIR__/1 2.php' 123 \"trertyertey\" '123456' `23563456` \"sdfgfdgfdg\""; 166 | //这样的字符串还原为正常的命令行参数 167 | //如上字符出阿奴解析之后会得到一个数组 ["__DIR__/1 2.php", "123", "trertyertey", "123456", "23563456", "sdfgfdgfdg"] 168 | //最多只支持7个参数 每个参数不得超过255个字符 169 | while (st <= et) { 170 | if (ac >= MAX_ARGC - 1) break; 171 | 172 | if (*st == '\'' || *st == '"' || *st == '`') { 173 | pos++; 174 | st++; 175 | start = 1; 176 | if (pos == 2) { 177 | while (*st == ' ') 178 | { 179 | st++; na = 1; 180 | } 181 | if (na) { 182 | ac++; 183 | printf("1ac++\r\n"); 184 | cc = 0; 185 | na = 0; 186 | } 187 | if (*st == '\'' || *st == '"' || *st == '`') { 188 | st++; pos=1; 189 | } 190 | } 191 | } 192 | 193 | if (start == 0) { 194 | if (*st == ' ') { 195 | ac++; printf("2ac++\r\n"); 196 | cc = 0; 197 | } 198 | 199 | while (*st == ' ') 200 | st++; 201 | 202 | if (*st == '\'' || *st == '"' || *st == '`') { 203 | pos++; 204 | st++; 205 | start = 1; 206 | } 207 | } 208 | 209 | if (*st == '\0') break; 210 | if (st >= et) break; 211 | if (cc < MAX_PATH) { 212 | _args[ac][cc] = *st; 213 | cc++; 214 | _args[ac][cc] = '\0'; 215 | 216 | } 217 | 218 | if (pos == 2) { 219 | pos = 0; 220 | start = 0; 221 | } 222 | st++; 223 | } 224 | //命令解析--end 225 | 226 | if (wing_file_is_php(command)) { 227 | switch (ac) { 228 | case 0: 229 | if (execl(PHP_PATH, "php", _args[0], NULL) < 0) { 230 | exit(0); 231 | } 232 | break; 233 | case 1: 234 | if (execl(PHP_PATH, "php", _args[0], _args[1], NULL) < 0) { 235 | exit(0); 236 | } 237 | break; 238 | case 2: 239 | if (execl(PHP_PATH, "php", _args[0], _args[1], _args[2], NULL) < 0) { 240 | exit(0); 241 | } 242 | break; 243 | case 3: 244 | if (execl(PHP_PATH, "php", _args[0], _args[1], _args[2], _args[3], NULL) < 0) { 245 | exit(0); 246 | } 247 | break; 248 | case 4: 249 | if (execl(PHP_PATH, "php", _args[0], _args[1], _args[2], _args[3], _args[4], NULL) < 0) { 250 | exit(0); 251 | } 252 | break; 253 | case 5: 254 | if (execl(PHP_PATH, "php", _args[0], _args[1], _args[2], _args[3], _args[4], _args[5], NULL) < 0) { 255 | exit(0); 256 | } 257 | break; 258 | case 6: 259 | if (execl(PHP_PATH, "php", _args[0], _args[1], _args[2], _args[3], _args[4], _args[5], _args[6], NULL) < 0) { 260 | exit(0); 261 | } 262 | break; 263 | case 7: 264 | if (execl(PHP_PATH, "php", _args[0], _args[1], _args[2], _args[3], _args[4], _args[5], _args[6], _args[7], NULL) < 0) { 265 | exit(0); 266 | } 267 | break; 268 | default: 269 | break; 270 | } 271 | } else { 272 | if (execl("/bin/sh", "sh", "-c", command, NULL) < 0) { 273 | exit(0); 274 | } 275 | } 276 | } else if(childpid > 0) { 277 | if (daemon) { 278 | //如果以守护进程方式启动,则等待子进程退出,防止子进程变成僵尸进程 279 | int status; 280 | return waitpid(childpid, &status, 0); 281 | } 282 | } else { 283 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "创建进程错误(fork a process error)"); 284 | } 285 | return (unsigned long )childpid; 286 | } 287 | 288 | /** 289 | * 获取当前进程id 290 | * 291 | * @return int 292 | */ 293 | int wing_get_process_id() 294 | { 295 | return getpid(); 296 | } 297 | 298 | #ifdef __APPLE__ 299 | /** 300 | * mac下面获取进程占用内存 返回单位为k 301 | * 302 | * @param int process_id 进程id 303 | * @return int 304 | */ 305 | unsigned long wing_get_memory(int process_id) 306 | { 307 | struct proc_taskallinfo info; 308 | 309 | int ret = proc_pidinfo(process_id, PROC_PIDTASKALLINFO, 0, 310 | (void*)&info, sizeof(struct proc_taskallinfo)); 311 | if (ret <= 0) { 312 | return 0; 313 | } 314 | return info.ptinfo.pti_resident_size/1024; 315 | } 316 | #else 317 | /** 318 | * linux下面获取进程占用内存 返回单位为k 319 | * 320 | * @param int process_id 进程id 321 | * @return int 322 | */ 323 | unsigned long wing_get_memory(int process_id) 324 | { 325 | char file[MAX_PATH] = {0}; 326 | sprintf(file, "/proc/%d/status", process_id); 327 | FILE *sp = fopen(file, "r"); 328 | if (!sp) { 329 | return 0; 330 | } 331 | char sbuffer[32] = { 0 }; 332 | char mem[16] = { 0 }; 333 | char *cs = NULL; 334 | int count = 0; 335 | 336 | while (!feof(sp)) { 337 | memset(sbuffer, 0, 32); 338 | fgets(sbuffer, 32, sp); 339 | if (strncmp(sbuffer, "VmSize:", 7) == 0) { 340 | cs = (char*)(sbuffer + 6); 341 | while (*cs++ != '\n') { 342 | if (*cs >= 48 && *cs <= 57) 343 | mem[count++] = *cs; 344 | } 345 | break; 346 | } 347 | } 348 | 349 | fclose(sp); 350 | return atoi((const char*)mem); 351 | } 352 | 353 | #endif 354 | /** 355 | * @todo 杀死进程 356 | * @param int process_id 357 | * @return int 0成功 -1失败 358 | */ 359 | int wing_kill(int process_id) 360 | { 361 | return 0; 362 | } 363 | 364 | /** 365 | * 获取系统临时路径 366 | * 367 | * @param char *buffer 输出结果,这里的buffer使用char数组,如: 368 | * char buffer[MAX_PATH]; 369 | * wing_get_tmp_dir(buffer); 370 | */ 371 | void wing_get_tmp_dir(char *buffer) 372 | { 373 | const char* tmp = "/tmp"; 374 | if(0 != access(tmp, W_OK)) { 375 | buffer = NULL; 376 | return; 377 | } 378 | 379 | const char* tmp_wing = "/tmp/wing_process"; 380 | if (0 == access(tmp_wing, F_OK)) { 381 | strcpy(buffer, tmp_wing); 382 | return; 383 | } 384 | 385 | if (0 == mkdir(tmp_wing, 0777)) { 386 | strcpy(buffer, tmp_wing); 387 | return; 388 | } 389 | buffer = NULL; 390 | return; 391 | } -------------------------------------------------------------------------------- /wing_process.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2016 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | php windows、mac and linux daemon process support 16 | | Author: yuyi 17 | | Email: 297341015@qq.com 18 | | Home: http://www.itdfy.com/ 19 | +----------------------------------------------------------------------+ 20 | */ 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include "config.h" 24 | #endif 25 | 26 | #include "php.h" 27 | #include "php_ini.h" 28 | #include "ext/standard/info.h" 29 | #include "php_wing_process.h" 30 | #include "wing_api.h" 31 | 32 | 33 | #define WING_ERROR_FAILED 0 34 | #define WING_ERROR_SUCCESS 1 35 | 36 | static int le_wing_process; 37 | char *PHP_PATH = NULL; 38 | 39 | zend_class_entry *wing_process_ce; 40 | 41 | typedef struct _WING_PROCESS_INFO { 42 | unsigned long process_id; 43 | unsigned long thread_id; 44 | void *ext_info; 45 | char* command; 46 | char* file; 47 | } WING_PROCESS_INFO; 48 | 49 | /** 50 | * 构造函数,第一个参数为需要以守护进程执行的php文件或者是其他可执行的命令和文件 51 | * 如果传入的文件是一个数字,则认为根据进程id打开进程,后续可以对此进程进行控制,比如kill 52 | * 53 | * @param string $file 54 | */ 55 | ZEND_METHOD(wing_process, __construct) 56 | { 57 | 58 | #if PHP_MAJOR_VERSION >= 7 59 | zend_string *_file = NULL; 60 | char *file = NULL; 61 | int file_len = 0; 62 | 63 | if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &_file)) { 64 | return; 65 | } 66 | 67 | if (_file) { 68 | file = ZSTR_VAL(_file); 69 | efree(_file); 70 | } 71 | 72 | file_len = strlen(file); 73 | #else 74 | char *file = NULL; 75 | int file_len = 0; 76 | 77 | if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len)) { 78 | return; 79 | } 80 | #endif 81 | 82 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO*)emalloc(sizeof(WING_PROCESS_INFO)+1); 83 | info->process_id = 0; 84 | info->thread_id = 0; 85 | info->ext_info = NULL; 86 | info->command = NULL; 87 | info->file = (char*)emalloc(strlen(file)+1); 88 | strcpy(info->file, file); 89 | 90 | int size = file_len + 2; 91 | if (PHP_PATH) { 92 | size += strlen(PHP_PATH); 93 | } 94 | char *command_line = NULL; 95 | 96 | //如果传入的文件是一个数字,则认为此数字为进程id 97 | if (is_numeric_string(file, strlen(file), NULL, NULL, 0)) { 98 | #ifdef PHP_WIN32 99 | PROCESSINFO *item = new PROCESSINFO(); 100 | DWORD process_id = zend_atoi(file, strlen(file)); 101 | 102 | info->process_id = (unsigned long)process_id; 103 | 104 | WingQueryProcessByProcessID(item, process_id); 105 | if (item) { 106 | spprintf(&command_line, strlen(item->command_line), "%s", item->command_line); 107 | delete item; 108 | } 109 | #else 110 | info->process_id = (unsigned long)zend_atoi(file, strlen(file)); 111 | 112 | char *buffer = NULL; 113 | wing_get_cmdline(info->process_id, &buffer); 114 | if (buffer) { 115 | spprintf(&command_line, strlen(buffer), "%s", buffer); 116 | } else { 117 | spprintf(&command_line, strlen(""), "%s", ""); 118 | } 119 | if (buffer) { 120 | free(buffer); 121 | } 122 | 123 | #endif 124 | 125 | //这里还需要解析command_line 判断是否是php命令 还原成file 填充到 info->file 126 | if (command_line) { 127 | char *find = strstr(command_line, " "); 128 | if(info->file) { 129 | efree(info->file); 130 | info->file = NULL; 131 | } 132 | 133 | if (find == NULL) { 134 | info->file = (char*)emalloc(strlen(command_line)+1); 135 | strcpy(info->file, command_line); 136 | } else { 137 | char _cmd[MAX_PATH] = {0}; 138 | strncpy(_cmd, command_line, find-command_line); 139 | int _dphp = strcmp(_cmd, "php"); 140 | if (strcmp(_cmd, PHP_PATH) == 0 || _dphp == 0) { 141 | //php文件 142 | memset(_cmd,0,MAX_PATH); 143 | strcpy(_cmd, (char*)(find+1)); 144 | info->file = (char*)emalloc(strlen(_cmd)+1); 145 | strcpy(info->file, _cmd); 146 | 147 | if (_dphp == 0) { 148 | efree(command_line); 149 | command_line = NULL; 150 | size = strlen(PHP_PATH) + strlen(info->file)+2; 151 | spprintf(&command_line, size, "%s %s\0", PHP_PATH, info->file); 152 | } 153 | } else { 154 | info->file = (char*)emalloc(strlen(command_line)+1); 155 | strcpy(info->file, command_line); 156 | } 157 | } 158 | } 159 | } else { 160 | if (wing_file_is_php((const char*)file)){ 161 | if (PHP_PATH) { 162 | spprintf(&command_line, size, "%s %s\0", PHP_PATH, file); 163 | } else { 164 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "找不到php命令(could not find command php)"); 165 | } 166 | } else { 167 | spprintf(&command_line, size, "%s\0", file); 168 | } 169 | } 170 | 171 | if (command_line) { 172 | info->command = (char*)emalloc(strlen(command_line)+1); 173 | strcpy(info->command, command_line); 174 | efree(command_line); 175 | } 176 | 177 | zend_update_property_long(wing_process_ce, getThis(), "process_info", strlen("process_info"), (unsigned long)info TSRMLS_CC); 178 | } 179 | 180 | /*** 181 | * 析构函数 182 | * windows下面需要释放一些资源 183 | */ 184 | ZEND_METHOD(wing_process, __destruct) { 185 | 186 | zval *_info = wing_zend_read_property(wing_process_ce, getThis(),"process_info"); 187 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO *)Z_LVAL_P(_info); 188 | 189 | #ifdef PHP_WIN32 190 | PROCESS_INFORMATION *pi = (PROCESS_INFORMATION *)(info->ext_info); 191 | 192 | if (pi) { 193 | CloseHandle(pi->hProcess); 194 | CloseHandle(pi->hThread); 195 | delete pi; 196 | } 197 | #endif 198 | 199 | if (info->command) { 200 | efree(info->command); 201 | } 202 | efree(info->file); 203 | efree(info); 204 | } 205 | 206 | /** 207 | * 运行进程 208 | * 209 | * @param string $output_file 默认为null,如果不为null,则以守护进程方式运行 210 | * @return int 返回进程id 211 | */ 212 | ZEND_METHOD(wing_process, run) 213 | { 214 | char *output_file = NULL; 215 | 216 | #if PHP_MAJOR_VERSION >= 7 217 | 218 | zend_string *_output_file = NULL; 219 | zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|S", &_output_file); 220 | 221 | if (_output_file) { 222 | output_file = ZSTR_VAL(_output_file); 223 | efree(_output_file); 224 | } 225 | 226 | #else 227 | int output_file_len = 0; 228 | zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &output_file, &output_file_len); 229 | #endif 230 | 231 | zval *_info = wing_zend_read_property(wing_process_ce, getThis(),"process_info"); 232 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO*)Z_LVAL_P(_info); 233 | 234 | #ifdef PHP_WIN32 235 | PROCESS_INFORMATION *pi = (PROCESS_INFORMATION *)wing_create_process(info->command, output_file); 236 | info->ext_info = (void*)pi; 237 | info->process_id = pi->dwProcessId; 238 | info->thread_id = pi->dwThreadId; 239 | RETURN_LONG(pi->dwProcessId); 240 | #else 241 | unsigned long childpid = wing_create_process(info->file, output_file); 242 | info->process_id = childpid; 243 | RETURN_LONG(childpid); 244 | #endif 245 | } 246 | 247 | 248 | /** 249 | * 等待进程退出,直接返回退出的进程id 250 | * 251 | * @param int $timout windows下面的意思为等待超时时间,linux下面的意思为是否等待,可选参数如 WNOHANG | WUNTRACED 252 | * @return int 253 | */ 254 | ZEND_METHOD(wing_process, wait) 255 | { 256 | int timeout = INFINITE; 257 | zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &timeout); 258 | 259 | zval *_info = wing_zend_read_property(wing_process_ce, getThis(),"process_info"); 260 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO *)Z_LVAL_P(_info); 261 | 262 | #ifdef PHP_WIN32 263 | HANDLE process = NULL; 264 | int process_id = 0; 265 | if (is_numeric_string(info->file, strlen(info->file), NULL, NULL, 0)) { 266 | process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, zend_atoi(info->file, strlen(info->file))); 267 | process_id = zend_atoi(info->file, strlen(info->file)); 268 | } else { 269 | PROCESS_INFORMATION *pi = (PROCESS_INFORMATION *)(info->ext_info); 270 | process = pi->hProcess; 271 | process_id = info->process_id; 272 | } 273 | 274 | DWORD wait_result = 0; 275 | DWORD wait_status = WaitForSingleObject(process, timeout); 276 | 277 | if (wait_status != WAIT_OBJECT_0) { 278 | RETURN_LONG(process_id);//wait_status); 279 | } 280 | if (GetExitCodeProcess(process, &wait_result) == 0) { 281 | RETURN_LONG(-1); 282 | } 283 | 284 | RETURN_LONG(process_id); 285 | #else 286 | int status; 287 | pid_t epid = waitpid(info->process_id, &status, timeout); 288 | RETURN_LONG(epid); 289 | #endif 290 | } 291 | 292 | /** 293 | * 获取进程id 294 | * 295 | * @return int 296 | */ 297 | ZEND_METHOD(wing_process, getProcessId) 298 | { 299 | zval *_info = wing_zend_read_property(wing_process_ce, getThis(),"process_info"); 300 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO *)Z_LVAL_P(_info); 301 | RETURN_LONG(info->process_id); 302 | } 303 | 304 | 305 | /** 306 | * 获取线程id 307 | * 308 | * @return int 309 | */ 310 | ZEND_METHOD(wing_process, getThreadId) 311 | { 312 | zval *_info = wing_zend_read_property(wing_process_ce, getThis(),"process_info"); 313 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO *)Z_LVAL_P(_info); 314 | #ifdef PHP_WIN32 315 | RETURN_LONG(info->thread_id); 316 | #else 317 | RETURN_LONG(info->process_id); 318 | #endif 319 | } 320 | 321 | 322 | /** 323 | * 获取命令行参数 324 | * 325 | * @return string 326 | */ 327 | ZEND_METHOD(wing_process, getCommandLine) 328 | { 329 | zval *zinfo = wing_zend_read_property(wing_process_ce, getThis(),"process_info"); 330 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO *)Z_LVAL_P(zinfo); 331 | 332 | #if PHP_MAJOR_VERSION >= 7 333 | ZVAL_STRING(return_value, info->command); 334 | #else 335 | ZVAL_STRING(return_value, info->command, 1); 336 | #endif 337 | } 338 | 339 | /** 340 | * 杀死进程 341 | * 342 | * @return int 343 | */ 344 | ZEND_METHOD(wing_process, kill) 345 | { 346 | zval *_info = wing_zend_read_property(wing_process_ce, getThis(),"process_info"); 347 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO *)Z_LVAL_P(_info); 348 | 349 | #ifdef PHP_WIN32 350 | HANDLE process = NULL; 351 | 352 | if (is_numeric_string(info->file, strlen(info->file), NULL, NULL, 0)) { 353 | process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, zend_atoi(info->file, strlen(info->file))); 354 | } else { 355 | PROCESS_INFORMATION *pi = (PROCESS_INFORMATION *)(info->ext_info); 356 | process = pi->hProcess; 357 | } 358 | 359 | //非安全的方式直接退出 可能造成进程数据丢失 360 | if (!TerminateProcess(process, 0)) { 361 | RETURN_FALSE;//LONG(WING_ERROR_FAILED); 362 | return; 363 | } 364 | //RETURN_LONG(WING_ERROR_SUCCESS); 365 | RETURN_TRUE; 366 | #else 367 | int process_id = 0; 368 | 369 | if (is_numeric_string(info->file, strlen(info->file), NULL, NULL, 0)) { 370 | process_id = zend_atoi(info->file, strlen(info->file)); 371 | } else { 372 | process_id = info->process_id; 373 | } 374 | 375 | int status = kill(process_id, SIGKILL); 376 | 377 | if (status == -1) { 378 | RETURN_FALSE; 379 | } 380 | 381 | wait(&status); 382 | 383 | if (WIFSIGNALED(status)) { 384 | RETURN_TRUE; 385 | } 386 | 387 | RETURN_FALSE; 388 | #endif 389 | } 390 | 391 | /** 392 | * 返回进程占用的实际内存,单位为k 393 | * 394 | * @return int 395 | */ 396 | ZEND_METHOD(wing_process, getMemory) 397 | { 398 | zval *_info = wing_zend_read_property(wing_process_ce, getThis(),"process_info"); 399 | WING_PROCESS_INFO *info = (WING_PROCESS_INFO *)Z_LVAL_P(_info); 400 | 401 | #ifdef PHP_WIN32 402 | HANDLE process = NULL; 403 | 404 | if (is_numeric_string(info->file, strlen(info->file), NULL, NULL, 0)) { 405 | process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, zend_atoi(info->file, strlen(info->file))); 406 | } else { 407 | PROCESS_INFORMATION *pi = (PROCESS_INFORMATION *)(info->ext_info); 408 | process = pi->hProcess; 409 | } 410 | 411 | if (!process) { 412 | RETURN_LONG(0); 413 | } 414 | 415 | PROCESS_MEMORY_COUNTERS pmc; 416 | GetProcessMemoryInfo(process, &pmc, sizeof(pmc)); 417 | RETURN_LONG(pmc.WorkingSetSize/1024); 418 | #else 419 | unsigned long mem = wing_get_memory(info->process_id); 420 | RETURN_LONG(mem); 421 | #endif 422 | } 423 | 424 | /** 425 | * 静态方法,获取当前进程id 426 | * @call \wing\wing_process::getCurrentProcessId() 427 | * @return int 428 | */ 429 | ZEND_METHOD(wing_process, getCurrentProcessId) 430 | { 431 | ZVAL_LONG(return_value, wing_get_process_id()); 432 | } 433 | // 434 | //ZEND_METHOD(wing_process, signal) 435 | //{ 436 | // int sig = -1; 437 | // zval* callback; 438 | // 439 | // zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", &sig, &callback); 440 | // 441 | // #ifdef PHP_WIN32 442 | // 443 | // #else 444 | // 445 | // #endif 446 | // RETURN_TRUE 447 | //} 448 | 449 | 450 | static zend_function_entry wing_process_methods[] = 451 | { 452 | ZEND_ME(wing_process, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) 453 | ZEND_ME(wing_process, __destruct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR) 454 | ZEND_ME(wing_process, wait, NULL, ZEND_ACC_PUBLIC) 455 | ZEND_ME(wing_process, run, NULL, ZEND_ACC_PUBLIC) 456 | ZEND_ME(wing_process, getProcessId, NULL, ZEND_ACC_PUBLIC) 457 | ZEND_ME(wing_process, getThreadId, NULL, ZEND_ACC_PUBLIC) 458 | ZEND_ME(wing_process, getCommandLine, NULL, ZEND_ACC_PUBLIC) 459 | ZEND_ME(wing_process, kill, NULL, ZEND_ACC_PUBLIC) 460 | ZEND_ME(wing_process, getMemory, NULL, ZEND_ACC_PUBLIC) 461 | ZEND_ME(wing_process, getCurrentProcessId, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 462 | //ZEND_ME(wing_process, signal, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) 463 | { 464 | NULL,NULL,NULL 465 | } 466 | }; 467 | 468 | /** 469 | * 模块初始化,这里会初始化PHP_PATH,也就是php的可执行文件路径 470 | */ 471 | PHP_MINIT_FUNCTION(wing_process) 472 | { 473 | 474 | PHP_PATH = wing_get_command_path("php"); 475 | 476 | REGISTER_STRING_CONSTANT("WING_PROCESS_PHP", PHP_PATH, CONST_CS | CONST_PERSISTENT ); 477 | REGISTER_STRING_CONSTANT("WING_PROCESS_VERSION", PHP_WING_PROCESS_VERSION, CONST_CS | CONST_PERSISTENT ); 478 | 479 | zend_class_entry _wing_process_ce; 480 | INIT_NS_CLASS_ENTRY(_wing_process_ce, "wing", "wing_process", wing_process_methods); 481 | wing_process_ce = zend_register_internal_class(&_wing_process_ce TSRMLS_CC); 482 | 483 | zend_declare_property_long(wing_process_ce, "process_info", strlen("process_info"), 0, ZEND_ACC_PRIVATE TSRMLS_CC); 484 | return SUCCESS; 485 | } 486 | 487 | /** 488 | * 模块释放 489 | */ 490 | PHP_MSHUTDOWN_FUNCTION(wing_process) 491 | { 492 | if (PHP_PATH) { 493 | free(PHP_PATH); 494 | } 495 | return SUCCESS; 496 | } 497 | 498 | /** 499 | * 模块请求初始化 500 | */ 501 | PHP_RINIT_FUNCTION(wing_process) 502 | { 503 | #if PHP_MAJOR_VERSION >= 7 504 | #if defined(COMPILE_DL_WING_PROCESS) && defined(ZTS) 505 | ZEND_TSRMLS_CACHE_UPDATE(); 506 | #endif 507 | #endif 508 | return SUCCESS; 509 | } 510 | 511 | /** 512 | * 模块请求释放 513 | */ 514 | PHP_RSHUTDOWN_FUNCTION(wing_process) 515 | { 516 | return SUCCESS; 517 | } 518 | 519 | /** 520 | * 模块相关的信息 phpinfo 521 | */ 522 | PHP_MINFO_FUNCTION(wing_process) 523 | { 524 | php_info_print_table_start(); 525 | php_info_print_table_header(2, "wing_process support", "enabled"); 526 | php_info_print_table_end(); 527 | } 528 | 529 | 530 | const zend_function_entry wing_process_functions[] = { 531 | //PHP_FE(wing_process_wait,NULL) 532 | //PHP_FE(wing_create_process_ex,NULL) 533 | //PHP_FE(alarm, NULL) 534 | PHP_FE_END /* Must be the last line in wing_process_functions[] */ 535 | }; 536 | 537 | zend_module_entry wing_process_module_entry = 538 | { 539 | STANDARD_MODULE_HEADER, 540 | "wing_process", 541 | wing_process_functions, 542 | PHP_MINIT(wing_process), 543 | PHP_MSHUTDOWN(wing_process), 544 | PHP_RINIT(wing_process), /* Replace with NULL if there's nothing to do at request start */ 545 | PHP_RSHUTDOWN(wing_process), /* Replace with NULL if there's nothing to do at request end */ 546 | PHP_MINFO(wing_process), 547 | PHP_WING_PROCESS_VERSION, 548 | STANDARD_MODULE_PROPERTIES 549 | }; 550 | 551 | #ifdef COMPILE_DL_WING_PROCESS 552 | #if PHP_MAJOR_VERSION >= 7 553 | #ifdef ZTS 554 | ZEND_TSRMLS_CACHE_DEFINE() 555 | #endif 556 | #endif 557 | ZEND_GET_MODULE(wing_process) 558 | #endif 559 | 560 | -------------------------------------------------------------------------------- /win32/ntdll.c: -------------------------------------------------------------------------------- 1 | #include "Windows.h" 2 | #include "ntdll.h" 3 | #include "wing_ntdll.h" 4 | #include "tlhelp32.h" 5 | #include "Psapi.h" 6 | #include "WingString.class.h" 7 | #include "WingWmic.class.h" 8 | #pragma comment(lib,"Psapi.lib") 9 | #pragma comment(lib,"Kernel32.lib") 10 | 11 | NTSTATUS WingOpenProcess( 12 | _In_ HMODULE hNtDll, 13 | _Out_ PHANDLE ProcessHandle, 14 | _In_ ACCESS_MASK DesiredAccess, 15 | _In_ HANDLE ProcessId 16 | ) 17 | { 18 | NTSTATUS status; 19 | OBJECT_ATTRIBUTES objectAttributes; 20 | CLIENT_ID clientId; 21 | 22 | clientId.UniqueProcess = ProcessId; 23 | clientId.UniqueThread = NULL; 24 | 25 | NTOPENPROCESS NtOpenProcess = (NTOPENPROCESS)GetProcAddress(hNtDll, "NtOpenProcess"); 26 | InitializeObjectAttributes(&objectAttributes, NULL, 0, NULL, NULL); 27 | status = NtOpenProcess(ProcessHandle, DesiredAccess, &objectAttributes, &clientId); 28 | 29 | return status; 30 | } 31 | 32 | 33 | NTSTATUS WingQueryProcessVariableSize( 34 | _In_ HMODULE hNtDll, 35 | _In_ HANDLE ProcessHandle, 36 | _In_ PROCESSINFOCLASS ProcessInformationClass, 37 | _Out_ PVOID *Buffer 38 | ) 39 | { 40 | NTSTATUS status; 41 | PVOID buffer; 42 | ULONG returnLength = 0; 43 | 44 | NTQUERYINFORMATIONPROCESS NtQueryInformationProcess = 45 | (NTQUERYINFORMATIONPROCESS)GetProcAddress(hNtDll, "NtQueryInformationProcess"); 46 | status = NtQueryInformationProcess( 47 | ProcessHandle, 48 | ProcessInformationClass, 49 | NULL, 0, &returnLength 50 | ); 51 | 52 | if (status != STATUS_BUFFER_OVERFLOW && 53 | status != STATUS_BUFFER_TOO_SMALL && 54 | status != STATUS_INFO_LENGTH_MISMATCH) { 55 | return status; 56 | } 57 | 58 | buffer = (LPVOID)malloc(returnLength); 59 | memset(buffer,0,returnLength); 60 | status = NtQueryInformationProcess(ProcessHandle, ProcessInformationClass, buffer, returnLength, &returnLength); 61 | 62 | if (NT_SUCCESS(status)){ 63 | *Buffer = buffer; 64 | } else { 65 | free(buffer); 66 | } 67 | return status; 68 | } 69 | 70 | void WingGetProcessCommandLine(DWORD process_id, char* &lpszCommandLine) 71 | { 72 | char *empty_string = "\0"; 73 | HANDLE hProcess = ::OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, process_id); 74 | HANDLE hToken; 75 | 76 | if (!hProcess) { 77 | lpszCommandLine = new char[4]; 78 | //sprintf(lpszCommandLine,"%s",empty_string); 79 | sprintf_s(lpszCommandLine,4,"%s",empty_string); 80 | return; 81 | } 82 | 83 | if (OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken)) { 84 | TOKEN_PRIVILEGES tp; 85 | tp.PrivilegeCount = 1; 86 | LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tp.Privileges[0].Luid); 87 | tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 88 | AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL); 89 | CloseHandle(hToken); 90 | } 91 | 92 | DWORD dwThreadId; 93 | HANDLE hThread = ::CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)GetCommandLine, NULL, 0, &dwThreadId); 94 | 95 | if (!hThread) { 96 | lpszCommandLine = new char[4]; 97 | sprintf_s(lpszCommandLine,4,"%s",empty_string); 98 | CloseHandle(hProcess); 99 | return; 100 | } 101 | 102 | DWORD dwExitCode = 0; 103 | SIZE_T dwReaded = 0; 104 | int buf_size = 10240; 105 | lpszCommandLine = new char[buf_size]; 106 | 107 | memset(lpszCommandLine,0,buf_size); 108 | ::WaitForSingleObject(hThread, 500); 109 | ::GetExitCodeThread(hThread, &dwExitCode); 110 | SetLastError(0); 111 | ::ReadProcessMemory(hProcess, (LPCVOID)&dwExitCode, lpszCommandLine, sizeof(char)*buf_size, &dwReaded); 112 | 113 | int start = 10240; 114 | if (299 == GetLastError()) { 115 | delete[] lpszCommandLine; 116 | lpszCommandLine = NULL; 117 | 118 | while(1) { 119 | lpszCommandLine = new char[start]; 120 | memset(lpszCommandLine, 0, start); 121 | SetLastError(0); 122 | ::ReadProcessMemory(hProcess, (LPCVOID)&dwExitCode, lpszCommandLine, sizeof(char)*start, &dwReaded); 123 | 124 | if ( 299 == GetLastError()) { 125 | delete[] lpszCommandLine; 126 | lpszCommandLine = NULL; 127 | start--; 128 | if (start<= 0) break; 129 | } else { 130 | break; 131 | } 132 | } 133 | } 134 | 135 | if (lpszCommandLine == NULL) { 136 | lpszCommandLine = new char[4]; 137 | sprintf_s(lpszCommandLine,4,"%s",empty_string); 138 | } 139 | CloseHandle(hProcess); 140 | } 141 | 142 | DWORD WingGetCurrentProcessInfo(PROCESSINFO *&all_process, int from, int max_count , int has_current_process) 143 | { 144 | DWORD process_id = GetCurrentProcessId(); 145 | HANDLE handle = INVALID_HANDLE_VALUE; 146 | 147 | PROCESS_MEMORY_COUNTERS pmc; 148 | PROCESSENTRY32 pe32; 149 | 150 | pe32.dwSize = sizeof(pe32); 151 | HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 152 | 153 | if (hProcessSnap == INVALID_HANDLE_VALUE) { 154 | return 0; 155 | } 156 | 157 | BOOL bMore = ::Process32First(hProcessSnap, &pe32); 158 | MODULEENTRY32 me32; 159 | me32.dwSize = sizeof(MODULEENTRY32); 160 | 161 | HANDLE hModuleSnap = INVALID_HANDLE_VALUE , hProcess = INVALID_HANDLE_VALUE; 162 | char *exepath = NULL; 163 | DWORD outsize = 0; 164 | int dwTotalProcess = 0; 165 | 166 | HMODULE hNtDll = GetModuleHandleA("ntdll.dll"); 167 | while (bMore) { 168 | if (has_current_process) { 169 | if (pe32.th32ProcessID == process_id) { 170 | bMore = ::Process32Next(hProcessSnap, &pe32); 171 | continue; 172 | } 173 | } 174 | 175 | if (pe32.th32ProcessID != process_id && pe32.th32ParentProcessID != process_id) { 176 | bMore = ::Process32Next(hProcessSnap, &pe32); 177 | continue; 178 | } 179 | 180 | if (all_process == NULL) { 181 | dwTotalProcess++; 182 | bMore = ::Process32Next(hProcessSnap, &pe32); 183 | continue; 184 | } 185 | 186 | PROCESSINFO *process_item = &all_process[from+dwTotalProcess]; 187 | hModuleSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe32.th32ProcessID); 188 | ZeroMemory(&me32,me32.dwSize); 189 | me32.dwSize = sizeof(MODULEENTRY32); 190 | 191 | if (hModuleSnap != INVALID_HANDLE_VALUE) { 192 | Module32First(hModuleSnap , &me32); //QueryFullProcessImageName GetProcessImageFileName 193 | CloseHandle(hModuleSnap); 194 | hModuleSnap = INVALID_HANDLE_VALUE; 195 | } 196 | 197 | SetLastError(0); 198 | process_item->process_id = pe32.th32ProcessID ; 199 | 200 | int size = sizeof(pe32.szExeFile)+1; 201 | process_item->process_name = new char[size]; 202 | memset(process_item->process_name,0,size); 203 | 204 | sprintf_s(process_item->process_name,size,"%s",pe32.szExeFile); 205 | process_item->parent_process_id = pe32.th32ParentProcessID; 206 | 207 | size = sizeof(me32.szExePath)+1; 208 | process_item->file_path = new char[size];//me32.szExePath; 209 | memset(process_item->file_path, 0, size); 210 | 211 | sprintf_s(process_item->file_path,size,"%s",me32.szExePath); 212 | process_item->cpu_time = 0; 213 | 214 | size = sizeof(pe32.szExeFile)+1; 215 | process_item->file_name = new char[size]; 216 | memset(process_item->file_name,0,size); 217 | sprintf_s(process_item->file_name,size,"%s",pe32.szExeFile); 218 | 219 | 220 | process_item->thread_count = 0; 221 | process_item->base_priority = 0; 222 | process_item->handle_count = 0; 223 | process_item->working_set_size = 0; 224 | 225 | //process_item->command_line = new char[4]; 226 | //memset(process_item->command_line,0,4); 227 | 228 | if (process_id == pe32.th32ProcessID) { 229 | handle = GetCurrentProcess(); 230 | char *comm = GetCommandLineA(); 231 | size = strlen(comm)+1; 232 | process_item->command_line = new char[size]; 233 | memset(process_item->command_line,0,size); 234 | sprintf_s(process_item->command_line,size,"%s",comm); 235 | } else { 236 | NTSTATUS status = WingOpenProcess(hNtDll, &hProcess, PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,(HANDLE)pe32.th32ProcessID); 237 | if (NT_SUCCESS(status)) { 238 | LPVOID commandline = NULL; 239 | if (NT_SUCCESS(WingQueryProcessVariableSize(hNtDll, hProcess, ProcessCommandLineInformation, (PVOID *)&commandline))) { 240 | process_item->command_line = wing_str_wchar_to_char((const wchar_t*)((PUNICODE_STRING)commandline)->Buffer) ; 241 | free(commandline); 242 | commandline = NULL; 243 | } else { 244 | process_item->command_line = new char[4]; 245 | memset(process_item->command_line , 0 , 4); 246 | } 247 | } else { 248 | process_item->command_line = new char[4]; 249 | memset(process_item->command_line , 0 , 4); 250 | } 251 | } 252 | 253 | GetProcessMemoryInfo(handle, &pmc, sizeof(pmc)); 254 | process_item->working_set_size = pmc.WorkingSetSize; 255 | GetProcessHandleCount(handle ,&process_item->handle_count); 256 | process_item->base_priority = GetPriorityClass(handle); 257 | CloseHandle(handle); 258 | 259 | bMore = ::Process32Next(hProcessSnap, &pe32); 260 | dwTotalProcess++; 261 | 262 | if (dwTotalProcess > max_count) { 263 | break; 264 | } 265 | } 266 | 267 | if (hProcessSnap) { 268 | CloseHandle(hProcessSnap); 269 | } 270 | 271 | FreeLibrary(hNtDll); 272 | 273 | return dwTotalProcess; 274 | } 275 | 276 | unsigned long WingQueryProcess(PROCESSINFO *&all_process , int max_count) 277 | { 278 | 279 | PSYSTEM_PROCESSES pSystemProc; 280 | HMODULE hNtDll = NULL; 281 | LPVOID lpSystemInfo = NULL; 282 | DWORD dwNumberBytes = MAX_INFO_BUF_LEN; 283 | DWORD dwTotalProcess = 0; 284 | DWORD dwReturnLength; 285 | NTSTATUS Status; 286 | LONGLONG llTempTime; 287 | NTQUERYSYSTEMINFORMATION NtQuerySystemInformation; 288 | 289 | char *empty_string = "\0"; 290 | char *sys_process_name = "System Idle Process\0"; 291 | int has_current_process = 0; 292 | DWORD current_process_id = GetCurrentProcessId(); 293 | 294 | //__try 295 | //{ 296 | hNtDll = GetModuleHandleA("ntdll.dll"); 297 | if (hNtDll == NULL) { 298 | if (lpSystemInfo != NULL) { 299 | free(lpSystemInfo); 300 | } 301 | if (hNtDll != NULL) { 302 | FreeLibrary(hNtDll); 303 | } 304 | return 0; 305 | } 306 | 307 | NtQuerySystemInformation = (NTQUERYSYSTEMINFORMATION)GetProcAddress(hNtDll, "NtQuerySystemInformation"); 308 | if (NtQuerySystemInformation == NULL) { 309 | if (lpSystemInfo != NULL) { 310 | free(lpSystemInfo); 311 | } 312 | if (hNtDll != NULL) { 313 | FreeLibrary(hNtDll); 314 | } 315 | return 0; 316 | } 317 | 318 | lpSystemInfo = (LPVOID)malloc(dwNumberBytes); 319 | Status = NtQuerySystemInformation(SystemProcessInformation, lpSystemInfo, dwNumberBytes, &dwReturnLength); 320 | if (Status == STATUS_INFO_LENGTH_MISMATCH) { 321 | if (lpSystemInfo != NULL) { 322 | free(lpSystemInfo); 323 | } 324 | if (hNtDll != NULL) { 325 | FreeLibrary(hNtDll); 326 | } 327 | return 0; 328 | } 329 | 330 | else if (Status != STATUS_SUCCESS) { 331 | if (lpSystemInfo != NULL) { 332 | free(lpSystemInfo); 333 | } 334 | if (hNtDll != NULL) { 335 | FreeLibrary(hNtDll); 336 | } 337 | return 0; 338 | } 339 | 340 | pSystemProc = (PSYSTEM_PROCESSES)lpSystemInfo; 341 | HANDLE hProcess; 342 | 343 | while (pSystemProc->NextEntryDelta != 0) { 344 | if (all_process == NULL) { 345 | dwTotalProcess++; 346 | pSystemProc = (PSYSTEM_PROCESSES)((char *)pSystemProc + pSystemProc->NextEntryDelta); 347 | continue; 348 | } 349 | 350 | PROCESSINFO *process_item = &all_process[dwTotalProcess]; 351 | 352 | if (pSystemProc->ProcessId != 0) { 353 | process_item->process_name = wing_str_wchar_to_char((const wchar_t*)pSystemProc->ProcessName.Buffer) ; 354 | } else { 355 | int len = strlen(sys_process_name); 356 | process_item->process_name = new char[len+1]; 357 | memset(process_item->process_name , 0 , len+1); 358 | sprintf_s(process_item->process_name ,(len+1), "%s" , sys_process_name); 359 | } 360 | 361 | if (current_process_id == pSystemProc->ProcessId) { 362 | has_current_process = 1; 363 | } 364 | 365 | process_item->command_line = NULL; 366 | process_item->file_name = NULL; 367 | process_item->file_path = NULL; 368 | 369 | if (NT_SUCCESS(WingOpenProcess(hNtDll, &hProcess, PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,(HANDLE)pSystemProc->ProcessId))) { 370 | LPVOID commandline = NULL; 371 | if (NT_SUCCESS(WingQueryProcessVariableSize(hNtDll, hProcess, ProcessCommandLineInformation, (PVOID *)&commandline))) { 372 | process_item->command_line = wing_str_wchar_to_char((const wchar_t*)((PUNICODE_STRING)commandline)->Buffer);; 373 | free(commandline); 374 | commandline = NULL; 375 | } else { 376 | process_item->command_line = new char[4]; 377 | memset(process_item->command_line , 0 , 4); 378 | } 379 | 380 | PUNICODE_STRING fileName; 381 | if (NT_SUCCESS(WingQueryProcessVariableSize(hNtDll, hProcess, ProcessImageFileName, (PVOID*)&fileName))) { 382 | process_item->file_name = wing_str_wchar_to_char((const wchar_t*)fileName->Buffer); 383 | free(fileName); 384 | } else { 385 | process_item->file_name = new char[4]; 386 | memset(process_item->file_name , 0 , 4); 387 | } 388 | 389 | PUNICODE_STRING filepath; 390 | if (NT_SUCCESS(WingQueryProcessVariableSize(hNtDll, hProcess, ProcessImageFileNameWin32, (PVOID*)&filepath))){ 391 | process_item->file_path = wing_str_wchar_to_char((const wchar_t*)filepath->Buffer); 392 | free(filepath); 393 | } else { 394 | process_item->file_path = new char[4]; 395 | memset(process_item->file_path , 0 , 4); 396 | } 397 | } else { 398 | process_item->command_line = new char[4]; 399 | process_item->file_name = new char[4]; 400 | process_item->file_path = new char[4]; 401 | 402 | memset(process_item->command_line , 0 , 4); 403 | memset(process_item->file_name , 0 , 4); 404 | memset(process_item->file_path , 0 , 4); 405 | } 406 | 407 | process_item->process_id = pSystemProc->ProcessId; 408 | process_item->parent_process_id = pSystemProc->InheritedFromProcessId; 409 | process_item->working_set_size = pSystemProc->VmCounters.WorkingSetSize; 410 | process_item->base_priority = (unsigned long)pSystemProc->BasePriority; 411 | process_item->thread_count = pSystemProc->ThreadCount; 412 | process_item->handle_count = pSystemProc->HandleCount; 413 | 414 | llTempTime = pSystemProc->KernelTime.QuadPart + pSystemProc->UserTime.QuadPart; 415 | llTempTime /= 10000; 416 | llTempTime /= 1000; //��ȷ���� 417 | 418 | process_item->cpu_time = (unsigned long)llTempTime; 419 | 420 | dwTotalProcess ++; 421 | if (dwTotalProcess > (DWORD)max_count) break; 422 | pSystemProc = (PSYSTEM_PROCESSES)((char *)pSystemProc + pSystemProc->NextEntryDelta); 423 | } 424 | //} 425 | //__finally 426 | //{ 427 | if (lpSystemInfo != NULL) { 428 | free(lpSystemInfo); 429 | } 430 | if (hNtDll != NULL) { 431 | FreeLibrary(hNtDll); 432 | } 433 | //} 434 | 435 | dwTotalProcess += WingGetCurrentProcessInfo(all_process, dwTotalProcess , max_count - dwTotalProcess , has_current_process); 436 | 437 | return dwTotalProcess; 438 | } 439 | 440 | int WingQueryObject(HANDLE handle) 441 | { 442 | if (handle == INVALID_HANDLE_VALUE || !handle) { 443 | return -1; 444 | } 445 | 446 | HMODULE hNtDll = GetModuleHandleA("ntdll.dll"); 447 | if (NULL == hNtDll) { 448 | return -1; 449 | } 450 | 451 | WingNtQueryObject NtQueryObject = (WingNtQueryObject)GetProcAddress(hNtDll , "NtQueryObject"); 452 | SYSTEM_HANDLE_STATE *pOutBuffer = (SYSTEM_HANDLE_STATE *)malloc(0x38); 453 | memset(pOutBuffer,0,0x38); 454 | 455 | if (!NT_SUCCESS(NtQueryObject(handle, ObjectBasicInformation, pOutBuffer, 0x38, NULL))) { 456 | free(pOutBuffer); 457 | return 0; 458 | } 459 | 460 | int count = pOutBuffer->HandleCount; 461 | free(pOutBuffer); 462 | FreeLibrary(hNtDll); 463 | 464 | return count; 465 | } 466 | 467 | int WingWindowsVersion() 468 | { 469 | RTL_OSVERSIONINFOEXW versionInfo; 470 | ULONG majorVersion; 471 | ULONG minorVersion; 472 | ULONG WindowsVersion; 473 | RTL_OSVERSIONINFOEXW PhOsVersion; 474 | 475 | versionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); 476 | HMODULE hNtDll = GetModuleHandleA("ntdll.dll"); 477 | 478 | if (NULL == hNtDll) { 479 | return -1; 480 | } 481 | 482 | RTLGETVERSION RtlGetVersion = (RTLGETVERSION)GetProcAddress(hNtDll,"RtlGetVersion"); 483 | 484 | if (!NT_SUCCESS(RtlGetVersion((PRTL_OSVERSIONINFOW)&versionInfo))) { 485 | FreeLibrary(hNtDll); 486 | return WING_WINDOWS_NEW ; 487 | } 488 | 489 | memcpy(&PhOsVersion, &versionInfo, sizeof(RTL_OSVERSIONINFOEXW)); 490 | majorVersion = versionInfo.dwMajorVersion; 491 | minorVersion = versionInfo.dwMinorVersion; 492 | 493 | if (majorVersion == 5 && minorVersion < 1 || majorVersion < 5) { 494 | WindowsVersion = WING_WINDOWS_ANCIENT; 495 | } 496 | /* Windows XP */ 497 | else if (majorVersion == 5 && minorVersion == 1) { 498 | WindowsVersion = WING_WINDOWS_XP; 499 | } 500 | /* Windows Server 2003 */ 501 | else if (majorVersion == 5 && minorVersion == 2) { 502 | WindowsVersion = WING_WINDOWS_SERVER_2003; 503 | } 504 | /* Windows Vista, Windows Server 2008 */ 505 | else if (majorVersion == 6 && minorVersion == 0) { 506 | WindowsVersion = WING_WINDOWS_VISTA; 507 | } 508 | /* Windows 7, Windows Server 2008 R2 */ 509 | else if (majorVersion == 6 && minorVersion == 1) { 510 | WindowsVersion = WING_WINDOWS_7; 511 | } 512 | /* Windows 8 */ 513 | else if (majorVersion == 6 && minorVersion == 2) { 514 | WindowsVersion = WING_WINDOWS_8; 515 | } 516 | /* Windows 8.1 */ 517 | else if (majorVersion == 6 && minorVersion == 3) { 518 | WindowsVersion = WING_WINDOWS_8_1; 519 | } 520 | /* Windows 10 */ 521 | else if (majorVersion == 10 && minorVersion == 0) { 522 | WindowsVersion = WING_WINDOWS_10; 523 | } 524 | else if (majorVersion == 10 && minorVersion > 0 || majorVersion > 10) { 525 | WindowsVersion = WING_WINDOWS_NEW; 526 | } 527 | FreeLibrary(hNtDll); 528 | return WindowsVersion ; 529 | } 530 | 531 | unsigned long WingQueryProcessByProcessID(PROCESSINFO *process_item, unsigned long process_id) 532 | { 533 | 534 | PSYSTEM_PROCESSES pSystemProc; 535 | HMODULE hNtDll = NULL; 536 | LPVOID lpSystemInfo = NULL; 537 | DWORD dwNumberBytes = MAX_INFO_BUF_LEN; 538 | DWORD dwTotalProcess = 0; 539 | DWORD dwReturnLength; 540 | NTSTATUS Status; 541 | LONGLONG llTempTime; 542 | NTQUERYSYSTEMINFORMATION NtQuerySystemInformation; 543 | 544 | char *empty_string = "\0"; 545 | char *sys_process_name = "System Idle Process\0"; 546 | int has_current_process = 0; 547 | DWORD current_process_id = GetCurrentProcessId(); 548 | 549 | //__try 550 | //{ 551 | hNtDll = GetModuleHandleA("ntdll.dll"); 552 | if (hNtDll == NULL) { 553 | if (lpSystemInfo != NULL) { 554 | free(lpSystemInfo); 555 | } 556 | if (hNtDll != NULL) { 557 | FreeLibrary(hNtDll); 558 | } 559 | return 0; 560 | } 561 | 562 | NtQuerySystemInformation = (NTQUERYSYSTEMINFORMATION)GetProcAddress(hNtDll, "NtQuerySystemInformation"); 563 | if (NtQuerySystemInformation == NULL) { 564 | if (lpSystemInfo != NULL) { 565 | free(lpSystemInfo); 566 | } 567 | if (hNtDll != NULL) { 568 | FreeLibrary(hNtDll); 569 | } 570 | return 0; 571 | } 572 | 573 | lpSystemInfo = (LPVOID)malloc(dwNumberBytes); 574 | Status = NtQuerySystemInformation(SystemProcessInformation, lpSystemInfo, dwNumberBytes, &dwReturnLength); 575 | if (Status == STATUS_INFO_LENGTH_MISMATCH) { 576 | if (lpSystemInfo != NULL) { 577 | free(lpSystemInfo); 578 | } 579 | if (hNtDll != NULL) { 580 | FreeLibrary(hNtDll); 581 | } 582 | return 0; 583 | } else if (Status != STATUS_SUCCESS) { 584 | if (lpSystemInfo != NULL) { 585 | free(lpSystemInfo); 586 | } 587 | if (hNtDll != NULL) { 588 | FreeLibrary(hNtDll); 589 | } 590 | return 0; 591 | } 592 | 593 | pSystemProc = (PSYSTEM_PROCESSES)lpSystemInfo; 594 | HANDLE hProcess; 595 | 596 | while (pSystemProc->NextEntryDelta != 0) { 597 | if (pSystemProc->ProcessId != process_id) { 598 | pSystemProc = (PSYSTEM_PROCESSES)((char *)pSystemProc + pSystemProc->NextEntryDelta); 599 | continue; 600 | } 601 | //PROCESSINFO *process_item = &all_process[dwTotalProcess]; 602 | if (pSystemProc->ProcessId != 0) { 603 | process_item->process_name = wing_str_wchar_to_char((const wchar_t*)pSystemProc->ProcessName.Buffer); 604 | } else { 605 | int len = strlen(sys_process_name); 606 | process_item->process_name = new char[len + 1]; 607 | memset(process_item->process_name, 0, len + 1); 608 | sprintf_s(process_item->process_name, (len + 1), "%s", sys_process_name); 609 | } 610 | 611 | if (current_process_id == pSystemProc->ProcessId) { 612 | has_current_process = 1; 613 | } 614 | 615 | process_item->command_line = NULL; 616 | process_item->file_name = NULL; 617 | process_item->file_path = NULL; 618 | 619 | if (NT_SUCCESS(WingOpenProcess(hNtDll, &hProcess, PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, (HANDLE)pSystemProc->ProcessId))) { 620 | LPVOID commandline = NULL; 621 | if (NT_SUCCESS(WingQueryProcessVariableSize(hNtDll, hProcess, ProcessCommandLineInformation, (PVOID *)&commandline))) { 622 | process_item->command_line = wing_str_wchar_to_char((const wchar_t*)((PUNICODE_STRING)commandline)->Buffer);; 623 | free(commandline); 624 | commandline = NULL; 625 | } else { 626 | process_item->command_line = new char[4]; 627 | memset(process_item->command_line, 0, 4); 628 | } 629 | 630 | PUNICODE_STRING fileName; 631 | if (NT_SUCCESS(WingQueryProcessVariableSize(hNtDll, hProcess, ProcessImageFileName, (PVOID*)&fileName))) { 632 | process_item->file_name = wing_str_wchar_to_char((const wchar_t*)fileName->Buffer); 633 | free(fileName); 634 | } else { 635 | process_item->file_name = new char[4]; 636 | memset(process_item->file_name, 0, 4); 637 | } 638 | 639 | PUNICODE_STRING filepath; 640 | if (NT_SUCCESS(WingQueryProcessVariableSize(hNtDll, hProcess, ProcessImageFileNameWin32, (PVOID*)&filepath))) { 641 | process_item->file_path = wing_str_wchar_to_char((const wchar_t*)filepath->Buffer); 642 | free(filepath); 643 | } else { 644 | process_item->file_path = new char[4]; 645 | memset(process_item->file_path, 0, 4); 646 | } 647 | } else { 648 | process_item->command_line = new char[4]; 649 | process_item->file_name = new char[4]; 650 | process_item->file_path = new char[4]; 651 | 652 | memset(process_item->command_line, 0, 4); 653 | memset(process_item->file_name, 0, 4); 654 | memset(process_item->file_path, 0, 4); 655 | } 656 | 657 | //process_item->thread_id = pSystemProc->Threads[0].ClientId; 658 | process_item->process_id = pSystemProc->ProcessId; 659 | process_item->parent_process_id = pSystemProc->InheritedFromProcessId; 660 | process_item->working_set_size = pSystemProc->VmCounters.WorkingSetSize; 661 | process_item->base_priority = (unsigned long)pSystemProc->BasePriority; 662 | process_item->thread_count = pSystemProc->ThreadCount; 663 | process_item->handle_count = pSystemProc->HandleCount; 664 | 665 | llTempTime = pSystemProc->KernelTime.QuadPart + pSystemProc->UserTime.QuadPart; 666 | llTempTime /= 10000; 667 | llTempTime /= 1000; 668 | 669 | process_item->cpu_time = (unsigned long)llTempTime; 670 | dwTotalProcess++; 671 | //if (dwTotalProcess > (DWORD)max_count) break; 672 | pSystemProc = (PSYSTEM_PROCESSES)((char *)pSystemProc + pSystemProc->NextEntryDelta); 673 | 674 | break; 675 | } 676 | //} 677 | //__finally 678 | //{ 679 | if (lpSystemInfo != NULL) { 680 | free(lpSystemInfo); 681 | } 682 | if (hNtDll != NULL) { 683 | FreeLibrary(hNtDll); 684 | } 685 | //} 686 | //dwTotalProcess += WingGetCurrentProcessInfo(all_process, dwTotalProcess, max_count - dwTotalProcess, has_current_process); 687 | 688 | return dwTotalProcess; 689 | } --------------------------------------------------------------------------------