2.0版本(去除对第三方代码的依赖,添加定时功能,主程序上线)

This commit is contained in:
DLmaster
2024-02-06 21:12:49 +08:00
parent 30bbf3823f
commit 9e93b6ef35
12 changed files with 131 additions and 173 deletions

BIN
AUTO_MAA.exe Normal file

Binary file not shown.

29
AUTO_MAA.py Normal file
View File

@@ -0,0 +1,29 @@
import sqlite3
import subprocess
import datetime
import time
import os
from termcolor import colored
DATABASE="data/data.db"
db=sqlite3.connect(DATABASE)
cur=db.cursor()
cur.execute("SELECT * FROM timeset WHERE True")
timeset=cur.fetchall()
timeset=[list(row) for row in timeset]
while True:
curtime=datetime.datetime.now().strftime("%H:%M")
print(colored("当前时间:"+curtime,'green'))
timenew=[]
timenew.append(curtime)
if timenew in timeset:
print(colored("开始执行",'yellow'))
maa=subprocess.Popen(["run.exe"])
maapid=maa.pid
while True:
if os.path.exists("OVER"):
os.system('taskkill /F /T /PID '+str(maapid))
os.remove("OVER")
print(colored("执行完毕",'yellow'))
break
time.sleep(1)

View File

@@ -1,133 +0,0 @@
#include"stdafx.h"
#include<iostream>
#include<Windows.h>
#include "boost/filesystem.hpp"
#include "boost/iostreams/stream.hpp"
#include "boost/format.hpp"
#include "boost/algorithm/algorithm.hpp"
#include "boost/algorithm/string.hpp"
using namespace std;
#define READ_ONE_NUM 1024
/*
ɱ<><C9B1>ָ<EFBFBD><D6B8>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
*/
BOOL KillSpecifiedProcess(const std::string& p_strPath)
{
/*
C:\Users\10139>wmic process where name="notepad.exe" get executablepath,processid
ExecutablePath ProcessId
C:\WINDOWS\system32\notepad.exe 6196
C:\WINDOWS\system32\notepad.exe 6056
C:\Users\10139>taskkill /F /PID 6196 /PID 6056
<20>ɹ<EFBFBD>: <20><><EFBFBD><EFBFBD>ֹ PID Ϊ 6196 <20>Ľ<EFBFBD><C4BD>̡<EFBFBD>
<20>ɹ<EFBFBD>: <20><><EFBFBD><EFBFBD>ֹ PID Ϊ 6056 <20>Ľ<EFBFBD><C4BD>̡<EFBFBD>
*/
if(!boost::filesystem::exists(p_strPath))
{
cout << p_strPath << " not exist" << endl;
return FALSE;
}
int index = p_strPath.rfind("\\");
std::string strName = p_strPath.substr(index + 1);
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
HANDLE hStdOutRead = NULL, hStdOutWrite = NULL;
if (!CreatePipe(&hStdOutRead, &hStdOutWrite, &sa, 0))
{
cout << "create pipe error," << GetLastError() << endl;
return FALSE;
}
STARTUPINFOA startInfo;
PROCESS_INFORMATION procInfo;
BOOL bSuccess = FALSE;
ZeroMemory(&procInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory(&startInfo, sizeof(STARTUPINFOA));
startInfo.cb = sizeof(STARTUPINFOA);
startInfo.hStdOutput = hStdOutWrite;
startInfo.dwFlags |= (STARTF_USESTDHANDLES |STARTF_USESHOWWINDOW) ;
startInfo.wShowWindow = SW_HIDE;
boost::format fmt("wmic process where name=\"%1%\" get executablepath,processid");
fmt % strName;
std::string strSQL = fmt.str();
bSuccess = CreateProcessA(NULL, (char*)strSQL.data(), NULL, NULL, TRUE, 0, NULL, NULL, &startInfo, &procInfo);
if (!bSuccess)
{
cout << "create process error," << GetLastError() << endl;
return FALSE;
}
WaitForSingleObject(procInfo.hProcess,INFINITE);
CloseHandle(hStdOutWrite);
DWORD byteRead = 0;
std::string strContent;
char buffer[READ_ONE_NUM] = {0};
while (true)
{
byteRead = 0;
memset(buffer, 0, READ_ONE_NUM);
BOOL bRead = ReadFile(hStdOutRead, buffer, (READ_ONE_NUM-1)* sizeof(buffer[0]) , &byteRead, NULL);
if (!bRead)
{
break;
}
strContent.append(buffer);
}
CloseHandle(hStdOutRead);
std::vector<std::string> splitVec;
boost::split(splitVec, strContent, boost::is_any_of("\r\n"), boost::token_compress_on);
if(splitVec.size() > 0)
{
if( !boost::icontains(splitVec[0], "ExecutablePath") )
{
// û<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
cout << strName << " is not runing" << endl;
return FALSE;
}
// <20><><EFBFBD><EFBFBD>for<6F><72><EFBFBD><EFBFBD><EBA3BA><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD>PID
// <20><>1<EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
for(int i = 1; i < splitVec.size() -1; i++)
{
std::vector<std::string> splitVec2;
boost::split(splitVec2, splitVec[i], boost::is_any_of(" "), boost::token_compress_on);
int size = splitVec2.size();
if(size >= 3)
{
std::string exePath;
// ȡ<><C8A1>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
for(int i = 0; i < size -1 -1; i++)
{
exePath.append(splitVec2[i]);
exePath.append(" ");
}
// <20>ж<EFBFBD>·<EFBFBD><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȫƥ<C8AB><C6A5>
if( !boost::icontains(exePath, p_strPath) )
{
continue;
}
// <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>пո񣬵<D5B8><F1A3ACB5><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32>Ϊpid
std::string pId = splitVec2[size -1 -1];
std::string cmd = "taskkill /F /PID ";
cmd.append(pId);
cout << p_strPath << "->" << cmd << endl;
WinExec(cmd.c_str(), SW_HIDE);
}
}
}
return TRUE;
}
int main(int argc, char* argv[])
{
for(int i = 1; i < argc ; i++)
{
KillSpecifiedProcess(argv[i]);
}
return 0;
}

BIN
manage.exe Normal file

Binary file not shown.

View File

@@ -42,13 +42,30 @@ def delete(id):
def search(id,book): def search(id,book):
db=sqlite3.connect(DATABASE) db=sqlite3.connect(DATABASE)
cur=db.cursor() cur=db.cursor()
#处理启动时间查询
if id=="time":
cur.execute("SELECT * FROM timeset WHERE True")
timex=cur.fetchall()
timex=[list(row) for row in timex]
cur.close()
db.close()
if len(timex)==0:
return "启动时间未设置"
else:
for i in range(len(timex)):
print(timex[i][0])
return ""
#处理MAA路径查询 #处理MAA路径查询
if id=="maa": if id=="maa":
cur.execute("SELECT * FROM setting WHERE True") cur.execute("SELECT * FROM pathset WHERE True")
pathx=cur.fetchall() pathx=cur.fetchall()
if len(pathx)>0: if len(pathx)>0:
cur.close()
db.close()
return pathx[0][0] return pathx[0][0]
else: else:
cur.close()
db.close()
return "MAA路径未设置" return "MAA路径未设置"
#处理用户查询与全部信息查询 #处理用户查询与全部信息查询
if id=="all": if id=="all":
@@ -56,13 +73,24 @@ def search(id,book):
else: else:
cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id)) cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id))
data=cur.fetchall() data=cur.fetchall()
#处理全部信息查询时的MAA路径与启动时间查询
if id=="all": if id=="all":
cur.execute("SELECT * FROM setting WHERE True") cur.execute("SELECT * FROM pathset WHERE True")
pathx=cur.fetchall() pathx=cur.fetchall()
if len(pathx)>0: if len(pathx)>0:
print("\nMAA路径"+pathx[0][0]) print("\nMAA路径"+pathx[0][0])
else: else:
print("\nMAA路径未设置") print("\nMAA路径未设置")
cur.execute("SELECT * FROM timeset WHERE True")
timex=cur.fetchall()
timex=[list(row) for row in timex]
if len(timex)==0:
print("\n启动时间未设置")
else:
print("启动时间:",end='')
for i in range(len(timex)):
print(timex[i][0],end=' ')
print('')
cur.close() cur.close()
db.close() db.close()
data=[list(row) for row in data] data=[list(row) for row in data]
@@ -89,7 +117,7 @@ def search(id,book):
print(unit(data[i][0],15),unit(data[i][1],12),unit(data[i][2],8),unit(data[i][3],4),unit(data[i][4],10),unit(data[i][5],10),unit(data[i][6],25)) print(unit(data[i][0],15),unit(data[i][1],12),unit(data[i][2],8),unit(data[i][3],4),unit(data[i][4],10),unit(data[i][5],10),unit(data[i][6],25))
return "" return ""
elif id=="all": elif id=="all":
return "当前没有用户记录" return "\n当前没有用户记录"
else: else:
return "未找到"+id return "未找到"+id
@@ -107,6 +135,8 @@ def renewal(readxx):
cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id)) cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id))
data=cur.fetchall() data=cur.fetchall()
if len(data)==0: if len(data)==0:
cur.close()
db.close()
return "未找到"+id return "未找到"+id
#应用更新 #应用更新
cur.execute("UPDATE adminx SET day=%d WHERE admin='%s'" %(data[0][2]+dayp,id)) cur.execute("UPDATE adminx SET day=%d WHERE admin='%s'" %(data[0][2]+dayp,id))
@@ -123,9 +153,10 @@ def turn(id,t):
cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id)) cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id))
data=cur.fetchall() data=cur.fetchall()
if len(data)==0: if len(data)==0:
cur.close()
db.close()
return "未找到"+id return "未找到"+id
#应用更新 #应用更新
if t=='y' or t=='n':
cur.execute("UPDATE adminx SET status='%s' WHERE admin='%s'" %(t,id)) cur.execute("UPDATE adminx SET status='%s' WHERE admin='%s'" %(t,id))
db.commit() db.commit()
cur.close() cur.close()
@@ -149,6 +180,8 @@ def gameid(readxx):
cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id)) cur.execute("SELECT * FROM adminx WHERE admin='%s'" %(id))
data=cur.fetchall() data=cur.fetchall()
if len(data)==0: if len(data)==0:
cur.close()
db.close()
return "未找到"+id return "未找到"+id
#导入与应用特殊关卡规则 #导入与应用特殊关卡规则
games={} games={}
@@ -174,17 +207,52 @@ def gameid(readxx):
def setpath(pathx): def setpath(pathx):
db=sqlite3.connect(DATABASE) db=sqlite3.connect(DATABASE)
cur=db.cursor() cur=db.cursor()
cur.execute("SELECT * FROM setting WHERE True") cur.execute("SELECT * FROM pathset WHERE True")
pathold=cur.fetchall() pathold=cur.fetchall()
if len(pathold)>0: if len(pathold)>0:
cur.execute("UPDATE setting SET path='%s' WHERE True" %(pathx)) cur.execute("UPDATE pathset SET path='%s' WHERE True" %(pathx))
else: else:
cur.execute("INSERT INTO setting(path) VALUES('%s')" %(pathx)) cur.execute("INSERT INTO pathset(path) VALUES('%s')" %(pathx))
db.commit() db.commit()
cur.close() cur.close()
db.close() db.close()
return "MAA路径已设置为"+pathx return "MAA路径已设置为"+pathx
#设置启动时间
def settime(book,timex):
db=sqlite3.connect(DATABASE)
cur=db.cursor()
#检查待操作对象存在情况
cur.execute("SELECT * FROM timeset WHERE True")
timeold=cur.fetchall()
timeold=[list(row) for row in timeold]
timenew=[]
timenew.append(timex)
#添加时间设置
if book=='+':
if timenew in timeold:
cur.close()
db.close()
return "已存在"+timex
else:
cur.execute("INSERT INTO timeset(time) VALUES('%s')" %(timex))
db.commit()
cur.close()
db.close()
return "已添加"+timex
#删除时间设置
elif book=='-':
if timenew in timeold:
cur.execute("DELETE FROM timeset WHERE time='%s'" %(timex))
db.commit()
cur.close()
db.close()
return "已删除"+timex
else:
cur.close()
db.close()
return "未找到"+timex
#统一制表单元 #统一制表单元
def unit(x,m): def unit(x,m):
#字母与连接符占1位中文占2位 #字母与连接符占1位中文占2位
@@ -201,9 +269,10 @@ if not os.path.exists(DATABASE):
db=sqlite3.connect(DATABASE) db=sqlite3.connect(DATABASE)
cur=db.cursor() cur=db.cursor()
db.execute("CREATE TABLE adminx(admin text,number text,day int,status text,last date,game text,password text)") db.execute("CREATE TABLE adminx(admin text,number text,day int,status text,last date,game text,password text)")
db.execute("CREATE TABLE setting(path text)") db.execute("CREATE TABLE pathset(path text)")
db.execute("CREATE TABLE timeset(time text)")
readx=input("首次启动请设置MAA路径") readx=input("首次启动请设置MAA路径")
cur.execute("INSERT INTO setting(path) VALUES('%s')" %(readx)) cur.execute("INSERT INTO pathset(path) VALUES('%s')" %(readx))
db.commit() db.commit()
cur.close() cur.close()
db.close() db.close()
@@ -223,6 +292,8 @@ while True:
exit() exit()
elif read[0]=='/': elif read[0]=='/':
print(setpath(read[1:])) print(setpath(read[1:]))
elif read[0]==':' and (read[1]=='+' or read[1]=='-'):
print(settime(read[1],read[2:]))
else: else:
if read[-1]=='?': if read[-1]=='?':
print(search(read[:-2],1)) print(search(read[:-2],1))

