コード例 #1
0
ファイル: csmfile.c プロジェクト: cbuehler/gwyddion
static gint
csmfile_detect(const GwyFileDetectInfo *fileinfo,
               gboolean only_name)
{
    guint size, xres, yres;

    if (only_name)
        return g_str_has_suffix(fileinfo->name_lowercase, EXTENSION) ? 20 : 0;

    // Weed out files that do not pretend to be Windows bitmaps quickly.
    if (fileinfo->buffer_len < BMP_HEADER_SIZE
        || !read_bmp_header(fileinfo->head, &size, &xres, &yres))
        return 0;

    // Weed out incorrect Windows bitmaps but also those no extra data beyond
    // the nominal end.
    if (fileinfo->file_size <= size)
        return 0;

    // Look for "Version = CSPM" somewhere near the end.
    if (!gwy_memmem(fileinfo->tail, fileinfo->buffer_len,
                    MAGIC, MAGIC_SIZE))
        return 0;


    return 90;
}
コード例 #2
0
ファイル: ezdfile.c プロジェクト: svn2github/gwyddion
static guint
find_data_start(const guchar *buffer,
                gsize size)
{
    const guchar *p;
    p = gwy_memmem(buffer, size, DATA_MAGIC, DATA_MAGIC_SIZE);
    return p ? (p - buffer) + DATA_MAGIC_SIZE : 0;
}
コード例 #3
0
ファイル: opengps.c プロジェクト: DavidMercier/gwyddion
static gint
x3p_detect(const GwyFileDetectInfo *fileinfo,
           gboolean only_name)
{
    unzFile zipfile;
    guchar *content;
    gint score = 0;

    if (only_name)
        return g_str_has_suffix(fileinfo->name_lowercase, EXTENSION) ? 15 : 0;

    /* Generic ZIP file. */
    if (fileinfo->file_size < MAGIC_SIZE
        || memcmp(fileinfo->head, MAGIC, MAGIC_SIZE) != 0)
        return 0;

    /* It contains main.xml and maybe directory bindata.  One of them should be
     * somewehre near the begining of the file. */
    if (!gwy_memmem(fileinfo->head, fileinfo->buffer_len,
                    MAGIC1, MAGIC1_SIZE)
        && !gwy_memmem(fileinfo->head, fileinfo->buffer_len,
                       MAGIC2, MAGIC2_SIZE))
        return 0;

    /* We have to realy look inside.  And since main.xml is a popular name
     * for the main XML document within such files, we also have to see if
     * we find "ISO5436_2" somewehre near the begining of the file. */
    if ((zipfile = gwyminizip_unzOpen(fileinfo->name))) {
        if (unzLocateFile(zipfile, "main.xml", 1) == UNZ_OK) {
            if ((content = x3p_get_file_content(zipfile, NULL, NULL))) {
                if (g_strstr_len(content, 4096, "ISO5436_2"))
                    score = 100;
                g_free(content);
            }
        }
        unzClose(zipfile);
    }

    return score;
}