MPEG2Repair.exeをバッジ処理するためのプロキシソフト 適当に不正終了対策ver
MPEG2Repair.exeをバッジ処理するためのプロキシソフト 適当に不正終了対策ver
#include "kernel32.as"#include "user32.as"#uselib "shlwapi"#cfunc global PathFileExists "PathFileExistsA" str#packopt name "MPEG2RepairProxy"// コンソールにしない場合はCONSOLEMODEをコメントアウトしてください#define CONSOLEMODE#ifdef CONSOLEMODE#runtime "hsp3cl"#define ERRORMSG mes#define LOGMSG mes#else#packopt hide 1#define ERRORMSG dialog#define LOGMSG logmes#endif#module#deffunc GetWindowList var list, int _maxif _max == 0 : max = 4096 : else : max = _maxVirtualAlloc 0, 12*4, 0x2000/*MEM_RESERVE*/, 0x40/*PAGE_EXECUTE_READWRITE*/VirtualAlloc stat, 12*4, 0x1000/*MEM_COMMIT*/, 0x40/*PAGE_EXECUTE_READWRITE*/pbm = statdupptr bm, pbm, 12*4, 4bm.0 = $0824448b, $8b08488b, $ca3b0450, $c033057c, $8b0008c2, $748b5610bm.6 = $34890824, $08488b8a, $48895e41, $0001b808, $08c20000, $00000000dim list, maxENUMWND_DATA = varptr(list), max, 0EnumWindows pbm, varptr(ENUMWND_DATA)dim bmVirtualFree pbm, 12*4, 0x4000 /*MEM_DECOMMIT*/VirtualFree pbm, 0, 0x8000 /*MEM_RELEASE*/return#global#module#defcfunc exec2 str _cmd, var pid, int showmodepid = -1cmd = _cmd; STARTUPINFO構造体を設定dim stinfo, 17stinfo.0 = 68 ; 構造体サイズ(cbメンバ)stinfo.11 = 1//STARTF_USESHOWWINDOWstinfo.12 = showmode & 0xFFFF; PROCESS_INFOMATION構造体を設定dim prinfo, 4; 新しいプロセスを起動CreateProcess 0,varptr(cmd),0,0,0,0,0,0,varptr(stinfo),varptr(prinfo)if (stat == 0) : return 0hProcess = prinfo.0 ; プロセスのハンドルhThread = prinfo.1 ; プライマリスレッドのハンドルpid = prinfo.2; プライマリスレッドのハンドルは直ちにクローズCloseHandle hThreadhThread = 0return hProcess#global*main// コマンドライン保存cl = dir_cmdline + " "// test;cl = "-input \"D:\\DummyTs\\ -output -hide -errorlog ☆ Duumy01あれれれれ.ts\" -output -errorlog -hide -minimize -nooverwrite";cl = "-input \"D:\\DummyTs\\Duumy01.ts\" -output -errorlog"m_hide = 0m_minimize = 0m_overwrite = 1m_seqnum = 0sdim m_input : m_input_f = 0sdim m_output : m_output_f = 0sdim m_errorlog : m_errorlog_f = 0mode = 0p = 0repeat strlen(cl)sdim m// 現在位置の1文字取得tmp = strmid(cl, p, 1)if tmp == "-"{mode = 1}else : if tmp == "\""{mode = 2}else{mode = 0}if mode == 0{}if mode == 1{i = prepeat strlen(cl)-ptmp2 = strmid(cl, i, 1)// コレの場合は文字列取得し抜けるif tmp2 == " " | tmp2 == "\"" : m = strmid(cl, p, i-p) : p = i : break// 最終桁到達の場合とりあえずとってみるif cnt == (strlen(cl) - p) - 1 : m = strmid(cl, p, i-p+1) : p = i : breaki++loop// -input,-output,-errorlogは続きを取らないといけない(強制はinputのみ)のでモード変更し続行するif m == "-input"{m_input_f = 1mode = 2}else : if m == "-output"{m_output_f = 1mode = 2}else : if m == "-errorlog"{m_errorlog_f = 1mode = 2}else : if m == ""{// 該当しない場合}else : if m == "-hide"{m_hide = 1}else : if m == "-minimize"{m_minimize = 1}else : if m == "-nooverwrite"{m_overwrite = 0}else : if m == "-seqnum"{m_seqnum = 1}}if mode == 2{i = psp = -1 : ep = -1repeat strlen(cl)-ptmp2 = strmid(cl, i, 1)// コレの場合は文字列取得し抜けるif tmp2 == "\"" {mode_dq = 1if sp == -1 : sp = i : i++ : continueif ep == -1 : ep = i : i++ : break}i++loop// 取得できた場合if sp != -1 && ep != -1 {p = i // 読み進めるtmp2 = strmid(cl, sp + 1, ep - sp - 1)if m == "-input"{m_input = tmp2}else : if m == "-output"{m_output = tmp2}else : if m == "-errorlog"{m_errorlog = tmp2}}}p++loop// チェックif m_input == "" {ERRORMSG "ERROR:引数が不正です。-input がありません。" : end}if m_output_f == 0{ERRORMSG "ERROR:引数が不正です。-output がありません。" : end}// 2GB以上のファイルに対応するため、existは使わないif PathFileExists(m_input) == 0{ERRORMSG "ERROR:入力ファイルが存在しません。\n"+m_input : end}// MPEG2Repair.exeを探すif PathFileExists("./MPEG2Repair/MPEG2Repair.exe") == 0{ERRORMSG "ERROR:MPEG2Repair.exeが存在しません。 ./MPEG2Repair/MPEG2Repair.exe" : end}// 起動するhProcess = exec2("./MPEG2Repair/MPEG2Repair.exe", pID, 0)if hProcess == 0{ERRORMSG "ERROR:MPEG2Repair.exe の起動に失敗しました。" : end}// 起動を待つWaitForInputIdle hProcess, 0xFFFFFFFF/*INFINITE*/// 60回ほど検索を繰り返す(約1分)repeat 60wait 100// ウィンドウを列挙するGetWindowList list, 8096 : hMain = 0 : c_pID = 0repeat length(list)sdim name, 256 : sdim class, 256GetClassNameA list(cnt), varptr(class), 256GetWindowTextA list(cnt), varptr(name), 256GetWindowThreadProcessId list(cnt), varptr(c_pID)if c_pID == pID && class == "#32770" && name == "MPEG2Repair"{hMain = list(cnt)break}loopif hMain != 0 : breakLOGMSG "WAIT:ウィンドウの検索中... 試行回数("+(cnt+1)+"/60)"loopif hMain == 0 {ERRORMSG "ERROR:ウィンドウの検索に失敗しました。"TerminateProcess hProcess, 0end}// 最小化が有効の場合if m_minimize == 1{ShowWindow hMain, 6}else : if m_hide == 1{// 隠すモード(動作しない様子)ShowWindow hMain, 0}else{// ノーマルモードShowWindow hMain, 4}sleep 500// 1番目のエディトボックスを取得FindWindowEx hMain, 0, "Edit", 0hEdit = stathStatic = statif hEdit == 0 {ERRORMSG "ERROR:MPEG2Repairの操作に失敗しました。(Editが見つかりません)"TerminateProcess hProcess, 0end}// 反映させる;SetWindowTextA hEdit, varptr(m_input) // 別プロセスだと使えないので↓SendMessageA hEdit, 0x000C, 0, varptr(m_input)// スタティックを取得FindWindowEx hMain, 0, "Static", "0 % Complete"hStatic = statif hStatic == 0 {ERRORMSG "ERROR:MPEG2Repairの操作に失敗しました。(Staticが見つかりません)"TerminateProcess hProcess, 0end}// Find PID's を取得(ボタン)hButton = 0repeat 60wait 100FindWindowEx hMain, 0, "Button", "Find PID's"hButton = statif hButton != 0 : breakLOGMSG "WAIT:ボタンの検索中... 試行回数("+(cnt+1)+"/60)"loopif hButton == 0 {ERRORMSG "ERROR:MPEG2Repairの操作に失敗しました。(Buttonが見つかりません)"TerminateProcess hProcess, 0end}// ボタンを押すSendMessageA hButton, 0x00F5, 0, 0// パーセントを調査するrepeat 60wait 100sdim string, 256GetWindowTextA hStatic, varptr(string), 256if instr(string, 0, "100 % Completed.") != -1 : breakLOGMSG "WAIT:PID解析待機中... 試行回数("+(cnt+1)+"/60)"loopif instr(string, 0, "100 % Completed.") == -1 {ERRORMSG "ERROR:MPEG2Repairの操作に失敗しました。PID解析に失敗しました。"TerminateProcess hProcess, 0end}// Repair Errosを取得FindWindowEx hMain, 0, "Button", "Repair Errors"hButton2 = statif hButton2 == 0 {ERRORMSG "ERROR:MPEG2Repairの操作に失敗しました。(Buttonが見つかりません)"TerminateProcess hProcess, 0end}// ボタンを押すSendMessageA hButton2, 0x00F5, 0, 0sleep 500if m_output != ""{//2番目のエディトボックスを取得FindWindowEx hMain, hEdit, "Edit", 0hEdit2 = statif hEdit2 == 0 {ERRORMSG "ERROR:MPEG2Repairの操作に失敗しました。(Editが見つかりません)"TerminateProcess hProcess, 0end}// 反映SendMessageA hEdit2, 0x000C, 0, varptr(m_output)}// エラーログ機能が有効な場合if m_errorlog_f == 1{// Log Errosを取得FindWindowEx hMain, 0, "Button", "Log Errors"hButton3 = statif hButton3 == 0 {ERRORMSG "ERROR:MPEG2Repairの操作に失敗しました。(Buttonが見つかりません)"TerminateProcess hProcess, 0end}// ボタンを押すSendMessageA hButton3, 0x00F5, 0, 0sleep 500if m_errorlog != ""{//3番目のエディトボックスを取得FindWindowEx hMain, 0, "Edit", 0FindWindowEx hMain, stat, "Edit", 0FindWindowEx hMain, stat, "Edit", 0hEdit3 = statif hEdit3 == 0 {ERRORMSG "ERROR:MPEG2Repairの操作に失敗しました。(Editが見つかりません)"TerminateProcess hProcess, 0end}// 反映SendMessageA hEdit3, 0x000C, 0, varptr(m_errorlog)}}// ボタンを押して処理を開始する(SendMessageだと止まってしまう場合あり)PostMessageA hButton, 0x00F5, 0, 0wait 50f = 0repeat// 状態表示sdim string, 256GetWindowTextA hStatic, varptr(string), 256LOGMSG stringgosub *WindowCheckif f == 1 : break// 不正終了チェックIsWindow hMainif stat == 0 {ERRORMSG "ERROR:操作を完了する前にMPEG2Repairが不正終了した可能性があります。"end}//wait 100loopTerminateProcess hProcess, 0LOGMSG "SUCCEED:処理が完了しました。"end*WindowCheck// ウィンドウの検索GetWindowList list, 8096repeat length(list)sdim class, 256 : sdim name, 256 : c_pid = 0GetClassNameA list.cnt, varptr(class), 256GetWindowTextA list.cnt, varptr(name), 256GetWindowThreadProcessId list.cnt, varptr(c_pid)// 上書き確認のダイアログ検出if class == "#32770" && name == "Warning:" && c_pid == pID{// 本当にOverWriteかチェックするhDialog = 0hDialog2 = list.cntrepeatFindWindowEx hDialog2, hDialog, "Static", 0hDialog = statif hDialog == 0 : breaksdim static_string, 1024GetWindowTextA hDialog, varptr(static_string), 1024// オーバーライト画面を確認できた場合if instr(static_string, 0, "Overwrite it?") != -1 {if m_overwrite == 1{FindWindowEx hDialog2, 0, "Button", 0SendMessageA stat, 0x00F5, 0, 0}else{FindWindowEx hDialog2, 0, "Button", 0FindWindowEx hDialog2, stat, "Button", 0SendMessageA stat, 0x00F5, 0, 0}break}loop}// 連結確認のダイアログ検出if class == "#32770" && name == "Question:" && c_pid == pID{// 本当に連結確認かチェックするhDialog = 0hDialog2 = list.cntrepeatFindWindowEx hDialog2, hDialog, "Static", 0hDialog = statif hDialog == 0 : breaksdim static_string, 1024GetWindowTextA hDialog, varptr(static_string), 1024// 連結確認画面を確認できた場合if instr(static_string, 0, "numbered sequence") != -1 {if m_seqnum == 1{FindWindowEx hDialog2, 0, "Button", 0SendMessageA stat, 0x00F5, 0, 0}else{FindWindowEx hDialog2, 0, "Button", 0FindWindowEx hDialog2, stat, "Button", 0SendMessageA stat, 0x00F5, 0, 0}break}loop}// 完了ダイアログの検出if class == "#32770" && name == "Status:" && c_pid == pID{// 完了ボタンを押すFindWindowEx list.cnt, 0, "Button", 0SendMessageA stat, 0x00F5, 0, 0f = 1break}loopreturn