org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream Java Examples

The following examples show how to use org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CpioFileSystem.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected InputStream getData(GFile file, TaskMonitor monitor)
		throws IOException, CancelledException, CryptoException {
	CpioArchiveEntry fileEntry = map.get(file);
	if (!fileEntry.isRegularFile()) {
		throw new IOException("CPIO entry " + file.getName() + " is not a regular file.");
	}
	try (CpioArchiveInputStream cpioInputStream =
		new CpioArchiveInputStream(provider.getInputStream(0));) {

		CpioArchiveEntry entry;
		while ((entry = cpioInputStream.getNextCPIOEntry()) != null) {
			if (!entry.equals(fileEntry)) {
				skipEntryContents(cpioInputStream, monitor);
			}
			else {
				byte[] entryBytes = readEntryContents(cpioInputStream, monitor);
				return new ByteArrayInputStream(entryBytes);
			}
		}
	}
	catch (IllegalArgumentException e) {
		//unknown MODES..
	}
	return null;
}
 
Example #2
Source File: CpioFileSystem.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private byte[] readEntryContents(CpioArchiveInputStream cpioInputStream, TaskMonitor monitor)
		throws IOException, CancelledException {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	byte[] buffer = new byte[64 * 1024];
	while (true) {
		if (monitor.isCancelled()) {
			throw new CancelledException();
		}
		int bytesRead = cpioInputStream.read(buffer);
		if (bytesRead <= 0) {
			break;
		}
		out.write(buffer, 0, bytesRead);
	}
	return out.toByteArray();
}
 
Example #3
Source File: RpmInputStream.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
protected void ensureInit () throws IOException
{
    if ( this.lead == null )
    {
        this.lead = readLead ();
    }

    if ( this.signatureHeader == null )
    {
        this.signatureHeader = readHeader ( true );
    }

    if ( this.payloadHeader == null )
    {
        this.payloadHeader = readHeader ( false );
    }

    // set up content stream

    if ( this.payloadStream == null )
    {
        this.payloadStream = setupPayloadStream ();
        this.cpioStream = new CpioArchiveInputStream ( this.payloadStream, "UTF-8" ); // we did ensure that we only support CPIO before
    }
}
 
Example #4
Source File: CpioFileSystem.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void skipEntryContents(CpioArchiveInputStream cpioInputStream, TaskMonitor monitor)
		throws IOException, CancelledException {
	byte[] buffer = new byte[64 * 1024];
	while (true) {
		if (monitor.isCancelled()) {
			throw new CancelledException();
		}
		int bytesRead = cpioInputStream.read(buffer);
		if (bytesRead <= 0) {
			break;
		}
	}
}
 
Example #5
Source File: Dumper.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public static void dumpAll ( final RpmInputStream in ) throws IOException
{
    final RpmLead lead = in.getLead ();
    System.out.format ( "Version: %s.%s%n", lead.getMajor (), lead.getMinor () );
    System.out.format ( "Name: %s%n", lead.getName () );
    System.out.format ( "Signature Version: %s%n", lead.getSignatureVersion () );
    System.out.format ( "Type: %s, Arch: %s, OS: %s%n", dumpFlag ( lead.getType (), Type::fromValue ), dumpFlag ( lead.getArchitecture (), Architecture::fromValue ), dumpFlag ( lead.getOperatingSystem (), OperatingSystem::fromValue ) );

    dumpHeader ( "Signature", in.getSignatureHeader (), tag -> RpmSignatureTag.find ( tag ), false );
    dumpHeader ( "Payload", in.getPayloadHeader (), tag -> RpmTag.find ( tag ), false );

    final CpioArchiveInputStream cpio = in.getCpioStream ();

    CpioArchiveEntry entry;
    while ( ( entry = cpio.getNextCPIOEntry () ) != null )
    {
        dumpEntry ( entry );
    }

    dumpGroup ( in, "Require", RpmTag.REQUIRE_NAME, RpmTag.REQUIRE_VERSION, RpmTag.REQUIRE_FLAGS );
    dumpGroup ( in, "Provide", RpmTag.PROVIDE_NAME, RpmTag.PROVIDE_VERSION, RpmTag.PROVIDE_FLAGS );
    dumpGroup ( in, "Conflict", RpmTag.CONFLICT_NAME, RpmTag.CONFLICT_VERSION, RpmTag.CONFLICT_FLAGS );
    dumpGroup ( in, "Obsolete", RpmTag.OBSOLETE_NAME, RpmTag.OBSOLETE_VERSION, RpmTag.OBSOLETE_FLAGS );
    dumpGroup ( in, "Suggest", RpmTag.SUGGEST_NAME, RpmTag.SUGGEST_VERSION, RpmTag.SUGGEST_FLAGS );
    dumpGroup ( in, "Recommend", RpmTag.RECOMMEND_NAME, RpmTag.RECOMMEND_VERSION, RpmTag.RECOMMEND_FLAGS );
    dumpGroup ( in, "Supplement", RpmTag.SUPPLEMENT_NAME, RpmTag.SUPPLEMENT_VERSION, RpmTag.SUPPLEMENT_FLAGS );
    dumpGroup ( in, "Enhance", RpmTag.ENHANCE_NAME, RpmTag.ENHANCE_VERSION, RpmTag.ENHANCE_FLAGS );

}
 
