Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Problems trying to understand the format #9

Closed
JakubKoralewski opened this issue May 27, 2020 · 2 comments
Closed

Problems trying to understand the format #9

JakubKoralewski opened this issue May 27, 2020 · 2 comments

Comments

@JakubKoralewski
Copy link

I'm curious, how you reversed engineer this, and I'm taking a look at a project file but the header parsing doesn't seem right to me.

The highlighted part in the image should be equivalent to the 4-byte long Int16 variable named type:

var type = reader.ReadInt16();
if (type != 0) throw new FlParseException($"Type {type} is not supported", reader.BaseStream.Position);

image

Seems like the type variable is not being parsed the way it should be, and would throw a wrong type error for this project file?

I'm a bit of a noob in reverse engineering, am I understanding correctly? Is this project file too new a version, corrupted or am I just mistaken?

@cpdt
Copy link
Member

cpdt commented May 28, 2020

Hey, I think you might've made a mistake, that line should be reading the 08/09 bytes:

if (Encoding.ASCII.GetString(reader.ReadBytes(4)) != "FLhd")
throw new FlParseException("Invalid magic number", reader.BaseStream.Position);

This will read the first 4 bytes, 00-03.

// header + type
var headerLength = reader.ReadInt32();
if (headerLength != 6)
throw new FlParseException($"Expected header length 6, not {headerLength}", reader.BaseStream.Position);

This will read the next 4 bytes, 04-07 (Int32 is four bytes).

var type = reader.ReadInt16();
if (type != 0) throw new FlParseException($"Type {type} is not supported", reader.BaseStream.Position);

So this will then read bytes 08-09 (Int16 is only two bytes).

As for how it was reverse engineered, the basic parsing structure and some of the "event types" were from andrewrk's Node FL parser library (which is very out of date now) and the rest was just from changing different values in FL and seeing what changed. As far as I'm aware his library was based on an old implementation in LMMS (which doesn't exist anymore afaik) which was based on an old thread somewhere (which I haven't been able to find again) where an Image-Line employee talked about the basic structure.

I'll close this thread for now, but if you have any other questions please feel free to ask them!

@cpdt cpdt closed this as completed May 28, 2020
@JakubKoralewski
Copy link
Author

JakubKoralewski commented May 28, 2020

I see it now, I somehow mistook a byte for 4 bits 😄.
Thanks for the patience and the detailed answer.

github.com/LMMS/lmms/pull/2904
Seems like it was a licensing problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants