Ejemplo n.º 1
0
const WORD * CResModule::CountMemReplaceDialogResource(const WORD * res, size_t * wordcount, WORD * newDialog)
{
	BOOL bEx = FALSE;
	DWORD style = GET_DWORD(res);
	if (newDialog)
	{
		newDialog[(*wordcount)++] = GET_WORD(res++);
		newDialog[(*wordcount)++] = GET_WORD(res++);
	}
	else
	{
		res += 2;
		(*wordcount) += 2;
	}

	if (style == 0xffff0001)	// DIALOGEX resource
	{
		bEx = TRUE;
		if (newDialog)
		{
			newDialog[(*wordcount)++] = GET_WORD(res++);	//help id
			newDialog[(*wordcount)++] = GET_WORD(res++);	//help id
			newDialog[(*wordcount)++] = GET_WORD(res++);	//exStyle
			newDialog[(*wordcount)++] = GET_WORD(res++);	//exStyle
			style = GET_DWORD(res);
			newDialog[(*wordcount)++] = GET_WORD(res++);	//style
			newDialog[(*wordcount)++] = GET_WORD(res++);	//style
		}
		else
		{
			res += 4;
			style = GET_DWORD(res);
			res += 2;
			(*wordcount) += 6;
		}
	}
	else
	{
		bEx = FALSE;
		if (newDialog)
		{
			newDialog[(*wordcount)++] = GET_WORD(res++);	//exStyle
			newDialog[(*wordcount)++] = GET_WORD(res++);	//exStyle
			//style = GET_DWORD(res);
			//newDialog[(*wordcount)++] = GET_WORD(res++);	//style
			//newDialog[(*wordcount)++] = GET_WORD(res++);	//style
		}
		else
		{
			res += 2;
			(*wordcount) += 2;
		}
	}

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res);
	WORD nbItems = GET_WORD(res);
	(*wordcount)++;
	res++;

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res); //x
	(*wordcount)++;
	res++;

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res); //y
	(*wordcount)++;
	res++;

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res); //cx
	(*wordcount)++;
	res++;

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res); //cy
	(*wordcount)++;
	res++;

	// Get the menu name

	switch (GET_WORD(res))
	{
	case 0x0000:
		if (newDialog)
			newDialog[(*wordcount)] = GET_WORD(res);
		(*wordcount)++;
		res++;
		break;
	case 0xffff:
		if (newDialog)
		{
			newDialog[(*wordcount)++] = GET_WORD(res++);
			newDialog[(*wordcount)++] = GET_WORD(res++);
		}
		else
		{
			(*wordcount) += 2;
			res += 2;
		}
		break;
	default:
		if (newDialog)
		{
			wcscpy((LPWSTR)&newDialog[(*wordcount)], (LPCWSTR)res);
		}
		(*wordcount) += wcslen((LPCWSTR) res) + 1;
		res += wcslen((LPCWSTR) res) + 1;
		break;
	}

	// Get the class name

	switch (GET_WORD(res))
	{
	case 0x0000:
		if (newDialog)
			newDialog[(*wordcount)] = GET_WORD(res);
		(*wordcount)++;
		res++;
		break;
	case 0xffff:
		if (newDialog)
		{
			newDialog[(*wordcount)++] = GET_WORD(res++);
			newDialog[(*wordcount)++] = GET_WORD(res++);
		}
		else
		{
			(*wordcount) += 2;
			res += 2;
		}
		break;
	default:
		if (newDialog)
		{
			wcscpy((LPWSTR)&newDialog[(*wordcount)], (LPCWSTR)res);
		}
		(*wordcount) += wcslen((LPCWSTR) res) + 1;
		res += wcslen((LPCWSTR) res) + 1;
		break;
	}

	// Get the window caption

	ReplaceStr((LPCWSTR)res, newDialog, wordcount, &m_bTranslatedDialogStrings, &m_bDefaultDialogStrings);
	res += wcslen((LPCWSTR)res) + 1;

	// Get the font name

	if (style & DS_SETFONT)
	{
		if (newDialog)
			newDialog[(*wordcount)] = GET_WORD(res);
		res++;
		(*wordcount)++;

		if (bEx)
		{
			if (newDialog)
			{
				newDialog[(*wordcount)++] = GET_WORD(res++);
				newDialog[(*wordcount)++] = GET_WORD(res++);
			}
			else
			{
				res += 2;
				(*wordcount) += 2;
			}
		}

		if (newDialog)
			wcscpy((LPWSTR)&newDialog[(*wordcount)], (LPCWSTR)res);
		(*wordcount) += wcslen((LPCWSTR)res) + 1;
		res += wcslen((LPCWSTR)res) + 1;
	}
	// First control is on DWORD boundary
	while ((*wordcount)%2)
		(*wordcount)++;
	while ((ULONG)res % 4)
		res++;

	while (nbItems--)
	{
		res = ReplaceControlInfo(res, wordcount, newDialog, bEx);
	}
	return res;
}
Ejemplo n.º 2
0
const WORD* CResModule::GetDialogInfo(const WORD * pTemplate, LPDIALOGINFO lpDlgInfo)
{
	const WORD* p = (const WORD *)pTemplate;

	lpDlgInfo->style = GET_DWORD(p);
	p += 2;

	if (lpDlgInfo->style == 0xffff0001)	// DIALOGEX resource
	{
		lpDlgInfo->dialogEx = TRUE;
		lpDlgInfo->helpId   = GET_DWORD(p);
		p += 2;
		lpDlgInfo->exStyle  = GET_DWORD(p);
		p += 2;
		lpDlgInfo->style    = GET_DWORD(p);
		p += 2;
	}
	else
	{
		lpDlgInfo->dialogEx = FALSE;
		lpDlgInfo->helpId   = 0;
		lpDlgInfo->exStyle  = GET_DWORD(p);
		p += 2;
	}

	lpDlgInfo->nbItems = GET_WORD(p);
	p++;

	lpDlgInfo->x = GET_WORD(p);
	p++;

	lpDlgInfo->y = GET_WORD(p);
	p++;

	lpDlgInfo->cx = GET_WORD(p);
	p++;

	lpDlgInfo->cy = GET_WORD(p);
	p++;

	// Get the menu name

	switch (GET_WORD(p))
	{
	case 0x0000:
		lpDlgInfo->menuName = NULL;
		p++;
		break;
	case 0xffff:
		lpDlgInfo->menuName = (LPCTSTR) (WORD) GET_WORD(p + 1);
		p += 2;
		break;
	default:
		lpDlgInfo->menuName = (LPCTSTR) p;
		p += wcslen((LPCWSTR) p) + 1;
		break;
	}

	// Get the class name

	switch (GET_WORD(p))
	{
	case 0x0000:
		lpDlgInfo->className = (LPCTSTR)MAKEINTATOM(32770);
		p++;
		break;
	case 0xffff:
		lpDlgInfo->className = (LPCTSTR) (WORD) GET_WORD(p + 1);
		p += 2;
		break;
	default:
		lpDlgInfo->className = (LPCTSTR) p;
		p += wcslen((LPCTSTR)p) + 1;
		break;
	}

	// Get the window caption

	lpDlgInfo->caption = (LPCTSTR)p;
	p += wcslen((LPCWSTR) p) + 1;

	// Get the font name

	if (lpDlgInfo->style & DS_SETFONT)
	{
		lpDlgInfo->pointSize = GET_WORD(p);
		p++;

		if (lpDlgInfo->dialogEx)
		{
			lpDlgInfo->weight = GET_WORD(p);
			p++;
			lpDlgInfo->italic = LOBYTE(GET_WORD(p));
			p++;
		}
		else
		{
			lpDlgInfo->weight = FW_DONTCARE;
			lpDlgInfo->italic = FALSE;
		}

		lpDlgInfo->faceName = (LPCTSTR)p;
		p += wcslen((LPCWSTR) p) + 1;
	}
	// First control is on DWORD boundary
	return (const WORD *) ((((long)p) + 3) & ~3);
}
Ejemplo n.º 3
0
const WORD* CResModule::GetControlInfo(const WORD* p, LPDLGITEMINFO lpDlgItemInfo, BOOL dialogEx, LPBOOL bIsID)
{
	if (dialogEx)
	{
		lpDlgItemInfo->helpId = GET_DWORD(p);
		p += 2;
		lpDlgItemInfo->exStyle = GET_DWORD(p);
		p += 2;
		lpDlgItemInfo->style = GET_DWORD(p);
		p += 2;
	}
	else
	{
		lpDlgItemInfo->helpId = 0;
		lpDlgItemInfo->style = GET_DWORD(p);
		p += 2;
		lpDlgItemInfo->exStyle = GET_DWORD(p);
		p += 2;
	}

	lpDlgItemInfo->x = GET_WORD(p);
	p++;

	lpDlgItemInfo->y = GET_WORD(p);
	p++;

	lpDlgItemInfo->cx = GET_WORD(p);
	p++;

	lpDlgItemInfo->cy = GET_WORD(p);
	p++;

	if (dialogEx)
	{
		// ID is a DWORD for DIALOGEX
		lpDlgItemInfo->id = (WORD) GET_DWORD(p);
		p += 2;
	}
	else
	{
		lpDlgItemInfo->id = GET_WORD(p);
		p++;
	}

	if (GET_WORD(p) == 0xffff)
	{
		GET_WORD(p + 1);

		p += 2;
	}
	else
	{
		lpDlgItemInfo->className = (LPCTSTR) p;
		p += wcslen((LPCWSTR) p) + 1;
	}

	if (GET_WORD(p) == 0xffff)	// an integer ID?
	{
		*bIsID = TRUE;
		lpDlgItemInfo->windowName = (LPCTSTR) (DWORD) GET_WORD(p + 1);
		p += 2;
	}
	else
	{
		*bIsID = FALSE;
		lpDlgItemInfo->windowName = (LPCTSTR) p;
		p += wcslen((LPCWSTR) p) + 1;
	}

	if (GET_WORD(p))
	{
		lpDlgItemInfo->data = (LPVOID) (p + 1);
		p += GET_WORD(p) / sizeof(WORD);
	}
	else
		lpDlgItemInfo->data = NULL;

	p++;
	// Next control is on DWORD boundary
	return (const WORD *)((((long)p) + 3) & ~3);
}
Ejemplo n.º 4
0
uint16_t getBigEndianWord(uint8_t *bytes){
  uint8_t msb = *bytes;
  uint8_t lsb = GET_NEXT_BYTE_OF(bytes);
  return GET_WORD(msb,lsb);
}
Ejemplo n.º 5
0
Elf_Arsym *
_libelf_ar_process_symtab(Elf *e, size_t *count)
{
	size_t n, nentries, off;
	Elf_Arsym *symtab, *sym;
	unsigned char  *p, *s, *end;

	assert(e != NULL);
	assert(count != NULL);

	if (e->e_u.e_ar.e_rawsymtabsz < INTSZ) {
		LIBELF_SET_ERROR(ARCHIVE, 0);
		return (NULL);
	}

	p = (unsigned char *) e->e_u.e_ar.e_rawsymtab;
	end = p + e->e_u.e_ar.e_rawsymtabsz;

	GET_WORD(p, nentries);
	p += INTSZ;

	if (nentries == 0 || p + nentries * INTSZ >= end) {
		LIBELF_SET_ERROR(ARCHIVE, 0);
		return (NULL);
	}

	/* Allocate space for a nentries + a sentinel. */
	if ((symtab = malloc(sizeof(Elf_Arsym) * (nentries+1))) == NULL) {
		LIBELF_SET_ERROR(RESOURCE, 0);
		return (NULL);
	}

	s = p + (nentries * INTSZ); /* start of the string table. */

	for (n = nentries, sym = symtab; n > 0; n--) {
		off = 0;

		GET_WORD(p, off);

		sym->as_off = off;
		sym->as_hash = elf_hash(s);
		sym->as_name = s;

		p += INTSZ;
		sym++;

		for (; s < end && *s++ != '\0';) /* skip to next string */
			;
		if (s > end) {
			LIBELF_SET_ERROR(ARCHIVE, 0);
			free(symtab);
			return (NULL);
		}
	}

	/* Fill up the sentinel entry. */
	sym->as_name = NULL;
	sym->as_hash = ~0UL;
	sym->as_off = (off_t) 0;

	*count = e->e_u.e_ar.e_symtabsz = nentries + 1;
	e->e_u.e_ar.e_symtab = symtab;

	return (symtab);
}
Ejemplo n.º 6
0
BOOL CResModule::ExtractMenu(UINT nID)
{
	HRSRC		hrsrc = FindResource(m_hResDll, MAKEINTRESOURCE(nID), RT_MENU);
	HGLOBAL		hglMenuTemplate;
	WORD		version, offset;
	DWORD dwHelpId;
	const WORD *p, *p0;

	if (!hrsrc)
		MYERROR;

	hglMenuTemplate = LoadResource(m_hResDll, hrsrc);

	if (!hglMenuTemplate)
		MYERROR;

	p = (const WORD*)LockResource(hglMenuTemplate);

	if (p == NULL)
		MYERROR;

	// Standard MENU resource
	//struct MenuHeader { 
	//	WORD   wVersion;           // Currently zero 
	//	WORD   cbHeaderSize;       // Also zero 
	//}; 

	// MENUEX resource
	//struct MenuExHeader {
	//    WORD wVersion;           // One
	//    WORD wOffset;
	//    DWORD dwHelpId;
	//};
	p0 = p;
	version = GET_WORD(p);

	p++;

	switch (version)
	{
	case 0:
		{
			offset = GET_WORD(p);
			p += offset;
			p++;
			if (!ParseMenuResource(p))
				goto DONE_ERROR;
		}
		break;
	case 1:
		{
			offset = GET_WORD(p);
			p++;
			dwHelpId = GET_DWORD(p);
			if (!ParseMenuExResource(p0 + offset))
				goto DONE_ERROR;
		}
		break;
	default:
		goto DONE_ERROR;
	}

	UnlockResource(hglMenuTemplate);
	FreeResource(hglMenuTemplate);
	return TRUE;

DONE_ERROR:
	UnlockResource(hglMenuTemplate);
	FreeResource(hglMenuTemplate);
	MYERROR;
}
Ejemplo n.º 7
0
const WORD* CResModule::ParseMenuResource(const WORD * res)
{
	WORD		flags;
	WORD		id = 0;
	LPCWSTR		str;
	WORD *p0;

	//struct PopupMenuItem { 
	//	WORD   fItemFlags; 
	//	WCHAR  szItemText[]; 
	//}; 
	//struct NormalMenuItem { 
	//	WORD   fItemFlags; 
	//	WORD   wMenuID; 
	//	WCHAR  szItemText[]; 
	//}; 

	do
	{
		p0 = (WORD *)res;
		flags = GET_WORD(res);
		res++;
		if (!(flags & MF_POPUP))
		{
			id = GET_WORD(res);	//normal menu item
			res++;
		}
		else
			id = (WORD)-1;			//popup menu item

		str = (LPCWSTR)res;
		size_t l = wcslen(str)+1;
		res += l;

		if (flags & MF_POPUP)
		{
			TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
			SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
			_tcscpy(pBuf, str);
			CUtils::StringExtend(pBuf);

			std::wstring wstr = std::wstring(pBuf);
			RESOURCEENTRY entry = m_StringEntries[wstr];
			if (id)
				entry.resourceIDs.insert(id);

			m_StringEntries[wstr] = entry;
			delete [] pBuf;

			if ((res = ParseMenuResource(res))==0)
				return NULL;
		}
		else if (id != 0)
		{
			TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
			SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
			_tcscpy(pBuf, str);
			CUtils::StringExtend(pBuf);

			std::wstring wstr = std::wstring(pBuf);
			RESOURCEENTRY entry = m_StringEntries[wstr];
			entry.resourceIDs.insert(id);

			TCHAR szTempBuf[1024];
			_stprintf(szTempBuf, _T("#: MenuEntry; ID:%d"), id);
			MENUENTRY menu_entry;
			menu_entry.wID = id;
			menu_entry.reference = szTempBuf;
			menu_entry.msgstr = wstr;

			m_StringEntries[wstr] = entry;
			m_MenuEntries[id] = menu_entry;
			delete [] pBuf;
		}
	} while (!(flags & MF_END));
	return res;
}
Ejemplo n.º 8
0
PROTO(void, bout_swap_exec_header_in,
      (bfd *abfd,
      struct external_exec *raw_bytes,
      struct internal_exec *execp));
	 
