02_decompress.c000644 000765 000024 00000031526 13137655056 014716 0ustar00morpheusstaff000000 000000 ///////////////////////////////////////////////////////////////////////////////
//
/// \file       02_decompress.c
/// \brief      Decompress .xz files to stdout
///
/// Usage:      ./02_decompress INPUT_FILES... > OUTFILE
///
/// Example:    ./02_decompress foo.xz bar.xz > foobar
//
//  Author:     Lasse Collin
//
//  This file has been put into the public domain.
//  You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////

#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <lzma.h>

#include <unistd.h> // for write

static bool
init_decoder(lzma_stream *strm)
{
	// Initialize a .xz decoder. The decoder supports a memory usage limit
	// and a set of flags.
	//
	// The memory usage of the decompressor depends on the settings used
	// to compress a .xz file. It can vary from less than a megabyte to
	// a few gigabytes, but in practice (at least for now) it rarely
	// exceeds 65 MiB because that's how much memory is required to
	// decompress files created with "xz -9". Settings requiring more
	// memory take extra effort to use and don't (at least for now)
	// provide significantly better compression in most cases.
	//
	// Memory usage limit is useful if it is important that the
	// decompressor won't consume gigabytes of memory. The need
	// for limiting depends on the application. In this example,
	// no memory usage limiting is used. This is done by setting
	// the limit to UINT64_MAX.
	//
	// The .xz format allows concatenating compressed files as is:
	//
	//     echo foo | xz > foobar.xz
	//     echo bar | xz >> foobar.xz
	//
	// When decompressing normal standalone .xz files, LZMA_CONCATENATED
	// should always be used to support decompression of concatenated
	// .xz files. If LZMA_CONCATENATED isn't used, the decoder will stop
	// after the first .xz stream. This can be useful when .xz data has
	// been embedded inside another file format.
	//
	// Flags other than LZMA_CONCATENATED are supported too, and can
	// be combined with bitwise-or. See lzma/container.h
	// (src/liblzma/api/lzma/container.h in the source package or e.g.
	// /usr/include/lzma/container.h depending on the install prefix)
	// for details.
	lzma_ret ret = lzma_stream_decoder(
			strm, UINT64_MAX, LZMA_CONCATENATED);

	// Return successfully if the initialization went fine.
	if (ret == LZMA_OK)
		return true;

	// Something went wrong. The possible errors are documented in
	// lzma/container.h (src/liblzma/api/lzma/container.h in the source
	// package or e.g. /usr/include/lzma/container.h depending on the
	// install prefix).
	//
	// Note that LZMA_MEMLIMIT_ERROR is never possible here. If you
	// specify a very tiny limit, the error will be delayed until
	// the first headers have been parsed by a call to lzma_code().
	const char *msg;
	switch (ret) {
	case LZMA_MEM_ERROR:
		msg = "Memory allocation failed";
		break;

	case LZMA_OPTIONS_ERROR:
		msg = "Unsupported decompressor flags";
		break;

	default:
		// This is most likely LZMA_PROG_ERROR indicating a bug in
		// this program or in liblzma. It is inconvenient to have a
		// separate error message for errors that should be impossible
		// to occur, but knowing the error code is important for
		// debugging. That's why it is good to print the error code
		// at least when there is no good error message to show.
		msg = "Unknown error, possibly a bug";
		break;
	}

	fprintf(stderr, "Error initializing the decoder: %s (error code %u)\n",
			msg, ret);
	return false;
}


