forked from AeonLucid/AndroidNativeEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic java classloader using a metaclass.
- Loading branch information
Showing
7 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import itertools | ||
|
||
|
||
class JavaClassDef(type): | ||
next_jvm_id = itertools.count(start=1) | ||
|
||
def __init__(cls, name, base, ns, jvm_name=None): | ||
cls.jvm_id = next(JavaClassDef.next_jvm_id) | ||
cls.jvm_name = jvm_name | ||
cls.jvm_natives = list() | ||
type.__init__(cls, name, base, ns) | ||
|
||
def __new__(mcs, name, base, ns, **kargs): | ||
return type.__new__(mcs, name, base, ns) | ||
|
||
def register_native(self, name, signature, ptr_func): | ||
self.jvm_natives.append((name, signature, ptr_func)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from androidemu.java.helpers.java_class_def import JavaClassDef | ||
|
||
|
||
class JavaClassLoader: | ||
|
||
""" | ||
:type class_by_id dict[int, JavaClassDef] | ||
:type class_by_name dict[string, JavaClassDef] | ||
""" | ||
def __init__(self): | ||
self.class_by_id = dict() | ||
self.class_by_name = dict() | ||
|
||
def add_class(self, clazz): | ||
if not isinstance(clazz, JavaClassDef): | ||
raise ValueError('Expected a JavaClassDef.') | ||
|
||
if clazz.jvm_name in self.class_by_name: | ||
raise KeyError('The class \'%s\' is already registered.' % clazz.jvm_name) | ||
|
||
self.class_by_id[clazz.jvm_id] = clazz | ||
self.class_by_name[clazz.jvm_name] = clazz | ||
|
||
def find_class_by_id(self, jvm_id): | ||
if jvm_id not in self.class_by_id: | ||
return None | ||
|
||
return self.class_by_id[jvm_id] | ||
|
||
def find_class_by_name(self, name): | ||
if name not in self.class_by_name: | ||
return None | ||
|
||
return self.class_by_name[name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters