How to change windows exe file's icon in linux without wine? - linux

I know I can use ResHacker to change a resource from windows and I know I can use ResourceUpdate function to do the same problematically (again in windows). My problem is that I have to update the icon of a windows exe file in linux, without using wine.
(the reason for not using wine is that this process should run on an automation server that change the files and sign them).
I don't know even where to start from.

You can change a files metadata like this:
gvfs-set-attribute '/path/to/file' -t stringv metadata::custom-icon "/path/to/image.png"

There's a program called windres that should suit your needs
Whoops, that's just a resource compiler, sorry.
However there is pefile a python module for working with PE executables, perhaps you could write a script with it that does what you want

Related

How do I get a portable installation of the Rust programming language?

I've been trying to get a windows installation on a flash drive for a while now.
Since this question comes up first in the search engine when I searching for installing Rust on a pen drive. I'll answer it.
Installing on pen drive makes sense on Windows, if you want to carry the installation with you.
Download rustup-init.exe from the official Rust page (you probably want the 64 bit one nowadays).
set RUSTUP_HOME and CARGO_HOME environment variables to point to a location on your pen drive.
When you start it will echo back these environment variables. To let you verify it.
When asked tell it to customize install.
I have portable MinGW on my pen drive so I have chosen x86_64-pc-windows-gnu as the host triplet to install.
Tell it to not to alter your PATH, instead have a BAT script that you can start to set these vars for the shell.
I have a BAT script on the pen drive to ensure the PATHs are right despite what drive letter gets assigned, such as this:
set DRIVE=%CD:~0,2%
set MINGW_PATH=%DRIVE%\!\Mingw64\mingw64\bin
set GIT_PATH=%DRIVE%\!\PortableGit\cmd
set VSCODE_PATH=%DRIVE%\!\VSCode
set RUSTUP_HOME=%DRIVE%\!\Rust\rust
set CARGO_HOME=%DRIVE%\!\Rust\cargo
set RUST_PATH=%CARGO_HOME%\bin
And when you plug in the pen drive to a different computer, then after the install run this bat to have the paths.
Notice: note that this way can not use in ExFAT filesystem. Please see this issues
Something like https://www.codejam.info/2015/03/portable-rust-installation.html might work? Possibly with putting the profile script on the drive to be run after inserting? Also, is this for Linux, Windows or something else?
First, get the binaries according to your system, and the Rust version
you want. For me (nightly 64-bit Linux binaries) and extract the
archive (I like to put it in ~/opt):
wget https://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz
tar xf rust-nightly-x86_64-unknown-linux-gnu.tar.gz
mv rust-nightly-x86_64-unknown-linux-gnu rust
Then, just export the appropriate environment variables (do this from
your ~/.profile or equivalent to have it set up automatically). No
need to install anything globally!
export LD_LIBRARY_PATH=~/opt/rust/rustc/lib:$LD_LIBRARY_PATH
export PATH=~/opt/rust/rustc/bin:~/opt/rust/cargo/bin:$PATH

x64 Portable executable not working

I created an exact replica of this file in a hex editor: https://i.imgur.com/LIImg.jpg
The problem is, the .exe file I made from it doesn't work, it says it's an invalid Win32 application when trying to run it. Is there something flawed in it? I've checked and double checked my file...
I'm not sure where I can host an exe file but I can email it if someone else wants to check it.
I should also mention I'm running Windows 7 64-bit.
The PE binary file from that illustration is already available here from the author, Ange Albertini. I have tested it both on Windows 7 and Windows 8/8.1, and it runs just fine, so you can use it for comparison with your binary.
In case anyone was wondering, the difference between the image and the executable is that there has to be 0's at the end of the file to match the section size. It doesn't work without that.

Set a Windows exe icon from Linux (without Wine ?)

