Skip to content

Commit cf16e6c

Browse files
nbs32krdbo
andauthored
Add compatibility with Oracle's JVM (#30)
* Add compatibility with Oracle's JVM * do the fix a bit differently * fix minor issue --------- Co-authored-by: rdbo <rdbodev@gmail.com>
1 parent 84c12fa commit cf16e6c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/jnihook.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ JNIHook_Init(JavaVM *jvm)
476476

477477
// Force AllowRedefinitionToAddDeleteMethods
478478
auto jvm_flag_type_result = VMType::from_static("JVMFlag");
479-
if (!jvm_flag_type_result) {
479+
if (!jvm_flag_type_result && !(jvm_flag_type_result = VMType::from_static("Flag"))) {
480480
LOG("Failed to parse VMStructs\n");
481481
return JNIHOOK_ERR_UNKNOWN;
482482
}
@@ -496,7 +496,7 @@ JNIHook_Init(JavaVM *jvm)
496496
auto flags_buf = *(unsigned char **)flagsField; // flagTable
497497
auto numFlags = *numFlagsField;
498498
for (size_t i = 0; i < numFlags; ++i) {
499-
auto flag = VMType::from_instance("JVMFlag", &flags_buf[i * jvm_flag_size]);
499+
auto flag = VMType::from_instance(jvm_flag_type.get_type_name().c_str(), &flags_buf[i * jvm_flag_size]);
500500
auto name_addr = flag->get_field<void *>("_name").value();
501501
auto name = (char *)*name_addr;
502502
LOG("FLAG: %s\n", name);

src/jvm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ std::optional<VMType> VMType::from_static(const char *typeName)
8181

8282
VMType vmtype;
8383
vmtype.instance = NULL;
84+
vmtype.type_name = std::string(typeName);
8485
vmtype.type_entry = type.value();
8586
vmtype.fields = fields;
8687

src/jvm.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class VMTypes {
8080

8181
class VMType {
8282
private:
83+
std::string type_name;
8384
VMTypeEntry *type_entry;
8485
std::optional<std::reference_wrapper<VMTypes::struct_entry_t>> fields;
8586
void *instance; // pointer to instantiated VM type
@@ -119,6 +120,11 @@ class VMType {
119120
return reinterpret_cast<T *>(fieldAddress.value());
120121
}
121122

123+
const std::string &get_type_name()
124+
{
125+
return this->type_name;
126+
}
127+
122128
inline void *get_instance()
123129
{
124130
return this->instance;

0 commit comments

Comments
 (0)