Skip to content

Commit

Permalink
Add nim lang support (#3015)
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Sep 10, 2022
1 parent 7dda939 commit e3f72d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions librz/bin/bin_language.c
Expand Up @@ -64,6 +64,13 @@ static inline bool check_pascal(RzBinSymbol *sym) {
return strstr(sym->name, "_$$_");
}

static inline bool check_nim(RzBinSymbol *sym) {
if (!strncmp(sym->name, "NimMain", strlen("NimMain"))) {
return true;
}
return rz_str_endswith(sym->name, ".nim.c");
}

/**
* \brief Tries to detect which language is used in the binary based on symbols and libraries
*
Expand Down Expand Up @@ -170,6 +177,9 @@ RZ_API RzBinLanguage rz_bin_language_detect(RzBinFile *binfile) {
} else if (check_pascal(sym)) {
info->lang = "pascal";
return RZ_BIN_LANGUAGE_PASCAL;
} else if (check_nim(sym)) {
info->lang = "nim";
return RZ_BIN_LANGUAGE_NIM;
}
}

Expand Down Expand Up @@ -231,6 +241,8 @@ RZ_API RzBinLanguage rz_bin_language_to_id(const char *language) {
return RZ_BIN_LANGUAGE_GO;
} else if (!strcmp(language, "pascal")) {
return RZ_BIN_LANGUAGE_PASCAL;
} else if (!strcmp(language, "nim")) {
return RZ_BIN_LANGUAGE_NIM;
}
return RZ_BIN_LANGUAGE_UNKNOWN;
}
Expand Down Expand Up @@ -266,6 +278,8 @@ RZ_API const char *rz_bin_language_to_string(RzBinLanguage language) {
return "dart";
case RZ_BIN_LANGUAGE_PASCAL:
return "pascal";
case RZ_BIN_LANGUAGE_NIM:
return "nim";
default:
return NULL;
}
Expand Down
1 change: 1 addition & 0 deletions librz/include/rz_bin.h
Expand Up @@ -157,6 +157,7 @@ typedef enum {
RZ_BIN_LANGUAGE_GROOVY = 1 << 10,
RZ_BIN_LANGUAGE_DART = 1 << 11,
RZ_BIN_LANGUAGE_PASCAL = 1 << 12,
RZ_BIN_LANGUAGE_NIM = 1 << 13,
RZ_BIN_LANGUAGE_BLOCKS = 1 << 31,
} RzBinLanguage;

Expand Down
7 changes: 7 additions & 0 deletions test/db/abi/languages/nim
@@ -0,0 +1,7 @@
NAME=LANGUAGES : nim detection
FILE=bins/nim/chatserver-dbg
CMDS=iI~lang
EXPECT=<<EOF
lang nim
EOF
RUN

0 comments on commit e3f72d8

Please sign in to comment.