Exemplo n.º 1
0
char *
strcasestr2 (const char *str, const char *search)
{
  if (!(*search))
    return (char *) str;

  return (char *) memmem2 (str, strlen (str), search, strlen (search), MEMMEM2_CASE);
}
Exemplo n.º 2
0
const st_filter_t *
filter_get_filter_by_magic (const st_filter_chain_t *fc, const unsigned char *magic, int magic_len)
{
  int x = 0;

  if (magic && magic_len > 0)
    for (; fc->all[x]; x++)
      {
        int m_len = fc->all[x]->magic_len;

        if (m_len == -1)
          m_len = strlen (fc->all[x]->magic);

        if (fc->all[x]->magic && m_len > 0)
          if (!memcmp (fc->all[x]->magic, magic, magic_len) ||
              memmem2 (fc->all[x]->magic, m_len, magic, magic_len, 0))
          return fc->all[x];
      }
  return NULL;
}
Exemplo n.º 3
0
//#ifdef  TEST
int
main (int argc, char **argv)
{
#define MAXBUFSIZE 32768
  char buf[MAXBUFSIZE];
#if 0
  const char *b = "123(123.32.21.44)214";
  const char *s = "(xxx.xx.xx.xx)";

//  const char *p = memmem2 (b, strlen (b), s, strlen (s), MEMCMP2_WCARD('*', 'x'));
  const char *p = memmem2 (b, strlen (b), s, strlen (s), MEMCMP2_WCARD('x'));
  printf ("%s\n", p);

  strcpy (buf, "1234567890");
  strins (buf + 2, 6, "abc");
  printf ("%s\n", buf);
#else
  strcpy (buf, "12434akjgkjh56453fdsg");
  stritrim_s (buf, "sg", "xx");
  printf (buf);
#endif  
  return 0;
}
Exemplo n.º 4
0
int
pce_init (st_ucon64_nfo_t *rominfo)
{
  int result = -1, size, swapped, x;
  unsigned char *rom_buffer;
  st_pce_data_t *info, key;

  x = ucon64.file_size % (16 * 1024);
  rominfo->backup_header_len = UCON64_ISSET (ucon64.backup_header_len) ?
    ucon64.backup_header_len : (ucon64.file_size > x ? x : 0);

  size = ucon64.file_size - rominfo->backup_header_len;
  if ((rom_buffer = (unsigned char *) malloc (size)) == NULL)
    {
      fprintf (stderr, ucon64_msg[ROM_BUFFER_ERROR], size);
      return -1;
    }
  ucon64_fread (rom_buffer, rominfo->backup_header_len, size, ucon64.fname);

  if (pce_check (rom_buffer, size) == 1)
    result = 0;

  swapped = -1;
  /*
    29 40 f0 => unhacked
    29 40 80 => U.S.A. -> Jap hack
    94 02 0f => bit-swapped and unhacked
    94 02 01 => bit-swapped and hacked

    According to Cowering 2 or 3 games don't use these opcodes to check if a
    Japanese game is running on an American console. If they are present then
    it is in the first 500 (or so) bytes.
    The check for "A..Z" is a fix for Puzznic (J). The check for "HESM" a fix
    for:
    Fire Pro Wrestling - 2nd Bout Sounds
    Fire Pro Wrestling 3 - Legend Bout Sounds
  */
  x = size > 32768 ? 32768 : size;
  if ((memmem2 (rom_buffer, x, "\x94\x02\x0f", 3, 0) ||
       memmem2 (rom_buffer, x, "\x94\x02\x01", 3, 0)) &&
       memmem2 (rom_buffer, x, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26, 0) == 0 &&
       memcmp (rom_buffer, "HESM", 4))
    swapped = 1;
  if (UCON64_ISSET (ucon64.interleaved))
    swapped = ucon64.interleaved;

  if ((result == -1 && swapped != 0) || swapped == 1)
    {                                   // don't swap the bits if -nint is specified
      if (!UCON64_ISSET (ucon64.do_not_calc_crc) || swapped == 1)
        ucon64.fcrc32 = crc32 (0, rom_buffer, size);
      swapbits (rom_buffer, size);
      if (pce_check (rom_buffer, size) == 1)
        {
          swapped = 1;
          result = 0;
        }
      if (swapped != 1)
        {
          ucon64.crc32 = ucon64.fcrc32;
          ucon64.fcrc32 = 0;
        }
    }
  if (swapped != -1)
    rominfo->interleaved = swapped;

  if (ucon64.console == UCON64_PCE)
    result = 0;

  rominfo->header_start = PCE_HEADER_START;
  rominfo->header_len = PCE_HEADER_LEN;
  rominfo->console_usage = pce_usage[0].help;
  rominfo->backup_usage = rominfo->backup_header_len ? msg_usage[0].help : mgd_usage[0].help;

  if (!UCON64_ISSET (ucon64.do_not_calc_crc) && result == 0)
    {
      if (!ucon64.crc32)
        ucon64.crc32 = crc32 (0, rom_buffer, size);
      // additional info
      key.crc32 = ucon64.crc32;
      info = (st_pce_data_t *) bsearch (&key, pce_data,
                                        sizeof pce_data / sizeof (st_pce_data_t),
                                        sizeof (st_pce_data_t), pce_compare);
      if (info)
        {
          if (info->maker)
            rominfo->maker = NULL_TO_UNKNOWN_S (pce_maker[MIN (info->maker,
                                                               PCE_MAKER_MAX - 1)]);

          if (info->serial)
            if (info->serial[0])
              {
                strcat (rominfo->misc, "\nSerial: ");
                strcat (rominfo->misc, info->serial);
              }

          if (info->date)
            {
              int day = info->date / 10000, month = (info->date % 10000) / 100,
                  year = info->date % 100;
              char date[80];

              date[0] = 0;
              if (day)
                sprintf (date, "\nDate: %d/%d/19%d", day, month, year);
              else if (month)
                sprintf (date, "\nDate: %d/19%d", month, year);
              else if (year)
                sprintf (date, "\nDate: 19%d", year);
              strcat (rominfo->misc, date);
            }

          if (info->comment)
            if (info->comment[0])
              {
                strcat (rominfo->misc, "\nComment: ");
                strcat (rominfo->misc, info->comment);
              }
        }
    }

  free (rom_buffer);
  return result;
}