pax_global_header00006660000000000000000000000064133461706410014517gustar00rootroot0000000000000052 comment=480880338ed4b1d52b118bc1247d725bc7fa0d01 recoverjpeg-2.6.3/000077500000000000000000000000001334617064100140425ustar00rootroot00000000000000recoverjpeg-2.6.3/.gitignore000066400000000000000000000002161334617064100160310ustar00rootroot00000000000000aclocal.m4 autom4te.cache config.log config.status configure depcomp .deps install-sh Makefile Makefile.in missing *.o recoverjpeg recovermov recoverjpeg-2.6.3/.indent.pro000066400000000000000000000000121334617064100161140ustar00rootroot00000000000000-npcs -br recoverjpeg-2.6.3/.travis.yml000066400000000000000000000004351334617064100161550ustar00rootroot00000000000000language: cpp sudo: false addons: apt: packages: - pandoc compiler: - gcc - clang env: - CFLAGS=-O2 CXXFLAGS=-O2 - CFLAGS="-O2 -pedantic -Wall -Wextra -Werror" CXXFLAGS="-O2 -pedantic -Wall -Wextra -Werror" - CFLAGS=-O3 CXXFLAGS=-O3 script: support/test-build.sh recoverjpeg-2.6.3/COPYING000066400000000000000000000432541334617064100151050ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. recoverjpeg-2.6.3/Makefile.am000066400000000000000000000000731334617064100160760ustar00rootroot00000000000000AUTOMAKE_OPTIONS = foreign SUBDIRS = src doc scripts tests recoverjpeg-2.6.3/README.md000066400000000000000000000062271334617064100153300ustar00rootroot00000000000000Installation ------------ To install recoverjpeg, run ./configure make sudo make install To use sort-pictures, you need to install: - exif: http://sourceforge.net/projects/libexif - ImageMagick: http://www.imagemagick.org/ Usage ----- Look at the manual pages for recoverjpeg(1), recovermov(1) and sort-pictures(1). What to do if the medium is physically damaged? ----------------------------------------------- Mike Ingle wrote about working with a drive that cannot be read because of errors: > The hard drive was more complicated because recoverjpeg would abort on the first bad sector it hit. > I tried using a named pipe and that did not work, so I did: > > dd if=/dev/sdc of=recovery-image bs=65536 conv=noerror > > and that made an image file while skipping over the bad blocks without aborting. Then I would end up with a > 500 GByte file which I ran recoverjpeg on, and it worked. Another option suggested by Florian Schmaus is to use the dedicated [ddrescue](http://www.gnu.org/software/ddrescue/ddrescue.html) which may cope with even more desperate situations where multiple passes are needed in order to recover the physical medium content. History ------- recoverjpeg was written on 23 December 2004 after a *huge* mistake: a disk containing pictures was repartitioned and a new operating system was installed on top. recoverjpeg and sort-pictures ran on this 80GB disk and rescued 19222 pictures (11GB): - 9538 pictures sorted by date (a few of them were corrupted in a way that no software can detect as they are valid JFIF files) and taken on 337 different days - 1310 JFIF files without date (some of them were correct pictures whose exif data had been corrupted) - 8301 JFIF files too small to be digital pictures (no error there, most of them were thumbnails of real pictures previously made by software such as gqview) - 71 invalid JFIF files - 4 pictures recorded at a date of 0000-00-00 (probably a bug in the camera used to take the pictures) Of course, I had a backup of everything, but I cannot seem to remember where I put it. On January 2010, Jan Funke added the recovermov(1) program to the package to recover lost movies. On April 2012, Samuel Tardieu added the -d option to recoverjpeg(1) to circumvent arbitrary limits set on the number of files per directory on certain limited filesystems. Also, support of compilation with clang(1) was added. Portability ----------- You need to ensure that the off_t type from the C library and the lseek() function support offsets of at least the size of the device you want to recover pictures from. Contact information ------------------- Home page: Authors: - [Jan Funke](mailto:jan.funke@inf.tu-dresden.de) - [Samuel Tardieu](https://rfc1149.net/) Development ----------- If you got this software using your revision control tool, you can build the autogenerated files by using: autoreconf --install Thanks ------ The following beta-testers and contributors are warmly thanked: - Olivier Beyssac - Pierre Beyssac - Bertrand Petit - Dunc recoverjpeg-2.6.3/configure.ac000066400000000000000000000004471334617064100163350ustar00rootroot00000000000000AC_INIT([recoverjpeg], [2.6.3]) AC_CONFIG_SRCDIR([src/recoverjpeg.c]) AC_CONFIG_AUX_DIR([support]) AC_CONFIG_MACRO_DIR([support]) AM_INIT_AUTOMAKE AC_CONFIG_HEADER([config.h]) AC_PROG_CC AC_PROG_CXX AC_CONFIG_FILES([Makefile src/Makefile scripts/Makefile doc/Makefile tests/Makefile]) AC_OUTPUT recoverjpeg-2.6.3/doc/000077500000000000000000000000001334617064100146075ustar00rootroot00000000000000recoverjpeg-2.6.3/doc/Makefile.am000066400000000000000000000003021334617064100166360ustar00rootroot00000000000000dist_man_MANS = recoverjpeg.1 recovermov.1 sort-pictures.1 remove-duplicates.1 extra_DIST = recoverjpeg.md recovermov.md sort-pictures.md remove-duplicates.md .md.1: pandoc -s -w man $< -o $@ recoverjpeg-2.6.3/doc/recoverjpeg.md000066400000000000000000000120761334617064100174520ustar00rootroot00000000000000% RECOVERJPEG(1) Recoverjpeg User Manuals % Samuel Tardieu % November 12, 2016 # NAME recoverjpeg - recover jpeg pictures from a filesystem image # SYNOPSIS recoverjpeg [*options*] *device* # DESCRIPTION Recoverjpeg tries to identify jpeg pictures from a filesystem image. To achieve this goal, it scans the filesystem image and looks for a jpeg structure at blocks starting at 512 bytes boundaries. Salvaged jpeg pictures are stored by default under the name *imageXXXXX.jpg* where *XXXXX* is a five digit number starting at zero. If there are more than 100,000 recovered pictures, recoverjpeg will start using six figures numbers and more as soon as needed, but the 100,000 first ones will use a five figures number. Options *-f* and *-i* can override this behaviour. `recoverjpeg` stores the recovered pictures into the current directory. If you want it to store them elsewhere, just go to the directory you want `recoverjpeg` to save the images into (using the `cd` command at the shell prompt) and start `recoverjpeg` from there, or use the *-o* option. Note that *device* is not necessarily a physical device. It may also be a file containing a copy of the faulty device in order to reduce the actual processing time and the stress imposed to an already defective hardware. `dd`(1) or `ddrescue`(1) may be used to create such a working copy. # OPTIONS -h : Display an help message. -b *blocksize* : Set the size of blocks in bytes. On most file systems, setting it to 512 (the default) will work fine as any large file will be stored on 512 bytes boundaries. Setting it to 1 maximize the chances of finding very small files if the filesystems aggregates them (UFS for example) at the expense of a much longer running time. -d *formatstring* : Set the directory format string (printf-style, default: use the current directory). When used, 0 will be used for the 100 first images, 1 for the 100 next images, and so on. The goal of this option is to circumvent the directory size limit imposed by some file systems. -f *formatstring* : Set the file name format string (printf-style, default: "image%05d.jpg"). It is used with the image index as an integer argument. -i *integerindex* : Set the initial index value for image numbering (default: 0). -m *maxsize* : Maximum size of extract jpeg files. If a file would be larger than that, it is discarded. The default is 6 MiB. -o *directory* : Change the working directory before restoring files. Use this option to restore files into a directory with enough space instead of the current directory. This option can be repeated. -q : Be quiet and do not display anything. -r *readsize* : Set the readsize in bytes. By default, this is 128 MiB. Using a large readsize reduces the number of system calls but consumes more memory. The readsize will automatically be adjusted to be a multiple of the system page size. It **must** be greater than the *maxsize* parameter. -s *cutoffsize* : Set the cutoff size in bytes. Files smaller than that will be ignored. -S *skipsize* : Set the number of bytes to skip at the beginning of the filesystem image. This can be used to resume an interrupted session, in conjunction with *-i*. The number of bytes may be rounded down to be a multiple of a memory page size in order to improve performances. -v : Be verbose and describes the process of jpeg identification. By default, if this flag is not used, recoverjpeg will print a progress bar showing how much it has analyzed already and how many jpeg pictures have been recovered. -V : Display program version and exit. All the sizes may be suffixed by a *k*, *m*, *g*, or *t* letter to indicate KiB, MiB, GiB, or TiB. For example, 6m correspond to 6 MiB (6291456 bytes). # EXAMPLES Recover as many pictures as possible from the memory card located in `/dev/sdc`: recoverjpeg /dev/sdc Do the same thing but ignore files smaller than one megabyte: recoverjpeg -s 1m /dev/sdc Recover as many pictures as possible from a crashed ReiserFS file system (which does not necessarily store pictures at block boundaries) in `/dev/sdb1`: recoverjpeg -b 1 /dev/sdb1 Do the same thing in a memory constrained environment where no more than 16MB of RAM can be used for the operation: recoverjpeg -b 1 -r 16m /dev/sdb1 # COPYRIGHT Copyright (c) 2004-2016 Samuel Tardieu . This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. If recoverjpeg saves your day and you liked it, you are welcome to send me the best rescued ones by email (please send only 800x600 versions of the pictures) and authorize me to put them online (indicate which contact information you want me to use for credits). # SEE ALSO `recovermov`(1) `sort-pictures`(1) `remove-duplicates`(1) # KNOWN BUGS Recoverjpeg does not include a complete jpeg parser. You may need to use sort-pictures afterwards to identify bogus pictures. Some pictures may be corrupted but have a correct structure; in this case, the image may be garbled. There is no automated way to detect those pictures with a 100% success rate. recoverjpeg-2.6.3/doc/recovermov.md000066400000000000000000000050061334617064100173210ustar00rootroot00000000000000% RECOVERMOV(1) Recovermov User Manuals % Jan Funke and Samuel Tardieu % November 12, 2016 # NAME recovermov - recover movies from a filesystem image # SYNOPSIS recovermov [*options*] *device* # DESCRIPTION Recovermov tries to identify mov movies from a filesystem image. To achieve this goal, it scans the filesystem image and looks for a mov structure at blocks starting at 512 bytes boundaries. `recovermov` stores the recovered movies into the current directory. If you want it to store them elsewhere, just go to the directory you want `recovermov` to save the movies into (using the `cd` command at the shell prompt) and start `recovermov` from there, or use the *-o* option. Note that *device* is not necessarily a physical device. It may also be a file containing a copy of the faulty device in order to reduce the actual processing time and the stress imposed to an already defective hardware. `dd`(1) or `ddrescue`(1) may be used to create such a working copy. # OPTIONS -h : Display an help message. -b *blocksize* : Set the size of blocks in bytes. On most file systems, setting it to 512 (the default) will work fine as any large file will be stored on 512 bytes boundaries. Setting it to 1 maximize the chances of finding very small files if the filesystems aggregates them (UFS for example) at the expense of a much longer running time. -i *integerindex* : Set the initial index value for image numbering (default: 0). -n *basename* : Basename to use to create the salvaged files. Default is `video_`. -o *directory* : Change the working directory before restoring files. Use this option to restore files into a directory with enough space instead of the current directory. This option can be repeated. -V : Display program version and exit. All the sizes may be suffixed by a *k*, *m*, *g*, or *t* letter to indicate KiB, MiB, GiB, or TiB. For example, 6m correspond to 6 MiB (6291456 bytes). # EXAMPLES Recover as many movies as possible from the memory card located in `/dev/sdc`: recovermov /dev/sdc Recover as many movies as possible from a crashed ReiserFS file system (which does not necessarily store files at block boundaries) in `/dev/hdb1`: recovermov -b 1 /dev/hdb1 # COPYRIGHT Copyright (c) 2010-2016 Samuel Tardieu and Jan Funke . This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # SEE ALSO `recoverjpeg`(1) recoverjpeg-2.6.3/doc/remove-duplicates.md000066400000000000000000000016571334617064100205720ustar00rootroot00000000000000%REMOVE-DUPLICATES(1) User Manuals %Samuel Tardieu %November 12, 2016 # NAME remove-duplicates - remove duplicates of the same file in the current directory # SYNOPSIS remove-duplicate [*-f*] # DESCRIPTION Removes duplicates of the same file in the current directory if *-f* is given. If *-f* is not given, duplicate will be identified twice (once in every direction). # OPTIONS -f # COPYRIGHT Copyright (c) 2004-2016 Samuel Tardieu . This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. If recoverjpeg saves your day and you liked it, you are welcome to send me the best rescued ones by email (please send only 800x600 versions of the pictures) and authorize me to put them online (indicate which contact information you want me to use for credits). # SEE ALSO `recoverjpeg`(1) `sort-pictures`(1) recoverjpeg-2.6.3/doc/sort-pictures.md000066400000000000000000000021741334617064100177600ustar00rootroot00000000000000%SORT-PICTURES(1) User Manuals %Samuel Tardieu %November 12, 2016 # NAME sort-pictures - sort pictures according to exif date # SYNOPSIS sort-pictures # DESCRIPTION Sort-pictures uses the exif tags in jpeg pictures recovered by `recoverjpeg` in directories. It creates hard links to organize sorted pictures. Running sort-pictures will scan the current directory for files named after the template `image?????*.jpg` (`image` followed by at least five characters followed by `.jpg`). A new hardlink will be created for each file in one of the following directories: - *invalid* The picture is an invalid JFIF file. - *small* The picture size is less than 100,000 bytes. - *undated* Sort-pictures was unable to determine the date of the picture from the exif tags. - *YYYY-MM-DD* A directory representing the date at which the picture was taken. # SEE ALSO `recoverjpeg`(1) `remove-duplicates`(1) # COPYRIGHT Copyright (c) 2004-2016 Samuel Tardieu . This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. recoverjpeg-2.6.3/scripts/000077500000000000000000000000001334617064100155315ustar00rootroot00000000000000recoverjpeg-2.6.3/scripts/Makefile.am000066400000000000000000000000631334617064100175640ustar00rootroot00000000000000dist_bin_SCRIPTS = sort-pictures remove-duplicates recoverjpeg-2.6.3/scripts/remove-duplicates000077500000000000000000000014531334617064100211120ustar00rootroot00000000000000#! /usr/bin/python # # Usage: remove-duplicates # # Remove duplicates of the same file in the current directory if -f is # given. # # If -f is not given, duplicate will be identified twice (once in every # direction). # import os def check_duplicate(orig, copy): try: if open(orig).read() == open(copy).read(): print("Removing %s which is a copy of %s" % (copy, orig)) os.unlink(copy) except: pass def aggregate(): d = {} for f in os.listdir('.'): s = os.stat(f)[6] if s in d: d[s].append(f) else: d[s] = [f] return d def remove_duplicates(d): for v in d.values(): while v: del v[0] for c in v[1:]: check_duplicate(v[0], c) if __name__ == '__main__': remove_duplicates(aggregate()) recoverjpeg-2.6.3/scripts/sort-pictures000077500000000000000000000017161334617064100203070ustar00rootroot00000000000000#! /bin/sh # # This file is part of the recoverjpeg program. # Copyright (c) 2004-2016 Samuel Tardieu # http://www.rfc1149.net/devel/recoverjpeg # # recoverjpeg is released under the GNU General Public License # version 2 that you can find in the COPYING file bundled with the # distribution. # # Usage: sort-pictures # See the sort-pictures manual page for more information. # destdir () { if identify $1 > /dev/null 2>&1; then if [ `wc -c $1 | awk '{print $1}'` -lt 100000 ]; then echo small else dest=`exif -t 0x132 $1 | grep 'Value:' | tail -1 | awk '{print $2}' | tr : -` dest=${dest:-undated} echo $dest fi else echo invalid fi } dependencies () { echo You need to install the identify and exif programs to use sort-pictures \ >&2 exit 1 } type identify > /dev/null 2>&1 || dependencies type exif > /dev/null 2>&1 || dependencies for i in image?????*.jpg; do d=`destdir $i` mkdir -p $d echo $i $d ln -f $i $d done recoverjpeg-2.6.3/src/000077500000000000000000000000001334617064100146315ustar00rootroot00000000000000recoverjpeg-2.6.3/src/Makefile.am000066400000000000000000000002171334617064100166650ustar00rootroot00000000000000bin_PROGRAMS = recoverjpeg recovermov recoverjpeg_SOURCES = recoverjpeg.c utils.c utils.h recovermov_SOURCES = recovermov.cpp utils.c utils.h recoverjpeg-2.6.3/src/recoverjpeg.c000066400000000000000000000212451334617064100173140ustar00rootroot00000000000000/* * This file is part of the recoverjpeg program. * * Copyright (c) 2004-2016 Samuel Tardieu * http://www.rfc1149.net/devel/recoverjpeg * * recoverjpeg is released under the GNU General Public License * version 2 that you can find in the COPYING file bundled with the * distribution. */ /* Needed on Linux to work on large files or devices */ #define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include #include #include #include #include "utils.h" static int verbose = 0; static int quiet = 0; static size_t max_size = 6 * 1024 * 1024; static size_t ignore_size = 0; static void usage(int clean_exit) { fprintf(stderr, "Usage: recoverjpeg [options] file|device\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, " -b blocksize Block size in bytes " "(default: 512)\n"); fprintf(stderr, " -d format Directory format string in printf syntax\n"); fprintf(stderr, " -f format File format string in printf syntax\n"); fprintf(stderr, " -h This help message\n"); fprintf(stderr, " -i index Initial picture index\n"); fprintf(stderr, " -m maxsize Max jpeg file size in bytes " "(default: 6m)\n"); fprintf(stderr, " -o directory Restore jpeg files into this directory\n"); fprintf(stderr, " -q Be quiet\n"); fprintf(stderr, " -r readsize Size of disk reads in bytes " "(default: 128m)\n"); fprintf(stderr, " -s cutoff Minimal file size in bytes to restore\n"); fprintf(stderr, " -S skipsize Size to skip at the beginning\n"); fprintf(stderr, " -v Be verbose\n"); fprintf(stderr, " -V Display version and exit\n"); exit(clean_exit ? 0 : 1); } static inline int progressbar() { return !(quiet || verbose); } static void display_progressbar(off_t offset, unsigned int n) { off_t to_display; static unsigned int old_n = -1; static int gib_mode = 0; static off_t old_to_display = 0; if (offset < 1024 * 1024 * 1024) { to_display = offset / 1024 * 10 / 1024; } else { gib_mode = 1; to_display = offset / (1024 * 1024) * 10 / 1024; } if (n != old_n || to_display != old_to_display) { printf("\rRecovered files: %4u Analyzed: %4.1f %s ", n, to_display / 10.0, gib_mode ? "GiB" : "MiB"); fflush(stdout); old_n = n; old_to_display = to_display; } } static void cleanup_progressbar() { printf("\r \r"); } static size_t jpeg_size(const unsigned char *start) { const unsigned char *addr; unsigned char code; size_t size; if (*start != 0xff || *(start + 1) != 0xd8) { return 0; } if (verbose) { fprintf(stderr, "Candidate jpeg found\n"); } for (addr = start + 2;;) { if (*addr != 0xff) { if (verbose) { fprintf(stderr, " Incorrect marker %02x, stopping prematurely\n", *addr); } return 0; } code = *(addr + 1); addr += 2; if (code == 0xd9) { if (verbose) { fprintf(stderr, " Found end of image after %ld bytes\n", (long) (addr - start + 1)); } return addr - start; } if (code == 0x01 || code == 0xff) { if (verbose) { fprintf(stderr, " Found lengthless section %02x\n", code); } continue; } size = (*addr << 8) + *(addr + 1); addr += size; if (verbose) { fprintf(stderr, " Found section %02x of len %ld\n", code, (long) size); } if (size < 2 || size > max_size) { if (verbose) { fprintf(stderr, " Section size is out of bounds, aborting\n"); } return 0; } if (code == 0xda) { if (verbose) { fprintf(stderr, " Looking for end marker... "); fflush(stderr); } for (; (size_t) (addr - start) < max_size && (*addr != 0xff || *(addr + 1) == 0 || /* Escape */ (*(addr + 1) >= 0xd0 && *(addr + 1) <= 0xd7) /* RSTn */ ); addr++); if ((size_t) (addr - start) >= max_size) { if (verbose) { fprintf(stderr, "too big, aborting\n"); } return 0; } if (verbose) { fprintf(stderr, "found at offset %ld\n", (long) (addr - start)); } } } } static const char * file_name(const char *dir_format, const char *file_format, unsigned int index) { static char dir_buffer[200]; char file_buffer[100]; if (dir_format) { snprintf(dir_buffer, sizeof dir_buffer, dir_format, index / 100); if (mkdir(dir_buffer, 0777) == -1 && errno != EEXIST) { fprintf(stderr, "recoverjpeg: unable to create directory %s (%s)\n", dir_buffer, strerror(errno)); exit(1); } strncat(dir_buffer, "/", sizeof dir_buffer - 1); } else { *dir_buffer = '\0'; } snprintf(file_buffer, sizeof file_buffer, file_format, index); strncat(dir_buffer, file_buffer, sizeof dir_buffer - strlen(dir_buffer) - 1); return dir_buffer; } int main(int argc, const char *const argv[]) { int fd, fdout; size_t read_size, block_size; unsigned int i, begin_index; unsigned char *start, *end, *addr; size_t size; int page_size; off_t offset, skip_size; const char *file_format; const char *dir_format; int c; read_size = 128 * 1024 * 1024; block_size = 512; skip_size = 0; begin_index = 0; file_format = "image%05d.jpg"; dir_format = NULL; while ((c = getopt(argc, (char * const *) argv, "b:d:f:hi:m:o:qr:s:S:vV")) != -1) { switch (c) { case 'b': block_size = atol_suffix(optarg); break; case 'd': dir_format = optarg; break; case 'f': file_format = optarg; break; case 'i': begin_index = atoi(optarg); break; case 'm': max_size = atol_suffix(optarg); break; case 'o': record_chdir(optarg); break; case 'q': quiet = 1; break; case 'r': read_size = atol_suffix(optarg); break; case 's': ignore_size = atol_suffix(optarg) - 1; break; case 'S': skip_size = atol_suffix(optarg); break; case 'v': verbose = 1; break; case 'V': display_version_and_exit("recoverjpeg"); default: usage(c == 'h'); } } argc -= optind; argv += optind; if (argc != 1) { usage(0); } fd = open(argv[0], O_RDONLY); if (fd < 0) { fprintf(stderr, "recoverjpeg: unable to open %s for reading (%s)\n", argv[argc - 1], strerror(errno)); exit(1); } perform_chdirs(); page_size = getpagesize(); if (read_size % page_size || read_size < max_size) { if (read_size < max_size) { read_size = max_size; } read_size = (read_size + page_size - 1) / page_size * page_size; if (!quiet) { fprintf(stderr, "Adjusted read size to %ld bytes\n", (long) read_size); } } start = end = (unsigned char *) malloc(read_size); if (start == 0) { fprintf(stderr, "recoverjpeg: cannot allocate necessary memory (%s)\n", strerror(errno)); exit(1); } if (skip_size % page_size) { skip_size = (skip_size / page_size) * page_size; if (!quiet) { fprintf(stderr, "Adjusted skip size to %ld bytes\n", (long) skip_size); } } for (i = 0, offset = skip_size, addr = NULL; addr < end;) { if (progressbar()) { display_progressbar(offset, i); } if (addr == NULL || (size_t) (start + read_size - addr) < max_size) { off_t base_offset; long n; base_offset = offset / page_size * page_size; lseek(fd, base_offset, SEEK_SET); n = read(fd, start, read_size); if (n < 0) { fprintf(stderr, "recoverjpeg: unable to read data (%s)\n", strerror(errno)); exit(1); } end = start + n; addr = start + (offset - base_offset); } size = jpeg_size(addr); if (size > ignore_size) { size_t n; const char *buffer = file_name(dir_format, file_format, begin_index + i); i++; if (verbose) { printf("%s %ld bytes\n", buffer, (long) size); } fdout = open(buffer, O_WRONLY | O_CREAT, 0666); if (fdout < 0) { fprintf(stderr, "Unable to open %s for writing\n", buffer); exit(1); } if ((size_t) write(fdout, addr, size) != size) { fprintf(stderr, "Unable to write %ld bytes to %s\n", (long) size, buffer); exit(1); } close(fdout); n = ((size + block_size - 1) / block_size) * block_size; addr += n; offset += n; } else { addr += block_size; offset += block_size; } } if (progressbar()) { cleanup_progressbar(); } if (!quiet) { printf("Restored %d picture%s\n", i, i > 1 ? "s" : ""); } /* Free allocated memory to keep valgrind happy */ free(start); exit(0); } recoverjpeg-2.6.3/src/recovermov.cpp000066400000000000000000000106301334617064100175240ustar00rootroot00000000000000/* * This file is part of the recoverjpeg program. * * Copyright (c) 2010-2016 Samuel Tardieu * and Jan Funke . * http://www.rfc1149.net/devel/recoverjpeg * * recoverjpeg is released under the GNU General Public License * version 2 that you can find in the COPYING file bundled with the * distribution. */ #include #include #include #include #include #include "utils.h" size_t read_size(std::ifstream& infile) { size_t size = 0; unsigned char byte; byte = infile.get(); size += byte << 24; byte = infile.get(); size += byte << 16; byte = infile.get(); size += byte << 8; byte = infile.get(); size += byte; return size; } const std::string read_atom_type(std::ifstream& infile) { std::string type = ""; char byte; for (int i = 0; i < 4; i++) { byte = infile.get(); type += byte; } return type; } void copy_n(std::ifstream& infile, std::ofstream& outfile, size_t bytes) { while (bytes > 0) { /* naiv implementation */ outfile.put(infile.get()); bytes--; } } bool is_mov_file(std::ifstream& infile) { /* try to read the first atom type "ftyp" */ infile.seekg(4, std::ios_base::cur); std::string atom_type = read_atom_type(infile); /* reset read position */ infile.seekg(-8, std::ios_base::cur); if (atom_type == "ftyp") return true; return false; } bool is_valid_atom_type(const std::string atom_type) { if (atom_type == "ftyp" || atom_type == "moov" || atom_type == "mdat" || atom_type == "free" || atom_type == "skip" || atom_type == "wide" || atom_type == "pnot") return true; return false; } void print_usage(int exitcode) { std::cerr << "Usage: recovermov [options] file|device\n"; std::cerr << "Options:\n"; std::cerr << " -b blocksize Block size in bytes\n"; std::cerr << " (default: 512)\n"; std::cerr << " -n base_name Basename of the mov files to create\n"; std::cerr << " (default: \"video_\")\n"; std::cerr << " -h This help message\n"; std::cerr << " -i index Initial movie index\n"; std::cerr << " -o directory Restore mov files into this directory\n"; std::cerr << " -V Display version and exit\n"; exit (exitcode); } int main(int argc, char* const* argv) { size_t blocksize = 512; unsigned int mov_index = 0; std::string outfilebase = "video_"; int c; while ((c = getopt (argc, argv, "b:f:hi:m:o:qr:vV")) != -1) { switch (c) { case 'b': blocksize = atol_suffix(optarg); break; case 'n': outfilebase = optarg; break; case 'i': mov_index = atoi(optarg); break; case 'o': record_chdir(optarg); break; case 'V': display_version_and_exit("recovermov"); default: print_usage((c == 'h'? 0 : 1)); } } argc -= optind; argv += optind; if (argc != 1) { print_usage(0); } const char* infilename = argv[0]; std::ifstream infile(infilename, std::ios_base::in | std::ios_base::binary); perform_chdirs(); size_t atom_size; std::string atom_type; while (!infile.eof()) { if (is_mov_file(infile)) { std::cout << "mov file detected\n"; mov_index++; std::ostringstream outfilename; outfilename << outfilebase << mov_index << ".mov"; std::cout << "writing to " << outfilename.str() << "\n"; std::ofstream outfile(outfilename.str().c_str(), std::ios_base::out | std::ios_base::binary); while (!infile.eof()) { atom_size = read_size(infile); atom_type = read_atom_type(infile); if (atom_size < 8) { std::cout << "encountered special atom (size=" << atom_size << "), aborting\n"; break; } /* check whether we reached the end of the movie file */ if (!is_valid_atom_type(atom_type)) break; /* go back to beginning of atom */ infile.seekg(-8, std::ios_base::cur); /* copy atom */ copy_n(infile, outfile, atom_size); } std::cout << "recovery of " << outfilename.str() << " finished\n"; /* go back to last block start */ size_t cur_pos = infile.tellg(); size_t cur_block = cur_pos/blocksize; infile.seekg(cur_block*blocksize); } infile.seekg(blocksize, std::ios_base::cur); } } recoverjpeg-2.6.3/src/utils.c000066400000000000000000000033271334617064100161420ustar00rootroot00000000000000/* * This file is part of the recoverjpeg program. * * Copyright (c) 2004-2016 Samuel Tardieu * http://www.rfc1149.net/devel/recoverjpeg * * recoverjpeg is released under the GNU General Public License * version 2 that you can find in the COPYING file bundled with the * distribution. */ #include #include #include #include #include #include "utils.h" typedef struct move_s { const char *target; struct move_s *next; } move_t; static move_t *chdirs = NULL; size_t atol_suffix(char *arg) { long multiplier = 1; switch (arg[strlen(arg) - 1]) { case 't': case 'T': multiplier *= 1024; /* Fallthrough */ case 'g': case 'G': multiplier *= 1024; /* Fallthrough */ case 'm': case 'M': multiplier *= 1024; /* Fallthrough */ case 'k': case 'K': multiplier *= 1024; } if (multiplier != 1) { arg[strlen(arg) - 1] = '\0'; } return atol(arg) * multiplier; } void display_version_and_exit(const char *program_name) { printf("%s %s (from the `%s' package)\n", program_name, VERSION, PACKAGE); exit(0); } void record_chdir(const char *directory) { move_t **ptr = &chdirs; while (*ptr != NULL) { ptr = &(*ptr)->next; } *ptr = malloc(sizeof(move_t)); if (*ptr == NULL) { perror("malloc"); exit(1); } (*ptr)->target = directory; (*ptr)->next = NULL; } void perform_chdirs() { move_t *to_free; move_t *p = chdirs; while (p != NULL) { if (chdir(p->target) != 0) { char buffer[512]; snprintf(buffer, sizeof buffer, "cannot change directory to `%s'", p->target); perror(buffer); exit(1); } to_free = p; p = p->next; free(to_free); } } recoverjpeg-2.6.3/src/utils.h000066400000000000000000000013031334617064100161370ustar00rootroot00000000000000/* * This file is part of the recoverjpeg program. * * Copyright (c) 2004-2016 Samuel Tardieu * http://www.rfc1149.net/devel/recoverjpeg * * recoverjpeg is released under the GNU General Public License * version 2 that you can find in the COPYING file bundled with the * distribution. */ #ifndef _UTILS_H #define _UTILS_H #include #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ size_t atol_suffix(char *arg); void display_version_and_exit(const char *program_name) __attribute__ ((noreturn)); void record_chdir(const char *directory); void perform_chdirs(); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* _UTILS_H */ recoverjpeg-2.6.3/support/000077500000000000000000000000001334617064100155565ustar00rootroot00000000000000recoverjpeg-2.6.3/support/test-build.sh000077500000000000000000000003021334617064100201640ustar00rootroot00000000000000#! /bin/sh -e autoreconf -fvi rm -rf *.tar.gz ./configure make dist rm -rf _build mkdir _build cd _build tar zxvf ../*.tar.gz cd recoverjpeg* mkdir _build cd _build ../configure make make check recoverjpeg-2.6.3/tests/000077500000000000000000000000001334617064100152045ustar00rootroot00000000000000recoverjpeg-2.6.3/tests/Makefile.am000066400000000000000000000001461334617064100172410ustar00rootroot00000000000000TESTS = chdir-ok.test chdir-not-ok.test XFAIL_TESTS = chdir-not-ok.test EXTRA_DIST = *.test never:: recoverjpeg-2.6.3/tests/chdir-not-ok.test000077500000000000000000000002421334617064100204040ustar00rootroot00000000000000#! /bin/sh # RECOVERJPEG="$PWD/../src/recoverjpeg" trap "rm -rf $PWD/$0.dir" INT QUIT TERM EXIT mkdir "$0.dir" cd "$0.dir" ${RECOVERJPEG} -o foo ${RECOVERJPEG} recoverjpeg-2.6.3/tests/chdir-ok.test000077500000000000000000000002721334617064100176110ustar00rootroot00000000000000#! /bin/sh # RECOVERJPEG="$PWD/../src/recoverjpeg" trap "rm -rf $PWD/$0.dir" INT QUIT TERM EXIT mkdir "$0.dir" cd "$0.dir" mkdir -p foo/bar ${RECOVERJPEG} -o foo -o bar ${RECOVERJPEG}