[GH-ISSUE #723] Unify rar2john and rar5tojohn #364

Closed
opened 2026-10-14 03:03:07 +07:00 by bsakaguchi · 12 comments
Owner

Originally created by @magnumripper on GitHub (Aug 26, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/723

Originally assigned to: @kholia on GitHub.

We should only have one rar2john (be it python) and it should handle any RAR files we support.

Originally created by @magnumripper on GitHub (Aug 26, 2014). Original GitHub issue: https://github.com/openwall/john/issues/723 Originally assigned to: @kholia on GitHub. We should only have one rar2john (be it python) and it should handle any RAR files we support.
bsakaguchi 2026-10-14 03:03:07 +07:00
Author
Owner

@jfoug commented on GitHub (Nov 26, 2014):

Does the current rar2john (exe) handle all rar types? I see that the python script does not. Why are we so hell bent to put out python for these conversion projects?

<!-- gh-comment-id:64506531 --> @jfoug commented on GitHub (Nov 26, 2014): Does the current rar2john (exe) handle all rar types? I see that the python script does not. Why are we so hell bent to put out python for these conversion projects?
Author
Owner

@kholia commented on GitHub (Nov 26, 2014):

rar5tojohn.py only supports RAR 5 archives. rar2john.c only supports RAR 3.x archives.

Python is really fun, productive, and easy for doing such stuff.

<!-- gh-comment-id:64508541 --> @kholia commented on GitHub (Nov 26, 2014): `rar5tojohn.py` only supports RAR 5 archives. `rar2john.c` only supports RAR 3.x archives. Python is really fun, productive, and easy for doing such stuff.
Author
Owner

@jfoug commented on GitHub (Nov 26, 2014):

Does anyone have heartburn if I add rar5 to the rar2john project ?

<!-- gh-comment-id:64665874 --> @jfoug commented on GitHub (Nov 26, 2014): Does anyone have heartburn if I add rar5 to the rar2john project ?
Author
Owner

@magnumripper commented on GitHub (Nov 26, 2014):

That would be great. For some reason Solar prefers C too.

<!-- gh-comment-id:64696507 --> @magnumripper commented on GitHub (Nov 26, 2014): That would be great. For some reason Solar prefers C too.
Author
Owner

@jfoug commented on GitHub (Nov 26, 2014):

Got a start. Appears pretty trivial. Should I reduce the complexity of the rar3 stuff also? There are several things that should have been done procedurally, vs tons of inline stuff. It would not 'need' to change, but I think it can be made quite a bit simpler. But first, I will work on putting rar5 into rar2john (incouding sfx support, but I doubt sfx is used too much).

<!-- gh-comment-id:64703885 --> @jfoug commented on GitHub (Nov 26, 2014): Got a start. Appears pretty trivial. Should I reduce the complexity of the rar3 stuff also? There are several things that should have been done procedurally, vs tons of inline stuff. It would not 'need' to change, but I think it can be made quite a bit simpler. But first, I will work on putting rar5 into rar2john (incouding sfx support, but I doubt sfx is used too much).
Author
Owner

@magnumripper commented on GitHub (Nov 26, 2014):

Yeah I'm a bit ashamed of some of the rar2john stuff. It grew organically as I figured stuff out and then I never cleaned it up.

<!-- gh-comment-id:64722560 --> @magnumripper commented on GitHub (Nov 26, 2014): Yeah I'm a bit ashamed of some of the rar2john stuff. It grew organically as I figured stuff out and then I never cleaned it up.
Author
Owner

@jfoug commented on GitHub (Nov 27, 2014):

POC code.

dc6f481

I have not cleaned up anything, NOR is this code completed. It works on the simple test files I have provided but I am 99% sure it has more work needing done.

It would be nice to support solid files also (since that is pretty much a default mode??) but I do not think the program does this now. The rar5 was just a port from the python code (and not complete), but enough that my simple test files worked.

Keep this issue open, there is more work left, and we can get it looking better than it looks now. We should at a minimum have it able to walk the directory structure of pretty much any rar file before we call it good, probably hide some of the debugging output, and see if handing solid is an option (likely not, but possibly there is a lib that would allow us to do that).

I have family coming over to my house for the next few days. Only 2 extra now (my parents), but there will be 13 adults, and 5 kids, so I am not sure how much time I will have. On the other hand, with that many ppl, I may simply want to lock myself in my office to escape, lol.

<!-- gh-comment-id:64808456 --> @jfoug commented on GitHub (Nov 27, 2014): POC code. dc6f481 I have not cleaned up anything, NOR is this code completed. It works on the simple test files I have provided but I am 99% sure it has more work needing done. It would be nice to support solid files also (since that is pretty much a default mode??) but I do not think the program does this now. The rar5 was just a port from the python code (and not complete), but enough that my simple test files worked. Keep this issue open, there is more work left, and we can get it looking better than it looks now. We should at a minimum have it able to walk the directory structure of pretty much any rar file before we call it good, probably hide some of the debugging output, and see if handing solid is an option (likely not, but possibly there is a lib that would allow us to do that). I have family coming over to my house for the next few days. Only 2 extra now (my parents), but there will be 13 adults, and 5 kids, so I am not sure how much time I will have. On the other hand, with that many ppl, I may simply want to lock myself in my office to escape, lol.
Author
Owner

@magnumripper commented on GitHub (Nov 27, 2014):

There are some very odd decoding stuff implemented for RAR3 (with help from that technote iirc) for parsing non-ASCII filenames correctly. I wonder if that also applies to RAR5. But my guess is it only uses UTF-8 now, or possibly UTF-16.

BTW speaking of var sized fields, that encoding is also for space saving iirc so maybe it's still used.

Edit: the function in rar2john is DecodeFileName() and it's not from the tech note but derived from unrar's encname.cpp

<!-- gh-comment-id:64828607 --> @magnumripper commented on GitHub (Nov 27, 2014): There are some very odd decoding stuff implemented for RAR3 (with help from that technote iirc) for parsing non-ASCII filenames correctly. I wonder if that also applies to RAR5. But my guess is it only uses UTF-8 now, or possibly UTF-16. BTW speaking of var sized fields, that encoding is also for space saving iirc so maybe it's still used. _Edit: the function in rar2john is DecodeFileName() and it's not from the tech note but derived from unrar's encname.cpp_
Author
Owner

@jfoug commented on GitHub (Nov 28, 2014):

The variable sized ints (7 bits value per byte), is a huge savings. Yes, it takes 10 bytes to encode a full width 64 bit number, but how many of those are going to be seen? Most of these vint numbers are used for encoding lengths. A lot of items are 100k or less (many less than 10k). If you need to handle 64 bit values, then a flat encoding would use 8 bytes for all. So something like 126000 would take 8 bytes encoded with flat 64 bit value. But encoded with variable numbers, it only would take 3 bytes. a vint is a string of 7 bit ints, with the high bit reserved as 'continuation'. So to encode, simply convert the number into base-128, and set the high bit. The vint's from rar are LE, BUT can be preceded with 0x80 (i.e. 0 padded). The byte that signifies that the number is complete does not have high bit set. So for 126000,

$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
obase=128
126000
 007 088 048

so (7_128+88)_128+48 == 126000 The vint bytes would be (48|128), (88|128), 7

Here is the current code in rar2john to decode them (note, I need to switch to using uint64's, and the looping has to be from 0 to 10, but have not done so yet)

int read_vuint32 (FILE *fp, uint32_t *n, uint32_t *bytes_read) {
    unsigned char c;
    int i, shift=0;
    *n = 0;
    for (i = 0; i < 4; ++i) {
        if (fread(&c, 1, 1, fp) != 1)
            return 0;
        *n = *n + ( (c&0x7F) << shift);
        shift += 7;
        if ((c & 0x80) == 0) {
            *bytes_read += i+1;
            return i+1;
        }
    }
    return 0;
}
<!-- gh-comment-id:64883300 --> @jfoug commented on GitHub (Nov 28, 2014): The variable sized ints (7 bits value per byte), is a huge savings. Yes, it takes 10 bytes to encode a full width 64 bit number, but how many of those are going to be seen? Most of these vint numbers are used for encoding lengths. A lot of items are 100k or less (many less than 10k). If you need to handle 64 bit values, then a flat encoding would use 8 bytes for all. So something like 126000 would take 8 bytes encoded with flat 64 bit value. But encoded with variable numbers, it only would take 3 bytes. a vint is a string of 7 bit ints, with the high bit reserved as 'continuation'. So to encode, simply convert the number into base-128, and set the high bit. The vint's from rar are LE, BUT can be preceded with 0x80 (i.e. 0 padded). The byte that signifies that the number is complete does not have high bit set. So for 126000, ``` $ bc bc 1.06.95 Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. obase=128 126000 007 088 048 ``` so (7_128+88)_128+48 == 126000 The vint bytes would be (48|128), (88|128), 7 Here is the current code in rar2john to decode them (note, I need to switch to using uint64's, and the looping has to be from 0 to 10, but have not done so yet) ``` C int read_vuint32 (FILE *fp, uint32_t *n, uint32_t *bytes_read) { unsigned char c; int i, shift=0; *n = 0; for (i = 0; i < 4; ++i) { if (fread(&c, 1, 1, fp) != 1) return 0; *n = *n + ( (c&0x7F) << shift); shift += 7; if ((c & 0x80) == 0) { *bytes_read += i+1; return i+1; } } return 0; } ```
Author
Owner

@jfoug commented on GitHub (Nov 28, 2014):

big bug in rar2john.c (rar5). Outputting a size value, and not the iteration count. Fixed in 222870e

<!-- gh-comment-id:64920963 --> @jfoug commented on GitHub (Nov 28, 2014): big bug in rar2john.c (rar5). Outputting a size value, and not the iteration count. Fixed in 222870e
Author
Owner

@jfoug commented on GitHub (Nov 28, 2014):

I think it is done now. Original rar2john code not changed much, except for:

memmem looks for all 7 bytes, not just rar! which is the first 4.

We always call rar5_file if we do not find the rar3 signature. Before, even though sfx code was added to rar5_file, it would never have been called, if the file did not start with 8 byte rar5 signature.

some debugging output muted (unless DEBUG set)

fp was NOT being set to null during rar5 check. So a non-rar5 file would have had a double file close (i..e core).

c8db452

<!-- gh-comment-id:64931938 --> @jfoug commented on GitHub (Nov 28, 2014): I think it is done now. Original rar2john code not changed much, except for: memmem looks for all 7 bytes, not just rar! which is the first 4. We always call rar5_file if we do not find the rar3 signature. Before, even though sfx code was added to rar5_file, it would never have been called, if the file did not start with 8 byte rar5 signature. some debugging output muted (unless DEBUG set) fp was NOT being set to null during rar5 check. So a non-rar5 file would have had a double file close (i..e core). c8db452
Author
Owner

@jfoug commented on GitHub (Nov 28, 2014):

fb4fcdc moved rar5tojohn.py to unused.

<!-- gh-comment-id:64932113 --> @jfoug commented on GitHub (Nov 28, 2014): fb4fcdc moved rar5tojohn.py to unused.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#364
No description provided.