pax_global_header00006660000000000000000000000064132546720610014520gustar00rootroot0000000000000052 comment=869b145e98e60a9002b9ffca5630e1c3e8b9ee96 guymager-0.8.8/000077500000000000000000000000001325467206100133555ustar00rootroot00000000000000guymager-0.8.8/COPYING000066400000000000000000000432541325467206100144200ustar00rootroot00000000000000 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.8/CREDITS000066400000000000000000000033621325467206100144010ustar00rootroot00000000000000 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.8/aaff.cpp000066400000000000000000000524061325467206100147650ustar00rootroot00000000000000// **************************************************************************** // 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 // 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_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[0]; } __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 // ------------------ 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; t_AffSegmentHeader SegmentHeader; // Optimisation: This header and this footer only need to be t_AffSegmentFooter SegmentFooter; // allocated and initialised once, and can be used again and again unsigned char *pUncompressBuffer; unsigned int UncompressBufferLen; unsigned long long BytesVerified; unsigned long long DeviceSize; } t_Aaff; #define AAFF_MD5_LEN 16 #define AAFF_SHA1_LEN 20 #define AAFF_SHA256_LEN 32 #define AAFF_BADSECTORMARKER_MAXLEN 65536 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 = 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, strlen (pStr))) return NO_ERROR; } static APIRET AaffWriteSegmentArg (t_pAaff pAaff, const char *pName, unsigned int Argument) { CHK (AaffWriteSegment (pAaff, pName, Argument, NULL, 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 == NULL) 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 = NULL; 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 = NULL; // 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 == NULL) { 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 = NULL; // pPreProcess = (t_pAaffPreprocess) UTIL_MEM_ALLOC(sizeof(t_AaffPreprocess)); // if (pPreProcess == NULL) // 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 = 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 == NULL) return ERROR_AAFF_MEMALLOC_FAILED; pAaff->UncompressBufferLen = NewLen; } return NO_ERROR; } static unsigned long long AaffGetCurrentSeekPos (t_Aaff *pAaff) { return 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, 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[strlen(AFF_HEADER)+1]; *ppAaff = NULL; CHK (AaffCreateHandle (&pAaff)) pAaff->OpenedForWrite = false; pAaff->pUncompressBuffer = NULL; 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 == NULL) { 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 (time (0)); 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 int 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.8/aewf.cpp000066400000000000000000001512601325467206100150100ustar00rootroot00000000000000// **************************************************************************** // 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 // 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 // ------------------ const uchar AEWF_SIGNATURE[8] = {0x45, 0x56, 0x46, 0x09, 0x0D, 0x0A, 0xFF, 0x00}; const uchar AEWF_STARTOFFIELDS = 0x01; const ushort AEWF_ENDOFFIELDS = 0x0000; const char * AEWF_SECTIONNAME_HEADER2 = "header2"; const char * AEWF_SECTIONNAME_HEADER = "header" ; const char * AEWF_SECTIONNAME_VOLUME = "volume" ; const char * AEWF_SECTIONNAME_SECTORS = "sectors"; const char * AEWF_SECTIONNAME_TABLE = "table" ; const char * AEWF_SECTIONNAME_TABLE2 = "table2" ; const char * AEWF_SECTIONNAME_DATA = "data" ; const char * AEWF_SECTIONNAME_ERROR2 = "error2" ; const char * AEWF_SECTIONNAME_HASH = "hash" ; const char * AEWF_SECTIONNAME_DIGEST = "digest" ; const char * AEWF_SECTIONNAME_NEXT = "next" ; const char * AEWF_SECTIONNAME_DONE = "done" ; const unsigned int AEWF_MAX_CHUNK_OFFSETS = 65534; const unsigned int AEWF_MAX_SIZE_SECTIONSECTOR = 0x7FFFFFFF; const unsigned int AEWF_COMPRESSED_CHUNK = 0x80000000; 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[]; uint CRC2; } __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[]; uint CRC2; } __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 = NULL; SegmentFiles = 0; pVerifyBuffer = NULL; 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 // ---------------- unsigned char *pAewfZeroBlockCompressed; ulong AewfZeroBlockCompressedLen; ulong AewfZeroBlockUnCompressedLen; int AewfZipCompressionLevel; 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 numbers 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 == NULL) 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 == NULL) 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 = NULL; if (pAewf->pCurrentSegmentFile == NULL) 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 == NULL) CHK (ERROR_AEWF_NO_FILE_OPEN) pAewf->pCurrentSegmentFile = NULL; 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==NULL) && (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, NULL, 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, NULL, 0)) return NO_ERROR; } static APIRET AewfWriteSectionDone (t_Aewf *pAewf) { CHK (AewfWriteSection (pAewf, AEWF_SECTIONNAME_DONE, NULL, 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 = NULL; // pPreProcess = (t_pAewfPreprocess) UTIL_MEM_ALLOC(sizeof(t_AewfPreprocess)); // if (pPreProcess == NULL) // 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 == NULL) 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, NULL, 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 = NULL; 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 == NULL) 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 = NULL; 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 == NULL) 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 = NULL; *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_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 == NULL) || (pAewfZeroBlockCompressed == NULL)) 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 == NULL) 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.8/aewf.h000066400000000000000000000113601325467206100144510ustar00rootroot00000000000000// **************************************************************************** // 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 // 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__ #include "hash.h" 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.8/changelog000066400000000000000000000561531325467206100152410ustar00rootroot00000000000000guymager-beta (0.8.8-1) unstable; urgency=low * Using pkexec instead of gksudo * New compile option ENABLE_LIBEWF -- Guy Voncken Wed, 24 Jan 2018 16:00:00 +0100 guymager-beta (0.8.7-1) unstable; urgency=low * Typing errors corrected -- Guy Voncken Fri, 22 Sep 2017 10:00:00 +0200 guymager-beta (0.8.6-1) unstable; urgency=low * Upon disconnection of device, do not pause verification if it is done on the image only (pausing still for source verifications). * New cfg parameter AdditionalStateInfoName * System signal HUP triggers device rescanning * Special tokens %UserField% and %AddStateInfo% added -- Guy Voncken Fri, 11 Aug 2017 11:00:00 +0200 guymager-beta (0.8.5-1) unstable; urgency=low * New cfg parameters BadSectorLogThreshold and BadSectorLogModulo. -- Guy Voncken Wed, 26 Apr 2017 11:00:00 +0200 guymager-beta (0.8.4-1) unstable; urgency=low * Removed bug that occurred if remaining time was longer than 99 hours * Adapted to gcc7 -- Guy Voncken Thu, 02 Feb 2017 17:00:00 +0100 guymager-beta (0.8.3-1) unstable; urgency=low * Corrected bug where Guymager not always recognised if duplicate image or info file was the same as first one. * In the duplicate acquisition dialog mark the device selected in the first acquisition dialog and make it unselectable. * New features in acquisition dialog: Allow relative paths in filenames, allow direct editing of directory fields. See new configuration parameters DirectoryFieldEditing, AllowPathInFilename and ConfirmDirectoryCreation. * Forbid overwriting image / info files of other acquisitions (up until now, only an warning was shown that could have been ignored by the user). -- Guy Voncken Fri, 05 Aug 2016 15:00:00 +0200 guymager-beta (0.8.2-1) unstable; urgency=low * Support for SHA1 checksum in EWF images (for AEWF and LIBEWF) * Corrected bug where directory button in dlgacquire would be drawn half underneath entry field for certain configuration settings. * Corrected bug where %SizeHumanNoSep% behaved the same as %SizeHuman% -- Guy Voncken Wed, 15 Apr 2016 16:00:00 +0200 guymager-beta (0.8.1-1) unstable; urgency=low * New DeviceScanMethod libudev * Adapted to Qt 5 API * For computers with non standard mouse: Double click open context menu * New configuration parameter AvoidCifsProblems * Show version number in main window title bar * Debug CIFS flcose problem * Added EWFX support from libewf -- Guy Voncken Wed, 09 Mar 2016 12:00:00 +0100 guymager-beta (0.7.6-1) unstable; urgency=low * Additional log output for fclose problem on Samba (cases) share -- Guy Voncken Thu, 29 Jul 2015 14:00:00 +0200 guymager-beta (0.7.5-1) unstable; urgency=low * Bug fixed where we could run out of FIFO blocks in extremely rare conditions (ERROR_FIFO_MALLOC_FAILED) -- Guy Voncken Tue, 05 May 2015 10:00:00 +0200 guymager-beta (0.7.4-1) unstable; urgency=low * Added output for hostname, domainname and system to info file * New cfg param InfoFieldsForDd * Corrected bug: DisconnectTimeout only must be active if LimitJobs is active * libewf version check changed, all versions >= 20130416 are accepted -- Guy Voncken Tue, 09 Sep 2014 10:30:00 +0200 guymager-beta (0.7.3a-1) unstable; urgency=low * New cfg parameter InfoFieldsForDd -- Guy Voncken Fri, 10 Feb 2014 15:30:00 +0100 guymager-beta (0.7.3-1) unstable; urgency=low * Removed logical image format LVF * Following patches by Thorsten Glaser , adapted by Guy: Add new libewf formats: Encase7, Linen6, Linen7 Port to newer libewf API to fix FTBFS (Closes: #729651) * Removed bug when SHA1 was the only selected hash algorithm * Wrong NativePath, ByPath and Interface display when moving device from one port to another without refreshing device list in between. * New cfg parameter AffEnabled -- Guy Voncken Fri, 17 Dec 2014 16:00:00 +0100 guymager-beta (0.7.2-1) unstable; urgency=low * Adding support for empty block compression * GUI Status text corrected when all verfications are off * Scanning also /usr/lib64 for libparted * New screen columns NativePath, ByPath and Interface adedd * RegExp search for hidden and local devices adedd -- Guy Voncken Wed, 12 Dec 2013 09:00:00 +0100 guymager-beta (0.7.1-1) unstable; urgency=low * Duplicate image creation * New RunStats module * New job queue mechanism * New userfield * New configuration table for main Guymager table * New font configuration * New cfg table HiddenDevices * New configuration parameter CommandAcquisitionEnd * Writing hidden area info into info file * Gray out rescan button when scan is running * In order to avoid the "contagious error", DirectIO is switched on in fallback mode. * Removed race condition where write thread would write hash into image before it has been calculated by hash thread. * SHA-1 support added -- Guy Voncken Thu, 15 Mar 2013 16:45:00 +0100 guymager-beta (0.6.13-1) unstable; urgency=low * Package dependency to udisks added (for recent Ubuntu) * libparted search extended to subdirs * Added cfg parameter ForceCommandGetSerialNumber -- Guy Voncken Thu, 27 Dec 2012 11:00:00 +0100 guymager-beta (0.6.12-1) unstable; urgency=low * Avoiding -O3 / inline compiler bug * Correct srceen output if no log file is in use * DD verification: retry with NOATIME switched off if open fails * DD verification: Do not exit if open fails -- Guy Voncken Thu, 30 Jul 2012 17:00:00 +0200 guymager-beta (0.6.11-1) unstable; urgency=low * Releasing changes of 0.6.10 -- Guy Voncken Thu, 12 Jul 2012 11:30:00 +0200 guymager-beta (0.6.10-1) unstable; urgency=low * Removed bug where section tables might contain only one entry. * New cfg parameter EwfNaming supports 2 methods for naming EWF segment files * Added warnings for low space on destination path and large number of image files before starting acquisition, new configuration parameters WarnAboutImageSize and WarnAboutSegmentFileCount * When opening destination image fails, retry with NOATIME switched off (thus enabling cloning without root rights) -- Guy Voncken Fri, 4 Jul 2012 11:30:00 +0200 guymager-beta (0.6.10-1) unstable; urgency=low * Removed bug where section tables might contain only one entry. -- Guy Voncken Thu, 12 Jul 2012 10:30:00 +0200 guymager-beta (0.6.9-1) unstable; urgency=low * Releasing all changes of 0.6.8 (switch to new version in order to have test users update their packages correctly) -- Guy Voncken Fri, 29 Jun 2012 15:30:00 +0200 guymager-beta (0.6.8-1) unstable; urgency=low * AEWF: Considering also 1st chunk base offset when checking if chunk can be added to current sectors section. * New cfg parameter CheckRootRights * If source disk can't be opened, give it another try without option NOATIME * Corrected text output for image hash calculation in info file; Translations updated. * Error in UtilIsZero removed (leading to wrong image if FifoBlockSizeEwf is set to values above 65536) * Package no longer recommends gksu, smartmontools and hdparm but depends on them * No longer exits on write errors on info file or in AEWF module (should already have been done in 0.6.4, but the takeover from trunk wasn't done) * New cfg parameter EwfCompressionThreshold * Also include symlinks when searching for libparted * Changes from Mika (unistd.h) -- Guy Voncken Fri, 29 Jun 2012 15:00:00 +0200 guymager-beta (0.6.7-1) unstable; urgency=low * Configuration parameter CommandGetAddStateInfo now understands placeholder %local for distinguishing between local and non-local devices. * New configuration parameter QueryDeviceMediaInfo for devices that do not like HPA/DCO querying * MD5 calculation of destination disk corrected for disks whose size is not a multiple of the block size -- Guy Voncken Mon, 30 Apr 2012 14:00:00 +0200 guymager-beta (0.6.6-1) unstable; urgency=low * no longer depends on libproc (using libc functions instead) * New, fast SHA256 and MD5 routines (from package coreutils) * No longer depends on libcrypto or libcrypto for fast hash functions -- Guy Voncken Fri, 12 Mar 2012 14:15:00 +0100 guymager-beta (0.6.5-1) unstable; urgency=low * Device scan: Assume that a device will not be included more than once in a scan * New CFG parameter AvoidEncaseProblems for Encase EWF string limitations -- Guy Voncken Fri, 06 Feb 2012 16:00:00 +0100 guymager-beta (0.6.4-1) unstable; urgency=low * No longer exits on write errors in AEWF module * No longer exits on info file write errors * Center info dialog relative to application (not screen) -- Guy Voncken Fri, 30 Dec 2011 14:00:00 +0100 guymager-beta (0.6.3-1) unstable; urgency=low * Compressed chunks must be smaller than uncompressed chunks without the CRC, or else Encase fails -- Guy Voncken Thu, 7 Dec 2011 14:00:00 +0100 guymager-beta (0.6.2-1) unstable; urgency=low * Better HPA/DCO log output -- Guy Voncken Thu, 1 Dec 2011 15:00:00 +0100 guymager-beta (0.6.1-1) unstable; urgency=low * New branch for 0.6 release -- Guy Voncken Wed, 2 Nov 2011 15:00:00 +0100 guymager-beta (0.6.0beta8-1) unstable; urgency=low * Bug removed where acquisition hash codes were not shown in info file if verification was aborted. -- Guy Voncken Thu, 20 Oct 2011 15:30:00 +0200 guymager-beta (0.6.0beta7-1) unstable; urgency=low * Additional State Info added * zlib zero block compression / decompression optimised -- Guy Voncken Mon, 17 Oct 2011 14:30:00 +0200 guymager-beta (0.6.0beta6-1) unstable; urgency=low * New configuration parameter DirectIO -- Guy Voncken Tue, 08 Sep 2011 11:30:00 +0200 guymager-beta (0.6.0beta5-1) unstable; urgency=low * Setting sectors per chunk correctly for libewf -- Guy Voncken Tue, 06 Sep 2011 14:30:00 +0200 guymager-beta (0.6.0beta4-1) unstable; urgency=low * Removed full path of image file names from .info file, only show the image filename * Bug removal: pDevice->ImageFilehashList was not cleared after acquisition -- Guy Voncken Tue, 06 Sep 2011 12:00:00 +0200 guymager-beta (0.6.0beta3-1) unstable; urgency=low * New thread debugging messages -- Guy Voncken Tue, 05 Sep 2011 14:00:00 +0200 guymager-beta (0.6.0beta2-1) unstable; urgency=low * New EWF module reduces memory footprint significantly. * Posibility to compute MD5 hashes of the individual image files and write them to the .info file. * Better log output always contains acquired device * Bug removed where libewf only did empty block compression (slight API change in libewf20100226) -- Guy Voncken Tue, 01 Sep 2011 14:00:00 +0200 guymager-beta (0.6.0beta1-1) unstable; urgency=low * Compression problem with libewf20100226 fixed * Wrong file size check in acquisition dialog corrected -- Guy Voncken Tue, 23 Aug 2011 10:00:00 +0200 guymager-beta (0.5.9-1) unstable; urgency=low * Releasing 0.5.8beta10-1 as 0.5.9 -- Guy Voncken Thu, 07 Jul 2011 16:00:00 +0200 guymager-beta (0.5.8beta10-1) unstable; urgency=low * CREDITS updated * guymager.desktop corrected * Recommends gksu because of new menu entry * Officialy released as 0.5.9 -- Guy Voncken Thu, 07 Jul 2011 16:00:00 +0200 guymager-beta (0.5.8beta9-1) unstable; urgency=low * Copyright and Credits adapted/added -- Guy Voncken Fri, 01 Jul 2011 12:15:00 +0200 guymager-beta (0.5.8beta8-1) unstable; urgency=low * Menu entry and icon -- Guy Voncken Tue, 30 Jun 2011 16:55:00 +0200 guymager-beta (0.5.8beta7-1) unstable; urgency=low * Create destination directory if it does not exist (recursively) -- Guy Voncken Tue, 29 Jun 2011 16:30:00 +0200 guymager-beta (0.5.8beta6-1) unstable; urgency=low * Moved to libewf20100226 * Allow EWF files above 2GB -- Guy Voncken Tue, 28 Jun 2011 14:00:00 +0200 guymager-beta (0.5.8beta5-2) unstable; urgency=low * Special version for debugging serial nr. problem (Th. Schwarze) -- Guy Voncken Wed, 16 Feb 2011 14:00:00 +0100 guymager-beta (0.5.8beta5-1) unstable; urgency=low * Reading out sector size if using UDisks and writing it correctly to EWF files. -- Guy Voncken Wed, 11 Feb 2011 10:00:00 +0100 guymager-beta (0.5.8beta4-1) unstable; urgency=low * Do not Autoexit if there's an acquisition aborted because of errors (user aborts are ok) * Try to start Kubuntu's udisk daemon by accessing it, only then check if it's up and running -- Guy Voncken Tue, 25 Jan 2011 11:30:00 +0100 guymager-beta (0.5.8beta3-1) unstable; urgency=low * AutoExit behaviour corrected in case of user abort * Returning correct exit code -- Guy Voncken Mon, 20 Dec 2010 12:00:00 +0100 guymager-beta (0.5.8beta2-1) unstable; urgency=low * write fifo no longer shows the dummy blocks it still contains while image verification * man pages updated * Special exit code 1 upon AutoExit * Default AFF block size set to 64K -- Guy Voncken Mon, 20 Dec 2010 11:30:00 +0100 guymager-beta (0.5.8beta1-1) unstable; urgency=low * Autoexit feature added * Copyright information integrated correctly into source code (thanks to Mika) * Compiler/assembler problems for Ubuntu 10.10 removed -- Guy Voncken Wed, 6 Oct 2010 11:30:00 +0200 guymager-beta (0.5.7beta2-1) unstable; urgency=low * Memory leak in FIFO buffer removed * Module MemWatch removed (use valgrind instead) -- Guy Voncken Tue, 14 Sep 2010 10:00:00 +0200 guymager-beta (0.5.7beta1-1) unstable; urgency=low * Fixed a bug where Guymager refused to add 2 special devices of the same size. -- Guy Voncken Mon, 30 Aug 2010 14:45:00 +0200 guymager-beta (0.5.6beta1-1) unstable; urgency=low * Using min. 3 digits for split dd file extension * Treating file open error in ThreadWrite as a problem and not as a reason for ending Guymager * Removed bug in acquisition dialog with unsplit dd image -- Guy Voncken Mon, 09 Aug 2010 10:30:00 +0200 guymager-beta (0.5.5beta1-1) unstable; urgency=low * Language files updated * Bug in clone dialog removed (segfault when pressing ok) * The acquire dialog is no longer limited to 2/3 of the screen when first opened. -- Guy Voncken Fri, 06 Aug 2010 14:15:00 +0200 guymager-beta (0.5.4beta1-1) unstable; urgency=low * Supporting split dd images -- Guy Voncken Tue, 03 Aug 2010 11:15:00 +0200 guymager-beta (0.5.3beta1-1) unstable; urgency=low * First official beta release of guymager-beta -- Guy Voncken Mon, 02 May 2010 15:15:00 +0200 guymager-beta (0.5.1beta11-1) unstable; urgency=low * Show config errors on console * DeviceKit now is named UDisks in Ubuntu 10.04 * Clone dialog resized * Package dependencies debugged -- Guy Voncken Mon, 02 May 2010 11:45:00 +0200 guymager-beta (0.5.1beta10-1) unstable; urgency=low * New guymager-beta package * Preparations for split dd images (not finished yet) -- Guy Voncken Fri, 30 Apr 2010 16:45:00 +0200 guymager (0.5.1beta9-0) unstable; urgency=low * Acquisition dialog made scrollable (for low resolution screens) -- Guy Voncken Fri, 24 Mar 2010 16:00:00 +0100 guymager (0.5.1beta8-0) unstable; urgency=low * Corrected bug where acquisition hangs on write errros * Checking also device model for checking if it is a local device * Debug clone function -- Guy Voncken Fri, 09 Mar 2010 11:45:00 +0100 guymager (0.5.1beta7-0) unstable; urgency=low * Device cloning added -- Guy Voncken Fri, 26 Feb 2010 09:30:00 +0100 guymager (0.5.1beta6-0) unstable; urgency=low * Direct read mode for source device * If special device size unknown, try seek_end to get it * Debugged of checking if special device already there -- Guy Voncken Thu, 4 Feb 2010 15:06:11 +0100 guymager (0.5.1beta5-0) unstable; urgency=low * Special devices added * Writing image meta data (case number, examiner, ...) to info file * Own memory manager for FIFO queues -- Guy Voncken Fri, 8 Dec 2009 15:06:11 +0100 guymager (0.5.1beta4-0) unstable; urgency=low * Bug in file name check / test file access removed -- Guy Voncken Mon, 8 Dec 2009 11:00:00 +0100 guymager (0.5.1beta3-0) unstable; urgency=low * New search method for finding libparted * Checkbox fields in acquisition dialog now fully configurable -- Guy Voncken Mon, 7 Dec 2009 10:00:00 +0100 guymager (0.5.1beta2-0) unstable; urgency=low * Image verification added (for all formats: aff, ewf and dd) * Support for DeviceKit-Disks (thanks -> Daniel Gillen) * Small bug in acquisition dialog removed -- Guy Voncken Tue, 8 Nov 2009 08:30:00 +0200 guymager (0.5.1beta1-0) unstable; urgency=low * Reading HPA/DCO information (only for displaying) * EWF sub format Encase6 can now be selected * Tests with libewf 2009xxxxbeta (EWF call sequence changed to avoid libwf bug) -- Guy Voncken Thu, 8 Oct 2009 14:00:00 +0200 guymager (0.5.0beta1-0) unstable; urgency=low * Code cosmetics * MD5 and SHA256 calculation can be seprately switched on/off * No direct usage of libparted any longer, loading it dynamically instead * Allowing to switch over to libparted (DBus) in case of failure of DBus (libparted) * Releasing all this as Guymager 0.4.2 -- Guy Voncken Fri, 25 Sep 2009 09:00:00 +0200 guymager (0.4.0beta12) unstable; urgency=low * Better device detection when using HAL * Automatic language selection * Checking for write access on destination path before starting acquisition * Locale clean up * More precise size display; using SI units for sizes * Info area updated (showing start timestamp and running time) * %size% parameter (cfgtable DlgAcquireField) unit switch changed -- Guy Voncken Thu, 13 Aug 2009 14:00:00 +0200 guymager (0.4.0beta11) unstable; urgency=low * afflib removed, using own aaff code instead * optimised sha256 calculation -- Guy Voncken Fri, 31 Jul 2009 16:00:00 +0200 guymager (0.4.0beta10) unstable; urgency=low * Flushing dd data before closing file * Fifo size calculation reviewed -- Guy Voncken Thu, 23 Apr 2009 17:00:00 +0200 guymager (0.4.0beta9) unstable; urgency=low * Debug aff parallelised compression * Ask before overwriting image files * New cfg params FifoBlockSizeDD, FifoBlockSizeEWF and FifoBlockSizeAFF * New cfg param FifoMaxMem and automatic fifo queue size calculation * Fixed a bug where Guymager crashed if several configuration parameters where given on the command line -- Guy Voncken Thu, 16 Apr 2009 16:00:00 +0200 guymager (0.4.0beta8) unstable; urgency=low * Using libaff with parallelised compression -- Guy Voncken Mon, 07 Apr 2009 10:00:00 +0200 guymager (0.4.0beta7) unstable; urgency=low * Info directory bug removed * New cfg parameter AffCompression -- Guy Voncken Mon, 30 Mar 2009 15:00:00 +0200 guymager (0.4.0beta6) unstable; urgency=low * Support for SHA256 -- Guy Voncken Fri, 02 Jan 2009 14:30:00 +0200 guymager (0.4.0beta5) unstable; urgency=low * New cfg param CheckEwfData * Cfg param EwfSegmentSize limited to 2047 -- Guy Voncken Fri, 23 Dec 2008 14:30:00 +0200 guymager (0.4.0beta4) unstable; urgency=low * Supporting AFF format * Treating image and info path separately -- Guy Voncken Fri, 05 Dec 2008 14:30:00 +0200 guymager (0.4.0beta3) unstable; urgency=low * Hash comparison error * Language files updated * Suppports all EWF subformats included in libewf * Info and image paths treatted separately -- Guy Voncken Fri, 10 Oct 2008 14:30:00 +0200 guymager (0.4.0beta2) unstable; urgency=low * MD5-Verification added (Source device read 2 times if enabled) * Using minimal display width for certain columnns * New command in cfg-table DeviceInfoCommands for detecting (maybe) HPAs * Circle with configurable color for acquisition state field -- Guy Voncken Wed, 01 Oct 2008 11:00:00 +0200 guymager (0.4.0beta1) unstable; urgency=low * Own MD5 functions added (copied from fdupes) in order to avoid other dependencies * Linking libparted statically to avoid dependency problems * Missing build dependency for libqt4-dev added -- Guy Voncken Tue, 16 Sep 2008 09:45:00 +0200 guymager (0.3.0beta3) unstable; urgency=low * Several things concerning Debian packaging * New, flexible handling for acquisition dialog fields * Language support -- Guy Voncken Tue, 09 Sep 2008 17:15:00 +0200 guymager (0.3.0beta2) unstable; urgency=low * New cfg param SpecialFilenameChars for allowing special chars in image and info filenames * Writing version info also to log file * Auto-detect number of CPUs for optimal multi-threaded compression * Special sequence %size% in cfg file expands to non fractional value -- Guy Voncken Tue, 02 Sep 2008 15:00:00 +0200 guymager (0.3.0beta1) unstable; urgency=low * Possibility to chose between self-written or Qt file dialog (cfg param UseFileDialogFromQt) * Correct display of libewf version in use * Device matching on device rescan corrected (as some memsticks behave like 2 devices with identical serial nr.) * When starting without root rights: Ask user if he really wants this -- Guy Voncken Tue, 15 Apr 2008 12:00:00 +0200 guymager (0.2.0beta3) unstable; urgency=low * Locale initialisation added * MemWatch really switched off if UseMemWatch is false * Simplified compilation * Man page added * Debian package corrections (lintian no longer reports errors) -- Guy Voncken Tue, 01 Apr 2008 15:15:00 +0200 guymager (0.2.0beta2) unstable; urgency=low * Current unstable -- Guy Voncken Tue, 01 Apr 2008 15:15:00 +0200 guymager (0.2.0beta1) unstable; urgency=low * Current unstable -- Guy Voncken Fri, 21 Mar 2008 08:00:00 +0200 guymager (0.1.0-1) unstable; urgency=low * First official branch, released for "BKA-Fachtagung forensische IuK", 18-19 Sept. 2007, D-Knuellwald. -- Guy Voncken Wed, 12 Sep 2007 16:00:19 +0200 guymager-0.8.8/common.h000066400000000000000000000072341325467206100150240ustar00rootroot00000000000000// **************************************************************************** // 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 // 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.8/compileinfo.h000066400000000000000000000030731325467206100160350ustar00rootroot00000000000000// **************************************************************************** // 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 // 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 *pCompileInfoTimestamp; extern const char *pCompileInfoVersion; guymager-0.8.8/compileinfo.sh000077500000000000000000000010061325467206100162150ustar00rootroot00000000000000#!/bin/bash echo '// Automatically generated file. See project file and compileinfo.sh for further information.' date --utc '+const char *pCompileInfoTimestamp = "%Y-%m-%d-%H.%M.%S";' head -qn 1 changelog debian/changelog 2>/dev/null | awk '{ Version = $2 gsub ("\\(", "", Version) gsub ("\\)", "", Version) print "const char *pCompileInfoVersion = \"" Version "\";"}' guymager-0.8.8/config.cpp000066400000000000000000002041441325467206100153330ustar00rootroot00000000000000// **************************************************************************** // 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 // 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_pchar *ppErrorText); static APIRET CfgIniCPUs (t_pToolCfgParamDesc pCfgParamDesc, t_pchar *ppErrorText); static APIRET CfgIniMem (t_pToolCfgParamDesc pCfgParamDesc, t_pchar *ppErrorText); static APIRET CfgIniJobs (t_pToolCfgParamDesc pCfgParamDesc, t_pchar *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 }, { NULL , 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 }, { NULL , 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}, { NULL , 0 } }; static t_ToolCfgSet SetArrEntryMode[] = { // Name in cfg file Corresponding value // ------------------------------------------- { "HIDE" , CFG_ENTRYMODE_HIDE }, { "SHOWDEFAULT" , CFG_ENTRYMODE_SHOWDEFAULT}, { "SHOWLAST" , CFG_ENTRYMODE_SHOWLAST }, { NULL , 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 }, { NULL , 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 }, { NULL , 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}, { NULL , 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 { NULL , 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 }, { NULL , 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 }, { NULL , 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 }, { NULL , 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 }, { NULL, 0 } }; static t_ToolCfgSet SetArrEwfNaming[] = { // Name in cfg file Corresponding value // ---------------------------------------- { "Old", EWFNAMING_OLD }, { "FTK", EWFNAMING_FTK }, { NULL, 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 , NULL , {CMDLINE_OPTION_LOG , CFGTYPE_NULL , 0 , 0, 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_CMD , NULL , {CMDLINE_OPTION_CFG , CFGTYPE_NULL , 0 , 0, 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, CfgIniLang , {"Language" , CFGTYPE_STRING , ELT_SIZ(Language) , 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"CheckRootRights" , CFGTYPE_SET , ELT_SIZ(CheckRootRights) , 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"StartupSize" , CFGTYPE_SET , ELT(StartupSize) , 0, 0, 0, INIARR(SetArrStartupSize) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"StartupSizeManualX" , CFGTYPE_INTEGER, ELT(StartupSizeManualX ), 0, 0, 3000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"StartupSizeManualY" , CFGTYPE_INTEGER, ELT(StartupSizeManualY ), 0, 0, 3000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"StartupSizeManualDx" , CFGTYPE_INTEGER, ELT(StartupSizeManualDx ), 0, 0, 3000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"StartupSizeManualDy" , CFGTYPE_INTEGER, ELT(StartupSizeManualDy ), 0, 0, 3000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"FileDialogSize" , CFGTYPE_SET , ELT(FileDialogSize) , 0, 0, 0, INIARR(SetArrStartupSize) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"FileDialogSizeManualDx" , CFGTYPE_INTEGER, ELT(FileDialogSizeManualDx ), 0, 0, 3000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"FileDialogSizeManualDy" , CFGTYPE_INTEGER, ELT(FileDialogSizeManualDy ), 0, 0, 3000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"NumberStyle" , CFGTYPE_SET , ELT(NumberStyle) , 0, 0, 0, INIARR(SetArrNumberStyle) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"ScreenRefreshInterval" , CFGTYPE_INTEGER, ELT(ScreenRefreshInterval ), 0, 1, 8640000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"UseFileDialogFromQt" , CFGTYPE_SET , ELT(UseFileDialogFromQt) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"UserFieldName" , CFGTYPE_STRING , ELT_SIZ(UserFieldName ), 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AdditionalStateInfoName" , CFGTYPE_STRING , ELT_SIZ(AdditionalStateInfoName ), 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"WarnAboutImageSize" , CFGTYPE_SET , ELT(WarnAboutImageSize) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"WarnAboutSegmentFileCount" , CFGTYPE_SET , ELT(WarnAboutSegmentFileCount) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AutoExit" , CFGTYPE_SET , ELT(AutoExit) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AutoExitCountdown" , CFGTYPE_INTEGER, ELT(AutoExitCountdown) , 0, 3, 864000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"DefaultFormat" , CFGTYPE_SET , ELT(DefaultFormat) , 0, 0, 0, INIARR(SetArrFormat) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"InfoFieldsForDd" , CFGTYPE_SET , ELT(InfoFieldsForDd) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"EwfFormat" , CFGTYPE_SET , ELT(EwfFormat ) , 0, 0, 0, INIARR(SetArrEwfFormat) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"EwfCompression" , CFGTYPE_SET , ELT(EwfCompression) , 0, 0, 0, INIARR(SetArrEwfCompression) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"EwfCompressionThreshold" , CFGTYPE_DOUBLE , ELT(EwfCompressionThreshold) , 0, 0.0, 1.0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"EwfNaming" , CFGTYPE_SET , ELT(EwfNaming) , 0, 0, 0, INIARR(SetArrEwfNaming) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AffEnabled" , CFGTYPE_SET , ELT(AffEnabled) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AffCompression" , CFGTYPE_INTEGER, ELT(AffCompression) , 0, 1, 9, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AffMarkBadSectors" , CFGTYPE_SET , ELT(AffMarkBadSectors) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"SpecialFilenameChars" , CFGTYPE_STRING , ELT_SIZ(SpecialFilenameChars) , 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"CalcImageFileMD5" , CFGTYPE_SET , ELT(CalcImageFileMD5) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"DuplicateImage" , CFGTYPE_SET , ELT(DuplicateImage) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"DirectoryFieldEditing" , CFGTYPE_SET , ELT(DirectoryFieldEditing) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AllowPathInFilename" , CFGTYPE_SET , ELT(AllowPathInFilename) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"ConfirmDirectoryCreation" , CFGTYPE_SET , ELT(ConfirmDirectoryCreation) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AvoidEncaseProblems" , CFGTYPE_SET , ELT(AvoidEncaseProblems) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"AvoidCifsProblems" , CFGTYPE_SET , ELT(AvoidCifsProblems) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"DeviceScanMethod" , CFGTYPE_SET , ELT(DeviceScanMethod) , 0, 0, 0, INIARR(SetArrDeviceScanMethod) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"ScanInterval" , CFGTYPE_INTEGER, ELT(ScanInterval ), 0, 1, 8640000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"CommandGetSerialNumber" , CFGTYPE_STRING , ELT_SIZ(CommandGetSerialNumber ), 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"ForceCommandGetSerialNumber" , CFGTYPE_SET , ELT(ForceCommandGetSerialNumber ), 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"CommandGetAddStateInfo" , CFGTYPE_STRING , ELT_SIZ(CommandGetAddStateInfo ), 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"CommandAcquisitionEnd" , CFGTYPE_STRING , ELT_SIZ(CommandAcquisitionEnd ), 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"QueryDeviceMediaInfo" , CFGTYPE_SET , ELT(QueryDeviceMediaInfo ), 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"DirectIO" , CFGTYPE_SET , ELT(DirectIO ), 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"RunStatsTemplateActive" , CFGTYPE_STRING , ELT_SIZ(RunStatsTemplateActive ), 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"RunStatsTemplateEnded" , CFGTYPE_STRING , ELT_SIZ(RunStatsTemplateEnded ), 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"RunStatsOutput" , CFGTYPE_STRING , ELT_SIZ(RunStatsOutput ), 0, 0, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"RunStatsInterval" , CFGTYPE_INTEGER, ELT(RunStatsInterval ), 0, 1,99999999, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"FifoBlockSizeDD" , CFGTYPE_INTEGER, ELT(FifoBlockSizeDD ), 0, 0,99999999, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"FifoBlockSizeEWF" , CFGTYPE_INTEGER, ELT(FifoBlockSizeEWF ), 0, 0,99999999, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"FifoBlockSizeAFF" , CFGTYPE_INTEGER, ELT(FifoBlockSizeAFF ), 0, 0,99999999, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, CfgIniMem , {"FifoMaxMem" , CFGTYPE_INTEGER, ELT(FifoMaxMem ), 0, 0, 2000, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"FifoMemoryManager" , CFGTYPE_SET , ELT(FifoMemoryManager) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"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, NULL , {"BadSectorLogThreshold" , CFGTYPE_INTEGER, ELT(BadSectorLogThreshold) , 0, 0,99999999, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"BadSectorLogModulo" , CFGTYPE_INTEGER, ELT(BadSectorLogModulo) , 0, 1,99999999, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, CfgIniJobs , {"LimitJobs" , CFGTYPE_SET , ELT(LimitJobs) , 0, 1, 8, INIARR(SetArrMaximumJobs) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"JobMaxBadSectors" , CFGTYPE_INTEGER, ELT(JobMaxBadSectors) , 0, 0,99999999, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"JobDisconnectTimeout" , CFGTYPE_INTEGER, ELT(JobDisconnectTimeout) , 0, 0,99999999, NULL }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"LocalHiddenDevicesUseRegExp" , CFGTYPE_SET , ELT(LocalHiddenDevicesUseRegExp) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"SignalHandling" , CFGTYPE_SET , ELT(SignalHandling) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"WriteToDevNull" , CFGTYPE_SET , ELT(WriteToDevNull) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"UseMemWatch" , CFGTYPE_SET , ELT(UseMemWatch) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"VerboseLibewf" , CFGTYPE_SET , ELT(VerboseLibewf) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {"CheckEwfData" , CFGTYPE_SET , ELT(CheckEwfData) , 0, 0, 0, INIARR(SetArrBoolean) }, CFG_FILLUP_FORLINT}, {CFGASSIGN_BOTH_MULTIPLE, NULL , {NULL ,(t_ToolCfgType)0, 0, 0, 0, 0, 0 }, CFG_FILLUP_FORLINT} }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: Languages // ---------------------------------------------------------------------------------------------------------------------- //static t_pCfgBuffLanguage pLanguage = NULL; //#undef ELT //#undef ELT_SIZ //#define ELT_SIZ(Elt) (long)&pLanguage->Elt, sizeof (pLanguage->Elt)-1 // for strings only, thus substract 1 byte (for terminating 0) // //static t_ToolCfgDataDesc CfgDescArrLanguage [] = //{ // // ParameterName Type (see DestinationOfs Len Min Max SetArray // // in cfg file t_ToolCfgType) type is long (CFGTYPE_SET only) // // ----------------------------------------------------------------------------------- // { "Code", CFGTYPE_STRING , ELT_SIZ(Code) , 0, 0, NULL }, // { "Name", CFGTYPE_STRING , ELT_SIZ(AsciiName) , 0, 0, NULL }, // { NULL , CFGTYPE_NULL , 0, 0, 0, 0, NULL } //}; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: Fonts // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffFont pFont0 = NULL; #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, NULL }, { "Size", CFGTYPE_INTEGER, ELT(Size) , 0, 0, 100, NULL }, { "Weight", CFGTYPE_INTEGER, ELT(Weight) , 0, 0, 100, NULL }, { "Italic", CFGTYPE_SET , ELT(Italic) , 0, 0, 0, SetArrBoolean }, { NULL , CFGTYPE_NULL , 0 , 0, 0, 0, NULL } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: Columns // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgColumn pColumn0 = NULL; #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, NULL }, { "Alignment" , CFGTYPE_SET , ELT(Alignment) , 0, 0, 0, SetArrAlignment }, { "MinWidth" , CFGTYPE_INTEGER, ELT(MinWidth) , 0, 0, 9999, NULL }, { "ShowInMainTable", CFGTYPE_SET , ELT(ShowInMainTable) , 0, 0, 0, SetArrBoolean }, { "ShowInCloneTabe", CFGTYPE_SET , ELT(ShowInCloneTable), 0, 0, 0, SetArrBoolean }, { NULL , CFGTYPE_NULL , 0 , 0, 0, 0, NULL } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: Colors // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffColor pColor0 = NULL; #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, NULL }, { "G", CFGTYPE_INTEGER, ELT(G) , 0, 0, 255, NULL }, { "B", CFGTYPE_INTEGER, ELT(B) , 0, 0, 255, NULL }, { NULL , CFGTYPE_NULL , 0 , 0, 0, 0, NULL } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: LocalHiddenDevices // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffLocalHiddenDevice pLoc0 = NULL; #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, NULL }, { NULL , CFGTYPE_NULL , 0 , 0, 0, 0, NULL } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: DeviceInfoCommands // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffDeviceInfoCommand pCmd0 = NULL; #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, NULL }, { NULL , CFGTYPE_NULL , 0 , 0, 0, 0, NULL } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: DlgAcquireField // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffDlgAcquireField pFld0 = NULL; #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, NULL }, { "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, NULL }, { NULL , CFGTYPE_NULL , 0 , 0, 0, 0, NULL } }; // ---------------------------------------------------------------------------------------------------------------------- // TABLE: DlgAcquireRule // ---------------------------------------------------------------------------------------------------------------------- static t_pCfgBuffDlgAcquireRule pFil0 = NULL; #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, NULL }, { "DestinationFieldName", CFGTYPE_STRING , ELT_SIZ(DestFieldName) , 0, 0, NULL }, { "Value" , CFGTYPE_STRING , ELT_SIZ(Value) , 0, 0, NULL }, { NULL , CFGTYPE_NULL , 0 , 0, 0, 0, NULL } }; // ---------------------------------------------------------------------------------------------------------------------- // 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]}, {NULL , NULL , NULL , NULL , NULL } }; //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]; 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)) if (!CONFIG(AffEnabled) && (CONFIG(DefaultFormat) == t_File::AAFF)) { LOG_INFO ("Problem in configuration detected: AffEnabled is off, but AFF is set as default format. Please correct settings for parameter AffEnabled or DefaultFormat.") 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_pchar *ppErrorText) { QString Language = CONFIG(Language); QString LanguageSystem; *ppErrorText = NULL; 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_pchar *ppErrorText) { t_pcchar pParamName; unsigned int CPUs; *ppErrorText = NULL; 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) = 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_pchar *ppErrorText) { t_pcchar pParamName; int CPUs; *ppErrorText = NULL; 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_pchar *ppErrorText) { t_pcchar pParamName; unsigned long long Bytes; *ppErrorText = NULL; 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), 64); // Stay below 64MB 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 = NULL; // #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 = NULL; return NO_ERROR; } static APIRET CfgFontEnd (t_pcchar *ppErrorText) { // const char *pObjectName; // int i; *ppErrorText = NULL; // for (i=0; i= 0) && (Object < FONTOBJECT_COUNT)) //lint !e568: non-negative quantity is never less than zero return (CfgLocal.FontArr[Object]); else return NULL; } static APIRET CfgDestroyFonts (void) { int i; 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 = NULL; 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 = NULL; return NO_ERROR; } static APIRET CfgColorEnd (t_pcchar *ppErrorText) { const char *pName; int i; *ppErrorText = NULL; for (i=0; i= 0) && (Color < COLOR_COUNT)) //lint !e568: non-negative quantity is never less than zero return (CfgLocal.ColorArr[Color]); else return NULL; } } static APIRET CfgDestroyColors (void) { int i; for (i=0; i