diff options
Diffstat (limited to 'libraries/classparser')
-rw-r--r-- | libraries/classparser/CMakeLists.txt | 11 | ||||
-rw-r--r-- | libraries/classparser/include/classparser.h (renamed from libraries/classparser/include/javautils.h) | 6 | ||||
-rw-r--r-- | libraries/classparser/include/classparser_config.h | 2 | ||||
-rw-r--r-- | libraries/classparser/src/annotations.h | 1 | ||||
-rw-r--r-- | libraries/classparser/src/classparser.cpp (renamed from libraries/classparser/src/javautils.cpp) | 10 | ||||
-rw-r--r-- | libraries/classparser/src/constants.h | 16 |
6 files changed, 25 insertions, 21 deletions
diff --git a/libraries/classparser/CMakeLists.txt b/libraries/classparser/CMakeLists.txt index a6c3fa14..db266f53 100644 --- a/libraries/classparser/CMakeLists.txt +++ b/libraries/classparser/CMakeLists.txt @@ -18,7 +18,7 @@ include_directories(${Qt5Base_INCLUDE_DIRS}) set(CLASSPARSER_HEADERS # Public headers include/classparser_config.h -include/javautils.h +include/classparser.h # Private headers src/annotations.h @@ -30,12 +30,13 @@ src/membuffer.h ) set(CLASSPARSER_SOURCES -src/javautils.cpp +src/classparser.cpp src/annotations.cpp ) add_definitions(-DCLASSPARSER_LIBRARY) -add_library(classparser SHARED ${CLASSPARSER_SOURCES} ${CLASSPARSER_HEADERS}) -target_include_directories(classparser PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") -qt5_use_modules(classparser Core) +add_library(MultiMC_classparser STATIC ${CLASSPARSER_SOURCES} ${CLASSPARSER_HEADERS}) +target_include_directories(MultiMC_classparser PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") +target_link_libraries(MultiMC_classparser MultiMC_quazip) +qt5_use_modules(MultiMC_classparser Core) diff --git a/libraries/classparser/include/javautils.h b/libraries/classparser/include/classparser.h index aad7b504..23a65589 100644 --- a/libraries/classparser/include/javautils.h +++ b/libraries/classparser/include/classparser.h @@ -1,4 +1,4 @@ -/* Copyright 2013-2017 MultiMC Contributors +/* Copyright 2013-2018 MultiMC Contributors * * Authors: Orochimarufan <orochimarufan.x3@gmail.com> * @@ -18,9 +18,7 @@ #include <QString> #include "classparser_config.h" -#define MCVer_Unknown "Unknown" - -namespace javautils +namespace classparser { /** * @brief Get the version from a minecraft.jar by parsing its class files. Expensive! diff --git a/libraries/classparser/include/classparser_config.h b/libraries/classparser/include/classparser_config.h index cc903210..db8f40a3 100644 --- a/libraries/classparser/include/classparser_config.h +++ b/libraries/classparser/include/classparser_config.h @@ -1,4 +1,4 @@ -/* Copyright 2013-2017 MultiMC Contributors +/* Copyright 2013-2018 MultiMC Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/libraries/classparser/src/annotations.h b/libraries/classparser/src/annotations.h index aa25d241..dd603af3 100644 --- a/libraries/classparser/src/annotations.h +++ b/libraries/classparser/src/annotations.h @@ -42,6 +42,7 @@ protected: public: element_value(element_value_type type, constant_pool &pool) : type(type), pool(pool) {}; + virtual ~element_value() {} element_value_type getElementValueType() { diff --git a/libraries/classparser/src/javautils.cpp b/libraries/classparser/src/classparser.cpp index 719032af..8837781f 100644 --- a/libraries/classparser/src/javautils.cpp +++ b/libraries/classparser/src/classparser.cpp @@ -1,4 +1,4 @@ -/* Copyright 2013-2017 MultiMC Contributors +/* Copyright 2013-2018 MultiMC Contributors * * Authors: Orochimarufan <orochimarufan.x3@gmail.com> * @@ -15,17 +15,18 @@ * limitations under the License. */ #include "classfile.h" -#include "javautils.h" +#include "classparser.h" #include <QFile> #include <quazipfile.h> +#include <QDebug> -namespace javautils +namespace classparser { QString GetMinecraftJarVersion(QString jarName) { - QString version = MCVer_Unknown; + QString version; // check if minecraft.jar exists QFile jar(jarName); @@ -61,6 +62,7 @@ QString GetMinecraftJarVersion(QString jarName) if (constant.type != java::constant::j_string_data) continue; const std::string &str = constant.str_data; + qDebug() << QString::fromStdString(str); if (str.compare(0, 20, "Minecraft Minecraft ") == 0) { version = str.substr(20).data(); diff --git a/libraries/classparser/src/constants.h b/libraries/classparser/src/constants.h index 242b943e..9c74ab20 100644 --- a/libraries/classparser/src/constants.h +++ b/libraries/classparser/src/constants.h @@ -21,14 +21,12 @@ public: j_methodref = 10, j_interface_methodref = 11, j_nameandtype = 12 + // FIXME: missing some constant types, see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4 } type; constant(util::membuffer &buf) { buf.read(type); - // invalid constant type! - if (type > j_nameandtype || type == (type_t)0 || type == (type_t)2) - throw new classfile_exception(); // load data depending on type switch (type) @@ -65,10 +63,13 @@ public: buf.read_be(name_and_type.name_index); buf.read_be(name_and_type.descriptor_index); break; + default: + // invalid constant type! + throw new classfile_exception(); } } - constant(int fake) + constant(int) { type = j_hole; } @@ -115,6 +116,9 @@ public: ss << "NameAndType: " << name_and_type.name_index << " " << name_and_type.descriptor_index; break; + default: + ss << "Invalid entry (" << int(type) << ")"; + break; } return ss.str(); } @@ -166,10 +170,10 @@ public: */ void load(util::membuffer &buf) { + // FIXME: @SANITY this should check for the end of buffer. uint16_t length = 0; buf.read_be(length); length--; - uint16_t index = 1; const constant *last_constant = nullptr; while (length) { @@ -182,12 +186,10 @@ public: // push in a fake constant to preserve indexing constants.push_back(constant(0)); length -= 2; - index += 2; } else { length--; - index++; } } } |