no message

master
zcy 2021-07-25 02:32:17 +08:00
parent 12e30ddea4
commit be55c4218d
13 changed files with 286 additions and 59 deletions

View File

@ -17,7 +17,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
# using Intel C++ # using Intel C++
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options("/std:c++17")
# using Visual Studio C++ # using Visual Studio C++
endif() endif()

View File

@ -31,7 +31,7 @@ namespace Loger{
public: public:
_C_Loger(FILE *p); _C_Loger(FILE *p);
_C_Loger(string path); _C_Loger(string path);
#define DEBUG_FILE_POSITION __FILE__,__LINE__
int Debug(string,string,int); int Debug(string,string,int);
int Log(); int Log();
int LogFile(); int LogFile();

View File

@ -75,6 +75,7 @@ int selectsort(T *data,uint64_t len,CompareHanlder<T> handle){
data[i] = tmp; data[i] = tmp;
} }
} }
template <typename T> template <typename T>
void swap(T *a1,T *a2){ void swap(T *a1,T *a2){
T tmp = *a1; T tmp = *a1;

View File

@ -0,0 +1,85 @@
/*
* @Author: your name
* @Date: 2021-07-23 23:39:57
* @LastEditTime: 2021-07-25 02:31:24
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: \generallib\general\src\function\daemon.c
*/
#include "daemon.h"
BOOL SetProcessPrivilege(char *lpName, BOOL opt)
{
HANDLE tokenhandle;
TOKEN_PRIVILEGES NewState;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tokenhandle))
{
LookupPrivilegeValue(NULL, lpName, &NewState.Privileges[0].Luid);
NewState.PrivilegeCount = 1;
NewState.Privileges[0].Attributes = opt != 0 ? 2 : 0;
AdjustTokenPrivileges(tokenhandle, FALSE, &NewState, sizeof(NewState), NULL, NULL);
CloseHandle(tokenhandle);
return 1;
}
else
{
return 0;
}
}
int RangeProcess()
{
DWORD Proc_pid[1024], Retn_bytes, Proc_count, Retn_bytes2;
unsigned int i;
HMODULE hMod[1024];
HANDLE hProcess;
char szModName[MAX_PATH];
if (EnumProcesses(Proc_pid, sizeof(Proc_pid), &Retn_bytes))
{
Proc_count = Retn_bytes / sizeof(DWORD);
SetProcessPrivilege("SeDebugPrivilege", 1);
for (i = 0; i < Proc_count; i++)
{
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, Proc_pid[i]);
if (hProcess != NULL)
{
EnumProcessModules(hProcess, hMod, sizeof(hMod), &Retn_bytes2);
GetModuleFileNameEx(hProcess, hMod[0], szModName, sizeof(szModName));
printf("PID=%d Path=%s\n", Proc_pid[i], szModName);
}
CloseHandle(hProcess);
}
SetProcessPrivilege("SeDebugPrivilege", 0);
}
return 0;
}
int test_fork()
{
char szCommandLine[] = "D:\\game\\The Legend of Zelda Breath of the Wild\\cemu\\cemu.exe";
STARTUPINFO si = {sizeof(si)};
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW; //指定wShowWindow成员有效
si.wShowWindow = TRUE; //此成员设为TRUE的话则显示新建进程的主窗口
BOOL bRet = CreateProcess(
NULL, //不在此指定可执行文件的文件名
szCommandLine, //命令行参数
NULL, //默认进程安全性
NULL, //默认进程安全性
FALSE, //指定当前进程内句柄不可以被子进程继承
CREATE_NEW_CONSOLE, //为新进程创建一个新的控制台窗口
NULL, //使用本进程的环境变量
NULL, //使用本进程的驱动器和目录
&si,
&pi);
if (bRet)
{
//不使用的句柄最好关掉
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
printf("new process id %d\n", pi.dwProcessId);
printf("new thread id %d\n", pi.dwThreadId);
}
return 0;
}

View File

@ -0,0 +1,24 @@
/*
* @Author: your name
* @Date: 2021-07-23 23:40:36
* @LastEditTime: 2021-07-25 02:31:09
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edi
* @FilePath: \generallib\general\src\function\daemon.h
*/
#if __cplusplus >= 201103L
#pragma message("编译器支持c++11")
#endif
#include <list>
#include<iostream>
#include <algorithm>
using namespace std;
extern "C"{
#include<stdio.h>
#include <time.h>
}
#include <windows.h>
#include <Tlhelp32.h>
#include <psapi.h>

View File

