Terenz Posted September 21, 2019 Share Posted September 21, 2019 (edited) Hello, My goal is change an autoit compiled icon to another one, after i have compiled After some search i have found this example: https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_BeginUpdateResource.htm Which seems the good one for my goal but if fail on ReadFile ( return 0, but the handle is present ). I have try with several icon, same result. For example this script work: https://pastebin.com/5ru8H0cN But is too overcomplex with several function. I just want to set two variable, the EXE and the ICON. I don't have any interest to other resource, or the information, or the GUI etc. something very simple without using ReasHack or other tools since it works just using autoit Thanks Edited September 21, 2019 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Nine Posted September 21, 2019 Share Posted September 21, 2019 3 hours ago, Terenz said: After some search i have found this example: https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_BeginUpdateResource.htm I just ran the example and it worked for me... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
abberration Posted September 21, 2019 Share Posted September 21, 2019 I tried to pull out functions in the script to eliminate the gui, but I couldn't get it to work. It's a complicated script. Basically, you need to modify the following functions: Replace() _ResRep _ResourceGetAsRaw _ResourceEnumerate _LittleEndianBinaryToInt If you are able to get it to work, it will still be a large and complicated script. Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
abberration Posted September 21, 2019 Share Posted September 21, 2019 Aww heck, the _WinAPI_BeginUpdateResource example script you mentioned works. I modified the script a little and here it is. Just change the name of your exe and the icon and there you go. It's still kind of long, but if you wanted, you could convert some of the code into a #include file to have super short and simple code. expandcollapse popup#include <WinAPIRes.au3> Global Const $g_sExe = @ScriptDir & '\photofiltre7.exe' ; this is the name of the executable Global Const $tagICONRESDIR = 'byte Width;byte Height;byte ColorCount;byte Reserved;ushort Planes;ushort BitCount;dword BytesInRes;ushort IconId;' Global Const $tagNEWHEADER = 'ushort Reserved;ushort ResType;ushort ResCount;' ; & $tagICONRESDIR[ResCount] ; Select icon to update resource Local $sIcon = @ScriptDir & "\icon.ico" ; this is the name of your icon If Not $sIcon Then Exit EndIf Local $iError = 1 Do ; Begin update resources Local $hUpdate = _WinAPI_BeginUpdateResource($g_sExe) If @error Then ExitLoop EndIf ; Read .ico file as raw binary data into the structure Local $tIcon = DllStructCreate('ushort Reserved;ushort Type;ushort Count;byte[' & (FileGetSize($sIcon) - 6) & ']') Local $hFile = _WinAPI_CreateFile($sIcon, 2, 2) If Not $hFile Then ExitLoop EndIf Local $iBytes = 0 _WinAPI_ReadFile($hFile, $tIcon, DllStructGetSize($tIcon), $iBytes) _WinAPI_CloseHandle($hFile) If Not $iBytes Then ExitLoop EndIf ; Add all icons from .ico file into the RT_ICON resources identified as 400, 401, etc., and fill group icons structure Local $iCount = DllStructGetData($tIcon, 'Count') Local $tDir = DllStructCreate($tagNEWHEADER & 'byte[' & (14 * $iCount) & ']') Local $pDir = DllStructGetPtr($tDir) DllStructSetData($tDir, 'Reserved', 0) DllStructSetData($tDir, 'ResType', 1) DllStructSetData($tDir, 'ResCount', $iCount) Local $tInfo, $iSize, $tData, $iID = 400 Local $pIcon = DllStructGetPtr($tIcon) For $i = 1 To $iCount $tInfo = DllStructCreate('byte Width;byte Heigth;byte Colors;byte Reserved;ushort Planes;ushort BPP;dword Size;dword Offset', $pIcon + 6 + 16 * ($i - 1)) $iSize = DllStructGetData($tInfo, 'Size') If Not _WinAPI_UpdateResource($hUpdate, $RT_ICON, $iID, 0, $pIcon + DllStructGetData($tInfo, 'Offset'), $iSize) Then ExitLoop 2 EndIf $tData = DllStructCreate($tagICONRESDIR, $pDir + 6 + 14 * ($i - 1)) DllStructSetData($tData, 'Width', DllStructGetData($tInfo, 'Width')) DllStructSetData($tData, 'Height', DllStructGetData($tInfo, 'Heigth')) DllStructSetData($tData, 'ColorCount', DllStructGetData($tInfo, 'Colors')) DllStructSetData($tData, 'Reserved', 0) DllStructSetData($tData, 'Planes', DllStructGetData($tInfo, 'Planes')) DllStructSetData($tData, 'BitCount', DllStructGetData($tInfo, 'BPP')) DllStructSetData($tData, 'BytesInRes', $iSize) DllStructSetData($tData, 'IconId', $iID) $iID += 1 Next ; Add new RT_GROUP_ICON resource named as "MAINICON" If Not _WinAPI_UpdateResource($hUpdate, $RT_GROUP_ICON, 'MAINICON', 0, $pDir, DllStructGetSize($tDir)) Then ExitLoop EndIf $iError = 0 Until 1 ; Save or discard changes of the resources within an executable file If Not _WinAPI_EndUpdateResource($hUpdate, $iError) Then $iError = 1 EndIf ; Show message if an error occurred If $iError Then MsgBox(BitOR($MB_ICONERROR, $MB_SYSTEMMODAL), 'Error', 'Unable to change resources.') EndIf Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
abberration Posted September 21, 2019 Share Posted September 21, 2019 Ok, I'm feeling generous today. I made the large portion of code into an #include. Here's and example of how you would script with it: #include <WinAPIRes.au3> #include <ChangeIcon.au3> $sIcon = @ScriptDir & "\icon.ico" ; this is the name of your icon $sExe = @ScriptDir & '\photofiltre7.exe' ; this is the name of the executable _ChangeIcon($sIcon, $sExe) ; in this case, you must specify the icon first then the exe The function to change the icon is called _ChangeIcon. Don't forget to download the #include attachment otherwise it won't work. ChangeIcon.au3 Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
Terenz Posted September 21, 2019 Author Share Posted September 21, 2019 (edited) Thanks but maybe i wasn't clear... Which seems the good one for my goal but if fail on ReadFile (return 0, but the handle is present ) an autoit compiled icon to another one I have try with with UPX or not, Always fail Edited September 21, 2019 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Nine Posted September 21, 2019 Share Posted September 21, 2019 Retested with x64 compile script to modify icon of another x86 compile script, works perfectly. There must be something wrong on you side @Terenz “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
abberration Posted September 21, 2019 Share Posted September 21, 2019 I think he's having trouble expressing exactly what the problem is. I think he's trying to change out icons on multiple executables and is getting an error if one is missing. I am confused because he is sometimes using the word icon where he meant exe. Terenz, can you try to explain it by using an example or a list of your files? Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
Terenz Posted September 21, 2019 Author Share Posted September 21, 2019 (edited) A list of what? I'll take a script with MsgBox, i'll compile, i'll try to change the icon. Fail on ReadFile funciton, return 0. There is nothing wrong on my side, i'm using a fresh VM @Jos if i'm using this: The resource will be updated but the exe doesn't work anymore Edited September 21, 2019 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
Developers Jos Posted September 21, 2019 Developers Share Posted September 21, 2019 23 minutes ago, Terenz said: A list of what? I'll take a script with MsgBox, i'll compile, i'll try to change the icon. Fail on RedFile funciton, return 0. There is nothing wrong on my side, i'm using a fresh VM That sounds like the right attitude to get your issue sorted. Good luck with that. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Terenz Posted September 21, 2019 Author Share Posted September 21, 2019 (edited) @Jos can you please check it out my previous post? Your script work on change the icon but corrupt in some way the EXE, with or without UPX. It doesn' start anymore. I don't have any AV on the machine. Thanks P.S. I don't have understand the "attitude", english isn't my motehr language Edited September 21, 2019 by Terenz Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
abberration Posted September 21, 2019 Share Posted September 21, 2019 Now I understand. I thought my script was giving you an error. I just created a msgbox and compiled as x86 and x64. Then I changed the icon. Both msgbox work fine. All I can say is try it on a different computer. Also, you might want to disable your antivirus while testing. Good luck. Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
Developers Jos Posted September 21, 2019 Developers Share Posted September 21, 2019 (edited) Don't use an 11 years old script and expect that to work. Autoit3wrapper has quite a bit evolved since then. Jos Edited September 21, 2019 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nine Posted September 21, 2019 Share Posted September 21, 2019 2 hours ago, Terenz said: There is nothing wrong on my side Denial is not your best friend... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now