Example #6
Source File: RpmInputStream.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public CpioArchiveInputStream getCpioStream ()
{
    return this.cpioStream;
}
 
Example #7
Source File: CpioFileSystem.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isValid(TaskMonitor monitor) throws IOException {
	byte[] signature = provider.readBytes(0, 0x10);
	return CpioArchiveInputStream.matches(signature, 0x10);
}
 
Example #8
Source File: RpmInformations.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public static RpmInformation makeInformation ( final RpmInputStream in ) throws IOException
{
    final InputHeader<RpmTag> header = in.getPayloadHeader ();
    final InputHeader<RpmSignatureTag> signature = in.getSignatureHeader ();

    final RpmInformation result = new RpmInformation ();

    result.setHeaderStart ( header.getStart () );
    result.setHeaderEnd ( header.getStart () + header.getLength () );

    result.setName ( asString ( header.getTag ( RpmTag.NAME ) ) );
    result.setArchitecture ( asString ( header.getTag ( RpmTag.ARCH ) ) );
    result.setSummary ( asString ( header.getTag ( RpmTag.SUMMARY ) ) );
    result.setDescription ( asString ( header.getTag ( RpmTag.DESCRIPTION ) ) );
    result.setPackager ( asString ( header.getTag ( RpmTag.PACKAGER ) ) );
    result.setUrl ( asString ( header.getTag ( RpmTag.URL ) ) );
    result.setLicense ( asString ( header.getTag ( RpmTag.LICENSE ) ) );
    result.setVendor ( asString ( header.getTag ( RpmTag.VENDOR ) ) );
    result.setGroup ( asString ( header.getTag ( RpmTag.GROUP ) ) );

    result.setBuildHost ( asString ( header.getTag ( RpmTag.BUILDHOST ) ) );
    result.setBuildTimestamp ( asLong ( header.getTag ( RpmTag.BUILDTIME ) ) );
    result.setSourcePackage ( asString ( header.getTag ( RpmTag.SOURCE_PACKAGE ) ) );

    result.setInstalledSize ( asLong ( header.getTag ( RpmTag.SIZE ) ) );
    result.setArchiveSize ( asLong ( header.getTag ( RpmTag.ARCHIVE_SIZE ) ) );
    if ( result.getArchiveSize () == null )
    {
        result.setArchiveSize ( asLong ( signature.getTag ( RpmSignatureTag.PAYLOAD_SIZE ) ) );
    }

    // version

    final RpmInformation.Version ver = new RpmInformation.Version ( asString ( header.getTag ( RpmTag.VERSION ) ), asString ( header.getTag ( RpmTag.RELEASE ) ), asString ( header.getTag ( RpmTag.EPOCH ) ) );
    result.setVersion ( ver );

    // changelog

    final Object val = header.getTag ( RpmTag.CHANGELOG_TIMESTAMP );
    if ( val instanceof Long[] )
    {
        final Long[] ts = (Long[])val;
        final String[] authors = (String[])header.getTag ( RpmTag.CHANGELOG_AUTHOR );
        final String[] texts = (String[])header.getTag ( RpmTag.CHANGELOG_TEXT );

        final List<RpmInformation.Changelog> changes = new ArrayList<> ( ts.length );

        for ( int i = 0; i < ts.length; i++ )
        {
            changes.add ( new RpmInformation.Changelog ( ts[i], authors[i], texts[i] ) );
        }

        Collections.sort ( changes, ( o1, o2 ) -> Long.compare ( o1.getTimestamp (), o2.getTimestamp () ) );

        result.setChangelog ( changes );
    }

    // dependencies

    result.setProvides ( makeDependencies ( header, RpmTag.PROVIDE_NAME, RpmTag.PROVIDE_VERSION, RpmTag.PROVIDE_FLAGS ) );
    result.setRequires ( makeDependencies ( header, RpmTag.REQUIRE_NAME, RpmTag.REQUIRE_VERSION, RpmTag.REQUIRE_FLAGS ) );
    result.setConflicts ( makeDependencies ( header, RpmTag.CONFLICT_NAME, RpmTag.CONFLICT_VERSION, RpmTag.CONFLICT_FLAGS ) );
    result.setObsoletes ( makeDependencies ( header, RpmTag.OBSOLETE_NAME, RpmTag.OBSOLETE_VERSION, RpmTag.OBSOLETE_FLAGS ) );

    // files

    final CpioArchiveInputStream cpio = in.getCpioStream ();
    CpioArchiveEntry cpioEntry;
    while ( ( cpioEntry = cpio.getNextCPIOEntry () ) != null )
    {
        final String name = normalize ( cpioEntry.getName () );

        if ( cpioEntry.isRegularFile () )
        {
            result.getFiles ().add ( name );
        }
        else if ( cpioEntry.isDirectory () )
        {
            result.getDirectories ().add ( name );
        }
    }
    cpio.close ();

    return result;
}
 
