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 symbol hooking for malloc, memcpy & friends.
Also moved some stuff inside the Emulator class because that is what this entire project is about.
- Loading branch information
Showing
14 changed files
with
154 additions
and
44 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
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
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
Empty file.
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 @@ | ||
import logging | ||
|
||
from androidemu.hooker import Hooker | ||
from androidemu.native.memory import NativeMemory | ||
|
||
from androidemu.java.helpers.native_method import native_method | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class NativeHooks: | ||
|
||
""" | ||
:type memory NativeMemory | ||
:type modules Modules | ||
:type hooker Hooker | ||
""" | ||
def __init__(self, memory, modules, hooker): | ||
self._memory = memory | ||
|
||
modules.add_symbol_hook('malloc', hooker.write_function(self.malloc) + 1) | ||
modules.add_symbol_hook('memcpy', hooker.write_function(self.memcpy) + 1) | ||
|
||
@native_method | ||
def malloc(self, mu, size): | ||
# TODO: Actually reserve memory with checks. | ||
logger.warning("Application requested %d bytes." % size) | ||
return 0x10 | ||
|
||
@native_method | ||
def memcpy(self, mu, dst, src, count): | ||
# TODO: Actually copy memory with checks. | ||
logger.warning("Application copies %d bytes from 0x%x to 0x%x." % (count, src, dst)) | ||
return 0x10 |
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,5 @@ | ||
class NativeMemory: | ||
|
||
def __init__(self, memory_base, memory_size): | ||
self._memory_base = memory_base | ||
self._memory_size = memory_size |
Empty file.
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,27 @@ | ||
import hexdump | ||
|
||
|
||
def hex_dump(mu, address, size): | ||
data = mu.mem_read(address, size) | ||
return hexdump.hexdump(data) | ||
|
||
|
||
def read_ptr(mu, address): | ||
return int.from_bytes(mu.mem_read(address, 4), byteorder='little') | ||
|
||
|
||
def read_utf8(mu, address): | ||
buffer_address = address | ||
buffer_read_size = 32 | ||
buffer = b"" | ||
null_pos = None | ||
|
||
# Keep reading until we read something that contains a null terminator. | ||
while null_pos is None: | ||
buf_read = mu.mem_read(buffer_address, buffer_read_size) | ||
if b'\x00' in buf_read: | ||
null_pos = len(buffer) + buf_read.index(b'\x00') | ||
buffer += buf_read | ||
buffer_address += buffer_read_size | ||
|
||
return buffer[:null_pos].decode("utf-8") |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
unicorn==1.0.1 | ||
pyelftools==0.24 | ||
pyelftools==0.24 | ||
hexdump==3.3 |