Git Product home page Git Product logo

cemu's Introduction

Logo

CEmu : The Cheap (Assembly) Emulator

Code style: black Licence MIT Python-Version 3.10 CEmu on PyPI CEmu on Discord Downloads

Description

Writing assembly is fun. Assembly is the lowest language (humanly understandable) available to communicate with computers, and is crucial to understand the internal mechanisms of any machine. Unfortunately, setting up an environment to write, compile and run assembly for various architectures (x86, ARM, MIPS, SPARC) has always been painful. CEmu is an attempt to fix this by providing GUI, CLI and library that allows to write and test assembly quickly.

CEmu is built upon:

And the GUI is powered by in a Qt6.

It allows to test binary samples, check your shellcodes or even simply learn how to write assembly code, all of this for the following architectures:

  • x86-32 / x86-64
  • ARM / AArch64
  • MIPS / MIPS64
  • SPARC / SPARC64
  • PPC (but not emulation)

CEmu was mostly tested to work on Linux and Windows, but should work on MacOS.

Installation

Notes

Since version 0.2.2, cemu is now Python3 only for simplicity and mostly also due to the fact that Python2 is not developed any longer. If your current installation of cemu is <= 0.2.1 and on Python2, please uninstall it and install it using Python3.

In addition, Python >= 3.10 is required, starting 0.6.

Quick install with PIP

Last stable from PyPI:

pip3 install cemu

Last stable from Github:

git clone https://github.com/hugsy/cemu
cd cemu
pip3 install --upgrade .

For 99% of cases, that's all you need to do. cemu will be installed in the associated Scripts directory:

  • On Linux by default the executable will be found as /usr/local/bin/cemu if installed as root, ~/.local/bin/cemu for non-root
  • On Windows, %PYTHON_DIR%\Scripts\cemu.exe if installed with privileges, %APPDATA%\Python\Python310\Scripts\cemu.exe if not

Usage

As a GUI

After installing with pip, simply run the executable, or invoke via Python

python -m cemu

This should produce a GUI similar to this:

cemu-gui

In the terminal

python -m cemu cli

From where you'll end up in a REPL, allowing you to build and run the emulation environment.

cemu-cli

As a Library

$ python
>>> import cemu

Then use the provided API to build and run your environment.

Contribution

cemu was created and maintained by myself, @_hugsy_, but kept fresh thanks to all the contributors.

contributors-img

If you just like the tool, consider dropping on Discord (or Twitter or other) a simple "thanks", it is always very appreciated. And if you can, consider sponsoring me - it really helps dedicating time and resources to the projects!

cemu's People

Contributors

ahmed-nematallah avatar hugsy avatar mx-pycoder avatar nobool avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cemu's Issues

unbuildable project?

keystone-engine readme states:

Keystone will be released to public after a testing phase

is it possible to build cemu in spite of this fact? If so, how?

MIPS architecture (Crashes program)

Your program entirely stops working when you try to make a MIPS program.
Here's an example, put this in the IDE section and try to run either step by step or run all:

.data
	myCharacter:	.byte 'm'
.text
	li $v0, 4
	la $a0, myCharacter
	syscall

The output should be "m" but it just crashes the entire program.

I believe the error is caused by the dot entries, so like .text and .data seem to crash your program. They are necessary when using MIPS assembly. I'd really appreciate it if you fixed this bug (I really want to replace MARS with this program).

Also is it possible to make your program into an IDE with markups? So like when I get an error it highlights it and perhaps offers suggestions? This would make your all-in-one far superior to any other assembly IDE.

Error I try to run my code