@ -1,4 +1,4 @@
#include "PackageReceiver.h" #include "package_receiver.h"
PackageReceiver::PackageReceiver() PackageReceiver::PackageReceiver()
{ {

View File

@ -2,7 +2,7 @@
// Created by 29019 on 2020/4/18. // Created by 29019 on 2020/4/18.
// //
#include "TcpClient.h" #include "tcp_client.h"
void conn_writecb(struct bufferevent *, void *); void conn_writecb(struct bufferevent *, void *);
void conn_readcb(struct bufferevent *, void *); void conn_readcb(struct bufferevent *, void *);

View File

@ -1,3 +1,11 @@
/*
* @Author: your name
* @Date: 2021-06-12 14:42:28
* @LastEditTime: 2021-07-24 00:47:43
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \generallib\general\src\net\tcp_client.h
*/
// //
// Created by 29019 on 2020/4/18. // Created by 29019 on 2020/4/18.
// //
@ -15,7 +23,8 @@
#define EVENT__HAVE_PTHREADS #define EVENT__HAVE_PTHREADS
#endif #endif
extern "C"{ extern "C"
{
#include "third/include/event2/bufferevent.h" #include "third/include/event2/bufferevent.h"
#include "third/include/event2/buffer.h" #include "third/include/event2/buffer.h"
#include "third/include/event2/listener.h" #include "third/include/event2/listener.h"
@ -25,19 +34,22 @@ extern "C"{
}; };
#include <iostream> #include <iostream>
#include "PackageReceiver.h" #include "package_receiver.h"
#include <mutex> #include <mutex>
#include <thread> #include <thread>
using namespace std; using namespace std;
class TcpClientLibevent { class TcpClientLibevent
{
public: public:
typedef enum { typedef enum
{
UNCONNECTED, // 未连接 UNCONNECTED, // 未连接
CONNECTED, //已经连接 CONNECTED, //已经连接
FAIL, // 连接失败 FAIL, // 连接失败
} Status; } Status;
class TcpClientObserver{ class TcpClientObserver
{
public: public:
virtual ~TcpClientObserver() { return; } virtual ~TcpClientObserver() { return; }
mutex mMux; mutex mMux;
@ -47,7 +59,8 @@ public:
virtual void OnClose() { return; }; virtual void OnClose() { return; };
}; };
TcpClientLibevent(std::string addrinfo, int port, TcpClientObserver *p); TcpClientLibevent(std::string addrinfo, int port, TcpClientObserver *p);
~TcpClientLibevent(){ ~TcpClientLibevent()
{
event_base_free(mBase); event_base_free(mBase);
}; };
int ConnectServer(); int ConnectServer();
@ -59,6 +72,7 @@ public:
int Close(); int Close();
Status mStatus; Status mStatus;
TcpClientObserver *mObserver; TcpClientObserver *mObserver;
private: private:
bool mReConnect = false; bool mReConnect = false;
int sendData(void *, size_t); int sendData(void *, size_t);

View File

@ -1,3 +1,11 @@
/*
* @Author: your name
* @Date: 2020-10-11 17:37:54
* @LastEditTime: 2021-07-24 00:46:47
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \generallib\general\src\utils.cpp
*/
// //
// Created by 29019 on 2019/5/2. // Created by 29019 on 2019/5/2.
// //
@ -39,7 +47,7 @@ inline ENV_SYS CurrentEnvSys() {
return ENV_LINUX; return ENV_LINUX;
#endif #endif
#ifdef _WINDOWS #ifdef _WINDOWS
return ENV_WINDOWS return ENV_WINDOWS;
#endif #endif
#ifdef _UNIX #ifdef _UNIX
return ENV_UNIX return ENV_UNIX

View File

@ -4,15 +4,13 @@ add_definitions(-std=c++11)
message("current dir" ${CMAKE_CURRENT_SOURCE_DIR}) message("current dir" ${CMAKE_CURRENT_SOURCE_DIR})
# set(CMAKE_CXX_FLAGS "-fno-elide-constructors") # set(CMAKE_CXX_FLAGS "-fno-elide-constructors")
aux_source_directory(. SOURCE)
message(info ${SOURCE}) message(info ${SOURCE})
link_directories("./third/jsoncpp/lib/") link_directories("./third/jsoncpp/lib/")
link_directories("../../../obj/") link_directories("../../../obj/")
link_libraries(jsoncpp)
link_libraries(generallib) link_libraries(generallib)
add_executable(cpp11 ${SOURCE} ) add_executable(cpp11 cpp11_test.cpp )
include_directories("./third/jsoncpp/include/pkgsrc/include/json") include_directories("./third/jsoncpp/include/pkgsrc/include/json")
include_directories("../../../obj/inc/") include_directories("../../../obj/inc/")

View File

@ -1,3 +1,11 @@
/*
* @Author: your name
* @Date: 2021-03-15 23:07:25
* @LastEditTime: 2021-07-24 23:19:57
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \cpp11\cpp11_test.cpp
*/
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#pragma message("编译器支持c++11") #pragma message("编译器支持c++11")
#endif #endif
@ -13,9 +21,89 @@ extern "C"{
#include<stdio.h> #include<stdio.h>
#include <time.h> #include <time.h>
} }
#include <windows.h>
#include <Tlhelp32.h>
#include "loger.h" #include "loger.h"
#include <psapi.h>
int main(){ BOOL SetProcessPrivilege(char *lpName, BOOL opt)
{
HANDLE tokenhandle;
TOKEN_PRIVILEGES NewState;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tokenhandle))
{
LookupPrivilegeValue(NULL, lpName, &NewState.Privileges[0].Luid);
NewState.PrivilegeCount = 1;
NewState.Privileges[0].Attributes = opt != 0 ? 2 : 0;
AdjustTokenPrivileges(tokenhandle, FALSE, &NewState, sizeof(NewState), NULL, NULL);
CloseHandle(tokenhandle);
return 1;
}
else
{
return 0;
}
}
int RangeProcess()
{
DWORD Proc_pid[1024], Retn_bytes, Proc_count, Retn_bytes2;
unsigned int i;
HMODULE hMod[1024];
HANDLE hProcess;
char szModName[MAX_PATH];
if (EnumProcesses(Proc_pid, sizeof(Proc_pid), &Retn_bytes))
{
Proc_count = Retn_bytes / sizeof(DWORD);
SetProcessPrivilege("SeDebugPrivilege", 1);
for (i = 0; i < Proc_count; i++)
{
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, Proc_pid[i]);
if (hProcess != NULL)
{
EnumProcessModules(hProcess, hMod, sizeof(hMod), &Retn_bytes2);
GetModuleFileNameEx(hProcess, hMod[0], szModName, sizeof(szModName));
printf("PID=%d Path=%s\n", Proc_pid[i], szModName);
}
CloseHandle(hProcess);
}
SetProcessPrivilege("SeDebugPrivilege", 0);
}
return 0;
}
int test_fork()
{
char szCommandLine[] = "D:\\game\\The Legend of Zelda Breath of the Wild\\cemu\\cemu.exe";
STARTUPINFO si = {sizeof(si)};
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW; //指定wShowWindow成员有效
si.wShowWindow = TRUE; //此成员设为TRUE的话则显示新建进程的主窗口
BOOL bRet = CreateProcess(
NULL, //不在此指定可执行文件的文件名
szCommandLine, //命令行参数
NULL, //默认进程安全性
NULL, //默认进程安全性
FALSE, //指定当前进程内句柄不可以被子进程继承
CREATE_NEW_CONSOLE, //为新进程创建一个新的控制台窗口
NULL, //使用本进程的环境变量
NULL, //使用本进程的驱动器和目录
&si,
&pi);
if (bRet)
{
//不使用的句柄最好关掉
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
printf("new process id %d\n", pi.dwProcessId);
printf("new thread id %d\n", pi.dwThreadId);
}
return 0;
}
int main(int argc, char **argv)
{
// std::cout<<"test start"<<endl; // std::cout<<"test start"<<endl;
// try{ // try{
// std::cout<<"cpu count is "<<CoreCount()<<std::endl; // std::cout<<"cpu count is "<<CoreCount()<<std::endl;
@ -23,28 +111,36 @@ int main(){
// }catch( std::exception e){ // }catch( std::exception e){
// std::cout<<"exception"<<e.what(); // std::cout<<"exception"<<e.what();
// } // }
std::list<int> i; test_fork();
i.insert(i.begin(),2); while (true)
i.insert(i.begin(),3); {
i.insert(i.begin(),4); RangeProcess();
i.insert(i.begin(),5); Sleep(1000);
i.insert(i.begin(),6);
list<int>::iterator pos = (find(i.begin(), i.end(), 4));
i.insert(pos,1);
auto begin = i.begin();
while(*begin != 4)
begin++;
i.erase(begin);
for(auto x : i){
std::cout<<x<<"\r\n"<<std::endl;
} }
Loger::Loger loger("d://"); // std::list<int>
loger.Debug("测试测试",DEBUG_FILE_POSITION); // i;
std::cout<<"line " << __FILE__<<__LINE__<<" "<<__FUNCTION__<<std::endl; // i.insert(i.begin(),2);
// i.insert(i.begin(),3);
// i.insert(i.begin(),4);
// i.insert(i.begin(),5);
// i.insert(i.begin(),6);
// list<int>::iterator pos = (find(i.begin(), i.end(), 4));
// i.insert(pos,1);
// auto begin = i.begin();
// while(*begin != 4)
// begin++;
// i.erase(begin);
// for(auto x : i){
// std::cout<<x<<"\r\n"<<std::endl;
// }
// Loger::Loger loger("d://");
// loger.Debug("测试测试",DEBUG_FILE_POSITION);
// std::cout<<"line " << __FILE__<<__LINE__<<" "<<__FUNCTION__<<std::endl;
// TestRingBuffer(); // TestRingBuffer();
} }

View File

@ -139,6 +139,7 @@ int TestRValue()
v.push_back(std::move(str)); v.push_back(std::move(str));
std::cout << "After move, str is \"" << str << "\"\n"; std::cout << "After move, str is \"" << str << "\"\n";
std::cout << "The contents of the vector are \"" << v[0]; std::cout << "The contents of the vector are \"" << v[0];
return 0;
} }
int global = 0; int global = 0;
@ -191,5 +192,6 @@ int TestThreadPool()
double dr_ms = std::chrono::duration<double,std::milli>(t2-t1).count(); double dr_ms = std::chrono::duration<double,std::milli>(t2-t1).count();
std::cout<<"count is "<<dr_ms<<std::endl; std::cout<<"count is "<<dr_ms<<std::endl;
getchar(); getchar();
return 0;
} }