I'm trying to set a Windows executable icon with a Bash script in Linux, but I can't find anything relevant.
I have found this tool www.nongnu.org/icoutils, but it seems to me that you can only extract .ico file from the executable (then convert it into png), or do the opposite: it takes pngs and it creates an .ico BUT it can't write the new ico into the executable.
Am I right or wrong ? What should I do ?
By the way, I've found this thread and this one, but they do not fully answer the question...
Thanks !
One way would be to use Resource Hacker with wine.
Therefore,
install wine
download Resource Hacker
install Resource Hacker with wine (or wine32 if you are on 64bit):
$ wine32 /path/to/reshack_setup.exe
change icon:
$ wine32 .wine/drive_c/Program\ Files/Resource\ Hacker/ResHacker.exe -addoverwrite "oldexe.exe,new.exe,new.ico,ICONGROUP,MAINICON,0"
This worked for me on a few .exe files. It also failed on one, i don't know why.
Hope this helps!

I've downloaded an .exe file but it closes quickly as it opens

I am trying to open a downloaded .exe file but it closes as soon as it opens. Is there any possible way so that I can open it for a longer duration to read the content.
It's probably a console application rather than a GUI application. Use the command prompt to run the .exe.
Do the following...
Hold down your Windows key on your keyboard and then tap "R".
This will bring up the Run dialog. Type in "cmd" (without the quotes). Hit enter.
(this will work in all Windows versions - browsing the start menu/screen differs in each version)
If you saved the file to c:\downloads and it's called myFile.exe, type
C:
cd C:\Downloads
myFile.exe
Some of the steps are a bit redundant - if you know what you're doing in the command prompt then skip as needed (but then you probably wouldn't be posting this question). This will work even if you saved the file to D:\downloads.
Another example - if you saved the file to D:\folderA\Folder with a space\ and the file is called "my file with a space.exe" then type
D:
cd "D:\folderA\Folder with a space"
"my file with a space.exe"
If there is an issue (eg it's a 64-bit executable and you're on 32-bit Windows) then you may get a better error message at the command line.
There are so many reasons why the executable does not run. Here are some ways to check what is going wrong:
Is it your .exe? Do you known the "normal" behavior?
When you download it manually, it the result the same?
Do you download the .exe manually or via your application?
Do you see any problem in your Windows Event Viewer?
Is it the same result if you try to download the .exe via different browsers (IE, FF, ...)?
More details are welcome!
The nuget.exe file is not a console GUI application but rather a console package. Once you've downloaded it, you'll want to place it in a folder outside your Downloads folder. For example, C:\NuGet\nuget.exe - then set it as a PATH variable so that it's executable from anywhere.

Error installing cab file on Windows CE

I'm having trouble using macros in my .inf file that I'm using to create my cab, specifically when setting the InstallDir string. If I do something like this:
InstallDir=\<PathToProgramFiles>\MyAppName
then everything works fine. However, if I do this:
InstallDir=%CE1%\MyAppName
then I get the following error when trying to install the cab (double tapping it on my device): "MyAppName was not installed successfully. Please run Setup again."
This only seems to apply to the built-in macro strings. I can use %AppName% without any problems. Maybe there is some registry setting that isn't properly set that would normally resolve the %CE1% macro?
Any ideas about what is going on?
Edit: My device doesn't have a \Program Files directory. It seems the %CE1% macro always resolves to that path and if the InstallDir specified in the inf file doesn't exist (with the exception of the last directory portion then the install fails. Manually creating \Program Files fixed the issue. Since a lot of the devices I'm working with have different paths for their Program Files directory, is there a generic way to get the installer to default to the actual Program Files dir? I guess my only other option is to not specify a path and force the user to choose one?
First, in this link you can find the shortcuts and their meaning (the %C..%), goto appendix B. The Windows CE5 MSDN link.
You can add a Setup Dll to your CAB installaer that will check the directory structure and will create a folder in case it does not exist. You may find this SO question useful.
A warning: If you are targeting regular Windows CE devices, beware where you place the files as it can be to a RAM based file system and then the files will disappear after reboot.

Resources