-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds documentation for porting, resolves PR comments
- Loading branch information
Showing
14 changed files
with
430 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <keystone/keystone.h> | ||
|
||
#include <string.h> | ||
|
||
FILE * outfile = NULL; | ||
|
||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | ||
ks_engine *ks; | ||
ks_err err; | ||
size_t count; | ||
unsigned char *encode = NULL; | ||
size_t size; | ||
char * assembler; | ||
|
||
if (outfile == NULL) { | ||
// we compute the output | ||
outfile = fopen("/dev/null", "w"); | ||
if (outfile == NULL) { | ||
printf("failed opening /dev/null\n"); | ||
abort(); | ||
} | ||
} | ||
|
||
if (Size < 1) { | ||
return 0; | ||
} | ||
|
||
err = ks_open(KS_ARCH_RISCV, KS_MODE_RISCV32 + KS_MODE_LITTLE_ENDIAN, &ks); | ||
if (err != KS_ERR_OK) { | ||
printf("ERROR: failed on ks_open(), quit error = %u\n", err); | ||
abort(); | ||
} | ||
|
||
ks_option(ks, KS_OPT_SYNTAX, Data[Size-1]); | ||
|
||
assembler = malloc(Size); | ||
memcpy(assembler, Data, Size-1); | ||
//null terminate string | ||
assembler[Size-1] = 0; | ||
|
||
if (ks_asm(ks, assembler, 0, &encode, &size, &count) != KS_ERR_OK) { | ||
fprintf(outfile, "ERROR: ks_asm() failed & count = %lu, error = %u\n", | ||
count, ks_errno(ks)); | ||
} else { | ||
size_t i; | ||
|
||
fprintf(outfile, "%s = ", assembler); | ||
for (i = 0; i < size; i++) { | ||
fprintf(outfile, "%02x ", encode[i]); | ||
} | ||
fprintf(outfile, "\n"); | ||
fprintf(outfile, "Compiled: %lu bytes, statements: %lu\n", size, count); | ||
} | ||
|
||
free(assembler); | ||
// NOTE: free encode after usage to avoid leaking memory | ||
if (encode != NULL) { | ||
ks_free(encode); | ||
} | ||
|
||
// close Keystone instance when done | ||
ks_close(ks); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <keystone/keystone.h> | ||
|
||
#include <string.h> | ||
|
||
FILE * outfile = NULL; | ||
|
||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | ||
ks_engine *ks; | ||
ks_err err; | ||
size_t count; | ||
unsigned char *encode = NULL; | ||
size_t size; | ||
char * assembler; | ||
|
||
if (outfile == NULL) { | ||
// we compute the output | ||
outfile = fopen("/dev/null", "w"); | ||
if (outfile == NULL) { | ||
printf("failed opening /dev/null\n"); | ||
abort(); | ||
} | ||
} | ||
|
||
if (Size < 1) { | ||
return 0; | ||
} | ||
|
||
err = ks_open(KS_ARCH_RISCV, KS_MODE_RISCV64 + KS_MODE_LITTLE_ENDIAN, &ks); | ||
if (err != KS_ERR_OK) { | ||
printf("ERROR: failed on ks_open(), quit error = %u\n", err); | ||
abort(); | ||
} | ||
|
||
ks_option(ks, KS_OPT_SYNTAX, Data[Size-1]); | ||
|
||
assembler = malloc(Size); | ||
memcpy(assembler, Data, Size-1); | ||
//null terminate string | ||
assembler[Size-1] = 0; | ||
|
||
if (ks_asm(ks, assembler, 0, &encode, &size, &count) != KS_ERR_OK) { | ||
fprintf(outfile, "ERROR: ks_asm() failed & count = %lu, error = %u\n", | ||
count, ks_errno(ks)); | ||
} else { | ||
size_t i; | ||
|
||
fprintf(outfile, "%s = ", assembler); | ||
for (i = 0; i < size; i++) { | ||
fprintf(outfile, "%02x ", encode[i]); | ||
} | ||
fprintf(outfile, "\n"); | ||
fprintf(outfile, "Compiled: %lu bytes, statements: %lu\n", size, count); | ||
} | ||
|
||
free(assembler); | ||
// NOTE: free encode after usage to avoid leaking memory | ||
if (encode != NULL) { | ||
ks_free(encode); | ||
} | ||
|
||
// close Keystone instance when done | ||
ks_close(ks); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters