summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2024-01-05 22:59:05 +0300
committerOxore <oxore@protonmail.com>2024-01-05 22:59:05 +0300
commit6bc56335677514a1f508f1d83bdafbcc2f66c9f0 (patch)
tree2c3dbfd32a8db416fa7231274781c20bfc260285
Initial commit
-rw-r--r--.gitignore1
-rw-r--r--Makefile20
-rw-r--r--make.bat35
-rw-r--r--source/_static/.keep0
-rw-r--r--source/amberelec-internals.rst45
-rw-r--r--source/c-calling-conventions.rst22
-rw-r--r--source/conf.py54
-rw-r--r--source/index.rst14
-rw-r--r--source/radare2-tips.rst118
9 files changed, 309 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..567609b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+build/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d0c3cbf
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line, and also
+# from the environment for the first two.
+SPHINXOPTS ?=
+SPHINXBUILD ?= sphinx-build
+SOURCEDIR = source
+BUILDDIR = build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/make.bat b/make.bat
new file mode 100644
index 0000000..6fcf05b
--- /dev/null
+++ b/make.bat
@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=source
+set BUILDDIR=build
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.https://www.sphinx-doc.org/
+ exit /b 1
+)
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+
+:end
+popd
diff --git a/source/_static/.keep b/source/_static/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/_static/.keep
diff --git a/source/amberelec-internals.rst b/source/amberelec-internals.rst
new file mode 100644
index 0000000..5b742a0
--- /dev/null
+++ b/source/amberelec-internals.rst
@@ -0,0 +1,45 @@
+###################
+AmberELEC internals
+###################
+
+`AmberELEC`_ (former 351ELEC) is a fork of `EmuELEC`_, which is a fork of `CoreELEC`_, which is a fork of `LibreELEC`_, which is a fork of `OpenELEC`_). Knowing this inheritance scheme may help you find some lost knowledge and understand reasoning behind some decisions.
+
+.. _AmberELEC: https://github.com/AmberELEC/AmberELEC
+.. _EmuELEC: https://github.com/EmuELEC/EmuELEC
+.. _CoreELEC: https://github.com/CoreELEC/CoreELEC
+.. _LibreELEC: https://github.com/LibreELEC/LibreELEC.tv
+.. _OpenELEC: https://github.com/OpenELEC/OpenELEC.tv
+
+How the disk image file is constructed
+======================================
+
+The image is built by ``/scripts/mkimage`` script.
+
+The final image has size of 2097 MiB and consists of the following parts:
+
+* 16 MiB - A padding, purpose is unclear. It is defined by ``SYSTEM_PART_START`` variable, measured in sectors, 1 sector = 512 bytes. The ``SYSTEM_PART_START`` variable is defined in the ``/projects/Rockchip/options`` file.
+* 2 GiB - System storage partition, a FAT file system, containing the bootloader, the kernel, device tree blobs and the system - a squasfs file of rootfs.
+* 32 MiB - Games storage partition, an ext4 file system, to be expanded at first boot to fill out all available memory on the microSD card.
+* 1 MiB - Some GPT padding, purpose is unclear.
+
+Tools used in the script:
+
+* ``dd`` is used to create the disk image file.
+* ``parted`` is used to crate partitions on the file like if it was a disk.
+* ``sync`` is used to fully commit changes made to the file.
+* ``mformat`` is used to create boot sector, format the first partition in FAT system and create the root directory on the partition.
+* ``mcopy`` is used to copy files into the first partition's file system.
+* ``mmd`` is used to create directories inside the first partition's file system.
+* ``pigz`` is used to compress the image file
+
+Where the tools are coming from:
+
+* ``dd`` and ``sync`` are from ``/packages/tools/sysutils/coreutils`` package.
+* ``pigz`` is from ``/packages/compress/pigz`` package.
+* ``mformat``, ``mcopy`` and ``mmd`` are from ``/packages/tools/mtools`` package.
+* ``parted`` is from ``/packages/tools/sysutils/parted`` package.
+
+How the system is loaded
+========================
+
+The ``init`` script, that ends up in the ``initramfs`` CPIO image, is copied from ``/packages/sysutils/busybox/scripts/init`` file.
diff --git a/source/c-calling-conventions.rst b/source/c-calling-conventions.rst
new file mode 100644
index 0000000..06ae61e
--- /dev/null
+++ b/source/c-calling-conventions.rst
@@ -0,0 +1,22 @@
+C calling conventions
+=====================
+
+cdecl (Windows X86)
+-------------------
+
+Subroutine arguments are passed on the stack.
+
+Integer values and memory addresses are returned in the EAX register
+
+Registers EAX, ECX, and EDX are caller-saved, and the rest are callee-saved. [#wiki-call-conv]_
+
+Other
+-----
+
+GCC keeps stack aligned to 16 bytes because called function may be SSE2 instruction that requires alignment to 16 bytes. [#gcc-stack-alignment]_
+
+Footnotes
+---------
+
+.. [#wiki-call-conv] https://en.wikipedia.org/wiki/X86_calling_conventions
+.. [#gcc-stack-alignment] `StackOverflow: why does the compiler subtract value on ESP <https://stackoverflow.com/q/38128940>`_
diff --git a/source/conf.py b/source/conf.py
new file mode 100644
index 0000000..03ce8d5
--- /dev/null
+++ b/source/conf.py
@@ -0,0 +1,54 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# This file only contains a selection of the most common options. For a full
+# list see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+
+
+# -- Project information -----------------------------------------------------
+
+from datetime import datetime
+project = 'Notes'
+copyright = f'2022-{datetime.now().year}, Oxore'
+author = 'Oxore'
+html_title = project
+
+
+# -- General configuration ---------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = []
+
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'furo'
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
diff --git a/source/index.rst b/source/index.rst
new file mode 100644
index 0000000..eb4a715
--- /dev/null
+++ b/source/index.rst
@@ -0,0 +1,14 @@
+Notes
+=====
+
+Notes and tips kind of knowledge about various tools. Sometimes I need some of
+this knowledge when I'm not at my home desktop computer, want to have a
+convenient way to share with someone or I just want it all to be in one place -
+that's why this site exist.
+
+.. toctree::
+ :hidden:
+
+ amberelec-internals
+ radare2-tips
+ c-calling-conventions
diff --git a/source/radare2-tips.rst b/source/radare2-tips.rst
new file mode 100644
index 0000000..915e2b8
--- /dev/null
+++ b/source/radare2-tips.rst
@@ -0,0 +1,118 @@
+Radare2 tips
+============
+
+Data
+----
+
+``iz``, ``izz`` - list nil-terminated strings.
+
+``px <size> @<offset>`` - hexdump ``<size>`` bytes at ``<offset>``. If you want
+to use address from a register, you can refer to it as ``@reg``. [#px-for-registers]_
+
+Example usage:
+
+.. code-block::
+
+ :> px 4 @esp
+ - offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
+ 0xffd5df4c 7860 5656 x`VV
+ :> px 4 @esp+4
+ - offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
+ 0xffd5df50 0a00 0000 ....
+ :> px 4 @esp-4
+ - offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
+ 0xffd5df48 0090 5656 ..VV
+
+
+``wao <asm-instr>`` - Write Assembly Opcode, change the opcode of current instruction.
+
+``wao nocj`` - change opcode of conditional jump at the current offset to be nonconditional.
+
+``wai <instruction>`` - Write Assembly Instruction - literally write any full assembly instruction instead of current instruction, if it would fit, of course. If new instruction is shorter, then NOPs are added.
+
+``w 'string'``, ``w 'a'`` - overWrite inplace a string or a single letter.
+
+``wx FFAA00`` - overWrite sequence of heX tetrads. Spaces are ignored.
+
+``wx <hex-seq>`` - Overwrites high tetrad of byte to be ``F``, so, e.g. byte ``00`` becomes ``F0``.
+
+``wx FFF`` - Overwrites first byte and high tetrad of second byte to be ``F``, so, e.g. sequence ``12 34`` becomes ``FF F4``.
+
+``/ <string>`` - Search for a string. Note that space is mandatory.
+
+Functions
+---------
+
+``afl`` - list functions.
+
+``afx`` - show current function references.
+
+``afn`` - rename function.
+
+``axt`` - xrefs to.
+
+``axf`` - xrefs from.
+
+Press ``v`` in capital-V-mode to bring up the list of functions.
+
+``pdd`` - print decompiled code. Requires installing ``r2dec`` [#r2dec]_
+
+``afv-*``, ``afv-[name]`` - remove annoying variables and args aliases automatically declared at the beginning of the function.
+
+``afva`` - get variables and args aliases back.
+
+While reversing SMD (Sega MegaDrive ROM) there may be a crap ton of lables
+defined over first address (0x200) due to all addresses in IVT are set to 0x200.
+Here are some tips about this:
+
+- ``f sym.shit`` - define new shitty label (flag) you don't need. The ``sym.``
+ prefix is optional, it is just what r2 uses for creating the shit.
+
+- ``f- sym.*`` - remove all these shitty lables (flags) you don't need. These
+ without the ``sym.`` prefix are actually OK and are not irritating at all,
+ they are rather useful. Note: labels are removed globally, not only for
+ current address.
+
+While reversing ARM Cortex-M (thumb2) binaries, especially ELF binaries without
+symbols, the asm.bits is always 32 and running ``e asm.bits=16`` does not change
+anything. To fix this one must use ``ahb 16``:
+
+- ``ahb 16`` set bitness to 16 (useful for ARM thumb) [#asmbits16]_
+
+Project
+-------
+
+``Ps`` - save project.
+
+``$ r2 -p <projectname>`` - open a project from shell.
+
+Visual (capital-V-mode) and moving around
+-----------------------------------------
+
+Press ``C`` - rotate no color/terminal colorscheme/truecolor colorscheme.
+
+Press ``R`` - random truecolor coloscheme.
+
+Press ``v`` - bring up the list of functions.
+
+``ecd`` - set default truecolor coloscheme (reset colorscheme).
+
+Press ENTER to follow jump
+
+Press ``u``/``U`` - undo/redo seek or jump following.
+
+Confusing abbreviations and words
+-----------------------------------------
+
+``nbbs`` may stand for `number of basic blocks`. Found in ``aflj`` command
+output.
+
+``cc`` stands for `calling convention`. Found in ``aflj`` command output, may be
+set via ``e anal.cc``.
+
+Footnotes
+---------
+
+.. [#px-for-registers] `how to get value at an address with radare / stackoverflow.com <https://stackoverflow.com/a/54264998>`_
+.. [#r2dec] `How to install r2dec / stackoverflow.com <https://stackoverflow.com/a/51466052>`_
+.. [#asmbits16] `Cannot set asm.bits to 16 for arm arch #13019 / github.com <https://github.com/radareorg/radare2/issues/13019#issuecomment-461775283>`_