about summary refs log tree commit diff
path: root/frida_mode
diff options
context:
space:
mode:
Diffstat (limited to 'frida_mode')
-rw-r--r--frida_mode/DEBUGGING.md119
-rw-r--r--frida_mode/MapDensity.md82
-rw-r--r--frida_mode/README.md495
-rw-r--r--frida_mode/Scripting.md92
4 files changed, 422 insertions, 366 deletions
diff --git a/frida_mode/DEBUGGING.md b/frida_mode/DEBUGGING.md
index 69663510..9cdc5eb6 100644
--- a/frida_mode/DEBUGGING.md
+++ b/frida_mode/DEBUGGING.md
@@ -1,6 +1,8 @@
+# Debugging
+
 If you are using FRIDA mode and have hit some problems, then this guide may help
 you to diagnose any problems you are encountering. This assumes you have
-followed the [osx-lib](#test/osx-lib) example to start fuzzing your target.
+followed the [osx-lib](test/osx-lib) example to start fuzzing your target.
 
 It should be noted that attempting to debug code using gdb which has been
 instrumented in FRIDA is unlikely to be successful since the debugger will be
@@ -10,69 +12,76 @@ you are very familiar with the implementation of Stalker, the instrumented code
 generated by FRIDA is likely to be very difficult to follow. For this reason,
 the following debugging strategies are outlined below.
 
-By convention below all files should be provided with their path (they are
+By convention, all files below should be provided with their path (they are
 omitted for readability) and all items in `<braces>` are placeholders and should
 be replaced accordingly.
 
-# Select your version
+## Select your version
+
 Test with both the `dev` and `stable` branches of AFL++. The `dev` branch should
 have the very latest version containing any fixes for identified issues. The
 `stable` branch is updated less frequently, but equally might avoid a problem if
 a regression has been introduced into the `dev` branch.
 
-# Enable Diagnostic Information
-- Run your target specifying the `AFL_DEBUG_CHILD=1` environment variable. This
-  will print a lot more diagnostic information to the screen when the target
-  starts up. If you have a simple configuration issue then you will likely see a
-  warning or error message in the output.
+## Enable diagnostic information
+
+Run your target specifying the `AFL_DEBUG_CHILD=1` environment variable. This
+will print a lot more diagnostic information to the screen when the target
+starts up. If you have a simple configuration issue, then you will likely see a
+warning or error message in the output.
+
+## Check your test harness
 
-# Check your Test Harness
 If any of the following steps fail, then there is a problem with your test
-harness, or your target library. Since this is running without FRIDA mode or
+harness or your target library. Since this is running without FRIDA mode or
 `afl-fuzz` that greatly reduces the search area for your defect. This is why it
 is *VERY* important to carry out these basic steps first before taking on the
 additional complexity of debugging with FRIDA mode or `afl-fuzz`.
 
 - Run your harness outside of the fuzzer, passing it a representative seed as
   it's input `./harness <input>`.
-- Pass you harness multiple seeds to check that it is stable when running
+- Pass your harness multiple seeds to check that it is stable when running
   multiple tests as it will when running in fork server mode `./harness <input1>
   <intput2>`.
 - Build your test harness with `CFLAGS=-fsanitize=address` and
   `LDFLAGS=-fsanitize=address`. Then run it again with multiple inputs to check
-  for errors (note that when fuzzing your harness should not be built with any
+  for errors (note that when fuzzing, your harness should not be built with any
   sanitizer options).
 
-# Check the Samples
+## Check the samples
+
 FRIDA mode contains a number of different sample targets in the `test` folder.
-Have a look throught these and find one which is similar to your real target.
+Have a look through these and find one which is similar to your real target.
 Check whether you have any issues running the sample target and make sure you
-compare the command line used to launch the sample with that you are using to
-launch your real target very carefully to check for any differences. If possible
-start with one of these samples and gradually make changes one at a time
-re-testing as you go until you have migrated it to run your own target.
+compare the command line used to launch the sample with the one you are using to
+launch your real target very carefully to check for any differences. If
+possible, start with one of these samples and gradually make changes one at a
+time re-testing as you go until you have migrated it to run your own target.
 
-# FRIDA Mode
-## Basic
-First just try running your target with `LD_PRELOAD=afl-frida-trace.so ./harness
- <input>`. An error here means that your defect occurs when running with just
- FRIDA mode and isn't related to `afl-fuzz`.
+## FRIDA mode
+
+### Basic
+
+First, just try running your target with `LD_PRELOAD=afl-frida-trace.so
+ ./harness <input>`. An error here means that your defect occurs when running
+ with just FRIDA mode and isn't related to `afl-fuzz`.
 
 Now you can try commenting out the implementation of `LLVMFuzzerTestOneInput` so
 that the harness doesn't actually run your target library. This may also aid in
 narrowing down the problem.
+
 ```c
 int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size){
     // fpn_crashme(data, size);
     return 0;
 }
-
 ```
 
-## Persistent Mode
+### Persistent mode
+
 If your target is ok running in basic mode, you can try running it in persistent
 mode (if that is the configuration you are having issues with) as follows (again
-outside of afl-fuzz). This time you will want to run it inside a debugger so
+outside of `afl-fuzz`). This time, you will want to run it inside a debugger so
 that you can use the debugger to send the `SIGCONT` signals (by continuing)
 usually sent by `afl-fuzz` on each iteration.
 
@@ -84,13 +93,15 @@ gdb \
   --ex 'set environment AFL_FRIDA_PERSISTENT_ADDR=<entry_address>' \
   --args ./harness <input>
 ```
-Note we have to manually set the `__AFL_PERSISTENT` environment variable which
-is usually passed by `afl-fuzz`.
 
-Note that setting breakpoints etc is likely to interfere with FRIDA and cause
-spurious errors.
+Note:
+- We have to manually set the `__AFL_PERSISTENT` environment variable which is
+  usually passed by `afl-fuzz`.
+- Setting breakpoints etc. is likely to interfere with FRIDA and cause spurious
+  errors.
 
 If this is successful, you can try additionally loading the hook library:
+
 ```bash
 gdb \
   --ex 'set environment __AFL_PERSISTENT=1' \
@@ -100,6 +111,7 @@ gdb \
   --ex 'set environment AFL_FRIDA_PERSISTENT_HOOK=frida_hook.so'
   --args ./harness <input>
 ```
+
 Note that the format of the hook used for FRIDA mode is subtly different to that
 used when running in QEMU mode as shown below. Thus the DSO used for the hook is
 not interchangeable.
@@ -112,12 +124,14 @@ void afl_persistent_hook(struct x86_64_regs *regs, uint64_t guest_base,
                          uint8_t *input_buf, uint32_t input_buf_len);
 ```
 
-## ASAN
+### ASAN
+
 It is also possible to enable ASAN (if that is the configuration you are having
-issues with) without having to use `afl-fuzz`. This can be done as follows (note
-that the name of the asan DSO may need to be changed depending on your
-platform). Note that the asan DSO must appear first in the `LD_PRELOAD`
-environment variable:
+issues with) without having to use `afl-fuzz`. This can be done as follows:
+
+Note:
+- The name of the asan DSO may need to be changed depending on your platform.
+- The asan DSO must appear first in the `LD_PRELOAD` environment variable.
 
 ```bash
 LD_PRELOAD=libclang_rt.asan-x86_64.so:afl-frida-trace.so \
@@ -132,29 +146,34 @@ DSO from coverage. Failure to do so will result in ASAN attempting to sanitize
 itself and as a result detecting failures when it attempts to update the shadow
 maps.
 
-# Printf
+## Printf
+
 If you have an idea of where things are going wrong for you, then don't be
 scared to add `printf` statements to either AFL++ or FRIDA mode itself to show
 more diagnostic information. Just be sure to set `AFL_DEBUG=1` and
 `AFL_DEBUG_CHILD=1` when you are testing it.
 
-# Core Dumps
-Lastly, if your defect only occurs when using `afl-fuzz` (e.g. when using
-`CMPLOG` which cannot be tested outside of `afl-fuzz` due to it's need for a
+## Core dumps
+
+Lastly, if your defect only occurs when using `afl-fuzz` (e.g., when using
+`CMPLOG` which cannot be tested outside of `afl-fuzz` due to its need for a
 shared memory mapping being created for it to record its data), it is possible
 to enable the creation of a core dump for post-mortem analysis.
 
-Firstly check your `/proc/sys/kernel/core_pattern` configuration is simply set
-to a filename (AFL++ encourages you to set it to the value 'core' in any case
-since it doesn't want any handler applications getting in the way). Next set
-`ulimit -c unlimited` to remove any size limitations for core files. Lastly,
-when you `afl-fuzz` set the environment variable `AFL_DEBUG=1` to enable the
-creation of the `core` file. The file should be created in the working directory
-of the target application. If there is an existing `core` file aleady there,
-then it may not be overwritten.
+Firstly, check if your `/proc/sys/kernel/core_pattern` configuration is simply
+set to a filename (AFL++ encourages you to set it to the value `core` in any
+case since it doesn't want any handler applications getting in the way).
+
+Next, set `ulimit -c unlimited` to remove any size limitations for core files.
+
+Lastly, when you `afl-fuzz`, set the environment variable `AFL_DEBUG=1` to
+enable the creation of the `core` file. The file should be created in the
+working directory of the target application. If there is an existing `core` file
+already there, then it may not be overwritten.
+
+## Reach out
 
-# Reach out
 Get in touch on discord and ask for help. The groups are pretty active so
 someone may well be able to offer some advice. Better still, if you are able to
-create a minimal reproducer for your problem it will make it easier to diagnose
-the issue.
+create a minimal reproducer for your problem, it will make it easier to diagnose
+the issue.
\ No newline at end of file
diff --git a/frida_mode/MapDensity.md b/frida_mode/MapDensity.md
index f4ae3ace..b6a96ca0 100644
--- a/frida_mode/MapDensity.md
+++ b/frida_mode/MapDensity.md
@@ -1,8 +1,9 @@
-# Map Density
+# Map density
+
+## How coverage works
 
-# How Coverage Works
 The coverage in AFL++ works by assigning each basic block of code a unique ID
-and during execution when transitioning between blocks (e.g. by calls or jumps)
+and during execution when transitioning between blocks (e.g., by calls or jumps)
 assigning each of these edges an ID based upon the source and destination block
 ID.
 
@@ -13,11 +14,12 @@ A single dimensional cumulative byte array is also constructed where each byte
 again represents an individual edge ID, but this time, the value of the byte
 represents a range of how many times that edge has been traversed.
 
-```1, 2, 3, 4-7, 8-15, 16-31, 32-127, 128+```
+`1, 2, 3, 4-7, 8-15, 16-31, 32-127, 128+`
 
 The theory is that a new path isn't particularly interesting if an edge has been
 traversed `23` instead of `24` times for example, but is interesting if an edge
-has been traversed for the very first time, or the number of times fits within a different bucket.
+has been traversed for the very first time or the number of times fits within a
+different bucket.
 
 After each run, the count of times each edge is hit is compared to the values in
 the cumulative map and if it is different, then the input is kept as a new seed
@@ -27,19 +29,22 @@ This mechanism is described in greater detail in the seminal
 [paper](https://lcamtuf.coredump.cx/afl/technical_details.txt) on AFL by
 [lcamtuf](https://github.com/lcamtuf).
 
-# Collisions
+## Collisions
+
 In black-box fuzzing, we must assume that control may flow from any block to any
-other block, since we don't know any better. Thus for a target with `n` basic
+other block, since we don't know any better. Thus, for a target with `n` basic
 blocks of code, there are `n * n` potential edges. As we can see, even with a
 small number of edges, a very large map will be required so that we have space
 to fit them all. Even if our target only had `1024` blocks, this would require a
 map containing `1048576` entries (or 1Mb in size).
 
-Whilst this may not seem like a lot of memory, it causes problems for two reasons. Firstly, the processing step after each execution must now process much more
-data, and secondly a map this size is unlikely to fit within the L2 cache of the processor. Since this is a very hot code path, we are likely to pay a very heavy
-performance cost.
+Whilst this may not seem like a lot of memory, it causes problems for two
+reasons. Firstly, the processing step after each execution must now process much
+more data, and secondly, a map this size is unlikely to fit within the L2 cache
+of the processor. Since this is a very hot code path, we are likely to pay a
+very heavy performance cost.
 
-Therefore, we must accept that not all edges can have a unique and that
+Therefore, we must accept that not all edges can have a unique ID and that
 therefore there will be collisions. This means that if the fuzzer finds a new
 path by uncovering an edge which was not previously found, but that the same
 edge ID is used by another edge, then it may go completely unnoticed. This is
@@ -47,15 +52,15 @@ obviously undesirable, but equally if our map is too large, then we will not be
 able to process as many potential inputs in the same time and hence not uncover
 edges for that reason. Thus a careful trade-off of map size must be made.
 
-# Block & Edge Numbering
+## Block & edge numbering
+
 Since the original AFL, blocks and edges have always been numbered in the same
-way as we can see from the following C snippet from the whitepaper.
+way as we can see from the following C snippet from the whitepaper:
 
 ```c
-    cur_location = (block_address >> 4) ^ (block_address << 8);
-    shared_mem[cur_location ^ prev_location]++;
-    prev_location = cur_location >> 1;
-
+cur_location = (block_address >> 4) ^ (block_address << 8);
+shared_mem[cur_location ^ prev_location]++;
+prev_location = cur_location >> 1;
 ```
 
 Each block ID is generated by performing a shift and XOR on its address. Then
@@ -63,15 +68,16 @@ the edge ID is calculated as `E = B ^ (B' >> 1)`. Here, we can make two
 observations. In fact, the edge ID is also masked to ensure it is less than the
 size of the map being used.
 
-## Block IDs
+### Block IDs
+
 Firstly, the block ID doesn't have very good entropy. If we consider the address
 of the block, then whilst each block has a unique ID, it isn't necessarily very
 evenly distributed.
 
-We start with a large address, and need to discard a large number of the bits to
+We start with a large address and need to discard a large number of the bits to
 generate a block ID which is within range. But how do we choose the unique bits
-of the address verus those which are the same for every block? The high bits of
-the address may simply be all `0s` or all `1s` to make the address cannonical,
+of the address versus those which are the same for every block? The high bits of
+the address may simply be all `0s` or all `1s` to make the address canonical,
 the middle portion of the address may be the same for all blocks (since if they
 are all within the same binary, then they will all be adjacent in memory), and
 on some systems, even the low bits may have poor entropy as some use fixed
@@ -79,20 +85,22 @@ length aligned instructions. Then we need to consider that a portion of each
 binary may contain the `.data` or `.bss` sections and so may not contain any
 blocks of code at all.
 
-## Edge IDs
+### Edge IDs
+
 Secondly, we can observe that when we generate an edge ID from the source and
 destination block IDs, we perform a right shift on the source block ID. Whilst
 there are good reasons as set out in the whitepaper why such a transform is
-applied, in so doing, we dispose of `1` bit of precious entropy in our source
+applied, in doing so, we dispose of `1` bit of precious entropy in our source
 block ID.
 
 All together, this means that some edge IDs may be more popular than others.
-This means that some portions of the map may be very densly populated with large
-numbers of edges, whilst others may be very sparsely populated, or not populated
-at all.
+This means that some portions of the map may be very densely populated with
+large numbers of edges, whilst others may be very sparsely populated, or not
+populated at all.
+
+## Improvements
 
-# Improvements
-One of the main reaons why this algorithm selected, is performance. All of the
+One of the main reasons why this algorithm selected, is performance. All of the
 operations are very quick to perform and given we may be carrying this out for
 every block of code we execute, performance is critical.
 
@@ -106,23 +114,25 @@ only need to generate this ID once per block and so this ID generation no longer
 needs to be as performant. We can therefore use a hash algorithm to generate
 this ID and therefore ensure that the block IDs are more evenly distributed.
 
-Edge IDs however, can only be determined at run-time. Since we don't know which
+Edge IDs, however, can only be determined at run-time. Since we don't know which
 blocks a given input will traverse until we run it. However, given our block IDs
 are now evenly distributed, generating an evenly distributed edge ID becomes
-simple. Here, the only change we make is to use a rotate operation rather than
-a shift operation so we don't lose a bit of entropy from the source ID.
+simple. Here, the only change we make is to use a rotate operation rather than a
+shift operation so we don't lose a bit of entropy from the source ID.
 
 So our new algorithm becomes:
+
 ```c
-    cur_location = hash(block_address)
-    shared_mem[cur_location ^ prev_location]++;
-    prev_location = rotate(cur_location, 1);
+cur_location = hash(block_address)
+shared_mem[cur_location ^ prev_location]++;
+prev_location = rotate(cur_location, 1);
 ```
 
 Lastly, in the original design, the `cur_location` was always set to `0`, at the
 beginning of a run, we instead set the value of `cur_location` to `hash(0)`.
 
-# Parallel Fuzzing
+## Parallel fuzzing
+
 Another sub-optimal aspect of the original design is that no matter how many
 instances of the fuzzer you ran in parallel, each instance numbered each block
 and so each edge with the same ID. Each instance would therefore find the same
@@ -144,4 +154,4 @@ If only a single new edge is found, and the new path is shared with an instance
 for which that edge collides, that instance may disregard it as irrelevant. In
 practice, however, the discovery of a single new edge, likely leads to several
 more edges beneath it also being found and therefore the likelihood of all of
-these being collisions is very slim.
+these being collisions is very slim.
\ No newline at end of file
diff --git a/frida_mode/README.md b/frida_mode/README.md
index 6c46fe08..c19280e1 100644
--- a/frida_mode/README.md
+++ b/frida_mode/README.md
@@ -1,38 +1,34 @@
-# FRIDA MODE
+# FRIDA mode
 
 The purpose of FRIDA mode is to provide an alternative binary only fuzzer for
-AFL just like that provided by QEMU mode. The intention is to provide a very
+AFL++ just like that provided by QEMU mode. The intention is to provide a very
 similar user experience, right down to the options provided through environment
 variables.
 
-Whilst AFLplusplus already has some support for running on FRIDA [here](https://github.com/AFLplusplus/AFLplusplus/tree/stable/utils/afl_frida)
-this requires the code to be fuzzed to be provided as a shared library, it
-cannot be used to fuzz executables. Additionally, it requires the user to write
-a small harness around their target code of interest.
-FRIDA mode instead takes a different approach to avoid these limitations.
-In Frida mode binary programs are instrumented, similarly to QEMU mode.
+In FRIDA mode, binary programs are instrumented, similarly to QEMU mode.
 
-## Current Progress
+## Current progress
 
-As FRIDA mode is new, it is missing a lot of features. The design is such that it
-should be possible to add these features in a similar manner to QEMU mode and
+As FRIDA mode is new, it is missing a lot of features. The design is such that
+it should be possible to add these features in a similar manner to QEMU mode and
 perhaps leverage some of its design and implementation.
 
-  | Feature/Instrumentation  | frida-mode | Notes                                        |
-  | -------------------------|:----------:|:--------------------------------------------:|
-  | NeverZero                |     x      |                                              |
-  | Persistent Mode          |     x      | (x86/x64/aarch64 only)                       |
-  | LAF-Intel / CompCov      |     -      | (CMPLOG is better 90% of the time)           |
-  | CMPLOG                   |     x      | (x86/x64/aarch64 only)                       |
-  | Selective Instrumentation|     x      |                                              |
-  | Non-Colliding Coverage   |     -      | (Not possible in binary-only instrumentation |
-  | Ngram prev_loc Coverage  |     -      |                                              |
-  | Context Coverage         |     -      |                                              |
-  | Auto Dictionary          |     -      |                                              |
-  | Snapshot LKM Support     |     -      |                                              |
-  | In-Memory Test Cases     |     x      | (x86/x64/aarch64 only)                       |
+| Feature/Instrumentation  | FRIDA mode | Notes                                         |
+| -------------------------|:----------:|:---------------------------------------------:|
+| NeverZero                |     x      |                                               |
+| Persistent Mode          |     x      | (x86/x64/aarch64 only)                        |
+| LAF-Intel / CompCov      |     -      | (CMPLOG is better 90% of the time)            |
+| CMPLOG                   |     x      | (x86/x64/aarch64 only)                        |
+| Selective Instrumentation|     x      |                                               |
+| Non-Colliding Coverage   |     -      | (not possible in binary-only instrumentation) |
+| Ngram prev_loc Coverage  |     -      |                                               |
+| Context Coverage         |     -      |                                               |
+| Auto Dictionary          |     -      |                                               |
+| Snapshot LKM Support     |     -      |                                               |
+| In-Memory Test Cases     |     x      | (x86/x64/aarch64 only)                        |
 
 ## Compatibility
+
 Currently FRIDA mode supports Linux and macOS targets on both x86/x64
 architecture and aarch64. Later releases may add support for aarch32 and Windows
 targets as well as embedded linux environments.
@@ -41,60 +37,58 @@ FRIDA has been used on various embedded targets using both uClibc and musl C
 runtime libraries, so porting should be possible. However, the current build
 system does not support cross compilation.
 
-## Getting Started
+## Getting started
 
-To build everything run `make`. To build for x86 run `make 32`. Note that in
+To build everything, run `make`. To build for x86, run `make 32`. Note that in
 x86 bit mode, it is not necessary for afl-fuzz to be built for 32-bit. However,
-the shared library for frida_mode must be since it is injected into the target
+the shared library for FRIDA mode must be since it is injected into the target
 process.
 
 Various tests can be found in subfolders within the `test/` directory. To use
-these, first run `make` to build any dependencies. Then run `make qemu` or
-`make frida` to run on either QEMU of FRIDA mode respectively. To run frida
-tests in 32-bit mode, run `make ARCH=x86 frida`. When switching between
-architectures it may be necessary to run `make clean` first for a given build
-target to remove previously generated binaries for a different architecture.
+these, first run `make` to build any dependencies. Then run `make qemu` or `make
+frida` to run on either QEMU of FRIDA mode respectively. To run frida tests in
+32-bit mode, run `make ARCH=x86 frida`. When switching between architectures, it
+may be necessary to run `make clean` first for a given build target to remove
+previously generated binaries for a different architecture.
 
 ### Android
 
-In order to build, you need to download the Android SDK.
+In order to build, you need to download the Android SDK:
 
-```
-https://developer.android.com/ndk/downloads
-```
+[https://developer.android.com/ndk/downloads](https://developer.android.com/ndk/downloads)
 
-Then creating locally a standalone chain as follow.
+Then creating locally a standalone chain as follows:
 
-```
-https://developer.android.com/ndk/guides/standalone_toolchain
-```
+[https://developer.android.com/ndk/guides/standalone_toolchain](https://developer.android.com/ndk/guides/standalone_toolchain)
 
 ## Usage
 
-FRIDA mode added some small modifications to `afl-fuzz` and similar tools
-in AFLplusplus. The intention was that it behaves identically to QEMU, but it uses
-the 'O' switch rather than 'Q'. Whilst the options 'f', 'F', 's' or 'S' may have
+FRIDA mode added some small modifications to `afl-fuzz` and similar tools in
+AFL++. The intention was that it behaves identically to QEMU, but it uses the
+'O' switch rather than 'Q'. Whilst the options 'f', 'F', 's' or 'S' may have
 made more sense for a mode powered by FRIDA Stalker, they were all taken, so
-instead we use 'O' in hommage to the [author](https://github.com/oleavr) of
+instead we use 'O' in homage to the [author](https://github.com/oleavr) of
 FRIDA.
 
 Similarly, the intention is to mimic the use of environment variables used by
-QEMU where possible (by replacing `s/QEMU/FRIDA/g`). Accordingly, the
-following options are currently supported:
+QEMU where possible (by replacing `s/QEMU/FRIDA/g`). Accordingly, the following
+options are currently supported:
 
-* `AFL_FRIDA_DEBUG_MAPS` - See `AFL_QEMU_DEBUG_MAPS`
-* `AFL_FRIDA_EXCLUDE_RANGES` - See `AFL_QEMU_EXCLUDE_RANGES`
-* `AFL_FRIDA_INST_RANGES` - See `AFL_QEMU_INST_RANGES`
-* `AFL_FRIDA_PERSISTENT_ADDR` - See `AFL_QEMU_PERSISTENT_ADDR`
-* `AFL_FRIDA_PERSISTENT_CNT` - See `AFL_QEMU_PERSISTENT_CNT`
-* `AFL_FRIDA_PERSISTENT_HOOK` - See `AFL_QEMU_PERSISTENT_HOOK`
-* `AFL_FRIDA_PERSISTENT_RET` - See `AFL_QEMU_PERSISTENT_RET`
+* `AFL_FRIDA_DEBUG_MAPS` - See `AFL_QEMU_DEBUG_MAPS`.
+* `AFL_FRIDA_EXCLUDE_RANGES` - See `AFL_QEMU_EXCLUDE_RANGES`.
+* `AFL_FRIDA_INST_RANGES` - See `AFL_QEMU_INST_RANGES`.
+* `AFL_FRIDA_PERSISTENT_ADDR` - See `AFL_QEMU_PERSISTENT_ADDR`.
+* `AFL_FRIDA_PERSISTENT_CNT` - See `AFL_QEMU_PERSISTENT_CNT`.
+* `AFL_FRIDA_PERSISTENT_HOOK` - See `AFL_QEMU_PERSISTENT_HOOK`.
+* `AFL_FRIDA_PERSISTENT_RET` - See `AFL_QEMU_PERSISTENT_RET`.
 
 To enable the powerful CMPLOG mechanism, set `-c 0` for `afl-fuzz`.
 
 ## Scripting
 
-One of the more powerful features of FRIDA mode is it's support for configuration by JavaScript, rather than using environment variables. For details of how this works see [here](Scripting.md).
+One of the more powerful features of FRIDA mode is it's support for
+configuration by JavaScript, rather than using environment variables. For
+details of how this works, see [Scripting.md](Scripting.md).
 
 ## Performance
 
@@ -118,7 +112,8 @@ FRIDA mode is supported by using `LD_PRELOAD` (`DYLD_INSERT_LIBRARIES` on macOS)
 to inject a shared library (`afl-frida-trace.so`) into the target. This shared
 library is built using the [frida-gum](https://github.com/frida/frida-gum)
 devkit from the [FRIDA](https://github.com/frida/frida) project. One of the
-components of frida-gum is [Stalker](https://medium.com/@oleavr/anatomy-of-a-code-tracer-b081aadb0df8),
+components of frida-gum is
+[Stalker](https://medium.com/@oleavr/anatomy-of-a-code-tracer-b081aadb0df8),
 this allows the dynamic instrumentation of running code for AARCH32, AARCH64,
 x86 and x64 architectures. Implementation details can be found
 [here](https://frida.re/docs/stalker/).
@@ -127,7 +122,8 @@ Dynamic instrumentation is used to augment the target application with similar
 coverage information to that inserted by `afl-gcc` or `afl-clang`. The shared
 library is also linked to the `compiler-rt` component of AFLplusplus to feedback
 this coverage information to AFL++ and also provide a fork server. It also makes
-use of the FRIDA [prefetch](https://github.com/frida/frida-gum/blob/56dd9ba3ee9a5511b4b0c629394bf122775f1ab7/gum/gumstalker.h#L115)
+use of the FRIDA
+[prefetch](https://github.com/frida/frida-gum/blob/56dd9ba3ee9a5511b4b0c629394bf122775f1ab7/gum/gumstalker.h#L115)
 support to feedback instrumented blocks from the child to the parent using a
 shared memory region to avoid the need to regenerate instrumented blocks on each
 fork.
@@ -146,228 +142,237 @@ instances run CMPLOG mode and instrumentation of the binary is less frequent
 
 ## Advanced configuration options
 * `AFL_FRIDA_DRIVER_NO_HOOK` - See `AFL_QEMU_DRIVER_NO_HOOK`. When using the
-QEMU driver to provide a `main` loop for a user provided
-`LLVMFuzzerTestOneInput`, this option configures the driver to read input from
-`stdin` rather than using in-memory test cases.
-* `AFL_FRIDA_INST_COVERAGE_FILE` - File to write DynamoRio format coverage
-information (e.g. to be loaded within IDA lighthouse).
+  QEMU driver to provide a `main` loop for a user provided
+  `LLVMFuzzerTestOneInput`, this option configures the driver to read input from
+  `stdin` rather than using in-memory test cases.
+* `AFL_FRIDA_INST_COVERAGE_FILE` - File to write DynamoRIO format coverage
+  information (e.g., to be loaded within IDA lighthouse).
 * `AFL_FRIDA_INST_DEBUG_FILE` - File to write raw assembly of original blocks
-and their instrumented counterparts during block compilation.
-```
-***
-
-Creating block for 0x7ffff7953313:
-        0x7ffff7953313  mov qword ptr [rax], 0
-        0x7ffff795331a  add rsp, 8
-        0x7ffff795331e  ret
-
-Generated block 0x7ffff75e98e2
-        0x7ffff75e98e2  mov qword ptr [rax], 0
-        0x7ffff75e98e9  add rsp, 8
-        0x7ffff75e98ed  lea rsp, [rsp - 0x80]
-        0x7ffff75e98f5  push rcx
-        0x7ffff75e98f6  movabs rcx, 0x7ffff795331e
-        0x7ffff75e9900  jmp 0x7ffff75e9384
-
-
-***
-```
+  and their instrumented counterparts during block compilation.
+
+  ```
+  ***
+
+  Creating block for 0x7ffff7953313:
+          0x7ffff7953313  mov qword ptr [rax], 0
+          0x7ffff795331a  add rsp, 8
+          0x7ffff795331e  ret
+
+  Generated block 0x7ffff75e98e2
+          0x7ffff75e98e2  mov qword ptr [rax], 0
+          0x7ffff75e98e9  add rsp, 8
+          0x7ffff75e98ed  lea rsp, [rsp - 0x80]
+          0x7ffff75e98f5  push rcx
+          0x7ffff75e98f6  movabs rcx, 0x7ffff795331e
+          0x7ffff75e9900  jmp 0x7ffff75e9384
+
+  ***
+  ```
+
 * `AFL_FRIDA_INST_JIT` - Enable the instrumentation of Just-In-Time compiled
-code. Code is considered to be JIT if the executable segment is not backed by a
-file.
+  code. Code is considered to be JIT if the executable segment is not backed by
+  a file.
 * `AFL_FRIDA_INST_NO_OPTIMIZE` - Don't use optimized inline assembly coverage
-instrumentation (the default where available). Required to use
-`AFL_FRIDA_INST_TRACE`.
+  instrumentation (the default where available). Required to use
+  `AFL_FRIDA_INST_TRACE`.
 * `AFL_FRIDA_INST_NO_BACKPATCH` - Disable backpatching. At the end of executing
-each block, control will return to FRIDA to identify the next block to execute.
-* `AFL_FRIDA_INST_NO_PREFETCH` - Disable prefetching. By default the child will
-report instrumented blocks back to the parent so that it can also instrument
-them and they be inherited by the next child on fork, implies
-`AFL_FRIDA_INST_NO_PREFETCH_BACKPATCH`.
+  each block, control will return to FRIDA to identify the next block to
+  execute.
+* `AFL_FRIDA_INST_NO_PREFETCH` - Disable prefetching. By default, the child will
+  report instrumented blocks back to the parent so that it can also instrument
+  them and they be inherited by the next child on fork, implies
+  `AFL_FRIDA_INST_NO_PREFETCH_BACKPATCH`.
 * `AFL_FRIDA_INST_NO_PREFETCH_BACKPATCH` - Disable prefetching of stalker
-backpatching information. By default the child will report applied backpatches
-to the parent so that they can be applied and then be inherited by the next
-child on fork.
+  backpatching information. By default, the child will report applied
+  backpatches to the parent so that they can be applied and then be inherited by
+  the next child on fork.
 * `AFL_FRIDA_INST_SEED` - Sets the initial seed for the hash function used to
-generate block (and hence edge) IDs. Setting this to a constant value may be
-useful for debugging purposes, e.g. investigating unstable edges.
-* `AFL_FRIDA_INST_TRACE` - Log to stdout the address of executed blocks,
-implies `AFL_FRIDA_INST_NO_OPTIMIZE`.
+  generate block (and hence edge) IDs. Setting this to a constant value may be
+  useful for debugging purposes, e.g., investigating unstable edges.
+* `AFL_FRIDA_INST_TRACE` - Log to stdout the address of executed blocks, implies
+  `AFL_FRIDA_INST_NO_OPTIMIZE`.
 * `AFL_FRIDA_INST_TRACE_UNIQUE` - As per `AFL_FRIDA_INST_TRACE`, but each edge
-is logged only once, requires `AFL_FRIDA_INST_NO_OPTIMIZE`.
-* `AFL_FRIDA_INST_UNSTABLE_COVERAGE_FILE` - File to write DynamoRio format
-coverage information for unstable edges (e.g. to be loaded within IDA
-lighthouse).
+  is logged only once, requires `AFL_FRIDA_INST_NO_OPTIMIZE`.
+* `AFL_FRIDA_INST_UNSTABLE_COVERAGE_FILE` - File to write DynamoRIO format
+  coverage information for unstable edges (e.g., to be loaded within IDA
+  lighthouse).
 * `AFL_FRIDA_JS_SCRIPT` - Set the script to be loaded by the FRIDA scripting
-engine. See [here](Scripting.md) for details.
+  engine. See [Scipting.md](Scripting.md) for details.
 * `AFL_FRIDA_OUTPUT_STDOUT` - Redirect the standard output of the target
-application to the named file (supersedes the setting of `AFL_DEBUG_CHILD`)
+  application to the named file (supersedes the setting of `AFL_DEBUG_CHILD`).
 * `AFL_FRIDA_OUTPUT_STDERR` - Redirect the standard error of the target
-application to the named file (supersedes the setting of `AFL_DEBUG_CHILD`)
+  application to the named file (supersedes the setting of `AFL_DEBUG_CHILD`).
 * `AFL_FRIDA_PERSISTENT_DEBUG` - Insert a Breakpoint into the instrumented code
-at `AFL_FRIDA_PERSISTENT_HOOK` and `AFL_FRIDA_PERSISTENT_RET` to allow the user
-to detect issues in the persistent loop using a debugger.
-
-```
+  at `AFL_FRIDA_PERSISTENT_HOOK` and `AFL_FRIDA_PERSISTENT_RET` to allow the
+  user to detect issues in the persistent loop using a debugger.
+
+  ```
+  gdb \
+      --ex 'set environment AFL_FRIDA_PERSISTENT_ADDR=XXXXXXXXXX' \
+      --ex 'set environment AFL_FRIDA_PERSISTENT_RET=XXXXXXXXXX' \
+      --ex 'set environment AFL_FRIDA_PERSISTENT_DEBUG=1' \
+      --ex 'set environment AFL_DEBUG_CHILD=1' \
+      --ex 'set environment LD_PRELOAD=afl-frida-trace.so' \
+      --args <my-executable> [my arguments]
+  ```
 
-gdb \
-		--ex 'set environment AFL_FRIDA_PERSISTENT_ADDR=XXXXXXXXXX' \
-		--ex 'set environment AFL_FRIDA_PERSISTENT_RET=XXXXXXXXXX' \
-		--ex 'set environment AFL_FRIDA_PERSISTENT_DEBUG=1' \
-		--ex 'set environment AFL_DEBUG_CHILD=1' \
-		--ex 'set environment LD_PRELOAD=afl-frida-trace.so' \
-		--args <my-executable> [my arguments]
-
-```
 * `AFL_FRIDA_SECCOMP_FILE` - Write a log of any syscalls made by the target to
-the specified file.
+  the specified file.
 * `AFL_FRIDA_STALKER_ADJACENT_BLOCKS` - Configure the number of adjacent blocks
- to fetch when generating instrumented code. By fetching blocks in the same
- order they appear in the original program, rather than the order of execution
- should help reduce locallity and adjacency. This includes allowing us to vector
- between adjancent blocks using a NOP slide rather than an immediate branch.
+  to fetch when generating instrumented code. By fetching blocks in the same
+  order they appear in the original program, rather than the order of execution
+  should help reduce locality and adjacency. This includes allowing us to vector
+  between adjacent blocks using a NOP slide rather than an immediate branch.
 * `AFL_FRIDA_STALKER_IC_ENTRIES` - Configure the number of inline cache entries
-stored along-side branch instructions which provide a cache to avoid having to
-call back into FRIDA to find the next block. Default is 32.
+  stored along-side branch instructions which provide a cache to avoid having to
+  call back into FRIDA to find the next block. Default is 32.
 * `AFL_FRIDA_STATS_FILE` - Write statistics information about the code being
-instrumented to the given file name. The statistics are written only for the
-child process when new block is instrumented (when the
-`AFL_FRIDA_STATS_INTERVAL` has expired). Note that simply because a new path is
-found does not mean a new block needs to be compiled. It could simply be that
-the existing blocks instrumented have been executed in a different order.
-```
-stats
------
-Time                  2021-07-21 11:45:49
-Elapsed                                 1 seconds
-
-
-Transitions                    cumulative               delta
------------                    ----------               -----
-total                              753619               17645
-call_imm                             9193 ( 1.22%)        344 ( 1.95%) [       344/s]
-call_reg                                0 ( 0.00%)          0 ( 0.00%) [         0/s]
-call_mem                                0 ( 0.00%)          0 ( 0.00%) [         0/s]
-ret_slow_path                       67974 ( 9.02%)       2988 (16.93%) [      2988/s]
-post_call_invoke                     7996 ( 1.06%)        299 ( 1.69%) [       299/s]
-excluded_call_imm                    3804 ( 0.50%)        200 ( 1.13%) [       200/s]
-jmp_imm                              5445 ( 0.72%)        255 ( 1.45%) [       255/s]
-jmp_reg                             42081 ( 5.58%)       1021 ( 5.79%) [      1021/s]
-jmp_mem                            578092 (76.71%)      10956 (62.09%) [     10956/s]
-jmp_cond_imm                        38951 ( 5.17%)       1579 ( 8.95%) [      1579/s]
-jmp_cond_mem                            0 ( 0.00%)          0 ( 0.00%) [         0/s]
-jmp_cond_reg                            0 ( 0.00%)          0 ( 0.00%) [         0/s]
-jmp_cond_jcxz                           0 ( 0.00%)          0 ( 0.00%) [         0/s]
-jmp_continuation                       84 ( 0.01%)          3 ( 0.02%) [         3/s]
-
-
-Instrumentation
----------------
-Instructions                         7907
-Blocks                               1764
-Avg Instructions / Block                4
-
-
-EOB Instructions
-----------------
-Total                                1763 (22.30%)
-Call Immediates                       358 ( 4.53%)
-Call Immediates Excluded               74 ( 0.94%)
-Call Register                           0 ( 0.00%)
-Call Memory                             0 ( 0.00%)
-Jump Immediates                       176 ( 2.23%)
-Jump Register                           8 ( 0.10%)
-Jump Memory                            10 ( 0.13%)
-Conditional Jump Immediates          1051 (13.29%)
-Conditional Jump CX Immediate           0 ( 0.00%)
-Conditional Jump Register               0 ( 0.00%)
-Conditional Jump Memory                 0 ( 0.00%)
-Returns                               160 ( 2.02%)
-
-
-Relocated Instructions
-----------------------
-Total                                 232 ( 2.93%)
-addsd                                   2 ( 0.86%)
-cmp                                    46 (19.83%)
-comisd                                  2 ( 0.86%)
-divsd                                   2 ( 0.86%)
-divss                                   2 ( 0.86%)
-lea                                   142 (61.21%)
-mov                                    32 (13.79%)
-movsd                                   2 ( 0.86%)
-ucomisd                                 2 ( 0.86%)
-```
+  instrumented to the given file name. The statistics are written only for the
+  child process when new block is instrumented (when the
+  `AFL_FRIDA_STATS_INTERVAL` has expired). Note that simply because a new path
+  is found does not mean a new block needs to be compiled. It could simply be
+  that the existing blocks instrumented have been executed in a different order.
+
+  ```
+  stats
+  -----
+  Time                  2021-07-21 11:45:49
+  Elapsed                                 1 seconds
+
+
+  Transitions                    cumulative               delta
+  -----------                    ----------               -----
+  total                              753619               17645
+  call_imm                             9193 ( 1.22%)        344 ( 1.95%) [       344/s]
+  call_reg                                0 ( 0.00%)          0 ( 0.00%) [         0/s]
+  call_mem                                0 ( 0.00%)          0 ( 0.00%) [         0/s]
+  ret_slow_path                       67974 ( 9.02%)       2988 (16.93%) [      2988/s]
+  post_call_invoke                     7996 ( 1.06%)        299 ( 1.69%) [       299/s]
+  excluded_call_imm                    3804 ( 0.50%)        200 ( 1.13%) [       200/s]
+  jmp_imm                              5445 ( 0.72%)        255 ( 1.45%) [       255/s]
+  jmp_reg                             42081 ( 5.58%)       1021 ( 5.79%) [      1021/s]
+  jmp_mem                            578092 (76.71%)      10956 (62.09%) [     10956/s]
+  jmp_cond_imm                        38951 ( 5.17%)       1579 ( 8.95%) [      1579/s]
+  jmp_cond_mem                            0 ( 0.00%)          0 ( 0.00%) [         0/s]
+  jmp_cond_reg                            0 ( 0.00%)          0 ( 0.00%) [         0/s]
+  jmp_cond_jcxz                           0 ( 0.00%)          0 ( 0.00%) [         0/s]
+  jmp_continuation                       84 ( 0.01%)          3 ( 0.02%) [         3/s]
+
+
+  Instrumentation
+  ---------------
+  Instructions                         7907
+  Blocks                               1764
+  Avg Instructions / Block                4
+
+
+  EOB Instructions
+  ----------------
+  Total                                1763 (22.30%)
+  Call Immediates                       358 ( 4.53%)
+  Call Immediates Excluded               74 ( 0.94%)
+  Call Register                           0 ( 0.00%)
+  Call Memory                             0 ( 0.00%)
+  Jump Immediates                       176 ( 2.23%)
+  Jump Register                           8 ( 0.10%)
+  Jump Memory                            10 ( 0.13%)
+  Conditional Jump Immediates          1051 (13.29%)
+  Conditional Jump CX Immediate           0 ( 0.00%)
+  Conditional Jump Register               0 ( 0.00%)
+  Conditional Jump Memory                 0 ( 0.00%)
+  Returns                               160 ( 2.02%)
+
+
+  Relocated Instructions
+  ----------------------
+  Total                                 232 ( 2.93%)
+  addsd                                   2 ( 0.86%)
+  cmp                                    46 (19.83%)
+  comisd                                  2 ( 0.86%)
+  divsd                                   2 ( 0.86%)
+  divss                                   2 ( 0.86%)
+  lea                                   142 (61.21%)
+  mov                                    32 (13.79%)
+  movsd                                   2 ( 0.86%)
+  ucomisd                                 2 ( 0.86%)
+  ```
+
 * `AFL_FRIDA_STATS_INTERVAL` - The maximum frequency to output statistics
-information. Stats will be written whenever they are updated if the given
-interval has elapsed since last time they were written.
+  information. Stats will be written whenever they are updated if the given
+  interval has elapsed since last time they were written.
 * `AFL_FRIDA_TRACEABLE` - Set the child process to be traceable by any process
-to aid debugging and overcome the restrictions imposed by YAMA. Supported on
-Linux only. Permits a non-root user to use `gcore` or similar to collect a core
-dump of the instrumented target. Note that in order to capture the core dump you
-must set a sufficient timeout (using `-t`) to avoid `afl-fuzz` killing the
-process whilst it is being dumped.
-
-## FASAN - Frida Address Sanitizer Mode
-Frida mode also supports FASAN. The design of this is actually quite simple and
+  to aid debugging and overcome the restrictions imposed by YAMA. Supported on
+  Linux only. Permits a non-root user to use `gcore` or similar to collect a
+  core dump of the instrumented target. Note that in order to capture the core
+  dump you must set a sufficient timeout (using `-t`) to avoid `afl-fuzz`
+  killing the process whilst it is being dumped.
+
+## FASAN - FRIDA Address Sanitizer mode
+
+FRIDA mode also supports FASAN. The design of this is actually quite simple and
 very similar to that used when instrumenting applications compiled from source.
 
-### Address Sanitizer Basics
+### Address Sanitizer basics
 
 When Address Sanitizer is used to instrument programs built from source, the
 compiler first adds a dependency (`DT_NEEDED` entry) for the Address Sanitizer
-dynamic shared object (DSO). This shared object contains the main logic for Address
-Sanitizer, including setting and managing up the shadow memory. It also provides
-replacement implementations for a number of functions in standard libraries.
-
-These replacements include things like `malloc` and `free` which allows for those
-allocations to be marked in the shadow memory, but also a number of other fuctions.
-Consider `memcpy` for example, this is instrumented to validate the paramters
-(test the source and destination buffers against the shadow memory. This is much
-easier than instrumenting those standard libraries since, first it would require
-you to re-compile them and secondly it would mean that the instrumentation would
-be applied at a more expensive granular level. Lastly, load-widening (typically
-found in highy optimized code) can also make this instrumentation more difficult.
+dynamic shared object (DSO). This shared object contains the main logic for
+Address Sanitizer, including setting and managing up the shadow memory. It also
+provides replacement implementations for a number of functions in standard
+libraries.
+
+These replacements include things like `malloc` and `free` which allows for
+those allocations to be marked in the shadow memory, but also a number of other
+functions. Consider `memcpy`, for example. This is instrumented to validate the
+parameters (test the source and destination buffers against the shadow memory).
+This is much easier than instrumenting those standard libraries, since first, it
+would require you to re-compile them and secondly it would mean that the
+instrumentation would be applied at a more expensive granular level. Lastly,
+load-widening (typically found in highly optimized code) can also make this
+instrumentation more difficult.
 
 Since the DSO is loaded before all of the standard libraries (in fact it insists
 on being first), the dynamic loader will use it to resolve imports from other
 modules which depend on it.
 
-### FASAN Implementation
+### FASAN implementation
+
+FASAN takes a similar approach. It requires the user to add the Address
+Sanitizer DSO to the `AFL_PRELOAD` environment variable such that it is loaded
+into the target. Again, it must be first in the list. This means that it is not
+necessary to instrument the standard libraries to detect when an application has
+provided an incorrect argument to `memcpy`, for example. This avoids issues with
+load-widening and should also mean a huge improvement in performance.
+
+FASAN then adds instrumentation for any instructions which use memory operands
+and then calls into the `__asan_loadN` and `__asan_storeN` functions provided by
+the DSO to validate memory accesses against the shadow memory.
+
+## Collisions
 
-FASAN takes a similar approach. It requires the user to add the Address Sanitizer
-DSO to the `AFL_PRELOAD` environment variable such that it is loaded into the target.
-Again, it must be first in the list. This means that it is not necessary to
-instrument the standard libraries to detect when an application has provided an
-incorrect argument to `memcpy` for example. This avoids issues with load-widening
-and should also mean a huge improvement in performance.
+FRIDA mode has also introduced some improvements to reduce collisions in the
+map. For details, see [MapDensity.md](MapDensity.md).
 
-FASAN then adds instrumentation for any instrucutions which use memory operands and
-then calls into the `__asan_loadN` and `__asan_storeN` functions provided by the DSO
-to validate memory accesses against the shadow memory.
+## OSX library fuzzing
 
-# Collisions
-FRIDA mode has also introduced some improvements to reduce collisions in the map.
-See [here](MapDensity.md) for details.
+An example of how to fuzz a dynamic library on OSX is included, see
+[test/osx-lib](test/osx-lib). This requires the use of a simple test harness
+executable which will load the library and call a target function within it. The
+dependent library can either be loaded in using `dlopen` and `dlsym` in a
+function marked `__attribute__((constructor()))` or the test harness can simply
+be linked against it. It is important that the target library is loaded before
+execution of `main`, since this is the point where FRIDA mode is initialized.
+Otherwise, it will not be possible to configure coverage for the test library
+using `AFL_FRIDA_INST_RANGES` or similar.
 
-# OSX Library Fuzzing
-An example of how to fuzz a dynamic library on OSX is included [here](test/osx-lib).
-This requires the use of a simple test harness executable which will load the
-library and call a target function within it. The dependent library can either
-be loaded in using `dlopen` and `dlsym` in a function marked
-`__attribute__((constructor()))` or the test harness can simply be linked
-against it. It is important that the target library is loaded before execution
-of `main`, since this is the point where FRIDA mode is initialized. Otherwise, it
-will not be possible to configure coverage for the test library using
-`AFL_FRIDA_INST_RANGES` or similar.
+## Debugging
 
-# Debugging
-Please refer to the [debugging](#debugging) guide for assistant should you
-encounter problems with FRIDA mode.
+Please refer to [DEBUGGING.md](DEBUGGING.md) for assistance should you encounter
+problems with FRIDA mode.
 
-## TODO
+## To do
 
 The next features to be added are Aarch32 support as well as looking at
-potential performance improvements. The intention is to achieve feature parity with
-QEMU mode in due course. Contributions are welcome, but please get in touch to
-ensure that efforts are deconflicted.
+potential performance improvements. The intention is to achieve feature parity
+with QEMU mode in due course. Contributions are welcome, but please get in touch
+to ensure that efforts are deconflicted.
\ No newline at end of file
diff --git a/frida_mode/Scripting.md b/frida_mode/Scripting.md
index 2ee0c858..fcf8a490 100644
--- a/frida_mode/Scripting.md
+++ b/frida_mode/Scripting.md
@@ -1,25 +1,32 @@
 # Scripting
+
 FRIDA now supports the ability to configure itself using JavaScript. This allows
 the user to make use of the convenience of FRIDA's scripting engine (along with
 it's support for debug symbols and exports) to configure all of the things which
 were traditionally configured using environment variables.
 
-By default FRIDA mode will look for the file `afl.js` in the current working
+By default, FRIDA mode will look for the file `afl.js` in the current working
 directory of the target. Alternatively, a script file can be configured using
 the environment variable `AFL_FRIDA_JS_SCRIPT`.
 
-This script can make use of all of the standard [frida api functions](https://frida.re/docs/javascript-api/), but FRIDA mode adds some additional functions to allow
-you to interact with FRIDA mode itself. These can all be accessed via the global
-`Afl` parameter. e.g. `Afl.print("HELLO WORLD");`,
+This script can make use of all of the standard [frida api
+functions](https://frida.re/docs/javascript-api/), but FRIDA mode adds some
+additional functions to allow you to interact with FRIDA mode itself. These can
+all be accessed via the global `Afl` parameter, e.g., `Afl.print("HELLO
+WORLD");`.
 
 If you encounter a problem with your script, then you should set the environment
 variable `AFL_DEBUG_CHILD=1` to view any diagnostic information.
 
+## Example
 
-# Example
-Most of the time, users will likely be wanting to call the functions which configure an address (e.g. for the entry point, or the persistent address).
+Most of the time, users will likely be wanting to call the functions which
+configure an address (e.g., for the entry point or the persistent address).
 
-The example below uses the API [`DebugSymbol.fromName()`](https://frida.re/docs/javascript-api/#debugsymbol). Another use API is [`Module.getExportByName()`](https://frida.re/docs/javascript-api/#module).
+The example below uses the API
+[`DebugSymbol.fromName()`](https://frida.re/docs/javascript-api/#debugsymbol).
+Another use API is
+[`Module.getExportByName()`](https://frida.re/docs/javascript-api/#module).
 
 ```js
 /* Use Afl.print instead of console.log */
@@ -86,9 +93,9 @@ Afl.done();
 Afl.print("done");
 ```
 
-# Stripped Binaries
+## Stripped binaries
 
-Lastly, if the binary you attempting to fuzz has no symbol information, and no
+Lastly, if the binary you attempting to fuzz has no symbol information and no
 exports, then the following approach can be used.
 
 ```js
@@ -98,11 +105,12 @@ const address = module.base.add(0xdeadface);
 Afl.setPersistentAddress(address);
 ```
 
-# Persisent Hook
+## Persistent hook
+
 A persistent hook can be implemented using a conventional shared object, sample
 source code for a hook suitable for the prototype of `LLVMFuzzerTestOneInput`
-can be found [here](hook/hook.c). This can be configured using code similar to
-the following.
+can be found in [hook/hook.c](hook/hook.c). This can be configured using code
+similar to the following.
 
 ```js
 const path = Afl.module.path;
@@ -112,7 +120,8 @@ const hook = mod.getExportByName('afl_persistent_hook');
 Afl.setPersistentHook(hook);
 ```
 
-Alternatively, the hook can be provided by using FRIDAs built in support for `CModule`, powered by TinyCC.
+Alternatively, the hook can be provided by using FRIDA's built-in support for
+`CModule`, powered by TinyCC.
 
 ```js
 const cm = new CModule(`
@@ -134,8 +143,10 @@ const cm = new CModule(`
 Afl.setPersistentHook(cm.afl_persistent_hook);
 ```
 
-# Advanced Persistence
+## Advanced persistence
+
 Consider the following target code...
+
 ```c
 
 #include <fcntl.h>
@@ -281,14 +292,15 @@ Afl.done();
 Here, we replace the function `slow` with our own code. This code is then
 selected as the entry point as well as the persistent loop address.
 
-## Replacing LLVMFuzzerTestOneInput
-The function `LLVMFuzzerTestOneInput` can be replaced just like any other. Also
+### Replacing LLVMFuzzerTestOneInput
+
+The function `LLVMFuzzerTestOneInput` can be replaced just like any other. Also,
 any replaced function can also call itself. In the example below, we replace
 `LLVMFuzzerTestOneInput` with `My_LLVMFuzzerTestOneInput` which ignores the
 parameters `buf` and `len` and then calls the original `LLVMFuzzerTestOneInput`
-with the paramaters `__afl_fuzz_ptr` and `__afl_fuzz_len`. This allows us to
+with the parameters `__afl_fuzz_ptr` and `__afl_fuzz_len`. This allows us to
 carry out in-memory fuzzing without the need for any hook function. It should be
-noted that the replacement function and the original can *NOT* share the same
+noted that the replacement function and the original *CANNOT* share the same
 name, since otherwise the `C` code in the `CModule` will not compile due to a
 symbol name collision.
 
@@ -320,7 +332,8 @@ Afl.setInMemoryFuzzing();
 Interceptor.replace(LLVMFuzzerTestOneInput, cm.My_LLVMFuzzerTestOneInput);
 ```
 
-## Hooking `main`
+### Hooking `main`
+
 Lastly, it should be noted that using FRIDA mode's scripting support to hook
 the `main` function is a special case. This is because the `main` function is
 already hooked by the FRIDA mode engine itself and hence the function `main` (or
@@ -359,14 +372,16 @@ Afl.setPersistentAddress(cm.main);
 Afl.setInMemoryFuzzing();
 Afl.setJsMainHook(cm.main);
 ```
-## Library Fuzzing
+
+### Library Fuzzing
 
 It doesn't take too much imagination to see that the above example can be
 extended to use FRIDA's `Module.load` API so that the replaced `main` function
 can then call an arbitrary function. In this way, if we have a library which we
-wish to fuzz rather than an execuatble, then a surrogate executable can be used.
+wish to fuzz rather than an executable, then a surrogate executable can be used.
+
+## Patching
 
-# Patching
 Consider the [following](test/js/test2.c) test code...
 
 ```c
@@ -498,7 +513,7 @@ int main(int argc, char **argv) {
 There are a couple of obstacles with our target application. Unlike when fuzzing
 source code, though, we can't simply edit it and recompile it. The following
 script shows how we can use the normal functionality of FRIDA to modify any
-troublesome behaviour.
+troublesome behavior.
 
 ```js
 Afl.print('******************');
@@ -537,8 +552,10 @@ Afl.done();
 Afl.print("done");
 ```
 
-# Advanced Patching
+## Advanced patching
+
 Consider the following code fragment...
+
 ```c
 extern void some_boring_bug2(char c);
 
@@ -565,7 +582,7 @@ void LLVMFuzzerTestOneInput(char *buf, int len) {
 }
 ```
 
-Rather than using FRIDAs `Interceptor.replace` or `Interceptor.attach` APIs, it
+Rather than using FRIDA's `Interceptor.replace` or `Interceptor.attach` APIs, it
 is possible to apply much more fine grained modification to the target
 application by means of using the Stalker APIs.
 
@@ -649,39 +666,43 @@ Afl.setStalkerCallback(cm.js_stalker_callback)
 Afl.setStdErr("/tmp/stderr.txt");
 ```
 
-Note that you will more likely want to find the
-patch address by using:
+Note that you will more likely want to find the patch address by using:
 
 ```js
 const module = Process.getModuleByName('target.exe');
 /* Hardcoded offset within the target image */
 const address = module.base.add(0xdeadface);
 ```
+
 OR
+
 ```
 const address = DebugSymbol.fromName("my_function").address.add(0xdeadface);
 ```
+
 OR
+
 ```
 const address = Module.getExportByName(null, "my_function").add(0xdeadface);
 ```
 
 The function `js_stalker_callback` should return `TRUE` if the original
-instruction should be emitted in the instrumented code, or `FALSE` otherwise.
-In the example above, we can see it is replaced with a `NOP`.
+instruction should be emitted in the instrumented code or `FALSE` otherwise. In
+the example above, we can see it is replaced with a `NOP`.
 
 Lastly, note that the same callback will be called when compiling instrumented
 code both in the child of the forkserver (as it is executed) and also in the
-parent of the forserver (when prefetching is enabled) so that it can be
+parent of the forkserver (when prefetching is enabled) so that it can be
 inherited by the next forked child. It is **VERY** important that the same
-instructions be generated in both the parent and the child, or if prefetching is
+instructions be generated in both the parent and the child or if prefetching is
 disabled that the same instructions are generated every time the block is
 compiled. Failure to do so will likely lead to bugs which are incredibly
 difficult to diagnose. The code above only prints the instructions when running
 in the parent process (the one provided by `Process.id` when the JS script is
 executed).
 
-# OSX
+## OSX
+
 Note that the JavaScript debug symbol api for OSX makes use of the
 `CoreSymbolication` APIs and as such the `CoreFoundation` module must be loaded
 into the target to make use of it. This can be done by setting:
@@ -691,10 +712,11 @@ AFL_PRELOAD=/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 ```
 
 It should be noted that `CoreSymbolication` API may take a while to initialize
-and build its caches. For this reason, it may be nescessary to also increase the
+and build its caches. For this reason, it may be necessary to also increase the
 value of the `-t` flag passed to `afl-fuzz`.
 
-# API
+## API
+
 ```js
 class Afl {
   /**
@@ -973,4 +995,4 @@ class Afl {
       return Afl.module.getExportByName(name);
   }
 }
-```
+```
\ No newline at end of file