Skip to content

Commit 97da7d9

Browse files
feat: proxy class parsing (messy!)
1 parent 797f02d commit 97da7d9

13 files changed

+211
-7
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION VERSION 3.30)
2-
project(JavaObjectStreams VERSION 1.3.9)
2+
project(JavaObjectStreams VERSION 1.3.10)
33

44
set(CMAKE_CXX_STANDARD 20)
55

@@ -147,6 +147,14 @@ set(FILES
147147
src/type/object/parsers/ExceptionObjectParser.cpp
148148
include/JavaObject/type/object/parsers/ClassObjectParser.h
149149
src/type/object/parsers/ClassObjectParser.cpp
150+
include/JavaObject/type/object/types/descriptor/ProxyClassDescriptorObject.cpp
151+
include/JavaObject/type/object/types/descriptor/ProxyClassDescriptorObject.h
152+
include/JavaObject/type/object/types/descriptor/ProxyClassDescriptorInfoObject.cpp
153+
include/JavaObject/type/object/types/descriptor/ProxyClassDescriptorInfoObject.h
154+
include/JavaObject/type/object/parsers/descriptor/NewProxyClassDescriptorParser.cpp
155+
include/JavaObject/type/object/parsers/descriptor/NewProxyClassDescriptorParser.h
156+
include/JavaObject/type/object/parsers/descriptor/ProxyClassDescriptorInfoParser.cpp
157+
include/JavaObject/type/object/parsers/descriptor/ProxyClassDescriptorInfoParser.h
150158
)
151159