static bool
decompress(lzma_stream *strm, const char *inname, FILE *infile, FILE *outfile)
{
	// When LZMA_CONCATENATED flag was used when initializing the decoder,
	// we need to tell lzma_code() when there will be no more input.
	// This is done by setting action to LZMA_FINISH instead of LZMA_RUN
	// in the same way as it is done when encoding.
	//
	// When LZMA_CONCATENATED isn't used, there is no need to use
	// LZMA_FINISH to tell when all the input has been read, but it
	// is still OK to use it if you want. When LZMA_CONCATENATED isn't
	// used, the decoder will stop after the first .xz stream. In that
	// case some unused data may be left in strm->next_in.
	lzma_action action = LZMA_RUN;

	uint8_t inbuf[BUFSIZ];
	uint8_t outbuf[BUFSIZ];

	strm->next_in = NULL;
	strm->avail_in = 0;
	strm->next_out = outbuf;
	strm->avail_out = sizeof(outbuf);

	while (true) {
		if (strm->avail_in == 0 && !feof(infile)) {
			strm->next_in = inbuf;
			strm->avail_in = fread(inbuf, 1, sizeof(inbuf),
					infile);

			if (ferror(infile)) {
				fprintf(stderr, "%s: Read error: %s\n",
						inname, strerror(errno));
				return false;
			}

			// Once the end of the input file has been reached,
			// we need to tell lzma_code() that no more input
			// will be coming. As said before, this isn't required
			// if the LZMA_CONATENATED flag isn't used when
			// initializing the decoder.
			if (feof(infile))
				action = LZMA_FINISH;
		}

		lzma_ret ret = lzma_code(strm, action);

		while (strm->avail_out == 0 || ret == LZMA_STREAM_END) {
			size_t write_size = sizeof(outbuf) - strm->avail_out;

			if (fwrite(outbuf, 1, write_size, outfile)
					!= write_size) {
				fprintf(stderr, "Write error: %s\n",
						strerror(errno));
				return false;
			}

			strm->next_out = outbuf;
			strm->avail_out = sizeof(outbuf);
		}

		if (ret != LZMA_OK) {
			// Once everything has been decoded successfully, the
			// return value of lzma_code() will be LZMA_STREAM_END.
			//
			// It is important to check for LZMA_STREAM_END. Do not
			// assume that getting ret != LZMA_OK would mean that
			// everything has gone well or that when you aren't
			// getting more output it must have successfully
			// decoded everything.
			if (ret == LZMA_STREAM_END)
				return true;

			// It's not LZMA_OK nor LZMA_STREAM_END,
			// so it must be an error code. See lzma/base.h
			// (src/liblzma/api/lzma/base.h in the source package
			// or e.g. /usr/include/lzma/base.h depending on the
			// install prefix) for the list and documentation of
			// possible values. Many values listen in lzma_ret
			// enumeration aren't possible in this example, but
			// can be made possible by enabling memory usage limit
			// or adding flags to the decoder initialization.
			const char *msg;
			switch (ret) {
			case LZMA_MEM_ERROR:
				msg = "Memory allocation failed";
				break;

			case LZMA_FORMAT_ERROR:
				// .xz magic bytes weren't found.
				msg = "The input is not in the .xz format";
				break;

			case LZMA_OPTIONS_ERROR:
				// For example, the headers specify a filter
				// that isn't supported by this liblzma
				// version (or it hasn't been enabled when
				// building liblzma, but no-one sane does
				// that unless building liblzma for an
				// embedded system). Upgrading to a newer
				// liblzma might help.
				//
				// Note that it is unlikely that the file has
				// accidentally became corrupt if you get this
				// error. The integrity of the .xz headers is
				// always verified with a CRC32, so
				// unintentionally corrupt files can be
				// distinguished from unsupported files.
				msg = "Unsupported compression options";
				break;

			case LZMA_DATA_ERROR:
				msg = "Compressed file is corrupt";
				break;

			case LZMA_BUF_ERROR:
				// Typically this error means that a valid
				// file has got truncated, but it might also
				// be a damaged part in the file that makes
				// the decoder think the file is truncated.
				// If you prefer, you can use the same error
				// message for this as for LZMA_DATA_ERROR.
				msg = "Compressed file is truncated or "
						"otherwise corrupt";
				break;

			default:
				// This is most likely LZMA_PROG_ERROR.
				msg = "Unknown error, possibly a bug";
				break;
			}

			fprintf(stderr, "%s: Decoder error: "
					"%s (error code %u)\n",
					inname, msg, ret);
			return false;
		}
	}
}



#ifndef NOJ

 	// J's modifications
static bool
decompressBytes(lzma_stream *strm, const char *inbytes, int size)
{
	// When LZMA_CONCATENATED flag was used when initializing the decoder,
	// we need to tell lzma_code() when there will be no more input.
	// This is done by setting action to LZMA_FINISH instead of LZMA_RUN
	// in the same way as it is done when encoding.
	//
	// When LZMA_CONCATENATED isn't used, there is no need to use
	// LZMA_FINISH to tell when all the input has been read, but it
	// is still OK to use it if you want. When LZMA_CONCATENATED isn't
	// used, the decoder will stop after the first .xz stream. In that
	// case some unused data may be left in strm->next_in.
	lzma_action action = LZMA_RUN;

	uint8_t inbuf[BUFSIZ];
	uint8_t outbuf[BUFSIZ];

	strm->next_in = NULL;
	strm->avail_in = 0;
	strm->next_out = outbuf;
	strm->avail_out =BUFSIZ;

	// Do just once, removed while loop
	 {
		strm->next_in = inbytes;
		strm->avail_in = size;

		lzma_ret ret;

		ret = lzma_code(strm, action);

		int total = 0 ;
		while (strm->avail_out == 0 &&  ret != LZMA_STREAM_END) {
			size_t write_size = sizeof(outbuf) - strm->avail_out;

			write (1, outbuf, write_size);
			total += write_size;
			strm->avail_out = BUFSIZ;
			strm->next_out = outbuf;
			ret = lzma_code(strm, action);
			}


                action = LZMA_FINISH;
		ret = lzma_code(strm, action);
		if (ret == LZMA_STREAM_END) { fprintf(stderr,"OK!  (%d bytes)\n", total);}

		if (ret != LZMA_OK) {
			// Once everything has been decoded successfully, the
			// return value of lzma_code() will be LZMA_STREAM_END.
			//
			// It is important to check for LZMA_STREAM_END. Do not
			// assume that getting ret != LZMA_OK would mean that
			// everything has gone well or that when you aren't
			// getting more output it must have successfully
			// decoded everything.
			if (ret == LZMA_STREAM_END)
				return true;

			// It's not LZMA_OK nor LZMA_STREAM_END,
			// so it must be an error code. See lzma/base.h
			// (src/liblzma/api/lzma/base.h in the source package
			// or e.g. /usr/include/lzma/base.h depending on the
			// install prefix) for the list and documentation of
			// possible values. Many values listen in lzma_ret
			// enumeration aren't possible in this example, but
			// can be made possible by enabling memory usage limit
			// or adding flags to the decoder initialization.
			const char *msg;
			switch (ret) {
			case LZMA_MEM_ERROR:
				msg = "Memory allocation failed";
				break;

			case LZMA_FORMAT_ERROR:
				// .xz magic bytes weren't found.
				msg = "The input is not in the .xz format";
				break;

			case LZMA_OPTIONS_ERROR:
				// For example, the headers specify a filter
				// that isn't supported by this liblzma
				// version (or it hasn't been enabled when
				// building liblzma, but no-one sane does
				// that unless building liblzma for an
				// embedded system). Upgrading to a newer
				// liblzma might help.
				//
				// Note that it is unlikely that the file has
				// accidentally became corrupt if you get this
				// error. The integrity of the .xz headers is
				// always verified with a CRC32, so
				// unintentionally corrupt files can be
				// distinguished from unsupported files.
				msg = "Unsupported compression options";
				break;

			case LZMA_DATA_ERROR:
				msg = "Compressed file is corrupt";
				break;

			case LZMA_BUF_ERROR:
				// Typically this error means that a valid
				// file has got truncated, but it might also
				// be a damaged part in the file that makes
				// the decoder think the file is truncated.
				// If you prefer, you can use the same error
				// message for this as for LZMA_DATA_ERROR.
				msg = "Compressed file is truncated or "
						"otherwise corrupt";
				break;

			default:
				// This is most likely LZMA_PROG_ERROR.
				msg = "Unknown error, possibly a bug";
				break;
			}

			fprintf(stderr, " Decoder error: " "%s (error code %u)\n",  msg, ret);
			return false;
		}
	}

}
	
