guymager-0.8.13/0000775000175000017500000000000014102741601011203 5ustar gjgjguymager-0.8.13/COPYING0000664000175000017500000004325414102741454012254 0ustar gjgj 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. guymager-0.8.13/CREDITS0000664000175000017500000000336214102741454012235 0ustar gjgj Joachim Metz Guymager can be configured to use the famous libewf for writing EWF images and Guymager's own EWF module is based on Joachim's documentation. Without Joachim's work on the EWF format, the Guymager project would probably never have been started. Special thanks to Joachim as well for believing in the idea of parallelised compression. Michael Prokop Mika took care of correctly packaging Guymager and making it available in the main repositories. Without him, the Guymager installation would have remained the nightmare it was before. As well, many thanks to Mika for his patience while answering my numerous questions about copyright and his suggestions for giving the sources a GPL compliant shape. Erwin van Eijk Erwin not only had many good ideas for new Guymager features, but also directly put them into working code which he shared in his feedbacks. Among others, the job queue, the user field and the running statistics are based on Erwin's work and ideas. Many thanks for this and for supporting the spirit of open source. Wilhelm Spiegl Software is only as good as it has been tested. Willi always played an important role in this. Many thanks for his persistent testing and detailed problem documentation. If Guymager is said to be stable and user friendly it's because of Willi's unwearied work. Trevor Welsby Thanks to Trevor, Guymager has a few bugs less and includes some new features (SHA1 support and relative paths). Trevor submitted his bug reports and feature requests together with suggestions for source code changes and thus made the necessary changes in the main trunk really easy. guymager-0.8.13/aaff.cpp0000664000175000017500000005320514102741454012617 0ustar gjgj// **************************************************************************** // Project: GUYMAGER // **************************************************************************** // Programmer: Guy Voncken // Police Grand-Ducale // Service de Police Judiciaire // Section Nouvelles Technologies // **************************************************************************** // Module: Multithreaded AFF (AAFF = Advanced AFF) // **************************************************************************** // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, // 2018, 2019, 2020 // Guy Voncken // // This file is part of Guymager. // // Guymager 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. // // Guymager 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 Guymager. If not, see . #include "common.h" #include "compileinfo.h" #include #include #include //lint !e537 !e451 repeated include file #include #include #include #include "util.h" #include "config.h" #include "aaff.h" // ----------------- // AFF definitions // ----------------- #define AFF_GID_LENGTH 16 #define AFF_SEGARG_U64 2 // Used as argument for segments that contain a 64 bit unsigned in the data field #define AFF_HEADER "AFF10\r\n" #define AFF_HEADER_LEN 7 #define AFF_SEGMENT_HEADER_MAGIC "AFF" #define AFF_SEGMENT_FOOTER_MAGIC "ATT" #define AFF_BADSECTOR_HEADER "BAD SECTOR" #define AFF_FILE_TYPE "AFF" #define AFF_SEGNAME_BADFLAG "badflag" #define AFF_SEGNAME_AFFLIB_VERSION "afflib_version" #define AFF_SEGNAME_FILETYPE "aff_file_type" #define AFF_SEGNAME_GID "image_gid" #define AFF_SEGNAME_SECTORS "devicesectors" #define AFF_SEGNAME_SECTORSIZE "sectorsize" #define AFF_SEGNAME_IMAGESIZE "imagesize" #define AFF_SEGNAME_PAGESIZE "pagesize" #define AFF_SEGNAME_BADSECTORS "badsectors" #define AFF_SEGNAME_MD5 "md5" #define AFF_SEGNAME_SHA1 "sha1" #define AFF_SEGNAME_SHA256 "sha256" #define AFF_SEGNAME_DURATION "acquisition_seconds" #define AFF_SEGNAME_PAGE "page" #define AFF_PAGEFLAGS_UNCOMPRESSED 0x0000 #define AFF_PAGEFLAGS_COMPRESSED_ZLIB 0x0001 #define AFF_PAGEFLAGS_COMPRESSED_ZERO 0x0033 // Compressed, Zero and MaxCompression typedef struct { char Magic[4]; unsigned int NameLen; unsigned int DataLen; unsigned int Argument; // Named "flags" in original aff source, named "arg" in afinfo output. char Name[]; } __attribute__ ((packed)) t_AffSegmentHeader; // Between header and footer lie the segment name and the data typedef struct { char Magic[4]; unsigned int SegmentLen; } __attribute__ ((packed)) t_AffSegmentFooter; // ------------------ // Aaff definitions // ------------------ #pragma GCC diagnostic push #ifdef Q_CREATOR_RUN #pragma GCC diagnostic ignored "-Wgnu-variable-sized-type-not-at-end" #endif typedef struct _t_Aaff { FILE *pFile; bool OpenedForWrite; unsigned long long PagesWritten; unsigned long long PagesRead; t_HashContextMD5 HashContextMD5; // For image file MD5 calculation during verification QString *pFilename; unsigned char *pUncompressBuffer; unsigned int UncompressBufferLen; unsigned long long BytesVerified; unsigned long long DeviceSize; t_AffSegmentFooter SegmentFooter; // This header and footer are allocated and initialised only once and re-used afterwards; t_AffSegmentHeader SegmentHeader; // SegmentHeader.Name isn't used, so ignore compiler warning about flexible array members } t_Aaff; #pragma GCC diagnostic pop #define AAFF_MD5_LEN 16 #define AAFF_SHA1_LEN 20 #define AAFF_SHA256_LEN 32 #define AAFF_BADSECTORMARKER_MAXLEN 65536 static unsigned char AaffBadSectorMarker[AAFF_BADSECTORMARKER_MAXLEN]; // ---------------- // Error handling // ---------------- #define CHK_FWRITE(Fn) \ if ((Fn) != 1) \ CHK (ERROR_AAFF_CANNOT_WRITE_FILE) // ------------------- // Segment functions // ------------------- static APIRET AaffWriteSegment (t_pAaff pAaff, const char *pName, unsigned int Argument, const unsigned char *pData, unsigned int DataLen) { unsigned int NameLen0 = (unsigned int) strlen(pName); pAaff->SegmentHeader.NameLen = htonl(NameLen0); pAaff->SegmentHeader.DataLen = htonl(DataLen); pAaff->SegmentHeader.Argument = htonl(Argument); pAaff->SegmentFooter.SegmentLen = htonl(sizeof(t_AffSegmentHeader) + sizeof(t_AffSegmentFooter) + NameLen0 + DataLen); CHK_FWRITE(fwrite (&pAaff->SegmentHeader, sizeof(t_AffSegmentHeader), 1, pAaff->pFile)) CHK_FWRITE(fwrite (pName, NameLen0, 1, pAaff->pFile)) if (pData && DataLen) CHK_FWRITE(fwrite (pData, DataLen, 1, pAaff->pFile)) CHK_FWRITE(fwrite (&pAaff->SegmentFooter, sizeof(t_AffSegmentFooter), 1, pAaff->pFile)) return NO_ERROR; } APIRET AaffWriteSegmentStr (t_pAaff pAaff, const char *pName, unsigned int Argument, const char *pStr) { CHK (AaffWriteSegment (pAaff, pName, Argument, (const unsigned char *) pStr, (unsigned int) strlen (pStr))) return NO_ERROR; } static APIRET AaffWriteSegmentArg (t_pAaff pAaff, const char *pName, unsigned int Argument) { CHK (AaffWriteSegment (pAaff, pName, Argument, nullptr, 0)) return NO_ERROR; } static APIRET AaffWriteSegmentU64 (t_pAaff pAaff, const char *pName, unsigned long long Value) { unsigned int Data[2]; Data[0] = htonl ((unsigned int)(Value & 0xFFFFFFFF)); Data[1] = htonl ((unsigned int)(Value >> 32)); CHK (AaffWriteSegment (pAaff, pName, AFF_SEGARG_U64, (unsigned char *)&Data[0], sizeof(Data))) return NO_ERROR; } static APIRET AaffWriteSegmentGID (t_pAaff pAaff) { unsigned char GID[AFF_GID_LENGTH]; int i; for (i=0; i AAFF_BADSECTORMARKER_MAXLEN) CHK (ERROR_AAFF_SECTORSIZE_TOO_BIG) memcpy (pBuffer, &AaffBadSectorMarker[0], Len); return NO_ERROR; } // --------------------- // API write functions // --------------------- static APIRET AaffCreateHandle (t_pAaff *ppAaff) { t_pAaff pAaff; pAaff = (t_pAaff) UTIL_MEM_ALLOC(sizeof(t_Aaff)); if (pAaff == nullptr) CHK (ERROR_AAFF_MEMALLOC_FAILED) memset (pAaff, 0, sizeof(t_Aaff)); pAaff->pFilename = new QString; *ppAaff = pAaff; return NO_ERROR; } static APIRET AaffDestroyHandle (t_pAaff *ppAaff) { t_pAaff pAaff = *ppAaff; if (pAaff->pUncompressBuffer) free (pAaff->pUncompressBuffer); // Must released with free, as realloc is used for allocating it delete pAaff->pFilename; memset (pAaff, 0, sizeof(t_Aaff)); UTIL_MEM_FREE (pAaff); *ppAaff = nullptr; return NO_ERROR; } //lint -save -esym(613,pAaff) Possible use of null pointer pAaff APIRET AaffOpen (t_pAaff *ppAaff, const char *pFilename, unsigned long long DeviceSize, unsigned int SectorSize, unsigned int PageSize) { t_pAaff pAaff; char Buff[512]; *ppAaff = nullptr; // Open file and intialise // ----------------------- if (SectorSize > AAFF_BADSECTORMARKER_MAXLEN) CHK (ERROR_AAFF_SECTORSIZE_TOO_BIG) CHK (AaffCreateHandle (&pAaff)) *(pAaff->pFilename) = pFilename; pAaff->OpenedForWrite = true; pAaff->pFile = fopen64 (pFilename, "w"); if (pAaff->pFile == nullptr) { CHK (AaffDestroyHandle (ppAaff)) CHK (ERROR_AAFF_CANNOT_CREATE_FILE) } *ppAaff = pAaff; CHK_FWRITE(fwrite (AFF_HEADER, sizeof(AFF_HEADER), 1, pAaff->pFile)) pAaff->PagesWritten = 0; memset (&pAaff->SegmentHeader, 0, sizeof (t_AffSegmentHeader)); memset (&pAaff->SegmentFooter, 0, sizeof (t_AffSegmentFooter)); strcpy (&pAaff->SegmentHeader.Magic[0], AFF_SEGMENT_HEADER_MAGIC); strcpy (&pAaff->SegmentFooter.Magic[0], AFF_SEGMENT_FOOTER_MAGIC); // Write standard segments // ----------------------- snprintf (&Buff[0], sizeof(Buff), "aaff module of Guymager %s", pCompileInfoVersion); CHK (AaffWriteSegmentGID (pAaff)) if CONFIG (AffMarkBadSectors) CHK (AaffWriteSegment (pAaff, AFF_SEGNAME_BADFLAG , 0, AaffBadSectorMarker, SectorSize)) CHK (AaffWriteSegmentStr (pAaff, AFF_SEGNAME_AFFLIB_VERSION, 0, &Buff[0])) CHK (AaffWriteSegmentStr (pAaff, AFF_SEGNAME_FILETYPE , 0, AFF_FILE_TYPE)) CHK (AaffWriteSegmentArg (pAaff, AFF_SEGNAME_PAGESIZE , PageSize)) CHK (AaffWriteSegmentArg (pAaff, AFF_SEGNAME_SECTORSIZE , SectorSize)) CHK (AaffWriteSegmentU64 (pAaff, AFF_SEGNAME_SECTORS , DeviceSize / SectorSize)) CHK (AaffWriteSegmentU64 (pAaff, AFF_SEGNAME_IMAGESIZE , DeviceSize)) return NO_ERROR; } //lint -restore APIRET AaffClose (t_pAaff *ppAaff, unsigned long long BadSectors, const unsigned char *pMD5, const unsigned char *pSHA1, const unsigned char *pSHA256, uint Duration) { t_pAaff pAaff = *ppAaff; CHK (AaffWriteSegmentU64 (pAaff, AFF_SEGNAME_BADSECTORS, BadSectors)) CHK (AaffWriteSegment (pAaff, AFF_SEGNAME_MD5 , 0, pMD5 , AAFF_MD5_LEN )) CHK (AaffWriteSegment (pAaff, AFF_SEGNAME_SHA1 , 0, pSHA1 , AAFF_SHA1_LEN )) CHK (AaffWriteSegment (pAaff, AFF_SEGNAME_SHA256 , 0, pSHA256, AAFF_SHA256_LEN)) CHK (AaffWriteSegmentArg (pAaff, AFF_SEGNAME_DURATION , Duration)) if (fflush (pAaff->pFile)) { (void) fclose (pAaff->pFile); CHK (ERROR_AAFF_CANNOT_FLUSH_FILE) } if (fclose (pAaff->pFile)) CHK (ERROR_AAFF_CANNOT_CLOSE_FILE) CHK (AaffDestroyHandle (ppAaff)) return NO_ERROR; } //lint -save -esym(613,pPreProcess) Possible use of null pointer APIRET AaffPreprocess (t_pAaffPreprocess pPreprocess, unsigned char *pDataIn, unsigned int DataLenIn, unsigned char *pDataOut, uint DataLenOut) { // t_pAaffPreprocess pPreProcess; int rc; uLongf LenOut; // *ppPreprocess = nullptr; // pPreProcess = (t_pAaffPreprocess) UTIL_MEM_ALLOC(sizeof(t_AaffPreprocess)); // if (pPreProcess == nullptr) // CHK (ERROR_AAFF_MEMALLOC_FAILED) // *ppPreprocess = pPreProcess; pPreprocess->Zero = false; pPreprocess->Compressed = false; // Check if zero // ------------- pPreprocess->Zero = UtilIsZero (pDataIn, DataLenIn); if (pPreprocess->Zero) return NO_ERROR; // Try compression // --------------- LenOut = DataLenOut; rc = compress2 ((Bytef *)pDataOut, &LenOut, (Bytef *)pDataIn, DataLenIn, CONFIG (AffCompression)); pPreprocess->DataLenOut = (uint) LenOut; if (rc != Z_OK) { if (rc != Z_BUF_ERROR) // Do not log this one (the destination buffer was too small for the compressed result) LOG_ERROR ("compress2 returned %d", rc) return NO_ERROR; } pPreprocess->Compressed = (LenOut < DataLenIn); return NO_ERROR; } //lint -restore APIRET AaffWrite (t_pAaff pAaff, t_pAaffPreprocess pPreprocess, const unsigned char *pData, unsigned int DataLen) { char SegmentName[64]; snprintf (&SegmentName[0], sizeof(SegmentName), "%s%llu", AFF_SEGNAME_PAGE, pAaff->PagesWritten++); if (pPreprocess->Zero) { unsigned int Len = htonl(DataLen); CHK (AaffWriteSegment (pAaff, &SegmentName[0], AFF_PAGEFLAGS_COMPRESSED_ZERO, (unsigned char *) &Len, sizeof (Len))) } else if (pPreprocess->Compressed) CHK (AaffWriteSegment (pAaff, &SegmentName[0], AFF_PAGEFLAGS_COMPRESSED_ZLIB, pData, pPreprocess->DataLenOut)) else CHK (AaffWriteSegment (pAaff, &SegmentName[0], AFF_PAGEFLAGS_UNCOMPRESSED , pData, DataLen)) // UTIL_MEM_FREE (pPreprocess); return NO_ERROR; } // --------------------- // API read functions // --------------------- static APIRET AaffReallocUncompressBuffer (t_pAaff pAaff, unsigned int NewLen) { if (NewLen > pAaff->UncompressBufferLen) { pAaff->pUncompressBuffer = (unsigned char *) realloc (pAaff->pUncompressBuffer, NewLen); if (pAaff->pUncompressBuffer == nullptr) return ERROR_AAFF_MEMALLOC_FAILED; pAaff->UncompressBufferLen = NewLen; } return NO_ERROR; } static unsigned long long AaffGetCurrentSeekPos (t_Aaff *pAaff) { return (quint64) ftello64 (pAaff->pFile); } APIRET AaffGetImageFileSize (t_Aaff *pAaff, unsigned long long *pSize) { unsigned long long CurrentSeekPos; int rc; CurrentSeekPos = AaffGetCurrentSeekPos (pAaff); rc = fseeko64 (pAaff->pFile, 0, SEEK_END); if (rc) return ERROR_AAFF_CANNOT_SEEK; *pSize = AaffGetCurrentSeekPos (pAaff); rc = fseeko64 (pAaff->pFile, (__off64_t) CurrentSeekPos, SEEK_SET); if (rc) return ERROR_AAFF_CANNOT_SEEK; return NO_ERROR; } static APIRET AaffReadFile (t_Aaff *pAaff, void *pData, unsigned int DataLen) { if (fread (pData, DataLen, 1, pAaff->pFile) != 1) CHK (ERROR_AAFF_CANNOT_READ_DATA) if (CONFIG(CalcImageFileMD5)) CHK (HashMD5Append (&pAaff->HashContextMD5, pData, DataLen)) return NO_ERROR; } APIRET AaffOpen (t_pAaff *ppAaff, const char *pFilename, unsigned long long DeviceSize) { t_pAaff pAaff; char Signature[AFF_HEADER_LEN+1]; *ppAaff = nullptr; CHK (AaffCreateHandle (&pAaff)) pAaff->OpenedForWrite = false; pAaff->pUncompressBuffer = nullptr; pAaff->UncompressBufferLen = 0; pAaff->PagesRead = 0; pAaff->BytesVerified = 0; pAaff->DeviceSize = DeviceSize; *(pAaff->pFilename) = pFilename; if (CONFIG(CalcImageFileMD5)) CHK (HashMD5Init (&pAaff->HashContextMD5)) pAaff->pFile = fopen64 (pFilename, "r"); if (pAaff->pFile == nullptr) { UTIL_MEM_FREE (pAaff); CHK (ERROR_AAFF_CANNOT_OPEN_FILE) } // Check signature // --------------- CHK (AaffReadFile (pAaff, &Signature, sizeof(Signature))) if (memcmp (Signature, AFF_HEADER, sizeof(Signature)) != 0) return ERROR_AAFF_INVALID_SIGNATURE; *ppAaff = pAaff; return NO_ERROR; } APIRET AaffClose (t_pAaff *ppAaff) { if (fclose ((*ppAaff)->pFile)) CHK (ERROR_AAFF_CANNOT_CLOSE_FILE) CHK (AaffDestroyHandle (ppAaff)) return NO_ERROR; } APIRET AaffReadNextPage (t_pAaff pAaff, unsigned char *pData, unsigned int *pDataLen, QString *pImageFilename, t_pHashMD5Digest pMD5Digest, bool *pMD5Valid) { t_AffSegmentHeader Header; t_AffSegmentFooter Footer; char SegmentName[100]; char *pSegmentNamePageNumber; char *pTail; bool Found=false; uLongf DataLen = *pDataLen; int rc; unsigned long long BytesToNextHeader; *pImageFilename = QString(); *pMD5Valid = false; // Search for the next segment whose name starts with "page" // --------------------------------------------------------- do { CHK (AaffReadFile (pAaff, &Header, offsetof(t_AffSegmentHeader, Name))) if (strcmp (&Header.Magic[0], AFF_SEGMENT_HEADER_MAGIC) != 0) return ERROR_AAFF_INVALID_HEADER; Header.NameLen = ntohl (Header.NameLen ); Header.DataLen = ntohl (Header.DataLen ); Header.Argument = ntohl (Header.Argument); if (Header.NameLen >= sizeof(SegmentName)) return ERROR_AAFF_INVALID_SEGMENT_NAME; CHK (AaffReadFile (pAaff, &SegmentName[0], Header.NameLen)) SegmentName[Header.NameLen] = '\0'; Found = (strncmp (&SegmentName[0], AFF_SEGNAME_PAGE, strlen(AFF_SEGNAME_PAGE)) == 0); // The segment name must start with "page" if (Found) Found = (strlen (&SegmentName[0]) > strlen(AFF_SEGNAME_PAGE)); // The string "page" must be followed by at least 1 digit if (Found) Found = isdigit ( SegmentName[strlen(AFF_SEGNAME_PAGE)]); // Check if the following char is a digit (Some checking done after strtol, see below) if (!Found) { BytesToNextHeader = Header.DataLen + sizeof(t_AffSegmentFooter); if (CONFIG (CalcImageFileMD5)) // Read the data between current pos and next header in order have image file MD5 calculated correctly { CHK (AaffReallocUncompressBuffer (pAaff, BytesToNextHeader)) CHK (AaffReadFile (pAaff, pAaff->pUncompressBuffer, BytesToNextHeader)) } else // Simply seek to next header, which is faster { rc = fseeko64 (pAaff->pFile, BytesToNextHeader, SEEK_CUR); if (rc) return ERROR_AAFF_CANNOT_SEEK; } } } while (!Found); // Check page number // ----------------- pSegmentNamePageNumber = &SegmentName[strlen(AFF_SEGNAME_PAGE)]; unsigned int PageNumber = strtol (pSegmentNamePageNumber, &pTail, 10); if (*pTail != '\0') return ERROR_AAFF_INVALID_PAGE_NUMBER; // There should be no extra chars after the number if (PageNumber != pAaff->PagesRead) return ERROR_AAFF_INVALID_PAGE_ORDER; pAaff->PagesRead++; // Get data // -------- if (Header.DataLen > *pDataLen) return ERROR_AAFF_PAGE_LARGER_THAN_BUFFER; switch (Header.Argument) { case AFF_PAGEFLAGS_UNCOMPRESSED: CHK (AaffReadFile (pAaff, pData, Header.DataLen)) *pDataLen = Header.DataLen; break; case AFF_PAGEFLAGS_COMPRESSED_ZERO: unsigned int Len; CHK (AaffReadFile (pAaff, &Len, sizeof(Len))) Len = ntohl (Len); memset (pData, 0, Len); *pDataLen = Len; break; case AFF_PAGEFLAGS_COMPRESSED_ZLIB: CHK (AaffReallocUncompressBuffer (pAaff, Header.DataLen)) CHK (AaffReadFile (pAaff, pAaff->pUncompressBuffer, Header.DataLen)) rc = uncompress (pData, &DataLen, pAaff->pUncompressBuffer, Header.DataLen); *pDataLen = DataLen; if (rc != Z_OK) { LOG_ERROR ("Zlib uncompress returned %d", rc) return ERROR_AAFF_UNCOMPRESS_FAILED; } break; default: LOG_INFO ("Invalid page argument: %d", Header.Argument) CHK (ERROR_AAFF_INVALID_PAGE_ARGUMENT) } // Check footer // ------------ CHK (AaffReadFile (pAaff, &Footer, sizeof(Footer))) if (strcmp (&Footer.Magic[0], AFF_SEGMENT_FOOTER_MAGIC) != 0) return ERROR_AAFF_INVALID_FOOTER; unsigned int SegmentLen = sizeof (t_AffSegmentHeader) + sizeof(t_AffSegmentFooter) + Header.NameLen + Header.DataLen; if (ntohl(Footer.SegmentLen) != SegmentLen) return ERROR_AAFF_INVALID_SEGMENTLEN; // Check if all data has been read // ------------------------------- pAaff->BytesVerified += *pDataLen; if (pAaff->BytesVerified == pAaff->DeviceSize) { if (CONFIG(CalcImageFileMD5)) { unsigned long long ImageFileSize; unsigned long long BytesRemaining; CHK (AaffGetImageFileSize(pAaff, &ImageFileSize)) BytesRemaining = ImageFileSize - AaffGetCurrentSeekPos(pAaff); CHK (AaffReadFile (pAaff, pAaff->pUncompressBuffer, BytesRemaining)) CHK (HashMD5Digest (&pAaff->HashContextMD5, pMD5Digest)) *pMD5Valid = true; } *pImageFilename = *(pAaff->pFilename); } return NO_ERROR; } // ----------------------- // Misc. functions // ----------------------- unsigned int AaffPreprocessExtraSpace (unsigned int FifoBlockSize) { return UtilGetMaxZcompressedBufferSize (FifoBlockSize) - FifoBlockSize; } APIRET AaffInit (void) { int i; CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_CANNOT_CLOSE_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_CANNOT_CREATE_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_CANNOT_FLUSH_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_CANNOT_OPEN_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_CANNOT_READ_DATA )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_CANNOT_SEEK )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_CANNOT_WRITE_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_INVALID_FOOTER )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_INVALID_HEADER )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_INVALID_PAGE_ARGUMENT )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_INVALID_PAGE_NUMBER )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_INVALID_PAGE_ORDER )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_INVALID_SEGMENTLEN )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_INVALID_SEGMENT_NAME )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_INVALID_SIGNATURE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_MEMALLOC_FAILED )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_PAGE_LARGER_THAN_BUFFER)) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_SECTORSIZE_TOO_BIG )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AAFF_UNCOMPRESS_FAILED )) srandom ((unsigned int) time (nullptr)); for (i=0; i. #ifndef AAFF_H #define AAFF_H #include "hash.h" typedef struct _t_Aaff *t_pAaff; typedef struct { bool Zero; // Tells AaffWrite that all data is 0 bool Compressed; // Tells AaffWrite whether the data should be written compressed or uncompressed uint DataLenOut; // If Compressed is true: The size of the compressed data } t_AaffPreprocess, *t_pAaffPreprocess; #define AAFF_SEGNAME_COMMAND_LINE "acquisition_commandline" #define AAFF_SEGNAME_MACADDR "acquisition_macaddr" #define AAFF_SEGNAME_DATE "acquisition_date" // Format: YYYY-MM-DD HH:MM:SS TZT #define AAFF_SEGNAME_DEVICE "acquisition_device" #define AAFF_SEGNAME_MODEL "device_model" #define AAFF_SEGNAME_SN "device_sn" // ------------------------------------ // Functions // ------------------------------------ // Write access functions APIRET AaffOpen (t_pAaff *ppAaff, const char *pFilename, unsigned long long DeviceSize, unsigned int SectorSize, unsigned int PageSize); APIRET AaffPreprocess (t_pAaffPreprocess pPreprocess, unsigned char *pDataIn, unsigned int DataLenIn, unsigned char *pDataOut, unsigned int DataLenOut); APIRET AaffWrite (t_pAaff pAaff, t_pAaffPreprocess pPreprocess, const unsigned char *pData, unsigned int DataLen); APIRET AaffClose (t_pAaff *ppAaff, unsigned long long BadSectors, const unsigned char *pMD5, const unsigned char *pSHA1, const unsigned char *pSHA256, uint Duration); // Read access functions APIRET AaffOpen (t_pAaff *ppAaff, const char *pFilename, unsigned long long DeviceSize); APIRET AaffReadNextPage (t_pAaff pAaff, unsigned char *pData, unsigned int *pDataLen, QString *pImageFilename, t_pHashMD5Digest pMD5Digest, bool *pMD5valid); APIRET AaffClose (t_pAaff *ppAaff); APIRET AaffWriteSegmentStr (t_pAaff pAaff, const char *pName, unsigned int Argument, const char *pStr); APIRET AaffCopyBadSectorMarker (unsigned char *pBuffer, unsigned int Len); // Misc. functions unsigned int AaffPreprocessExtraSpace (unsigned int FifoBlockSize); APIRET AaffInit (void); APIRET AaffDeInit (void); // ------------------------------------ // Error codes // ------------------------------------ enum { ERROR_AAFF_CANNOT_CLOSE_FILE = ERROR_BASE_AAFF + 1, ERROR_AAFF_CANNOT_CREATE_FILE, ERROR_AAFF_CANNOT_FLUSH_FILE, ERROR_AAFF_CANNOT_OPEN_FILE, ERROR_AAFF_CANNOT_READ_DATA, ERROR_AAFF_CANNOT_SEEK, ERROR_AAFF_CANNOT_WRITE_FILE, ERROR_AAFF_INVALID_FOOTER, ERROR_AAFF_INVALID_HEADER, ERROR_AAFF_INVALID_PAGE_ARGUMENT, ERROR_AAFF_INVALID_PAGE_NUMBER, ERROR_AAFF_INVALID_PAGE_ORDER, ERROR_AAFF_INVALID_SEGMENTLEN, ERROR_AAFF_INVALID_SEGMENT_NAME, ERROR_AAFF_INVALID_SIGNATURE, ERROR_AAFF_MEMALLOC_FAILED, ERROR_AAFF_PAGE_LARGER_THAN_BUFFER, ERROR_AAFF_SECTORSIZE_TOO_BIG, ERROR_AAFF_UNCOMPRESS_FAILED }; #endif guymager-0.8.13/aewf.cpp0000664000175000017500000015221414102741454012644 0ustar gjgj// **************************************************************************** // Project: GUYMAGER // **************************************************************************** // Programmer: Guy Voncken // Police Grand-Ducale // Service de Police Judiciaire // Section Nouvelles Technologies // **************************************************************************** // Module: Multithreaded AEWF (AEWF = Advanced EWF) // **************************************************************************** // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, // 2018, 2019, 2020 // Guy Voncken // // This file is part of Guymager. // // Guymager 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. // // Guymager 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 Guymager. If not, see . #include "common.h" #include "compileinfo.h" #include #include #include //lint !e537 repeated include file #include #include #include #include #include #include #include "ewf.h" #include "util.h" #include "config.h" #include "aewf.h" // ------------------ // Qt // ------------------ // Qt inconsistently defines its little/big endian functions, see QTBUG-21208 on bugreports.qt.nokia.com // The following lines implement conversin for uchar and avoid the problems. #if (QT_VERSION < 0x040800) template T qbswap(T source); template <> inline uchar qbswap(uchar source) { return source; } #endif // ------------------ // AEWF definitions // ------------------ static const uchar AEWF_SIGNATURE[8] = {0x45, 0x56, 0x46, 0x09, 0x0D, 0x0A, 0xFF, 0x00}; static const uchar AEWF_STARTOFFIELDS = 0x01; static const ushort AEWF_ENDOFFIELDS = 0x0000; static const char * AEWF_SECTIONNAME_HEADER2 = "header2"; static const char * AEWF_SECTIONNAME_HEADER = "header" ; static const char * AEWF_SECTIONNAME_VOLUME = "volume" ; static const char * AEWF_SECTIONNAME_SECTORS = "sectors"; static const char * AEWF_SECTIONNAME_TABLE = "table" ; static const char * AEWF_SECTIONNAME_TABLE2 = "table2" ; static const char * AEWF_SECTIONNAME_DATA = "data" ; static const char * AEWF_SECTIONNAME_ERROR2 = "error2" ; static const char * AEWF_SECTIONNAME_HASH = "hash" ; static const char * AEWF_SECTIONNAME_DIGEST = "digest" ; static const char * AEWF_SECTIONNAME_NEXT = "next" ; static const char * AEWF_SECTIONNAME_DONE = "done" ; static const unsigned int AEWF_MAX_CHUNK_OFFSETS = 65534; static const unsigned int AEWF_MAX_SIZE_SECTIONSECTOR = 0x7FFFFFFF; static const unsigned int AEWF_COMPRESSED_CHUNK = 0x80000000; static const unsigned long long AEWF_SEEK_END = 0xFFFFFFFFFFFFFFFFULL; typedef struct { uchar Signature[8]; uchar StartOfFields; ushort SegmentNumber; ushort EndOfFields; } __attribute__ ((packed)) t_AewfFileHeader, *t_pAewfFileHeader; typedef struct { char Name[16]; quint64 NextSectionOffset; // based on file start quint64 SectionSize; uchar Padding[40]; uint CRC; // CRC of data from beginning of this section to the field before CRC uchar Data[]; } __attribute__ ((packed)) t_AewfSection, *t_pAewfSection; typedef struct { uchar MediaType; uchar Unknown1[3]; // contains 0x00 uint ChunkCount; uint SectorsPerChunk; uint BytesPerSector; quint64 SectorCount; uint CHS_Cylinders; uint CHS_Heads; uint CHS_Sectors; uchar MediaFlags; uchar Unknown2[3]; // contains 0x00 uint PalmVolumeStartSector; uchar Padding1[4]; // contains 0x00 uint SmartLogsStartSector; uchar CompressionLevel; uchar Unknown3[3]; // contains 0x00 uint ErrorBlockSize; uchar Unknown4[4]; uchar AcquirySystemGUID[16]; uchar Padding2[963]; uchar Reserved [5]; uint Checksum; } __attribute__ ((packed)) t_AewfSectionVolumeContents, *t_pAewfSectionVolumeContents; typedef struct { uint Offsets; uint Padding1; quint64 BaseOffset; uint Padding2; uint CRC1; uint OffsetArr[0]; uint CRC2; // unused - do not remove or else sizeof calculation become wrong } __attribute__ ((packed)) t_AewfSectionTableContents; typedef struct { uint FirstSector; uint NumberOfSectors; } __attribute__ ((packed)) t_AewfSectionErrorEntry; typedef struct { uint NumberOfErrors; uchar Padding[512]; uint CRC1; t_AewfSectionErrorEntry ErrorArr[0]; uint CRC2; // unused - do not remove or else sizeof calculation become wrong } __attribute__ ((packed)) t_AewfSectionErrorContents; typedef struct { uchar MD5 [16]; uchar Unknown[16]; uint CRC; } __attribute__ ((packed)) t_AewfSectionHashContents; typedef struct { uchar MD5 [16]; uchar SHA1 [20]; uchar Padding[40]; uint CRC; } __attribute__ ((packed)) t_AewfSectionDigestContents; class t_Aewf { public: QString SegmentFilename; // The base path and filename, without extension quint64 DeviceSize; quint64 SegmentSize; quint64 ChunkSize; quint64 SectorSize; t_AewfMediaType MediaType; t_AewfMediaFlags MediaFlags; QString Description; QString CaseNumber; QString EvidenceNumber; QString Examiner; QString Notes; QString DeviceModel; QString SerialNumber; QString ImagerVersion; QString OSVersion; uint SegmentFiles; // uchar EwfCompressionLevel; // The compression levels have been made global in order not to depend upon // int ZipCompressionLevel; // Aewf handle in preprocessing (this simplifies duplicate image writing) QStringList SegmentFilenameList; FILE *pCurrentSegmentFile; quint64 CurrentSectionSectorSeekPos; quint64 CurrentSectionSectorContentSize; t_AewfFileHeader FileHeaderCache; quint64 ChunkBaseOffset; uint ChunkOffsetArr[AEWF_MAX_CHUNK_OFFSETS+1]; // Data is stored in little endian for speed optimisation here! +1 as we add a fake chunk offset marking the end of the section "sectors" when verifying the data uint ChunkOffsets; uint CurrentChunkOffset; // For knowing the current chunk during verification t_HashContextMD5 CurrentSegmentHashContextMD5; // For segment file MD5 calculation during verification uchar *pVerifyBuffer; // For uncompression and other verification tasks uint VerifyBufferLen; t_Aewf () { pCurrentSegmentFile = nullptr; SegmentFiles = 0; pVerifyBuffer = nullptr; VerifyBufferLen = 0; memcpy (FileHeaderCache.Signature, AEWF_SIGNATURE, sizeof (AEWF_SIGNATURE)); FileHeaderCache.StartOfFields = qToLittleEndian (AEWF_STARTOFFIELDS); FileHeaderCache.SegmentNumber = qToLittleEndian (0); FileHeaderCache.EndOfFields = qToLittleEndian (AEWF_ENDOFFIELDS); // switch (CONFIG(EwfCompression)) // { // case LIBEWF_COMPRESSION_NONE: ZipCompressionLevel = 0; EwfCompressionLevel = 0x00; break; // case LIBEWF_COMPRESSION_FAST: ZipCompressionLevel = 1; EwfCompressionLevel = 0x01; break; // case LIBEWF_COMPRESSION_BEST: ZipCompressionLevel = 9; EwfCompressionLevel = 0x02; break; // default: CHK_EXIT (ERROR_AEWF_INVALID_COMPRESSION_LEVEL) // } } }; // ---------------- // Global vars // ---------------- static unsigned char *pAewfZeroBlockCompressed; static ulong AewfZeroBlockCompressedLen; static ulong AewfZeroBlockUnCompressedLen; static int AewfZipCompressionLevel; static uchar AewfEwfCompressionLevel; // ---------------- // Error handling // ---------------- #define CHK_FWRITE(Fn) \ if ((Fn) != 1) \ CHK (ERROR_AEWF_CANNOT_WRITE_FILE) // ------------------- // Utility functions // ------------------- static int AewfCRC (const void *pBuffer, size_t Len) { return adler32 (1, (const Bytef *) pBuffer, Len); } // EWF file extension calculation: That extension naming convention of EWF files most probably was a quick hack. // The known sequence is: // E01 - E99 // EAA - EZZ // FAA - ZZZ // Nobody exactly seems to know what follows then. Joachim Metz writes that maybe [AA would follow. If so, it // doesn't help a lot, as it only doubles the available naming space (the following ASCII character is \ and // thus cannot be used on Windows systems with their inconsistent usage of \ and / ). // Guymager suports 2 ways for continuing beyond extension ZZZ: // OLD method: // Here I decided to continue with ZZZxxx, where xxx represents a number from 000 to ZZZ in base36 notation (i.e. // 0-9 and A-Z). After that, it would continue with ZZZxxxx and so on. // FTK method // According to tests made by Willi Spiegel, FTK continues with E14972, E14973 and so on. // // Reminder: Old-fashionned Windows-file systems only allow 3 letters for the extension. So, extensions beyond ZZZ // must be avoided there. const QString AewfGetExtension (uint SegmentFileNr) { QString Extension; if (SegmentFileNr == 0) Extension = "Error_filenr_is_zero"; else if (SegmentFileNr < 100) Extension = QString("E%1").arg(SegmentFileNr,2,10,QChar('0')); else { SegmentFileNr += ('E' -'A') * 26 * 26 - 100; // The first extension after .E99 is .EAA. So, this is the offset we need unsigned int DigitL = SegmentFileNr % 26; unsigned int DigitM = (SegmentFileNr / 26) % 26; unsigned int DigitH = (SegmentFileNr / (26*26)); if (DigitH < 26) { Extension = QString (char (DigitH + 'A')) + QString (char (DigitM + 'A')) + QString (char (DigitL + 'A')); } else { switch (CONFIG(EwfNaming)) { case EWFNAMING_OLD: SegmentFileNr -= 26*26*26; // substract ZZZ+1 -> so, for the segment following ZZZ the results is 0 Extension = QString("ZZZ%1").arg(SegmentFileNr,3,36,QChar('0')).toUpper(); break; case EWFNAMING_FTK: SegmentFileNr -= 26*26*26; // substract ZZZ+1 -> so, for the segment following ZZZ the results is 0 SegmentFileNr += 14972; Extension = QString("E%1").arg(SegmentFileNr); break; default: CHK_EXIT (ERROR_AEWF_INVALID_EWFNAMING) } } } return Extension; } // AewfCompress: No need to have an extra check if compression is set to "none". If this is the case, pAewf->ZipCompressionLevel // is set to 0 and compress2 won't do any compression (see libz / compress2 documentation). // As well, no need to check for compression level "empty", as AewfZipCompressionLevel is set to 0 in this case (see AewfInit) static APIRET AewfCompress (void *pDst, ulong *pDstLen, const void* pSrc, unsigned SrcLen) { int rc; if ((SrcLen == AewfZeroBlockUnCompressedLen) && UtilIsZero ((unsigned char *)pSrc, SrcLen)) // Check if pre-compressed { // zero block can be used if (*pDstLen < AewfZeroBlockCompressedLen) return ERROR_AEWF_COMPRESSION_FAILED; *pDstLen = AewfZeroBlockCompressedLen; memcpy (pDst, pAewfZeroBlockCompressed, AewfZeroBlockCompressedLen); } else { rc = compress2 ((Bytef*)pDst, pDstLen, (Bytef*)pSrc, SrcLen, AewfZipCompressionLevel); if (rc != Z_OK) return ERROR_AEWF_COMPRESSION_FAILED; } return NO_ERROR; } static APIRET AewfUncompress (void *pUncompressed, ulong *pUncompressedLen, void *pCompressed, ulong CompressedLen) { int rc; // #define AEWF_SIMULATE_IMAGE_FAILURE #ifdef AEWF_SIMULATE_IMAGE_FAILURE #warning "AEWF_SIMULATE_IMAGE_FAILURE debugging code active" static int Debug=0; if (Debug++ == 5654) return ERROR_AEWF_UNCOMPRESS_FAILED; #endif if ((CompressedLen == AewfZeroBlockCompressedLen) && (memcmp(pCompressed, pAewfZeroBlockCompressed, CompressedLen) == 0)) { if (*pUncompressedLen < AewfZeroBlockUnCompressedLen) return ERROR_AEWF_UNCOMPRESS_ZEROBLOCK_FAILED; *pUncompressedLen = AewfZeroBlockUnCompressedLen; memset (pUncompressed, 0, AewfZeroBlockUnCompressedLen); } else { rc = uncompress ((Bytef*)pUncompressed, pUncompressedLen, (Bytef*)pCompressed, CompressedLen); if (rc != Z_OK) return ERROR_AEWF_UNCOMPRESS_FAILED; } return NO_ERROR; } static quint64 AewfGetCurrentSeekPos (t_Aewf *pAewf) { if (pAewf->pCurrentSegmentFile) return ftello64 (pAewf->pCurrentSegmentFile); else return (quint64)(-1); } static APIRET AewfSetCurrentSeekPos (t_Aewf *pAewf, quint64 SeekPos) { int rc; if (pAewf->pCurrentSegmentFile == nullptr) CHK (ERROR_AEWF_NO_FILE_OPEN) if (SeekPos == AEWF_SEEK_END) rc = fseeko64 (pAewf->pCurrentSegmentFile, 0 , SEEK_END); else rc = fseeko64 (pAewf->pCurrentSegmentFile, SeekPos, SEEK_SET); if (rc) return ERROR_AEWF_CANNOT_SEEK; return NO_ERROR; } // --------------------- // Low level functions // --------------------- static inline APIRET AewfWriteFile (t_pAewf pAewf, const void *pBuffer, size_t Len) { if (pAewf->pCurrentSegmentFile == nullptr) CHK (ERROR_AEWF_NO_FILE_OPEN) CHK_FWRITE (fwrite (pBuffer, Len, 1, pAewf->pCurrentSegmentFile)) // Simulate cases write error // static int FakeWriteError=0; // if (FakeWriteError++ == 1500) // CHK (ERROR_AEWF_CANNOT_WRITE_FILE) return NO_ERROR; } static APIRET AewfCreateFile (t_Aewf *pAewf) { QString Extension; QString Filename; if (pAewf->pCurrentSegmentFile) CHK (ERROR_AEWF_ANOTHER_FILE_STILL_OPEN) // Get extension and open file // --------------------------- pAewf->SegmentFiles++; Extension = AewfGetExtension (pAewf->SegmentFiles); Filename = pAewf->SegmentFilename + "." + Extension; pAewf->pCurrentSegmentFile = fopen64 (QSTR_TO_PSZ(Filename), "w"); // Simulate cases open error // static int FakeOpenError=0; // if (FakeOpenError++ == 2) // pAewf->pCurrentSegmentFile = nullptr; if (pAewf->pCurrentSegmentFile == nullptr) CHK (ERROR_AEWF_CANNOT_CREATE_FILE) pAewf->SegmentFilenameList += Filename; // Reset fields related to current segment file // -------------------------------------------- pAewf->ChunkBaseOffset = 0; pAewf->CurrentSectionSectorSeekPos = 0; pAewf->CurrentSectionSectorContentSize = 0; pAewf->ChunkOffsets = 0; // Write file header // ----------------- pAewf->FileHeaderCache.SegmentNumber = qToLittleEndian ((ushort)pAewf->SegmentFiles); CHK (AewfWriteFile (pAewf, &pAewf->FileHeaderCache, sizeof (pAewf->FileHeaderCache))) return NO_ERROR; } static APIRET AewfCloseFile (t_pAewf pAewf) { FILE *pCurrentSegmentFile = pAewf->pCurrentSegmentFile; int rc, err; if (pCurrentSegmentFile == nullptr) CHK (ERROR_AEWF_NO_FILE_OPEN) pAewf->pCurrentSegmentFile = nullptr; rc = fflush (pCurrentSegmentFile); if (rc) { err = errno; LOG_ERROR ("fflush returned %d (errno %d - %s)", rc, err, strerror(err)); (void) UtilClose (pCurrentSegmentFile); CHK (ERROR_AEWF_CANNOT_FLUSH_FILE) } rc = UtilClose (pCurrentSegmentFile); if (rc) { err = errno; LOG_ERROR ("UtilClose returned %d (errno %d - %s)", rc, err, strerror(err)); CHK (ERROR_AEWF_CANNOT_CLOSE_FILE) } // Simulate cases close error // static int FakeCloseError=0; // if (FakeCloseError++ == 2) // CHK (ERROR_AEWF_CANNOT_CLOSE_FILE) return NO_ERROR; } static APIRET AewfWriteSection (t_pAewf pAewf, const char *pName, const void *pData, quint64 Len) { t_AewfSection Section; memset (Section.Padding, 0, sizeof (Section.Padding)); memset (Section.Name , 0, sizeof (Section.Name )); strcpy (Section.Name, pName); if ((pData==nullptr) && (Len==0)) { Section.NextSectionOffset = qToLittleEndian (AewfGetCurrentSeekPos(pAewf)); // Sections "next" and "done", the only ones without Section.SectionSize = 0; // additional data, refer to themselves and have size set to 0 } else { Section.NextSectionOffset = qToLittleEndian (AewfGetCurrentSeekPos(pAewf) + sizeof (t_AewfSection) + Len); Section.SectionSize = qToLittleEndian (sizeof (t_AewfSection) + Len); } Section.CRC = qToLittleEndian (AewfCRC (&Section, offsetof (t_AewfSection, CRC))); CHK (AewfWriteFile (pAewf, &Section, sizeof (t_AewfSection))) if (pData && Len) CHK (AewfWriteFile (pAewf, pData, Len)) return NO_ERROR; } static APIRET AewfWriteSectionHeader (t_pAewf pAewf) // Writes the sections header2, header2 and header alltogether { QString HeaderData; time_t NowT; int Utf16Codes, i; ushort *pArr; ulong ArrLen; void *pCompressed; ulong CompressedLen; const ushort *pUtf16; APIRET rc; QByteArray ByteArr; QString TimeBuff; struct tm TM; time (&NowT); localtime_r (&NowT, &TM); // Generate 2 sections "header2" // ----------------------------- HeaderData = QString ("3\nmain\n"); // 1 2 HeaderData += QString ("a\tc\tn\te\tt\tmd\tsn\tav\tov\tm\tu\tp\tdc\n"); // 3 HeaderData += QString ("%1\t%2\t%3\t%4\t%5\t%6\t%7\t%8\t%9\t%10\t%11\t\t\n") .arg(pAewf->Description) .arg(pAewf->CaseNumber) .arg(pAewf->EvidenceNumber) .arg(pAewf->Examiner) .arg(pAewf->Notes) .arg(pAewf->DeviceModel) .arg(pAewf->SerialNumber) .arg(pAewf->ImagerVersion) .arg(pAewf->OSVersion) .arg(NowT) .arg(NowT); // 4 HeaderData += QString ("\nsrce\n0\t1\n"); // 5 6 7 HeaderData += QString ("p\tn\tid\tev\ttb\tlo\tpo\tah\tgu\taq\n"); // 8 HeaderData += QString ("0\t0\n"); // 9 HeaderData += QString ("\t\t\t\t\t-1\t-1\t\t\t\n"); // 10 HeaderData += QString ("\nsub\n0\t1\n"); // 11 12 13 HeaderData += QString ("p\tn\tid\tnu\tco\tgu\n"); // 14 HeaderData += QString ("0\t0\n\t\t\t\t1\t\n"); // 15 16 pUtf16 = HeaderData.utf16(); Utf16Codes=0; while (pUtf16[Utf16Codes] != 0) Utf16Codes++; ArrLen = (Utf16Codes+1)*sizeof(ushort); pArr = (ushort *) UTIL_MEM_ALLOC (ArrLen); // +1 for BOM pArr[0] = qToLittleEndian((ushort)0xFEFF); // BOM for (i=0; iCaseNumber) .arg(pAewf->EvidenceNumber) .arg(pAewf->Description) .arg(pAewf->Examiner) .arg(pAewf->Notes) .arg(pAewf->ImagerVersion) .arg(pAewf->OSVersion) .arg(TimeBuff) .arg(TimeBuff); // 4 ByteArr = HeaderData.toLatin1(); CompressedLen = UtilGetMaxZcompressedBufferSize (ByteArr.length()); pCompressed = UTIL_MEM_ALLOC (CompressedLen); CHK (AewfCompress (pCompressed, &CompressedLen, ByteArr.constData(), ByteArr.length())) rc = AewfWriteSection (pAewf, AEWF_SECTIONNAME_HEADER, pCompressed, CompressedLen); UTIL_MEM_FREE (pCompressed); CHK (rc) return NO_ERROR; } static APIRET AewfWriteSectionVolume (t_Aewf *pAewf, bool NameVolume=true) { t_AewfSectionVolumeContents VolumeContents; quint64 Chunks; Chunks = pAewf->DeviceSize / pAewf->ChunkSize; if (pAewf->DeviceSize % pAewf->ChunkSize) Chunks++; memset (&VolumeContents, 0, sizeof(VolumeContents)); VolumeContents.MediaType = qToLittleEndian ((uchar)pAewf->MediaType); VolumeContents.ChunkCount = qToLittleEndian ((uint) Chunks); VolumeContents.SectorsPerChunk = qToLittleEndian ((uint) (pAewf->ChunkSize / pAewf->SectorSize)); VolumeContents.BytesPerSector = qToLittleEndian ((uint) pAewf->SectorSize); VolumeContents.SectorCount = qToLittleEndian ((quint64) pAewf->DeviceSize / pAewf->SectorSize); VolumeContents.MediaFlags = qToLittleEndian ((uchar) (pAewf->MediaFlags | AEWF_MEDIAFLAGS_IMAGE)); VolumeContents.CompressionLevel = qToLittleEndian ((uchar) AewfEwfCompressionLevel); VolumeContents.ErrorBlockSize = qToLittleEndian ((uint) 1); VolumeContents.Checksum = qToLittleEndian (AewfCRC (&VolumeContents, offsetof(t_AewfSectionVolumeContents, Checksum))); if (NameVolume) CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_VOLUME, &VolumeContents, sizeof(VolumeContents))) else CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_DATA , &VolumeContents, sizeof(VolumeContents))) return NO_ERROR; } static APIRET AewfFinishSectionSectors (t_Aewf *pAewf) { CHK (AewfSetCurrentSeekPos (pAewf, pAewf->CurrentSectionSectorSeekPos)) CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_SECTORS, nullptr, pAewf->CurrentSectionSectorContentSize)) CHK (AewfSetCurrentSeekPos (pAewf, AEWF_SEEK_END)) pAewf->CurrentSectionSectorSeekPos = 0; pAewf->CurrentSectionSectorContentSize = 0; return NO_ERROR; } static APIRET AewfWriteSectionTable (t_Aewf *pAewf) { t_AewfSectionTableContents *pTableContents; uint TableContentsSize; quint64 OffsetArrSize; uint *pCRC2; OffsetArrSize = pAewf->ChunkOffsets * sizeof (unsigned int); TableContentsSize = sizeof (t_AewfSectionTableContents) + OffsetArrSize; pTableContents = (t_AewfSectionTableContents *) UTIL_MEM_ALLOC (TableContentsSize); memset (pTableContents, 0, sizeof(t_AewfSectionTableContents)); pTableContents->Offsets = qToLittleEndian (pAewf->ChunkOffsets ); pTableContents->BaseOffset = qToLittleEndian (pAewf->ChunkBaseOffset); pTableContents->CRC1 = qToLittleEndian (AewfCRC(pTableContents, offsetof(t_AewfSectionTableContents, CRC1))); memcpy (&pTableContents->OffsetArr[0], &pAewf->ChunkOffsetArr[0], OffsetArrSize); // pAewf->ChunkOffsetArr already is in little endian! #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" pCRC2 = (unsigned int *) (&pTableContents->OffsetArr[0] + pAewf->ChunkOffsets); #pragma GCC diagnostic pop *pCRC2 = qToLittleEndian (AewfCRC(pTableContents->OffsetArr, OffsetArrSize)); CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_TABLE , pTableContents, sizeof(t_AewfSectionTableContents)+OffsetArrSize)) CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_TABLE2, pTableContents, sizeof(t_AewfSectionTableContents)+OffsetArrSize)) UTIL_MEM_FREE (pTableContents); memset (pAewf->ChunkOffsetArr, 0, sizeof(pAewf->ChunkOffsetArr)); pAewf->ChunkOffsets = 0; pAewf->ChunkBaseOffset = 0; return NO_ERROR; } static APIRET AewfWriteSectionError (t_Aewf *pAewf, QList &BadSectors) { t_AewfSectionErrorContents *pErrorContents; uint *pCRC2; uint Entries; uint SectionSize; quint64 i, Count; quint64 From, To, Next; Count = BadSectors.count(); if (Count == 0) return NO_ERROR; pErrorContents = (t_AewfSectionErrorContents *) UTIL_MEM_ALLOC (sizeof(t_AewfSectionErrorContents)); memset (pErrorContents, 0, sizeof(t_AewfSectionErrorContents)); Entries = 0; i = 0; while (iErrorArr[Entries-1].FirstSector = qToLittleEndian (From); pErrorContents->ErrorArr[Entries-1].NumberOfSectors = qToLittleEndian (To - From + 1); } pCRC2 = (unsigned int *) &pErrorContents->ErrorArr[Entries]; pErrorContents->NumberOfErrors = qToLittleEndian (Entries); pErrorContents->CRC1 = qToLittleEndian (AewfCRC (pErrorContents, offsetof (t_AewfSectionErrorContents, CRC1))); *pCRC2 = qToLittleEndian (AewfCRC (&pErrorContents->ErrorArr[0], Entries * sizeof (t_AewfSectionErrorEntry))); CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_ERROR2, pErrorContents, SectionSize)) return NO_ERROR; } static APIRET AewfWriteSectionHash (t_Aewf *pAewf, const uchar *pMD5) { t_AewfSectionHashContents HashContents; memset (&HashContents, 0, sizeof(HashContents)); memcpy (HashContents.MD5, pMD5, sizeof(HashContents.MD5)); HashContents.CRC = qToLittleEndian (AewfCRC (&HashContents, offsetof (t_AewfSectionHashContents, CRC))); CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_HASH, &HashContents, sizeof(HashContents))) return NO_ERROR; } static APIRET AewfWriteSectionDigest (t_Aewf *pAewf, const uchar *pMD5, const uchar *pSHA1) { t_AewfSectionDigestContents DigestContents; memset (&DigestContents, 0, sizeof(DigestContents)); memcpy (DigestContents.MD5 , pMD5 , sizeof(DigestContents.MD5 )); memcpy (DigestContents.SHA1, pSHA1, sizeof(DigestContents.SHA1)); DigestContents.CRC = qToLittleEndian (AewfCRC (&DigestContents, offsetof (t_AewfSectionDigestContents, CRC))); CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_DIGEST, &DigestContents, sizeof(DigestContents))) return NO_ERROR; } static APIRET AewfWriteSectionNext (t_Aewf *pAewf) { CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_NEXT, nullptr, 0)) return NO_ERROR; } static APIRET AewfWriteSectionDone (t_Aewf *pAewf) { CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_DONE, nullptr, 0)) return NO_ERROR; } // --------------------- // API functions // --------------------- APIRET AewfOpen (t_pAewf *ppAewf, const char *pFilename, unsigned long long DeviceSize, unsigned long long SegmentSize, unsigned int ChunkSize , unsigned int SectorSize, t_AewfMediaType MediaType, t_AewfMediaFlags MediaFlags, QString Description, QString CaseNumber, QString EvidenceNumber, QString Examiner, QString Notes, QString DeviceModel, QString SerialNumber, QString ImagerVersion, QString OSVersion) { *ppAewf = new t_Aewf; (*ppAewf)->SegmentFilename = pFilename; (*ppAewf)->DeviceSize = DeviceSize; (*ppAewf)->SegmentSize = SegmentSize; (*ppAewf)->ChunkSize = ChunkSize; (*ppAewf)->SectorSize = SectorSize; (*ppAewf)->MediaType = MediaType; (*ppAewf)->MediaFlags = MediaFlags; (*ppAewf)->Description = Description; (*ppAewf)->CaseNumber = CaseNumber; (*ppAewf)->EvidenceNumber = EvidenceNumber; (*ppAewf)->Examiner = Examiner; (*ppAewf)->Notes = Notes; (*ppAewf)->DeviceModel = DeviceModel; (*ppAewf)->SerialNumber = SerialNumber; (*ppAewf)->ImagerVersion = ImagerVersion; (*ppAewf)->OSVersion = OSVersion; CHK (AewfCreateFile (*ppAewf)) CHK (AewfWriteSectionHeader (*ppAewf)) CHK (AewfWriteSectionVolume (*ppAewf)) return NO_ERROR; } APIRET AewfPreprocess (t_pAewfPreprocess pPreprocess, uchar *pDataIn, unsigned int DataLenIn, uchar *pDataOut, unsigned int DataLenOut) { // t_pAewfPreprocess pPreProcess; int rc; uLongf LenOut; uint *pCRC; uint MaxLenOut; #ifdef AEWF_COMPRESSION_DEBUG static bool FirstCall=true; static int CharCount=0; #endif // *ppPreprocess = nullptr; // pPreProcess = (t_pAewfPreprocess) UTIL_MEM_ALLOC(sizeof(t_AewfPreprocess)); // if (pPreProcess == nullptr) // CHK (ERROR_AEWF_MEMALLOC_FAILED) // *ppPreprocess = pPreProcess; pPreprocess->Compressed = false; if (CONFIG(EwfCompression) != LIBEWF_COMPRESSION_NONE) { LenOut = DataLenOut; rc = AewfCompress (pDataOut, &LenOut, pDataIn, DataLenIn); pPreprocess->DataLenOut = LenOut; MaxLenOut = (unsigned int) (DataLenIn * CONFIG(EwfCompressionThreshold)); MaxLenOut = (unsigned int) GETMIN (DataLenIn-1, MaxLenOut); // Avoid potential float operation side effects #ifdef AEWF_COMPRESSION_DEBUG if (FirstCall) { printf ("\nAEWF -- Chunk size: %u" , DataLenIn); printf ("\nAEWF -- Min. required compression ratio: %1.3f (EwfCompressionThreshold)" , CONFIG(EwfCompressionThreshold)); printf ("\nAEWF -- Max. compressed size: %u (EwfCompressionThreshold * ChunkSize)", MaxLenOut); printf ("\nAEWF -- List of chunks (. = not compressed because compressed data is larger than uncompressed data,\n" " M = not compressed because compressed data is larger max. compressed size,\n" " c = Compressed\n"); FirstCall = false; } #endif if (rc != NO_ERROR) LOG_ERROR ("compress2 returned %d - treating this block as uncompressed in order to resume", rc) else pPreprocess->Compressed = (LenOut <= MaxLenOut); } if (!pPreprocess->Compressed) // Add the CRC to the end of the non-compressed data. The FIFO buffer is { // big enough for this (see extra space calculation) pCRC = (unsigned int *) &pDataIn[DataLenIn]; *pCRC = qToLittleEndian (AewfCRC (pDataIn, DataLenIn)); pPreprocess->DataLenOut = DataLenIn + sizeof (unsigned int); #ifdef AEWF_COMPRESSION_DEBUG if (LenOut < DataLenIn) printf("M"); else printf("."); #endif } #ifdef AEWF_COMPRESSION_DEBUG else { printf("c"); } if (++CharCount == 80) { printf ("\n"); CharCount=0; } #endif return NO_ERROR; } APIRET AewfWrite (t_Aewf *pAewf, t_AewfPreprocess *pPreprocess, const uchar *pData, unsigned int DataLen) { quint64 SectionTableSize; quint64 MinRemainingSize; uint OffsetArrEntry; uint NewLen; if (pAewf->pCurrentSegmentFile == nullptr) CHK (ERROR_AEWF_NO_FILE_OPEN) // printf ("\nChunk: %d %u bytes - %s", pAewf->ChunkOffsets, DataLen, pPreprocess->Compressed ? "compressed" : "uc"); // Check if enough space remaining in current segment file // ------------------------------------------------------- SectionTableSize = sizeof (t_AewfSection) + sizeof (t_AewfSectionTableContents) + (pAewf->ChunkOffsets + 1)* sizeof(unsigned int); MinRemainingSize = DataLen + 2 * SectionTableSize // Sections "table" and "table2" + sizeof (t_AewfSection) + sizeof (t_AewfSectionVolumeContents) // Section "data" + sizeof (t_AewfSection) + sizeof (t_AewfSectionHashContents ) // Section "hash" + sizeof (t_AewfSection) + sizeof (t_AewfSectionDigestContents) // Section "digest" + sizeof (t_AewfSection) // Section "done" + sizeof (t_AewfSection) + // In case we need to start a new section "sectors" (see below), + 2 * sizeof (t_AewfSection) + sizeof (t_AewfSectionTableContents); // which would also require additonal sections "table" and "table2" if ((pAewf->SegmentSize - AewfGetCurrentSeekPos(pAewf)) < MinRemainingSize) { // Close the current segment and open a new one CHK (AewfFinishSectionSectors(pAewf)) CHK (AewfWriteSectionTable (pAewf)) CHK (AewfWriteSectionNext (pAewf)) CHK (AewfCloseFile (pAewf)) CHK (AewfCreateFile (pAewf)) CHK (AewfWriteSectionVolume (pAewf, false)) } // Check if current sector section or offset table is full // ------------------------------------------------------- NewLen = pAewf->CurrentSectionSectorContentSize + DataLen; if (pAewf->ChunkOffsets) // We have to add the offset of the first chunk, which normally is 76 (see also comment related to NewLen += pAewf->ChunkOffsetArr[0] & ~AEWF_COMPRESSED_CHUNK; // ewfacquire behaviour below). However, we only know this for sure after a first chunk has been written. // This is no problem, as the first chunk will never be so big that it would touch the 2GB limit. if ((NewLen > AEWF_MAX_SIZE_SECTIONSECTOR) || // Unlike libewf, we prefer to have the whole section "sectors" <= 2GiB (libewf allows to have the (pAewf->ChunkOffsets == AEWF_MAX_CHUNK_OFFSETS)) // last chunk start below the 2GiB limit and span beyond). { // printf ("\nNew table -- %llu %d %u %u", pAewf->CurrentSectionSectorContentSize, DataLen, NewLen, pAewf->ChunkOffsets); CHK (AewfFinishSectionSectors (pAewf)) CHK (AewfWriteSectionTable (pAewf)) } // Write the data // -------------- // Create a new section "sectors" if necessary if (pAewf->CurrentSectionSectorContentSize == 0) { pAewf->CurrentSectionSectorSeekPos = AewfGetCurrentSeekPos(pAewf); pAewf->ChunkBaseOffset = AewfGetCurrentSeekPos(pAewf); // We also could do this after section "sectors" has been written (thus gaining 76 bytes), but this mimics ewfacquire behaviour CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_SECTORS, nullptr, 0)) } OffsetArrEntry = AewfGetCurrentSeekPos(pAewf) - pAewf->ChunkBaseOffset; if (pPreprocess->Compressed) OffsetArrEntry |= AEWF_COMPRESSED_CHUNK; // printf ("\nWrite chunk %d -- %d bytes", pAewf->ChunkOffsets, DataLen); pAewf->ChunkOffsetArr[pAewf->ChunkOffsets++] = qToLittleEndian (OffsetArrEntry); CHK (AewfWriteFile (pAewf, pData, DataLen)) pAewf->CurrentSectionSectorContentSize += DataLen; // UTIL_MEM_FREE (pPreprocess); return NO_ERROR; } APIRET AewfClose (t_pAewf *ppAewf, QList &BadSectors, const uchar *pMD5, const uchar *pSHA1, const uchar */*pSHA256*/) { t_Aewf *pAewf = *ppAewf; if (pAewf->pCurrentSegmentFile) // This must be checked as pCurrentSegmentFile might be zero if an error occurred (for example fwrite or fclose error during acquisition) { if (pAewf->CurrentSectionSectorContentSize) // Is there an unfinished section "sectors"? { CHK (AewfFinishSectionSectors (pAewf)) CHK (AewfWriteSectionTable (pAewf)) } if (pAewf->SegmentFiles == 1) // Add section "data" if there was only 1 segment file CHK (AewfWriteSectionVolume (pAewf, false)) if (BadSectors.count()) CHK (AewfWriteSectionError (pAewf, BadSectors)) CHK (AewfWriteSectionDigest (pAewf, pMD5, pSHA1)) CHK (AewfWriteSectionHash (pAewf, pMD5)) CHK (AewfWriteSectionDone (pAewf)) CHK (AewfCloseFile (pAewf)) } delete pAewf; *ppAewf = nullptr; return NO_ERROR; } // --------------------- // API read functions // --------------------- #define CHK_LOG(pAewf, rc) \ { \ int ChkRc = (rc); \ if (ChkRc != NO_ERROR) \ LOG_INFO ("AEWF verification error in file %s", QSTR_TO_PSZ(pAewf->SegmentFilenameList[pAewf->SegmentFiles-1])) \ CHK (ChkRc) \ } static APIRET AewfReallocVerifyBuffer (t_Aewf *pAewf, uint Len) { if (pAewf->VerifyBufferLen < Len) { pAewf->pVerifyBuffer = (uchar *) realloc (pAewf->pVerifyBuffer, Len); if (pAewf->pVerifyBuffer == nullptr) CHK (ERROR_AEWF_MEMALLOC_FAILED) pAewf->VerifyBufferLen = Len; } return NO_ERROR; } APIRET AewfOpen (t_pAewf *ppAewf, const char *pFilename) { t_Aewf *pAewf; *ppAewf = new t_Aewf; pAewf = *ppAewf; pAewf->SegmentFilename = pFilename; return NO_ERROR; } APIRET AewfClose (t_pAewf *ppAewf) { t_Aewf *pAewf; pAewf = *ppAewf; if (pAewf->pVerifyBuffer) free (pAewf->pVerifyBuffer); // Must released with free, as realloc is used for allocating it delete (pAewf); *ppAewf = nullptr; return NO_ERROR; } static APIRET AewfReadFile (t_Aewf *pAewf, void *pData, uint DataLen, bool DisableMD5=false) { if (fread (pData, DataLen, 1, pAewf->pCurrentSegmentFile) != 1) CHK_LOG (pAewf, ERROR_AEWF_CANNOT_READ_DATA) if (CONFIG(CalcImageFileMD5) && !DisableMD5) CHK (HashMD5Append (&pAewf->CurrentSegmentHashContextMD5, pData, DataLen)) return NO_ERROR; } static APIRET AewfVerifyFileHeader (t_Aewf *pAewf) { t_AewfFileHeader FileHeader; CHK (AewfReadFile (pAewf, &FileHeader, sizeof(FileHeader))) if (qFromLittleEndian (FileHeader.SegmentNumber) != pAewf->SegmentFiles) CHK_LOG (pAewf, ERROR_AEWF_WRONG_SEGMENT_NUMBER) return NO_ERROR; } static APIRET AewfReadSection (t_Aewf *pAewf, t_AewfSection *pSection, bool DisableMD5=false) { unsigned int CRC; CHK (AewfReadFile (pAewf, pSection, sizeof(t_AewfSection), DisableMD5)) // printf ("\nsection %s ", pSection->Name); CRC = AewfCRC (pSection, offsetof (t_AewfSection, CRC)); pSection->NextSectionOffset = qFromLittleEndian (pSection->NextSectionOffset); pSection->SectionSize = qFromLittleEndian (pSection->SectionSize ); pSection->CRC = qFromLittleEndian (pSection->CRC ); if (CRC != pSection->CRC) CHK_LOG (pAewf, ERROR_AEWF_WRONG_SECTION_CRC) // printf (" -- ok"); return NO_ERROR; } static APIRET AewfCheckSection (t_Aewf *pAewf, bool *pIsSectors, bool *pIsEof, bool *pIsEoi, quint64 *pNextSectionSeekPos) { t_AewfSection Section; int RemainingLen; bool IsSectors; bool IsEof; bool IsEoi; char EofTest; CHK (AewfReadSection (pAewf, &Section)) IsSectors = (strcmp(Section.Name, AEWF_SECTIONNAME_SECTORS) == 0); IsEof = (strcmp(Section.Name, AEWF_SECTIONNAME_NEXT ) == 0); IsEoi = (strcmp(Section.Name, AEWF_SECTIONNAME_DONE ) == 0); if (IsEof || IsEoi) { // In this case, there should be no more bytes. Lets try to if (fread (&EofTest, 1, 1, pAewf->pCurrentSegmentFile) == 1) // read 1 more byte - this is one of the rare places where CHK_LOG (pAewf, ERROR_AEWF_DATA_FOLLOWING_LAST_SECTION) // successful reading leads to an error :-) } if (!IsSectors && !IsEof && !IsEoi) // Read remaining section data for correct segment MD5 calculation { RemainingLen = Section.SectionSize - sizeof(Section); if (RemainingLen) { if (RemainingLen < 0) CHK_LOG (pAewf, ERROR_AEWF_WRONG_SECTION_LENGTH) // printf ("\nCurrentSeekPos %llu - Remaining %u", AewfGetCurrentSeekPos(pAewf), RemainingLen); CHK (AewfReallocVerifyBuffer(pAewf, RemainingLen)) CHK (AewfReadFile (pAewf, pAewf->pVerifyBuffer, RemainingLen)) } } if (pIsSectors) *pIsSectors = IsSectors; if (pIsEof) *pIsEof = IsEof; if (pIsEoi) *pIsEoi = IsEoi; if (pNextSectionSeekPos) *pNextSectionSeekPos = Section.NextSectionOffset; return NO_ERROR; } static APIRET AewfReadTable (t_Aewf *pAewf) { t_AewfSection Section; t_AewfSectionTableContents TableContents; uint CalcCRC1; uint CalcCRC2, StoredCRC2; uint OffsetArrSize; quint64 DummyOffset; DummyOffset = AewfGetCurrentSeekPos(pAewf); CHK (AewfReadSection (pAewf, &Section, true)) if (strcmp (Section.Name, AEWF_SECTIONNAME_TABLE) != 0) CHK_LOG (pAewf, ERROR_AEWF_EXPECTED_SECTION_TABLE) CHK (AewfReadFile (pAewf, &TableContents, offsetof (t_AewfSectionTableContents, OffsetArr), true)) CalcCRC1 = AewfCRC(&TableContents, offsetof(t_AewfSectionTableContents, CRC1)); TableContents.Offsets = qFromLittleEndian (TableContents.Offsets ); TableContents.BaseOffset = qFromLittleEndian (TableContents.BaseOffset); TableContents.CRC1 = qFromLittleEndian (TableContents.CRC1 ); if (TableContents.Offsets > AEWF_MAX_CHUNK_OFFSETS) CHK_LOG (pAewf, ERROR_AEWF_TOO_MANY_TABLE_OFFSETS) if (CalcCRC1 != TableContents.CRC1) CHK_LOG (pAewf, ERROR_AEWF_TABLE_WRONG_CRC1) pAewf->CurrentChunkOffset = 0; pAewf->ChunkOffsets = TableContents.Offsets; pAewf->ChunkBaseOffset = TableContents.BaseOffset; OffsetArrSize = TableContents.Offsets * sizeof (unsigned int); CHK (AewfReadFile (pAewf, &pAewf->ChunkOffsetArr[0], OffsetArrSize , true)) CHK (AewfReadFile (pAewf, &StoredCRC2 , sizeof (StoredCRC2), true)) StoredCRC2 = qFromLittleEndian (StoredCRC2); CalcCRC2 = AewfCRC (&pAewf->ChunkOffsetArr[0], OffsetArrSize); if (CalcCRC2 != StoredCRC2) CHK_LOG (pAewf, ERROR_AEWF_TABLE_WRONG_CRC2) pAewf->ChunkOffsetArr[TableContents.Offsets] = qToLittleEndian ((uint)(DummyOffset - TableContents.BaseOffset)); return NO_ERROR; } // AewfReadNextChunk: Besides reading data chunk, the function returns image filenames and image file hashes "from time to time", i.e. when // finishing with the data found in a segment file. If ever this is the case, all 3 params (pSegmentFilename, pMD5Digest and pMD5Valid) are correctly // filled in. If not, SegmentFilename simply is empty. // AewfReadNextChunk must be called again and again until pFinished is set to true, even if no data is returned. This must be done in order to have // the function return all segment file names with correct MD5 values. APIRET AewfReadNextChunk (t_Aewf *pAewf, uchar *pData, uint *pDataLen, QString *pSegmentFilename, t_pHashMD5Digest pMD5Digest, bool *pMD5valid, bool *pFinished) { uint Offset; uint NextOffset; uint ReadLen; uint CalcCRC, StoredCRC; quint64 SavedSeekPos; quint64 NextSectionSeekPos; quint64 FullOffset; bool Compressed; bool IsSectors = false; bool IsEof = false; // end of file bool IsEoi = false; // end of image APIRET rc; uLongf DataLen; *pSegmentFilename = QString(); *pMD5valid = false; *pFinished = false; // Open segment file if necessary and check file header // ---------------------------------------------------- if (!pAewf->pCurrentSegmentFile) { QString Extension, Filename; // Open next segment file // ---------------------- pAewf->SegmentFiles++; Extension = AewfGetExtension (pAewf->SegmentFiles); Filename = pAewf->SegmentFilename + "." + Extension; pAewf->SegmentFilenameList += Filename; // printf ("\nOpening %s", QSTR_TO_PSZ(Filename)); pAewf->pCurrentSegmentFile = fopen64 (QSTR_TO_PSZ(Filename), "r"); if (pAewf->pCurrentSegmentFile == nullptr) CHK_LOG (pAewf, ERROR_AEWF_CANNOT_OPEN_FILE) if (CONFIG(CalcImageFileMD5)) CHK (HashMD5Init (&pAewf->CurrentSegmentHashContextMD5)) CHK (AewfVerifyFileHeader (pAewf)) memset (pAewf->ChunkOffsetArr, 0, sizeof(pAewf->ChunkOffsetArr)); pAewf->ChunkBaseOffset = 0; pAewf->ChunkOffsets = 0; pAewf->CurrentChunkOffset = 0; } // Check if still chunks remain; search next section "sectors" if // not; close segment file if no other section "sectors" is present // ----------------------------------------------------------------- if (pAewf->CurrentChunkOffset == pAewf->ChunkOffsets) { do { CHK (AewfCheckSection (pAewf, &IsSectors, &IsEof, &IsEoi, &NextSectionSeekPos)) // Loop through sections until a new section "sectors" is found } while (!IsSectors && !IsEof && !IsEoi); if (IsEof || IsEoi) { int ret = UtilClose (pAewf->pCurrentSegmentFile); if (ret) { int err = errno; LOG_ERROR ("UtilClose returned %d (errno %d - %s)", ret, err, strerror(err)); CHK_LOG (pAewf, ERROR_AEWF_CANNOT_CLOSE_FILE) } pAewf->pCurrentSegmentFile = nullptr; *pDataLen = 0; *pSegmentFilename = pAewf->SegmentFilenameList[pAewf->SegmentFiles-1]; *pFinished = IsEoi; if (CONFIG(CalcImageFileMD5)) { CHK (HashMD5Digest (&pAewf->CurrentSegmentHashContextMD5, pMD5Digest)) *pMD5valid = true; } return NO_ERROR; } SavedSeekPos = AewfGetCurrentSeekPos(pAewf); CHK (AewfSetCurrentSeekPos (pAewf, NextSectionSeekPos)) CHK (AewfReadTable (pAewf)) CHK (AewfSetCurrentSeekPos (pAewf, SavedSeekPos)) } // Read next chunk // --------------- // printf ("\nReading chunk %u", pAewf->CurrentChunkOffset); Offset = qFromLittleEndian (pAewf->ChunkOffsetArr[pAewf->CurrentChunkOffset++]); NextOffset = qFromLittleEndian (pAewf->ChunkOffsetArr[pAewf->CurrentChunkOffset ]); Compressed = ((Offset & AEWF_COMPRESSED_CHUNK) != 0); Offset &= ~AEWF_COMPRESSED_CHUNK; NextOffset &= ~AEWF_COMPRESSED_CHUNK; ReadLen = NextOffset - Offset; FullOffset = pAewf->ChunkBaseOffset + Offset; // printf (" -- size %u", ReadLen); if (AewfGetCurrentSeekPos(pAewf) != FullOffset) // Check if table entry is correct { LOG_INFO ("AEWF section table: Offset is %llu, current seek pos is %llu", FullOffset, AewfGetCurrentSeekPos(pAewf)) CHK_LOG (pAewf, ERROR_AEWF_TABLE_CORRUPT) } if (!Compressed) { if (ReadLen > *pDataLen) { LOG_INFO ("ChunkBaseOffset=%llu CurrentChunkOffset=%u", pAewf->ChunkBaseOffset, pAewf->CurrentChunkOffset) LOG_INFO ("ReadLen=%u DataLen=%u" , ReadLen, *pDataLen) LOG_INFO ("Offset=%u NextOffset=%u" , Offset, NextOffset) CHK_LOG (pAewf, ERROR_AEWF_VERIFY_BUFFER_TOO_SMALL) } CHK (AewfReadFile (pAewf, pData, ReadLen)) *pDataLen = ReadLen - sizeof (unsigned int); // CRC is at the end of uncompressed data CalcCRC = AewfCRC (pData, *pDataLen); StoredCRC = qFromLittleEndian (* ((unsigned int *) (&pData[*pDataLen]))); if (CalcCRC != StoredCRC) CHK_LOG (pAewf, ERROR_AEWF_DATA_CRC_ERROR) } else { CHK (AewfReallocVerifyBuffer (pAewf, ReadLen)) CHK (AewfReadFile (pAewf, pAewf->pVerifyBuffer, ReadLen)) DataLen = *pDataLen; rc = AewfUncompress (pData, &DataLen, pAewf->pVerifyBuffer, ReadLen); *pDataLen = DataLen; if (rc != NO_ERROR) CHK_LOG (pAewf, rc) } return NO_ERROR; } // ----------------------- // Misc. functions // ----------------------- unsigned int AewfPreprocessExtraSpace (uint FifoBlockSize) { // AEWF needs some extra FIFO block buffer space in order to do the compression or to add the CRC // at the end of the uncompressed data. We take the max. value of both in order to be sure that // enough space is available for both. uint ExtraZ = UtilGetMaxZcompressedBufferSize (FifoBlockSize) - FifoBlockSize; uint ExtraUncompressedCRC = sizeof (unsigned int); return GETMAX (ExtraZ, ExtraUncompressedCRC); } APIRET AewfInit (void) { CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_MEMALLOC_FAILED )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_CANNOT_CREATE_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_CANNOT_WRITE_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_ANOTHER_FILE_STILL_OPEN )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_NO_FILE_OPEN )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_CANNOT_FLUSH_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_CANNOT_CLOSE_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_INVALID_COMPRESSION_LEVEL )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_COMPRESSION_FAILED )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_CANNOT_SEEK )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_CANNOT_OPEN_FILE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_TABLE_CORRUPT )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_VERIFY_BUFFER_TOO_SMALL )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_CANNOT_READ_DATA )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_DATA_CRC_ERROR )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_UNCOMPRESS_FAILED )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_UNCOMPRESS_ZEROBLOCK_FAILED)) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_WRONG_SEGMENT_NUMBER )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_WRONG_SECTION_CRC )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_ENDING_SECTION_MISSING )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_EXPECTED_SECTION_TABLE )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_TABLE_WRONG_CRC1 )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_TABLE_WRONG_CRC2 )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_TOO_MANY_TABLE_OFFSETS )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_DATA_FOLLOWING_LAST_SECTION)) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_WRONG_SECTION_LENGTH )) CHK (TOOL_ERROR_REGISTER_CODE (ERROR_AEWF_INVALID_EWFNAMING )) // Compresison levels // ------------------ switch (CONFIG(EwfCompression)) { case LIBEWF_COMPRESSION_NONE : AewfZipCompressionLevel = 0; AewfEwfCompressionLevel = 0x00; break; case LIBEWF_COMPRESSION_EMPTY: AewfZipCompressionLevel = 0; AewfEwfCompressionLevel = 0x00; break; case LIBEWF_COMPRESSION_FAST : AewfZipCompressionLevel = 1; AewfEwfCompressionLevel = 0x01; break; case LIBEWF_COMPRESSION_BEST : AewfZipCompressionLevel = 9; AewfEwfCompressionLevel = 0x02; break; default: CHK_EXIT (ERROR_AEWF_INVALID_COMPRESSION_LEVEL) } // Compressed zero buffer initialisation // ------------------------------------- unsigned char *pZeroBuff; int rc; AewfZeroBlockUnCompressedLen = CONFIG (FifoBlockSizeEWF); // Alloc and initialise zero and compression buffers AewfZeroBlockCompressedLen = UtilGetMaxZcompressedBufferSize (AewfZeroBlockUnCompressedLen); pZeroBuff = (unsigned char *) malloc (AewfZeroBlockUnCompressedLen); pAewfZeroBlockCompressed = (unsigned char *) malloc (AewfZeroBlockUnCompressedLen); if ((pZeroBuff == nullptr) || (pAewfZeroBlockCompressed == nullptr)) CHK (ERROR_AEWF_MEMALLOC_FAILED) memset (pZeroBuff, 0, AewfZeroBlockUnCompressedLen); rc = compress2 ((Bytef*)pAewfZeroBlockCompressed, &AewfZeroBlockCompressedLen, (Bytef*)pZeroBuff, AewfZeroBlockUnCompressedLen, 9); // Compress zero buff if (rc != Z_OK) CHK (ERROR_AEWF_COMPRESSION_FAILED) free (pAewfZeroBlockCompressed); // Realloc compressed to the size that is really needed pAewfZeroBlockCompressed = (unsigned char *) malloc (AewfZeroBlockCompressedLen); if (pAewfZeroBlockCompressed == nullptr) CHK (ERROR_AEWF_MEMALLOC_FAILED) rc = compress2 ((Bytef*)pAewfZeroBlockCompressed, &AewfZeroBlockCompressedLen, (Bytef*)pZeroBuff, AewfZeroBlockUnCompressedLen, 9); if (rc != Z_OK) CHK (ERROR_AEWF_COMPRESSION_FAILED) free (pZeroBuff); return NO_ERROR; } APIRET AewfDeInit (void) { free (pAewfZeroBlockCompressed); return NO_ERROR; } guymager-0.8.13/aewf.h0000664000175000017500000001141514102741454012306 0ustar gjgj// **************************************************************************** // Project: GUYMAGER // **************************************************************************** // Programmer: Guy Voncken // Police Grand-Ducale // Service de Police Judiciaire // Section Nouvelles Technologies // **************************************************************************** // Module: Multithreaded AEWF (AEWF = Advanced EWF) // **************************************************************************** // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, // 2018, 2019, 2020 // Guy Voncken // // This file is part of Guymager. // // Guymager 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. // // Guymager 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 Guymager. If not, see . #ifndef AEWF_H #define AEWF_H #ifndef HASH_H #include "hash.h" #endif class t_Aewf; typedef t_Aewf *t_pAewf; typedef struct { bool Compressed; // Tells AewfWrite whether the data should be written compressed or uncompressed int DataLenOut; // If Compressed - is true: The size of the compressed data // - is false: The size of the original data + size of CRC } t_AewfPreprocess, *t_pAewfPreprocess; typedef enum { AEWF_MEDIATYPE_REMOVABLE = 0x00, AEWF_MEDIATYPE_FIXED = 0x01, AEWF_MEDIATYPE_OPTICAL = 0x03 } t_AewfMediaType; typedef enum { AEWF_MEDIAFLAGS_IMAGE = 0x01, AEWF_MEDIAFLAGS_PHYSICAL = 0x02, AEWF_MEDIAFLAGS_FASTBLOCK_USED = 0x04, AEWF_MEDIAFLAGS_TABLEAU_USED = 0x08 } t_AewfMediaFlags; // ------------------------------------ // Functions // ------------------------------------ // Write access functions // ---------------------- APIRET AewfOpen (t_pAewf *ppAewf, const char *pFilename, quint64 DeviceSize, quint64 SegmentSize, uint ChunkSize , uint SectorSize, t_AewfMediaType MediaType, t_AewfMediaFlags MediaFlags, QString Description, QString CaseNumber, QString EvidenceNumber, QString Examiner, QString Notes, QString DeviceModel, QString SerialNumber, QString ImagerVersion, QString OSVersion); APIRET AewfPreprocess ( t_pAewfPreprocess pPreprocess, uchar *pDataIn, uint DataLenIn, uchar *pDataOut, uint DataLenOut); APIRET AewfWrite (t_pAewf pAewf, t_pAewfPreprocess pPreprocess, const uchar *pData, uint DataLen); APIRET AewfClose (t_pAewf *ppAewf, QList &BadSectors, const uchar *pMD5, const uchar *pSHA1, const uchar *pSHA256); // Read access functions // --------------------- APIRET AewfOpen (t_pAewf *ppAewf, const char *pFilename); APIRET AewfReadNextChunk (t_pAewf pAewf, uchar *pData, uint *pDataLen, QString *pSegmentFilename, t_pHashMD5Digest pMD5, bool *pMD5valid, bool *pFinished); APIRET AewfClose (t_pAewf *ppAewf); // Misc. functions // --------------- uint AewfPreprocessExtraSpace (uint FifoBlockSize); APIRET AewfInit (void); APIRET AewfDeInit (void); // ------------------------------------ // Error codes // ------------------------------------ enum { ERROR_AEWF_MEMALLOC_FAILED = ERROR_BASE_AEWF + 1, ERROR_AEWF_CANNOT_CREATE_FILE, ERROR_AEWF_CANNOT_WRITE_FILE, ERROR_AEWF_ANOTHER_FILE_STILL_OPEN, ERROR_AEWF_NO_FILE_OPEN, ERROR_AEWF_CANNOT_FLUSH_FILE, ERROR_AEWF_CANNOT_CLOSE_FILE, ERROR_AEWF_INVALID_COMPRESSION_LEVEL, ERROR_AEWF_COMPRESSION_FAILED, ERROR_AEWF_CANNOT_SEEK, ERROR_AEWF_CANNOT_OPEN_FILE, ERROR_AEWF_TABLE_CORRUPT, ERROR_AEWF_VERIFY_BUFFER_TOO_SMALL, ERROR_AEWF_CANNOT_READ_DATA, ERROR_AEWF_DATA_CRC_ERROR, ERROR_AEWF_UNCOMPRESS_FAILED, ERROR_AEWF_UNCOMPRESS_ZEROBLOCK_FAILED, ERROR_AEWF_WRONG_SEGMENT_NUMBER, ERROR_AEWF_WRONG_SECTION_CRC, ERROR_AEWF_ENDING_SECTION_MISSING, ERROR_AEWF_EXPECTED_SECTION_TABLE, ERROR_AEWF_TABLE_WRONG_CRC1, ERROR_AEWF_TABLE_WRONG_CRC2, ERROR_AEWF_TOO_MANY_TABLE_OFFSETS, ERROR_AEWF_DATA_FOLLOWING_LAST_SECTION, ERROR_AEWF_WRONG_SECTION_LENGTH, ERROR_AEWF_INVALID_EWFNAMING }; #endif guymager-0.8.13/common.h0000664000175000017500000000724314102741454012660 0ustar gjgj// **************************************************************************** // Project: GUYMAGER // **************************************************************************** // Programmer: Guy Voncken // Police Grand-Ducale // Service de Police Judiciaire // Section Nouvelles Technologies // **************************************************************************** // Module: Standard include file // **************************************************************************** // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, // 2018, 2019, 2020 // Guy Voncken // // This file is part of Guymager. // // Guymager 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. // // Guymager 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 Guymager. If not, see . #ifdef LINT_CODE_CHECK #include "macros_for_lint.h" #endif #ifndef COMMON_H #define COMMON_H #ifndef ENABLE_LIBEWF #define ENABLE_LIBEWF 1 #endif //#define USE_MD5_FROM_OPENSSL //#define USE_SHA256_FROM_OPENSSL // GNU C lib definitions // --------------------- #ifndef _LARGEFILE_SOURCE #define _LARGEFILE_SOURCE 1 #endif #ifndef _FILE_OFFSET_BITS #define _FILE_OFFSET_BITS 64 #endif #ifndef _GNU_SOURCE #define _GNU_SOURCE 1 #endif #ifndef _THREAD_SAFE #define _THREAD_SAFE 1 #endif #ifndef _STDIO_H #include #endif #include #include #include "toolglobalid.h" #include "toolerror.h" #include "toollog.h" #include "tooltypes.h" #include "modules.h" #include "error.h" #define QSTR_TO_PSZ(QStr) (QStr).toLatin1().constData() extern void *pOffsetOfNullPointer; #define OFFSET_OF(Type, Element) \ ((unsigned int) &(((Type*)pOffsetOfNullPointer)->Element)) class t_Device; // As t_Device is the core structure of guymager and as it is needed typedef t_Device *t_pDevice; // all the time, it is easiest to declare it here (eventhough I don't typedef t_Device const *t_pcDevice; // like that style too much, but we won't change C++ at this time). class t_Acquisition; typedef t_Acquisition *t_pAcquisition; typedef t_Acquisition const *t_pcAcquisition; #define EWF_MULTITHREADED_COMPRESSION_CHUNK_SIZE 32768 const unsigned long long BYTES_PER_MiB = 1ULL << 20; const unsigned long long BYTES_PER_GiB = 1ULL << 30; const unsigned long long BYTES_PER_TiB = 1ULL << 40; const unsigned long long BYTES_PER_PiB = 1ULL << 50; const unsigned long long BYTES_PER_EiB = 1ULL << 60; const unsigned long long EWF_MIN_SEGMENT_SIZE = 20 * BYTES_PER_MiB; const unsigned long long EWF_MAX_SEGMENT_SIZE = 2047 * BYTES_PER_MiB; const unsigned long long EWF_MAX_SEGMENT_SIZE_EXT = LONG_LONG_MAX - 10 * BYTES_PER_PiB; // Let's keep some distance from the absolute maximum - just for safety. #define GETMAX(a,b) ((a)>(b)?(a):(b)) #define GETMIN(a,b) ((a)<(b)?(a):(b)) typedef unsigned char t_uint8; typedef unsigned short t_uint16; typedef unsigned int t_uint32; typedef unsigned long long t_uint64; typedef char t_int8; typedef short t_int16; typedef int t_int32; typedef long long t_int64; #endif guymager-0.8.13/compileinfo.h0000664000175000017500000000320214102741454013663 0ustar gjgj// **************************************************************************** // Project: GUYMAGER // **************************************************************************** // Programmer: Guy Voncken // Police Grand-Ducale // Service de Police Judiciaire // Section Nouvelles Technologies // **************************************************************************** // This external constant allows other modules to access the compilation // timestamp. The constant itself is instantiated in compileinfo.cpp which is // generated automatically when calling make. // See .pro file as well. // **************************************************************************** // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, // 2018, 2019, 2020 // Guy Voncken // // This file is part of Guymager. // // Guymager 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. // // Guymager 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 Guymager. If not, see . extern const char *pCompileInfoTimestampBuild; extern const char *pCompileInfoTimestampChangelog; extern const char *pCompileInfoVersion; guymager-0.8.13/compileinfo.sh0000775000175000017500000000151314102741454014054 0ustar gjgj#!/bin/bash echo '// Automatically generated file. See project file and compileinfo.sh for further information.' date --utc '+const char *pCompileInfoTimestampBuild = "%Y-%m-%d-%H.%M.%S UTC";' date --utc '+const char *pCompileInfoTimestampChangelog = "%Y-%m-%d-%H.%M.%S UTC";' -d "$(dpkg-parsechangelog -S Date)" # Line below: changelog figures twice because subdirectory debian is missing in Sourceforge upload # (changelog is in source code directory there). By putting it twice, it works in any case. head -qn 1 changelog debian/changelog 2>/dev/null | awk '{ Version = $2 gsub ("\\(", "", Version) gsub ("\\)", "", Version) print "const char *pCompileInfoVersion = \"" Version "\";"}' guymager-0.8.13/config.cpp0000664000175000017500000020511514102741454013166 0ustar gjgj// **************************************************************************** // Project: GUYMAGER // **************************************************************************** // Programmer: Guy Voncken // Police Grand-Ducale // Service de Police Judiciaire // Section Nouvelles Technologies // **************************************************************************** // Module: Application configuration data // **************************************************************************** // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, // 2018, 2019, 2020 // Guy Voncken // // This file is part of Guymager. // // Guymager 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. // // Guymager 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 Guymager. If not, see . #include "common.h" #include #include #include #include #include "toolcfg.h" #include "toolsysinfo.h" #include "file.h" #include "ewf.h" #include "qtutil.h" #include "util.h" #include "config.h" // ------------------------------------ // Constants // ------------------------------------ static const char * CMDLINE_OPTION_LOG = "LOG"; static const char * CMDLINE_OPTION_CFG = "CFG"; static const char * DEFAULT_LOG_FILENAME = "/var/log/guymager.log"; static const char * DEFAULT_CFG_FILENAME = "/etc/guymager/guymager.cfg"; static const char * TEMPLATE_CFG_FILENAME = "template.cfg"; static const char * CFG_SECTION_GUYMAGER = "GUYMAGER"; static const unsigned char CONFIG_DUMMY_FILL = 0xAA; static const uint CFG_MAX_COMPRESSIONTHREADS = 16; static const int CFG_MAX_LIMIT_JOBS = 4; // ------------------------------------ // Type definitions // ------------------------------------ typedef struct { t_CfgData CfgData; t_CfgBuffFont CfgBuffFont; t_CfgColumn CfgBuffColumn; t_CfgBuffColor CfgBuffColor; t_CfgBuffLocalHiddenDevice CfgBuffLocalHiddenDevice; t_CfgBuffDeviceInfoCommand CfgBuffDeviceInfoCommand; t_CfgBuffDlgAcquireField CfgBuffDlgAcquireField; t_CfgBuffDlgAcquireRule CfgBuffDlgAcquireRule; QFont * FontArr [FONTOBJECT_COUNT]; QColor * ColorArr[COLOR_COUNT]; t_CfgColumn ColumnArr[CFG_MAX_COLUMNS]; int Columns; QStringList LocalDevices; QStringList HiddenDevices; QStringList *pCurrentDeviceList; QStringList DeviceInfoCommands; t_CfgDlgAcquireFields DlgAcquireFields; t_CfgDlgAcquireRules DlgAcquireRules; QStringList DlgAcquireFieldNames; t_ToolSysInfoMacAddr MacAddr; QString HostName; } t_CfgLocal; // ------------------------------------ // Global variables // ------------------------------------ static t_CfgLocal CfgLocal; // ------------------------------------ // Prototypes // ------------------------------------ bool MainWindowColumnExists (const char *pName); // Start and SaveAndNext prototypes are declared here, as the declaration in the proper header files // would require too manu include files for CONFIG.CPP and too much unnecessary recompilation. static APIRET CfgFontStart (t_pchar pTableId, long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgFontSaveAndNext (long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgFontEnd (t_pcchar *ppErrorText); static APIRET CfgColumnStart (t_pchar pTableId, long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgColumnSaveAndNext (long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgColumnEnd (t_pcchar *ppErrorText); static APIRET CfgColorStart (t_pchar pTableId, long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgColorSaveAndNext (long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgColorEnd (t_pcchar *ppErrorText); static APIRET CfgLocalDeviceStart (t_pchar pTableId, long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgHiddenDeviceStart (t_pchar pTableId, long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgLocalHiddenDeviceSaveAndNext (long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgLocalHiddenDeviceEnd (t_pcchar *ppErrorText); static APIRET CfgDeviceInfoCommandStart (t_pchar pTableId, long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgDeviceInfoCommandSaveAndNext (long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgDeviceInfoCommandEnd (t_pcchar *ppErrorText); static APIRET CfgDlgAcquireFieldStart (t_pchar pTableId, long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgDlgAcquireFieldSaveAndNext (long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgDlgAcquireFieldEnd (t_pcchar *ppErrorText); static APIRET CfgDlgAcquireRuleStart (t_pchar pTableId, long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgDlgAcquireRuleSaveAndNext (long *pBaseAddr, t_pcchar *ppErrorText); static APIRET CfgDlgAcquireRuleEnd (t_pcchar *ppErrorText); static APIRET CfgIniLang (t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText); static APIRET CfgIniCPUs (t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText); static APIRET CfgIniMem (t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText); static APIRET CfgIniJobs (t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText); // ------------------------------------ // Configuration parameter table // ------------------------------------ static t_ToolCfgSet SetArrBoolean[] = { // Name in cfg file Corresponding value // -------------------------------------- { "YES" , true }, { "ON" , true }, { "TRUE" , true }, { "1" , true }, { "ENABLED" , true }, { "ACTIVATED" , true }, { "NO" , false }, { "OFF" , false }, { "FALSE" , false }, { "0" , false }, { "DISABLED" , false }, { "DEACTIVATED" , false }, { nullptr , 0 } }; static t_ToolCfgSet SetArrBooleanAuto[] = { // Name in cfg file Corresponding value // -------------------------------------- { "YES" , CFG_BOOLEANAUTO_TRUE }, { "ON" , CFG_BOOLEANAUTO_TRUE }, { "TRUE" , CFG_BOOLEANAUTO_TRUE }, { "1" , CFG_BOOLEANAUTO_TRUE }, { "ENABLED" , CFG_BOOLEANAUTO_TRUE }, { "ACTIVATED" , CFG_BOOLEANAUTO_TRUE }, { "NO" , CFG_BOOLEANAUTO_FALSE}, { "OFF" , CFG_BOOLEANAUTO_FALSE}, { "FALSE" , CFG_BOOLEANAUTO_FALSE}, { "0" , CFG_BOOLEANAUTO_FALSE}, { "DISABLED" , CFG_BOOLEANAUTO_FALSE}, { "DEACTIVATED" , CFG_BOOLEANAUTO_FALSE}, { "AUTO" , CFG_BOOLEANAUTO_AUTO }, { nullptr , 0 } }; static t_ToolCfgSet SetArrStartupSize[] = { // Name in cfg file Corresponding value // ------------------------------------------- { "STANDARD" , CFG_STARTUPSIZE_STANDARD }, { "FULLSCREEN" , CFG_STARTUPSIZE_FULLSCREEN}, { "MAXIMIZED" , CFG_STARTUPSIZE_MAXIMIZED }, { "MAXIMISED" , CFG_STARTUPSIZE_MAXIMIZED }, { "MANUAL" , CFG_STARTUPSIZE_MANUAL }, { nullptr , 0 } }; static t_ToolCfgSet SetArrNumberStyle[] = { // Name in cfg file Corresponding value // ------------------------------------------- { "LOCALE" , CFG_NUMBERSTYLE_LOCALE }, { "DECIMALCOMMA" , CFG_NUMBERSTYLE_DECIMAL_COMMA}, { "DECIMALPOINT" , CFG_NUMBERSTYLE_DECIMAL_POINT}, { nullptr , 0 } }; static t_ToolCfgSet SetArrEntryMode[] = { // Name in cfg file Corresponding value // ------------------------------------------- { "HIDE" , CFG_ENTRYMODE_HIDE }, { "SHOWDEFAULT" , CFG_ENTRYMODE_SHOWDEFAULT}, { "SHOWLAST" , CFG_ENTRYMODE_SHOWLAST }, { nullptr , 0 } }; static t_ToolCfgSet SetArrFontObject[] = { // Name in cfg file Corresponding value // ------------------------------------------------------ { "Menu" , FONTOBJECT_MENU }, { "Toolbar" , FONTOBJECT_TOOLBAR }, { "Table" , FONTOBJECT_TABLE }, { "InfoField" , FONTOBJECT_INFOFIELD }, { "AcquisitionDialogs", FONTOBJECT_ACQUISITION_DIALOGS}, { "MessageDialogs" , FONTOBJECT_MESSAGE_DIALOGS }, { "DialogData" , FONTOBJECT_DIALOG_DATA }, { nullptr , 0 } }; static t_ToolCfgSet SetArrAlignment[] = { // Name in cfg file Corresponding value // --------------------------------------- { "LEFT" , Qt::AlignLeft }, { "RIGHT" , Qt::AlignRight }, { "CENTER" , Qt::AlignCenter } }; static t_ToolCfgSet SetArrColor[] = { // Name in cfg file Corresponding value // --------------------------------------------------------------- { "LocalDevices" , COLOR_LOCALDEVICES }, { "AdditionalState1" , COLOR_ADDITIONALSTATE1 }, { "AdditionalState2" , COLOR_ADDITIONALSTATE2 }, { "AdditionalState3" , COLOR_ADDITIONALSTATE3 }, { "AdditionalState4" , COLOR_ADDITIONALSTATE4 }, { "StateIdle" , COLOR_STATE_IDLE }, { "StateQueued" , COLOR_STATE_QUEUED }, { "StateAcquire" , COLOR_STATE_ACQUIRE }, { "StateAcquirePaused" , COLOR_STATE_ACQUIRE_PAUSED }, { "StateVerify" , COLOR_STATE_VERIFY }, { "StateVerifyPaused" , COLOR_STATE_VERIFY_PAUSED }, { "StateCleanup" , COLOR_STATE_CLEANUP }, { "StateFinished" , COLOR_STATE_FINISHED }, { "StateFinishedBadVerify" , COLOR_STATE_FINISHED_BADVERIFY }, { "StateFinishedDuplicateFailed", COLOR_STATE_FINISHED_DUPLICATE_FAILED}, { "StateAbortedUser" , COLOR_STATE_ABORTED_USER }, { "StateAbortedOther" , COLOR_STATE_ABORTED_OTHER }, { nullptr , 0 } }; static t_ToolCfgSet SetArrFormat[] = { // Name in cfg file Corresponding value // ------------------------------------------ { "DD" , t_File::DD }, { "EWF" , t_File::EWF }, { "AFF" , t_File::AAFF}, { "AAFF" , t_File::AAFF}, { nullptr , 0 } }; static t_ToolCfgSet SetArrEwfFormat[] = { // Name in cfg file Corresponding value // ------------------------------------------ #if (ENABLE_LIBEWF) { "Encase1" , LIBEWF_FORMAT_ENCASE1}, { "Encase2" , LIBEWF_FORMAT_ENCASE2}, { "Encase3" , LIBEWF_FORMAT_ENCASE3}, { "Encase4" , LIBEWF_FORMAT_ENCASE4}, { "Encase5" , LIBEWF_FORMAT_ENCASE5}, { "Encase6" , LIBEWF_FORMAT_ENCASE6}, { "Smart" , LIBEWF_FORMAT_SMART }, { "FTK" , LIBEWF_FORMAT_FTK }, { "Linen5" , LIBEWF_FORMAT_LINEN5 }, { "Linen6" , LIBEWF_FORMAT_LINEN6 }, #if (LIBEWF_VERSION >= 20130416) { "Encase7" , LIBEWF_FORMAT_ENCASE7}, { "Linen7" , LIBEWF_FORMAT_LINEN7 }, { "EWFX" , LIBEWF_FORMAT_EWFX }, #endif #endif { "Guymager", t_File::AEWF }, // AEWF format is a format on its own (for the function calls) and at the same time a { "AEWF" , t_File::AEWF }, // subformat of EWF (for the user interface). Looks a bit strange at first sight, but { nullptr , 0 } // probably is the best compromise. }; static t_ToolCfgSet SetArrEwfCompression[] = { // Name in cfg file Corresponding value // ---------------------------------------- { "None", LIBEWF_COMPRESSION_NONE }, { "Empty", LIBEWF_COMPRESSION_EMPTY}, { "Fast", LIBEWF_COMPRESSION_FAST }, { "Best", LIBEWF_COMPRESSION_BEST }, { nullptr , 0 } }; #define CONFIG_COMPRESSIONTHREADS_AUTO -1 static t_ToolCfgSet SetArrCompressionThreads[] = { // Name in cfg file Corresponding value // ---------------------------------------- { "Auto", CONFIG_COMPRESSIONTHREADS_AUTO}, { "0", 0 }, // Do not remove, this value will force guymager to use the non-paralellised functions of libewf { "1", 1 }, { "2", 2 }, { "3", 3 }, { "4", 4 }, { "5", 5 }, { "6", 6 }, { "7", 7 }, { "8", 8 }, { "9", 9 }, { "10", 10 }, { "11", 11 }, { "12", 12 }, { "13", 13 }, { "14", 14 }, { "15", 15 }, { "16", 16 }, { nullptr, 0 } }; static t_ToolCfgSet SetArrMaximumJobs[] = { // Name in cfg file Corresponding value // ---------------------------------------- { "Off", CONFIG_LIMITJOBS_OFF }, { "Auto", CONFIG_LIMITJOBS_AUTO}, { "1", 1 }, { "2", 2 }, { "3", 3 }, { "4", 4 }, { "5", 5 }, { "6", 6 }, { "7", 7 }, { "8", 8 }, { "9", 9 }, { "10", 10 }, { "11", 11 }, { "12", 12 }, { "13", 13 }, { "14", 14 }, { "15", 15 }, { "16", 16 }, { nullptr, 0 } }; static t_ToolCfgSet SetArrDeviceScanMethod[] = { // Name in cfg file Corresponding value // ---------------------------------------- { "libparted", SCANMETHOD_LIBPARTED }, { "parted", SCANMETHOD_LIBPARTED }, { "DBusHAL", SCANMETHOD_DBUSHAL }, { "HAL", SCANMETHOD_DBUSHAL }, { "DBusDevKit", SCANMETHOD_DBUSDEVKIT}, { "DevKit", SCANMETHOD_DBUSDEVKIT}, { "DBusUDisks", SCANMETHOD_DBUSDEVKIT}, { "UDisks", SCANMETHOD_DBUSDEVKIT}, { "libudev", SCANMETHOD_LIBUDEV }, { "udev", SCANMETHOD_LIBUDEV }, { nullptr, 0 } }; static t_ToolCfgSet SetArrEwfNaming[] = { // Name in cfg file Corresponding value // ---------------------------------------- { "Old", EWFNAMING_OLD }, { "FTK", EWFNAMING_FTK }, { nullptr, 0 } }; #define ELT(Elt) ((long) &CfgLocal.CfgData.Elt) #define ELT_SIZ(Elt) ELT(Elt), (sizeof (CfgLocal.CfgData.Elt)-1) // for strings only, thus substract 1 byte (for terminating 0) #define INIARR(Arr) ((t_pToolCfgSet) (t_pvoid)&Arr) //lint -e545 Suspicious use of & static t_ToolCfgParamDesc CfgParamDescArr[] = { // Assignment CallOn ParameterName Type DestinationAddress Len Min Max SetArray // see t_CfgAssignment InitFn in cfg file see t_CfgType type is t_uint (CFGTYPE_SET only) // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- {CFGASSIGN_CMD , nullptr , {CMDLINE_OPTION_LOG , CFGTYPE_NULL , 0 , 0, 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_CMD , nullptr , {CMDLINE_OPTION_CFG , CFGTYPE_NULL , 0 , 0, 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, CfgIniLang , {"Language" , CFGTYPE_STRING , ELT_SIZ(Language) , 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"CheckRootRights" , CFGTYPE_SET , ELT_SIZ(CheckRootRights) , 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"StartupSize" , CFGTYPE_SET , ELT(StartupSize) , 0, 0, 0, INIARR(SetArrStartupSize) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"StartupSizeManualX" , CFGTYPE_INTEGER, ELT(StartupSizeManualX ), 0, 0, 3000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"StartupSizeManualY" , CFGTYPE_INTEGER, ELT(StartupSizeManualY ), 0, 0, 3000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"StartupSizeManualDx" , CFGTYPE_INTEGER, ELT(StartupSizeManualDx ), 0, 0, 3000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"StartupSizeManualDy" , CFGTYPE_INTEGER, ELT(StartupSizeManualDy ), 0, 0, 3000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"FileDialogSize" , CFGTYPE_SET , ELT(FileDialogSize) , 0, 0, 0, INIARR(SetArrStartupSize) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"FileDialogSizeManualDx" , CFGTYPE_INTEGER, ELT(FileDialogSizeManualDx ), 0, 0, 3000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"FileDialogSizeManualDy" , CFGTYPE_INTEGER, ELT(FileDialogSizeManualDy ), 0, 0, 3000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"NumberStyle" , CFGTYPE_SET , ELT(NumberStyle) , 0, 0, 0, INIARR(SetArrNumberStyle) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"ScreenRefreshInterval" , CFGTYPE_INTEGER, ELT(ScreenRefreshInterval ), 0, 1, 8640000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"UseFileDialogFromQt" , CFGTYPE_SET , ELT(UseFileDialogFromQt) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"UserFieldName" , CFGTYPE_STRING , ELT_SIZ(UserFieldName ), 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AdditionalStateInfoName" , CFGTYPE_STRING , ELT_SIZ(AdditionalStateInfoName ), 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"WarnAboutImageSize" , CFGTYPE_SET , ELT(WarnAboutImageSize) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"WarnAboutSegmentFileCount" , CFGTYPE_SET , ELT(WarnAboutSegmentFileCount) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"DeleteAbortedImageFiles" , CFGTYPE_SET , ELT(DeleteAbortedImageFiles) , 0, 0, 0, INIARR(SetArrBooleanAuto) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AutoExit" , CFGTYPE_SET , ELT(AutoExit) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AutoExitCountdown" , CFGTYPE_INTEGER, ELT(AutoExitCountdown) , 0, 3, 864000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"DefaultFormat" , CFGTYPE_SET , ELT(DefaultFormat) , 0, 0, 0, INIARR(SetArrFormat) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"InfoFieldsForDd" , CFGTYPE_SET , ELT(InfoFieldsForDd) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"EwfFormat" , CFGTYPE_SET , ELT(EwfFormat ) , 0, 0, 0, INIARR(SetArrEwfFormat) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"EwfCompression" , CFGTYPE_SET , ELT(EwfCompression) , 0, 0, 0, INIARR(SetArrEwfCompression) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"EwfCompressionThreshold" , CFGTYPE_DOUBLE , ELT(EwfCompressionThreshold) , 0, 0.0, 1.0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"EwfNaming" , CFGTYPE_SET , ELT(EwfNaming) , 0, 0, 0, INIARR(SetArrEwfNaming) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AffEnabled" , CFGTYPE_SET , ELT(AffEnabled) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AffCompression" , CFGTYPE_INTEGER, ELT(AffCompression) , 0, 1, 9, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AffMarkBadSectors" , CFGTYPE_SET , ELT(AffMarkBadSectors) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"SpecialFilenameChars" , CFGTYPE_STRING , ELT_SIZ(SpecialFilenameChars) , 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"CalcImageFileMD5" , CFGTYPE_SET , ELT(CalcImageFileMD5) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"DuplicateImage" , CFGTYPE_SET , ELT(DuplicateImage) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"DirectoryFieldEditing" , CFGTYPE_SET , ELT(DirectoryFieldEditing) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AllowPathInFilename" , CFGTYPE_SET , ELT(AllowPathInFilename) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"ConfirmDirectoryCreation" , CFGTYPE_SET , ELT(ConfirmDirectoryCreation) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AvoidEncaseProblems" , CFGTYPE_SET , ELT(AvoidEncaseProblems) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"AvoidCifsProblems" , CFGTYPE_SET , ELT(AvoidCifsProblems) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"DeviceScanMethod" , CFGTYPE_SET , ELT(DeviceScanMethod) , 0, 0, 0, INIARR(SetArrDeviceScanMethod) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"ScanInterval" , CFGTYPE_INTEGER, ELT(ScanInterval ), 0, 1, 8640000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"CommandGetSerialNumber" , CFGTYPE_STRING , ELT_SIZ(CommandGetSerialNumber ), 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"ForceCommandGetSerialNumber" , CFGTYPE_SET , ELT(ForceCommandGetSerialNumber ), 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"CommandGetAddStateInfo" , CFGTYPE_STRING , ELT_SIZ(CommandGetAddStateInfo ), 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"CommandAcquisitionEnd" , CFGTYPE_STRING , ELT_SIZ(CommandAcquisitionEnd ), 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"QueryDeviceMediaInfo" , CFGTYPE_SET , ELT(QueryDeviceMediaInfo ), 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"DirectIO" , CFGTYPE_SET , ELT(DirectIO ), 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"RunStatsTemplateActive" , CFGTYPE_STRING , ELT_SIZ(RunStatsTemplateActive ), 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"RunStatsTemplateEnded" , CFGTYPE_STRING , ELT_SIZ(RunStatsTemplateEnded ), 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"RunStatsOutput" , CFGTYPE_STRING , ELT_SIZ(RunStatsOutput ), 0, 0, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"RunStatsInterval" , CFGTYPE_INTEGER, ELT(RunStatsInterval ), 0, 1,99999999, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"FifoBlockSizeDD" , CFGTYPE_INTEGER, ELT(FifoBlockSizeDD ), 0, 0,99999999, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"FifoBlockSizeEWF" , CFGTYPE_INTEGER, ELT(FifoBlockSizeEWF ), 0, 0,99999999, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"FifoBlockSizeAFF" , CFGTYPE_INTEGER, ELT(FifoBlockSizeAFF ), 0, 0,99999999, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, CfgIniMem , {"FifoMaxMem" , CFGTYPE_INTEGER, ELT(FifoMaxMem ), 0, 0, 2000, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"FifoMemoryManager" , CFGTYPE_SET , ELT(FifoMemoryManager) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"UseSeparateHashThread" , CFGTYPE_SET , ELT(UseSeparateHashThread) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, CfgIniCPUs , {"CompressionThreads" , CFGTYPE_SET , ELT(CompressionThreads) , 0, 0, 1024, INIARR(SetArrCompressionThreads)}, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"BadSectorLogThreshold" , CFGTYPE_INTEGER, ELT(BadSectorLogThreshold) , 0, 0,99999999, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"BadSectorLogModulo" , CFGTYPE_INTEGER, ELT(BadSectorLogModulo) , 0, 1,99999999, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, CfgIniJobs , {"LimitJobs" , CFGTYPE_SET , ELT(LimitJobs) , 0, 1, 8, INIARR(SetArrMaximumJobs) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"JobMaxBadSectors" , CFGTYPE_INTEGER, ELT(JobMaxBadSectors) , 0, 0,99999999, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"JobDisconnectTimeout" , CFGTYPE_INTEGER, ELT(JobDisconnectTimeout) , 0, 0,99999999, nullptr }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"LocalHiddenDevicesUseRegExp" , CFGTYPE_SET , ELT(LocalHiddenDevicesUseRegExp) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"SignalHandling" , CFGTYPE_SET , ELT(SignalHandling) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"WriteToDevNull" , CFGTYPE_SET , ELT(WriteToDevNull) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"UseMemWatch" , CFGTYPE_SET , ELT(UseMemWatch) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"VerboseLibewf" , CFGTYPE_SET , ELT(VerboseLibewf) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {"CheckEwfData" , CFGTYPE_SET , ELT(CheckEwfData) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, nullptr , {nullptr ,(t_ToolCfgType)0, 0, 0, 0, 0, nullptr }, CFG_FILLUP_FORLINT} }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: Fonts // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffFont pFont0 = nullptr; #undef ELT #undef ELT_SIZ #define ELT(Elt) ((long)&pFont0->Elt) #define ELT_SIZ(Elt) (long)&pFont0->Elt, sizeof (pFont0->Elt)-1 // for strings only, thus substract 1 byte (for terminating 0) static t_ToolCfgDataDesc CfgDescArrFont[] = { // ParameterName Type (see DestinationOfs Len Min Max SetArray // in cfg file t_ToolCfgType) type is long (CFGTYPE_SET only) // -------------------------------------------------------------------------------- { "Object", CFGTYPE_SET , ELT(Object) , 0, 0, 0, SetArrFontObject}, { "Family", CFGTYPE_STRING , ELT_SIZ(Family) , 0, 0, nullptr }, { "Size", CFGTYPE_INTEGER, ELT(Size) , 0, 0, 100, nullptr }, { "Weight", CFGTYPE_INTEGER, ELT(Weight) , 0, 0, 100, nullptr }, { "Italic", CFGTYPE_SET , ELT(Italic) , 0, 0, 0, SetArrBoolean }, { nullptr, CFGTYPE_NULL , 0 , 0, 0, 0, nullptr } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: Columns // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgColumn pColumn0 = nullptr; #undef ELT #undef ELT_SIZ #define ELT(Elt) ((long)&pColumn0->Elt) #define ELT_SIZ(Elt) (long)&pColumn0->Elt, sizeof (pColumn0->Elt)-1 // for strings only, thus substract 1 byte (for terminating 0) static t_ToolCfgDataDesc CfgDescArrColumn[] = { // ParameterName Type (see DestinationOfs Len Min Max SetArray // in cfg file t_ToolCfgType) type is long (CFGTYPE_SET only) // ---------------------------------------------------------------------------------------------- { "ColumnName" , CFGTYPE_STRING , ELT_SIZ(Name) , 0, 0, nullptr }, { "Alignment" , CFGTYPE_SET , ELT(Alignment) , 0, 0, 0, SetArrAlignment }, { "MinWidth" , CFGTYPE_INTEGER, ELT(MinWidth) , 0, 0, 9999, nullptr }, { "ShowInMainTable", CFGTYPE_SET , ELT(ShowInMainTable) , 0, 0, 0, SetArrBoolean }, { "ShowInCloneTabe", CFGTYPE_SET , ELT(ShowInCloneTable), 0, 0, 0, SetArrBoolean }, { nullptr , CFGTYPE_NULL , 0 , 0, 0, 0, nullptr } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: Colors // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffColor pColor0 = nullptr; #undef ELT #undef ELT_SIZ #define ELT(Elt) ((long)&pColor0->Elt) static t_ToolCfgDataDesc CfgDescArrColor[] = { // ParameterName Type (see DestinationOfs Len Min Max SetArray // in cfg file t_ToolCfgType) type is long (CFGTYPE_SET only) // -------------------------------------------------------------------------------- { "Color", CFGTYPE_SET , ELT(Color) , 0, 0, 0, SetArrColor }, { "R", CFGTYPE_INTEGER, ELT(R) , 0, 0, 255, nullptr }, { "G", CFGTYPE_INTEGER, ELT(G) , 0, 0, 255, nullptr }, { "B", CFGTYPE_INTEGER, ELT(B) , 0, 0, 255, nullptr }, { nullptr, CFGTYPE_NULL , 0 , 0, 0, 0, nullptr } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: LocalHiddenDevices // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffLocalHiddenDevice pLoc0 = nullptr; #undef ELT #undef ELT_SIZ #define ELT(Elt) ((long)&pLoc0->Elt) #define ELT_SIZ(Elt) (long)&pLoc0->Elt, sizeof (pLoc0->Elt)-1 // for strings only, thus substract 1 byte (for terminating 0) static t_ToolCfgDataDesc CfgDescArrLocalHiddenDevice[] = { // ParameterName Type (see DestinationOfs Len Min Max SetArray // in cfg file t_ToolCfgType) type is long (CFGTYPE_SET only) // -------------------------------------------------------------------------------- { "Device", CFGTYPE_STRING , ELT_SIZ(Device) , 0, 0, nullptr }, { nullptr, CFGTYPE_NULL , 0 , 0, 0, 0, nullptr } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: DeviceInfoCommands // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffDeviceInfoCommand pCmd0 = nullptr; #undef ELT //lint !e750: local macro 'ELT' not referenced #undef ELT_SIZ #define ELT(Elt) ((long)&pCmd0->Elt) #define ELT_SIZ(Elt) (long)&pCmd0->Elt, sizeof (pCmd0->Elt)-1 // for strings only, thus substract 1 byte (for terminating 0) static t_ToolCfgDataDesc CfgDescArrDeviceInfoCommand[] = { // ParameterName Type (see DestinationOfs Len Min Max SetArray // in cfg file t_ToolCfgType) type is long (CFGTYPE_SET only) // -------------------------------------------------------------------------------- { "Command", CFGTYPE_STRING , ELT_SIZ(Command) , 0, 0, nullptr }, { nullptr, CFGTYPE_NULL , 0 , 0, 0, 0, nullptr } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: DlgAcquireField // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffDlgAcquireField pFld0 = nullptr; #undef ELT //lint !e750: local macro 'ELT' not referenced #undef ELT_SIZ #define ELT(Elt) ((long)&pFld0->Elt) #define ELT_SIZ(Elt) (long)&pFld0->Elt, sizeof (pFld0->Elt)-1 // for strings only, thus substract 1 byte (for terminating 0) static t_ToolCfgDataDesc CfgDescArrDlgAcquireField[] = { // ParameterName Type (see DestinationOfs Len Min Max SetArray // in cfg file t_ToolCfgType) type is long (CFGTYPE_SET only) // --------------------------------------------------------------------------------------- { "FieldName" , CFGTYPE_STRING , ELT_SIZ(FieldName) , 0, 0, nullptr }, { "EntryModeImage", CFGTYPE_SET , ELT(EntryModeImage), 0, 0, 0, SetArrEntryMode}, { "EntryModeClone", CFGTYPE_SET , ELT(EntryModeClone), 0, 0, 0, SetArrEntryMode}, { "DefaultValue" , CFGTYPE_STRING , ELT_SIZ(DefaultValue) , 0, 0, nullptr }, { nullptr , CFGTYPE_NULL , 0 , 0, 0, 0, nullptr } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: DlgAcquireRule // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffDlgAcquireRule pFil0 = nullptr; #undef ELT //lint !e750: local macro 'ELT' not referenced #undef ELT_SIZ #define ELT(Elt) ((long)&pFil0->Elt) #define ELT_SIZ(Elt) (long)&pFil0->Elt, sizeof (pFil0->Elt)-1 // for strings only, thus substract 1 byte (for terminating 0) static t_ToolCfgDataDesc CfgDescArrDlgAcquireRule[] = { // ParameterName Type (see DestinationOfs Len Min Max SetArray // in cfg file t_ToolCfgType) type is long (CFGTYPE_SET only) // ----------------------------------------------------------------------------------------------- { "TriggerFieldName" , CFGTYPE_STRING , ELT_SIZ(TriggerFieldName), 0, 0, nullptr }, { "DestinationFieldName", CFGTYPE_STRING , ELT_SIZ(DestFieldName) , 0, 0, nullptr }, { "Value" , CFGTYPE_STRING , ELT_SIZ(Value) , 0, 0, nullptr }, { nullptr , CFGTYPE_NULL , 0 , 0, 0, 0, nullptr } }; // ---------------------------------------------------------------------------------------------------------------------- // Table descriptor // ---------------------------------------------------------------------------------------------------------------------- #undef ELT //lint !e750: local macro 'ELT' not referenced #undef ELT_SIZ static t_ToolCfgTableDesc CfgTableDescArr[] = { // Tabletype StartFn SaveAndNextFn EndFn pDataDescArray // ----------------------------------------------------------------------------------------------------------------------------------------------------- {"Fonts" , &CfgFontStart , &CfgFontSaveAndNext , CfgFontEnd , &CfgDescArrFont [0]}, {"Columns" , &CfgColumnStart , &CfgColumnSaveAndNext , CfgColumnEnd , &CfgDescArrColumn [0]}, {"Colors" , &CfgColorStart , &CfgColorSaveAndNext , CfgColorEnd , &CfgDescArrColor [0]}, {"LocalDevices" , &CfgLocalDeviceStart , &CfgLocalHiddenDeviceSaveAndNext , CfgLocalHiddenDeviceEnd , &CfgDescArrLocalHiddenDevice [0]}, {"HiddenDevices" , &CfgHiddenDeviceStart , &CfgLocalHiddenDeviceSaveAndNext , CfgLocalHiddenDeviceEnd , &CfgDescArrLocalHiddenDevice [0]}, {"DeviceInfoCommands" , &CfgDeviceInfoCommandStart , &CfgDeviceInfoCommandSaveAndNext , CfgDeviceInfoCommandEnd , &CfgDescArrDeviceInfoCommand [0]}, {"DlgAcquireField" , &CfgDlgAcquireFieldStart , &CfgDlgAcquireFieldSaveAndNext , CfgDlgAcquireFieldEnd , &CfgDescArrDlgAcquireField [0]}, {"DlgAcquireRule" , &CfgDlgAcquireRuleStart , &CfgDlgAcquireRuleSaveAndNext , CfgDlgAcquireRuleEnd , &CfgDescArrDlgAcquireRule [0]}, {nullptr , nullptr , nullptr , nullptr , nullptr } }; //lint +e545 Suspicious use of & // ------------------------------------ // Functions // ------------------------------------ t_pCfgData CfgGetpData (void) { return &CfgLocal.CfgData; } APIRET CfgReadConfiguration (t_pcchar pCfgFileName) { QString DeskModel; QString MacAddrSectionName; QString HostSectionName; char HostName[64]; t_pcchar pMsg = nullptr; APIRET rc; // Section name for MAC address (MACADDR_11BB33CC55DD) // --------------------------------------------------- rc = ToolSysInfoGetMacAddr (&CfgLocal.MacAddr); if (rc == TOOLSYSINFO_ERROR_NO_ADDR) { LOG_INFO ("MAC network hardware address: none found") } else { CHK (rc) LOG_INFO ("MAC network hardware address: %s", &CfgLocal.MacAddr.AddrStr[0]) MacAddrSectionName = "MACADDR_"; MacAddrSectionName += &CfgLocal.MacAddr.AddrStr[0]; CHK (ToolCfgAddGlobalSectionName (QSTR_TO_PSZ(MacAddrSectionName))) } // Section name for host name (HOST_thename) // --------------------------------------------- if (gethostname (&HostName[0], sizeof(HostName))) { LOG_INFO ("Error in gethostname.") } else { LOG_INFO ("Host name: %s", &HostName[0]) CfgLocal.HostName = HostName; HostSectionName = "HOST_"; HostSectionName += CfgLocal.HostName; CHK (ToolCfgAddGlobalSectionName (QSTR_TO_PSZ(HostSectionName))) } CHK (ToolCfgAddGlobalSectionName (CFG_SECTION_GUYMAGER)) CHK (ToolCfgScanConfiguration (pCfgFileName, "", &CfgParamDescArr[0], &CfgTableDescArr[0])) CHK (ToolCfgLogConfiguration (CfgParamDescArr)) // Configuration plausibility checks // --------------------------------- if (!CONFIG(AffEnabled) && (CONFIG(DefaultFormat) == t_File::AAFF)) pMsg = "Problem in configuration detected: AffEnabled is off, but AFF is set as default format. Please correct settings for parameter AffEnabled or DefaultFormat."; if ((CONFIG (EwfFormat) != t_File::AEWF) && (CONFIG (EwfCompression) == LIBEWF_COMPRESSION_EMPTY)) pMsg = "Parameter EwfCompression is set to 'Empty'; however, this setting only is allowed with EwfFormat set to 'Guymager'. Please correct settings for parameter EwfCompression or EwfFormat."; if (pMsg) { printf ("%s", pMsg); LOG_INFO ("%s", pMsg) CHK (ERROR_CFG_INCOHERENCY_DETECTED) } return NO_ERROR; } QString CfgGetHostName (void) { return CfgLocal.HostName; } QString CfgGetMacAddress (void) { return QString(CfgLocal.MacAddr.AddrStr); } // ---------------------------------- // CallOnInit functions // ---------------------------------- APIRET CfgIniLang (t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText) { QString Language = CONFIG(Language); QString LanguageSystem; *ppErrorText = nullptr; if (Language.compare ("AUTO", Qt::CaseInsensitive) == 0) { // LanguageSystem = QLocale::system().name(); // This is not reliable. Qt seems to use LC_NUMERIC for selecting the language, which LanguageSystem = QString (getenv ("LANGUAGE")); // is not what we want. So, let's read the LANGUAGE evironment variable ourselves. Language = LanguageSystem.split('_')[0]; snprintf (CONFIG(Language), sizeof(CONFIG(Language)), "%s", QSTR_TO_PSZ(Language)); LOG_INFO ("Parameter %s set to 'AUTO', switching to language '%s'", pCfgParamDesc->DataDesc.pName, CONFIG(Language)) } return NO_ERROR; } APIRET CfgIniCPUs (t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText) { t_pcchar pParamName; unsigned int CPUs; *ppErrorText = nullptr; pParamName = pCfgParamDesc->DataDesc.pName; if (CONFIG (CompressionThreads) == CONFIG_COMPRESSIONTHREADS_AUTO) { CPUs = UtilGetNumberOfCPUs(); LOG_INFO ("Parameter %s set to AUTO; %u CPUs detected", pParamName, CPUs) CONFIG (CompressionThreads) = (int)CPUs; if (CPUs > CFG_MAX_COMPRESSIONTHREADS) { CONFIG (CompressionThreads) = CFG_MAX_COMPRESSIONTHREADS; LOG_INFO ("Maximum value for %s is %d", pParamName, CFG_MAX_COMPRESSIONTHREADS) } LOG_INFO ("Setting %s to %d.", pParamName, CONFIG (CompressionThreads)) } return NO_ERROR; } APIRET CfgIniJobs (t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText) { t_pcchar pParamName; int CPUs; *ppErrorText = nullptr; pParamName = pCfgParamDesc->DataDesc.pName; if (CONFIG (LimitJobs) == CONFIG_LIMITJOBS_AUTO) { CPUs = (int) UtilGetNumberOfCPUs(); LOG_INFO ("Parameter %s set to AUTO; %d processors detected", pParamName, CPUs) CONFIG (LimitJobs) = GETMIN (CPUs / 2, CFG_MAX_LIMIT_JOBS); LOG_INFO ("Setting %s to %d (half the number of CPUs, with a maximum of %d).", pParamName, CONFIG (LimitJobs), CFG_MAX_LIMIT_JOBS) } return NO_ERROR; } APIRET CfgIniMem (t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText) { t_pcchar pParamName; unsigned long long Bytes; *ppErrorText = nullptr; pParamName = pCfgParamDesc->DataDesc.pName; // meminfo(); // Bytes = kb_main_total * 1024; Bytes = UtilGetInstalledRAM (); if (CONFIG (FifoMaxMem) == 0) { CONFIG (FifoMaxMem) = GETMAX (1, (int)(Bytes / (8*1024*1024))); // Use one eighth of the available mem, convert to MB CONFIG (FifoMaxMem) = GETMIN (CONFIG (FifoMaxMem), 128); // Stay below 128MB LOG_INFO ("Parameter %s set to 0 (auto); %0.1f MB of RAM detected.", pParamName, Bytes/(1024.0*1024.0)); LOG_INFO ("Setting %s to %d (i.e. using %d MB per acquisition as FIFO memory)", pParamName, CONFIG (FifoMaxMem), CONFIG (FifoMaxMem)) } return NO_ERROR; } // ---------------------------------- // LOG and CFG command line options // ---------------------------------- APIRET CfgGetLogFileName (t_pcchar *ppLogFileName, bool *pDefaultUsed) { APIRET rc; bool Def; Def = false; rc = ToolCfgGetCmdLineOption (CMDLINE_OPTION_LOG, ppLogFileName); if (rc == TOOLCFG_ERROR_CMDLINE_OPTION_NOT_FOUND) { *ppLogFileName = DEFAULT_LOG_FILENAME; Def = true; } else { CHK (rc) } if (pDefaultUsed) *pDefaultUsed = Def; return NO_ERROR; } APIRET CfgGetCfgFileName (t_pcchar *ppCfgFileName, bool *pDefaultUsed) { APIRET rc; bool Def; t_pcchar pVersion; Def = false; rc = ToolCfgGetCmdLineOption (CMDLINE_OPTION_CFG, ppCfgFileName); // Try to get the configuration file name if (rc == TOOLCFG_ERROR_CMDLINE_OPTION_NOT_FOUND) { *ppCfgFileName = DEFAULT_CFG_FILENAME; // Use default if not found Def = true; } else { CHK (rc) if(strcasecmp(*ppCfgFileName, "template") == 0) { pVersion = "Version unknown"; CHK (ToolCfgBuildTemplate (TEMPLATE_CFG_FILENAME, pVersion, CFG_SECTION_GUYMAGER, &CfgParamDescArr[0], &CfgTableDescArr[0])) return ERROR_CFG_ONLY_TEMPLATE_GENERATED; } } if (pDefaultUsed) *pDefaultUsed = Def; return NO_ERROR; } // ------------------------------------ // Fonts // ------------------------------------ static APIRET CfgFontStart (t_pchar /*pTableId*/, long *pBaseAddr, t_pcchar *ppErrorText) { memset (CfgLocal.FontArr, 0, sizeof(CfgLocal.FontArr)); *pBaseAddr = (long) &CfgLocal.CfgBuffFont; *ppErrorText = nullptr; // #define CONFIG_SHOW_FONTS #ifdef CONFIG_SHOW_FONTS QFontDatabase FontDB; QString Sizes; foreach (const QString &Family, FontDB.families()) { foreach (const QString &Style, FontDB.styles(Family)) { Sizes.clear (); foreach (int Size, FontDB.smoothSizes (Family, Style)) Sizes += QString::number (Size) + " "; LOG_INFO ("Family/style: %s/%s - Smooth sizes: %s", QSTR_TO_PSZ(Family), QSTR_TO_PSZ(Style), QSTR_TO_PSZ(Sizes.trimmed())) } } #endif return NO_ERROR; } static APIRET CfgFontSaveAndNext (long *pBaseAddr, t_pcchar *ppErrorText) { t_pCfgBuffFont pCfg; QFont *pFont; QFont **ppFontDest; const char *pObjectName; pCfg = &CfgLocal.CfgBuffFont; if (strlen (pCfg->Family)) { pFont = new QFont (pCfg->Family, pCfg->Size, pCfg->Weight, (bool)pCfg->Italic); ppFontDest = &CfgLocal.FontArr[pCfg->Object]; if (*ppFontDest) // This might happen if a fonts figures more delete *ppFontDest; // than once in the configuration *ppFontDest = pFont; CHK (ToolCfgGetSetString (&SetArrFontObject[0], pCfg->Object, &pObjectName)) LOG_INFO ("Font object %15s: Requested: %20s Size %2d Weight %2d %-8s", pObjectName, pCfg->Family, pCfg->Size, pCfg->Weight, pCfg->Italic ? "Italic" : "NoItalic") // QFontInfo *pFontInfo = new QFontInfo (*pFont); // LOG_INFO (" Returned : %20s Size %2d Weight %2d %-8s PixelSize %d %s %s %s", // pFontInfo->family ().toAscii().constData(), // pFontInfo->pointSize (), // pFontInfo->weight (), // pFontInfo->italic () ? "Italic" : "NoItalic", // // pFontInfo->pixelSize (), // pFontInfo->fixedPitch() ? "FixedPitch" : "NoFixedPitch", // pFontInfo->rawMode () ? "RawMode" : "NoRawMode" , // pFontInfo->exactMatch() ? "ExactMatch" : "NoxactMatch" ); // delete pFontInfo; } *pBaseAddr = (long) &CfgLocal.CfgBuffFont; *ppErrorText = nullptr; return NO_ERROR; } static APIRET CfgFontEnd (t_pcchar *ppErrorText) { // const char *pObjectName; // int i; *ppErrorText = nullptr; // for (i=0; i= CFG_MAX_COLUMNS) *ppErrorText = "Max. number of columns exceeded"; else if (!MainWindowColumnExists (CfgLocal.CfgBuffColumn.Name)) *ppErrorText = "Non existent column name"; else CfgLocal.ColumnArr[CfgLocal.Columns++] = CfgLocal.CfgBuffColumn; *pBaseAddr = (long) &CfgLocal.CfgBuffColumn; return NO_ERROR; } static APIRET CfgColumnEnd (t_pcchar *ppErrorText) { *ppErrorText = nullptr; return NO_ERROR; } int CfgGetColumnCount (void) { return CfgLocal.Columns; } t_pcCfgColumn CfgGetColumn (int i) { return &CfgLocal.ColumnArr[i]; } // ------------------------------------ // Colors // ------------------------------------ static APIRET CfgColorStart (t_pchar /*pTableId*/, long *pBaseAddr, t_pcchar *ppErrorText) { int i; for (i=0; iR, pCfg->G, pCfg->B); CfgLocal.ColorArr[pCfg->Color] = pColor; *pBaseAddr = (long) &CfgLocal.CfgBuffColor; *ppErrorText = nullptr; return NO_ERROR; } static APIRET CfgColorEnd (t_pcchar *ppErrorText) { const char *pName; int i; *ppErrorText = nullptr; for (i=0; i= 0) && (Color < COLOR_COUNT)) //lint !e568: non-negative quantity is never less than zero return (CfgLocal.ColorArr[Color]); else return nullptr; } } static APIRET CfgDestroyColors (void) { int i; for (i=0; i