Example #9
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
private FileTree cpioTree(Object arPath, ArchiveInputStreamProvider<CpioArchiveInputStream> inputStreamProvider) {
    File file = fileOperations.file(arPath);
    ArchiveFileTree<CpioArchiveInputStream, CpioArchiveEntry> cpioFileTree = new ArchiveFileTree<>(file, inputStreamProvider, getExpandDir(), fileSystem, directoryFileTreeFactory, fileHasher);
    return new FileTreeAdapter(cpioFileTree, patternSetFactory);
}
 
Example #10
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree cpioTree(Object cpioFile, int blockSize, String encoding) {
    return cpioTree(cpioFile, f -> new CpioArchiveInputStream(new FileInputStream(f), blockSize, encoding));
}
 
Example #11
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree cpioTree(Object cpioFile, String encoding) {
    return cpioTree(cpioFile, f -> new CpioArchiveInputStream(new FileInputStream(f), encoding));
}
 
Example #12
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree cpioTree(Object cpioFile, int blockSize) {
    return cpioTree(cpioFile, f -> new CpioArchiveInputStream(new FileInputStream(f), blockSize));
}
 
Example #13
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree cpioTree(Object cpioFile) {
    return cpioTree(cpioFile, f -> new CpioArchiveInputStream(new FileInputStream(f)));
}
 
Example #14
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
private FileTree cpioTree(Object arPath, ArchiveInputStreamProvider<CpioArchiveInputStream> inputStreamProvider) {
    File file = fileOperations.file(arPath);
    ArchiveFileTree<CpioArchiveInputStream, CpioArchiveEntry> cpioFileTree = new ArchiveFileTree<>(file, inputStreamProvider, getExpandDir(), fileSystem, directoryFileTreeFactory, fileHasher);
    return new FileTreeAdapter(cpioFileTree, patternSetFactory);
}
 
Example #15
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree cpioTree(Object cpioFile, int blockSize, String encoding) {
    return cpioTree(cpioFile, f -> new CpioArchiveInputStream(new FileInputStream(f), blockSize, encoding));
}
 
Example #16
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree cpioTree(Object cpioFile, String encoding) {
    return cpioTree(cpioFile, f -> new CpioArchiveInputStream(new FileInputStream(f), encoding));
}
 
Example #17
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree cpioTree(Object cpioFile, int blockSize) {
    return cpioTree(cpioFile, f -> new CpioArchiveInputStream(new FileInputStream(f), blockSize));
}
 
Example #18
Source File: CompressFileOperationsImpl.java    From gradle-plugins with MIT License 4 votes vote down vote up
@Override
public FileTree cpioTree(Object cpioFile) {
    return cpioTree(cpioFile, f -> new CpioArchiveInputStream(new FileInputStream(f)));
}