Exemplo n.º 1
0
ST_FN char *get_line(char *line, int size, FILE *fp)
{
    if (NULL == fgets(line, size, fp))
        return NULL;
    trimback(line, strchr(line, 0));
    return trimfront(line);
}
Exemplo n.º 2
0
/* ------------------------------------------------------------- */
PUB_FN int pe_load_def_file(TCCState *s1, int fd)
{
    DLLReference *dllref;
    int state = 0, ret = -1;
    char line[400], dllname[80], *p;
    FILE *fp = fdopen(dup(fd), "rb");

    if (NULL == fp)
        goto quit;

    for (;;) {
        p = get_line(line, sizeof line, fp);
        if (NULL == p)
            break;
        if (0 == *p || ';' == *p)
            continue;
        switch (state) {
        case 0:
            if (0 != strnicmp(p, "LIBRARY", 7))
                goto quit;
            strcpy(dllname, trimfront(p+7));
            ++state;
            continue;

        case 1:
            if (0 != stricmp(p, "EXPORTS"))
                goto quit;
            ++state;
            continue;

        case 2:
            dllref = tcc_malloc(sizeof(DLLReference) + strlen(dllname));
            strcpy(dllref->name, dllname);
            dllref->level = 0;
            dynarray_add((void ***) &s1->loaded_dlls, &s1->nb_loaded_dlls, dllref);
            ++state;

        default:
            add_elf_sym(s1->dynsymtab_section,
                s1->nb_loaded_dlls, 0,
                ELF32_ST_INFO(STB_GLOBAL, STT_FUNC), 0,
                text_section->sh_num, p);
            continue;
        }
    }
    ret = 0;
quit:
    if (fp)
        fclose(fp);
    if (ret)
        error_noabort("unrecognized export definition file format");
    return ret;
}
Exemplo n.º 3
0
Arquivo: pe.c Projeto: HarryR/sanos
int pe_load_def_file(TCCState *s1, int fd) {
  DLLReference *dllref;
  int state = 0, ret = -1, hint;
  char line[400], dllname[80], *p, *ordinal;
  FILE *fp = fdopen(dup(fd), "rb");
  if (fp == NULL) goto quit;

  for (;;) {
    p = get_line(line, sizeof line, fp);
    if (p == NULL) break;
    if (*p == 0 || *p == ';') continue;
    switch (state) {
      case 0:
        if (strncasecmp(p, "LIBRARY", 7) != 0) goto quit;
        strcpy(dllname, trimfront(p + 7));
        ++state;
        continue;

      case 1:
        if (strcasecmp(p, "EXPORTS") != 0) goto quit;
        ++state;
        continue;

      case 2:
        dllref = tcc_malloc(sizeof(DLLReference) + strlen(dllname));
        strcpy(dllref->name, dllname);
        dllref->level = 0;
        dynarray_add((void ***) &s1->loaded_dlls, &s1->nb_loaded_dlls, dllref);
        ++state;

      default:
        hint = 0;
        ordinal = strchr(p, '@');
        if (ordinal) {
          *ordinal = 0;
          trimback(p, ordinal);
          ordinal++;
          hint = atoi(ordinal);
        }
        add_elf_sym(s1->dynsymtab_section, s1->nb_loaded_dlls, 0, 
                    ELF32_ST_INFO(STB_GLOBAL, STT_FUNC), hint, 
                    text_section->sh_num, p);
        continue;
    }
  }
  ret = 0;

quit:
  if (fp) fclose(fp);
  if (ret) error_noabort("unrecognized export definition file format");
  return ret;
}
Exemplo n.º 4
0
Arquivo: pe.c Projeto: HarryR/sanos
static char *get_line(char *line, int size, FILE *fp) {
  if (fgets(line, size, fp) == NULL) return NULL;
  trimback(line, strchr(line, 0));
  return trimfront(line);
}