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")
# using Intel C++
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options("/std:c++17")
# using Visual Studio C++
endif()

View File

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

View File

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

View File

@ -2,7 +2,7 @@
// Created by 29019 on 2020/4/18.
//
#include "TcpClient.h"
#include "tcp_client.h"
void conn_writecb(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.
//
@ -9,13 +17,14 @@
#define _WIN32_WINNT 0x0500
#endif
#ifdef linux
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define EVENT__HAVE_PTHREADS
#endif
extern "C"{
extern "C"
{
#include "third/include/event2/bufferevent.h"
#include "third/include/event2/buffer.h"
#include "third/include/event2/listener.h"
@ -25,29 +34,33 @@ extern "C"{
};
#include <iostream>
#include "PackageReceiver.h"
#include "package_receiver.h"
#include <mutex>
#include <thread>
using namespace std;
using namespace std;
class TcpClientLibevent {
class TcpClientLibevent
{
public:
typedef enum {
UNCONNECTED, // 未连接
CONNECTED, //已经连接
FAIL, // 连接失败
}Status;
class TcpClientObserver{
typedef enum
{
UNCONNECTED, // 未连接
CONNECTED, //已经连接
FAIL, // 连接失败
} Status;
class TcpClientObserver
{
public:
virtual ~TcpClientObserver(){return;}
virtual ~TcpClientObserver() { return; }
mutex mMux;
virtual void OnConnected() { return; };
virtual void OnDisConnected() { return; };
virtual void OnData(uint8_t *dat,uint64_t len){return;};
virtual void OnClose(){return;};
virtual void OnData(uint8_t *dat, uint64_t len) { return; };
virtual void OnClose() { return; };
};
TcpClientLibevent(std::string addrinfo,int port, TcpClientObserver *p);
~TcpClientLibevent(){
TcpClientLibevent(std::string addrinfo, int port, TcpClientObserver *p);
~TcpClientLibevent()
{
event_base_free(mBase);
};
int ConnectServer();
@ -55,15 +68,16 @@ public:
int Dispatch();
int OnTCPPackage(uint8_t *, uint16_t);
int SetReconnect(bool);
int SetObserver(TcpClientObserver*);
int SetObserver(TcpClientObserver *);
int Close();
Status mStatus;
TcpClientObserver *mObserver;
private:
bool mReConnect = false;
int sendData(void*,size_t);
int sendData(void *, size_t);
struct event_base *mBase;
struct bufferevent* bev;
struct bufferevent *bev;
struct sockaddr_in mSrv;
std::thread *mThread;
mutex mLock;

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.
//
@ -39,17 +47,17 @@ inline ENV_SYS CurrentEnvSys() {
return ENV_LINUX;
#endif
#ifdef _WINDOWS
return ENV_WINDOWS
#endif
#ifdef _UNIX
return ENV_UNIX
#endif
#ifdef _WIN32
return ENV_WINDOWS;
#endif
#if !defined(linux) && defined(_WINDOWS)&&defined(_UNIX)&&defined(_WIN32)
#endif
#ifdef _UNIX
return ENV_UNIX
#endif
#ifdef _WIN32
return ENV_WINDOWS;
#endif
#if !defined(linux) && defined(_WINDOWS) && defined(_UNIX) && defined(_WIN32)
return ENV_NONE;
#endif
#endif
}
inline ENV_COMPILER CurrentEnvCompiler()

View File

@ -4,15 +4,13 @@ add_definitions(-std=c++11)
message("current dir" ${CMAKE_CURRENT_SOURCE_DIR})
# set(CMAKE_CXX_FLAGS "-fno-elide-constructors")
aux_source_directory(. SOURCE)
message(info ${SOURCE})
link_directories("./third/jsoncpp/lib/")
link_directories("../../../obj/")
link_libraries(jsoncpp)
link_libraries(generallib)
add_executable(cpp11 ${SOURCE} )
add_executable(cpp11 cpp11_test.cpp )
include_directories("./third/jsoncpp/include/pkgsrc/include/json")
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
#pragma message("编译器支持c++11")
#endif
@ -13,9 +21,89 @@ extern "C"{
#include<stdio.h>
#include <time.h>
}
#include <windows.h>
#include <Tlhelp32.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;
// try{
// std::cout<<"cpu count is "<<CoreCount()<<std::endl;
@ -23,28 +111,36 @@ int main(){
// }catch( std::exception e){
// std::cout<<"exception"<<e.what();
// }
std::list<int> i;
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;
test_fork();
while (true)
{
RangeProcess();
Sleep(1000);
}
Loger::Loger loger("d://");
loger.Debug("测试测试",DEBUG_FILE_POSITION);
std::cout<<"line " << __FILE__<<__LINE__<<" "<<__FUNCTION__<<std::endl;
// std::list<int>
// i;
// 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();
}

View File

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