-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathulibewf.pas
1235 lines (1133 loc) · 50.1 KB
/
ulibewf.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit uLibEWF;
{$MODE Delphi}
{/*
* Original Module providing Delphi bindings for the Library for the
* Expert Witness Compression Format Support (libewf.dll)
* LibEWF (and the libewf-x64.dll, libewf-x86.dll and libewf-Linux-x64.so Linux file)
* are compiled from source by Ted Smith from Joachim Metz
* (joachimmetz - https://github.com/libyal/libewf) LibEWF library using MSYS2
* on Windows and gcc on Linux. LibEWF is LGPL-3.0 Licensed.
Acknowledgements: libewf
Copyright (c) 2006-2021, Joachim Metz <[email protected]>
Joachims code, from which this wrapper has been built, is derived from information
and software contributed by:
- Expert Witness Compression Format specification by Andrew Rosen
(http://www.arsdata.com/SMART/whitepaper.html)
- libevf from PyFlag by Michael Cohen
(http://pyflag.sourceforge.net/)
- Zlib for the implementation of the Zlib compression and optimized
Adler32 function
- OpenSSL for the implementation of the MD5 and SHA1 hash algorithm
- libuuid for the implementation of GUID/UUID calculation
- Wietse Venema for an example of the initial error handling code
Additional credits go to:
- Kees Mastwijk, Hoffmann Invesigations for writing the initial man pages.
- Robert Jan Mora, Hoffmann Invesigations for testing and other contribution
(http://www.hoffmannbv.nl/).
- Rob Meijer, KLPD for providing libtool and header installation,
and ISO8601 date string support patches/adjustments.
- The OCFA team <[email protected]>, for EWF Fuse integration.
- George M. Garner Jr. for his support with the native Windows port.
- Christophe Grenier for his various input and support for the SPEC file
autoconf/automake integration.
- Guy Voncken for his support and thorough testing of the EWF files
generated by libewf and for help with the deb package support.
- David Loveall <[email protected]> for creating mount-ewf,
a MacOS-X installation package and the providing for the delta segment file idea.
- David Collett <[email protected]> for providing the Python bindings (pyewf).
- Simson Garfinkel for providing the MinGW compilation adjustments, Digital
Forensics XML (DFXML) output for the ewftools and various input and support
e.g. for autoconf/automake optimization.
- Bernhard Zach <[email protected]>, for providing a C++ 11 multi-threaded
version of ewfacquirestream and proposing multiple write performance enhancements.
- Several others for pointing out flaws within the product and its related
documentation. Refer to the project website for more information:
http://code.google.com/p/libewf/
* libgcc_s_dw2-1.dll (GCC low-level runtime library) is licensed under
* GPL licence (https://gcc.gnu.org/) and the DLL was compiled using MSYS2
* libwinpthread-1.dll is licensed under MIT, BSD
* https://packages.msys2.org/package/mingw-w64-x86_64-libwinpthread and the DLL
* was compiled using MSYS2
* zLib is Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
* https://zlib.net/zlib_license.html and the DLL was compiled using MSYS2
*
* This wrapper unit is copyright (c) 2010 Brendan Berney <[email protected]> and modified
* and updated by Ted Smith 2015, and 2021 for QuickHash GUI ([email protected])
* (c) 2011-2021
*
* This software is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software 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 Lesser General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/}
interface
uses
Messages, SysUtils, Classes,forms,
Dialogs, StdCtrls, FileUtil,
{$ifdef Windows}
Windows, ActiveX;
{$endif}
{$ifdef Linux}
dynlibs;
{$endif}
{$ifdef darwin}
dynlibs;
{$endif}
type
TINT16 = ShortInt; // was short
TUINT16 = word;
TUINT8 = byte;
PLIBEWFHDL = pointer;
TSIZE = longword;
TSIZE64 = int64;
PSIZE64 = ^int64;
TARRPCHAR = array of pansiChar;
PARRPCHAR = ^TARRPCHAR;
TLibEWFCheckSig = function(filename : pansiChar; error:pointer) : integer; cdecl;
TLibEWFOpen = function(filenames : TARRPCHAR; amount_of_files : TUINT16; flags : TUINT8) : PLIBEWFHDL; cdecl;
TLibEWFReadRand = function(handle : PLIBEWFHDL; buffer : pointer; size : TSIZE; offset : TSIZE64) : integer; cdecl;
Tlibewfhandlewriterand = function(handle : PLIBEWFHDL; buffer : pointer; size : TSIZE; offset : TSIZE64) : integer; cdecl;
TLibEWFParseHdrVals = function(handle : PLIBEWFHDL; date_format : TUINT8) : integer; cdecl;
TLibEWFGetMediaSize = function(handle : PLIBEWFHDL; media_size : PSIZE64) : integer; cdecl;
TLibEWFClose = function(handle : PLIBEWFHDL) : TINT16; cdecl;
//v2 functions
Tlibewfhandleopen = function(handle : PLIBEWFHDL;filenames : TARRPCHAR; amount_of_files : integer; flags : integer;error:pointer) : integer; cdecl;
Tlibewfhandleinitialize = function(handle : PLIBEWFHDL;error:pointer) : integer; cdecl; //pointer to PLIBEWFHDL
Tlibewfhandlefree = function(handle : PLIBEWFHDL;error:pointer) : integer; cdecl; //pointer to PLIBEWFHDL
Tlibewfhandleclose = function(handle : PLIBEWFHDL;error:pointer) : integer; cdecl;
Tlibewfhandlereadrandom = function(handle : PLIBEWFHDL; buffer : pointer; size : TSIZE; offset : TSIZE64;error:pointer) : integer; cdecl;
Tlibewfhandlewriterandom = function(handle : PLIBEWFHDL; buffer : pointer; size : TSIZE; offset : TSIZE64;error:pointer) : integer; cdecl;
Tlibewfhandlegetmediasize= function(handle : PLIBEWFHDL; media_size : PSIZE64;error:pointer) : integer; cdecl;
Tlibewfhandlesetcompressionvalues = function(handle : PLIBEWFHDL; compression_level:TUINT8;compression_flags:TUINT8 ; error:pointer) : integer; cdecl;
Tlibewfhandlesetutf8headervalue = function(handle : PLIBEWFHDL;identifier:pansichar;identifier_length:TSIZE;utf8_string:pansichar;utf8_string_length:TSIZE; error:pointer) : integer; cdecl;
Tlibewfhandlegetutf8headervalue = function(handle : PLIBEWFHDL;identifier:pansichar;identifier_length:TSIZE;utf8_string:pansichar;utf8_string_length:TSIZE; error:pointer) : integer; cdecl;
Tlibewfhandlegetutf8hashvalue = function(handle : PLIBEWFHDL;identifier:pansichar;identifier_length:TSIZE;utf8_string:string;utf8_string_length:TSIZE; error:pointer) : integer; cdecl;
TLibEWFErrorSPrint = function (error: pointer; str: pchar; size: TSIZE) : TINT16; cdecl;
Tlibewfhandlereadbuffer = function(handle : PLIBEWFHDL; buffer : pointer; size : TSIZE; error:pointer) : integer; cdecl;
Tlibewfhandlewritebuffer = function(handle : PLIBEWFHDL; buffer : pointer; size : TSIZE; error:pointer) : integer; cdecl;
TlibewfhandlesetMD5hash = function(handle : PLIBEWFHDL; md5_hash : Pointer; size : TSIZE; error:pointer) : integer; cdecl;
TlibewfhandlesetSHA1hash = function(handle : PLIBEWFHDL; sha1_hash : Pointer; size : TSIZE; error:pointer) : integer; cdecl;
Tlibewfhandlepreparewritechunk = function(handle : PLIBEWFHDL; buffer : pointer; buffer_size : TSIZE; compressed_buffer:pointer;compressed_size:tsize;is_compressed:tuint8;checksum:integer;write_checksum:tuint8; error:pointer) : integer; cdecl;
Tlibewfhandlewritechunk = function(handle : PLIBEWFHDL; buffer : pointer; buffer_size : TSIZE; data_size : TSIZE; is_compressed:tuint8; checksum_buffer:pointer; chunk_checksum:integer; chunk_io_flags:tuint8; error:pointer) : integer; cdecl;
Tlibewfhandlesetmaximumsegmentsize= function(handle : PLIBEWFHDL; size : TSIZE64; error:pointer) : integer; cdecl;
Tlibewfhandlesetformat = function(handle : PLIBEWFHDL; Format : TUINT8; error:pointer) : integer; cdecl;
Tlibewfhandlesetmediaflags = function(handle : PLIBEWFHDL; volume_type : TUINT8; error:pointer) : integer; cdecl;
Tlibewfhandleseekoffset = function(handle : PLIBEWFHDL; Offset : TSIZE64; whence : TSIZE; error:pointer) : integer; cdecl;
// LibEWF v3 (https://github.com/libyal/libewf/blob/57dfc1f510f08f34eb34452f6679c38185be9472/manuals/libewf.3)
Tlibewfcheckfilesignaturefileiohandle = function(handle : PLIBEWFHDL; error:pointer) : integer; cdecl;
Tlibewfhandleclone = function(hDestination : PLIBEWFHDL; hSource : PLIBEWFHDL; error:pointer) : integer; cdecl;
Tlibewfhandlesignalabort = function(handle : PLIBEWFHDL; error:pointer) : integer; cdecl;
Tlibewfhandlereadbufferatoffset = function(handle : PLIBEWFHDL; buffer : pointer; size : TSIZE; offset : TSIZE64; error:pointer) : integer; cdecl;
Tlibewfhandlewritebufferatoffset = function(handle : PLIBEWFHDL; buffer : pointer; size : TSIZE; offset : TSIZE64; error:pointer) : integer; cdecl;
Tlibewfhandlegetdatachunk = function(handle : PLIBEWFHDL; data_chunk : integer; error:pointer) : integer; cdecl;
Tlibewfhandlereaddatachunk = function(handle : PLIBEWFHDL; data_chunk : integer; error:pointer) : TSIZE; cdecl;
Tlibewfhandlewritedatachunk = function(handle : PLIBEWFHDL; data_chunk : integer; error:pointer) : TSIZE; cdecl;
Tlibewfhandlewritefinalize = function(handle : PLIBEWFHDL; error:pointer) : TSIZE; cdecl;
Tlibewfhandlegetoffset = function(handle : PLIBEWFHDL; offset : TSIZE64; error:pointer) : integer; cdecl;
Tlibewfhandlesetsegmentfilename = function(handle : PLIBEWFHDL; filename : string; filenamelength : TSIZE; error:pointer) : integer; cdecl;
Tlibewfhandlegetsegmentfilename = function(handle : PLIBEWFHDL; filename : string; filenamelength : TSIZE; error:pointer) : integer; cdecl;
Tlibewfhandlegetsegmentfilenamesize = function(handle : PLIBEWFHDL; filenamelength : TSIZE; error:pointer) : TSIZE; cdecl;
Tlibewfhandlegetmaximumsegmentsize = function(handle : PLIBEWFHDL; max_segment_size : TSIZE64; error:pointer) : TSIZE; cdecl;
Tlibewfhandlesegmentfilescorrupted = function(handle : PLIBEWFHDL; error:pointer) : TSIZE; cdecl;
Tlibewfhandlesegmentfilesencrypted = function(handle : PLIBEWFHDL; error:pointer) : TSIZE; cdecl;
Tlibewfhandlegetfilenamesize = function(handle : PLIBEWFHDL; filename_size : TSIZE; error:pointer) : TSIZE; cdecl;
Tlibewfhandlegetfilename = function(handle : PLIBEWFHDL; filename : string; filename_size : TSIZE; error:pointer) : TSIZE; cdecl;
Tlibewfhandlesetmaximumnumberofopenhandles= function(handle : PLIBEWFHDL; max_number_of_open_handles : TSIZE; error:pointer) : TSIZE; cdecl;
TLibEWF = class(TObject)
private
fLibHandle : TLibHandle;
fCurEWFHandle : PLIBEWFHDL;
fLibEWFCheckSig : TLibEWFCheckSig;
fLibEWFOpen : TLibEWFOpen;
fLibEWFReadRand : TLibEWFReadRand;
fLibEWFWriteRand : TLibEWFReadRand;
fLibEWFGetSize : TLibEWFGetMediaSize;
fLibEWFParseHdrVals : TLibEWFParseHdrVals;
fLibEWFClose : TLibEWFClose;
//v2
flibewfhandleopen : Tlibewfhandleopen;
flibewfhandleclose : Tlibewfhandleclose;
flibewfhandleinitialize : Tlibewfhandleinitialize;
flibewfhandlefree : Tlibewfhandlefree;
flibewfhandlereadrandom : Tlibewfhandlereadrandom;
flibewfhandlewriterandom : Tlibewfhandlewriterandom;
flibewfhandlegetmediasize : Tlibewfhandlegetmediasize;
flibewfhandlesetcompressionvalues : Tlibewfhandlesetcompressionvalues;
flibewfhandlesetutf8headervalue : Tlibewfhandlesetutf8headervalue;
flibewfhandlegetutf8headervalue : Tlibewfhandlegetutf8headervalue;
flibewfhandlegetutf8hashvalue : Tlibewfhandlegetutf8hashvalue;
fLibEWFErrorSPrint : TLibEWFErrorSPrint;
flibewfhandlereadbuffer : Tlibewfhandlereadbuffer;
flibewfhandlewritebuffer : Tlibewfhandlewritebuffer;
flibewfhandlesetMD5hash : TlibewfhandlesetMD5hash;
flibewfhandlepreparewritechunk : Tlibewfhandlepreparewritechunk;
flibewfhandlewritechunk : Tlibewfhandlewritechunk;
flibewfhandlesetsha1hash : Tlibewfhandlesetsha1hash;
flibewfhandlesetmaximumsegmentsize : Tlibewfhandlesetmaximumsegmentsize;
flibewfhandlesetformat : Tlibewfhandlesetformat;
flibewfhandlesetmediaflags : Tlibewfhandlesetmediaflags;
flibewfhandleseekoffset : Tlibewfhandleseekoffset;
// LibEWF v3
flibewfcheckfilesignaturefileiohandle : Tlibewfcheckfilesignaturefileiohandle;
flibewfhandleclone : Tlibewfhandleclone;
flibewfhandlesignalabort : Tlibewfhandlesignalabort;
flibewfhandlereadbufferatoffset : Tlibewfhandlereadbufferatoffset;
flibewfhandlewritebufferatoffset : Tlibewfhandlewritebufferatoffset;
flibewfhandlegetdatachunk : Tlibewfhandlegetdatachunk;
flibewfhandlereaddatachunk : Tlibewfhandlereaddatachunk;
flibewfhandlewritedatachunk : Tlibewfhandlewritedatachunk;
flibewfhandlewritefinalize : Tlibewfhandlewritefinalize;
flibewfhandlegetoffset : Tlibewfhandlegetoffset;
flibewfhandlesetsegmentfilename : Tlibewfhandlesetsegmentfilename;
flibewfhandlegetmaximumsegmentsize : Tlibewfhandlegetmaximumsegmentsize;
flibewfhandlesegmentfilescorrupted : Tlibewfhandlesegmentfilescorrupted;
flibewfhandlesegmentfilesencrypted : Tlibewfhandlesegmentfilesencrypted;
flibewfhandlegetfilenamesize : Tlibewfhandlegetfilenamesize;
flibewfhandlegetfilename : Tlibewfhandlegetfilename;
flibewfhandlegetsegmentfilename : Tlibewfhandlegetsegmentfilename;
flibewfhandlesetmaximumnumberofopenhandles : Tlibewfhandlesetmaximumnumberofopenhandles;
flibewfhandlegetsegmentfilenamesize : Tlibewfhandlegetsegmentfilenamesize;
public
constructor create();
destructor destroy(); override;
function InitialiseProcAddresses() : boolean;
function libewf_check_file_signature(const filename : ansistring ) : integer;
function libewf_check_file_signature_file_io_handle(handle : PLIBEWFHDL; error:pointer) : integer;
function libewf_open(const filename : ansistring;flag:byte=$1) : integer;
function libewf_read_random(buffer : pointer; size : longword; offset : int64) : integer;
function libewf_write_random(buffer : pointer; size : longword; offset : int64) : integer;
function libewf_handle_get_media_size() : int64;
function libewf_parse_header_values_deprecated(date_format : byte) : integer;
function libewf_close() : integer;
function libewf_HandleSetCompressionValues(level,flags:byte) : integer;
function libewf_SetHeaderValue(identifier,value:ansistring) : integer;
function libewf_GetHeaderValue(identifier:ansistring;var value:ansistring) : integer;
function libewf_GetHashValue(identifier:ansistring;var value:ansistring) : integer;
function libewf_handle_read_buffer(Buffer : Pointer; size : longword) : integer;
function libewf_handle_write_buffer(Buffer : Pointer; size : longword) : integer;
function libewf_handle_set_md5_hash(md5_hash : Pointer; size : TSIZE) : integer;
function libewf_handle_prepare_write_chunk(ChunkBuffer : Pointer; ChunkBufferSize, CompressedChunkBufferSize : integer; size : Longword) : integer;
function libewf_handle_write_chunk(Chunkbuffer : Pointer; ChunkBufferSize, CompressedChunkBufferSize : integer) : integer;
function libewf_handle_set_SHA1_hash(sha1_hash : Pointer; size : TSIZE) : integer;
function libewf_handle_set_maximum_segment_size(size : TSIZE64) : integer;
function libewf_handle_set_format(Format : TUINT8) : integer;
function libewf_handle_set_media_flags(volume_type : TUINT8) : integer;
function libewf_handle_seek_offset(Offset : TSIZE64; Whence : TSIZE) : integer;
end;
const
LIBEWF_OPEN_READ = $01;
LIBEWF_OPEN_WRITE = $02;
LIBEWF_DATE_FORMAT_DAYMONTH = $01;
LIBEWF_DATE_FORMAT_MONTHDAY = $02;
LIBEWF_DATE_FORMAT_ISO8601 = $03;
LIBEWF_DATE_FORMAT_CTIME = $04;
LIBEWF_DEFAULT_SEGMENT_FILE_SIZE = (1500 * 1024 * 1024); // 2086666240 = 1,990Mb
LIBEWF_VERSION = 'V2';
LIBEWF_FORMAT_UNKNOWN = $00;
LIBEWF_FORMAT_ENCASE1 = $01;
LIBEWF_FORMAT_ENCASE2 = $02;
LIBEWF_FORMAT_ENCASE3 = $03;
LIBEWF_FORMAT_ENCASE4 = $04;
LIBEWF_FORMAT_ENCASE5 = $05;
LIBEWF_FORMAT_ENCASE6 = $06;
LIBEWF_FORMAT_ENCASE7 = $07;
LIBEWF_FORMAT_SMART = $0e;
LIBEWF_FORMAT_FTK_IMAGER = $0f;
LIBEWF_FORMAT_LOGICAL_ENCASE5 = $10;
LIBEWF_FORMAT_LOGICAL_ENCASE6 = $11;
LIBEWF_FORMAT_LOGICAL_ENCASE7 = $12;
LIBEWF_FORMAT_LINEN5 = $25;
LIBEWF_FORMAT_LINEN6 = $26;
LIBEWF_FORMAT_LINEN7 = $27;
LIBEWF_FORMAT_V2_ENCASE7 = $37;
LIBEWF_FORMAT_V2_LOGICAL_ENCASE7 = $47;
LIBEWF_FORMAT_EWF = $70; // Andrew Rosen format
LIBEWF_FORMAT_EWFX = $71;
implementation
// Initilise all handles to any libewf processes
function TLibEWF.InitialiseProcAddresses() : boolean;
begin
result := false;
@flibewfhandleinitialize := nil;
@flibewfhandlefree := nil;
@flibewfhandleopen := nil;
@flibewfhandleclose := nil;
@flibewfhandlereadrandom := nil;
@flibewfhandlewriterandom := nil;
@flibewfhandlegetmediasize := nil;
@flibewfhandlesetcompressionvalues := nil;
@flibewfhandlesetutf8headervalue := nil;
@flibewfhandlegetutf8headervalue := nil;
@flibewfhandlegetutf8hashvalue := nil;
@fLibEWFCheckSig := nil;
@fLibEWFOpen := nil;
@fLibEWFReadRand := nil;
@fLibEWFWriteRand := nil;
@fLibEWFGetSize := nil;
@fLibEWFParseHdrVals := nil;
@fLibEWFClose := nil;
@fLibEWFErrorSPrint := nil;
@flibewfhandlereadbuffer := nil;
@flibEWFhandlewritebuffer := nil;
@flibewfhandlesetSHA1hash := nil;
@flibewfhandlesetMD5hash := nil;
@flibewfhandlepreparewritechunk := nil;
@flibewfhandlewritechunk := nil;
@flibewfhandlesetmaximumsegmentsize:= nil;
@flibewfhandlesetformat := nil;
@flibewfhandlesetmediaflags := nil;
@flibewfhandleseekoffset := nil;
// libEWF V3
@flibewfcheckfilesignaturefileiohandle := nil;
@flibewfhandleclone := nil;
@flibewfhandlesignalabort := nil;
@flibewfhandlereadbufferatoffset := nil;
@flibewfhandlewritebufferatoffset := nil;
@flibewfhandlegetdatachunk := nil;
@flibewfhandlereaddatachunk := nil;
@flibewfhandlewritedatachunk := nil;
@flibewfhandlewritefinalize := nil;
@flibewfhandlegetoffset := nil;
@flibewfhandlesetsegmentfilename := nil;
@flibewfhandlegetmaximumsegmentsize := nil;
@flibewfhandlesetmaximumsegmentsize := nil;
@flibewfhandlesegmentfilescorrupted := nil;
@flibewfhandlesegmentfilesencrypted := nil;
@flibewfhandlegetfilenamesize := nil;
@flibewfhandlegetfilename := nil;
@flibewfhandlegetsegmentfilename := nil;
@flibewfhandlesetmaximumnumberofopenhandles:= nil;
@flibewfhandlegetsegmentfilenamesize := nil;
result := true;
end;
{/*
* Constructs a LibEWF object instance (also loads the library).
*/}
constructor TLibEWF.create();
const
{$ifdef CPU32}
{$ifdef Windows}
LIB_FOLDER : ansistring = 'libs\x86';
{$endif}
{$ifdef Linux}
LIB_FOLDER : ansistring = 'libs/x86';
{$endif}
{$ifdef Darwin}
LIB_FOLDER : ansistring = 'libs/x86';
{$endif}
{$else ifdef CPU64}
{$ifdef Windows}
LIB_FOLDER : ansistring = 'libs\x64';
{$endif}
{$ifdef Linux}
LIB_FOLDER : ansistring = 'libs/x64';
{$endif}
{$ifdef Darwin}
LIB_FOLDER : ansistring = 'libs/x64'; // Not releasing this for functionality for OSX yet but may do in future
{$endif}
{$endif}
var
libFileName : ansistring = Default(ansistring);
cvtString : string = Default(string);
ProcAddressesInitialised : Boolean = Default(boolean);
begin
fLibHandle := nilhandle;
fCurEWFHandle:=nil;
{$ifdef Windows}
{$ifdef CPU32}
libFileName:=ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER)+'libewf-x86.dll';//-new.dll';
{$else ifdef CPU64}
libFileName:=ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER)+'libewf-x64.dll';//-new.dll';
{$endif}
{$endif}
{$ifdef Linux}
{$ifdef CPU32}
// Reserved for when we compile a 32-bit SO file
{$else ifdef CPU64}
libFileName:=ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER)+'libewf-Linux-x64.so';
{$endif}
{$endif}
if FileExists(libFileName) then
begin
{$ifdef Windows}
//fLibHandle := LoadLibraryA(PAnsiChar(libFileName)); // The usual route, but LoadLibraryEx enables me to ensure QH DLLs are loaded
fLibHandle := LoadLibraryEx(PAnsiChar(libFileName), 0, LOAD_WITH_ALTERED_SEARCH_PATH); // LOAD_WITH_ALTERED_SEARCH_PATH ensures our DLLs are used
{$endif}
{$ifdef Linux}
fLibHandle := LoadLibrary(libFileName);
{$endif}
// check whether loading was successful
if fLibHandle <> 0 then
begin
// assign address of the subroutine call to the variable cvtString
Pointer(cvtString) := GetProcAddress(fLibHandle, 'cvtString');
// check whether a valid address has been returned
if @cvtString <> nil then
begin
// just crack on. But could notify user with ShowMessage(cvtString + 'Success')
end
// error message on no valid address
else
ShowMessage('libewf library could not access memory address. LastOSError1 = ' + SysErrorMessage(GetLastOSError));
end
else
// error message on load failure
ShowMessage('libewf library could not be loaded. LastOSError2 = ' + SysErrorMessage(GetLastOSError));
if fLibHandle<>nilhandle then
begin
ProcAddressesInitialised := InitialiseProcAddresses;
if ProcAddressesInitialised = true then
begin
// libEWF v2
@flibewfhandleinitialize :=GetProcAddress(fLibHandle,'libewf_handle_initialize');
@flibewfhandlefree :=GetProcAddress(fLibHandle,'libewf_handle_free');
@flibewfhandleopen :=GetProcAddress(fLibHandle,'libewf_handle_open');
@flibewfhandleclose :=GetProcAddress(fLibHandle,'libewf_handle_close');
@flibewfhandlereadrandom :=GetProcAddress(fLibHandle,'libewf_handle_read_random');
@flibewfhandlewriterandom :=GetProcAddress(fLibHandle,'libewf_handle_write_random');
@flibewfhandlegetmediasize :=GetProcAddress(fLibHandle,'libewf_handle_get_media_size');
@flibewfhandlesetcompressionvalues :=GetProcAddress(fLibHandle,'libewf_handle_set_compression_values');
@flibewfhandlesetutf8headervalue :=GetProcAddress(fLibHandle,'libewf_handle_set_utf8_header_value');
@flibewfhandlegetutf8headervalue :=GetProcAddress(fLibHandle,'libewf_handle_get_utf8_header_value');
@flibewfhandlegetutf8hashvalue :=GetProcAddress(fLibHandle,'libewf_handle_get_utf8_hash_value');
@fLibEWFCheckSig :=GetProcAddress(fLibHandle,'libewf_check_file_signature');
@fLibEWFOpen :=GetProcAddress(fLibHandle,'libewf_open');
@fLibEWFReadRand :=GetProcAddress(fLibHandle,'libewf_read_random');
@fLibEWFWriteRand :=GetProcAddress(fLibHandle,'libewf_write_random');
@fLibEWFGetSize :=GetProcAddress(fLibHandle,'libewf_get_media_size');
@fLibEWFParseHdrVals :=GetProcAddress(fLibHandle,'libewf_parse_header_values');
@fLibEWFClose :=GetProcAddress(fLibHandle,'libewf_close');
@fLibEWFErrorSPrint :=GetProcAddress(fLibHandle,'libewf_error_backtrace_sprint');
@flibewfhandlereadbuffer :=GetProcAddress(fLibHandle,'libewf_handle_read_buffer');
@flibEWFhandlewritebuffer :=GetProcAddress(fLibHandle,'libewf_handle_write_buffer');
@flibewfhandlesetSHA1hash :=GetProcAddress(fLibHandle,'libewf_handle_set_sha1_hash');
@flibewfhandlesetMD5hash :=GetProcAddress(fLibHandle,'libewf_handle_set_md5_hash');
@flibewfhandlepreparewritechunk :=GetProcAddress(fLibHandle,'libewf_handle_prepare_write_chunk');
@flibewfhandlewritechunk :=GetProcAddress(fLibHandle,'libewf_handle_write_chunk');
@flibewfhandlesetmaximumsegmentsize:=GetProcAddress(fLibHandle,'libewf_handle_set_maximum_segment_size');
@flibewfhandlesetformat :=GetProcAddress(fLibHandle,'libewf_handle_set_format');
@flibewfhandlesetmediaflags :=GetProcAddress(fLibHandle,'libewf_handle_set_media_flags');
@flibewfhandleseekoffset :=GetProcAddress(fLibHandle,'libewf_handle_seek_offset');
// libEWF V3
@flibewfcheckfilesignaturefileiohandle :=GetProcAddress(fLibHandle,'libewf_check_file_signature_file_io_handle');
@flibewfhandleclone :=GetProcAddress(fLibHandle,'libewf_handle_clone'); // V3
@flibewfhandlesignalabort :=GetProcAddress(fLibHandle,'libewf_handle_signal_abort'); //V3
@flibewfhandlereadbufferatoffset :=GetProcAddress(fLibHandle,'libewf_handle_read_buffer_at_offset'); //V3
@flibewfhandlewritebufferatoffset :=GetProcAddress(fLibHandle,'libewf_handle_write_buffer_at_offset'); //V3
@flibewfhandlegetdatachunk :=GetProcAddress(fLibHandle,'libewf_handle_get_data_chunk'); //V3
@flibewfhandlereaddatachunk :=GetProcAddress(fLibHandle,'libewf_handle_read_data_chunk'); //V3
@flibewfhandlewritedatachunk :=GetProcAddress(fLibHandle,'libewf_handle_write_data_chunk'); //V3
@flibewfhandlewritefinalize :=GetProcAddress(fLibHandle,'libewf_handle_write_finalize'); //V3
@flibewfhandlegetoffset :=GetProcAddress(fLibHandle,'libewf_handle_get_offset'); //V3
@flibewfhandlesetsegmentfilename :=GetProcAddress(fLibHandle,'libewf_handle_set_segment_filename'); //V3
@flibewfhandlegetmaximumsegmentsize :=GetProcAddress(fLibHandle,'libewf_handle_get_maximum_segment_size'); //V3
@flibewfhandlesetmaximumsegmentsize :=GetProcAddress(fLibHandle,'libewf_handle_set_maximum_segment_size'); //V3
@flibewfhandlesegmentfilescorrupted :=GetProcAddress(fLibHandle,'libewf_handle_segment_files_corrupted'); //V3
@flibewfhandlesegmentfilesencrypted :=GetProcAddress(fLibHandle,'libewf_handle_segment_files_encrypted'); //V3
@flibewfhandlegetfilenamesize :=GetProcAddress(fLibHandle,'libewf_handle_get_filename_size'); //V3
@flibewfhandlegetfilename :=GetProcAddress(fLibHandle,'libewf_handle_get_filename'); //V3
@flibewfhandlegetsegmentfilename :=GetProcAddress(fLibHandle,'libewf_handle_get_segment_filename'); //V3
@flibewfhandlesetmaximumnumberofopenhandles:=GetProcAddress(fLibHandle,'libewf_handle_set_maximum_number_of_open_handles'); //V3
@flibewfhandlegetsegmentfilenamesize :=GetProcAddress(fLibHandle,'libewf_handle_get_segment_filename_size'); //V3
end // End of process address initialisation
end // End of libewf handle check
else showmessage('could not find libewf dll file');
end;
end;
destructor TLibEWF.destroy();
var
LibUnloadedOK : Boolean = Default(Boolean);
begin
if (fCurEWFHandle<>nil) then
begin
libewf_close();
{$ifdef Windows}
LibUnloadedOK := FreeLibrary(fLibHandle); // Use this for Delphi\Windows suitability re LoadLibraryA
{$endif}
{$ifdef Linux}
LibUnloadedOK :=UnloadLibrary(fLibHandle);// Use this for Linux suitability as we use standard LoadLibrary
{$endif}
end;
inherited;
end;
{/*
* Checks if the supplied file is a valid EWF file.
* @param filename - the filename (of the specific part (e01, e02 etc.)).
* @return 0 if successful and valid, -1 otherwise.
*/}
function TLibEWF.libewf_check_file_signature(const filename : ansistring) : integer;
var
err:pointer;
begin
Result:=0;
err := nil;
if fLibHandle<>0 then
begin
Result:=fLibEWFCheckSig(pansiChar(filename), @err);
end;
end;
function TLibEWF.libewf_check_file_signature_file_io_handle(handle : PLIBEWFHDL; error:pointer) : integer;
var
err : pointer;
ret:integer;
begin
result := 0;
err := nil;
if fLibHandle<>0 then
begin
result := fLibewfcheckfilesignaturefileiohandle(handle, @err);
end;
end;
{/*
* Open an entire (even multipart) EWF file.
* @param filename - the first (.e01) file name.
* @return 0 if successful and valid, -1 otherwise.
*/}
function TLibEWF.libewf_open(const filename : ansistring;flag:byte=$1) : integer;
const
UppercaseExt : ansistring = '.E01';
LowercaseExt : ansistring = '.e01';
var
filenames : TStringList;
fileNamePChars : TARRPCHAR;
pFileNamePChars : PARRPCHAR;
filenameRoot,curFilename : ansistring;
fCount : integer;
err:pointer;
ret:integer;
incrementorVal : integer = Default(integer);
UseUpperCase : Boolean = Default(Boolean);
begin
err :=nil;
Result :=-1;
filenames :=TStringList.Create;
try
if fLibHandle<>0 then
begin
// Deal with case sensitivity of E01 extension for cross platform purposes
if ExtractFileExt(filename) = UppercaseExt then
begin
filenameRoot:=Copy(filename,1, Length(filename)-4);
curFilename:=filenameRoot+UppercaseExt;
UseUpperCase := true;
end
else
begin
if ExtractFileExt(filename) = LowercaseExt then
begin
filenameRoot:=Copy(filename,1, Length(filename)-4);
curFilename:=filenameRoot+LowercaseExt;
UseUpperCase := false;
end;
end;
// Itterate all the E01 segments for the image set to build the list of E01 to X0X.
// Break if any are invalid E01 files.
while FileExists(curFilename) do
begin
if libewf_check_file_signature(curFilename)=1 then
begin
filenames.Add(curFilename);
end
else
begin
raise exception.Create(curFilename + ' seems to have invalid E01 signature.');
break;
end;
if UseUpperCase then
begin
curFilename:=filenameRoot+'.E'+Format('%.2d',[filenames.Count+1]);
end
else curFilename:=filenameRoot+'.e'+Format('%.2d',[filenames.Count+1]);
end;
if flag=$2 then filenames.Add(filenameRoot);
SetLength(fileNamePChars, filenames.Count);
for fCount:=0 to filenames.Count-1 do
begin
fileNamePChars[fCount]:=pansiChar(ansistring(filenames[fCount]));
end;
// Blank out space for handles
fCurEWFHandle := nil;
// Initiate handle to image, and then open it
if LIBEWF_VERSION='V2' then
begin
ret := flibewfhandleinitialize (@fCurEWFHandle,@err); //pointer to pointer = ** in c
if ret=1 then
if flibewfhandleopen (fCurEWFHandle,fileNamePChars, Length(fileNamePChars), flag,@err)<>1 then
raise exception.Create('libewf_handle_open failed.');
end;
if fCurEWFHandle<>nil then Result:=0;
end;
finally
FreeAndNil(filenames);
end;
end;
{/*
* Read an arbitrary part of the EWF file.
* @param buffer : pointer - pointer to a preallocated buffer (byte array) to read into.
* @param size - The number of bytes to read
* @param offset - The position within the EWF file.
* @return The number of bytes successfully read, -1 if unsuccessful.
*/}
function TLibEWF.libewf_read_random(buffer : pointer; size : longword; offset : int64) : integer;
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V1' then
Result:=fLibEWFReadRand(fCurEWFHandle, buffer, size, offset);
if LIBEWF_VERSION='V2' then
Result:=flibewfhandlereadrandom(fCurEWFHandle,
buffer,
size,
offset,
@err);
end;
// This will throw are more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
{/*
* write an arbitrary part of the EWF file.
* @param buffer : pointer - pointer to a preallocated buffer (byte array) to write from.
* @param size - The number of bytes to write
* @param offset - The position within the EWF file.
* @return The number of bytes successfully written, -1 if unsuccessful.
*/}
function TLibEWF.libewf_write_random(buffer : pointer; size : longword; offset : int64) : integer;
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V1' then Result:=fLibEWFWriteRand(fCurEWFHandle, buffer, size, offset);
if LIBEWF_VERSION='V2' then
Result:=flibewfhandlewriterandom(fCurEWFHandle,
buffer,
size,
offset,
@err);
end;
// This will throw are more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
{/* write the buffer to a new EWF file.
* @param handle : libEWF File Handle to write to
* @param buffer : pointer - pointer to a preallocated buffer (byte array) to write from.
* @param size - The number of bytes to write
* @param offset - The position within the EWF file.
* @return The number of bytes successfully written, -1 if unsuccessful.
*/}
function TLibEWF.libewf_handle_write_buffer(Buffer : Pointer; size : longword) : integer;
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibEWFhandlewritebuffer(fCurEWFHandle,
buffer,
size,
@err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
// Used to read and then verify the newly created E01 file
function TLibEWF.libewf_handle_read_buffer(Buffer : Pointer; size : longword) : integer;
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibEWFhandlereadbuffer(fCurEWFHandle,
buffer,
size,
@err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
// We can't use FileSeek on an libEWF handle, so we use libewf_handle_seek_offset
// to ensure we start at offset zero of the opened E01 image, ready for verification
// Returns 1 if successful. -1 if error.
function TLibEWF.libewf_handle_seek_offset(Offset : TSIZE64; Whence : TSIZE) : integer;
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibewfhandleseekoffset(fCurEWFHandle,
Offset,
Whence,
@err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
{
md5_hash is a pointer the computed MD5 hash digest
Size is the size of the hash string itself
Returns 1 if successful. 0 if empty. -1 if error.
}
function TLibEWF.libewf_handle_set_md5_hash(md5_hash : Pointer; size : TSIZE) : integer;
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibewfhandlesetmd5hash(fCurEWFHandle,
md5_hash,
size,
@err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
{ sha1_hash is a pointer the computed SHA-1 hash digest
Size is the size of the hash itself
Returns 1 if successful. 0 if empty. -1 if error.
}
function TLibEWF.libewf_handle_set_SHA1_hash(sha1_hash : Pointer; size : TSIZE) : integer;
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibewfhandlesetsha1hash(fCurEWFHandle,
sha1_hash,
size,
@err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
// Sets the E01 segmentation size to whatever size is passed to it.
// EWF specification is 2Gb as preferred.
function TLibEWF.libewf_handle_set_maximum_segment_size(Size : TSIZE64) : integer;
// https://github.com/libyal/libewf/blob/54b0eada69defd015c49e4e1e1e4e26a27409ba3/include/libewf.h.in#L631
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibewfhandlesetmaximumsegmentsize(fCurEWFHandle,
size,
@err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
{ Sets the output format of the image, i.e. EnCase v6, v5 and so on
Returns 1 if successful or -1 on error
}
function TLibEWF.libewf_handle_set_format(Format : TUINT8) : integer;
// https://github.com/libyal/libewf/blob/54b0eada69defd015c49e4e1e1e4e26a27409ba3/libewf/libewf_metadata.h#L153
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibewfhandlesetformat(fCurEWFHandle, Format, @err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
// Sets the media flag to either physical or logical volume based on
// LIBEWF_MEDIA_FLAG_PHYSICAL flag
function TLibEWF.libewf_handle_set_media_flags(volume_type : TUINT8) : integer;
// https://github.com/libyal/libewf/blob/54b0eada69defd015c49e4e1e1e4e26a27409ba3/libewf/libewf_metadata.h#L141
// https://github.com/libyal/libewf/blob/54b0eada69defd015c49e4e1e1e4e26a27409ba3/libewf/libewf_definitions.h.in#L154
var
err:pointer;
strError : string;
begin
err:=nil;
Result:=-1;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibewfhandlesetmediaflags(fCurEWFHandle,
volume_type,
@err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
function TLibEWF.libewf_handle_prepare_write_chunk(ChunkBuffer : Pointer;
ChunkBufferSize,
CompressedChunkBufferSize : integer;
size : TSIZE) : integer;
var
err:pointer;
strError : string;
CompressedChunkBuff : array [0..32767] of byte;
IsCompressed, ChunkChecksum, Chunk_io_flags : integer;
begin
err := nil;
Result := -1;
IsCompressed := 0;
ChunkChecksum := 0;
Chunk_io_flags := 0;
if fLibHandle<>0 then
begin
if LIBEWF_VERSION='V2' then
Result:=flibewfhandlepreparewritechunk(fCurEWFHandle,
@ChunkBuffer,
ChunkBufferSize,
@CompressedChunkBuff,
CompressedChunkBufferSize,
IsCompressed,
ChunkChecksum,
Chunk_io_flags,
@err);
end;
// This will throw a more specific error than generic system messages
if result = -1 then
begin
SetLength(strError, 512);
fLibEWFErrorSPrint(err, @strError[1], Length(strError));
ShowMessage(strError);
end;
end;
{
/* Writes a chunk of (media) data in EWF format at the current offset
* the necessary settings of the write values must have been made
* chunk_buffer_size contains the size of the data within the buffer while
* data_size contains the size of the actual input data
* Will initialize write if necessary
* Returns the number of input bytes written, 0 when no longer bytes can be written or -1 on error
*/
LIBEWF_EXTERN \
ssize_t libewf_handle_write_chunk(
libewf_handle_t *handle,
const void *chunk_buffer,
size_t chunk_buffer_size,
size_t data_size,
int8_t is_compressed,
void *checksum_buffer,
uint32_t chunk_checksum,
int8_t chunk_io_flags,
libewf_error_t **error );
}
function TLibEWF.libewf_handle_write_chunk(Chunkbuffer : Pointer;
ChunkBufferSize,
CompressedChunkBufferSize : integer) : integer;
var
err : Pointer;
strError : string;
CheckSumBuffer : Pointer;
IsCompressed, ChunkChecksum, Chunk_io_flags, DataSize : integer;
begin
err := nil;
Result := -1;
IsCompressed := 0;
ChunkChecksum := 0;
Chunk_io_flags := 0;
DataSize := 0;