Binary file not shown.

BIN
res/AUTO_MAA.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

BIN
res/AUTO_MAA.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

BIN
run.exe Normal file

Binary file not shown.

35
run.py
View File

@@ -1,10 +1,12 @@
import os import os
import subprocess
import sqlite3 import sqlite3
import datetime import datetime
import time import time
import json import json
from termcolor import colored from termcolor import colored
#判断MAA程序运行状态
def ifoff(): def ifoff():
while True: while True:
time.sleep(10) time.sleep(10)
@@ -17,16 +19,9 @@ def ifoff():
elif ("请检查连接设置或尝试重启模拟器与 ADB 或重启电脑" in log) or ("已停止" in log): elif ("请检查连接设置或尝试重启模拟器与 ADB 或重启电脑" in log) or ("已停止" in log):
return False return False
def killpath(maapath): #执行MAA任务
kpath='.\\mytaskkill.exe ' def runmaa(tel,game,num=2):
for i in maapath: #配置MAA运行参数
if i=='/':
kpath=kpath+'\\'
else:
kpath=kpath+i
return kpath
def runmaa(tel,game):
with open(setpath,"r",encoding="utf-8") as f: with open(setpath,"r",encoding="utf-8") as f:
data = json.load(f) data = json.load(f)
data["Configurations"]["Default"]["Start.AccountName"]=tel[:3]+"****"+tel[7:] data["Configurations"]["Default"]["Start.AccountName"]=tel[:3]+"****"+tel[7:]
@@ -37,22 +32,18 @@ def runmaa(tel,game):
data["Configurations"]["Default"]["MainFunction.Stage1"]=game data["Configurations"]["Default"]["MainFunction.Stage1"]=game
with open(setpath,"w",encoding="utf-8") as f: with open(setpath,"w",encoding="utf-8") as f:
json.dump(data,f) json.dump(data,f)
os.system('start '+maapath) #开始运行
for i in range(num):
maa=subprocess.Popen([maapath])
maapid=maa.pid
time.sleep(60) time.sleep(60)
if ifoff(): if ifoff():
return True return True
else: else:
command=killpath(maapath) os.system('taskkill /F /T /PID '+str(maapid))
os.system(command)
os.system('start '+maapath)
time.sleep(60)
if ifoff():
return True
else:
command=killpath(maapath)
os.system(command)
return False return False
#更新已完成用户的数据
def updata(id): def updata(id):
db=sqlite3.connect(DATABASE) db=sqlite3.connect(DATABASE)
cur=db.cursor() cur=db.cursor()
@@ -71,7 +62,7 @@ def updata(id):
DATABASE="data/data.db" DATABASE="data/data.db"
db=sqlite3.connect(DATABASE) db=sqlite3.connect(DATABASE)
cur=db.cursor() cur=db.cursor()
cur.execute("SELECT * FROM setting WHERE True") cur.execute("SELECT * FROM pathset WHERE True")
path=cur.fetchall() path=cur.fetchall()
path=str(path[0][0]) path=str(path[0][0])
setpath=path+"/config/gui.json" setpath=path+"/config/gui.json"
@@ -110,3 +101,5 @@ with open("log.txt","w", encoding="utf-8") as f:
print("代理未完成的用户:",file=f) print("代理未完成的用户:",file=f)
for i in range(len(idfail)): for i in range(len(idfail)):
print(idfail[i],file=f) print(idfail[i],file=f)
with open("OVER","w", encoding="utf-8") as f:
print("OVER",file=f)

5
toexe.py Normal file
View File

@@ -0,0 +1,5 @@
import os
os.system("pyinstaller -F -i res/AUTO_MAA.ico manage.py")
os.system("pyinstaller -F -i res/AUTO_MAA.ico run.py")
os.system("pyinstaller -F -i res/AUTO_MAA.ico AUTO_MAA.py")

View File

@@ -1,7 +0,0 @@
声明:
KillSpecifiedProcess.cpp与mytaskkill.exe来自CSDN博主的文章遵循CC 4.0 BY-SA 版权协议附加以下信息:
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接https://blog.csdn.net/qq_29542611/article/details/122003681