void
DEFUN(bout_swap_exec_header_in,(abfd, raw_bytes, execp),
      bfd *abfd AND
      struct external_exec *raw_bytes AND
      struct internal_exec *execp)
{
  struct external_exec *bytes = (struct external_exec *)raw_bytes;

  /* Now fill in fields in the execp, from the bytes in the raw data.  */
  execp->a_info   = bfd_h_get_32 (abfd, bytes->e_info);
  execp->a_text   = GET_WORD (abfd, bytes->e_text);
  execp->a_data   = GET_WORD (abfd, bytes->e_data);
  execp->a_bss    = GET_WORD (abfd, bytes->e_bss);
  execp->a_syms   = GET_WORD (abfd, bytes->e_syms);
  execp->a_entry  = GET_WORD (abfd, bytes->e_entry);
  execp->a_trsize = GET_WORD (abfd, bytes->e_trsize);
  execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);
  execp->a_tload  = GET_WORD (abfd, bytes->e_tload);
  execp->a_dload  = GET_WORD (abfd, bytes->e_dload);
  execp->a_talign = bytes->e_talign[0];
  execp->a_dalign = bytes->e_dalign[0];
  execp->a_balign = bytes->e_balign[0];
  execp->a_relaxable = bytes->e_relaxable[0];
}

