-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rar file pattern as requested in #258 #324
Conversation
Removed some experimental (and apperantly broken) code.
Not sure why unit tests of other patterns suddenly fail, my |
Thanks a lot! The CI errors were my fault, sorry. I restarted the CI again now and it should hopefully pass |
About your questions, Issue 1: bitfield Test {
field1 : 3;
field2 : field1;
}; Issue 2: |
Thanks for the suggestions :) Issue 1: I don't think this approach will work. The vint implementation is a little more complex. The MSBit is basically a continue indicator. As long as that bit is set, we need to read another byte. Then for the actual integer value we have to mask out the continuation bits and do some shifting. Only then, does this computed value act as a bitfield. You can see the decoding implementation in line 33. So the problem is that I have a computed value (currently managed via both a Issue 2: That's useful, I think. :) Implemented it. |
There's not a very nice way to do it currently but here is one way. This uses the uLEB128 type since it works similar to your vint type. The import type.leb128;
type::uLEB128 value @ 0x00;
bitfield MyBitfield {
a : 1;
b : 2;
c : 3;
padding : 58;
};
std::mem::Reinterpreter<u64, MyBitfield> reinterpreter;
reinterpreter.from_value = value;
std::print("{}", reinterpreter.to_value); |
The vint defined in the rar documentation is really uLEB128. For some reason they don't call it that but the definition is identical. Also the rar template in 010 uses uLEB128 instead of vint. |
This will complicate things, but the proposed pattern only works for newer RAR5 archives, which even though it was introduced in 2013, there is still a lot of RAR files floating around using the older format. After a bit of digging to find any documentation on the older format I found this document that was listed on the format description from the Library of Congress. |
I don't know the spec super well but if it's too much work to implement full support right now, feel free to just add an |
…#324) * Add rar file pattern as requested in WerWolv#258 * Fix rar pattern Removed some experimental (and apperantly broken) code. * Break on EndOfArchive header instead of EOF --------- Co-authored-by: Nik <[email protected]>
Pattern
The RAR file format as defined in the official documentation (https://www.rarlab.com/technote.htm). This pattern was requested in #258 .
There are still some issues I'd like to resolve, but I'm not versed enough in the pattern language to do so. I need some help here.
Issue 1: I have multiple cases where they have used a variable-length integer with certain bits indicating certain things. In some cases I got away with just using a fixed size bitfield, because the fields effectively were fixed width (at least with the linux rar implementation). In case of line 295 I did observe the field having variable width. I know of no way to cast the computed value of a
vint
into a bitfield. Maybe I'm missing a feature of the pattern language or it simply isn't possible.Issue 2: As stated in line 360 I'd prefer to read headers until I reach a specific header, rather than end of file. This would allow for successful extraction of embedded rar files. Again, I don't know how to do this. Sadly, there is no absolute archive size anywhere that I could use instead.
Checklist
#pragma description My pattern Description here
)#pragma MIME mime-type
in the source code)application/octet-stream
here as that means "Unidentifiable binary data"PS
FYI: I'm not sure why, but Github didn't load the PR template, I copy-pasted it manually.