Skip to content

Commit

Permalink
PR cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonLucid committed Aug 20, 2019
1 parent 8568b31 commit b20d9b1
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 37 deletions.
Binary file removed .DS_Store
Binary file not shown.
101 changes: 94 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
# Created by https://www.gitignore.io/api/venv,python,pycharm+all

# Created by https://www.gitignore.io/api/venv,macos,python,windows,pycharm+all
# Edit at https://www.gitignore.io/?templates=venv,macos,python,windows,pycharm+all

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### PyCharm+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
Expand All @@ -11,6 +41,9 @@
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
Expand All @@ -24,6 +57,16 @@
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

Expand Down Expand Up @@ -54,6 +97,9 @@ fabric.properties
# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### PyCharm+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
Expand All @@ -67,6 +113,9 @@ modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
Expand All @@ -90,6 +139,8 @@ parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
Expand All @@ -108,6 +159,7 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
Expand All @@ -125,6 +177,7 @@ coverage.xml
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
Expand All @@ -142,9 +195,20 @@ target/
# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

Expand Down Expand Up @@ -172,9 +236,11 @@ venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

### Python Patch ###
.venv/
# Pyre type checker
.pyre/

### venv ###
# Virtualenv
Expand All @@ -188,9 +254,30 @@ venv.bak/
pyvenv.cfg
pip-selfcheck.json

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# End of https://www.gitignore.io/api/venv,python,pycharm+all
# Windows shortcuts
*.lnk

