diff options
Diffstat (limited to 'depends')
106 files changed, 22680 insertions, 0 deletions
diff --git a/depends/classparser/CMakeLists.txt b/depends/classparser/CMakeLists.txt new file mode 100644 index 00000000..5a48e002 --- /dev/null +++ b/depends/classparser/CMakeLists.txt @@ -0,0 +1,41 @@ +project(classparser) + +set(CMAKE_AUTOMOC ON) + +# Find Qt +find_package(Qt5Core REQUIRED) + +# Include Qt headers. +include_directories(${Qt5Base_INCLUDE_DIRS}) + +SET(CLASSPARSER_HEADERS +include/classparser_config.h + +# Public headers +include/javautils.h + +# Private headers +src/annotations.h +src/classfile.h +src/constants.h +src/errors.h +src/javaendian.h +src/membuffer.h +) + +SET(CLASSPARSER_SOURCES +src/javautils.cpp +src/annotations.cpp +) + +# Set the include dir path. +SET(LIBGROUPVIEW_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE) + +# Include self. +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +include_directories(${CMAKE_BINARY_DIR}/include) + +add_definitions(-DCLASSPARSER_LIBRARY) + +add_library(classparser SHARED ${CLASSPARSER_SOURCES} ${CLASSPARSER_HEADERS}) +qt5_use_modules(classparser Core) diff --git a/depends/classparser/include/classparser_config.h b/depends/classparser/include/classparser_config.h new file mode 100644 index 00000000..fe6a2ab9 --- /dev/null +++ b/depends/classparser/include/classparser_config.h @@ -0,0 +1,23 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <QtCore/QtGlobal> + +#ifdef CLASSPARSER_LIBRARY +# define CLASSPARSER_EXPORT Q_DECL_EXPORT +#else +# define CLASSPARSER_EXPORT Q_DECL_IMPORT +#endif + diff --git a/depends/classparser/include/javautils.h b/depends/classparser/include/javautils.h new file mode 100644 index 00000000..63e5ec26 --- /dev/null +++ b/depends/classparser/include/javautils.h @@ -0,0 +1,29 @@ +/* Copyright 2013 MultiMC Contributors + * + * Authors: Orochimarufan <orochimarufan.x3@gmail.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once +#include <QString> +#include "classparser_config.h" + +#define MCVer_Unknown "Unknown" + +namespace javautils +{ + /** + * @brief Get the version from a minecraft.jar by parsing its class files. Expensive! + */ + QString GetMinecraftJarVersion(QString jar); +} diff --git a/depends/classparser/src/annotations.cpp b/depends/classparser/src/annotations.cpp new file mode 100644 index 00000000..fc0c98fa --- /dev/null +++ b/depends/classparser/src/annotations.cpp @@ -0,0 +1,83 @@ +#include "classfile.h" +#include "annotations.h" +#include <sstream> + +namespace java +{ + std::string annotation::toString() + { + std::ostringstream ss; + ss << "Annotation type : " << type_index << " - " << pool[type_index].str_data << std::endl; + ss << "Contains " << name_val_pairs.size() << " pairs:" << std::endl; + for(unsigned i = 0; i < name_val_pairs.size(); i++) + { + std::pair<uint16_t, element_value *> &val = name_val_pairs[i]; + auto name_idx = val.first; + ss << pool[name_idx].str_data << "(" << name_idx << ")" << " = " << val.second->toString() << std::endl; + } + return ss.str(); + } + + annotation * annotation::read (util::membuffer& input, constant_pool& pool) + { + uint16_t type_index = 0; + input.read_be(type_index); + annotation * ann = new annotation(type_index,pool); + + uint16_t num_pairs = 0; + input.read_be(num_pairs); + while(num_pairs) + { + uint16_t name_idx = 0; + // read name index + input.read_be(name_idx); + auto elem = element_value::readElementValue(input,pool); + // read value + ann->add_pair(name_idx, elem); + num_pairs --; + } + return ann; + } + + element_value* element_value::readElementValue ( util::membuffer& input, java::constant_pool& pool ) + { + element_value_type type = INVALID; + input.read(type); + uint16_t index = 0; + uint16_t index2 = 0; + std::vector <element_value *> vals; + switch (type) + { + case PRIMITIVE_BYTE: + case PRIMITIVE_CHAR: + case PRIMITIVE_DOUBLE: + case PRIMITIVE_FLOAT: + case PRIMITIVE_INT: + case PRIMITIVE_LONG: + case PRIMITIVE_SHORT: + case PRIMITIVE_BOOLEAN: + case STRING: + input.read_be(index); + return new element_value_simple(type, index, pool); + case ENUM_CONSTANT: + input.read_be(index); + input.read_be(index2); + return new element_value_enum(type, index, index2, pool); + case CLASS: // Class + input.read_be(index); + return new element_value_class(type, index, pool); + case ANNOTATION: // Annotation + // FIXME: runtime visibility info needs to be passed from parent + return new element_value_annotation(ANNOTATION, annotation::read(input, pool), pool); + case ARRAY: // Array + input.read_be(index); + for (int i = 0; i < index; i++) + { + vals.push_back(element_value::readElementValue(input, pool)); + } + return new element_value_array(ARRAY, vals, pool); + default: + throw new java::classfile_exception(); + } + } +}
\ No newline at end of file diff --git a/depends/classparser/src/annotations.h b/depends/classparser/src/annotations.h new file mode 100644 index 00000000..b115dc0b --- /dev/null +++ b/depends/classparser/src/annotations.h @@ -0,0 +1,252 @@ +#pragma once +#include "classfile.h" +#include <map> +#include <vector> + +namespace java +{ + enum element_value_type : uint8_t + { + INVALID = 0, + STRING = 's', + ENUM_CONSTANT = 'e', + CLASS = 'c', + ANNOTATION = '@', + ARRAY = '[', // one array dimension + PRIMITIVE_INT = 'I', // integer + PRIMITIVE_BYTE = 'B', // signed byte + PRIMITIVE_CHAR = 'C', // Unicode character code point in the Basic Multilingual Plane, encoded with UTF-16 + PRIMITIVE_DOUBLE = 'D', // double-precision floating-point value + PRIMITIVE_FLOAT = 'F', // single-precision floating-point value + PRIMITIVE_LONG = 'J', // long integer + PRIMITIVE_SHORT = 'S', // signed short + PRIMITIVE_BOOLEAN = 'Z' // true or false + }; + /** + * The element_value structure is a discriminated union representing the value of an element-value pair. + * It is used to represent element values in all attributes that describe annotations + * - RuntimeVisibleAnnotations + * - RuntimeInvisibleAnnotations + * - RuntimeVisibleParameterAnnotations + * - RuntimeInvisibleParameterAnnotations). + * + * The element_value structure has the following format: + */ + class element_value + { + protected: + element_value_type type; + constant_pool & pool; + + public: + element_value(element_value_type type, constant_pool & pool): type(type), pool(pool) {}; + + element_value_type getElementValueType() + { + ret |
