1. #include <r_util.h>
    2. #include <r_bin.h>
    3. static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb) {
    4. ut64 size;
    5. const ut8 *buf = r_buf_data (b, &size);
    6. r_return_val_if_fail (buf, false);
    7. *bin_obj = r_bin_internal_nes_load (buf, size);
    8. return *bin_obj != NULL;
    9. }
    10. static void destroy(RBinFile *bf) {
    11. r_bin_free_all_nes_obj (bf->o->bin_obj);
    12. bf->o->bin_obj = NULL;
    13. }
    14. static bool check_buffer(RBuffer *b) {
    15. return (!memcmp (buf, "\x4E\x45\x53\x1A", 4));
    16. static RBinInfo* info(RBinFile *arch) {
    17. RBinInfo \*ret = R_NEW0 (RBinInfo);
    18. if (!ret) return NULL;
    19. if (!arch || !arch->buf) {
    20. free (ret);
    21. return NULL;
    22. }
    23. ret->file = strdup (arch->file);
    24. ret->type = strdup ("ROM");
    25. ret->machine = strdup ("Nintendo NES");
    26. ret->os = strdup ("nes");
    27. ret->arch = strdup ("6502");
    28. ret->bits = 8;
    29. return ret;
    30. }
    31. struct r_bin_plugin_t r_bin_plugin_nes = {
    32. .name = "nes",
    33. .desc = "NES",
    34. .get_sdb = NULL,
    35. .load_buffer = &load_buffer,
    36. .destroy = &destroy,
    37. .check_buffer = &check_buffer,
    38. .baddr = NULL,
    39. .entries = NULL,
    40. .sections = NULL,
    41. .info = &info,
    42. };
    43. #ifndef R2_PLUGIN_INCORE
    44. R_API RLibStruct radare_plugin = {
    45. .type = R_LIB_TYPE_BIN,
    46. .data = &r_bin_plugin_nes,
    47. .version = R2_VERSION
    48. };