diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7eb6322 --- /dev/null +++ b/.gitignore @@ -0,0 +1,256 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python,go,jetbrains+all +# Edit at https://www.toptal.com/developers/gitignore?templates=python,go,jetbrains+all + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### Go Patch ### +/vendor/ +/Godeps/ + +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.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/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### JetBrains+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 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +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 + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# profiling data +.prof + +# End of https://www.toptal.com/developers/gitignore/api/python,go,jetbrains+all + +/x1/*.bin diff --git a/README.md b/README.md index 913c3f2..6c154c2 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ - [read_keys.py](read_keys.py) Initialize the keyboard MCU and poll key code - [read_keys_SH3.py](read_keys_SH3.py) Scan key matrix and return key name(deprecated) - [read_keys_SH3.c](read_keys_SH3.c) Scan key matrix and return key name rewritten with C. nice performance + - [x1](x1) Executable to analyze `[JHSBA]1` gen + ### License diff --git a/x1/Makefile b/x1/Makefile new file mode 100644 index 0000000..1faf865 --- /dev/null +++ b/x1/Makefile @@ -0,0 +1,10 @@ +CROSS_COMPILE:=arm-linux-gnueabi- +AS:=$(CROSS_COMPILE)as + +.PHONY: +all: return.bin mrc.bin + +%.bin: %.S + @$(AS) $< + @./extract.py a.out $@ + @rm -f a.out diff --git a/x1/README.md b/x1/README.md new file mode 100644 index 0000000..5dbc408 --- /dev/null +++ b/x1/README.md @@ -0,0 +1,16 @@ +#### Code + - `mrc.S` Read SCTLR (MMU etc.) and return + - `return.S` Return immediately + - `extract.py` Extract .text + + +#### Build +```sh +pip3 install pyelftools +make all +``` + +#### Run + - Create a directory `/path/to/sd/APP/foo` + - Create index.din `touch /path/to/sd/APP/foo/index.din` + - Copy and rename the raw executable `cp foo.bin /path/to/sd/APP/foo/AppMain.bin` diff --git a/x1/extract.py b/x1/extract.py new file mode 100755 index 0000000..dc05a13 --- /dev/null +++ b/x1/extract.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import sys +from elftools.elf.elffile import ELFFile # pip install pyelftools + + +def main(): + if len(sys.argv) < 3: + print(f'Usage: {sys.argv[0]} in.elf out.bin') + sys.exit(1) + + with open(sys.argv[1], 'rb') as f: + extract(ELFFile(f)) + + +def extract(elf): + text = elf.get_section_by_name('.text') + if text is None: + print('Input ELF has no .text section', file=sys.stderr) + + with open(sys.argv[2], 'wb') as f: + f.write(text.data()) + + print(f'Successfully extracted the .text section to "{sys.argv[2]}"') + + +main() diff --git a/x1/mrc.S b/x1/mrc.S new file mode 100644 index 0000000..0126abc --- /dev/null +++ b/x1/mrc.S @@ -0,0 +1,7 @@ +.text + .align 2 + .global _start + +_start: + mrc p15, 0, r10, c1, c0, 0 + mov pc, lr diff --git a/x1/return.S b/x1/return.S new file mode 100644 index 0000000..e85e80c --- /dev/null +++ b/x1/return.S @@ -0,0 +1,6 @@ +.text + .align 2 + .global _start + +_start: + mov pc, lr