Example #1
0
static void memcmp_func() {
	char* src;
	char* dst;

	for(int i = 1; i < 4000; i++) {
		src = malloc(i);
		dst = malloc(i);

		memset(src, 0, i);		
		memset(dst, 0, i);		
		
		int rtn = __memcmp(src, dst, i);
		assert_int_equal(0, rtn);	

		free(src);
		src = NULL;
		free(dst);
		dst = NULL;
	}

	for(int i = 1; i < 4000; i++) {
		src = malloc(i);
		dst = malloc(i);

		memset(src, 1, i);
		memset(dst, 2, i);

		int rtn = __memcmp(dst, src, i);
		if(*src > *dst) {
			assert_in_range(rtn, 1, INT32_MAX);		
		} else if(*src < *dst) { 
			assert_in_range(rtn, INT32_MIN, -1);
		} 	
	}
}
static 
PCImgDelayDescr
PiddFromDllName(LPCSTR szDll) {
    PCImgDelayDescr     piddRet = NULL;
    PIMAGE_NT_HEADERS   pinh = PinhFromImageBase(HMODULE(&__ImageBase));

    // Scan the Delay load IAT/INT for the dll in question
    //
    if (pinh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].Size != 0) {
        PCImgDelayDescr pidd = PFromRva<PCImgDelayDescr>(
            pinh->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress
            );

        // Check all of the dlls listed up to the NULL one.
        //
        while (pidd->rvaDLLName != 0) {
            // Check to see if it is the DLL we want
            // Intentionally case sensitive to avoid complication of using the CRT
            // for those that don't use the CRT...the user can replace this with
            // a variant of a case insenstive comparison routine.
            //
            LPCSTR  szDllCur = PFromRva<LPCSTR>(pidd->rvaDLLName);
            size_t  cchDllCur = __strlen(szDllCur);
            if (cchDllCur == __strlen(szDll) && __memcmp(szDll, szDllCur, cchDllCur) == 0) {
                piddRet = pidd;
                break;
                }
            
            pidd++;
            }
        }
    return piddRet;
    }
Example #3
0
/**
 * slib_get_exp_lib - Retrieve an export library by name.
 */
int slib_get_exp_lib(const char *name, slib_exp_lib_t *library)
{
	u8 buf[0x300];	/* We can even handle CDVDMAN's bloat!  */
	slib_exp_lib_list_t *exp_lib_list = &_slib_cur_exp_lib_list;
	slib_exp_lib_t *exp_lib = (slib_exp_lib_t *)buf;
	void *cur_lib;
	int len = strlen(name), count = 0;

	if (!exp_lib_list->head && !(exp_lib_list = slib_exp_lib_list()))
		return 0;

	/* Read the tail export library to initiate the search.  */
	cur_lib = exp_lib_list->tail;

	while (cur_lib) {
		smem_read(cur_lib, exp_lib, sizeof buf);

		if (!__memcmp(exp_lib->name, name, len)) {
			while (exp_lib->exports[count] != 0)
				count++;

			if (library)
				memcpy(library, exp_lib, sizeof(slib_exp_lib_t) + count * 4);

			return count;
		}

		cur_lib = exp_lib->prev;
	}

	return 0;
}
Example #4
0
int
memcmp(const void *s1, const void *s2, size_t n)
{
#ifdef _TLIBC_USE_INTEL_FAST_STRING_
	return _intel_fast_memcmp((void*)s1, (void*)s2, n);
#else
	return __memcmp(s1, s2, n);
#endif
}
Example #5
0
/**
 * slib_exp_lib_list - Find the head and tail of the export library list.
 *
 * Returns NULL if the list couldn't be found, and the address of the head and
 * tail pointers if it was located.
 *
 * This routine will need to be called everytime the IOP is reset.
 */
slib_exp_lib_list_t *slib_exp_lib_list()
{
	slib_exp_lib_t *core_exps;
	u32 *exp_func, *core_info;
	u8 *smem_loc;	/* Current location into our IOP mem buffer.  */
	slib_exp_lib_list_t *exp_lib_list = 0;
	u32 i, addr, core_end, gmt_ofs = 0x800;

	/* Read 16k of IOP RAM from the start of the global module table -
	   this is where we will search.  */
	smem_read((void *)gmt_ofs, smem_buf, SEARCH_SIZE);

	/* The first entry points to LOADCORE's module info.  We then use the
	   module info to determine the end of LOADCORE's .text segment (just
	   past the export library we're trying to find.  */
	core_info = (u32 *)(smem_buf + (*(u32 *)smem_buf - gmt_ofs));
	core_end = core_info[6] + core_info[7];  /* 6 and 7 are .text start and end.  */

	/* Back up so we position ourselves infront of where the export
	   library will be.  */
	smem_loc = smem_buf + core_end - gmt_ofs - 512;
	
	/* Search for LOADCORE's export library.  */
	for (i = 0; i < 512; i += 4) {
		/* SYSMEM's export library sits at 0x830, so it should appear in
		   LOADCORE's prev pointer.  */
		if (*(u32 *)(smem_loc + i) == 0x830) {
			if (!__memcmp(smem_loc + i + 12, "loadcore", 8))
				break;
		}
	}
	if (i >= 512)
		return 0;

	/* Get to the start of the export table, and find the address of the
	   routine that will get us the export library list info.  */
	core_exps = (slib_exp_lib_t *)(smem_loc + i);
	exp_func = (u32 *)(smem_buf + (u32)core_exps->exports[3] - gmt_ofs);

	/* Parse the two instructions that hold the address of the table.  */
	if ((exp_func[0] & 0xffff0000) != 0x3c020000)	/* lui v0, XXXX */
		return 0;
	if ((exp_func[1] & 0xffff0000) != 0x24420000)	/* addiu v0, v0, XXXX */
		return 0;

	addr = (exp_func[0] & 0xffff) << 16;
	addr |= exp_func[1] & 0xffff;
	addr -= gmt_ofs;
	_slib_cur_exp_lib_list.tail = (slib_exp_lib_t *)(*(u32 *)(smem_buf + addr));
	_slib_cur_exp_lib_list.head = (slib_exp_lib_t *)(*(u32 *)(smem_buf + addr + 4));
	exp_lib_list = &_slib_cur_exp_lib_list;

	return exp_lib_list;
}
Example #6
0
void *memmem (const void *a, size_t a_len, const void *b,size_t b_len)
{
  const char *start = (const char *) a;
  const char *const end = start + a_len - b_len + 1;
  
  if(b_len == 0)
    return (void *) a;
  
  if((signed)b_len < 1 || !a || !b || (a_len < b_len))
    return NULL;
  
  while( start < end )
  {
    if(!__memcmp((const unsigned char *)start,(const unsigned char *)b,b_len))
      return (void *) start;
    
    ++start;
  }
  
  return NULL;
}