/* Swaps the information in an internal exec header structure into the
Ejemplo n.º 9
0
TEST( Types, basic_word_get ) {
	util::WORD result = GET_WORD(types::values);
	ASSERT_TRUE( result == 0xAA55 );
}
Ejemplo n.º 10
0
int capi2_checkuser2(int	fd,
		     char	*user,
		     char	*passwd)
{
#define CCHECK_ERR -1

    int ev;
    struct {
	CAPI_control_req_t	req;
	char			buffer[256];
    } r;
    struct {
	CAPI_control_conf_ex_t	conf;
	char			buffer[256];
    } a;
    union CAPI_primitives *cmsg = (union CAPI_primitives *)&a;
    int 	len;
    int		chall_len	= 0;
    char	*chall		= NULL;
    struct userdata	*data;
    md5context_t	md5Context;
   
    memset(&r.req, 0, sizeof(r.req));

    if (user == NULL) {
	return 0;	/* OK no authentication desired */
    }
    if (passwd == NULL) {
	passwd = "";
    }


    PUT_WORD(  r.req.len          , sizeof(r.req));
    PUT_WORD(  r.req.appl         , fd);
    PUT_WORD(  r.req.PRIM_type    , CAPI_CONTROL_REQ);
    PUT_WORD(  r.req.messid       , 0);
    PUT_WORD(  r.req.contrl       , 0);
    PUT_WORD(  r.req.type         , CTRL_GETCHALLENGE);
    PUT_BYTE(  r.req.structlen    , 0);

    if ((ev = capi2_put_message( fd, (char *)&r)) != 0) {
	cTRACE( 1, fprintf( stderr, "capi2_put_message rn=0x%x\n", ev));
	capi2_errno = ev;
	return CCHECK_ERR;
    }

    if ((ev = capi2_wait_for_signal(fd, MAXRTT)) != 0) {
        cTRACE(1, fprintf(stderr, "capi2_wait_for_signal 0x%x\n", ev));
        capi2_errno = ev;
	return CCHECK_ERR;    
    }

    if ((ev = capi2_get_message( fd, &cmsg, (union CAPI_primitives *)&a, NULL, 0)) != 0) {
	cTRACE( 1, fprintf( stderr, "capi2_get_message rn=0x%x\n", ev));
        capi2_errno = ev;
	return CCHECK_ERR;
    }

    if (GET_PRIMTYPE(cmsg) == CAPI_CONTROL_CONF
	&& GET_WORD(a.conf.type) == CTRL_GETCHALLENGE    /* get random number */
	&& a.conf.structlen	
    ) {
	chall_len = (size_t)a.conf.structlen;
	chall = a.buffer;  /* random number computed by the brick */
    } else {
        cTRACE( 1, fprintf( stderr, "CAPI_CONTROL_CONF failed\n"));
        capi2_errno = CAPI2_E_REG_OS_RESOURCE_ERROR;
	return CCHECK_ERR;
    }


    /*
     * calculate hash value;
     * see RFC 1321 for a description of the MD5 algorithm
     */

    MD5Init(&md5Context);
    MD5Update (&md5Context, (unsigned char *) user, strlen(user));
    MD5Update (&md5Context, chall, chall_len);
    MD5Update (&md5Context, (unsigned char *) passwd, strlen(passwd));
    MD5Final (&md5Context);

    PUT_WORD(  r.req.appl         , fd);
    PUT_WORD(  r.req.PRIM_type    , CAPI_CONTROL_REQ);
    PUT_WORD(  r.req.messid       , 0);
    PUT_WORD(  r.req.contrl       , 0);
    PUT_WORD(  r.req.type         , CTRL_SETUSER);
    /* copy user and hash value */
    data = (struct userdata *)&r.req.structlen;
 
    data->length = strlen(user);
    memcpy( data->data, user, data->length);
    data = (struct userdata *)&data->data[data->length];
 
    data->length = CAPI_MD5_HASH_LEN;


    memcpy( data->data, md5Context.digest, CAPI_MD5_HASH_LEN);  /* hash value to be compared */
    data = (struct userdata *)&data->data[data->length];        /* on the other side */
 
    len = (char *)data - (char *)&r;
    PUT_WORD(  r.req.len, len );
 
    if ((ev = capi2_put_message( fd, (char *)&r)) != 0) {
	cTRACE( 1, fprintf( stderr, "capi2_put_message rn=0x%x\n", ev));
	capi2_errno = ev;
	return CCHECK_ERR;
    }

    if ((ev = capi2_wait_for_signal(fd, MAXRTT)) != 0) {
        cTRACE(1, fprintf(stderr, "capi2_wait_for_signal 0x%x\n", ev));
        capi2_errno = ev;
	return CCHECK_ERR;
    }

    if ((ev = capi2_get_message( fd, &cmsg, (union CAPI_primitives *)&a, NULL, 0)) != 0) {
	cTRACE( 1, fprintf( stderr, "capi2_get_message rn=0x%x\n", ev));
        capi2_errno = ev;
	return CCHECK_ERR;
    }

    if (GET_PRIMTYPE(cmsg) == CAPI_CONTROL_CONF
	&& GET_WORD(a.conf.type) == CTRL_SETUSER
	&&  GET_WORD(a.conf.info) == 1
    ) {
	return 0; 		/* OK authentication passed */
    }
    cTRACE( 1, fprintf( stderr, "CAPI_CONTROL_CONF failed, invalid authentication"));
    capi2_errno = CAPI2_E_REG_EXT_EQUIPMENT_NOT_SUPPORTED;
    return CCHECK_ERR;
}
Ejemplo n.º 11
0
/************************************************************************
 *									*
 *	capi2_register2							*
 *									*
 ***********************************************************************/