void	decompressXZChunkToStdout(char *buf, int size)
{
	lzma_stream strm = LZMA_STREAM_INIT;
	init_decoder(&strm);

	decompressBytes(&strm, buf, size);



}

#else // Original code unmodified
extern int
main(int argc, char **argv)
{
	if (argc <= 1) {
		fprintf(stderr, "Usage: %s FILES...\n", argv[0]);
		return EXIT_FAILURE;
	}

	lzma_stream strm = LZMA_STREAM_INIT;

	bool success = true;

	// Try to decompress all files.
	for (int i = 1; i < argc; ++i) {
		if (!init_decoder(&strm)) {
			// Decoder initialization failed. There's no point
			// to retry it so we need to exit.
			success = false;
			break;
		}

		FILE *infile = fopen(argv[i], "rb");

		if (infile == NULL) {
			fprintf(stderr, "%s: Error opening the "
					"input file: %s\n",
					argv[i], strerror(errno));
			success = false;
		} else {
			success &= decompress(&strm, argv[i], infile, stdout);
			fclose(infile);
		}
	}

	// Free the memory allocated for the decoder. This only needs to be
	// done after the last file.
	lzma_end(&strm);

	if (fclose(stdout)) {
		fprintf(stderr, "Write error: %s\n", strerror(errno));
		success = false;
	}

	return success ? EXIT_SUCCESS : EXIT_FAILURE;
}
#endif
pbzx000755 000765 000024 00000050720 13137655057 013014 0ustar00morpheusstaff000000 000000 ELF> 
@@H@8	@$!@@@@@88@8@@@44 `` ``TT@T@DDPtdhh@h@TTQtdRtd``/lib64/ld-linux-x86-64.so.2GNU GNUXGⵗ{9 {* g9 M  `liblzma.so.5_ITM_deregisterTMCloneTable__gmon_start___Jv_RegisterClasses_ITM_registerTMCloneTablelzma_stream_decoderlzma_codelibc.so.6exitstrncmpperrorfeof__errno_locationmemcmpmallocstderrfwritefreadatoiopenfprintfstrerror__libc_start_mainferrorXZ_5.0GLIBC_2.2.5 (ui	`
 ` `  `( `0 `8 `@ `H `P `	X `
` `h `p `x ` ` ` ` ` ` `HHE HtSH52 %4 @%2 h%* h%" h% h% h%
 h% h% hp% h`% h	P% h
@% h0% h % h
% h% h% h% h% h% f1I^HHPTI@H@H@fD `UH- `HHvHt] `f]@f. `UH `HHHH?HHtHt] `]fD= uUHn] @`H?uHtUH]zUHHPHEE	EIHHHHǸBE}y HHHH3Iu5HHHHEH U@HǸHEHΉRH(@HYt(H H-@HDžHDžHEHΉHHHHH? D@HǸEEEEEHEHΉoHHHHEHΉEHHHE;EE}tS@]@HHH~ UII`@HǸHH4HEHHM؋EHΉEԋEԉE2HEHH)‹EHcHEHEHΉEԋEEEHcHH9rHEغ@Hst@EHE؋H @HǸ\HHEHƿHHPHEHк@HtEEHHPHEHHHpH9 H@HǸ}uHHE؉HcEH%HUHH H}HEHHE}uQEttHE@@HE`@	HE@H{ MHU@HǸUHH@@HؿHпHȿHEHؿHHؿH@HؿHHPHؿH@  HؿH@HHȿHHؿHHHȿHHѺ HHHؿHPHȿHt;HHW Hп@HǸHȿHtEUHؿHFEHؿH@  H)HHEHHUHHH;Et4HH @HǸEHؿHHPHؿH@  HؿH@ HX}N}S}u
Ew>H@HE@@1HE@'HE(@HEH@HEh@	HE@H uHMHпA@HǸfUHH@@HؿHп̿EHؿHHؿH@HؿHHPHؿH@  HؿHпH̿HcHؿHPUHؿHREExHؿH@  H)HHEHUHHƿDHE‹EЉEHؿH@  HؿHHPUHؿHEHؿH@ Hu
}nEUHؿHE}uHI
 U@HǸ}}uyEw>H8@HE@@1HE@'HE(@HEH@HEh@	HE@H MHU@HǸ[UHHHhdHpHHHpHdHhHpHHfAWAVAAUATL%n	 UH-n	 SIIL)HHHt 1LLDAHH9uH[]A\A]A^A_Ðf.HHStarting from Chunk %d
pbzxCan't find pbzx magic
Flags: 0x%llx
(skipped)Chunk #%d (flags: %llx, length: %lld bytes) %s
7zXZWarning: Can't find XZ header. Instead have 0x%x(?).. This is likely not XZ data.
YZWarning: Can't find XZ footer at 0x%llx (instead have %x). This is bad.
Memory allocation failedUnsupported decompressor flagsUnknown error, possibly a bugError initializing the decoder: %s (error code %u)
%s: Read error: %s
Write error: %s
The input is not in the .xz formatUnsupported compression optionsCompressed file is corruptCompressed file is truncated or otherwise corrupt%s: Decoder error: %s (error code %u)
@@@@@@OK!  (%d bytes)
 Decoder error: %s (error code %u)
@@@@@@;T	hpv(HhzRx@*zRx$@FJw?;*3$"DAC
dAC
AC
y
AC
f`AC
[DeBBE B(H0H8M@r8A0A(B BBB,
@
@@
@``o@@@
" `@@0	op@oo:@`@@	@	@&	@6	@F	@V	@f	@v	@	@	@	@	@	@	@	@	@
@GCC: (GNU) 6.2.1 20160916 (Red Hat 6.2.1-2)GCC: (GNU) 6.1.1 20160510 (Red Hat 6.1.1-2),@,s@o@78)+.-inteiLi>	Ub				s 	G(	>0	8	@
H
mP
 X
vV`
^\h
Vbp
bt
px
F
T
^b
r
!{
)
*
+
,
.-
/b
1xSV	V	\	b%r

;;\<=}\\\bl"9GbLbPb$HJMb@_bw_w$"ewfd#bl$bh
6OwV6Owi=bdoff>bX@b`AbT@bufQHSbDhTb\v*@78)int+.-eiLi>$07	U?				s 	G(	>0	8	@
H
mP
 X
vo`
^uh
V?p
?t
px
M
[
^{

!{
)
*
+
,
.-
/?
1So	o	u	?>
7
;;\<=}uuu?0F#78T,Q1.>T9miw@Z$	
Q\T(4OYt$
=
#S
=--$SCYvo
o
-
3
u
- 
u3(
{0
8
.@
<H
JP
XX
3`
3h
-p
-x
	Q

Q.#ej{l	"
9
G?
L?
P?[v@` bufv~v?~x~}@
 ~~?~T\K&пf&~u@ retl?h!@x-P@ msg=`#7"ie@+i ~i~Di+~i+~#Tul#Kw&п#fx&~@>$ret\!@	#-P~@$msg`%@ X$ret>d$msgMh%:;I$>$>I&I:;	
:;I8

:;I8:;I
!I/<4:;I?<4:;I?<!.?:;'I@B:;I4:;I4:;II!I/%:;I$>$>I&I:;	
:;I8

:;I8:;I
!I/<4:;I?<4:;I?<!I:;(:;I:;'II'.?:;'@B:;I:;I4:;I.:;'I@B:;I 4:;I!"!I/#4:;I$4:;I%.:;'I@B
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/include/usr/include/bits/usr/includepbzx.cstddef.htypes.hlibio.hstdio.hsys_errlist.hunistd.hgetopt.h	@yuv#f(ZuvuvYKftX00i0,c K(LH,jiKt:JY
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/include/usr/include/bits/usr/include/usr/include/lzma02_decompress.cstddef.htypes.hstdio.hlibio.hsys_errlist.hstdint.hbase.hunistd.hgetopt.h	@"gt1	.#Y3'y!<g10W,/whY%W%!u<	gh2.1	.2#*[	.y!@hu/u!yfugf	gth2.1	.2#x1ugoptindoptarg_IO_FILEsys_nerr_IO_save_endshort intsize_tsizetype_IO_write_ptr_flags_IO_2_1_stdout___environ_markers_IO_read_end/mnt/hgfs/iOS/pbzxstderrlong long int_lock_cur_column_IO_2_1_stderr__IO_FILE_plus_posskipChunkargv_sbuf_old_offsetlengthunsigned charargclong long unsigned int_IO_2_1_stdin_uint32_t_IO_marker_shortbuftotalBytes_IO_write_base_unused2opterr_IO_buf_endminChunkmainwarn_next__pad1__pad2__pad3__pad4__pad5GNU C11 6.1.1 20160510 (Red Hat 6.1.1-2) -mtune=generic -march=x86-64 -g2buffershort unsigned int_IO_write_end__off64_t_fileno_chain__off_t_IO_backup_basestdin_IO_buf_base_flags2_mode_IO_read_base_vtable_offsetpbzx.c_IO_save_basesys_errlistoptopt_IO_read_ptruint64_tstdout_IO_lock_tnext_inavail_inopaquefreeLZMA_RUNlzma_reserved_enuminfileinbuflzma_retLZMA_MEM_ERRORLZMA_NO_CHECKLZMA_UNSUPPORTED_CHECKlzma_internallzma_streamstrmLZMA_RESERVED_ENUMLZMA_PROG_ERRORtotal_inLZMA_BUF_ERRORtotalLZMA_MEMLIMIT_ERRORLZMA_FULL_BARRIERLZMA_OKinbytesLZMA_DATA_ERRORLZMA_FINISHLZMA_GET_CHECKlzma_actiondecompressXZChunkToStdouttotal_outoutfileLZMA_SYNC_FLUSH_Boolnext_outLZMA_FORMAT_ERRORinit_decoderavail_outdecompresslong doublelzma_allocatorlzma_internal_sallocLZMA_OPTIONS_ERRORLZMA_FULL_FLUSHreserved_ptr1reserved_ptr2reserved_ptr3reserved_ptr4outbufLZMA_STREAM_ENDdecompressBytesuint8_t02_decompress.cinnamewrite_sizereserved_int1reserved_int2reserved_int3reserved_int4reserved_enum1reserved_enum28@T@t@@@@:@p@	@
@@@

@ 
@@@h@@````` ` ` ` `P
@
@.
@D `S`z
@`@e@@
0@````+h@> `T@d B  `O `^@@`
,@ `Mbt @@@e
 `F 
@* `@ *<Nb `n @ `crtstuff.c__JCR_LIST__deregister_tm_clones__do_global_dtors_auxcompleted.6936__do_global_dtors_aux_fini_array_entryframe_dummy__frame_dummy_init_array_entrypbzx.c02_decompress.cinit_decoderdecompressdecompressBytes__FRAME_END____JCR_END____init_array_end_DYNAMIC__init_array_start__GNU_EH_FRAME_HDR_GLOBAL_OFFSET_TABLE___libc_csu_fini__errno_location@@GLIBC_2.2.5strncmp@@GLIBC_2.2.5_ITM_deregisterTMCloneTablelzma_code@@XZ_5.0ferror@@GLIBC_2.2.5fread@@GLIBC_2.2.5_edatadecompressXZChunkToStdout__libc_start_main@@GLIBC_2.2.5memcmp@@GLIBC_2.2.5__data_startfprintf@@GLIBC_2.2.5feof@@GLIBC_2.2.5__gmon_start____dso_handle_IO_stdin_usedlzma_stream_decoder@@XZ_5.0__libc_csu_initmalloc@@GLIBC_2.2.5__bss_startmainopen@@GLIBC_2.2.5perror@@GLIBC_2.2.5_Jv_RegisterClassesatoi@@GLIBC_2.2.5exit@@GLIBC_2.2.5fwrite@@GLIBC_2.2.5__TMC_END___ITM_registerTMCloneTablestrerror@@GLIBC_2.2.5stderr@@GLIBC_2.2.5.symtab.strtab.shstrtab.interp.note.ABI-tag.note.gnu.build-id.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rela.dyn.rela.plt.init.plt.got.text.fini.rodata.eh_frame_hdr.eh_frame.init_array.fini_array.jcr.dynamic.got.plt.data.bss.comment.debug_aranges.debug_info.debug_abbrev.debug_line.debug_str8@8#T@T 1t@t$Do@$N@XV@"^o:@:2kop@p@z@0B@@@@
@
 
@ 

@	@hh@hT@t````` `  `  `  0 X!`l!'Y.5j1jA04
GL:#8	Cpbzx.ELF64000755 000765 000024 00000050720 13137655116 013567 0ustar00morpheusstaff000000 000000 ELF> 
@@H@8	@$!@@@@@88@8@@@44 `` ``TT@T@DDPtdhh@h@TTQtdRtd``/lib64/ld-linux-x86-64.so.2GNU GNUXGⵗ{9 {* g9 M  `liblzma.so.5_ITM_deregisterTMCloneTable__gmon_start___Jv_RegisterClasses_ITM_registerTMCloneTablelzma_stream_decoderlzma_codelibc.so.6exitstrncmpperrorfeof__errno_locationmemcmpmallocstderrfwritefreadatoiopenfprintfstrerror__libc_start_mainferrorXZ_5.0GLIBC_2.2.5 (ui	`
 ` `  `( `0 `8 `@ `H `P `	X `
` `h `p `x ` ` ` ` ` ` `HHE HtSH52 %4 @%2 h%* h%" h% h% h%
 h% h% hp% h`% h	P% h
@% h0% h % h
% h% h% h% h% h% f1I^HHPTI@H@H@fD `UH- `HHvHt] `f]@f. `UH `HHHH?HHtHt] `]fD= uUHn] @`H?uHtUH]zUHHPHEE	EIHHHHǸBE}y HHHH3Iu5HHHHEH U@HǸHEHΉRH(@HYt(H H-@HDžHDžHEHΉHHHHH? D@HǸEEEEEHEHΉoHHHHEHΉEHHHE;EE}tS@]@HHH~ UII`@HǸHH4HEHHM؋EHΉEԋEԉE2HEHH)‹EHcHEHEHΉEԋEEEHcHH9rHEغ@Hst@EHE؋H @HǸ\HHEHƿHHPHEHк@HtEEHHPHEHHHpH9 H@HǸ}uHHE؉HcEH%HUHH H}HEHHE}uQEttHE@@HE`@	HE@H{ MHU@HǸUHH@@HؿHпHȿHEHؿHHؿH@HؿHHPHؿH@  HؿH@HHȿHHؿHHHȿHHѺ HHHؿHPHȿHt;HHW Hп@HǸHȿHtEUHؿHFEHؿH@  H)HHEHHUHHH;Et4HH @HǸEHؿHHPHؿH@  HؿH@ HX}N}S}u
Ew>H@HE@@1HE@'HE(@HEH@HEh@	HE@H uHMHпA@HǸfUHH@@HؿHп̿EHؿHHؿH@HؿHHPHؿH@  HؿHпH̿HcHؿHPUHؿHREExHؿH@  H)HHEHUHHƿDHE‹EЉEHؿH@  HؿHHPUHؿHEHؿH@ Hu
}nEUHؿHE}uHI
 U@HǸ}}uyEw>H8@HE@@1HE@'HE(@HEH@HEh@	HE@H MHU@HǸ[UHHHhdHpHHHpHdHhHpHHfAWAVAAUATL%n	 UH-n	 SIIL)HHHt 1LLDAHH9uH[]A\A]A^A_Ðf.HHStarting from Chunk %d
pbzxCan't find pbzx magic
Flags: 0x%llx
(skipped)Chunk #%d (flags: %llx, length: %lld bytes) %s
7zXZWarning: Can't find XZ header. Instead have 0x%x(?).. This is likely not XZ data.
YZWarning: Can't find XZ footer at 0x%llx (instead have %x). This is bad.
Memory allocation failedUnsupported decompressor flagsUnknown error, possibly a bugError initializing the decoder: %s (error code %u)
%s: Read error: %s
Write error: %s
The input is not in the .xz formatUnsupported compression optionsCompressed file is corruptCompressed file is truncated or otherwise corrupt%s: Decoder error: %s (error code %u)
@@@@@@OK!  (%d bytes)
 Decoder error: %s (error code %u)
@@@@@@;T	hpv(HhzRx@*zRx$@FJw?;*3$"DAC
dAC
AC
y
AC
f`AC
[DeBBE B(H0H8M@r8A0A(B BBB,
@
@@
@``o@@@
" `@@0	op@oo:@`@@	@	@&	@6	@F	@V	@f	@v	@	@	@	@	@	@	@	@	@
@GCC: (GNU) 6.2.1 20160916 (Red Hat 6.2.1-2)GCC: (GNU) 6.1.1 20160510 (Red Hat 6.1.1-2),@,s@o@78)+.-inteiLi>	Ub				s 	G(	>0	8	@
H
mP
 X
vV`
^\h
Vbp
bt
px
F
T
^b
r
!{
)
*
+
,
.-
/b
1xSV	V	\	b%r

;;\<=}\\\bl"9GbLbPb$HJMb@_bw_w$"ewfd#bl$bh
6OwV6Owi=bdoff>bX@b`AbT@bufQHSbDhTb\v*@78)int+.-eiLi>$07	U?				s 	G(	>0	8	@
H
mP
 X
vo`
^uh
V?p
?t
px
M
[
^{

!{
)
*
+
,
.-
/?
1So	o	u	?>
7
;;\<=}uuu?0F#78T,Q1.>T9miw@Z$	
Q\T(4OYt$
=
#S
=--$SCYvo
o
-
3
u
- 
u3(
{0
8
.@
<H
JP
XX
3`
3h
-p
-x
	Q

Q.#ej{l	"
9
G?
L?
P?[v@` bufv~v?~x~}@
 ~~?~T\K&пf&~u@ retl?h!@x-P@ msg=`#7"ie@+i ~i~Di+~i+~#Tul#Kw&п#fx&~@>$ret\!@	#-P~@$msg`%@ X$ret>d$msgMh%:;I$>$>I&I:;	
:;I8

:;I8:;I
!I/<4:;I?<4:;I?<!.?:;'I@B:;I4:;I4:;II!I/%:;I$>$>I&I:;	
:;I8

:;I8:;I
!I/<4:;I?<4:;I?<!I:;(:;I:;'II'.?:;'@B:;I:;I4:;I.:;'I@B:;I 4:;I!"!I/#4:;I$4:;I%.:;'I@B
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/include/usr/include/bits/usr/includepbzx.cstddef.htypes.hlibio.hstdio.hsys_errlist.hunistd.hgetopt.h	@yuv#f(ZuvuvYKftX00i0,c K(LH,jiKt:JY
/usr/lib/gcc/x86_64-redhat-linux/6.1.1/include/usr/include/bits/usr/include/usr/include/lzma02_decompress.cstddef.htypes.hstdio.hlibio.hsys_errlist.hstdint.hbase.hunistd.hgetopt.h	@"gt1	.#Y3'y!<g10W,/whY%W%!u<	gh2.1	.2#*[	.y!@hu/u!yfugf	gth2.1	.2#x1ugoptindoptarg_IO_FILEsys_nerr_IO_save_endshort intsize_tsizetype_IO_write_ptr_flags_IO_2_1_stdout___environ_markers_IO_read_end/mnt/hgfs/iOS/pbzxstderrlong long int_lock_cur_column_IO_2_1_stderr__IO_FILE_plus_posskipChunkargv_sbuf_old_offsetlengthunsigned charargclong long unsigned int_IO_2_1_stdin_uint32_t_IO_marker_shortbuftotalBytes_IO_write_base_unused2opterr_IO_buf_endminChunkmainwarn_next__pad1__pad2__pad3__pad4__pad5GNU C11 6.1.1 20160510 (Red Hat 6.1.1-2) -mtune=generic -march=x86-64 -g2buffershort unsigned int_IO_write_end__off64_t_fileno_chain__off_t_IO_backup_basestdin_IO_buf_base_flags2_mode_IO_read_base_vtable_offsetpbzx.c_IO_save_basesys_errlistoptopt_IO_read_ptruint64_tstdout_IO_lock_tnext_inavail_inopaquefreeLZMA_RUNlzma_reserved_enuminfileinbuflzma_retLZMA_MEM_ERRORLZMA_NO_CHECKLZMA_UNSUPPORTED_CHECKlzma_internallzma_streamstrmLZMA_RESERVED_ENUMLZMA_PROG_ERRORtotal_inLZMA_BUF_ERRORtotalLZMA_MEMLIMIT_ERRORLZMA_FULL_BARRIERLZMA_OKinbytesLZMA_DATA_ERRORLZMA_FINISHLZMA_GET_CHECKlzma_actiondecompressXZChunkToStdouttotal_outoutfileLZMA_SYNC_FLUSH_Boolnext_outLZMA_FORMAT_ERRORinit_decoderavail_outdecompresslong doublelzma_allocatorlzma_internal_sallocLZMA_OPTIONS_ERRORLZMA_FULL_FLUSHreserved_ptr1reserved_ptr2reserved_ptr3reserved_ptr4outbufLZMA_STREAM_ENDdecompressBytesuint8_t02_decompress.cinnamewrite_sizereserved_int1reserved_int2reserved_int3reserved_int4reserved_enum1reserved_enum28@T@t@@@@:@p@	@
@@@

@ 
@@@h@@````` ` ` ` `P
@
@.
@D `S`z
@`@e@@
0@````+h@> `T@d B  `O `^@@`
,@ `Mbt @@@e
 `F 
@* `@ *<Nb `n @ `crtstuff.c__JCR_LIST__deregister_tm_clones__do_global_dtors_auxcompleted.6936__do_global_dtors_aux_fini_array_entryframe_dummy__frame_dummy_init_array_entrypbzx.c02_decompress.cinit_decoderdecompressdecompressBytes__FRAME_END____JCR_END____init_array_end_DYNAMIC__init_array_start__GNU_EH_FRAME_HDR_GLOBAL_OFFSET_TABLE___libc_csu_fini__errno_location@@GLIBC_2.2.5strncmp@@GLIBC_2.2.5_ITM_deregisterTMCloneTablelzma_code@@XZ_5.0ferror@@GLIBC_2.2.5fread@@GLIBC_2.2.5_edatadecompressXZChunkToStdout__libc_start_main@@GLIBC_2.2.5memcmp@@GLIBC_2.2.5__data_startfprintf@@GLIBC_2.2.5feof@@GLIBC_2.2.5__gmon_start____dso_handle_IO_stdin_usedlzma_stream_decoder@@XZ_5.0__libc_csu_initmalloc@@GLIBC_2.2.5__bss_startmainopen@@GLIBC_2.2.5perror@@GLIBC_2.2.5_Jv_RegisterClassesatoi@@GLIBC_2.2.5exit@@GLIBC_2.2.5fwrite@@GLIBC_2.2.5__TMC_END___ITM_registerTMCloneTablestrerror@@GLIBC_2.2.5stderr@@GLIBC_2.2.5.symtab.strtab.shstrtab.interp.note.ABI-tag.note.gnu.build-id.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rela.dyn.rela.plt.init.plt.got.text.fini.rodata.eh_frame_hdr.eh_frame.init_array.fini_array.jcr.dynamic.got.plt.data.bss.comment.debug_aranges.debug_info.debug_abbrev.debug_line.debug_str8@8#T@T 1t@t$Do@$N@XV@"^o:@:2kop@p@z@0B@@@@
@
 
@ 

@	@hh@hT@t````` `  `  `  0 X!`l!'Y.5j1jA04
GL:#8	Cpbzx.MacOS000755 000765 000024 00000032160 13137654737 013757 0ustar00morpheusstaff000000 000000 8 H__PAGEZERO__TEXT  __text__TEXTp	__stubs__TEXT@T@__stub_helper__TEXT__cstring__TEXT0r0__unwind_info__TEXTP8__DATA  __got__DATA  __nl_symbol_ptr__DATA  __la_symbol_ptr__DATA  p  H__LINKEDIT00p"000@H0(1P1h3P2  /usr/lib/dyldf?b5%$

*(8/usr/lib/liblzma.5.dylib8/usr/lib/libSystem.B.dylib&x1)1UHSHH
HHEDžHDžDžDžF1HHx1	HHx	:HHxH5	H=fH?HH:pbzxDAH%H5B	HH861#HHDžHDžH'H5	H
HHHH9HHDžDžDžDžHH%HHHHHHHHHxLH56H
iHXL
LIL;AAAI8DLLHEDHpLMLpHhHdHHHljHcH;RHHcHHHcH)HH*ljHH5)ZH5H`	H8HHH`HXH5HHHHlOH5HH8HHHLBLH°THH8DžHRHHMH91HĨ[]qUHHHh1ɺH}uHljH`oH`3HhHuU_^Hİ]ff.UHH0HH}H}E}	E~EE܉ME܃E HHEHHEHHEH5H+H8HUMdEEЊE$H0]ffff.UHHpHH
H	HMHHDžHHHHAHHAHH@ HHHHcHHAHDž1HHz HHH+J HHRHHHcH։HHB HHJH1DžH$H5H2H8lƅHvHHHcHHHZHHGHH4HH!HHHHH5HCH8HvƅH
H	HUH9ш$Hp]"5H[n%%%%%%%%%%%%%%L}AS%mh?hPhhh$h0hkhyhhhhxhnhdStarting from Chunk %d
pbzxCan't find pbzx magic
Flags: 0x%llx
Chunk #%d (flags: %llx, length: %lld bytes) %s
(skipped)7zXZWarning: Can't find XZ header. Instead have 0x%x(?).. This is likely not XZ data.
YZWarning: Can't find XZ footer at 0x%llx (instead have %x). This is bad.
Memory allocation failedUnsupported decompressor flagsUnknown error, possibly a bugError initializing the decoder: %s (error code %u)
OK!  (%d bytes)
The input is not in the .xz formatUnsupported compression optionsCompressed file is corruptCompressed file is truncated or otherwise corrupt Decoder error: %s (error code %u)
44A4&" ^@___stack_chk_guardQr@___stderrp@dyld_stub_binderr @___stack_chk_failr(@_atoir0@_exitr8@_fprintfr@@_lzma_coderH@_lzma_stream_decoderrP@_mallocrX@_memcmpr`@_memsetrh@_openrp@_perrorrx@_readr@_strncmpr@_write__mh_execute_header<main@decompressXZChunkToStdoutE%/%
p(@17I\gms|	

@	

 __mh_execute_header_decompressXZChunkToStdout_main___stack_chk_fail___stack_chk_guard___stderrp_atoi_exit_fprintf_lzma_code_lzma_stream_decoder_malloc_memcmp_memset_open_perror_read_strncmp_writedyld_stub_binder_init_decoder_decompressBytespbzx.c000644 000765 000024 00000006045 13137655020 013221 0ustar00morpheusstaff000000 000000 #include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>

// Changelog:
// 02/17/2016 - Fixed so it works with Apple TV OTA PBZX
// 07/28/2016 - Fixed to handle uncompressed chunks and integrate XZ (via liblzma)


// To compile: gcc pbzx.c 02_decompress.c -o pbzx -llzma
// On Linux, make sure to install xz-devel first

typedef unsigned long long uint64_t;
typedef unsigned int uint32_t;

#define PBZX_MAGIC	"pbzx"


// This is in 02_decompress.c, modified from liblzma's examples
// I intentionally left that external since it's not my code.

extern void 	decompressXZChunkToStdout(char *buf, int length);



int main(int argc, const char * argv[])
{

    // Dumps a pbzx to stdout. Can work as a filter if no argument is specified

    char buffer[1024];
    int fd = 0;
    int minChunk = 0;

    if (argc < 2) { fd  = 0 ;}
    else { fd = open (argv[1], O_RDONLY);
           if (fd < 0) { perror (argv[1]); exit(5); }
         }

    if (argc ==3) {
	minChunk = atoi(argv[2]);
	fprintf(stderr,"Starting from Chunk %d\n", minChunk);

	}

    read (fd, buffer, 4);
    if (memcmp(buffer, PBZX_MAGIC, 4)) { fprintf(stderr, "Can't find pbzx magic\n"); exit(0);}

    // Now, if it IS a pbzx

    uint64_t length = 0, flags = 0;

    read (fd, &flags, sizeof (uint64_t));
    flags = __builtin_bswap64(flags);

    fprintf(stderr,"Flags: 0x%llx\n", flags);

    int i = 0;
    int off = 0;

    int warn = 0 ;
    int skipChunk = 0;

    while (flags &   0x01000000) { // have more chunks
    i++;
    read (fd, &flags, sizeof (uint64_t));
    flags = __builtin_bswap64(flags);
    read (fd, &length, sizeof (uint64_t));
    length = __builtin_bswap64(length);

    skipChunk = (i < minChunk);
    fprintf(stderr,"Chunk #%d (flags: %llx, length: %lld bytes) %s\n",i, flags,length,
     skipChunk? "(skipped)":"");
     


    // Let's ignore the fact I'm allocating based on user input, etc..
    char *buf = malloc (length);

    int bytes = read (fd, buf, length);
    int totalBytes = bytes;

    // 6/18/2017 - Fix for WatchOS 4.x OTA wherein the chunks are bigger than what can be read in one operation
    while (totalBytes < length) {
		// could be partial read
		bytes = read (fd, buf +totalBytes, length -totalBytes);
		totalBytes +=bytes;
	}	
	


   // We want the XZ header/footer if it's the payload, but prepare_payload doesn't have that, 
    // so just warn.
    
    if (memcmp(buf, "\xfd""7zXZ", 6))  { warn++; 
		fprintf (stderr, "Warning: Can't find XZ header. Instead have 0x%x(?).. This is likely not XZ data.\n",
			(* (uint32_t *) buf ));

		// Treat as uncompressed
        	write (1, buf, length);
		
		
		}
    else // if we have the header, we had better have a footer, too
	{
    if (strncmp(buf + length - 2, "YZ", 2)) { warn++; fprintf (stderr, "Warning: Can't find XZ footer at 0x%llx (instead have %x). This is bad.\n",
		(length -2),
		*((unsigned short *) (buf + length - 2))); 
		}
	if (1 && !skipChunk)
	{
	// Uncompress chunk

	decompressXZChunkToStdout(buf, length);

	}
	warn = 0;

	}
    }

    return 0;
}