Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER General Discussion Forum

Reply
 
Thread Tools Display Modes
Old 04-07-2024, 04:34 PM   #1
iMisspell
Human being with feelings
 
Join Date: Oct 2018
Posts: 2
Default [Solved] Reading "serialize" data from the .rpp project file using python ?

How do you read "serialize" data from the .rpp project file from python ?

Trying to read data from the .rpp project file which JS Notepad has saved to.
Tale's JS-Notepad code https://forums.cockos.com/showpost.p...2&postcount=15

Here's what im trying to read:
Code:
      <JS_SER
        AACcQk4AAABwLWJhc3MsIHJvdW5kIHdvdW5kcywgbG93IHBpY2t1cHMsIHZvbCBhbmQgdG9uZSAxMDAgJiBuYXBraW4gYXQgYnJpZGdlIHRvIG11dGVIvw==
      >
The closest ive come is with the following:
Open the file with...
Code:
with open(reaper_rpp_file, 'r') as content_file:
    reaper_content = content_file.read()
get the chunk of data i want from '<JS_SER'
pass that though
Code:
            decoded = base64.b64decode(str_JS_SER)
            decoded = decoded.decode('cp1258')
which gets close, but there's still other bytes, beginning and end of the string which are not the correct text.

Ive tried different encode's, cp1258 seams to work the best, also tried with skipping errors, but still do not get the correct results.
Code:
decoded = decoded.decode('utf-8', errors='ignore')
the results im getting...
Code:
œBNp-bass, round wounds, low pickups, vol and tone 100 & napkin at bridge to muteH¿
and
¶B&white - round wounds, vol 85, tone 950 a
should be
Code:
p-bass, round wounds, low pickups, vol and tone 100 & napkin at bridge to mute
and
white - round wounds, vol 85, tone 95

Im a bit new to the coding side of reaper, so any help would be great.
Thanks...

_

Last edited by iMisspell; 04-07-2024 at 09:19 PM. Reason: edited title to solved
iMisspell is offline   Reply With Quote
Old 04-07-2024, 08:03 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,964
Default

Code:
@serialize
file_var(0, len);
file_string(0, buf);
Data is 32-bit float (len) + 32-bit int (buf_len) + buf_bytes. There's an additional 2 bytes, seems like garbage to pad the total payload size to be a multiple of 4.

Lua:
Code:
local data = select(2, reaper.NF_Base64_Decode('AACcQk4AAABwLWJhc3MsIHJvdW5kIHdvdW5kcywgbG93IHBpY2t1cHMsIHZvbCBhbmQgdG9uZSAxMDAgJiBuYXBraW4gYXQgYnJpZGdlIHRvIG11dGVIvw=='))
local len, buf = string.unpack('fs4', data)
print(len, buf)


In Python that would be struct.unpack, but it lacks an equivalent for 's4' (read 4 bytes int string length, then that many bytes as a string). netstruct has it:

Code:
import base64
import netstruct
data = base64.b64decode('AACcQk4AAABwLWJhc3MsIHJvdW5kIHdvdW5kcywgbG93IHBpY2t1cHMsIHZvbCBhbmQgdG9uZSAxMDAgJiBuYXBraW4gYXQgYnJpZGdlIHRvIG11dGVIvw==')
(len, buf) = netstruct.unpack(b'<fi$', data)
print(len, buf)

Last edited by cfillion; 04-07-2024 at 08:33 PM.
cfillion is offline   Reply With Quote
Old 04-07-2024, 09:18 PM   #3
iMisspell
Human being with feelings
 
Join Date: Oct 2018
Posts: 2
Default

Thank you, cfillion, this worked great.
iMisspell is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:24 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.