Code: Select all
SetFormat, Integer, Hex
string:=5041544348 ; sorry misleading name, it's really just supposed to be a literal raw value represented in hex
MsgBox % string
myfile:=FileOpen("Test.bin", 0x1) ; edit, oops, meant to have 0x1 here to always overwrite the test file
myfile.RawWrite(string,10)
return
What it's outputting to the test.bin file is---------------------------
writefiletesting.ahk
---------------------------
0x12C7FDC9C
---------------------------
OK
---------------------------
As viewed in a hex editor. That is interpreted as 0.x.5.0.4. ... not what I want.30 00 78 00 35 00 30 00 34 00
What I want, of course, is it to have the hex editor open the file and show me the original value 5041544348
What's gone wrong is AHK assumes my string as is in the .ahk file is in decimal, when it's literally hex. So, I would have thought using string:=0x5041544348 would fix that? It does make the MsgBox say 0x50415444348 but it doesn't change the test.bin output.
I feel like it should be super obvious. Maybe once I ever stumble across an example, it will jive with me. All the past hour of search results get me a mix of answers from 15-5 years ago with far more complex functions than I would have thought necessary.
I wanted to use AHK to whip up a GUI to craft together bits and pieces of a hex file. But I may turn to just finding some linux terminal solutions. It's really easy in such a terminal to write out the hex I want, just not as pleasant to go through all the options in crafting that output. Old notes I have say it should be as simple as echo "50 41 54 ..." | xxd -r -p - AnyName.bin.
Hypothetically I could at least still use AHK to whip up the string of hex values, save to a .txt file, and open up the text file and use echo upon the text file. Cumbersome though to reboot the computer to flip OSes, hoped I could get everything done in just Windows. (Well, I can run a virtual machine I suppose, still a hassle.)