与A版一样,下面这个是替换二进制文件字符串,修改未压缩的autoit程序中类窗口别名
#Region ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#AccAu3Wrapper_Icon=water_melon.ico
#AccAu3Wrapper_Outfile=Compresspackage.exe
#AccAu3Wrapper_UseX64=n
#AccAu3Wrapper_Res_Language=2052
#AccAu3Wrapper_Res_requestedExecutionLevel=None
#EndRegion ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#include <math.au3>
#include <file.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include '_Res.au3'
DllCall('User32.dll', 'BOOL', 'ChangeWindowMessageFilter', 'UINT', 0x0233, 'DWORD', 1)
DllCall('User32.dll', 'BOOL', 'ChangeWindowMessageFilter', 'UINT', 0x0049, 'DWORD', 1)
Global $aDroppedFiles
Global $sSearchStr = 'AutoIt v3 GUI'
Global $rReplaceStr = 'Tubaba GUI'
Global $hGUI = GUICreate('Autoit Exe类名修改', 200, 80, -1, -1, BitOR($WS_POPUPWINDOW, $WS_CAPTION), BitOR($GUI_WS_EX_PARENTDRAG, $WS_EX_ACCEPTFILES))
Global $iButton = GUICtrlCreateButton('打開', 40, 37, 120, 40)
Global $iPic = GUICtrlCreatePic('', 0, 0, 200, 80, BitOR($SS_NOTIFY, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS), $GUI_WS_EX_PARENTDRAG)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState(@SW_SHOW)
WinSetOnTop($hGUI, '', 1)
GUIRegisterMsg(0x0233, "WM_DROPFILES")
While 1
$msg = GUIGetMsg()
Select
Case $msg = -3
Exit
Case $msg = $iButton
$OpenFile = FileOpenDialog('目标文件', @ScriptDir & '\', '所有文件(*.*)', 1 + 2, '', $hGUI)
If @error Then ContinueLoop
_Check($OpenFile)
Case $msg = $GUI_EVENT_DROPPED
$OpenFile = $aDroppedFiles[1]
_Check($OpenFile)
EndSelect
WEnd
Func _Check($OpenFile)
Local $szDrive, $szDir, $szFName, $szExt
Local $TestPath = _PathSplit($OpenFile, $szDrive, $szDir, $szFName, $szExt)
Local $UpxPath = _UpxBin()
Local $sCmd = @ComSpec & ' /c ""' & $UpxPath & '"'
$sCmd &= ' -t ' & '"' & $OpenFile & '"'
Local $res = _Std($sCmd)
Switch $res[0]
Case 1
If StringInStr($res[1], 'NotPackedException: not packed by UPX') Then
_Patch($OpenFile)
EndIf
Case 0
If StringInStr($res[1], 'Tested 1 file') Then
Local $TipPos[2]
_WindowGetPos($hGUI, $TipPos)
ToolTip('正在备份程序->"' & $OpenFile & '"', $TipPos[0], $TipPos[1], Default, 0, 4)
FileCopy($OpenFile, $TestPath[1] & $TestPath[2] & $TestPath[3] & $TestPath[4] & '.packed', 1)
_WindowGetPos($hGUI, $TipPos)
ToolTip('正在备份程序->"' & $OpenFile & '"', $TipPos[0], $TipPos[1], Default, 0, 4)
$sCmd = @ComSpec & ' /c ""' & $UpxPath & '"'
$sCmd &= ' -d ' & '"' & $OpenFile & '"'
Local $res1 = _Std($sCmd)
Switch $res1[0]
Case 0
If StringInStr($res1[1], 'Unpacked 1 file') Then
_Patch($OpenFile)
EndIf
EndSwitch
EndIf
Case Else
MsgBox(0, 0, 1)
EndSwitch
;~ _Patch($OpenFile)
EndFunc ;==>_Check
Func _Patch($OpenFile)
WinSetTitle($hGUI, '', '正在處理..' & $OpenFile)
Local $hFile, $sText, $nBytes, $tBuffer, $Replaced, $TipPos[2]
Local $szDrive, $szDir, $szFName, $szExt
Local $TestPath = _PathSplit($OpenFile, $szDrive, $szDir, $szFName, $szExt)
$hFile = FileOpen($OpenFile, 16)
$sText = FileRead($hFile)
FileClose($hFile)
If Not StringInStr($sText, _Str2UnicodeStr($sSearchStr)) Then
_WindowGetPos($hGUI, $TipPos)
ToolTip('无法识别->"' & $OpenFile & '"', $TipPos[0], $TipPos[1], Default, 0, 4)
AdlibRegister('_CloseToolTip', 3000)
WinSetTitle($hGUI, '', 'Compresspackage')
Return SetError(1, 0, 0)
EndIf
_WindowGetPos($hGUI, $TipPos)
ToolTip('正在备份程序->"' & $OpenFile & '"', $TipPos[0], $TipPos[1], Default, 0, 4)
FileCopy($OpenFile, $TestPath[1] & $TestPath[2] & $TestPath[3] & $TestPath[4] & '.bak', 1)
_WindowGetPos($hGUI, $TipPos)
ToolTip('正在修补程序->"' & $OpenFile & '"', $TipPos[0], $TipPos[1], Default, 0, 4)
$tBuffer = DllStructCreate("byte[" & BinaryLen($sText) & "]")
$Search = _Str2UnicodeStr($sSearchStr)
$Replace = _Str2UnicodeStr($rReplaceStr)
If StringLen($Search) > StringLen($Replace) Then
Do
$Replace = $Replace & '0'
Until StringLen($Replace) = StringLen($Search)
ElseIf StringLen($Search) < StringLen($Replace) Then
$Replace = StringMid($Replace,1,StringLen($Search))
EndIf
$Replaced = StringReplace($sText, $Search, $Replace)
DllStructSetData($tBuffer, 1, $Replaced)
$hFile = _WinAPI_CreateFile($OpenFile, 2)
_WinAPI_WriteFile($hFile, DllStructGetPtr($tBuffer), BinaryLen($Replaced), $nBytes)
_WinAPI_CloseHandle($hFile)
WinSetTitle($hGUI, '', 'Compresspackage')
ToolTip('')
_MSGBOXEX($hGUI, 0, '', '完成')
EndFunc ;==>_Patch
Func _Str2UnicodeStr($Str)
Local $Return='',$n = 1
$Return = StringTrimLeft(StringToBinary($Str,2),2)
Return $Return
EndFunc
Func _CloseToolTip()
AdlibUnRegister('_CloseToolTip')
ToolTip('')
EndFunc ;==>_CloseToolTip
Func WM_DROPFILES($hWnd, $msgID, $wParam, $lParam)
Local $nSize, $pFileName
Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
$aDroppedFiles = 0
Dim $aDroppedFiles[$nAmt[0] + 1]
For $i = 0 To $nAmt[0] - 1
$nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
$nSize = $nSize[0] + 1
$pFileName = DllStructCreate("char[" & $nSize & "]")
DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
DllStructGetPtr($pFileName), "int", $nSize)
$aDroppedFiles[0] += 1
$aDroppedFiles[$aDroppedFiles[0]] = DllStructGetData($pFileName, 1)
$pFileName = 0
Next
ReDim $aDroppedFiles[$aDroppedFiles[0] + 1]
EndFunc ;==>WM_DROPFILES
Func _MSGBOXEX($hWnd, $flag, $title, $text, $timeout = 0) ;hook msgbox
Local $hInst = _WinAPI_GetWindowLong($hWnd, $GWL_HINSTANCE)
Local $iThreadId = _WinAPI_GetCurrentThreadId()
Local $hCallBack = DllCallbackRegister("_CallBack", "int", "int;hWnd;hWnd")
Local $pCallBack = DllCallbackGetPtr($hCallBack)
Local $hHook = _WinAPI_SetWindowsHookEx($WH_CBT, $pCallBack, $hInst, $iThreadId)
Local $Mkmsg = MsgBox($flag, $title, $text, $timeout, $hWnd)
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hCallBack)
Return $Mkmsg
EndFunc ;==>_MSGBOXEX
Func _CallBack($iCode, $wParam, $lParam)
;If ($iCode = 5) And ($wParam <> $hGUI) Then
If ($iCode = $WH_CBT) And (_WinAPI_GetParent($wParam) > 0) Then
Local $WINDOWRECT = DllStructCreate($tagRECT)
Local $MSGBOXRECT = DllStructCreate($tagRECT)
Local $WINDOWRECT = _WinAPI_GetWindowRect(_WinAPI_GetParent($wParam))
Local $MSGBOXRECT = _WinAPI_GetWindowRect($wParam)
Local $WLeft = DllStructGetData($WINDOWRECT, 'Left')
Local $WTop = DllStructGetData($WINDOWRECT, 'Top')
Local $WRight = DllStructGetData($WINDOWRECT, 'Right')
Local $WBottom = DllStructGetData($WINDOWRECT, 'Bottom')
Local $MLeft = DllStructGetData($MSGBOXRECT, 'Left')
Local $MTop = DllStructGetData($MSGBOXRECT, 'Top')
Local $MRight = DllStructGetData($MSGBOXRECT, 'Right')
Local $MBottom = DllStructGetData($MSGBOXRECT, 'Bottom')
Local $X = $WLeft + (($WRight - $WLeft) - ($MRight - $MLeft)) / 2
Local $Y = $WTop + (($WBottom - $WTop) - ($MBottom - $MTop)) / 2
WinMove($wParam, "", $X, $Y, Default, Default)
EndIf
Return 0
EndFunc ;==>_CallBack
Func _WindowGetPos($hWnd, ByRef $aArray)
Local $tRect = _WinAPI_GetWindowRect($hWnd)
Local $cLeft = DllStructGetData($tRect, 'Left')
Local $cTop = DllStructGetData($tRect, 'Top')
Local $cRight = DllStructGetData($tRect, 'Right')
Local $cBottom = DllStructGetData($tRect, 'Bottom')
$aArray[0] = $cLeft
$aArray[1] = $cBottom
EndFunc ;==>_WindowGetPos
Func _Std($cmdline)
Local $res[2], $line, $sout, $serr
Local $pid = Run($cmdline, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($pid)
While 1
$line = StdoutRead($pid,False,True)
If @error Then ExitLoop
$sout &= $line
WEnd
While 1
$line = StderrRead($pid,False,True)
If @error Then ExitLoop
$serr &= $line
WEnd
StdioClose($pid)
If Not $serr = '' And Not $pid = 0 Then
$res[0] = 1
$Res[1] = BinaryToString($serr)
Else
$res[0] = 0
$Res[1] = BinaryToString($sout)
EndIf
Return $res
EndFunc ;==>_Std
|