[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] 文件图标提取工具:extractIcon.exe

  1. @echo Off
  2. :: extractIcon.exe <[文件] [图标序号] [输出文件名]>
  3. :: 返回值:
  4. ::          %errorlevel% =  0 : 成功提取
  5. ::          %errorlevel% = -1 : 参数错误
  6. ::          %errorlevel% = -2 : 找不到文件
  7. ::          %errorlevel% = -3 : 其他错误,序号不存在于文件中,或不能载入图标。
  8. extractIcon.exe shell32.dll -131 test.ico
  9. set "GetQQPath=reg query HKLM\Software\Tencent\QQ /v Install"
  10. For /f "skip=4 tokens=2*" %%a in ('%GetQQPath%') do (
  11.        extractIcon.exe "%%bQQ.exe" -1 "%cd%\QQ.Ico"
  12. )
复制代码
extractIcon.exe source:
  1. #NoTrayIcon
  2. #AutoIt3Wrapper_Change2CUI=y
  3. Global $aEN[1]
  4. Local $help = @scriptName & " <File> <Index> <Output file>" & @crLf
  5. If $CmdLine[0] <> 3 then
  6.         consoleWrite($help)
  7.         exit(-1)
  8. EndIf
  9. $File = $CmdLine[1]
  10. If not fileExists($File) then
  11.         $file = @systemDir & "\" & $cmdLine[1]
  12.         If not fileExists($File) then
  13.                 consoleWriteErr($cmdLine[1] & " not found." & @crLf)
  14.                 exit(-2)
  15.         EndIf
  16. EndIf
  17. $Index = number($cmdLine[2])
  18. _ExtractIconToFile($File, $Index, $CmdLine[3])
  19. If @error = 0 then exit(0)
  20. exit(-3)
  21. Func _ExtractIconToFile($sInFile, $iIcon, $sOutIco, $iPath = 0)
  22.         Local Const $LOAD_LIBRARY_AS_DATAFILE = 0x00000002
  23.         Local Const $RT_ICON = 3
  24.         Local Const $RT_GROUP_ICON = 14
  25.         Local $hInst, $iGN = "", $sData, $sHdr, $aHdr, $iCnt, $Offset, $FO, $FW, $iCrt = 18
  26.         If $iPath = 1 Then $iCrt = 26
  27.         If Not FileExists($sInFile) Then Return SetError(1, 0, 0)
  28.         If Not IsInt($iIcon) Then Return SetError(2, 0, 0)
  29.         $hInst = _LoadLibraryEx($sInFile, $LOAD_LIBRARY_AS_DATAFILE)
  30.         If Not $hInst Then Return SetError(3, 0, 0)
  31.         _ResourceEnumNames($hInst, $RT_GROUP_ICON)
  32.         For $i = 1 To $aEN[0]
  33.                 If $i = StringReplace($iIcon, "-", "") Then
  34.                         $iGN = $aEN[$i]
  35.                         ExitLoop
  36.                 EndIf
  37.         Next
  38.         Dim $aEN[1]
  39.         If $iGN = "" Then
  40.                 _FreeLibrary($hInst)
  41.                 Return SetError(4, 0, 0)
  42.         EndIf
  43.         $sData = _GetIconResource($hInst, $iGN, $RT_GROUP_ICON)
  44.     If @error Then
  45.             _FreeLibrary($hInst)
  46.                 Return SetError(5, 0, 0)
  47.         EndIf
  48.         $sHdr = BinaryMid($sData, 1, 6)
  49.         $aHdr = StringRegExp(StringTrimLeft(BinaryMid($sData, 7), 2), "(.{28})", 3)
  50.         $iCnt = UBound($aHdr)
  51.         $Offset = ($iCnt * 16) + 6
  52.         For $i = 0 To $iCnt -1
  53.                 Local $sDByte = Dec(_RB(StringMid($aHdr[$i], 17, 8)))
  54.                 $sHdr &= StringTrimRight($aHdr[$i], 4) & _RB(Hex($Offset))
  55.                 $Offset += $sDByte               
  56.         Next
  57.         For $i = 0 To $iCnt -1
  58.                 $sData = _GetIconResource($hInst, "#" & Dec(_RB(StringRight($aHdr[$i], 4))), $RT_ICON)
  59.                 If @error Then
  60.                     _FreeLibrary($hInst)
  61.                         Return SetError(6, 0, 0)
  62.                 EndIf
  63.                 $sHdr &= StringTrimLeft($sData, 2)
  64.         Next        
  65.         _FreeLibrary($hInst)
  66.         $FO = FileOpen($sOutIco, $iCrt)
  67.         If $FO = -1 Then Return SetError(7, 0, 0)
  68.         $FW = FileWrite($FO, $sHdr)
  69.         If $FW = 0 Then
  70.             FileClose($FO)
  71.                 Return SetError(8, 0, 0)
  72.         EndIf
  73.         FileClose($FO)
  74.         Return SetError(0, 0, 1)
  75. EndFunc   ;==>_ExtractIconToFile
  76. ; ========================================================================================================
  77. ; Internal Helper Functions from this point on
  78. ; ========================================================================================================
  79. Func _GetIconResource($hModule, $sResName, $iResType)
  80.         Local $hFind, $aSize, $hLoad, $hLock, $tRes, $sRet
  81.         $hFind = DllCall("kernel32.dll", "int", "FindResourceA", "int", $hModule, "str", $sResName, "long", $iResType)
  82.         If @error Or Not $hFind[0] Then Return SetError(1, 0, 0)
  83.         $aSize = DllCall("kernel32.dll", "dword", "SizeofResource", "int", $hModule, "int", $hFind[0])
  84.         If @error Or Not $aSize[0] Then Return SetError(2, 0, 0)
  85.         $hLoad = DllCall("kernel32.dll", "int", "LoadResource", "int", $hModule, "int", $hFind[0])
  86.         If @error Or Not $hLoad[0] Then Return SetError(3, 0, 0)
  87.         $hLock = DllCall("kernel32.dll", "int", "LockResource", "int", $hLoad[0])
  88.         If @error Or Not $hLock[0] Then
  89.                 _FreeResource($hLoad[0])
  90.                 Return SetError(4, 0, 0)
  91.         EndIf
  92.         $tRes = DllStructCreate("byte[" & $aSize[0] & "]", $hLock[0])
  93.         If Not IsDllStruct($tRes) Then
  94.                 _FreeResource($hLoad[0])
  95.                 Return SetError(5, 0, 0)
  96.         EndIf
  97.         $sRet = DllStructGetData($tRes, 1)
  98.         If $sRet = "" Then
  99.                 _FreeResource($hLoad[0])
  100.                 Return SetError(6, 0, 0)
  101.         EndIf
  102.         _FreeResource($hLoad[0])
  103.         Return $sRet
  104. EndFunc        
  105. ; Just a Reverse string byte function (smashly style..lol)
  106. Func _RB($sByte)
  107.         Local $aX = StringRegExp($sByte, "(.{2})", 3), $sX = ''
  108.         For $i = UBound($aX) - 1 To 0 Step -1
  109.                 $sX &= $aX[$i]
  110.         Next
  111.         Return $sX
  112. EndFunc   ;==>_RB
  113. Func _LoadLibraryEx($sFile, $iFlag)
  114.         Local $aRet = DllCall("Kernel32.dll", "hwnd", "LoadLibraryExA", "str", $sFile, "hwnd", 0, "int", $iFlag)
  115.         Return $aRet[0]
  116. EndFunc   ;==>_LoadLibraryEx
  117. Func _FreeLibrary($hModule)
  118.         DllCall("Kernel32.dll", "hwnd", "FreeLibrary", "hwnd", $hModule)
  119. EndFunc   ;==>_FreeLibrary        
  120. Func _FreeResource($hglbResource)
  121.         DllCall("kernel32.dll", "int", "FreeResource", "int", $hglbResource)
  122. EndFunc   ;==>_FreeResource
  123. Func _ResourceEnumNames($hModule, $iType)
  124.         Local $aRet, $xCB
  125.         If Not $hModule Then Return SetError(1, 0, 0)
  126.         $xCB = DllCallbackRegister('___EnumResNameProc', 'int', 'int_ptr;int_ptr;int_ptr;int_ptr')
  127.         $aRet = DllCall('kernel32.dll', 'int', 'EnumResourceNamesW', 'ptr', $hModule, 'int', $iType, 'ptr', DllCallbackGetPtr($xCB), 'ptr', 0)
  128.         DllCallbackFree($xCB)
  129.         If $aRet[0] <> 1 Then Return SetError(2, 0, 0)
  130.         Return SetError(0, 0, 1)
  131. EndFunc   ;==>_ResourceEnumNames
  132. Func ___EnumResNameProc($hModule, $pType, $pName, $lParam)
  133.         Local $aSize = DllCall('kernel32.dll', 'int', 'GlobalSize', 'ptr', $pName), $tBuf
  134.         If $aSize[0] Then
  135.                 $tBuf = DllStructCreate('wchar[' & $aSize[0] & ']', $pName)
  136.                 ReDim $aEN[UBound($aEN) + 1]
  137.                 $aEN[0] += 1
  138.                 $aEN[UBound($aEN) - 1] = DllStructGetData($tBuf, 1)
  139.         Else
  140.                 ReDim $aEN[UBound($aEN) + 1]
  141.                 $aEN[0] += 1
  142.                 $aEN[UBound($aEN) - 1] = "#" & $pName
  143.         EndIf
  144.         Return 1
  145. EndFunc   ;==>___EnumResNameProc
复制代码
[attach]745[/attach]

http://bcn.bathome.net/s/tool/index.html?key=extractIcon
1

评分人数

心绪平和,眼藏静谧。

返回列表