cprover
jar_filet Class Referencefinal

Class representing a .jar archive. More...

#include <jar_file.h>

Collaboration diagram for jar_filet:
[legend]

Public Member Functions

 jar_filet (java_class_loader_limitt &limit, const std::string &filename)
 Open java file for reading. More...
 
 jar_filet (java_class_loader_limitt &limit, const void *data, size_t size)
 Open a JAR file of size size loaded in memory at address data. More...
 
 jar_filet (const jar_filet &)=delete
 
jar_filetoperator= (const jar_filet &)=delete
 
 jar_filet (jar_filet &&)
 
jar_filetoperator= (jar_filet &&)
 
 ~jar_filet ()=default
 
optionalt< std::string > get_entry (const std::string &filename)
 Get contents of a file in the jar archive. More...
 
std::unordered_map< std::string, std::string > get_manifest ()
 Get contents of the Manifest file in the jar archive. More...
 
std::vector< std::string > filenames () const
 Get list of filenames in the archive. More...
 

Private Member Functions

void initialize_file_index (java_class_loader_limitt &limit)
 Loads the fileindex (m_name_to_index) with a map of loaded files to indices. More...
 

Private Attributes

mz_zip_archivet m_zip_archive
 
std::unordered_map< std::string, size_t > m_name_to_index
 Map of filename to the file index in the zip archive. More...
 

Detailed Description

Class representing a .jar archive.

Definition at line 24 of file jar_file.h.

Constructor & Destructor Documentation

◆ jar_filet() [1/4]

jar_filet::jar_filet ( java_class_loader_limitt limit,
const std::string &  filename 
)

Open java file for reading.

This constructor creates a jar_file object whose contents are extracted from a file with given name.

Parameters
limitObject limiting number of loaded .class files
filenameName of the file
Exceptions
Throwsstd::runtime_error if file cannot be opened

Definition at line 32 of file jar_file.cpp.

References initialize_file_index().

◆ jar_filet() [2/4]

jar_filet::jar_filet ( java_class_loader_limitt limit,
const void *  data,
size_t  size 
)

Open a JAR file of size size loaded in memory at address data.

This constructor creates a jar_file object whose contents are extracted from a memory buffer (byte array) as opposed to a jar file.

Parameters
limitObject limiting number of loaded .class files
datamemory buffer with the contents of the jar file
sizesize of the memory buffer
Exceptions
Throwsstd::runtime_error if file cannot be opened

Definition at line 43 of file jar_file.cpp.

References initialize_file_index().

◆ jar_filet() [3/4]

jar_filet::jar_filet ( const jar_filet )
delete

◆ jar_filet() [4/4]

jar_filet::jar_filet ( jar_filet &&  other)

Definition at line 54 of file jar_file.cpp.

◆ ~jar_filet()

jar_filet::~jar_filet ( )
default

Member Function Documentation

◆ filenames()

std::vector< std::string > jar_filet::filenames ( ) const

Get list of filenames in the archive.

Definition at line 123 of file jar_file.cpp.

References m_name_to_index.

Referenced by java_class_loadert::read_jar_file().

◆ get_entry()

optionalt< std::string > jar_filet::get_entry ( const std::string &  filename)

Get contents of a file in the jar archive.

Returns nullopt if file doesn't exist.

Parameters
filenameName of the file in the archive

Definition at line 65 of file jar_file.cpp.

References mz_zip_archivet::extract(), m_name_to_index, and m_zip_archive.

Referenced by java_class_loadert::get_class_from_jar(), and get_manifest().

◆ get_manifest()

std::unordered_map< std::string, std::string > jar_filet::get_manifest ( )

Get contents of the Manifest file in the jar archive.

Definition at line 99 of file jar_file.cpp.

References get_entry(), and trim().

Referenced by java_bytecode_languaget::parse().

◆ initialize_file_index()

void jar_filet::initialize_file_index ( java_class_loader_limitt limit)
private

Loads the fileindex (m_name_to_index) with a map of loaded files to indices.

Definition at line 19 of file jar_file.cpp.

References mz_zip_archivet::get_filename(), mz_zip_archivet::get_num_files(), has_suffix(), java_class_loader_limitt::load_class_file(), m_name_to_index, and m_zip_archive.

Referenced by jar_filet().

◆ operator=() [1/2]

jar_filet& jar_filet::operator= ( const jar_filet )
delete

◆ operator=() [2/2]

jar_filet & jar_filet::operator= ( jar_filet &&  other)

Definition at line 58 of file jar_file.cpp.

References m_name_to_index, and m_zip_archive.

Member Data Documentation

◆ m_name_to_index

std::unordered_map<std::string, size_t> jar_filet::m_name_to_index
private

Map of filename to the file index in the zip archive.

Definition at line 65 of file jar_file.h.

Referenced by filenames(), get_entry(), initialize_file_index(), and operator=().

◆ m_zip_archive

mz_zip_archivet jar_filet::m_zip_archive
private

Definition at line 62 of file jar_file.h.

Referenced by get_entry(), initialize_file_index(), and operator=().


The documentation for this class was generated from the following files: