Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling binary files
#1
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
#2
To search binary data, use findb().

Code:
Copy      Help
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
#3
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
#4
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
Code:
Copy      Help
str s.getfile("$desktop$\a.bin")
out s

;search
int i=findb(s "55AA")
out i
#5
out prints until the first [0] character. To print binary use outb.

Code:
Copy      Help
str s="AB CD"
s[2]=0
out s
outb s s.len 1
#6
thank you!
#7
powershell code: How to get code to its equivalent QM code?
 
Code:
Copy      Help
# 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
Code:
Copy      Help
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")


Forum Jump:


Users browsing this thread: 1 Guest(s)