int rcapi_register(int		msgsize, 
			int		level3cnt, 
			int		datablkcnt, 
			int		datablklen, 
			char		*datablock,
			rcapi_host_t	*host,
			rcapi_auth_t	*auth)
{
    int ev, fd = -1;
    CAPI_register_req_t req;
    struct {
	CAPI_register_conf_t conf;
	char buffer[256];
    } a;
    union CAPI_primitives *cmsg;

    memset(&req, 0, sizeof(req));
    memset(&a, 0, sizeof(a));

    if ((fd = rcapi_open(host)) == -1) {
	cTRACE( 1, perror("capi2_open"));
	capi2_errno = CAPI2_E_REG_CAPI_NOT_INSTALLED;
	goto error;
    }
    if(auth != NULL) {
	if (capi2_checkuser2(fd, auth->user ,auth->passwd) < 0) 				return -1;
    }
    PUT_WORD(  req.len          , sizeof(req));
    PUT_WORD(  req.appl         , fd);
    PUT_WORD(  req.PRIM_type    , CAPI_REGISTER_REQ);
    PUT_WORD(  req.messid       , 0);

    PUT_WORD(  req.nmess	, msgsize);
    PUT_WORD(  req.nconn	, level3cnt);
    PUT_WORD(  req.ndblock	, datablkcnt);
    PUT_WORD(  req.dblocksiz	, datablklen);

    PUT_BYTE(  req.version      , 2);	/*  CAPI 2.0  */

    if ((ev = capi2_put_message( fd, (char *)&req)) != 0) {
	cTRACE( 1, fprintf( stderr, "capi2_put_message rn=0x%x", ev));
	capi2_errno = ev;
	goto error;
    }

    while ((ev = capi2_get_message( fd, &cmsg, (union CAPI_primitives *)&a, 
				    NULL, 0)) != 0) {
	if (ev != CAPI2_E_MSG_QUEUE_EMPTY) break;
    }
    if (ev) { capi2_errno = ev; goto error; }

    if (GET_PRIMTYPE(cmsg) == CAPI_REGISTER_CONF
	&& GET_WORD(a.conf.info) == 0
    ) {
	return fd;
    }

error:
    cTRACE( 1, fprintf( stderr, "capi2_register_req failed\n"));
    capi2_close(fd);
    return -1;
}
Ejemplo n.º 12
0
size_t
md_stack_capture_curthread(caddr_t *pcs, size_t size)
{
        struct trapframe *tf = curthread->td_intr_frame;
	pmap_t pmap = vmspace_pmap(curthread->td_proc->p_vmspace);
	
        size_t num_kstacks = 0, num_ustacks = 0;

#if SAMPLE_DEBUG > 2
	printf("%s(%d):  curthread pid %u, tid %u, name %s\n", __FUNCTION__, __LINE__, curthread->td_proc->p_pid, curthread->td_tid, curthread->td_name);
#endif
	
        if (tf == NULL) {
#if SAMPLE_DEBUG > 5
		printf("%s(%d):  intr frame is NULL?\n", __FUNCTION__, __LINE__);
#endif
//		tf = curthread->td_frame;
		/*
		 * I'm not sure what this means.  This should be done via interrupt,
		 * so if curthread wasn't interrupted, then I don't think we can get
		 * anything here?  Please tell me what I'm doing wrong.
		 */
		return 0;
	}

        if (!TRAPF_USERMODE(tf)) {
                // Start with kernel mode
                unsigned long callpc;
                struct amd64_frame *frame;

                frame = (struct amd64_frame*)tf->tf_rbp;

                while (num_kstacks < size) {
                        if (!INKERNEL((long)frame))
                                break;
                        callpc = frame->f_retaddr;
                        if (!INKERNEL(callpc))
                                break;
                        pcs[num_kstacks++] = (caddr_t)callpc;
                        if (frame->f_frame <= frame ||
                            (vm_offset_t)frame->f_frame >= (vm_offset_t)tf->tf_rbp + KSTACK_PAGES * PAGE_SIZE)
                                break;
                        frame = frame->f_frame;
                }
                tf = curthread->td_frame;
        }
        if (TRAPF_USERMODE(tf)) {
                caddr_t *start_pc = pcs + num_kstacks;
                struct amd64_frame frame;

#if SAMPLE_DEBUG > 3
		printf("%s(%d):  doing user mode crawl\n", __FUNCTION__, __LINE__);
#endif
                frame.f_frame = (struct amd64_frame*)tf->tf_rbp;
                if (tf != curthread->td_intr_frame) {
                        start_pc[num_ustacks++] = (caddr_t)tf->tf_rip;
                }
                while ((num_kstacks + num_ustacks) < size) {
                        void *bp = frame.f_frame;
			/*
			 * The calls to GET_WORD replace the non-functional:
			 * copyin_nofault((void*)frame.f_frame, &frame, sizeof(frame));
			 */
			
			frame.f_frame = (struct amd64_frame*)GET_WORD(pmap, (caddr_t)frame.f_frame);
			if (frame.f_frame == 0) {
#if SAMPLE_DEBUG > 4
				printf("%s(%d):  %s:  frame is 0\n", __FUNCTION__, __LINE__, curthread->td_name);
#endif
				break;
			}
			frame.f_retaddr = (long)GET_WORD(pmap, (caddr_t)frame.f_frame + offsetof(struct amd64_frame, f_retaddr));
			if (frame.f_retaddr == 0) {
#if SAMPLE_DEBUG > 4
				printf("%s(%d):  %s:  retaddr from frame %p is 0\n", __FUNCTION__, __LINE__, curthread->td_name, (void*)frame.f_frame);
#endif
				break;
			}
#if SAMPLE_DEBUG > 2
			printf("%s(%d):  f_frame = %ld, f_retaddr = %ld\n", __FUNCTION__, __LINE__, (long)frame.f_frame, (long)frame.f_retaddr);
#endif
			start_pc[num_ustacks++] = (caddr_t)frame.f_retaddr;
			if ((void*)frame.f_frame < bp) {
				break;
			}
                }
        } else {
Ejemplo n.º 13
0
Archivo: game.c Proyecto: orodley/ttc
static bool handle_event_in_level(Game *game, SDL_Event *event)
{
    if (event->type == SDL_USEREVENT) {
        switch (event->user.code) {
        case SECOND_ELAPSED_EVENT:
            game->time_left--;

            if (game->time_left == 0) {
                puts("Time's up!");

                SDL_Color blue = { 0, 0xDB, 0xEB, 0xFF };
                SDL_Texture *missed_words = render_empty_words(game, blue);
                SDL_Texture *original_render_target =
                    SDL_GetRenderTarget(game->renderer);
                SDL_SetRenderTarget(game->renderer, game->guessed_words_texture);
                SDL_RenderCopy(game->renderer, missed_words, NULL, NULL);
                SDL_SetRenderTarget(game->renderer, original_render_target);

                // TODO: This could be made more efficient by keeping an index
                // into guessed_words too.
                for (size_t i = 0; i < game->anagrams->count; i++) {
                    char *word = GET_WORD(game->anagrams, i);
                    if (word_position(game->guessed_words, word) == -1)
                        render_guessed_word(game, word);
                }

                bool guessed_a_six_letter_word = false;
                for (size_t i = 0; i < game->guessed_words->count; i++) {
                    if (strlen(GET_WORD(game->guessed_words, i)) == 6) {
                        guessed_a_six_letter_word = true;
                        break;
                    }
                }

                if (guessed_a_six_letter_word) {
                    char *message = "You qualify for the next round!";
                    puts(message);
                    game->state = WON_LEVEL;
                    game->message_box = render_message_box(game, message);

                    return true;
                } else {
                    printf("You suck, you failed. No new level for you\n"
                           "Your final score was %d\n", game->points);
                    game->state = GAME_OVER;
                    game->message_box = render_message_box(game, "Game over, loser");
                    return true;
                }
            }

            break;
        }

        return true;
    } else if (event->type != SDL_KEYDOWN) {
        return true;
    }

    SDL_KeyboardEvent kbe = event->key;
    SDL_Keycode vk = kbe.keysym.sym;
    if (vk == SDLK_ESCAPE) {
        return false;
    } else if ((vk >= 'a') && (vk <= 'z')) {
        int removed_char_index = -1;
        for (size_t i = 0; i < MAX_WORD_LENGTH - game->chars_entered; i++) {
            char c = game->remaining_chars[i];

            if (c == vk) {
                removed_char_index = i;
                break;
            }
        }

        if (removed_char_index == -1)
            return true;
        for (int i = removed_char_index; i < MAX_WORD_LENGTH; i++)
            game->remaining_chars[i] = game->remaining_chars[i + 1];

        game->curr_input[game->chars_entered++] = vk;

    } else if (vk == SDLK_BACKSPACE) {
        if (game->chars_entered != 0) {
            game->chars_entered--;
            char removed = game->curr_input[game->chars_entered];
            game->remaining_chars[
                MAX_WORD_LENGTH - game->chars_entered - 1] = removed;
            game->curr_input[game->chars_entered] = '\0';
        }
    } else if (vk == SDLK_SPACE) {
        shuffle(game->remaining_chars);
    } else if (vk == SDLK_RETURN) {
        size_t length = strlen(game->curr_input);
        int position;
        if (length < 3 || length > 6) {
            printf("%s is not the right length\n", game->curr_input);
        } else if (word_position(game->guessed_words, game->curr_input) != -1) {
            printf("you've already guessed %s\n", game->curr_input);
        } else if ((position = word_position(
                                   game->anagrams_by_length[length - 3],
                                   game->curr_input))
                   != -1) {
            printf("yep, %s is correct\n", game->curr_input);

            memcpy(GET_WORD(game->guessed_words, game->guessed_words->count),
                   game->curr_input, length);
            game->guessed_words->count++;

            render_guessed_word(game, game->curr_input);

            game->points += 10 * length * length;

            if (game->guessed_words->count == game->anagrams->count) {
                char *message = "You guessed all the words!";

                puts(message);
                game->message_box = render_message_box(game, message);
                game->state = WON_LEVEL;

                // Bonus for guessing all the words.
                game->points += game->anagrams->count * 200 + 100;

                return true;
            }
        } else {
            printf("no, %s is wrong\n", game->curr_input);
        }

        memcpy((game->remaining_chars + MAX_WORD_LENGTH) - game->chars_entered,
               game->curr_input, game->chars_entered);
        memset(game->curr_input, 0, game->chars_entered);
        game->chars_entered = 0;
    }

    return true;
}
Ejemplo n.º 14
0
int getCapiInfo( union CAPI_primitives *capi )
{
    int info;

    switch (GET_PRIMTYPE(capi)) {
	case CAPI2_LISTEN_CONF:
	    info = GET_WORD(capi->c2listen_conf.info);
	    break;
	case CAPI2_ALERT_CONF:
	    info = GET_WORD(capi->c2alert_conf.info);
	    break;
	case CAPI2_CONNECT_CONF:		
	    info = GET_WORD(capi->c2connect_conf.info);
	    break;
	case CAPI2_INFO_CONF:
	    info = GET_WORD(capi->c2info_conf.info);
	    break;
	case CAPI2_CONNECTB3_CONF:
	    info = GET_WORD(capi->c2connectb3_conf.info);
	    break;
	case CAPI2_DATAB3_CONF:
	    info = GET_WORD(capi->c2datab3_conf.info);
	    break;
	case CAPI2_RESETB3_CONF:
	    info = GET_WORD(capi->c2resetb3_conf.info);
	    break;
	case CAPI2_DISCONNECTB3_CONF:
	    info = GET_WORD(capi->c2disconnectb3_conf.info);
	    break;
	case CAPI2_DISCONNECT_CONF:
	    info = GET_WORD(capi->c2disconnect_conf.info);
	    break;
	case CAPI2_FACILITY_CONF:
	    info = GET_WORD(capi->c2facility_conf.info);
	    break;
	case CAPI2_SELECTB_CONF:
	    info = GET_WORD(capi->c2selectb_conf.info);
	    break;
	case CAPI2_DISCONNECT_IND:
	    info = GET_WORD(capi->c2disconnect_ind.reason);
	    break;
	case CAPI2_DISCONNECTB3_IND:
	    info = GET_WORD(capi->c2disconnectb3_ind.reason_b3);
	    break;
	default:
	    info = 0;
	    break;
    }
    return (info);
}
Ejemplo n.º 15
0
const WORD* CResModule::ReplaceControlInfo(const WORD * res, size_t * wordcount, WORD * newDialog, BOOL bEx)
{
	if (bEx)
	{
		if (newDialog)
		{
			newDialog[(*wordcount)++] = GET_WORD(res++);	//helpid
			newDialog[(*wordcount)++] = GET_WORD(res++);	//helpid
		}
		else
		{
			res += 2;
			(*wordcount) += 2;
		}
	}
	if (newDialog)
	{
		LONG * exStyle = (LONG*)&newDialog[(*wordcount)];
		newDialog[(*wordcount)++] = GET_WORD(res++);	//exStyle
		newDialog[(*wordcount)++] = GET_WORD(res++);	//exStyle
		if (m_bRTL)
			*exStyle |= WS_EX_RTLREADING;
	}
	else
	{
		res += 2;
		(*wordcount) += 2;
	}

	if (newDialog)
	{
		newDialog[(*wordcount)++] = GET_WORD(res++);	//style
		newDialog[(*wordcount)++] = GET_WORD(res++);	//style
	}
	else
	{
		res += 2;
		(*wordcount) += 2;
	}

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res);	//x
	res++;
	(*wordcount)++;

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res);	//y
	res++;
	(*wordcount)++;

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res);	//cx
	res++;
	(*wordcount)++;

	if (newDialog)
		newDialog[(*wordcount)] = GET_WORD(res);	//cy
	res++;
	(*wordcount)++;

	if (bEx)
	{
		// ID is a DWORD for DIALOGEX
		if (newDialog)
		{
			newDialog[(*wordcount)++] = GET_WORD(res++);
			newDialog[(*wordcount)++] = GET_WORD(res++);
		}
		else
		{
			res += 2;
			(*wordcount) += 2;
		}
	}
	else
	{
		if (newDialog)
			newDialog[(*wordcount)] = GET_WORD(res);
		res++;
		(*wordcount)++;
	}

	if (GET_WORD(res) == 0xffff)	//classID
	{
		if (newDialog)
		{
			newDialog[(*wordcount)++] = GET_WORD(res++);
			newDialog[(*wordcount)++] = GET_WORD(res++);
		}
		else
		{
			res += 2;
			(*wordcount) += 2;
		}
	}
	else
	{
		if (newDialog)
			wcscpy((LPWSTR)&newDialog[(*wordcount)], (LPCWSTR)res);
		(*wordcount) += wcslen((LPCWSTR) res) + 1;
		res += wcslen((LPCWSTR) res) + 1;
	}

	if (GET_WORD(res) == 0xffff)	// an integer ID?
	{
		if (newDialog)
		{
			newDialog[(*wordcount)++] = GET_WORD(res++);
			newDialog[(*wordcount)++] = GET_WORD(res++);
		}
		else
		{
			res += 2;
			(*wordcount) += 2;
		}
	}
	else
	{
		ReplaceStr((LPCWSTR)res, newDialog, wordcount, &m_bTranslatedDialogStrings, &m_bDefaultDialogStrings);
		res += wcslen((LPCWSTR)res) + 1;
	}

	if (newDialog)
		memcpy(&newDialog[(*wordcount)], res, (GET_WORD(res)+1)*sizeof(WORD));
	(*wordcount) += (GET_WORD(res)+1);
	res += (GET_WORD(res)+1);
	// Next control is on DWORD boundary
	while ((*wordcount) % 2)
		(*wordcount)++;
	return (const WORD *)((((long)res) + 3) & ~3);
}
Ejemplo n.º 16
0
// =======================================================
void CHfsPart::readSuperBlock()
{
  BEGIN;

  QWORD qwBlocksInRegularAlloc;
  hfsSuperBlock sb, sb2;
  int nRes;

  // read superblock
  nRes = readData(&sb, 1024, sizeof(sb));
  if (nRes == -1)
    {
      showDebug(10, "ERROR 1\n");
      g_interface -> ErrorReadingSuperblock(errno);
      THROW(ERR_READING, (DWORD)0, errno);
    }

  if (Be16ToCpu(GET_WORD(&sb.drSigWord)) != HFS_SUPER_MAGIC)
    {
      showDebug(10, "ERROR 2\n");
      g_interface -> ErrorReadingSuperblock(errno);
      THROW(ERR_READING, (DWORD)0, errno);
    }

  // init
  memset(&m_info, 0, sizeof(CInfoHfsHeader));

  m_info.qwAllocCount = BeToCpu(GET_WORD(&sb.drNmAlBlks)); 
  m_info.dwAllocSize = BeToCpu(GET_DWORD(&sb.drAlBlkSize)); 
  m_info.dwBlocksPerAlloc = m_info.dwAllocSize / 512; 
  m_info.qwBitmapSectLocation = (QWORD)BeToCpu(GET_WORD(&sb.drVBMSt));
  m_info.qwFirstAllocBlock = (QWORD)BeToCpu(GET_WORD(&sb.drAlBlSt));
  m_info.qwFreeAllocs = (QWORD)BeToCpu(GET_WORD(&sb.drFreeBks));
  
  // if not a 512 multiple
  if ((m_info.dwAllocSize % 512) != 0)
    THROW(ERR_READING, (DWORD)0, errno);

  // check the last but one block is a superblock
  qwBlocksInRegularAlloc = m_info.dwBlocksPerAlloc * m_info.qwAllocCount;
  nRes = readData(&sb2, (m_info.qwFirstAllocBlock+qwBlocksInRegularAlloc)*512LL, sizeof(sb2));
  if (nRes == -1)
    {
      showDebug(10, "ERROR 3\n");
      g_interface -> ErrorReadingSuperblock(errno);
      THROW(ERR_READING, (DWORD)0, errno);
    }

  if (Be16ToCpu(GET_WORD(&sb.drSigWord)) != HFS_SUPER_MAGIC)
    {
      showDebug(10, "ERROR 4\n");
      g_interface -> ErrorReadingSuperblock(errno);
      THROW(ERR_READING, (DWORD)0, errno);
    }

  // show infos
  showDebug(10, "m_info.qwAllocCount=%llu\n", m_info.qwAllocCount);
  showDebug(10, "m_info.dwAllocSize=%lu=%lu sectors\n", m_info.dwAllocSize, m_info.dwBlocksPerAlloc);
  showDebug(10, "m_info.qwBitmapSectLocation=%llu\n", m_info.qwBitmapSectLocation);
  showDebug(10, "m_info.qwFirstAllocBlock=%llu\n", m_info.qwFirstAllocBlock);
  showDebug(10, "m_info.qwFreeAllocs=%llu\n", m_info.qwFreeAllocs);

  // label == pascal string
  memset(m_header.szLabel, 0, 64);
  memcpy(m_header.szLabel, ((char*)&sb.drVN)+1, my_min(((BYTE*)&sb.drVN)[0], 63));
  showDebug(10, "label=[%s]\n", m_header.szLabel);

  // calculate sectors count
  m_header.qwBlocksCount = m_info.qwFirstAllocBlock // first reserved (2 boot blocks, 1 superblock, ...)
    + (m_info.dwBlocksPerAlloc * m_info.qwAllocCount) // allocation blocks
    + 1 // alternate superblock
    + 1; // last volume of sector
  showDebug(10, "m_header.qwBlocksCount = %llu\n", m_header.qwBlocksCount);
   
  m_header.qwBlockSize = 512;

  m_header.qwBitmapSize = (m_header.qwBlocksCount+7)/8;
  
  QWORD qwUsedBlocks = m_info.qwFirstAllocBlock + 2 + ((m_info.qwAllocCount-m_info.qwFreeAllocs) * m_info.dwBlocksPerAlloc);
  QWORD qwFreeBlocks = m_info.qwFreeAllocs * m_info.dwBlocksPerAlloc;
  setSuperBlockInfos(true, true, qwUsedBlocks*512, qwFreeBlocks*512);

  RETURN;  
}
Ejemplo n.º 17
0
BOOL CResModule::ReplaceString(UINT nID, WORD wLanguage)
{
	HRSRC		hrsrc = FindResourceEx(m_hResDll, RT_STRING, MAKEINTRESOURCE(nID), wLanguage);
	HGLOBAL		hglStringTable;
	LPWSTR		p;

	if (!hrsrc)
		MYERROR;
	hglStringTable = LoadResource(m_hResDll, hrsrc);

	if (!hglStringTable)
		goto DONE_ERROR;
	p = (LPWSTR)LockResource(hglStringTable);

	if (p == NULL)
		goto DONE_ERROR;
/*	[Block of 16 strings.  The strings are Pascal style with a WORD 
	length preceding the string.  16 strings are always written, even 
	if not all slots are full.  Any slots in the block with no string 
	have a zero WORD for the length.] 
*/
	
	//first check how much memory we need
	size_t nMem = 0;
	LPWSTR pp = p;
	for (int i=0; i<16; ++i)
	{
		nMem++;
		size_t len = GET_WORD(pp);
		pp++;
		std::wstring msgid = std::wstring(pp, len);
		WCHAR * pBuf = new WCHAR[MAX_STRING_LENGTH*2];
		SecureZeroMemory(pBuf, MAX_STRING_LENGTH*2*sizeof(WCHAR));
		wcscpy(pBuf, msgid.c_str());
		CUtils::StringExtend(pBuf);
		msgid = std::wstring(pBuf);

		RESOURCEENTRY resEntry;
		resEntry = m_StringEntries[msgid];
		wcscpy(pBuf, resEntry.msgstr.c_str());
		CUtils::StringCollapse(pBuf);
		size_t newlen = wcslen(pBuf);
		if (newlen)
			nMem += newlen;
		else
			nMem += len;
		pp += len;
		delete [] pBuf;
	}

	WORD * newTable = new WORD[nMem + (nMem % 2)];
	SecureZeroMemory(newTable, (nMem + (nMem % 2))*2);

	size_t index = 0;
	for (int i=0; i<16; ++i)
	{
		int len = GET_WORD(p);
		p++;
		std::wstring msgid = std::wstring(p, len);
		WCHAR * pBuf = new WCHAR[MAX_STRING_LENGTH*2];
		SecureZeroMemory(pBuf, MAX_STRING_LENGTH*2*sizeof(WCHAR));
		wcscpy(pBuf, msgid.c_str());
		CUtils::StringExtend(pBuf);
		msgid = std::wstring(pBuf);

		RESOURCEENTRY resEntry;
		resEntry = m_StringEntries[msgid];
		wcscpy(pBuf, resEntry.msgstr.c_str());
		CUtils::StringCollapse(pBuf);
		size_t newlen = wcslen(pBuf);
		if (newlen)
		{
			newTable[index++] = (WORD)newlen;
			wcsncpy((wchar_t *)&newTable[index], pBuf, newlen);
			index += newlen;
			m_bTranslatedStrings++;
		}
		else
		{
			newTable[index++] = (WORD)len;
			if (len)
				wcsncpy((wchar_t *)&newTable[index], p, len);
			index += len;
			if (len)
				m_bDefaultStrings++;
		}
		p += len;
		delete [] pBuf;
	}

	if (!UpdateResource(m_hUpdateRes, RT_STRING, MAKEINTRESOURCE(nID), (m_wTargetLang ? m_wTargetLang : wLanguage), newTable, (DWORD)(nMem + (nMem % 2))*2))
	{
		delete [] newTable;
		goto DONE_ERROR;
	}
	
	if ((m_wTargetLang)&&(!UpdateResource(m_hUpdateRes, RT_STRING, MAKEINTRESOURCE(nID), wLanguage, NULL, 0)))
	{
		delete [] newTable;
		goto DONE_ERROR;
	}
	delete [] newTable;
	UnlockResource(hglStringTable);
	FreeResource(hglStringTable);
	return TRUE;
DONE_ERROR:
	UnlockResource(hglStringTable);
	FreeResource(hglStringTable);
	MYERROR;
}
Ejemplo n.º 18
0
/**********************************************************************
 * Convert ActiveX control templates to AtlAxWin class instances
 */
