fuzz: add fuzz_decode_platform.c

This commit is contained in:
Nguyen Anh Quynh 2019-04-13 11:11:58 +08:00
parent c2261ee7fd
commit d95736bc9d
3 changed files with 45 additions and 2 deletions

1
.gitignore vendored
View File

@ -117,6 +117,7 @@ fuzz_harness
test_iter_benchmark
fuzz_bindisasm
fuzz_disasm
fuzz_decode_platform
capstone_get_setup

View File

@ -42,11 +42,12 @@ SOURCES = fuzz_disasm.c drivermc.c fuzz_harness.c driverbin.c
OBJS = $(addprefix $(OBJDIR)/,$(SOURCES:.c=.o))
BINARY = $(addprefix $(TESTDIR)/,fuzz_disasm$(BIN_EXT))
BINARYBIN = $(addprefix $(TESTDIR)/,fuzz_bindisasm$(BIN_EXT))
PLATFORMDECODE = $(addprefix $(TESTDIR)/,fuzz_decode_platform$(BIN_EXT))
all: $(BINARY) $(BINARYBIN)
all: $(BINARY) $(BINARYBIN) $(PLATFORMDECODE)
clean:
rm -rf fuzz_harness $(OBJS) $(BINARY) $(BINARYBIN) $(OBJDIR)/lib$(LIBNAME).* $(OBJDIR)/$(LIBNAME).*
rm -rf fuzz_harness $(OBJS) $(PLATFORMDECODE) $(BINARY) $(BINARYBIN) $(OBJDIR)/lib$(LIBNAME).* $(OBJDIR)/$(LIBNAME).*
$(BINARY): fuzz_disasm.o drivermc.o
@mkdir -p $(@D)
@ -66,6 +67,15 @@ else
$(link-static)
endif
$(PLATFORMDECODE): fuzz_decode_platform.o
@mkdir -p $(@D)
ifeq ($(V),0)
$(call log,LINK,$(notdir $@))
@$(link-static)
else
$(link-static)
endif
$(OBJDIR)/%.o: %.c
@mkdir -p $(@D)
ifeq ($(V),0)

View File

@ -0,0 +1,32 @@
// this tool decodes first input byte feed to OSS fuzz, that encodes arch+mode
// by Nguyen Anh Quynh, 2019
#include <stdio.h>
#include <inttypes.h>
#include <capstone/capstone.h>
#include "platform.h"
static struct platform platforms[] = {
#include "platforms.inc"
};
int main(int argc, char **argv)
{
unsigned int platforms_len = sizeof(platforms)/sizeof(platforms[0]), data, i;
if (argc != 2) {
printf("Decoding OSS fuzz platform\n", argv[0]);
printf("Syntax: %s <hex-byte>\n", argv[0]);
return -1;
}
data = (unsigned int)strtol(argv[1], NULL, 16);
i = (unsigned int)data % platforms_len;
printf("cstool arch+mode = %s\n", platforms[i].cstoolname);
return 0;
}