152160
add_library(JavaObjectStreams SHARED ${FILES})

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ A C++ library to provide serialization and deserialization of Java objects (ala
1818
| **Deserialization** |||
1919
| **Serialization** |||
2020

21+
#### TODO
22+
- Fix up API (probably in the style of the Java Reflection API)
23+
- Add and implement common interfaces between similar objects (looking at you ProxyClass and NewClass)
24+
- Properly validate expected types, use std::variant (or actually it would be nicer to make a custom holder) in place of IObject when available.
25+
- For object types like TC_ENDBLOCKDATA, we can ignore it and store nullptr.
2126
## Contributing
2227
Unless otherwise stated, contributions are licensed under the terms of the
23-
MIT license.
28+
MIT license.
29+
30+
## Credits
31+
https://docs.oracle.com/javase/9/docs/specs/serialization/protocol.html#grammar-for-the-stream-format
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @file NewProxyClassDescriptorParser.h
2+
*
3+
* @author DexrnZacAttack
4+
* @date 3/29/26
5+
*
6+
* @device zPc-i2
7+
*/
8+
#ifndef JAVAOBJECTSTREAMS_NEWPROXYCLASSDESCRIPTORPARSER_H
9+
#define JAVAOBJECTSTREAMS_NEWPROXYCLASSDESCRIPTORPARSER_H
10+
#include "JavaObject/type/object/parsers/IObjectParser.h"
11+
12+
namespace javaobject::type::object::parsers::descriptor {
13+
struct NewProxyClassDescriptorParser : IObjectParser {
14+
std::shared_ptr<object::IObject> operator()(type::object::ObjectTypeCodeParser &parser) const override;
15+
};
16+
}
17+
18+
#endif // JAVAOBJECTSTREAMS_NEWPROXYCLASSDESCRIPTORPARSER_H
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @file ProxyClassDescriptorInfoParser.h
2+
*
3+
* @author DexrnZacAttack
4+
* @date 3/29/26
5+
*
6+
* @device zPc-i2
7+
*/
8+
#ifndef JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTORINFOPARSER_H
9+
#define JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTORINFOPARSER_H
10+
#include "JavaObject/type/object/parsers/IObjectParser.h"
11+
12+
namespace javaobject::type::object::parsers::descriptor {
13+
struct ProxyClassDescriptorInfoParser : IObjectParser {
14+
std::shared_ptr<object::IObject> operator()(type::object::ObjectTypeCodeParser &parser) const override;
15+
};
16+
}
17+
18+
#endif // JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTORINFOPARSER_H

include/JavaObject/type/object/types/descriptor/NewClassDescriptorObject.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#include <vector>
2323

2424
namespace javaobject::type::object::descriptor {
25-
class NewProxyClassDescriptorObject : public IObject {
26-
// TODO
27-
};
28-
2925
struct NewClassDescriptorObject : IObject {
3026
public:
3127
NewClassDescriptorObject(const std::string &name, const std::uint64_t serialVersionUid, std::shared_ptr<ClassDescriptorInfoObject> info)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/** @file ProxyClassDescriptorInfoObject.h
2+
*
3+
* @author DexrnZacAttack
4+
* @date 3/29/26
5+
*
6+
* @device zPc-i2
7+
*/
8+
#ifndef JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTORINFOOBJECT_H
9+
#define JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTORINFOOBJECT_H
10+
#include "JavaObject/type/object/types/AnnotationObject.h"
11+
#include "JavaObject/type/object/types/IObject.h"
12+
13+
#include <vector>
14+
15+
namespace javaobject::type::object::types::descriptor {
16+
class ProxyClassDescriptorInfoObject : public IObject {
17+
public:
18+
std::string toString() override;
19+
20+
std::vector<std::string> m_interfaces;
21+
/** if nullptr, endblockdata was hit instead */
22+
std::shared_ptr<AnnotationObject> m_annotation;
23+
std::shared_ptr<IObject> m_superClassDesc;
24+
};
25+
}
26+
27+
#endif // JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTORINFOOBJECT_H
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** @file ProxyClassDescriptorObject.h
2+
*
3+
* @author DexrnZacAttack
4+
* @date 3/29/26
5+
*
6+
* @device zPc-i2
7+
*/
8+
#ifndef JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTOROBJECT_H
9+
#define JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTOROBJECT_H
10+
#include "JavaObject/type/object/types/IObject.h"
11+
#include "JavaObject/type/object/types/descriptor/ProxyClassDescriptorInfoObject.h"
12+
13+
namespace javaobject::type::object::types::descriptor {
14+
class ProxyClassDescriptorObject : public IObject {
15+
public:
16+
explicit ProxyClassDescriptorObject(const std::shared_ptr<ProxyClassDescriptorInfoObject> &info)
17+
: info(info) {
18+
}
19+
20+
std::string toString() override;
21+
22+
std::shared_ptr<ProxyClassDescriptorInfoObject> info;
23+
};
24+
}
25+
26+
#endif // JAVAOBJECTSTREAMS_PROXYCLASSDESCRIPTOROBJECT_H

src/type/object/ObjectTypeCodeParser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "JavaObject/type/object/parsers/NullObjectParser.h"
3030
#include "JavaObject/type/object/parsers/ResetObjectParser.h"
3131
#include "JavaObject/type/object/parsers/ShortBlockDataObjectParser.h"
32+
#include "JavaObject/type/object/parsers/descriptor/NewProxyClassDescriptorParser.h"
3233

3334
namespace javaobject::type::object {
3435
ObjectTypeCodeParser::ObjectTypeCodeParser(std::istream &input, HandleContainer &handleContainer, TypeCodeParserStorage &parserStorage) : ITypeCodeParser(input, handleContainer), ITypeCodeParserStorageHolder(parserStorage) {
@@ -44,6 +45,7 @@ namespace javaobject::type::object {
4445
this->m_parsers[EObjectTypeCode::TC_ARRAY] = std::make_unique<parsers::ArrayObjectParser>();
4546
this->m_parsers[EObjectTypeCode::TC_RESET] = std::make_unique<parsers::ResetObjectParser>();
4647
this->m_parsers[EObjectTypeCode::TC_EXCEPTION] = std::make_unique<parsers::ExceptionObjectParser>();
48+
this->m_parsers[EObjectTypeCode::TC_PROXYCLASSDESC] = std::make_unique<parsers::descriptor::NewProxyClassDescriptorParser>();
4749
}
4850

4951
std::shared_ptr<IObject> ObjectTypeCodeParser::readUsingTypeCode(const EObjectTypeCode &typecode) {

src/type/object/parsers/ObjectParser.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "JavaObject/type/object/types/NullObject.h"
1717
#include "JavaObject/type/object/types/Object.h"
1818
#include "JavaObject/type/object/types/descriptor/NewClassDescriptorObject.h"
19+
#include "JavaObject/type/object/types/descriptor/ProxyClassDescriptorObject.h"
1920

2021
namespace javaobject::type::object::parsers {
2122
std::shared_ptr<object::IObject> ObjectParser::operator()(type::object::ObjectTypeCodeParser &parser) const {
@@ -24,7 +25,14 @@ namespace javaobject::type::object::parsers {
2425
obj->clazz = parser.readNext();
2526
parser.handleContainer().registerHandle(obj);
2627

27-
obj->classData = ClassDataParser(std::static_pointer_cast<descriptor::NewClassDescriptorObject>(obj->clazz)->info)(parser);
28+
// TODO we can implement common interface between proxy and non proxy class object with getters
29+
// TODO this really needs a cleanup
30+
if (auto c = std::dynamic_pointer_cast<descriptor::NewClassDescriptorObject>(obj->clazz)) {
31+
obj->classData = ClassDataParser(c->info)(parser);
32+
} else if (auto c = std::dynamic_pointer_cast<types::descriptor::ProxyClassDescriptorObject>(obj->clazz)) {
33+
if (auto ci = std::dynamic_pointer_cast<descriptor::NewClassDescriptorObject>(c->info->m_superClassDesc))
34+
obj->classData = ClassDataParser(ci->info)(parser);
35+
}
2836

2937
return obj;
3038
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** @file NewProxyClassDescriptorParser.cpp
2+
*
3+
* @author DexrnZacAttack
4+
* @date 3/29/26
5+
*
6+
* @device zPc-i2
7+
*/
8+
#include "JavaObject/type/object/parsers/descriptor/NewProxyClassDescriptorParser.h"
9+
10+
#include "JavaObject/type/object/ObjectTypeCodeParser.h"
11+
#include "JavaObject/type/object/parsers/descriptor/ProxyClassDescriptorInfoParser.h"
12+
#include "JavaObject/type/object/types/descriptor/ProxyClassDescriptorObject.h"
13+
14+
#include <format>
15+
16+
namespace javaobject::type::object::parsers::descriptor {
17+
std::shared_ptr<object::IObject> NewProxyClassDescriptorParser::operator()(type::object::ObjectTypeCodeParser &parser) const {
18+
std::shared_ptr<types::descriptor::ProxyClassDescriptorObject> dc = std::make_shared<types::descriptor::ProxyClassDescriptorObject>(nullptr);
19+
20+
parser.handleContainer().registerHandle(dc);
21+
22+
dc->info = parser.readAsUsingParser<types::descriptor::ProxyClassDescriptorInfoObject>(ProxyClassDescriptorInfoParser());
23+
24+
return dc;
25+
}
26+
}

0 commit comments

Comments
 (0)