This is the log in terminal when I press the button "Run all code".
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/cemu/ui/main.py", line 168, in runCode
self.run()
File "/usr/local/lib/python3.6/dist-packages/cemu/ui/main.py", line 174, in run
if not self.loadContext():
File "/usr/local/lib/python3.6/dist-packages/cemu/ui/main.py", line 135, in loadContext
if not self.emu.compile_code(code):
File "/usr/local/lib/python3.6/dist-packages/cemu/emulator.py", line 170, in compile_code
self.code, self.num_insns = assemble(code, self.parent.arch)
File "/usr/local/lib/python3.6/dist-packages/cemu/utils.py", line 149, in assemble
arch, mode, endian = get_arch_mode("keystone", mode)
File "/usr/local/lib/python3.6/dist-packages/cemu/utils.py", line 67, in get_arch_mode
if lib=="keystone": arch, mode, endian = keystone.KS_ARCH_ARM, keystone.KS_MODE_ARM, keystone.KS_MODE_LITTLE_ENDIAN
AttributeError: module 'keystone' has no attribute 'KS_ARCH_ARM'

Can't Assemble x86-64

Getting a very odd issue trying to run a single test instruction post cemu installation. Log below. What's odd is that this works fine on my VMWare VM, but on my VirtualBox machine, built from the exact same script, stubbornly refuses to assemble x64 in cemu. kstool seems to handle this instruction just fine, so it doesn't appear to be an issue with the Keystone build. Any thoughts? Start over from scratch?

Switching to 'Intel i386 64bit, syntax Intel - little endian'  
[logger] Setup - Map .text @40000 (size=4096,perm=READ|EXEC)  
[logger] Setup - Map .data @60000 (size=4096,perm=READ|WRITE)  
[logger] Setup - Map .stack @800000 (size=16384,perm=READ|WRITE)  
[logger] Setup - Map .misc @900000 (size=4096,perm=ALL)  
[logger] Compilation - Assembling 1 instructions for Intel i386 64bit:  
b'mov rsi, 3'  
[logger] Error - Failed to compile code  
An error occured when loading context  

Running setup.py install for unicorn ... error

screen shot 2019-01-06 at 1 29 05 pm

Getting the above error after successfully running brew install capstone. I manually checked and the error is correct, there isn't any pthread.h file in the 'Headers' folder nor is there a 'libunicorn.dylib' file in the 'lib' folder. Is this something I manually install then re-run the second command line instruction: pip3 install -U cemu?

TypeError: sequence item 0: expected str instance, NoneType found

Python 3.7.0, installed using pip 10.0.1

Traceback (most recent call last):
  File "c:\users\gokha\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\gokha\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\gokha\AppData\Local\Programs\Python\Python37\Scripts\cemu.exe\__main__.py", line 9, in <module>
  File "c:\users\gokha\appdata\local\programs\python\python37\lib\site-packages\cemu\__main__.py", line 8, in main
    from cemu.core import Cemu
  File "c:\users\gokha\appdata\local\programs\python\python37\lib\site-packages\cemu\core.py", line 13, in <module>
    from .const import ICON_PATH
  File "c:\users\gokha\appdata\local\programs\python\python37\lib\site-packages\cemu\const.py", line 23, in <module>
    CONFIG_FILEPATH    = os.sep.join([HOME, ".cemu.ini"])

Random improvement idea list

New features for CEMU

To add (in no particular order):

  • Add string support (convert "ABCD" -> 0x41424344)
  • resizable window
  • add new column for Mappings tab to prefill the memory location with the content of a file
  • generate valid .s ASM file ready to compile
  • check support on windows
  • check support on osx
  • improve dependency installer
  • add a Python interpreter widget tab
  • change memory mapping layout to QTableWidget or grid layout

Requirement script doesn't run?

I was trying to test on MacOSX, upon running the requirements script, here's the output:

 ~/src/cemu   master ●  ./requirements.sh