# Custom
private.py
!samples/example_binaries/*.so
# End of https://www.gitignore.io/api/venv,macos,python,windows,pycharm+all
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# AndroidNativeEmu
[ 中文README & 教程? ](README_cn.md)

Allows you to partly emulate an Android native library.

This is an educational project to learn more about the ELF file format and [Unicorn](https://github.com/unicorn-engine/unicorn).

[中文README](README_cn.md)

## Features

- Emulation of the [JNI Invocation API](https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html) so `JNI_OnLoad` can be called properly.
Expand All @@ -14,15 +15,6 @@ This is an educational project to learn more about the ELF file format and [Unic
- All JavaVM, JNIEnv and hooked functions are handled by python.
- Enable VFP support.

## My Changes
- Add init_array support depends on Relocation information.
- Add support of modify object value by reference id.
- Implement getcpu() syscall
- Implement set_byte_array_region
- Register Function failed would't raise an error(beacuse most jni functions are not used.)
- samples:添加抖音 X-Gorgen 调用实例
- [ 中文README ](README_cn.md)

## Usage

> In the future this will be possible through pypi.
Expand Down
4 changes: 0 additions & 4 deletions androidemu/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def _enable_vfp(self):
finally:
self.mu.mem_unmap(address, mem_size)

def _call_init_array(self):
pass

def load_library(self, filename, do_init=True):
libmod = self.modules.load_module(filename)
if do_init:
Expand Down Expand Up @@ -140,7 +137,6 @@ def call_native(self, addr, *argv):

try:
# Execute native call.

native_write_args(self, *argv)
stop_pos = randint(HOOK_MEMORY_BASE, HOOK_MEMORY_BASE + HOOK_MEMORY_SIZE) | 1
self.mu.reg_write(UC_ARM_REG_LR, stop_pos)
Expand Down
10 changes: 2 additions & 8 deletions androidemu/internal/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def find_symbol(self, addr):
return module.symbol_lookup[addr]
return None, None


def load_module(self, filename):
logger.debug("Loading module '%s'." % filename)

Expand All @@ -50,7 +49,6 @@ def load_module(self, filename):
# - LOAD (determinate what parts of the ELF file get mapped into memory)
load_segments = [x for x in elf.iter_segments() if x.header.p_type == 'PT_LOAD']


# Find bounds of the load segments.
bound_low = 0
bound_high = 0
Expand Down Expand Up @@ -111,7 +109,7 @@ def load_module(self, filename):
if fun_ptr != 0:
# fun_ptr += load_base
init_array.append(fun_ptr + load_base)
#print ("find init array for :%s %x" % (filename, fun_ptr))
# print ("find init array for :%s %x" % (filename, fun_ptr))
else:
# search in reloc
for rel in rel_section.iter_relocations():
Expand All @@ -121,7 +119,7 @@ def load_module(self, filename):
sym = dynsym.get_symbol(rel['r_info_sym'])
sym_value = sym['st_value']
init_array.append(load_base + sym_value)
#print ("find init array for :%s %x" % (filename, sym_value))
# print ("find init array for :%s %x" % (filename, sym_value))
break
init_array_offset += 4

Expand Down Expand Up @@ -151,7 +149,6 @@ def load_module(self, filename):
rel_addr = load_base + rel['r_offset'] # Location where relocation should happen
rel_info_type = rel['r_info_type']


# Relocation table for ARM
if rel_info_type == arm.R_ARM_ABS32:
# Create the new value.
Expand Down Expand Up @@ -190,9 +187,6 @@ def load_module(self, filename):
module = Module(filename, load_base, bound_high - bound_low, symbols_resolved, init_array)
self.modules.append(module)

#do init


return module

def _elf_get_symval(self, elf, elf_base, symbol):
Expand Down
3 changes: 2 additions & 1 deletion androidemu/java/classes/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from androidemu.java.java_field_def import JavaFieldDef
from androidemu.java.java_method_def import JavaMethodDef


class Constructor(metaclass=JavaClassDef,
jvm_name = 'java/lang/reflect/Constructor',
jvm_name='java/lang/reflect/Constructor',
jvm_fields=[
JavaFieldDef('slot', 'I', False, ignore=True),
JavaFieldDef('declaringClass', 'Ljava/lang/Class;', False)],
Expand Down
7 changes: 6 additions & 1 deletion androidemu/java/classes/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
from androidemu.java.java_field_def import JavaFieldDef


class Executable(metaclass = JavaClassDef,jvm_name = 'java/lang/reflect/Executable',jvm_fields=[JavaFieldDef('accessFlags', 'I', False)]):
class Executable(metaclass=JavaClassDef,
jvm_name='java/lang/reflect/Executable',
jvm_fields=[
JavaFieldDef('accessFlags', 'I', False)
]):

def __init__(self):
pass
9 changes: 6 additions & 3 deletions androidemu/java/jni_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def add_local_reference(self, obj):
def set_local_reference(self, idx, newobj):
if not isinstance(newobj, jobject):
raise ValueError('Expected a jobject.')
self._locals.set(idx, newobj)

self._locals.set(idx, newobj)

def get_local_reference(self, idx):
return self._locals.get(idx)
Expand Down Expand Up @@ -596,6 +596,10 @@ def is_instance_of(self, mu, env, obj_idx, class_idx):

@native_method
def get_method_id(self, mu, env, clazz_idx, name_ptr, sig_ptr):
"""
Returns the method ID for an instance (nonstatic) method of a class or interface. The method may be defined
in one of the clazz’s superclasses and inherited by clazz. The method is determined by its name and signature.
"""
name = memory_helpers.read_utf8(mu, name_ptr)
sig = memory_helpers.read_utf8(mu, sig_ptr)
clazz = self.get_reference(clazz_idx)
Expand Down Expand Up @@ -1546,8 +1550,7 @@ def set_boolean_array_region(self, mu, env):
def set_byte_array_region(self, mu, env, arrayJREF, startIndex, length, bufAddress):
string = memory_helpers.read_byte_array(mu, bufAddress, length)
logger.debug("JNIEnv->SetByteArrayRegion was called")
self.set_local_reference(arrayJREF,jbyteArray(string))

self.set_local_reference(arrayJREF, jbyteArray(string))

@native_method
def set_char_array_region(self, mu, env):
Expand Down
1 change: 0 additions & 1 deletion androidemu/java/reference_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def set(self, idx, newobj):

self._table[idx] = newobj


def add(self, obj):
if not isinstance(obj, jobject):
raise ValueError('Expected a jobject.')
Expand Down
1 change: 1 addition & 0 deletions androidemu/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


class Tracer:

def __init__(self, uc: Uc, modules: Modules):
self._uc = uc
self._modules = modules
Expand Down
1 change: 0 additions & 1 deletion androidemu/vfs/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class VirtualFileSystem:
"""
:type syscall_handler SyscallHandlers
"""

def __init__(self, root_path, syscall_handler):
self._root_path = root_path

Expand Down
Binary file removed samples/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion samples/example_douyin.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def getStackTrace(self, *args, **kwargs):


# bypass douyin checks
with open("samples/app_process32", 'rb') as ap:
with open("misc/samples/app_process32", 'rb') as ap:
data = ap.read()
len1 = len(data) + 1024 - (len(data) % 1024)
emulator.mu.mem_map(0xab006000, len1)
Expand Down
File renamed without changes.

0 comments on commit b20d9b1

Please sign in to comment.