static LPDLGTEMPLATEW AX_ConvertDialogTemplate(LPCDLGTEMPLATEW src_tmpl)
{
#define GET_WORD(x)  (*(const  WORD *)(x))
#define GET_DWORD(x) (*(const DWORD *)(x))
#define PUT_BLOCK(x,y) do {if (!advance_array(&output, &allocated, &filled, (x), (y))) return NULL;} while (0)
#define PUT_WORD(x)  do {WORD w = (x);PUT_BLOCK(&w, 1);} while(0)
#define PUT_DWORD(x)  do {DWORD w = (x);PUT_BLOCK(&w, 2);} while(0)
    const WORD *tmp, *src = (const WORD *)src_tmpl;
    WORD *output;
    DWORD allocated, filled; /* in WORDs */
    BOOL ext;
    WORD signature, dlgver, rescount;
    DWORD style;

    filled = 0; allocated = 256;
    output = HeapAlloc( GetProcessHeap(), 0, allocated * sizeof(WORD) );
    if (!output)
        return NULL;

    /* header */
    tmp = src;
    signature = GET_WORD(src);
    dlgver = GET_WORD(src + 1);
    if (signature == 1 && dlgver == 0xFFFF)
    {
        ext = TRUE;
        src += 6;
        style = GET_DWORD(src);
        src += 2;
        rescount = GET_WORD(src++);
        src += 4;
        if ( GET_WORD(src) == 0xFFFF ) /* menu */
            src += 2;
        else
            src += strlenW(src) + 1;
        if ( GET_WORD(src) == 0xFFFF ) /* class */
            src += 2;
        else
            src += strlenW(src) + 1;
        src += strlenW(src) + 1; /* title */
        if ( style & (DS_SETFONT | DS_SHELLFONT) )
        {
            src += 3;
            src += strlenW(src) + 1;
        }
    } else {
        ext = FALSE;
        style = GET_DWORD(src);
        src += 4;
        rescount = GET_WORD(src++);
        src += 4;
        if ( GET_WORD(src) == 0xFFFF ) /* menu */
            src += 2;
        else
            src += strlenW(src) + 1;
        if ( GET_WORD(src) == 0xFFFF ) /* class */
            src += 2;
        else
            src += strlenW(src) + 1;
        src += strlenW(src) + 1; /* title */
        if ( style & DS_SETFONT )
        {
            src++;
            src += strlenW(src) + 1;
        }
    }
    PUT_BLOCK(tmp, src-tmp);

    while(rescount--)
    {
        src = (const WORD *)( ( ((ULONG_PTR)src) + 3) & ~3); /* align on DWORD boundary */
        filled = (filled + 1) & ~1; /* depends on DWORD-aligned allocation unit */

        tmp = src;
        if (ext)
            src += 12;
        else
            src += 9;
        PUT_BLOCK(tmp, src-tmp);

        tmp = src;
        if ( GET_WORD(src) == 0xFFFF ) /* class */
        {
            src += 2;
        } else
        {
            src += strlenW(src) + 1;
        }
        src += strlenW(src) + 1; /* title */
        if ( GET_WORD(tmp) == '{' ) /* all this mess created because of this line */
        {
            static const WCHAR AtlAxWin[] = {'A','t','l','A','x','W','i','n', 0};
            PUT_BLOCK(AtlAxWin, sizeof(AtlAxWin)/sizeof(WCHAR));
            PUT_BLOCK(tmp, strlenW(tmp)+1);
        } else
            PUT_BLOCK(tmp, src-tmp);

        if ( GET_WORD(src) )
        {
            WORD size = (GET_WORD(src)+sizeof(WORD)-1) / sizeof(WORD); /* quite ugly :( Maybe use BYTE* instead of WORD* everywhere ? */
            PUT_BLOCK(src, size);
            src+=size;
        }
        else
        {
            PUT_WORD(0);
            src++;
        }
    }
    return (LPDLGTEMPLATEW) output;
}
Ejemplo n.º 19
0
BOOL CResModule::ReplaceMenu(UINT nID, WORD wLanguage)
{
	HRSRC		hrsrc = FindResourceEx(m_hResDll, RT_MENU, MAKEINTRESOURCE(nID), wLanguage);
	HGLOBAL		hglMenuTemplate;
	WORD		version, offset;
	LPWSTR		p;
	WORD *p0;
	DWORD dwHelpId;

	if (!hrsrc)
		MYERROR;	//just the language wasn't found

	hglMenuTemplate = LoadResource(m_hResDll, hrsrc);

	if (!hglMenuTemplate)
		MYERROR;

	p = (LPWSTR)LockResource(hglMenuTemplate);

	if (p == NULL)
		MYERROR;

	//struct MenuHeader { 
	//	WORD   wVersion;           // Currently zero 
	//	WORD   cbHeaderSize;       // Also zero 
	//};

	// MENUEX resource
	//struct MenuExHeader {
	//    WORD wVersion;           // One
	//    WORD wOffset;
	//    DWORD dwHelpId;
	//};
	p0 = (WORD *)p;
	version = GET_WORD(p);

	p++;

	switch (version)
	{
	case 0:
		{
			offset = GET_WORD(p);
			p += offset;
			p++;
			size_t nMem = 0;
			if (!CountMemReplaceMenuResource((WORD *)p, &nMem, NULL))
				goto DONE_ERROR;
			WORD * newMenu = new WORD[nMem + (nMem % 2)+2];
			SecureZeroMemory(newMenu, (nMem + (nMem % 2)+2)*2);
			size_t index = 2;		// MenuHeader has 2 WORDs zero
			if (!CountMemReplaceMenuResource((WORD *)p, &index, newMenu))
			{
				delete [] newMenu;
				goto DONE_ERROR;
			} 

			if (!UpdateResource(m_hUpdateRes, RT_MENU, MAKEINTRESOURCE(nID), (m_wTargetLang ? m_wTargetLang : wLanguage), newMenu, (DWORD)(nMem + (nMem % 2)+2)*2))
			{
				delete [] newMenu;
				goto DONE_ERROR;
			}

			if ((m_wTargetLang)&&(!UpdateResource(m_hUpdateRes, RT_MENU, MAKEINTRESOURCE(nID), wLanguage, NULL, 0)))
			{
				delete [] newMenu;
				goto DONE_ERROR;
			} 
			delete [] newMenu;
		}
		break;
	case 1:
		{
			offset = GET_WORD(p);
			p++;
			dwHelpId = GET_DWORD(p);
			size_t nMem = 0;
			if (!CountMemReplaceMenuExResource((WORD *)(p0 + offset), &nMem, NULL))
				goto DONE_ERROR;
			WORD * newMenu = new WORD[nMem + (nMem % 2) + 4];
			SecureZeroMemory(newMenu, (nMem + (nMem % 2) + 4) * 2);
			CopyMemory(newMenu, p0, 2 * sizeof(WORD) + sizeof(DWORD));
			size_t index = 4;		// MenuExHeader has 2 x WORD + 1 x DWORD
			if (!CountMemReplaceMenuExResource((WORD *)(p0 + offset), &index, newMenu))
			{
				delete [] newMenu;
				goto DONE_ERROR;
			} 

			if (!UpdateResource(m_hUpdateRes, RT_MENU, MAKEINTRESOURCE(nID), (m_wTargetLang ? m_wTargetLang : wLanguage), newMenu, (DWORD)(nMem + (nMem % 2) + 4) * 2))
			{
				delete [] newMenu;
				goto DONE_ERROR;
			}

			if ((m_wTargetLang)&&(!UpdateResource(m_hUpdateRes, RT_MENU, MAKEINTRESOURCE(nID), wLanguage, NULL, 0)))
			{
				delete [] newMenu;
				goto DONE_ERROR;
			} 
			delete [] newMenu;
		}
		break;
	default:
		goto DONE_ERROR;
	}

	UnlockResource(hglMenuTemplate);
	FreeResource(hglMenuTemplate);
	return TRUE;

DONE_ERROR:
	UnlockResource(hglMenuTemplate);
	FreeResource(hglMenuTemplate);
	MYERROR;
}
Ejemplo n.º 20
0
/**
* This can't be implemented directly with QT.
* (We can use QSound to play local files but that was not enough.
* Also support of media formats is limited)
*
* Current implementation is copied from GTK side and implementation uses ESD interface.
*
* If we have Qtopia then we can drop ESD implementation and use Qtopia "Multimedia API"
*/
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
                                        nsISupports *context,
                                        nsresult aStatus,
                                        PRUint32 dataLen,
                                        const PRUint8 *data)
{

#define GET_WORD(s, i) (s[i+1] << 8) | s[i]
#define GET_DWORD(s, i) (s[i+3] << 24) | (s[i+2] << 16) | (s[i+1] << 8) | s[i]

    // print a load error on bad status, and return
    if (NS_FAILED(aStatus)) {
#ifdef DEBUG
        if (aLoader) {
            nsCOMPtr<nsIRequest> request;
            aLoader->GetRequest(getter_AddRefs(request));
            if (request) {
                nsCOMPtr<nsIURI> uri;
                nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
                if (channel) {
                      channel->GetURI(getter_AddRefs(uri));
                      if (uri) {
                            nsCAutoString uriSpec;
                            uri->GetSpec(uriSpec);
                            printf("Failed to load %s\n", uriSpec.get());
                      }
                }
            }
        }
#endif
        return aStatus;
    }

    int fd, mask = 0;
    PRUint32 samples_per_sec = 0, avg_bytes_per_sec = 0, chunk_len = 0;
    PRUint16 format, channels = 1, bits_per_sample = 0;
    const PRUint8 *audio = nsnull;
    size_t audio_len = 0;

    if (dataLen < 4) {
        NS_WARNING("Sound stream too short to determine its type");
        return NS_ERROR_FAILURE;
    }

    if (memcmp(data, "RIFF", 4)) {
#ifdef DEBUG
        printf("We only support WAV files currently.\n");
#endif
        return NS_ERROR_FAILURE;
    }

    if (dataLen <= WAV_MIN_LENGTH) {
        NS_WARNING("WAV files should be longer than 44 bytes.");
        return NS_ERROR_FAILURE;
    }

    PRUint32 i = 12;
    while (i + 7 < dataLen) {
        if (!memcmp(data + i, "fmt ", 4) && !chunk_len) {
            i += 4;

            /* length of the rest of this subblock (should be 16 for PCM data */
            chunk_len = GET_DWORD(data, i);
            i += 4;

            if (chunk_len < 16 || i + chunk_len >= dataLen) {
                NS_WARNING("Invalid WAV file: bad fmt chunk.");
                return NS_ERROR_FAILURE;
            }

            format = GET_WORD(data, i);
            i += 2;

            channels = GET_WORD(data, i);
            i += 2;

            samples_per_sec = GET_DWORD(data, i);
            i += 4;

            avg_bytes_per_sec = GET_DWORD(data, i);
            i += 4;

            // block align
            i += 2;

            bits_per_sample = GET_WORD(data, i);
            i += 2;

            /* we don't support WAVs with odd compression codes */
            if (chunk_len != 16)
                NS_WARNING("Extra format bits found in WAV. Ignoring");

            i += chunk_len - 16;
        } else if (!memcmp(data + i, "data", 4)) {
            i += 4;
            if (!chunk_len) {
                NS_WARNING("Invalid WAV file: no fmt chunk found");
                return NS_ERROR_FAILURE;
            }

            audio_len = GET_DWORD(data, i);
            i += 4;

            /* try to play truncated WAVs */
            if (i + audio_len > dataLen)
                audio_len = dataLen - i;

            audio = data + i;
            break;
        } else {
            i += 4;
            i += GET_DWORD(data, i);
            i += 4;
        }
    }

    if (!audio) {
        NS_WARNING("Invalid WAV file: no data chunk found");
        return NS_ERROR_FAILURE;
    }

    /* No audio data? well, at least the WAV was valid. */
    if (!audio_len)
        return NS_OK;

#if 0
    printf("f: %d | c: %d | sps: %li | abps: %li | ba: %d | bps: %d | rate: %li\n",
         format, channels, samples_per_sec, avg_bytes_per_sec, block_align, bits_per_sample, rate);
#endif

    /* open up connection to esd */  
    EsdPlayStreamType EsdPlayStream = 
        (EsdPlayStreamType) PR_FindFunctionSymbol(elib, 
                                                  "esd_play_stream");
    if (!EsdPlayStream)
        return NS_ERROR_FAILURE;

    mask = ESD_PLAY | ESD_STREAM;

    if (bits_per_sample == 8)
        mask |= ESD_BITS8;
    else 
        mask |= ESD_BITS16;

    if (channels == 1)
        mask |= ESD_MONO;
    else 
        mask |= ESD_STEREO;

    nsAutoArrayPtr<PRUint8> buf;

    // ESD only handle little-endian data. 
    // Swap the byte order if we're on a big-endian architecture.
#ifdef IS_BIG_ENDIAN
    if (bits_per_sample != 8) {
        buf = new PRUint8[audio_len];
        if (!buf)
            return NS_ERROR_OUT_OF_MEMORY;
        for (PRUint32 j = 0; j + 2 < audio_len; j += 2) {
            buf[j]     = audio[j + 1];
            buf[j + 1] = audio[j];
        }

    audio = buf;
    }
#endif

    fd = (*EsdPlayStream)(mask, samples_per_sec, NULL, "mozillaSound"); 
  
    if (fd < 0) {
      int *esd_audio_format = (int *) PR_FindSymbol(elib, "esd_audio_format");
      int *esd_audio_rate = (int *) PR_FindSymbol(elib, "esd_audio_rate");
      EsdAudioOpenType EsdAudioOpen = (EsdAudioOpenType) PR_FindFunctionSymbol(elib, "esd_audio_open");
      EsdAudioWriteType EsdAudioWrite = (EsdAudioWriteType) PR_FindFunctionSymbol(elib, "esd_audio_write");
      EsdAudioCloseType EsdAudioClose = (EsdAudioCloseType) PR_FindFunctionSymbol(elib, "esd_audio_close");

      if (!esd_audio_format || !esd_audio_rate ||
          !EsdAudioOpen || !EsdAudioWrite || !EsdAudioClose)
          return NS_ERROR_FAILURE;

      *esd_audio_format = mask;
      *esd_audio_rate = samples_per_sec;
      fd = (*EsdAudioOpen)();

      if (fd < 0)
        return NS_ERROR_FAILURE;

      (*EsdAudioWrite)(audio, audio_len);
      (*EsdAudioClose)();
    } else {
      while (audio_len > 0) {
        size_t written = write(fd, audio, audio_len);
        if (written <= 0)
          break;
        audio += written;
        audio_len -= written;
      }
      close(fd);
    }

    return NS_OK;
}
Ejemplo n.º 21
0
const WORD* CResModule::ParseMenuExResource(const WORD * res)
{
	DWORD dwType, dwState, menuId;
	WORD bResInfo;
	LPCWSTR		str;
	WORD *p0;

	//struct MenuExItem {
	//    DWORD dwType;
	//    DWORD dwState;
	//    DWORD menuId;
	//    WORD bResInfo;
	//    WCHAR szText[];
	//    DWORD dwHelpId; - Popup menu only
	//};

	do
	{
		p0 = (WORD *)res;
		dwType = GET_DWORD(res);
		res += 2;
		dwState = GET_DWORD(res);
		res += 2;
		menuId = GET_DWORD(res);
		res += 2;
		bResInfo = GET_WORD(res);
		res++;

		str = (LPCWSTR)res;
		size_t l = wcslen(str)+1;
		res += l;
		// Align to DWORD boundary
		res += ((((WORD)res + 3) & ~3) - (WORD)res)/sizeof(WORD);

		if (dwType & MFT_SEPARATOR)
			continue;

		if (bResInfo & 0x01)
		{
			// Popup menu - note this can also have a non-zero ID
			if (menuId == 0)
				menuId = (WORD)-1;
			TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
			SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
			_tcscpy(pBuf, str);
			CUtils::StringExtend(pBuf);

			std::wstring wstr = std::wstring(pBuf);
			RESOURCEENTRY entry = m_StringEntries[wstr];
			// Popup has a DWORD help entry on a DWORD boundary - skip over it
			res += 2;

			entry.resourceIDs.insert(menuId);
			TCHAR szTempBuf[1024];
			_stprintf(szTempBuf, _T("#: MenuExPopupEntry; ID:%d"), menuId);
			MENUENTRY menu_entry;
			menu_entry.wID = (WORD)menuId;
			menu_entry.reference = szTempBuf;
			menu_entry.msgstr = wstr;
			m_StringEntries[wstr] = entry;
			m_MenuEntries[(WORD)menuId] = menu_entry;
			delete [] pBuf;

			if ((res = ParseMenuExResource(res)) == 0)
				return NULL;
		} else if (menuId != 0)
		{
			TCHAR * pBuf = new TCHAR[MAX_STRING_LENGTH];
			SecureZeroMemory(pBuf, MAX_STRING_LENGTH * sizeof(TCHAR));
			_tcscpy(pBuf, str);
			CUtils::StringExtend(pBuf);

			std::wstring wstr = std::wstring(pBuf);
			RESOURCEENTRY entry = m_StringEntries[wstr];
			entry.resourceIDs.insert(menuId);

			TCHAR szTempBuf[1024];
			_stprintf(szTempBuf, _T("#: MenuExEntry; ID:%d"), menuId);
			MENUENTRY menu_entry;
			menu_entry.wID = (WORD)menuId;
			menu_entry.reference = szTempBuf;
			menu_entry.msgstr = wstr;
			m_StringEntries[wstr] = entry;
			m_MenuEntries[(WORD)menuId] = menu_entry;
			delete [] pBuf;
		}
	} while (!(bResInfo & 0x80));
	return res;
}
Ejemplo n.º 22
0
void debug_printf(void) {
    char buffer[4096];
    size_t maxlen = sizeof(buffer);

    int fp = GET_REG16(7)+2;
    const char *format = (char*) &memory[GET_WORD(fp)];
    fp += 2;

    char ch;
    long value;
    char *strvalue;
    int min;
    int max;
    int state;
    int flags;
    int cflags;
    size_t currlen;
    
    state = DP_S_DEFAULT;
    currlen = flags = cflags = min = 0;
    max = -1;
    ch = *format++;
    
    while (state != DP_S_DONE) {
	if (ch == '\0') 
	    state = DP_S_DONE;
	
	switch(state) {
	case DP_S_DEFAULT:
	    if (ch == '%') 
		state = DP_S_FLAGS;
	    else 
		dopr_outch (buffer, &currlen, maxlen, ch);
	    ch = *format++;
	    break;
	case DP_S_FLAGS:
	    switch (ch) {
	    case '-':
		flags |= DP_F_MINUS;
		ch = *format++;
		break;
	    case '+':
		flags |= DP_F_PLUS;
		ch = *format++;
		break;
	    case ' ':
		flags |= DP_F_SPACE;
		ch = *format++;
		break;
	    case '#':
		flags |= DP_F_NUM;
		ch = *format++;
		break;
	    case '0':
		flags |= DP_F_ZERO;
		ch = *format++;
		break;
	    default:
		state = DP_S_MIN;
		break;
	    }
	    break;
	case DP_S_MIN:
	    if (isdigit((unsigned char)ch)) {
		min = 10*min + char_to_int (ch);
		ch = *format++;
	    } else if (ch == '*') {
		min = (short) GET_WORD(fp);
		fp += 2;
		ch = *format++;
		state = DP_S_DOT;
	    } else {
		state = DP_S_DOT;
	    }
	    break;
	case DP_S_DOT:
	    if (ch == '.') {
		state = DP_S_MAX;
		ch = *format++;
	    } else { 
		state = DP_S_MOD;
	    }
	    break;
	case DP_S_MAX:
	    if (isdigit((unsigned char)ch)) {
		if (max < 0)
		    max = 0;
		max = 10*max + char_to_int (ch);
		ch = *format++;
	    } else if (ch == '*') {
		min = (short) GET_WORD(fp);
		fp += 2;
		ch = *format++;
		state = DP_S_MOD;
	    } else {
		state = DP_S_MOD;
	    }
	    break;
	case DP_S_MOD:
	    switch (ch) {
	    case 'h':
		cflags = DP_C_SHORT;
		ch = *format++;
		break;
	    case 'l':
		cflags = DP_C_LONG;
		ch = *format++;
		break;
	    default:
		break;
	    }
	    state = DP_S_CONV;
	    break;
	case DP_S_CONV:
	    switch (ch) {
	    case 'd':
	    case 'i':
		if (cflags == DP_C_LONG) {
		    value = ((int) (short) GET_WORD(fp)) << 16
			| GET_WORD(fp+2);
		    fp += 4;
		} else {
		    value = (short) GET_WORD(fp);
		    fp += 2;
		}
		fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
		break;
	    case 'o':
		flags |= DP_F_UNSIGNED;
		if (cflags == DP_C_LONG) {
		    value = ((unsigned int) GET_WORD(fp)) << 16
			| GET_WORD(fp+2);
		    fp += 4;
		} else {
		    value = GET_WORD(fp);
		    fp += 2;
		}
		fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
		break;
	    case 'u':
		flags |= DP_F_UNSIGNED;
		if (cflags == DP_C_LONG) {
		    value = ((unsigned int) GET_WORD(fp)) << 16
			| GET_WORD(fp+2);
		    fp += 4;
		} else {
		    value = GET_WORD(fp);
		    fp += 2;
		}
		fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
		break;
	    case 'X':
		flags |= DP_F_UP;
	    case 'x':
		flags |= DP_F_UNSIGNED;
		if (cflags == DP_C_LONG) {
		    value = ((unsigned int) GET_WORD(fp)) << 16
			| GET_WORD(fp+2);
		    fp += 4;
		} else {
		    value = GET_WORD(fp);
		    fp += 2;
		}
		fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
		break;
	    case 'c':
		dopr_outch (buffer, &currlen, maxlen, 
			    (int)(short)GET_WORD(fp));
		fp += 2;
		break;
	    case 's':
		{
		    int addr = GET_WORD(fp);
		    strvalue = (char*) &memory[addr];
		    if (!addr) 
			strvalue = "(NULL)";
		    if (max == -1) {
			max = strlen(strvalue);
		    }
		    if (min > 0 && max >= 0 && min > max) max = min;
		    fmtstr (buffer, &currlen, maxlen, strvalue, flags, 
			    min, max);
		}
		break;
	    case 'p':
		value = GET_WORD(fp);
		fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
		break;
	    case '%':
		dopr_outch (buffer, &currlen, maxlen, ch);
		break;
	    default:
		/* Unknown, skip */
		break;
	    }
	    ch = *format++;
	    state = DP_S_DEFAULT;
	    flags = cflags = min = 0;
	    max = -1;
	    break;
	case DP_S_DONE:
	    break;
	default:
	    /* hmm? */
	    break; /* some picky compilers need this */
	}
    }
    if (maxlen != 0) {
	if (currlen < maxlen - 1) 
	    buffer[currlen] = '\0';
	else if (maxlen > 0) 
	    buffer[maxlen - 1] = '\0';
    }
    
    printf("Program said: `%s'\n", buffer);
}