[+] Install for OSX
[+] Using package manager ''
./requirements.sh: line 31: [: ==: unary operator expected
[+] Install for python3
usage: which [-as] program ...
[-] 'git' is missing, installing...
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...
usage: which [-as] program ...
[-] 'cmake' is missing, installing...
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...
usage: which [-as] program ...
[-] 'python3' is missing, installing...
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...
usage: which [-as] program ...
[-] 'pip3' is missing, installing...
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 file2
       install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
               [-o owner] file1 ... fileN directory
       install -d [-v] [-g group] [-m mode] [-o owner] directory ...

I do have brew:

`which brew`
/usr/local/bin/brew
`brew -v`
Homebrew 1.1.5
Homebrew/homebrew-core (git revision c984; last commit 2016-12-31)

Port CEMU to Python2

Got all the way to the end after much frustration with the PyQt5 dependency (without reading the source, of course!) and discovered that cemu requires Python 3. Would be nice if the readme stated that, so people who tend to use older versions of Python don't make the same mistake I did and build PyQt5 for Python2.7.

requirements.sh

There is a small bug in requirements.sh; after building and installing keystone sudo ldconfig needs to be run (at least on debian) I would submit a pull request, but that is a little tricky when you are on your phone 🤣

Missing required dependency 'unicorn'

So I have build and installed capstone/unicorn/keystone/pyqt/pygments/etc/etc/etc.
However I keep getting this issue, but the bindings are definitely installed

E:\Applications\cemu>python main.py
[-] Missing required dependency 'unicorn'

Unicorn

E:\Applications\cemu>pip install capstone
Requirement already satisfied (use --upgrade to upgrade): capstone in c:\python\lib\site-packages

E:\Applications\cemu>pip install keystone
Requirement already satisfied (use --upgrade to upgrade): keystone in c:\python\lib\site-packages

E:\Applications\cemu>easy_install unicorn
Searching for unicorn
Best match: unicorn 1.0
Processing unicorn-1.0-py3.5.egg
unicorn 1.0 is already the active version in easy-install.pth

Using c:\python\lib\site-packages\unicorn-1.0-py3.5.egg
Processing dependencies for unicorn
Finished processing dependencies for unicorn

E:\Applications\cemu>python main.py
[-] Missing required dependency 'unicorn'

Python35 x64 Windows 10 Pro

Improvement to the requirements.sh

Just for the project installation to work easier. It would be a good idea to add the installation of cmake and setupTools to the installation script.

sudo apt-get install cmake
sudo apt-get install python3-setuptools

Thanks
Rafael

Crash when click "Run all code"

os: macOS 10.12.4
python: 3.6.2
commit: f63c3f4

When I click run any arch code, it would crash.

➜  cemu git:(master) ✗ ./main.py
qt.qpa.cocoa.window: Window position outside any known screen, using primary screen
[1]  + 73543 terminated  ./main.py
[2]    73621 segmentation fault  ./main.py

OSX installation fails

Hi
I tried to install following your readme on OSX 10.14.3 with homebrew configured (I'm an iOS dev).
Command pip3 install -U cemu fails compiling unicorn (qemu missing pthread).

Building wheel for unicorn (setup.py) ... error
Complete output from command /usr/local/opt/python/bin/python3.7 -u -c "import setuptools, tokenize;file='/private/var/folders/_d/t7gfdbs16qdfzmzv7ry6q9fc0000gn/T/pip-install-_3nlbb5b/unicorn/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /private/var/folders/_d/t7gfdbs16qdfzmzv7ry6q9fc0000gn/T/pip-wheel-y1qsj0ve --python-tag cp37:
running bdist_wheel
running build
Building C extensions
cd qemu &&
./configure --cc="cc" --extra-cflags="-DUNICORN_HAS_X86 -DUNICORN_HAS_ARM -DUNICORN_HAS_ARMEB -DUNICORN_HAS_M68K -DUNICORN_HAS_ARM64 -DUNICORN_HAS_MIPS -DUNICORN_HAS_MIPSEL -DUNICORN_HAS_MIPS64 -DUNICORN_HAS_MIPS64EL -DUNICORN_HAS_SPARC -fPIC -fvisibility=hidden -m32 -arch i386 -m64 -arch x86_64" --target-list="x86_64-softmmu, arm-softmmu, armeb-softmmu, m68k-softmmu, aarch64-softmmu, mips-softmmu, mipsel-softmmu, mips64-softmmu, mips64el-softmmu, sparc-softmmu,sparc64-softmmu,"

ERROR: pthread check failed
Make sure to have the pthread libs and headers installed.

make: *** [qemu/config-host.h-timestamp] Error 1
error: [Errno 2] No such file or directory: 'libunicorn.dylib'


Failed building wheel for unicorn

requirements.sh quite buggy

diff --git a/requirements.sh b/requirements.sh
old mode 100644
new mode 100755
index 9f88d46..6c6056a
--- a/requirements.sh
+++ b/requirements.sh
@@ -6,14 +6,14 @@

 if [ "$(uname)" == "Darwin" ]; then
     echo "[+] Install for OSX"
-    PKG="$(which brew >/dev/null)"
+    PKG="$(which brew 2>/dev/null)"
 elif [ "$(uname)" == "Linux" ]; then
     echo "[+] Install for Linux"
-    PKG="$(which dnf >/dev/null)"
+    PKG="$(which dnf 2>/dev/null)"
     if [ $? -ne 0 ]; then
-        PKG="$(which yum >/dev/null)"
+        PKG="$(which yum 2>/dev/null)"
         if [ $? -ne 0 ]; then
-            PKG="$(which apt >/dev/null)"
+            PKG="$(which apt 2>/dev/null)"
             if [ $? -ne 0 ]; then
                 echo "[-] No valid package manager found"
                 exit 1
@@ -28,7 +28,7 @@ fi

 echo "[+] Using package manager '${PKG}'"

-if [ $1 == "--python2" ]; then
+if [ "$1" == "--python2" ]; then
     PYTHON=python2
     PIP=pip
     echo "[+] Install for python2"
@@ -41,7 +41,7 @@ fi
 # install build tools
 for req in git cmake ${PYTHON} ${PIP}
 do
-    dep="$(which $i)"
+    dep="$(which $req)"
     if [ $? -ne 0 ]; then
         echo "[-] '${req}' is missing, installing..."
         ${PKG} install ${req}
@@ -64,6 +64,7 @@ fi

 pushd .

+set +e
 # install keystone/capstone/unicorn
 ${PYTHON} -c 'import keystone' 2>/dev/null
 if [ $? -ne 0 ]; then

Error: cannot stop, cannot emulate instructions separately

Hi, I'm using cemu in Windows x64 with Python 2.7 x64, I cannot execute instructions one-by-one (separately) and after click "Next instruction", I see all instructions are executed and I cannot click "Stop".

QObject::connect: Cannot queue arguments of type 'QTextBlock'
(Make sure 'QTextBlock' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QTextCursor'
(Make sure 'QTextCursor' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QTextCursor'
(Make sure 'QTextCursor' is registered using qRegisterMetaType().)
Traceback (most recent call last):
File "D:\GitHub\cemu\cemu\core.py", line 511, in stopCode
self.emu.stop()
File "D:\GitHub\cemu\cemu\emulator.py", line 226, in stop
self.vm.mem_unmap(addr, size)
AttributeError: 'Uc' object has no attribute 'mem_unmap'

screenshot - 9_25_2016 8_28_10 pm

python-qt5 installation issue

Getting this when running requirements.sh on latest osx:
Collecting python-qt5
Downloading python-qt5-0.1.10.zip (57.5MB)
100% |████████████████████████████████| 57.5MB 24kB/s
No files/directories in /private/tmp/pip-build-It5nVa/python-qt5/pip-egg-info (from PKG-INFO)

any idea?

Compile help

Can we get some guidance on installing the deps? I've git pulled capstone, keystone, unicorn, and complied and installed all. I still get:

Traceback (most recent call last):
  File "main.py", line 18, in <module>
    from cemu.core import Cemu
  File "/home/jlay/build/cemu/cemu/core.py", line 9, in <module>
    import unicorn
ImportError: No module named unicorn

How do you get the python bindings?

Missing required dependency 'keystone'

I'm using Ubuntu 18.04.1 LTS. I installed cemu via pip3 install cemu:

Collecting cemu
[...] Downloading [...]
Building wheels for collected packages: cemu, capstone, keystone-engine
Running setup.py bdist_wheel for cemu ... done
Stored in directory: /home/user/.cache/pip/wheels/1d/61/92/73c06d1d4e50395016232fe2d1190d507e9e301f1aa5c0563a
Running setup.py bdist_wheel for capstone ... done
Stored in directory: /home/user/.cache/pip/wheels/6b/94/22/74a96ea9b9b5af3c506f45d5062aeac4ec5dae2ac1bfc59d9b
Running setup.py bdist_wheel for keystone-engine ... done
Stored in directory: /home/user/.cache/pip/wheels/e9/40/c1/6ac6e82d6aa880cd8d492d95e59be376eb77015683b94ee934
Successfully built cemu capstone keystone-engine
Installing collected packages: PyQt5-sip, PyQt5, Pygments, capstone, keystone-engine, unicorn, cemu
Successfully installed PyQt5-5.11.2 PyQt5-sip-4.19.12 Pygments-2.2.0 capstone-3.0.5 cemu-0.2.2 keystone-engine-0.9.1.post3 unicorn-1.0.1

(full log)

When I start cemu afterwards I get the following error:

[-] Missing required dependency 'keystone'

How can this be fixed?

Typo in requirements.sh

Line 59 has an extra quote which breaks on OSX... would submit a PR but it's not a major change.

if [ "${PKG}"" == "brew" ]; then

rep instructions cause compile error

base64 of raw program:

i30Ii9czwIPJ//Kug8EC99mKRQyL+vOqi8I=

which is originally:

8B 7D 08 mov edi, [ebp+8]
8B D7 mov edx, edi
33 C0 xor eax, eax
83 C9 FF or ecx, 0FFFFFFFFh
F2 AE repne scasb
83 C1 02 add ecx, 2
F7 D9 neg ecx
8A 45 0C mov al, [ebp+0Ch]
8B FA mov edi, edx
F3 AA rep stosb
8B C2 mov eax, edx

and disassembles in capstone as:

mov edi, dword ptr [ebp + 8]
mov edx, edi
xor eax, eax
or ecx, 0xffffffff
repne scasb al, byte ptr es:[edi]
add ecx, 2
neg ecx
mov al, byte ptr [ebp + 0xc]
mov edi, edx
rep stosb byte ptr es:[edi], al
mov eax, edx

But comes out as a byte array after being assembled in keystone code, cnt = ks.asm(original_code) as:

bytearray(b'\x8b}\x08\x89\xfa1\xc0\x83\xc9\xff\xf2\xae\x83\xc1\x02\xf7\xd9\x8aE\x0c\x89\xd7\xf3\xaa\x89\xd0') and a count of 14.

This causes self.num_insns != n and a compile error, though it was perfectly assembled by keystone.

Commenting out the rep/repne instructions reveals they are causing the imbalance in the number of instructions before and after.

I'm sure there are other instructions with the same issue, but fixing this problem will likely fix them also, and I would suppose there are deeper problems than just fixing the count, as instruction imbalances or repeating an instruction might cause issues with stepping.

Cannot run native ARM

I am trying cEMU with OSX Catalina. Emulating any ARM code causes the program to be unresponsive, and I have to force quit it. Afterward, even x86 code execution causes the GUI to freeze. I suspect it might be an issue with one of the libraries. Is it possible to do a try-catch and avoid the crash?

Cemu For 32Bit?

Look Guys Every time i go to install windows at a guy he installs it 32 bit even though i have a processor that supports 64bit

So If Anyone has 32 bit version of cemu pls put a link to it

Assembly Code Syntax Error[ARM Native mode]

When testing the following code[ARM Native mode], I got the error message after clicking the button "Check assembly code": Some errors were found in your code, check the logs...

bl funlabel
funlabel:
mov r0,pc
mov r1,lr

Log message: [logger] Error - Failed to compile: error at line 1
The test code is correct, so I don't know why CEMU displays the error message.

Crash because newer keystone.asm does not have `as_bytes` arg

Switching to 'ARM THUMB mode'                                                                                                                                                                                        
Traceback (most recent call last):                                                                                                                                                                                   
  File "/tmp/tmp.oUuaXwo2MV/lib/python3.8/site-packages/cemu/ui/codeeditor.py", line 80, in __update_assembly_code                                                                                                   
    code, cnt = assemble(asm, self.root.arch)                                                                                                                                                                        
  File "/tmp/tmp.oUuaXwo2MV/lib/python3.8/site-packages/cemu/utils.py", line 174, in assemble                                                                                                                        
    bytecode, cnt = ks.asm(asm_code, as_bytes=True)                                                                                                                                                                  
TypeError: asm() got an unexpected keyword argument 'as_bytes'                                                                                                                                                       
Segmentation fault

Installed versions: cemu - latest from the repo (rev 44427a8), keystone-engine==0.9.1.post3. Python version 3.8.0.

Also, when I removed as_bytes kwarg in cemu/utils.py, it crashed with the different error:

Switching to 'ARM THUMB mode'                                                                             
Traceback (most recent call last):                                                                        
  File "/tmp/cemu/cemu/ui/codeeditor.py", line 81, in __update_assembly_code                              
    if len(code) > len(old_code):                                                                         
TypeError: object of type 'NoneType' has no len()                                                         
Segmentation fault

Looks like Ks.asm returns None for bytecode if no instructions were generated. But our code expects empty bytes instead.

Get UC_ERR_WRITE_UNMAPPED when push registers into the stack.

OS: Windows 10
Target Architecture: ARM Native mode
Codes:
push {r0}
Logs:

Switching to 'ARM Native mode'
[logger] Setup - Map .text @40000 (size=4096,perm=READ|EXEC)
[logger] Setup - Map .data @60000 (size=4096,perm=READ|WRITE)
[logger] Setup - Map .stack @800000 (size=16384,perm=READ|WRITE)
[logger] Setup - Map .misc @900000 (size=4096,perm=ALL)
[logger] Compilation - Assembling 1 instructions for ARM Native mode:b'push {r0}'
[logger] Compilation - 1 instruction(s) compiled: 4 bytes
[logger] Setup - Register 'R0' = 0x0
[logger] Setup - Register 'R1' = 0x0
[logger] Setup - Register 'R2' = 0x0
[logger] Setup - Register 'R3' = 0x0
[logger] Setup - Register 'R4' = 0x0
[logger] Setup - Register 'R5' = 0x0
[logger] Setup - Register 'R6' = 0xffff0ff0
[logger] Setup - Register 'R7' = 0x400
[logger] Setup - Register 'R8' = 0x0
[logger] Setup - Register 'R9' = 0x0
[logger] Setup - Register 'R10' = 0x0
[logger] Setup - Register 'R12' = 0x0
[logger] Setup - Register 'FP' = 0x0
[logger] Setup - Register 'LR' = 0x0
[logger] Setup - Register 'CPSR' = 0x0
[logger] Setup - Register 'PC' = 0x0
[logger] Setup - Register 'SP' = 0x0
[logger] Setup - Mapping .text at 0x40000
[logger] Runtime - Executing instruction at 0x40000
[logger] Error - An error occured: Invalid memory write (UC_ERR_WRITE_UNMAPPED)

Aarch64: CBZ causes emulator exception

Hello,

I am testing a very small program for Aarch64 which is disassembled correctly in CEMU, as I've checked with two different disassemblers:

movz x0, #0
movz x1, #0x20
movz x2, #0x3a
movz x3, #0xa
cmp x2, x3
cset x3, lt
cbz x3, #0x4024
movz x4, #0xc8
adds x4, x2, x4
ret

Note that CBZ instruction has an offset of 0x4024, which is correct. I've left the text section at 0x4000, which is the default.

When running through the emulator, the DBZ causes an exception:

2020/09/13 - 23:09:52: Executing - 0x4018: cbz x3, #0x8024
2020/09/13 - 23:09:52: [logger] Error - An error occured: Fetch from non-executable memory (UC_ERR_FETCH_PROT)
2020/09/13 - 23:09:52: Exception - pc=0x8024 , sp=0x6000: Fetch from non-executable memory (UC_ERR_FETCH_PROT)
2020/09/13 - 23:09:52: Runtime - Ending emulation context

This is because it is trying to jump to 0x8024. While the issue may be in the emulator itself, it may just be a faulty configuration in CEMU where the emulator is not set to start at 0x4000. Typically Aarch64 loads the first instruction at 0x8000, so that might be the default setting of the emulator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.