aboutsummaryrefslogtreecommitdiff
path: root/frida_mode
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2021-04-16 13:53:08 +0200
committerGitHub <noreply@github.com>2021-04-16 13:53:08 +0200
commit400ab10cfdfdb25235bf0483bc0fa0332ae11461 (patch)
treec5f5c705b502109917f722ed79549e281f5a02c3 /frida_mode
parent98989f1088d04dd4c0d21834c38b7683f1cfb42d (diff)
parent5dad04867461e93cefd1ecee6d336fa4d9ef632d (diff)
downloadafl++-400ab10cfdfdb25235bf0483bc0fa0332ae11461.tar.gz
Merge branch 'dev' into dev
Diffstat (limited to 'frida_mode')
-rw-r--r--frida_mode/src/instrument.c8
-rw-r--r--frida_mode/src/ranges.c3
-rw-r--r--frida_mode/test/testinstr.c7
-rwxr-xr-xfrida_mode/test/testinstr.py49
4 files changed, 48 insertions, 19 deletions
diff --git a/frida_mode/src/instrument.c b/frida_mode/src/instrument.c
index 042fdab8..22910062 100644
--- a/frida_mode/src/instrument.c
+++ b/frida_mode/src/instrument.c
@@ -174,7 +174,13 @@ void instrument_coverage_optimize(const cs_insn * instr,
static void on_basic_block(GumCpuContext *context, gpointer user_data) {
- /* Avoid stack operations in potentially performance critical code */
+ /*
+ * This function is performance critical as it is called to instrument every
+ * basic block. By moving our print buffer to a global, we avoid it affecting
+ * the critical path with additional stack adjustments if tracing is not
+ * enabled. If tracing is enabled, then we're printing a load of diagnostic
+ * information so this overhead is unlikely to be noticeable.
+ */
static char buffer[200];
int len;
guint64 current_pc = (guint64)user_data;
diff --git a/frida_mode/src/ranges.c b/frida_mode/src/ranges.c
index fc14710f..49ef5a62 100644
--- a/frida_mode/src/ranges.c
+++ b/frida_mode/src/ranges.c
@@ -29,8 +29,7 @@ static void convert_address_token(gchar *token, GumMemoryRange *range) {
gchar **tokens;
int token_count;
tokens = g_strsplit(token, "-", 2);
- for (token_count = 0; tokens[token_count] != NULL; token_count++)
- ;
+ for (token_count = 0; tokens[token_count] != NULL; token_count++) {}
if (token_count != 2) {
diff --git a/frida_mode/test/testinstr.c b/frida_mode/test/testinstr.c
index 2c3d5144..37d47f91 100644
--- a/frida_mode/test/testinstr.c
+++ b/frida_mode/test/testinstr.c
@@ -78,6 +78,13 @@ int main(int argc, char **argv) {
}
buf = malloc(len);
+ if (buf == NULL) {
+
+ perror("malloc");
+ break;
+
+ }
+
n_read = read(fd, buf, len);
if (n_read != len) {
diff --git a/frida_mode/test/testinstr.py b/frida_mode/test/testinstr.py
index 8f5fe886..f648808b 100755
--- a/frida_mode/test/testinstr.py
+++ b/frida_mode/test/testinstr.py
@@ -1,32 +1,49 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
import argparse
from elftools.elf.elffile import ELFFile
+
def process_file(file, section, base):
- with open(file, 'rb') as f:
+ with open(file, "rb") as f:
for sect in ELFFile(f).iter_sections():
- if (sect.name == section):
- start = base + sect.header['sh_offset']
- end = start + sect.header['sh_size']
- print ("0x%016x-0x%016x" % (start, end))
+ if sect.name == section:
+ start = base + sect.header["sh_offset"]
+ end = start + sect.header["sh_size"]
+ print("0x%016x-0x%016x" % (start, end))
return
- print ("Section '%s' not found in '%s'" % (section, file))
+ print("Section '%s' not found in '%s'" % (section, file))
+
def hex_value(x):
return int(x, 16)
+
def main():
- parser = argparse.ArgumentParser(description='Process some integers.')
- parser.add_argument('-f', '--file', dest='file', type=str,
- help='elf file name', required=True)
- parser.add_argument('-s', '--section', dest='section', type=str,
- help='elf section name', required=True)
- parser.add_argument('-b', '--base', dest='base', type=hex_value,
- help='elf base address', required=True)
+ parser = argparse.ArgumentParser(description="Process some integers.")
+ parser.add_argument(
+ "-f", "--file", dest="file", type=str, help="elf file name", required=True
+ )
+ parser.add_argument(
+ "-s",
+ "--section",
+ dest="section",
+ type=str,
+ help="elf section name",
+ required=True,
+ )
+ parser.add_argument(
+ "-b",
+ "--base",
+ dest="base",
+ type=hex_value,
+ help="elf base address",
+ required=True,
+ )
args = parser.parse_args()
- process_file (args.file, args.section, args.base)
+ process_file(args.file, args.section, args.base)
+
if __name__ == "__main__":
- main() \ No newline at end of file
+ main()