Advertisement
THAT1ANONYMOUSDUDE

Icon Resource Editor

Jun 20th, 2012
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 64.25 KB | None | 0 0
  1. #include <ListviewConstants.au3>
  2. #include <WindowsConstants.au3>
  3. #include <GUIConstantsEx.au3>
  4. #include <winapi.au3>
  5. #include <Array.au3>
  6.  
  7. Global $ARRAY_MODULE_STRUCTURE[1][1][1]
  8. Global $global_types_count
  9. Global $iPopulateArray
  10. Global $global_langs_count
  11. Global $lang_count
  12. Global $global_names_count
  13. Global $name_count
  14.  
  15. Global Const $RT_CURSOR = 1
  16. Global Const $RT_BITMAP = 2
  17. Global Const $RT_ICON = 3
  18. Global Const $RT_MENU = 4
  19. Global Const $RT_DIALOG = 5
  20. Global Const $RT_STRING = 6
  21. Global Const $RT_FONTDIR = 7
  22. Global Const $RT_FONT = 8
  23. Global Const $RT_ACCELERATOR = 9
  24. Global Const $RT_RCDATA = 10
  25. Global Const $RT_MESSAGETABLE = 11
  26. Global Const $RT_GROUP_CURSOR = 12
  27. Global Const $RT_GROUP_ICON = 14
  28. Global Const $RT_VERSION = 16
  29. Global Const $RT_DLGINCLUDE = 17
  30. Global Const $RT_PLUGPLAY = 19
  31. Global Const $RT_VXD = 20
  32. Global Const $RT_ANICURSOR = 21
  33. Global Const $RT_ANIICON = 22
  34. Global Const $RT_HTML = 23
  35. Global Const $RT_MANIFEST = 24
  36.  
  37. Global $LangCodeCurrent
  38. Global $langNameCurrent[2]
  39. Global $TypeCurrent
  40. Global $TypeNameCurrent[2]
  41.  
  42. Global $Script
  43. Global $aListViewItem[1]
  44.  
  45. Global $GUIMINWID = 472; Resizing / minimum width
  46. Global $GUIMINHT = 222; Resizing / minimum hight
  47. Global Const $WS_RESIZABLE = 0x00070000
  48.  
  49. #region ### START Koda GUI section ### Form=
  50. AutoItSetOption("GUIOnEventMode", 1)
  51. AutoItSetOption("GUIResizeMode", 1)
  52.  
  53. $Form1 = GUICreate("Icon Resource Editor - powered by Trancexx", $GUIMINWID, $GUIMINHT, -1, -1, BitOR($WS_RESIZABLE, $WS_CAPTION, $WS_POPUP), $WS_EX_ACCEPTFILES)
  54. GUISetOnEvent(-3, "Terminate")
  55.  
  56. $Input1 = GUICtrlCreateInput("", 8, 8, 422, 21)
  57. GUICtrlSetResizing(-1, 512 + 32 + 4 + 2)
  58.  
  59. $Button1 = GUICtrlCreateButton("...", 438, 8, 27, 21)
  60. GUICtrlSetResizing(-1, 768 + 32)
  61. GUICtrlSetOnEvent(-1, "SelectFile")
  62.  
  63. Global $ListView1 = GUICtrlCreateListView("", 8, 32, 457, 153)
  64. GUICtrlSetResizing(-1, 102)
  65. $Button2 = GUICtrlCreateButton("Replace", 296, 192, 75, 25)
  66. GUICtrlSetResizing(-1, 768 + 64 + 4)
  67. GUICtrlSetOnEvent(-1, "Replace")
  68.  
  69. $Button3 = GUICtrlCreateButton("Delete", 392, 192, 75, 25)
  70. GUICtrlSetResizing(-1, 768 + 64 + 4)
  71. GUICtrlSetOnEvent(-1, "Delete")
  72.  
  73. $Button4 = GUICtrlCreateButton("Add", 216, 192, 75, 25)
  74. GUICtrlSetResizing(-1, 768 + 64 + 4)
  75. GUICtrlSetOnEvent(-1, "Add")
  76.  
  77. GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
  78. GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")
  79.  
  80. GUISetState(@SW_SHOW)
  81. #endregion ### END Koda GUI section ###
  82.  
  83. Sleep(999999999)
  84.  
  85. Func Delete()
  86.     $Str = GUICtrlRead(GUICtrlRead($ListView1))
  87.     $Str = StringRegExp($Str, "\|(.*?)\|", 3)
  88.     If @error Then
  89.         MsgBox(16, "Error!", "Select an item...")
  90.         Return
  91.     EndIf
  92.     $Str = $Str[0]
  93.     If $Str <> "" Then
  94.         $File = GUICtrlRead($Input1)
  95.         If @error Then Return
  96.         READEOF($File)
  97.         _ResRep($File, $Str, 0, 1)
  98.     EndIf
  99. EndFunc   ;==>Delete
  100.  
  101. Func Add()
  102.     AutoItSetOption("GUIOnEventMode", 0)
  103.     $Form2 = GUICreate("Form1", 82, 116, 321, 257, -1, -1, $Form1)
  104.     $Type = GUICtrlCreateInput("Type", 8, 8, 65, 21)
  105.     $Name = GUICtrlCreateInput("Name", 8, 32, 65, 21)
  106.     $Lang = GUICtrlCreateInput("Lang", 8, 56, 65, 21)
  107.     $AddTheResFile = GUICtrlCreateButton("Add", 8, 80, 65, 21)
  108.     GUISetState(@SW_SHOW, $Form2)
  109.     While 1
  110.         $nMsg = GUIGetMsg($Form2)
  111.         Switch $nMsg
  112.             Case -3
  113.                 ExitLoop
  114.             Case $AddTheResFile
  115.                 Local $RT = GUICtrlRead($Type)
  116.                 Local $OR = GUICtrlRead($Name)
  117.                 Local $LN = GUICtrlRead($Lang)
  118.                 If Not $RT Or Not $OR Then
  119.                     MsgBox(0, "Error!", "Empty value.")
  120.                     ContinueLoop
  121.                 EndIf
  122.                 If Not $LN Then $LN = 0
  123.                 If Not Number($LN) And Not Number($LN) = 0 Then
  124.                     MsgBox(0, "Error!", "Wrong language code type.")
  125.                     ContinueLoop
  126.                 EndIf
  127.                 $File = FileOpenDialog("Select a file to add", "", "(*)")
  128.                 If @error Then ExitLoop
  129.                 $File2 = GUICtrlRead($Input1)
  130.                 If Not FileExists($File2) Then
  131.                     MsgBox(0, "Error!", "No file selected.")
  132.                     ExitLoop
  133.                 EndIf
  134.                 READEOF($File2)
  135.                 _ResUpdate($File2, $RT, $OR, Number($LN), $File)
  136.                 ExitLoop
  137.         EndSwitch
  138.     WEnd
  139.     AutoItSetOption("GUIOnEventMode", 1)
  140.     GUIDelete($Form2)
  141. EndFunc   ;==>Add
  142.  
  143. Func SelectFile()
  144.     $var = FileOpenDialog("Select File", @DesktopDir & "\", "exe FILE (*.exe)", 1, "")
  145.     If @error Then Return
  146.     GUICtrlSetData($Input1, $var)
  147.     _ResEnum($var)
  148. EndFunc   ;==>SelectFile
  149.  
  150. Func Replace()
  151.     $var = FileOpenDialog("Select Icon File", @DesktopDir & "\", "ico FILE (*.ico)", 1, "")
  152.     If @error Then Return
  153.     $Str = GUICtrlRead(GUICtrlRead($ListView1))
  154.     $Str = StringRegExp($Str, "\|(.*?)\|", 3)
  155.     If @error Then
  156.         MsgBox(16, "Error!", "Select an item...")
  157.         Return
  158.     EndIf
  159.     $Str = $Str[0]
  160.     If $Str <> "" Then
  161.         If StringInStr($Str, "|") Then $Str = StringReplace($Str, "|", "")
  162.         $File = GUICtrlRead($Input1)
  163.         If @error Then Return
  164.         READEOF($File)
  165.         _ResRep($File, $Str, $var)
  166.     EndIf
  167. EndFunc   ;==>Replace
  168.  
  169.  
  170. Func _ResDelete($sModule, $iResType, $iResName, $iResLang, $lParam = 0)
  171.  
  172.     If Not FileExists($sModule) Then
  173.         Return SetError(100, 0, "") ; what happened???
  174.     EndIf
  175.  
  176.     Local $hFile = FileOpen($sModule, 1)
  177.     If $hFile = -1 Then
  178.         Return SetError(101, 0, "") ; cannot obtain writing rights
  179.     EndIf
  180.  
  181.     FileClose($hFile)
  182.  
  183.     Switch $iResType
  184.  
  185.         Case $RT_GROUP_ICON
  186.             Local $bBinGroupIcon = _ResourceGetAsRaw($iResType, $iResName, $iResLang, $sModule, 1)
  187.             Local $tGroupIcon = DllStructCreate("byte[" & BinaryLen($bBinGroupIcon) & "]")
  188.             DllStructSetData($tGroupIcon, 1, $bBinGroupIcon)
  189.  
  190.             Local $tEnumGroupIcon = DllStructCreate("ushort;" & _
  191.                     "ushort Type;" & _
  192.                     "ushort ResCount;" & _
  193.                     "byte Body[" & BinaryLen($bBinGroupIcon) - 6 & "]", _
  194.                     DllStructGetPtr($tGroupIcon))
  195.  
  196.         Case $RT_GROUP_CURSOR
  197.             Local $bBinGroupCursor = _ResourceGetAsRaw($iResType, $iResName, $iResLang, $sModule, 1)
  198.  
  199.         Case $RT_ICON
  200.             If Not $lParam Then ; currently not available, will return
  201.                 Return SetError(0, 0, 1) ;  <------'
  202.                 For $m = 0 To UBound($ARRAY_MODULE_STRUCTURE, 1) - 1
  203.                     If $ARRAY_MODULE_STRUCTURE[$m][0][0] = $RT_GROUP_ICON Then
  204.                         Local $bBinGroupIcon, $iResCount
  205.                         Local $tGroupIcon
  206.                         Local $tHeaderGroupIcon
  207.                         For $n = 1 To UBound($ARRAY_MODULE_STRUCTURE, 2) - 1
  208.                             $bBinGroupIcon = _ResourceGetAsRaw($RT_GROUP_ICON, $ARRAY_MODULE_STRUCTURE[$m][$n][0], $iResLang, $sModule, 1)
  209.                             $tGroupIcon = DllStructCreate("byte[" & BinaryLen($bBinGroupIcon) & "]")
  210.                             DllStructSetData($tGroupIcon, 1, $bBinGroupIcon)
  211.                             $tHeaderGroupIcon = DllStructCreate("ushort;" & _
  212.                                     "ushort Type;" & _
  213.                                     "ushort ResCount;" & _
  214.                                     "byte Body[" & BinaryLen($bBinGroupIcon) - 6 & "]", _
  215.                                     DllStructGetPtr($tGroupIcon))
  216.  
  217.                             $iResCount = DllStructGetData($tHeaderGroupIcon, "ResCount")
  218.  
  219.                             If $iResCount < 2 Then
  220.                                 _ResDelete($sModule, $RT_GROUP_ICON, $ARRAY_MODULE_STRUCTURE[$m][$n][0], $iResLang)
  221.                                 If @error Then
  222.                                     Return SetError(@error, 0, "")
  223.                                 EndIf
  224.                                 Return SetError(0, 0, 1)
  225.                             EndIf
  226.                         Next
  227.                     EndIf
  228.                 Next
  229.             EndIf
  230.  
  231.         Case $RT_CURSOR
  232.             If Not $lParam Then
  233.                 For $m = 0 To UBound($ARRAY_MODULE_STRUCTURE, 1) - 1
  234.                     If $ARRAY_MODULE_STRUCTURE[$m][0][0] = $RT_GROUP_CURSOR Then
  235.                         Local $bGroupCursor
  236.  
  237.                         For $n = 1 To UBound($ARRAY_MODULE_STRUCTURE, 2) - 1
  238.                             $bGroupCursor = _ResourceGetAsRaw($RT_GROUP_CURSOR, $ARRAY_MODULE_STRUCTURE[$m][$n][0], $iResLang, $sModule, 1)
  239.  
  240.                             If $iResName = _LittleEndianBinaryToInt(BinaryMid($bGroupCursor, 19, 2)) Then
  241.                                 _ResDelete($sModule, $RT_GROUP_CURSOR, $ARRAY_MODULE_STRUCTURE[$m][$n][0], $iResLang)
  242.                                 If @error Then
  243.                                     Return SetError(@error, 0, "")
  244.                                 EndIf
  245.                             EndIf
  246.  
  247.                         Next
  248.  
  249.                     EndIf
  250.                 Next
  251.                 Return SetError(0, 0, 1)
  252.             EndIf
  253.  
  254.     EndSwitch
  255.  
  256.     Local $a_hCall = DllCall("kernel32.dll", "hwnd", "BeginUpdateResourceW", "wstr", $sModule, "int", 0)
  257.  
  258.     If @error Or Not $a_hCall[0] Then
  259.         Return SetError(1, 0, "")
  260.     EndIf
  261.  
  262.     Local $a_iCall
  263.     Switch IsNumber($iResType) + 2 * IsNumber($iResName)
  264.         Case 0
  265.             Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  266.                     "hwnd", $a_hCall[0], _
  267.                     "wstr", $iResType, _
  268.                     "wstr", $iResName, _
  269.                     "int", $iResLang, _
  270.                     "ptr", 0, _
  271.                     "dword", 0)
  272.         Case 1
  273.             Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  274.                     "hwnd", $a_hCall[0], _
  275.                     "int", $iResType, _
  276.                     "wstr", $iResName, _
  277.                     "int", $iResLang, _
  278.                     "ptr", 0, _
  279.                     "dword", 0)
  280.         Case 2
  281.             Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  282.                     "hwnd", $a_hCall[0], _
  283.                     "wstr", $iResType, _
  284.                     "int", $iResName, _
  285.                     "int", $iResLang, _
  286.                     "ptr", 0, _
  287.                     "dword", 0)
  288.         Case 3
  289.             Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResource", _
  290.                     "hwnd", $a_hCall[0], _
  291.                     "int", $iResType, _
  292.                     "int", $iResName, _
  293.                     "int", $iResLang, _
  294.                     "ptr", 0, _
  295.                     "dword", 0)
  296.     EndSwitch
  297.  
  298.     If @error Or Not $a_iCall[0] Then
  299.         DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  300.         Return SetError(2, 0, "")
  301.     EndIf
  302.  
  303.     $a_iCall = DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  304.  
  305.     If @error Or Not $a_iCall[0] Then
  306.         Return SetError(3, 0, "")
  307.     EndIf
  308.  
  309.     Switch $iResType
  310.         Case $RT_GROUP_ICON
  311.             Local $iIconName
  312.             For $i = 1 To DllStructGetData($tEnumGroupIcon, "ResCount")
  313.                 $iIconName = _LittleEndianBinaryToInt(BinaryMid(DllStructGetData($tEnumGroupIcon, "Body"), (14 * $i) - 1, 2))
  314.                 If $iIconName Then
  315.                     _ResDelete($sModule, $RT_ICON, $iIconName, $iResLang, 1)
  316.                 EndIf
  317.             Next
  318.         Case $RT_GROUP_CURSOR
  319.             _ResDelete($sModule, $RT_CURSOR, _LittleEndianBinaryToInt(BinaryMid($bBinGroupCursor, 19, 2)), $iResLang, 1)
  320.             If @error Then
  321.                 Return SetError(@error, 0, "")
  322.             EndIf
  323.     EndSwitch
  324.  
  325.     Return SetError(0, 0, 1)
  326.  
  327. EndFunc   ;==>_ResDelete
  328.  
  329. Func _LittleEndianBinaryToInt($bBinary)
  330.  
  331.     Local $hex
  332.     $bBinary = Binary($bBinary)
  333.     Local $iBinaryLen = BinaryLen($bBinary)
  334.  
  335.     For $i = 1 To $iBinaryLen
  336.         $hex &= Hex(BinaryMid($bBinary, $iBinaryLen + 1 - $i, 1))
  337.     Next
  338.  
  339.     Return SetError(0, 0, Dec($hex))
  340.  
  341. EndFunc   ;==>_LittleEndianBinaryToInt
  342.  
  343. Func _ResUpdate($sModule, $iResType, $iResName, $iResLang, $sResFile, $lParam = 0)
  344.  
  345.     If Not FileExists($sModule) Then
  346.         Return SetError(100, 0, "") ; what happened???
  347.     EndIf
  348.  
  349.     Local $hFile = FileOpen($sModule, 1)
  350.     If $hFile = -1 Then
  351.         Return SetError(101, 0, "") ; cannot obtain writing rights
  352.     EndIf
  353.  
  354.     FileClose($hFile)
  355.  
  356.     Switch $iResType
  357.  
  358.         Case $RT_GROUP_CURSOR
  359.  
  360.             Local $tBinary = DllStructCreate("byte[" & FileGetSize($sResFile) & "]")
  361.             Local $hResFile = FileOpen($sResFile, 16)
  362.             DllStructSetData($tBinary, 1, FileRead($hResFile))
  363.             FileClose($hResFile)
  364.  
  365.             If @error Then
  366.                 Return SetError(5, 0, "")
  367.             EndIf
  368.  
  369.             Local $tResource = DllStructCreate("align 2;ushort;" & _
  370.                     "ushort Type;" & _
  371.                     "ushort ImageCount;" & _
  372.                     "ubyte Width;" & _
  373.                     "ubyte Height;" & _
  374.                     "ubyte ColorCount;" & _
  375.                     "byte;" & _
  376.                     "ushort Xhotspot;" & _
  377.                     "ushort Yhotspot;" & _
  378.                     "dword BitmapSize;" & _
  379.                     "dword BitmapOffset;" & _
  380.                     "byte Body[" & DllStructGetSize($tBinary) - 22 & "]", _
  381.                     DllStructGetPtr($tBinary))
  382.  
  383.             Local $tBitmap = DllStructCreate("dword HeaderSize", DllStructGetPtr($tResource, "Body"))
  384.  
  385.             Local $iHeaderSize = DllStructGetData($tBitmap, "HeaderSize")
  386.  
  387.             Switch $iHeaderSize
  388.                 Case 40
  389.                     $tBitmap = DllStructCreate("dword HeaderSize;" & _
  390.                             "dword Width;" & _
  391.                             "dword Height;" & _
  392.                             "ushort Planes;" & _
  393.                             "ushort BitPerPixel;" & _
  394.                             "dword CompressionMethod;" & _
  395.                             "dword Size;" & _
  396.                             "dword Hresolution;" & _
  397.                             "dword Vresolution;" & _
  398.                             "dword Colors;" & _
  399.                             "dword ImportantColors;", _
  400.                             DllStructGetPtr($tResource, "Body"))
  401.                 Case 12
  402.                     $tBitmap = DllStructCreate("dword HeaderSize;" & _
  403.                             "ushort Width;" & _
  404.                             "ushort Height;" & _
  405.                             "ushort Planes;" & _
  406.                             "ushort BitPerPixel;", _
  407.                             DllStructGetPtr($tResource, "Body"))
  408.                 Case Else
  409.                     Return SetError(6, 0, "")
  410.             EndSwitch
  411.  
  412.             Local $tCursorWrite = DllStructCreate("ushort Xhotspot;" & _
  413.                     "ushort Yhotspot;" & _
  414.                     "byte Body[" & DllStructGetSize($tResource) - 22 & "]", _
  415.                     DllStructGetPtr($tResource) + DllStructGetData($tResource, "BitmapOffset") - 4)
  416.  
  417.             DllStructSetData($tCursorWrite, "Xhotspot", DllStructGetData($tResource, "Xhotspot"))
  418.             DllStructSetData($tCursorWrite, "Yhotspot", DllStructGetData($tResource, "Xhotspot"))
  419.  
  420.             Local $a_hCall = DllCall("kernel32.dll", "hwnd", "BeginUpdateResourceW", "wstr", $sModule, "int", 0)
  421.  
  422.             If @error Or Not $a_hCall[0] Then
  423.                 Return SetError(7, 0, "")
  424.             EndIf
  425.  
  426.             Local $iCurName = 1
  427.             For $m = 0 To UBound($ARRAY_MODULE_STRUCTURE, 1) - 1
  428.                 If $ARRAY_MODULE_STRUCTURE[$m][0][0] = $RT_CURSOR Then
  429.                     For $n = 1 To UBound($ARRAY_MODULE_STRUCTURE, 2) - 1
  430.                         If $iCurName = $ARRAY_MODULE_STRUCTURE[$m][$n][0] Then
  431.                             $iCurName += 1
  432.                         EndIf
  433.                     Next
  434.                     ExitLoop
  435.                 EndIf
  436.             Next
  437.  
  438.             Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResource", _
  439.                     "hwnd", $a_hCall[0], _
  440.                     "int", $RT_CURSOR, _
  441.                     "int", $iCurName, _
  442.                     "int", $iResLang, _
  443.                     "ptr", DllStructGetPtr($tCursorWrite), _
  444.                     "dword", DllStructGetSize($tCursorWrite))
  445.  
  446.             If @error Or Not $a_iCall[0] Then
  447.                 DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  448.                 Return SetError(8, 0, "")
  449.             EndIf
  450.  
  451.             Local $tCursorGroupWrite = DllStructCreate("ushort;" & _
  452.                     "ushort Type;" & _
  453.                     "ushort ImageCount;" & _
  454.                     "ushort Width;" & _
  455.                     "ushort Height;" & _
  456.                     "ushort Planes;" & _
  457.                     "ushort BitPerPixel;" & _
  458.                     "ushort;" & _
  459.                     "ushort;" & _
  460.                     "ushort OrdinalName")
  461.  
  462.             DllStructSetData($tCursorGroupWrite, 1, DllStructGetData($tResource, 1))
  463.             DllStructSetData($tCursorGroupWrite, "Type", DllStructGetData($tResource, "Type"))
  464.             DllStructSetData($tCursorGroupWrite, "ImageCount", DllStructGetData($tResource, "ImageCount"))
  465.  
  466.             DllStructSetData($tCursorGroupWrite, "Width", DllStructGetData($tBitmap, "Width"))
  467.             DllStructSetData($tCursorGroupWrite, "Height", DllStructGetData($tBitmap, "Height"))
  468.  
  469.             DllStructSetData($tCursorGroupWrite, "Planes", DllStructGetData($tBitmap, "Planes"))
  470.             DllStructSetData($tCursorGroupWrite, "BitPerPixel", DllStructGetData($tBitmap, "BitPerPixel"))
  471.  
  472.             DllStructSetData($tCursorGroupWrite, 8, 308)
  473.  
  474.             DllStructSetData($tCursorGroupWrite, "OrdinalName", $iCurName)
  475.  
  476.             Switch IsNumber($iResName)
  477.                 Case True
  478.                     $a_iCall = DllCall("kernel32.dll", "int", "UpdateResource", _
  479.                             "hwnd", $a_hCall[0], _
  480.                             "int", $RT_GROUP_CURSOR, _
  481.                             "int", $iResName, _
  482.                             "int", $iResLang, _
  483.                             "ptr", DllStructGetPtr($tCursorGroupWrite), _
  484.                             "dword", DllStructGetSize($tCursorGroupWrite))
  485.                 Case Else
  486.                     $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  487.                             "hwnd", $a_hCall[0], _
  488.                             "int", $RT_GROUP_CURSOR, _
  489.                             "wstr", StringUpper($iResName), _
  490.                             "int", $iResLang, _
  491.                             "ptr", DllStructGetPtr($tCursorGroupWrite), _
  492.                             "dword", DllStructGetSize($tCursorGroupWrite))
  493.             EndSwitch
  494.  
  495.             If @error Or Not $a_iCall[0] Then
  496.                 DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  497.                 Return SetError(9, 0, "")
  498.             EndIf
  499.  
  500.             $a_iCall = DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  501.  
  502.             If @error Or Not $a_iCall[0] Then
  503.                 Return SetError(10, 0, "")
  504.             EndIf
  505.  
  506.  
  507.         Case $RT_GROUP_ICON
  508.  
  509.             Local $tBinary = DllStructCreate("byte[" & FileGetSize($sResFile) & "]")
  510.             Local $hResFile = FileOpen($sResFile, 16)
  511.             DllStructSetData($tBinary, 1, FileRead($hResFile))
  512.             FileClose($hResFile)
  513.  
  514.             Local $tResource = DllStructCreate("ushort;" & _
  515.                     "ushort Type;" & _
  516.                     "ushort ImageCount;" & _
  517.                     "byte Body[" & DllStructGetSize($tBinary) - 6 & "]", _
  518.                     DllStructGetPtr($tBinary))
  519.  
  520.             Local $iIconCount = DllStructGetData($tResource, "ImageCount")
  521.  
  522.             If Not $iIconCount Then
  523.                 Return SetError(5, 0, "")
  524.             EndIf
  525.  
  526.             Local $tIconGroupHeader = DllStructCreate("ushort;" & _
  527.                     "ushort Type;" & _
  528.                     "ushort ImageCount;" & _
  529.                     "byte Body[" & $iIconCount * 14 & "]")
  530.  
  531.             DllStructSetData($tIconGroupHeader, 1, DllStructGetData($tResource, 1))
  532.             DllStructSetData($tIconGroupHeader, "Type", DllStructGetData($tResource, "Type"))
  533.             DllStructSetData($tIconGroupHeader, "ImageCount", DllStructGetData($tResource, "ImageCount"))
  534.  
  535.             Local $tInputIconHeader
  536.             Local $tGroupIconData
  537.  
  538.             Local $a_hCall = DllCall("kernel32.dll", "hwnd", "BeginUpdateResourceW", "wstr", $sModule, "int", 0)
  539.  
  540.             If @error Or Not $a_hCall[0] Then
  541.                 Return SetError(6, 0, "")
  542.             EndIf
  543.  
  544.             Local $iEnumIconName
  545.  
  546.             For $i = 1 To $iIconCount
  547.  
  548.                 $tInputIconHeader = DllStructCreate("ubyte Width;" & _
  549.                         "ubyte Height;" & _
  550.                         "ubyte Colors;" & _
  551.                         "ubyte;" & _
  552.                         "ushort Planes;" & _
  553.                         "ushort BitPerPixel;" & _
  554.                         "dword BitmapSize;" & _
  555.                         "dword BitmapOffset", _
  556.                         DllStructGetPtr($tResource, "Body") + ($i - 1) * 16)
  557.  
  558.                 $tGroupIconData = DllStructCreate("ubyte Width;" & _
  559.                         "ubyte Height;" & _
  560.                         "ubyte Colors;" & _
  561.                         "ubyte;" & _
  562.                         "ushort Planes;" & _
  563.                         "ushort BitPerPixel;" & _
  564.                         "dword BitmapSize;" & _
  565.                         "ushort OrdinalName;", _
  566.                         DllStructGetPtr($tIconGroupHeader, "Body") + ($i - 1) * 14)
  567.  
  568.                 DllStructSetData($tGroupIconData, "Width", DllStructGetData($tInputIconHeader, "Width"))
  569.                 DllStructSetData($tGroupIconData, "Height", DllStructGetData($tInputIconHeader, "Height"))
  570.                 DllStructSetData($tGroupIconData, "Colors", DllStructGetData($tInputIconHeader, "Colors"))
  571.                 DllStructSetData($tGroupIconData, 4, DllStructGetData($tInputIconHeader, 4))
  572.                 DllStructSetData($tGroupIconData, "Planes", DllStructGetData($tInputIconHeader, "Planes"))
  573.                 DllStructSetData($tGroupIconData, "BitPerPixel", DllStructGetData($tInputIconHeader, "BitPerPixel"))
  574.                 DllStructSetData($tGroupIconData, "BitmapSize", DllStructGetData($tInputIconHeader, "BitmapSize"))
  575.  
  576.                 $iEnumIconName += 1
  577.                 For $m = 0 To UBound($ARRAY_MODULE_STRUCTURE, 1) - 1
  578.                     If $ARRAY_MODULE_STRUCTURE[$m][0][0] = $RT_ICON Then
  579.                         For $n = 1 To UBound($ARRAY_MODULE_STRUCTURE, 2) - 1
  580.                             If $iEnumIconName = $ARRAY_MODULE_STRUCTURE[$m][$n][0] Then
  581.                                 $iEnumIconName += 1
  582.                             EndIf
  583.                         Next
  584.                         ExitLoop
  585.                     EndIf
  586.                 Next
  587.  
  588.                 DllStructSetData($tGroupIconData, "OrdinalName", $iEnumIconName)
  589.  
  590.                 Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResource", _
  591.                         "hwnd", $a_hCall[0], _
  592.                         "int", $RT_ICON, _
  593.                         "int", $iEnumIconName, _
  594.                         "int", $iResLang, _
  595.                         "ptr", DllStructGetPtr($tResource) + DllStructGetData($tInputIconHeader, "BitmapOffset"), _
  596.                         "dword", DllStructGetData($tInputIconHeader, "BitmapSize"))
  597.  
  598.                 If @error Or Not $a_iCall[0] Then
  599.                     DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  600.                     Return SetError(7, $iEnumIconName, "")
  601.                 EndIf
  602.  
  603.             Next
  604.  
  605.             Switch IsNumber($iResName)
  606.                 Case True
  607.                     $a_iCall = DllCall("kernel32.dll", "int", "UpdateResource", _
  608.                             "hwnd", $a_hCall[0], _
  609.                             "int", $RT_GROUP_ICON, _
  610.                             "int", $iResName, _
  611.                             "int", $iResLang, _
  612.                             "ptr", DllStructGetPtr($tIconGroupHeader), _
  613.                             "dword", DllStructGetSize($tIconGroupHeader))
  614.                 Case Else
  615.                     $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  616.                             "hwnd", $a_hCall[0], _
  617.                             "int", $RT_GROUP_ICON, _
  618.                             "wstr", StringUpper($iResName), _
  619.                             "int", $iResLang, _
  620.                             "ptr", DllStructGetPtr($tIconGroupHeader), _
  621.                             "dword", DllStructGetSize($tIconGroupHeader))
  622.             EndSwitch
  623.  
  624.             If @error Or Not $a_iCall[0] Then
  625.                 DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  626.                 Return SetError(8, 0, "")
  627.             EndIf
  628.  
  629.             $a_iCall = DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  630.  
  631.             If @error Or Not $a_iCall[0] Then
  632.                 Return SetError(9, 0, "")
  633.             EndIf
  634.  
  635.  
  636.         Case $RT_RCDATA, $RT_MANIFEST, $RT_ANICURSOR, $RT_ANIICON, $RT_HTML
  637.  
  638.             Local $tResource = DllStructCreate("byte[" & FileGetSize($sResFile) & "]")
  639.             Local $hResFile = FileOpen($sResFile, 16)
  640.             DllStructSetData($tResource, 1, FileRead($hResFile))
  641.             FileClose($hResFile)
  642.  
  643.             If @error Then
  644.                 Return SetError(5, 0, "")
  645.             EndIf
  646.  
  647.             Local $a_hCall = DllCall("kernel32.dll", "hwnd", "BeginUpdateResourceW", "wstr", $sModule, "int", 0)
  648.  
  649.             If @error Or Not $a_hCall[0] Then
  650.                 Return SetError(6, 0, "")
  651.             EndIf
  652.  
  653.             Switch IsNumber($iResName)
  654.                 Case True
  655.                     Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResource", _
  656.                             "hwnd", $a_hCall[0], _
  657.                             "int", $iResType, _
  658.                             "int", $iResName, _
  659.                             "int", $iResLang, _
  660.                             "ptr", DllStructGetPtr($tResource), _
  661.                             "dword", FileGetSize($sResFile))
  662.                 Case Else
  663.                     Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  664.                             "hwnd", $a_hCall[0], _
  665.                             "int", $iResType, _
  666.                             "wstr", StringUpper($iResName), _
  667.                             "int", $iResLang, _
  668.                             "ptr", DllStructGetPtr($tResource), _
  669.                             "dword", FileGetSize($sResFile))
  670.             EndSwitch
  671.  
  672.             If @error Or Not $a_iCall[0] Then
  673.                 DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  674.                 Return SetError(7, 0, "")
  675.             EndIf
  676.  
  677.             $a_iCall = DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  678.  
  679.             If @error Or Not $a_iCall[0] Then
  680.                 Return SetError(8, 0, "")
  681.             EndIf
  682.  
  683.         Case $RT_BITMAP
  684.  
  685.             Local $tBinary = DllStructCreate("byte[" & FileGetSize($sResFile) & "]")
  686.             Local $hResFile = FileOpen($sResFile, 16)
  687.             DllStructSetData($tBinary, 1, FileRead($hResFile))
  688.             FileClose($hResFile)
  689.  
  690.             Local $tResource = DllStructCreate("align 2;char Identifier[2];" & _
  691.                     "dword BitmapSize;" & _
  692.                     "short;" & _
  693.                     "short;" & _
  694.                     "dword BitmapOffset;" & _
  695.                     "byte Body[" & DllStructGetSize($tBinary) - 14 & "]", _
  696.                     DllStructGetPtr($tBinary))
  697.  
  698.             If Not (DllStructGetData($tResource, 1) == "BM") Then
  699.                 Return SetError(5, 0, "")
  700.             EndIf
  701.  
  702.             Local $a_hCall = DllCall("kernel32.dll", "hwnd", "BeginUpdateResourceW", "wstr", $sModule, "int", 0)
  703.  
  704.             If @error Or Not $a_hCall[0] Then
  705.                 Return SetError(6, 0, "")
  706.             EndIf
  707.  
  708.             Switch IsNumber($iResName)
  709.                 Case True
  710.                     Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResource", _
  711.                             "hwnd", $a_hCall[0], _
  712.                             "int", $iResType, _
  713.                             "int", $iResName, _
  714.                             "int", $iResLang, _
  715.                             "ptr", DllStructGetPtr($tResource, "Body"), _
  716.                             "dword", FileGetSize($sResFile) - 14)
  717.                 Case Else
  718.                     Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  719.                             "hwnd", $a_hCall[0], _
  720.                             "int", $iResType, _
  721.                             "wstr", StringUpper($iResName), _
  722.                             "int", $iResLang, _
  723.                             "ptr", DllStructGetPtr($tResource, "Body"), _
  724.                             "dword", FileGetSize($sResFile) - 14)
  725.             EndSwitch
  726.  
  727.             If @error Or Not $a_iCall[0] Then
  728.                 DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  729.                 Return SetError(7, 0, "")
  730.             EndIf
  731.  
  732.             $a_iCall = DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  733.  
  734.             If @error Or Not $a_iCall[0] Then
  735.                 Return SetError(8, 0, "")
  736.             EndIf
  737.  
  738.  
  739.         Case Else
  740.  
  741.             Local $tResource = DllStructCreate("byte[" & FileGetSize($sResFile) & "]")
  742.             Local $hResFile = FileOpen($sResFile, 16)
  743.             DllStructSetData($tResource, 1, FileRead($hResFile))
  744.             FileClose($hResFile)
  745.  
  746.             If @error Then
  747.                 Return SetError(5, 0, "")
  748.             EndIf
  749.  
  750.             Local $a_hCall = DllCall("kernel32.dll", "hwnd", "BeginUpdateResourceW", "wstr", $sModule, "int", 0)
  751.  
  752.             If @error Or Not $a_hCall[0] Then
  753.                 Return SetError(6, 0, "")
  754.             EndIf
  755.  
  756.             Switch IsNumber($iResType) + 2 * IsNumber($iResName)
  757.                 Case 0
  758.                     Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  759.                             "hwnd", $a_hCall[0], _
  760.                             "wstr", StringUpper($iResType), _
  761.                             "wstr", StringUpper($iResName), _
  762.                             "int", $iResLang, _
  763.                             "ptr", DllStructGetPtr($tResource), _
  764.                             "dword", FileGetSize($sResFile))
  765.                 Case 1
  766.                     Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  767.                             "hwnd", $a_hCall[0], _
  768.                             "int", $iResType, _
  769.                             "wstr", StringUpper($iResName), _
  770.                             "int", $iResLang, _
  771.                             "ptr", DllStructGetPtr($tResource), _
  772.                             "dword", FileGetSize($sResFile))
  773.                 Case 2
  774.                     Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResourceW", _
  775.                             "hwnd", $a_hCall[0], _
  776.                             "wstr", StringUpper($iResType), _
  777.                             "int", $iResName, _
  778.                             "int", $iResLang, _
  779.                             "ptr", DllStructGetPtr($tResource), _
  780.                             "dword", FileGetSize($sResFile))
  781.                 Case 3
  782.                     Local $a_iCall = DllCall("kernel32.dll", "int", "UpdateResource", _
  783.                             "hwnd", $a_hCall[0], _
  784.                             "int", $iResType, _
  785.                             "int", $iResName, _
  786.                             "int", $iResLang, _
  787.                             "ptr", DllStructGetPtr($tResource), _
  788.                             "dword", FileGetSize($sResFile))
  789.             EndSwitch
  790.  
  791.             If @error Or Not $a_iCall[0] Then
  792.                 DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  793.                 Return SetError(7, 0, "")
  794.             EndIf
  795.  
  796.             $a_iCall = DllCall("kernel32.dll", "int", "EndUpdateResource", "hwnd", $a_hCall[0], "int", 0)
  797.  
  798.             If @error Or Not $a_iCall[0] Then
  799.                 Return SetError(8, 0, "")
  800.             EndIf
  801.  
  802.     EndSwitch
  803.  
  804.     Return SetError(0, 0, 1) ; all done
  805.  
  806. EndFunc   ;==>_ResUpdate
  807.  
  808. Func _ResourceGetAsRaw($iResType, $iResName, $iResLang, $sModule, $iMode = 0, $iSize = 0)
  809.  
  810.     Local $iLoaded
  811.     Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GetModuleHandleW", "wstr", $sModule)
  812.  
  813.     If @error Then
  814.         Return SetError(1, 0, "")
  815.     EndIf
  816.  
  817.     If Not $a_hCall[0] Then
  818.         $a_hCall = DllCall("kernel32.dll", "hwnd", "LoadLibraryExW", "wstr", $sModule, "hwnd", 0, "int", 34)
  819.         If @error Or Not $a_hCall[0] Then
  820.             Return SetError(2, 0, "")
  821.         EndIf
  822.         $iLoaded = 1
  823.     EndIf
  824.  
  825.     Local $hModule = $a_hCall[0]
  826.  
  827.     Switch IsNumber($iResType) + 2 * IsNumber($iResName)
  828.         Case 0
  829.             $a_hCall = DllCall("kernel32.dll", "hwnd", "FindResourceExW", _
  830.                     "hwnd", $hModule, _
  831.                     "wstr", $iResType, _
  832.                     "wstr", $iResName, _
  833.                     "int", $iResLang)
  834.         Case 1
  835.             $a_hCall = DllCall("kernel32.dll", "hwnd", "FindResourceExW", _
  836.                     "hwnd", $hModule, _
  837.                     "int", $iResType, _
  838.                     "wstr", $iResName, _
  839.                     "int", $iResLang)
  840.         Case 2
  841.             $a_hCall = DllCall("kernel32.dll", "hwnd", "FindResourceExW", _
  842.                     "hwnd", $hModule, _
  843.                     "wstr", $iResType, _
  844.                     "int", $iResName, _
  845.                     "int", $iResLang)
  846.         Case 3
  847.             $a_hCall = DllCall("kernel32.dll", "hwnd", "FindResourceExW", _
  848.                     "hwnd", $hModule, _
  849.                     "int", $iResType, _
  850.                     "int", $iResName, _
  851.                     "int", $iResLang)
  852.     EndSwitch
  853.  
  854.     If @error Or Not $a_hCall[0] Then
  855.         If $iLoaded Then
  856.             Local $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  857.             If @error Or Not $a_iCall[0] Then
  858.                 Return SetError(7, 0, "")
  859.             EndIf
  860.         EndIf
  861.         Return SetError(3, 0, "")
  862.     EndIf
  863.  
  864.     Local $hResource = $a_hCall[0]
  865.  
  866.     Local $a_iCall = DllCall("kernel32.dll", "int", "SizeofResource", "hwnd", $hModule, "hwnd", $hResource)
  867.  
  868.     If @error Or Not $a_iCall[0] Then
  869.         If $iLoaded Then
  870.             Local $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  871.             If @error Or Not $a_iCall[0] Then
  872.                 Return SetError(7, 0, "")
  873.             EndIf
  874.         EndIf
  875.         Return SetError(4, 0, "")
  876.     EndIf
  877.  
  878.     Local $iSizeOfResource = $a_iCall[0]
  879.  
  880.     $a_hCall = DllCall("kernel32.dll", "hwnd", "LoadResource", "hwnd", $hModule, "hwnd", $hResource)
  881.  
  882.     If @error Or Not $a_hCall[0] Then
  883.         If $iLoaded Then
  884.             Local $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  885.             If @error Or Not $a_iCall[0] Then
  886.                 Return SetError(7, 0, "")
  887.             EndIf
  888.         EndIf
  889.         Return SetError(5, 0, "")
  890.     EndIf
  891.  
  892.     Local $a_pCall = DllCall("kernel32.dll", "ptr", "LockResource", "hwnd", $a_hCall[0])
  893.  
  894.     If @error Or Not $a_pCall[0] Then
  895.         If $iLoaded Then
  896.             Local $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  897.             If @error Or Not $a_iCall[0] Then
  898.                 Return SetError(7, 0, "")
  899.             EndIf
  900.         EndIf
  901.         Return SetError(6, 0, "")
  902.     EndIf
  903.  
  904.     Local $tOut
  905.     Switch $iMode
  906.         Case 0
  907.             $tOut = DllStructCreate("char[" & $iSizeOfResource + 1 & "]", $a_pCall[0])
  908.         Case 1
  909.             $tOut = DllStructCreate("byte[" & $iSizeOfResource & "]", $a_pCall[0])
  910.     EndSwitch
  911.  
  912.     Local $sReturnData = DllStructGetData($tOut, 1)
  913.  
  914.     If $iLoaded Then
  915.         Local $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  916.         If @error Or Not $a_iCall[0] Then
  917.             Return SetError(7, 0, "")
  918.         EndIf
  919.     EndIf
  920.  
  921.     Switch $iSize
  922.         Case 0
  923.             Return SetError(0, 0, $sReturnData)
  924.         Case Else
  925.             Switch $iMode
  926.                 Case 0
  927.                     Return SetError(0, 0, StringLeft($sReturnData, $iSize))
  928.                 Case 1
  929.                     Return SetError(0, 0, BinaryMid($sReturnData, 1, $iSize))
  930.             EndSwitch
  931.     EndSwitch
  932.  
  933. EndFunc   ;==>_ResourceGetAsRaw
  934.  
  935. #region - Find Icon -
  936.  
  937. Func _ResRep($Host, $Name, $Res, $doWhat = 0)
  938.     If Not _ResInfo($Host) Then Return 0
  939.     For $f = 0 To UBound($ARRAY_MODULE_STRUCTURE, 1) - 1
  940.         If $ARRAY_MODULE_STRUCTURE[$f][0][0] = 14 Then; we only want acces to GROUPICON resources
  941.             For $g = 1 To UBound($ARRAY_MODULE_STRUCTURE, 2) - 1
  942.                 If $ARRAY_MODULE_STRUCTURE[$f][$g][0] == $Name Then
  943.                     Switch $doWhat
  944.                         Case 0
  945.                             If StringIsDigit($ARRAY_MODULE_STRUCTURE[$f][$g][0]) Then
  946.                                 _ResDelete($Host, 14, Int($Name), $ARRAY_MODULE_STRUCTURE[$f][$g][1])
  947.                                 If @error Then
  948.                                     _ResDelete($Host, 14, $Name, $ARRAY_MODULE_STRUCTURE[$f][$g][1])
  949.                                 Else
  950.                                     $Name = Int($Name)
  951.                                 EndIf
  952.                             Else
  953.                                 _ResDelete($Host, 14, $Name, $ARRAY_MODULE_STRUCTURE[$f][$g][1])
  954.                             EndIf
  955.                             If @error Then
  956.                                 MsgBox(16, "Error", "Could not replace icon.")
  957.                                 Return 0
  958.                             EndIf
  959.                             _ResUpdate($Host, 14, $Name, $ARRAY_MODULE_STRUCTURE[$f][$g][1], $Res)
  960.                         Case 1
  961.                             If StringIsDigit($ARRAY_MODULE_STRUCTURE[$f][$g][0]) Then
  962.                                 _ResDelete($Host, 14, Int($Name), $ARRAY_MODULE_STRUCTURE[$f][$g][1])
  963.                                 If @error Then
  964.                                     _ResDelete($Host, 14, $Name, $ARRAY_MODULE_STRUCTURE[$f][$g][1])
  965.                                 Else
  966.                                     $Name = Int($Name)
  967.                                 EndIf
  968.                             Else
  969.                                 _ResDelete($Host, 14, $Name, $ARRAY_MODULE_STRUCTURE[$f][$g][1])
  970.                             EndIf
  971.                     EndSwitch
  972.                 EndIf
  973.             Next
  974.         EndIf
  975.     Next
  976.     _ResEnum($Host)
  977.     Return 1
  978. EndFunc   ;==>_ResRep
  979.  
  980. Func _ResEnum($Host)
  981.  
  982.     Local $aListViewPos = ControlGetPos($Form1, 0, $ListView1)
  983.     If @error Then
  984.         Return SetError(1, 0, 0)
  985.     EndIf
  986.  
  987.     GUICtrlDelete($ListView1) ; the easiest way to stop leak
  988.     $ListView1 = 0
  989.     $ListView1 = GUICtrlCreateListView("Icons|name", $aListViewPos[0], $aListViewPos[1], $aListViewPos[2], $aListViewPos[3])
  990.  
  991.     GUICtrlSetFont($ListView1, 8)
  992.     GUICtrlSetColor($ListView1, 0x0000C0)
  993.     GUICtrlSetResizing($ListView1, 70)
  994.  
  995.     GUICtrlSetStyle($ListView1, 256) ; LVS_ICON|LVS_AUTOARRANGE
  996.     GUICtrlSetState($ListView1, 32)
  997.  
  998.     Local $aClientSize = WinGetClientSize($Form1)
  999.     If Not _ResInfo($Host) Then Return 0
  1000.     For $f = 0 To UBound($ARRAY_MODULE_STRUCTURE, 1) - 1
  1001.         If $ARRAY_MODULE_STRUCTURE[$f][0][0] = 14 Then ; we only want acces to GROUPICON resources
  1002.             For $g = 1 To UBound($ARRAY_MODULE_STRUCTURE, 2) - 1
  1003.                 If $ARRAY_MODULE_STRUCTURE[$f][$g][0] Then
  1004.                     For $h = 1 To UBound($ARRAY_MODULE_STRUCTURE, 3) - 1
  1005.                         ;MsgBox(0,"",$ARRAY_MODULE_STRUCTURE[$f][$g][0])
  1006.                         ;GUICtrlCreateListViewItem($ARRAY_MODULE_STRUCTURE[$f][$g][0], $CTRL)
  1007.                         ;GUICtrlSetImage(-1, $Host, $ARRAY_MODULE_STRUCTURE[$f][$g][0], 0)
  1008.                         Local $aIconData = _CrackIcon($ARRAY_MODULE_STRUCTURE[$f][$g][0], $ARRAY_MODULE_STRUCTURE[$f][$g][1], $Host)
  1009.                         If @error Then
  1010.                             Return SetError(2, 0, "")
  1011.                         EndIf
  1012.                         If Not IsArray($aIconData) Then
  1013.                             Return SetError(0, 1, "")
  1014.                         EndIf
  1015.  
  1016.                         Local $iWidth
  1017.                         Local $iHeight
  1018.                         For $i = 0 To UBound($aIconData) - 1
  1019.                             $iWidth = $aIconData[$i][0]
  1020.                             $iHeight = $aIconData[$i][1]
  1021.                             If $iWidth Then
  1022.                                 ExitLoop
  1023.                             EndIf
  1024.                         Next
  1025.  
  1026.  
  1027.  
  1028.  
  1029.                         ReDim $aListViewItem[UBound($aIconData)]
  1030.  
  1031.                         Local $bBinary
  1032.                         Local $tBinary
  1033.                         Local $tIcon, $iPNGIcon
  1034.                         Local $sTempFile = @DesktopDir & "\" & _GenerateGUID() & ".ico"
  1035.                         If @error Then
  1036.                             Return SetError(3, 0, "")
  1037.                         EndIf
  1038.                         Local $hTempFile
  1039.                         Local $iBitmapSize
  1040.  
  1041.                         For $i = 0 To UBound($aIconData) - 1
  1042.  
  1043.                             $bBinary = _ResourceGetAsRaw($RT_ICON, $aIconData[$i][6], $ARRAY_MODULE_STRUCTURE[$f][$g][1], $Host, 1)
  1044.                             If @error Then
  1045.                                 ContinueLoop
  1046.                             EndIf
  1047.  
  1048.                             $iBitmapSize = BinaryLen($bBinary)
  1049.                             $tBinary = DllStructCreate("byte[" & $iBitmapSize & "]")
  1050.                             DllStructSetData($tBinary, 1, $bBinary)
  1051.  
  1052.                             $tIcon = DllStructCreate("align 2;ushort;" & _
  1053.                                     "ushort Type;" & _
  1054.                                     "ushort ImageCount;" & _
  1055.                                     "ubyte Width;" & _
  1056.                                     "ubyte Height;" & _
  1057.                                     "ubyte Colors;" & _
  1058.                                     "ubyte;" & _
  1059.                                     "ushort Planes;" & _
  1060.                                     "ushort BitPerPixel;" & _
  1061.                                     "dword BitmapSize;" & _
  1062.                                     "dword BitmapOffset;" & _
  1063.                                     "byte Body[" & $iBitmapSize & "]")
  1064.  
  1065.                             DllStructSetData($tIcon, "Type", 1)
  1066.                             DllStructSetData($tIcon, "ImageCount", 1)
  1067.                             DllStructSetData($tIcon, "Width", $aIconData[$i][0])
  1068.                             DllStructSetData($tIcon, "Height", $aIconData[$i][1])
  1069.                             DllStructSetData($tIcon, "Colors", $aIconData[$i][2])
  1070.                             DllStructSetData($tIcon, "Planes", $aIconData[$i][3])
  1071.                             DllStructSetData($tIcon, "BitPerPixel", $aIconData[$i][4])
  1072.                             DllStructSetData($tIcon, "BitmapSize", $iBitmapSize) ; $aIconData[$i][5])
  1073.                             DllStructSetData($tIcon, "BitmapOffset", 22)
  1074.                             DllStructSetData($tIcon, "Body", DllStructGetData($tBinary, 1))
  1075.  
  1076.                             $tBinary = DllStructCreate("byte[" & DllStructGetSize($tIcon) & "]", DllStructGetPtr($tIcon))
  1077.  
  1078.                             $hTempFile = FileOpen($sTempFile, 26)
  1079.                             FileWrite($hTempFile, DllStructGetData($tBinary, 1))
  1080.                             FileClose($hTempFile)
  1081.  
  1082.                             If $aIconData[$i][6] Then
  1083.                                 If Not $aIconData[$i][2] Then
  1084.                                     $aIconData[$i][2] = ">256"
  1085.                                 EndIf
  1086.                                 If Not $aIconData[$i][0] Then
  1087.                                     $aIconData[$i][0] = 256
  1088.                                 EndIf
  1089.                                 If Not $aIconData[$i][1] Then
  1090.                                     $aIconData[$i][1] = 256
  1091.                                 EndIf
  1092.                             EndIf
  1093.  
  1094.                             $aListViewItem[$i] = GUICtrlCreateListViewItem("Width: " & $aIconData[$i][0] & @LF & _
  1095.                                     "Height: " & $aIconData[$i][1] & @LF & _
  1096.                                     "Colors: " & $aIconData[$i][2] & @LF & _
  1097.                                     "Planes: " & $aIconData[$i][3] & @LF & _
  1098.                                     "BitPerPixel: " & $aIconData[$i][4] & @LF & _
  1099.                                     "ImageSize: " & $aIconData[$i][5] & " bytes" & @LF & _
  1100.                                     "RTIcon name: " & $aIconData[$i][6] & "|" & $ARRAY_MODULE_STRUCTURE[$f][$g][0], _
  1101.                                     $ListView1)
  1102.  
  1103.                             If Not GUICtrlSetImage($aListViewItem[$i], $sTempFile, -1) Then
  1104.                                 $iPNGIcon += 1
  1105.                             EndIf
  1106.                         Next
  1107.  
  1108.                         FileDelete($sTempFile)
  1109.  
  1110.                         GUICtrlSetState($ListView1, 16)
  1111.  
  1112.                         ;Return SetError(0, 0, 1)
  1113.  
  1114.                     Next
  1115.                 EndIf
  1116.             Next
  1117.         EndIf
  1118.     Next
  1119.     Return 1
  1120. EndFunc   ;==>_ResEnum
  1121.  
  1122. Func _ResourceEnumerate(ByRef $sModule)
  1123.  
  1124.     DllCall("kernel32.dll", "dword", "SetErrorMode", "dword", 1) ; SEM_FAILCRITICALERRORS
  1125.     Local $iLoaded
  1126.     Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GetModuleHandleW", "wstr", $sModule)
  1127.     If @error Then
  1128.         Return SetError(2, 0, "")
  1129.     EndIf
  1130.     If Not $a_hCall[0] Then
  1131.         $a_hCall = DllCall("kernel32.dll", "hwnd", "LoadLibraryExW", "wstr", $sModule, "hwnd", 0, "int", 34) ; LOAD_LIBRARY_AS_IMAGE_RESOURCE|LOAD_LIBRARY_AS_DATAFILE
  1132.         If @error Or Not $a_hCall[0] Then
  1133.             Return SetError(3, 0, "")
  1134.         EndIf
  1135.         $iLoaded = 1
  1136.     EndIf
  1137.     Local $hModule = $a_hCall[0]
  1138.     $ARRAY_MODULE_STRUCTURE[0][0][0] = ""
  1139.     $global_names_count = 1
  1140.     $name_count = 0
  1141.     $global_langs_count = 1
  1142.     $lang_count = 0
  1143.     $global_types_count = 1
  1144.     Local $h_CB = DllCallbackRegister("_CallbackEnumResTypeProc", "int", "hwnd;ptr;ptr")
  1145.     If Not $h_CB Then
  1146.         Return SetError(4, 0, "")
  1147.     EndIf
  1148.     Local $h_CB1 = DllCallbackRegister("_CallbackEnumResNameProc", "int", "hwnd;ptr;ptr;ptr")
  1149.     If Not $h_CB1 Then
  1150.         Return SetError(4, 0, "")
  1151.     EndIf
  1152.     Local $a_iCall = DllCall("kernel32.dll", "int", "EnumResourceTypesW", _
  1153.             "hwnd", $hModule, _
  1154.             "ptr", DllCallbackGetPtr($h_CB), _
  1155.             "ptr", DllCallbackGetPtr($h_CB1)) ; 0
  1156.     If @error Then
  1157.         DllCallbackFree($h_CB)
  1158.         If $iLoaded Then
  1159.             $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  1160.             If @error Or Not $a_iCall[0] Then
  1161.                 Return SetError(6, 0, "")
  1162.             EndIf
  1163.         EndIf
  1164.         Return SetError(5, 0, "")
  1165.     EndIf
  1166.     DllCallbackFree($h_CB1)
  1167.     DllCallbackFree($h_CB)
  1168.     If $iLoaded Then
  1169.         $a_iCall = DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  1170.         If @error Or Not $a_iCall[0] Then
  1171.             Return SetError(6, 0, "")
  1172.         EndIf
  1173.     EndIf
  1174.     Return SetError(0, 0, 1)
  1175. EndFunc   ;==>_ResourceEnumerate
  1176.  
  1177. Func _CallbackEnumResTypeProc($hModule, $pType, $lParam)
  1178.     $global_types_count += 1
  1179.     $name_count = 0
  1180.     If $iPopulateArray Then
  1181.         Local $a_iCall = DllCall("kernel32.dll", "int", "lstrlenW", "ptr", $pType)
  1182.         If $a_iCall[0] Then
  1183.             Local $tType = DllStructCreate("wchar[" & $a_iCall[0] + 1 & "]", $pType)
  1184.             $ARRAY_MODULE_STRUCTURE[$global_types_count - 1][0][0] = DllStructGetData($tType, 1)
  1185.         Else
  1186.             $ARRAY_MODULE_STRUCTURE[$global_types_count - 1][0][0] = BitOR($pType, 0)
  1187.         EndIf
  1188.     EndIf
  1189.     Local $h_CB = DllCallbackRegister("_CallbackEnumResLangProc", "int", "hwnd;ptr;ptr;ushort;int")
  1190.     $a_iCall = DllCall("kernel32.dll", "int", "EnumResourceNamesW", _
  1191.             "hwnd", $hModule, _
  1192.             "ptr", $pType, _
  1193.             "ptr", $lParam, _
  1194.             "ptr", DllCallbackGetPtr($h_CB))
  1195.     DllCallbackFree($h_CB)
  1196.     Return 1
  1197. EndFunc   ;==>_CallbackEnumResTypeProc
  1198.  
  1199. Func _CallbackEnumResLangProc($hModule, $pType, $pName, $iLang, $lParam)
  1200.     $lang_count += 1
  1201.     If $lang_count > $global_langs_count - 1 Then
  1202.         $global_langs_count += 1
  1203.     EndIf
  1204.     If $iPopulateArray Then
  1205.         $ARRAY_MODULE_STRUCTURE[$global_types_count - 1][$lParam][$lang_count] = $iLang
  1206.     EndIf
  1207.     Return 1
  1208. EndFunc   ;==>_CallbackEnumResLangProc
  1209.  
  1210. Func _CallbackEnumResNameProc($hModule, $pType, $pName, $lParam)
  1211.     $lang_count = 0
  1212.     $name_count += 1
  1213.     If $iPopulateArray Then
  1214.         Local $a_iCall = DllCall("kernel32.dll", "int", "lstrlenW", "ptr", $pName)
  1215.         If $a_iCall[0] Then
  1216.             Local $tName = DllStructCreate("wchar[" & $a_iCall[0] + 1 & "]", $pName)
  1217.             $ARRAY_MODULE_STRUCTURE[$global_types_count - 1][$name_count][0] = DllStructGetData($tName, 1)
  1218.         Else
  1219.             $ARRAY_MODULE_STRUCTURE[$global_types_count - 1][$name_count][0] = BitOR($pName, 0)
  1220.         EndIf
  1221.     Else
  1222.         If $name_count > $global_names_count - 1 Then
  1223.             $global_names_count += 1
  1224.         EndIf
  1225.     EndIf
  1226.     $a_iCall = DllCall("kernel32.dll", "int", "EnumResourceLanguagesW", _
  1227.             "hwnd", $hModule, _
  1228.             "ptr", $pType, _
  1229.             "ptr", $pName, _
  1230.             "ptr", $lParam, _
  1231.             "int", $name_count)
  1232.     Return 1
  1233. EndFunc   ;==>_CallbackEnumResNameProc
  1234.  
  1235. Func _ResInfo($sFile)
  1236.     If $sFile Then
  1237.         Local $hFile = FileOpen($sFile, 16)
  1238.         If $hFile = -1 Then
  1239.             MsgBox(48, "Error", "Inernal error")
  1240.             Return 0
  1241.         EndIf
  1242.         Local $bFile = FileRead($hFile)
  1243.         FileClose($hFile)
  1244.         If Not (BinaryToString(BinaryMid($bFile, 1, 2)) == "MZ") Then
  1245.             MsgBox(48, "Error", "Invalid file type! Choose another.")
  1246.             Return 0
  1247.         EndIf
  1248.         $iPopulateArray = 0
  1249.         ReDim $ARRAY_MODULE_STRUCTURE[1][1][1]
  1250.         _ResourceEnumerate($sFile) ; to determine $ARRAY_MODULE_STRUCTURE size
  1251.         Switch @error
  1252.             Case 2, 4, 6
  1253.                 MsgBox(48, "Error", "Inernal error")
  1254.                 Return 0
  1255.             Case 3
  1256.                 MsgBox(48, "Error", "Unable to load " & FileGetLongName($sFile))
  1257.                 Return 0
  1258.             Case 5
  1259.                 MsgBox(48, "Error", "Error enumerating")
  1260.                 Return 0
  1261.         EndSwitch
  1262.         $iPopulateArray = 1
  1263.         ReDim $ARRAY_MODULE_STRUCTURE[$global_types_count][$global_names_count][$global_langs_count]
  1264.         _ResourceEnumerate($sFile)
  1265.         Switch @error
  1266.             Case 2, 4, 6
  1267.                 MsgBox(48, "Error", "Inernal error")
  1268.                 Return 0
  1269.             Case 3
  1270.                 MsgBox(48, "Error", "Unable to load " & FileGetLongName($sFile))
  1271.                 Return 0
  1272.             Case 5
  1273.                 MsgBox(48, "Error", "Error enumerating")
  1274.                 Return 0
  1275.         EndSwitch
  1276.     Else
  1277.         Return 0
  1278.     EndIf
  1279.     Return 1
  1280. EndFunc   ;==>_ResInfo
  1281.  
  1282. Func _GenerateGUID()
  1283.  
  1284.     Local $GUIDSTRUCT = DllStructCreate("int;short;short;byte[8]")
  1285.  
  1286.     Local $a_iCall = DllCall("rpcrt4.dll", "int", "UuidCreate", "ptr", DllStructGetPtr($GUIDSTRUCT))
  1287.  
  1288.     If @error Or $a_iCall[0] Then
  1289.         Return SetError(1, 0, "")
  1290.     EndIf
  1291.  
  1292.     $a_iCall = DllCall("ole32.dll", "int", "StringFromGUID2", _
  1293.             "ptr", DllStructGetPtr($GUIDSTRUCT), _
  1294.             "wstr", "", _
  1295.             "int", 40)
  1296.  
  1297.     If @error Or Not $a_iCall[0] Then
  1298.         Return SetError(2, 0, "")
  1299.     EndIf
  1300.  
  1301.     Return SetError(0, 0, $a_iCall[2])
  1302.  
  1303. EndFunc   ;==>_GenerateGUID
  1304.  
  1305. Func _CrackIcon($iIconName, $iResLang, $sModule, $doWhat = 0)
  1306.  
  1307.     Local $bBinary = _ResourceGetAsRaw($RT_GROUP_ICON, $iIconName, $iResLang, $sModule, 1)
  1308.  
  1309.     If @error Then
  1310.         Return SetError(@error + 3, 0, "")
  1311.     EndIf
  1312.  
  1313.     Local $tBinary = DllStructCreate("byte[" & BinaryLen($bBinary) & "]")
  1314.     DllStructSetData($tBinary, 1, $bBinary)
  1315.  
  1316.     Local $tResource = DllStructCreate("ushort;" & _
  1317.             "ushort Type;" & _
  1318.             "ushort ImageCount;" & _
  1319.             "byte Body[" & DllStructGetSize($tBinary) - 6 & "]", _
  1320.             DllStructGetPtr($tBinary))
  1321.  
  1322.     Local $iIconCount = DllStructGetData($tResource, "ImageCount")
  1323.  
  1324.     If Not $iIconCount Or $iIconCount > 50 Then ; this likely indicates usage of exe compressor
  1325.         Return SetError(0, 1, "")
  1326.     EndIf
  1327.  
  1328.     Local $iWidth, $iHeight
  1329.     Local $aIconsData[$iIconCount][7]
  1330.     Local $tGroupIconData
  1331.  
  1332.     For $i = 0 To $iIconCount - 1
  1333.         $tGroupIconData = DllStructCreate("ubyte Width;" & _
  1334.                 "ubyte Height;" & _
  1335.                 "ubyte Colors;" & _
  1336.                 "ubyte;" & _
  1337.                 "ushort Planes;" & _
  1338.                 "ushort BitPerPixel;" & _
  1339.                 "dword BitmapSize;" & _
  1340.                 "ushort OrdinalName;", _
  1341.                 DllStructGetPtr($tResource, "Body") + $i * 14)
  1342.  
  1343.         $iWidth = DllStructGetData($tGroupIconData, "Width")
  1344.         If Not $iWidth Then
  1345.             $iWidth = 256
  1346.         EndIf
  1347.  
  1348.         $iHeight = DllStructGetData($tGroupIconData, "Height")
  1349.         If Not $iHeight Then
  1350.             $iHeight = 256
  1351.         EndIf
  1352.  
  1353.         $aIconsData[$i][0] = $iWidth
  1354.         $aIconsData[$i][1] = $iHeight
  1355.         $aIconsData[$i][2] = DllStructGetData($tGroupIconData, "Colors")
  1356.         $aIconsData[$i][3] = DllStructGetData($tGroupIconData, "Planes")
  1357.         $aIconsData[$i][4] = DllStructGetData($tGroupIconData, "BitPerPixel")
  1358.         $aIconsData[$i][5] = DllStructGetData($tGroupIconData, "BitmapSize")
  1359.         $aIconsData[$i][6] = DllStructGetData($tGroupIconData, "OrdinalName")
  1360.         If $doWhat Then
  1361.         EndIf
  1362.     Next
  1363.  
  1364.     Return SetError(0, 0, $aIconsData)
  1365.  
  1366. EndFunc   ;==>_CrackIcon
  1367.  
  1368. #endregion - Find Icon -
  1369.  
  1370. Func READEOF($sModule)
  1371.     Local $iLoaded
  1372.     Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GetModuleHandleW", "wstr", $sModule)
  1373.     If @error Then
  1374.         Return SetError(1, 0, "")
  1375.     EndIf
  1376.     Local $pPointer = $a_hCall[0]
  1377.  
  1378.     If Not $a_hCall[0] Then
  1379.         $a_hCall = DllCall("kernel32.dll", "hwnd", "LoadLibraryExW", "wstr", $sModule, "hwnd", 0, "int", 1)
  1380.         If @error Or Not $a_hCall[0] Then
  1381.             Return SetError(2, 0, "")
  1382.         EndIf
  1383.         $iLoaded = 1
  1384.         $pPointer = $a_hCall[0]
  1385.     EndIf
  1386.  
  1387.  
  1388.     Local $hModule = $a_hCall[0]
  1389.     Local $tIMAGE_DOS_HEADER = DllStructCreate("char Magic[2];" & _
  1390.             "ushort BytesOnLastPage;" & _
  1391.             "ushort Pages;" & _
  1392.             "ushort Relocations;" & _
  1393.             "ushort SizeofHeader;" & _
  1394.             "ushort MinimumExtra;" & _
  1395.             "ushort MaximumExtra;" & _
  1396.             "ushort SS;" & _
  1397.             "ushort SP;" & _
  1398.             "ushort Checksum;" & _
  1399.             "ushort IP;" & _
  1400.             "ushort CS;" & _
  1401.             "ushort Relocation;" & _
  1402.             "ushort Overlay;" & _
  1403.             "char Reserved[8];" & _
  1404.             "ushort OEMIdentifier;" & _
  1405.             "ushort OEMInformation;" & _
  1406.             "char Reserved2[20];" & _
  1407.             "dword AddressOfNewExeHeader", _
  1408.             $pPointer)
  1409.     $pPointer += DllStructGetData($tIMAGE_DOS_HEADER, "AddressOfNewExeHeader")
  1410.     Local $tIMAGE_NT_SIGNATURE = DllStructCreate("dword Signature", $pPointer)
  1411.     If Not (DllStructGetData($tIMAGE_NT_SIGNATURE, "Signature") = 17744) Then
  1412.         If $iLoaded Then
  1413.             DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  1414.         EndIf
  1415.         Return SetError(3, 0, "")
  1416.     EndIf
  1417.     $pPointer += 4
  1418.     Local $tIMAGE_FILE_HEADER = DllStructCreate("ushort Machine;" & _
  1419.             "ushort NumberOfSections;" & _
  1420.             "dword TimeDateStamp;" & _
  1421.             "dword PointerToSymbolTable;" & _
  1422.             "dword NumberOfSymbols;" & _
  1423.             "ushort SizeOfOptionalHeader;" & _
  1424.             "ushort Characteristics", _
  1425.             $pPointer)
  1426.  
  1427.     Local $iNumberOfSections = DllStructGetData($tIMAGE_FILE_HEADER, "NumberOfSections")
  1428.     $pPointer += 20
  1429. ;~     Local $tIMAGE_OPTIONAL_HEADER = DllStructCreate("ushort Magic;" & _
  1430. ;~             "ubyte MajorLinkerVersion;" & _
  1431. ;~             "ubyte MinorLinkerVersion;" & _
  1432. ;~             "dword SizeOfCode;" & _
  1433. ;~             "dword SizeOfInitializedData;" & _
  1434. ;~             "dword SizeOfUninitializedData;" & _
  1435. ;~             "dword AddressOfEntryPoint;" & _
  1436. ;~             "dword BaseOfCode;" & _
  1437. ;~             "dword BaseOfData;" & _
  1438. ;~             "dword ImageBase;" & _
  1439. ;~             "dword SectionAlignment;" & _
  1440. ;~             "dword FileAlignment;" & _
  1441. ;~             "ushort MajorOperatingSystemVersion;" & _
  1442. ;~             "ushort MinorOperatingSystemVersion;" & _
  1443. ;~             "ushort MajorImageVersion;" & _
  1444. ;~             "ushort MinorImageVersion;" & _
  1445. ;~             "ushort MajorSubsystemVersion;" & _
  1446. ;~             "ushort MinorSubsystemVersion;" & _
  1447. ;~             "dword Win32VersionValue;" & _
  1448. ;~             "dword SizeOfImage;" & _
  1449. ;~             "dword SizeOfHeaders;" & _
  1450. ;~             "dword CheckSum;" & _
  1451. ;~             "ushort Subsystem;" & _
  1452. ;~             "ushort DllCharacteristics;" & _
  1453. ;~             "dword SizeOfStackReserve;" & _
  1454. ;~             "dword SizeOfStackCommit;" & _
  1455. ;~             "dword SizeOfHeapReserve;" & _
  1456. ;~             "dword SizeOfHeapCommit;" & _
  1457. ;~             "dword LoaderFlags;" & _
  1458. ;~             "dword NumberOfRvaAndSizes", _
  1459. ;~             $pPointer)
  1460.     $pPointer += 96
  1461. ;~     Local $tIMAGE_DIRECTORY_ENTRY_EXPORT = DllStructCreate("dword VirtualAddress;" & _
  1462. ;~             "dword Size", _
  1463. ;~             $pPointer)
  1464.     $pPointer += 8
  1465. ;~     Local $tIMAGE_DIRECTORY_ENTRY_IMPORT = DllStructCreate("dword VirtualAddress;" & _
  1466. ;~             "dword Size", _
  1467. ;~             $pPointer)
  1468.     $pPointer += 8
  1469. ;~     Local $tIMAGE_DIRECTORY_ENTRY_RESOURCE = DllStructCreate("dword VirtualAddress;" & _
  1470. ;~             "dword Size", _
  1471. ;~             $pPointer)
  1472.     $pPointer += 8
  1473. ;~     Local $tIMAGE_DIRECTORY_ENTRY_EXCEPTION = DllStructCreate("dword VirtualAddress;" & _
  1474. ;~             "dword Size", _
  1475. ;~             $pPointer)
  1476.     $pPointer += 8
  1477. ;~     Local $tIMAGE_DIRECTORY_ENTRY_SECURITY = DllStructCreate("dword VirtualAddress;" & _
  1478. ;~             "dword Size", _
  1479. ;~             $pPointer)
  1480.     $pPointer += 8
  1481. ;~     Local $tIMAGE_DIRECTORY_ENTRY_BASERELOC = DllStructCreate("dword VirtualAddress;" & _
  1482. ;~             "dword Size", _
  1483. ;~             $pPointer)
  1484.     $pPointer += 8
  1485. ;~     Local $tIMAGE_DIRECTORY_ENTRY_DEBUG = DllStructCreate("dword VirtualAddress;" & _
  1486. ;~             "dword Size", _
  1487. ;~             $pPointer)
  1488.     $pPointer += 8
  1489. ;~     Local $tIMAGE_DIRECTORY_ENTRY_COPYRIGHT = DllStructCreate("dword VirtualAddress;" & _
  1490. ;~             "dword Size", _
  1491. ;~             $pPointer)
  1492.     $pPointer += 8
  1493. ;~     Local $tIMAGE_DIRECTORY_ENTRY_GLOBALPTR = DllStructCreate("dword VirtualAddress;" & _
  1494. ;~             "dword Size", _
  1495. ;~             $pPointer)
  1496.     $pPointer += 8
  1497. ;~     Local $tIMAGE_DIRECTORY_ENTRY_TLS = DllStructCreate("dword VirtualAddress;" & _
  1498. ;~             "dword Size", _
  1499. ;~             $pPointer)
  1500.     $pPointer += 8
  1501. ;~     Local $tIMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = DllStructCreate("dword VirtualAddress;" & _
  1502. ;~             "dword Size", _
  1503. ;~             $pPointer)
  1504.     $pPointer += 8
  1505.     $pPointer += 40
  1506.     Local $tIMAGE_SECTION_HEADER
  1507.     For $i = 1 To $iNumberOfSections
  1508.         $tIMAGE_SECTION_HEADER = DllStructCreate("char Name[8];" & _
  1509.                 "dword UnionOfData;" & _
  1510.                 "dword VirtualAddress;" & _
  1511.                 "dword SizeOfRawData;" & _
  1512.                 "dword PointerToRawData;" & _
  1513.                 "dword PointerToRelocations;" & _
  1514.                 "dword PointerToLinenumbers;" & _
  1515.                 "ushort NumberOfRelocations;" & _
  1516.                 "ushort NumberOfLinenumbers;" & _
  1517.                 "dword Characteristics", _
  1518.                 $pPointer)
  1519.         If $i = $iNumberOfSections Then
  1520.             Local $array[2]
  1521.             $array[0] = Hex(DllStructGetData($tIMAGE_SECTION_HEADER, "PointerToRawData"))
  1522.             $array[1] = DllStructGetData($tIMAGE_SECTION_HEADER, "SizeOfRawData")
  1523.             Local $FilePath = $sModule
  1524.             Local $Offset = Dec($array[0]) + $array[1]
  1525.             Local $Length = FileGetSize($sModule) - $Offset
  1526.  
  1527.             Local $Buffer, $ptr, $fLen, $hFile, $Result, $Read, $err, $Pos
  1528.  
  1529.             If Not FileExists($FilePath) Then Return SetError(1, @error, 0)
  1530.             $fLen = FileGetSize($FilePath)
  1531.             If $Offset > $fLen Then Return SetError(2, @error, 0)
  1532.             If $fLen < $Offset + $Length Then Return SetError(3, @error, 0)
  1533.  
  1534.             $Buffer = DllStructCreate("byte[" & $Length & "]")
  1535.             $ptr = DllStructGetPtr($Buffer)
  1536.  
  1537.             $hFile = _WinAPI_CreateFile($FilePath, 2, 2, 0)
  1538.             If $hFile = 0 Then Return SetError(5, @error, 0)
  1539.  
  1540.             $Pos = $Offset
  1541.             $Result = _WinAPI_SetFilePointer($hFile, $Pos)
  1542.             $err = @error
  1543.             If $Result = 0xFFFFFFFF Then
  1544.                 _WinAPI_CloseHandle($hFile)
  1545.                 Return SetError(6, $err, 0)
  1546.             EndIf
  1547.  
  1548.             $Read = 0
  1549.             $Result = _WinAPI_ReadFile($hFile, $ptr, $Length, $Read)
  1550.             $err = @error
  1551.             If Not $Result Then
  1552.                 _WinAPI_CloseHandle($hFile)
  1553.                 Return SetError(7, $err, 0)
  1554.             EndIf
  1555.  
  1556.             _WinAPI_CloseHandle($hFile)
  1557.             If Not $Result Then Return SetError(8, @error, 0)
  1558.  
  1559.             $Result = DllStructGetData($Buffer, 1)
  1560.             DllCall("kernel32.dll", "int", "FreeLibrary", "hwnd", $hModule)
  1561.  
  1562.             If Not StringIsDigit($Result) Then
  1563.                 $Tempname = @TempDir & "\SCRIPT_DATUM.bin"
  1564.                 $Num = 0
  1565.                 If FileExists($Tempname) Then
  1566.                     While FileExists($Tempname)
  1567.                         $Tempname = @TempDir & "\SCRIPT_DATUM(" & $Num & ").bin"
  1568.                         $Num += 1
  1569.                     WEnd
  1570.                 EndIf
  1571.                 $Htmp = FileOpen($Tempname, 2)
  1572.                 FileWrite($Htmp, $Result)
  1573.                 FileClose($Htmp)
  1574.                 _ResUpdate($sModule, 10, "SCRIPT_DATUM", 0, $Tempname);Add as resource so nothing is lost
  1575.                 FileDelete($Tempname)
  1576.             EndIf
  1577.         EndIf
  1578.  
  1579.         $pPointer += 40
  1580.  
  1581.     Next
  1582.  
  1583. EndFunc   ;==>READEOF
  1584.  
  1585. Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
  1586.     Local $nSize, $pFileName, $aDropFiles[1]
  1587.     Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
  1588.     $nAmt = $nAmt[0] - 1
  1589.     If $nAmt > 0 Then Return MsgBox(64,"Advisory!","Only one file at a time!")
  1590.     $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0, "ptr", 0, "int", 0)
  1591.     $nSize = $nSize[0] + 1
  1592.     $pFileName = DllStructCreate("char[" & $nSize & "]")
  1593.     DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
  1594.     Local $sTarget = DllStructGetData($pFileName, 1)
  1595.     If StringRight($sTarget,4) == ".lnk" Then
  1596.         $aInfo = FileGetShortcut($sTarget)
  1597.         If Not @error Then
  1598.             $sTarget = $aInfo[0]
  1599.         EndIf
  1600.     EndIf
  1601.     GUICtrlSetData($Input1, $sTarget)
  1602.     $pFileName = 0
  1603.     _ResEnum(GUICtrlRead($Input1))
  1604. EndFunc
  1605.  
  1606. Func WM_GETMINMAXINFO($hWnd, $iMsg, $WPARAM, $lParam)
  1607.     #forceref $hwnd, $iMsg, $WPARAM
  1608.     Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
  1609.     DllStructSetData($tagMaxinfo, 7, $GUIMINWID) ; min X
  1610.     DllStructSetData($tagMaxinfo, 8, $GUIMINHT + 15) ; min Y
  1611.     DllStructSetData($tagMaxinfo, 9, 99999) ; max X
  1612.     DllStructSetData($tagMaxinfo, 10, 99999) ; max Y
  1613.     Return 'GUI_RUNDEFMSG'
  1614. EndFunc   ;==>WM_GETMINMAXINFO
  1615.  
  1616. Func Terminate()
  1617.     Exit
  1618. EndFunc   ;==>Terminate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement