Posts: 175
Threads: 43
Joined: Jun 2004
I need to read, search, and extract a binary file's contents. The file contains many 0x00 chars. The string and file functions seem to think this is the end of the file so never read to the end. Is there anyway to handle this in QM. Thanks.
Matt B
Posts: 12,095
Threads: 142
Joined: Dec 2002
To search binary data, use findb().
str s.getfile("$qm$\system.qml")
;search
int i=findb(s "OpenSaveDialog")
out i
;replace all 0 to 1
for(i 0 s.len) if(s[i]=0) s[i]=1
out s
Duh, how dumb of me.:oops: If at first you don't succede read the directions.
Thanks thats what I needed . Your support is amazing.
Matt
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-06-2023, 04:39 AM
(This post was last modified: 10-06-2023, 04:40 AM by Davider.)
The variable
s prints as empty, Why?
I want to replace 55AA with FFFF
https://i.ibb.co/wRhZDr4/456.png
File: a.bin
https://workupload.com/file/mBmP3zeeckg
Macro
Macro22
str s.getfile("$desktop$\a.bin")
out s
;search
int i=findb(s "55AA")
out i
Posts: 12,095
Threads: 142
Joined: Dec 2002
10-06-2023, 05:10 AM
(This post was last modified: 10-06-2023, 05:12 AM by Gintaras.)
out prints until the first [0] character. To print binary use outb.
str s="AB CD"
s[2]=0
out s
outb s s.len 1
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-06-2023, 06:04 AM
(This post was last modified: 10-06-2023, 11:18 AM by Davider.)
thank you!
Posts: 1,049
Threads: 249
Joined: Jul 2022
10-06-2023, 11:08 AM
(This post was last modified: 10-06-2023, 11:18 AM by Davider.)
powershell code: How to get code to its equivalent QM code?
# Read the content of the binary file
$fileContent = [System.IO.File]::ReadAllBytes("$HOME\desktop\a.bin")
# Find and replace specific bytes
for ($i = 0; $i -lt $fileContent.Length - 1; $i++)
{
if ($fileContent[$i] -eq 0x55 -and $fileContent[$i + 1] -eq 0xAA)
{
$fileContent[$i] = 0xFF
$fileContent[$i + 1] = 0xFF
}
}
# Write the modified content back to the file
[System.IO.File]::WriteAllBytes("$HOME\desktop\b.bin", $fileContent)
solved. The QM code looks simpler and more elegant.
Macro
Macro18
str s.getfile("$desktop$\a.bin")
for(_i 0 s.len)
,if s[_i]=0x55 and s[_i+1]=0xAA
,,s[_i]=0xFF
,,s[_i+1]=0xFF
s.setfile("$desktop$\b3.bin")