예제 #1
0
static unsigned long int _stol( const CHAR_TYPE *nptr,CHAR_TYPE **endptr,int base,int who)
    {
        const CHAR_TYPE *p;
        const CHAR_TYPE *startp;
        int digit;
        unsigned long int value;
        unsigned long int prev_value;
        CHAR_TYPE sign;
        char overflow;          /*overflow is used as a flag so it does not
                                 *need to be of type CHAR_TYPE */

        if( endptr != NULL ) *endptr = (CHAR_TYPE *)nptr;
        p = nptr;
        while( __F_NAME(isspace,iswspace)(*p) ) ++p;
        sign = *p;
        if( sign == '+'  ||  sign == '-' ) ++p;
        if( base == 0 ) {
            if( hexstr(p) )      base = 16;
            else if( *p == '0' ) base = 8;
            else                 base = 10;
        }
        if( base < 2  ||  base > 36 ) {
            __set_errno( EDOM );
            return( 0 );
        }
        if( base == 16 ) {
            if( hexstr(p) )  p += 2;    /* skip over '0x' */
        }
        startp = p;
        overflow = 0;
        value = 0;
        for(;;) {
            digit = radix_value( *p );
            if( digit >= base ) break;
            if( value > nearly_overflowing[base-2] ) overflow = 1;
            prev_value = value;
            value = value * base + digit;
            if( value < prev_value ) overflow = 1;
            ++p;
        }
        if( p == startp )  p = nptr;
        if( endptr != NULL ) *endptr = (CHAR_TYPE *)p;
        if( who == 1 ) {
            if( value >= 0x80000000 ) {
                if( value == 0x80000000  &&  sign == '-' ) {
                    ;  /* OK */
                } else {
                    overflow = 1;
                }
            }
        }
        if( overflow ) {
            __set_errno( ERANGE );
            if( who == 0 )     return( ULONG_MAX );
            if( sign == '-' )  return( LONG_MIN );
            return( LONG_MAX );
        }
        if( sign == '-' )  value = - value;
        return( value );
    }
예제 #2
0
paddr_t
strtopaddr(const char *nptr, char **endptr, int base) {
	const char	*p;
	const char	*startp;
	int 		digit;
	paddr_t		value;

	if(endptr != NULL) *endptr = (char *)nptr;
	p = nptr;
	if(base == 0) {
	    if(hexstr(p))	 base = 16;
	    else if(*p == '0') base = 8;
	    else		 base = 10;
	}
	if(base == 16) {
	    if(hexstr(p))  p += 2;	/* skip over '0x' */
	}
	startp = p;
	value = 0;
	for(;;) {
	    digit = radix_value(*p);
	    if(digit >= base) break;
	    value = value * base + digit;
	    ++p;
	}
	if(p == startp)  p = nptr;
	if(endptr != NULL) *endptr = (char *)p;
	return value;
}
예제 #3
0
파일: simpleprng.c 프로젝트: ahqmhjk/amanda
gboolean simpleprng_verify_buffer(
    simpleprng_state_t *state,
    gpointer buf,
    size_t len)
{
    guint8 *p = buf;
    while (len--) {
	guint64 count = state->count;
	guint8 expected = simpleprng_rand_byte(state);
	guint8 got = *p;
	if (expected != got) {
	    int remaining = MIN(len, 16);
	    guint8 expbytes[16] = { expected };
	    char *gotstr = hexstr(p, remaining);
	    char *expstr;
	    int i;

	    for (i = 1; i < remaining; i++)
		expbytes[i] = simpleprng_rand_byte(state);
	    expstr = hexstr(expbytes, remaining);

	    g_fprintf(stderr,
		    "random value mismatch at offset %ju: got %s, expected %s\n",
		    (uintmax_t)count, gotstr, expstr);
	    g_free(gotstr);
	    g_free(expstr);
	    return FALSE;
	}
	p++;
    }

    return TRUE;
}
예제 #4
0
VOID PageTest()
{
    ADDRINT addr = 0x123456;
    string pageAddr1 = hexstr(GetPageOfAddr(addr));
    string pageAddr2 = ptrstr(MemPageRange((void*)addr).Base());
    TEST(pageAddr1 == pageAddr2, "GetPageOfAddr or MemPageRange failed");
}
예제 #5
0
void
load_file_ino(ino32_t ino, const char *fn, uintptr_t loadadr, unsigned interactive, int part)
	/* fn:		 for message only */
{
	union ufs_dinode dinode;
	size_t sz;
	struct loadinfo inf;
	char buf[32];

	if (ino == 0 || ufs_get_inode(ino, &dinode))
		return;		/* not found */

	print(str_loading);		/* "loading " */
	print(fn);
	print(str_at);			/* " at 0x" */
	print(hexstr(buf, loadadr));
	print(str_dddot);		/* "..." */

	sz = DI_SIZE(&dinode);
	ufs_read(&dinode, (void *) loadadr, 0, sz);

	print(str_done);		/* "done\r\n" */

	/* digest executable format */
	inf.sec_size = sz;
	inf.entry_offset = 0;
	if (xi_load(&inf, (void *) loadadr)) {
		print(fn);
		print(str_ukfmt); /* ": unknown format -- exec from top\r\n" */
	}

	/* pass control to the secondary boot */
	dispatch(interactive, loadadr, loadadr + inf.sec_size, part,
	    loadadr + inf.entry_offset);
}
예제 #6
0
파일: dev.c 프로젝트: vrthra/9front-tmp
static int
cmdreq(Dev *d, int type, int req, int value, int index, uchar *data, int count)
{
	int ndata, n;
	uchar *wp;
	uchar buf[8];
	char *hd, *rs;

	assert(d != nil);
	if(data == nil){
		wp = buf;
		ndata = 0;
	}else{
		ndata = count;
		wp = emallocz(8+ndata, 0);
	}
	wp[0] = type;
	wp[1] = req;
	PUT2(wp+2, value);
	PUT2(wp+4, index);
	PUT2(wp+6, count);
	if(data != nil)
		memmove(wp+8, data, ndata);
	if(usbdebug>2){
		hd = hexstr(wp, ndata+8);
		rs = reqstr(type, req);
		fprint(2, "%s: %s val %d|%d idx %d cnt %d out[%d] %s\n",
			d->dir, rs, value>>8, value&0xFF,
			index, count, ndata+8, hd);
		free(hd);
	}
static VOID foo_after(ADDRINT returnIp)
{
	printf("foo after called\n");

    // May not be executed if exception occurs in previous statement
    printf("Caller IP = %s\n", hexstr(returnIp).c_str());
}
예제 #8
0
파일: dump.c 프로젝트: bhanug/harvey
static char*
seprintconf(char *s, char *e, Usbdev *d, int ci)
{
	int i;
	Conf *c;
	char *hd;

	c = d->conf[ci];
	s = seprint(s, e, "\tconf: cval %d attrib %x %d mA\n",
		c->cval, c->attrib, c->milliamps);
	for(i = 0; i < Niface; i++)
		if(c->iface[i] == nil)
			break;
		else
			s = seprintiface(s, e, c->iface[i]);
	for(i = 0; i < Nddesc; i++)
		if(d->ddesc[i] == nil)
			break;
		else if(d->ddesc[i]->conf == c){
			hd = hexstr((uint8_t*)&d->ddesc[i]->data,
				d->ddesc[i]->data.bLength);
			s = seprint(s, e, "\t\tdev desc %x[%d]: %s\n",
				d->ddesc[i]->data.bDescriptorType,
				d->ddesc[i]->data.bLength, hd);
			free(hd);
		}
	return s;
}
예제 #9
0
int quoted(char **pp)	/* pick up next thing after a \\ */
/* and increment *pp */
{
    char *p = *pp;
    int c;

    if ((c = *p++) == 't')
        c = '\t';
    else if (c == 'n')
        c = '\n';
    else if (c == 'f')
        c = '\f';
    else if (c == 'r')
        c = '\r';
    else if (c == 'b')
        c = '\b';
    else if (c == '\\')
        c = '\\';
    else if (c == 'x') {	/* hexadecimal goo follows */
        c = hexstr(&p);	/* this adds a null if number is invalid */
    } else if (isoctdigit(c)) {	/* \d \dd \ddd */
        int n = c - '0';
        if (isoctdigit(*p)) {
            n = 8 * n + *p++ - '0';
            if (isoctdigit(*p))
                n = 8 * n + *p++ - '0';
        }
        c = n;
    } /* else */
    /* c = c; */
    *pp = p;
    return c;
}
예제 #10
0
VOID CheckFlagsNoInline(ADDRINT app_flags)
{
    if ((app_flags & FLAGSET) != FLAGSET)
    {
        cerr << "Noinline failed: app_flags= " << hexstr(app_flags) << endl;
        exit(-1);
    }
}
예제 #11
0
string StringUtil::toHEX(unsigned int number)
{
	char hexVal[20];
	sprintf(hexVal, "%x", number);
	string hexstr(hexVal);
	memset(&hexVal[0], 0, sizeof(hexVal));
	return hexstr;
}
예제 #12
0
string StringUtil::toOCTAL(unsigned long long number)
{
	char hexVal[20];
	sprintf(hexVal, "%llo", number);
	string hexstr(hexVal);
	memset(&hexVal[0], 0, sizeof(hexVal));
	return hexstr;
}
예제 #13
0
// protect a page read-only
VOID SANDBOX::ProtectPage(const char * page)
{
    int result = mprotect(const_cast<char *>(page), PageSize, PROT_READ);

    if (result != 0)
    {
        Error("Can't read-protect page " + hexstr(page) + "\n" + strerror(errno));
    }
}
예제 #14
0
/* We simply allocate space for the dis-assembled instruction strings and 
 * let them leak.
 */
static char const * formatInstruction(INS ins)
{
    ADDRINT ip = INS_Address(ins);
    string formatted = hexstr(ip) + " " + INS_Disassemble(ins);
    char * res = new char [formatted.length()+1];

    strcpy (res, formatted.c_str());
    
    return res;
}
예제 #15
0
// check bytes in given address range
VOID SANDBOX::CheckAddressRange(const char * beginAddr, const char * endAddr)
{
    const char * beginPage = Addr2Page(beginAddr);
    const char * endPage = Addr2Page(endAddr);

    for (const char * page = beginPage; page <= endPage; page += PageSize)
    {
        const char * pageEnd = page + PageSize - 1;
        const char * beginCheckAddr = beginAddr > page ? beginAddr : page;
        const char * endCheckAddr = endAddr < pageEnd ? endAddr : pageEnd;
        size_t size = endCheckAddr - beginCheckAddr + 1;

        const char * pageFrameStart = _pages[page];
        if (pageFrameStart == NULL)
        {
            // note: this might also trigger if PIN has not found all the code
            // of a routine
            Error("Instruction address range " + hexstr(beginCheckAddr) +
                    " - " + hexstr(endCheckAddr) + " was not found\n"
                  "during initial code discovery.\n" +
                  "\n"
                  "The application is trying to execute instructions which were not in\n"
                  "the original application.\n"
                  "This might be due to a buffer overflow.\n"
                  "\n"
                  "Terminating the application!\n");
        }
        const char * pageFrameBeginCheckAddr = pageFrameStart + Addr2Offset(beginCheckAddr);

        if (memcmp(beginCheckAddr, pageFrameBeginCheckAddr, size) != 0)
        {
            Error("Instruction address range " + hexstr(beginCheckAddr) +
                          " - " + hexstr(endCheckAddr) + " is corrupted.\n" +
                  "\n"
                  "The application code has been corrupted during execution.\n"
                  "This might be due to a buffer overflow.\n"
                  "\n"
                  "Terminating the application!\n");
        }
    }
}
예제 #16
0
파일: wchan.cpp 프로젝트: pmattern/qps
char *Wchan::find_sym(unsigned long addr)
{
    // use binary search to find symbol; return malloced string
    int l = 0, r = sysmap_size;
    for (;;)
    {
        unsigned long a;
        char buf[80];
        int m = (l + r) / 2;
        m = beginning_of_line(m);
        if (m == l)
        {
            // see if there is a line further down
            while (m < r - 1 && sysmap[m] != '\n')
                m++;
            if (m < r - 1)
            {
                m++;
            }
            else
            {
                if (r == sysmap_size)
                {
                    // after last item, probably in a
                    // module. give hex addr
                    return hexstr(addr);
                }
                m = l;
                sscanf(sysmap + m, "%lx %*c %s", &a, buf);
                // strip leading sys_ or do_ to reduce field
                // width
                char *p = buf;
                if (strncmp(buf, "do_", 3) == 0)
                    p += 3;
                if (strncmp(buf, "sys_", 4) == 0)
                    p += 4;
                return strdup(p);
            }
        }
        sscanf(sysmap + m, "%lx %*c %s", &a, buf);
        if (addr < a)
        {
            r = m;
        }
        else
        {
            l = m;
        }
    }
}
예제 #17
0
파일: audio.c 프로젝트: CoryXie/nix-os
static void
audio_endpoint(Dev *, Desc *dd)
{
	byte *b = (uchar*)&dd->data;
	int n = dd->data.bLength;
	char *hd;

	switch(b[2]){
	case 0x01:
		if(usbdebug){
			fprint(2, "CS_ENDPOINT for attributes 0x%x, lockdelayunits %d, lockdelay %#ux, ",
				b[3], b[4], b[5] | (b[6]<<8));
			if(b[3] & has_setspeed)
				fprint(2, "has sampling-frequency control");
			else
				fprint(2, "does not have sampling-frequency control");
			if(b[3] & 0x1<<1)
				fprint(2, ", has pitch control");
			else
				fprint(2, ", does not have pitch control");
			if(b[3] & 0x1<<7)
				fprint(2, ", max packets only");
			fprint(2, "\n");
		}
		if(dd->conf == nil)
			sysfatal("conf == nil");
		if(dd->iface == nil)
			sysfatal("iface == nil");
		if(dd->altc == nil)
			sysfatal("alt == nil");
		if(dd->altc->aux == nil)
			dd->altc->aux= mallocz(sizeof(Audioalt),1);
		((Audioalt*)dd->altc->aux)->caps |= b[3];
		break;
	case 0x02:
		if(usbdebug){
			fprint(2, "CS_INTERFACE FORMAT_TYPE %d, channels %d, subframesize %d, resolution %d, freqtype %d, ",
				b[3], b[4], b[5], b[6], b[7]);
			fprint(2, "freq0 %d, freq1 %d\n",
				b[8] | (b[9]<<8) | (b[10]<<16), b[11] | (b[12]<<8) | (b[13]<<16));
		}
		break;
	default:
		if(usbdebug){
			hd = hexstr(b, n);
			fprint(2, "CS_INTERFACE: %s\n", hd);
			free(hd);
		}
	}
}
예제 #18
0
파일: re.c 프로젝트: carriercomm/legacy
void
quoted(char **s, char **to, char *end)	/* handle escaped sequence */
{
	char *p = *s;
	char *t = *to;
	wchar_t c;

	switch(c = *p++) {
	case 't':
		c = '\t';
		break;
	case 'n':
		c = '\n';
		break;
	case 'f':
		c = '\f';
		break;
	case 'r':
		c = '\r';
		break;
	case 'b':
		c = '\b';
		break;
	default:
		if (t < end-1)		/* all else must be escaped */
			*t++ = '\\';
		if (c == 'x') {		/* hexadecimal goo follows */
			c = hexstr(&p);
			if (t < end-MB_CUR_MAX)
				t += wctomb(t, c);
			else overflow();
			*to = t;
			*s = p;
			return;
		} else if (isoctdigit(c)) {	/* \d \dd \ddd */
			c -= '0';
			if (isoctdigit(*p)) {
				c = 8 * c + *p++ - '0';
				if (isoctdigit(*p))
					c = 8 * c + *p++ - '0';
			}
		}
		break;
	}
	if (t < end-1)
		*t++ = c;
	*s = p;
	*to = t;
}
예제 #19
0
void
dumpmem(int *ptr, int sz, int ustack)
{
	int i, val;

	for (i = 0; i < sz; i++) {
		if ((i & 7) == 0)
			printf("\n%s: ", hexstr((int)ptr, 6));
		else
			printf(" ");
/*
		if (ustack == 1) {
			if ((val = fuword(ptr++)) == -1)
				break;
		} else {
			if (ustack == 0 && (ptr < KSADDR || ptr > KSADDR+(NBPG/4-1)))
				break;
*/
			val = *ptr++;
/*		}	*/
		printf("%s", hexstr(val, 8));
	}
	printf("\n");
}
예제 #20
0
파일: XPortTTY.c 프로젝트: XPila/HW
int XPortTTY_Tx(SXPortTTY* pPort, void* pData, int iSize)
{
	if (!pPort) return -1;
	int iTx = write(pPort->iFile, pData, iSize);
	fsync(pPort->iFile);
	if (XPortTTY_LogFile)
	{
		char* pcHex = hexstr(pData, iSize);
		if (iTx == iSize)
			fprintf((FILE*)XPortTTY_LogFile, "TTY Tx %d %s\n", iSize, pcHex);
		else
			fprintf((FILE*)XPortTTY_LogFile, "TTY Tx Err %d %s (tx=%d)\n", iSize, pcHex, iTx);
		free(pcHex);
	}
	return iTx;
}
예제 #21
0
void
regdump(int *rp /* must not be register */, int sbytes)
{
	static int doingdump = 0;
	int i;
	int s;

	if (doingdump)
		return;
	s = splhigh();
	doingdump = 1;
/*	printf("pid = %d, pc = %s, ", u.u_procp->p_pid, hexstr(rp[PC], 8));	*/
	printf("pc = %s, ", hexstr(rp[PC], 8));
	printf("ps = %s, ", hexstr(rp[PS], 4));
	printf("sfc = %s, ", hexstr(getsfc(), 4));
	printf("dfc = %s\n", hexstr(getdfc(), 4));
/*
	printf("p0 = %x@%s, ",
	       u.u_pcb.pcb_p0lr, hexstr((int)u.u_pcb.pcb_p0br, 8));
	printf("p1 = %x@%s\n\n",
	       u.u_pcb.pcb_p1lr, hexstr((int)u.u_pcb.pcb_p1br, 8));
*/
	printf("Registers:\n     ");
	for (i = 0; i < 8; i++)
		printf("        %d", i);
	printf("\ndreg:");
	for (i = 0; i < 8; i++)
		printf(" %s", hexstr(rp[i], 8));
	printf("\nareg:");
	for (i = 0; i < 8; i++)
		printf(" %s", hexstr(rp[i+8], 8));
	if (sbytes > 0) {
/*		if (rp[PS] & PSL_S) {	*/
			printf("\n\nKernel stack (%s):",
			       hexstr((int)(((int *)&rp)-1), 8));
			dumpmem(((int *)&rp)-1, sbytes, 0);
/*
		} else {
			printf("\n\nUser stack (%s):", hexstr(rp[SP], 8));
			dumpmem((int *)rp[SP], sbytes, 1);
		}
*/
	}
	doingdump = 0;
	splx(s);
}
예제 #22
0
static int checkSyscalls(BOOL verbose)
{
    int successes = 0;

    if (verbose)
    {
        cerr << "Key   Call" << endl;
    }

    for (UINT32 key = SYSCALL_KEY_FIRST; key < SYSCALL_KEY_END; key++)
    {
        UINT32 syscallNumber = PIN_GetWindowsSyscallFromKey (SYSCALL_KEY(key));

        if (verbose)
        {
            cerr << decstr(key,3) << "   " << hexstr(syscallNumber,4) << endl;
        }

        // Some system calls are not available on some versions of the OS,
        // e.g.
        //    NtCreateUserProcess is only available on Vista (and later)
        //    NtCreateThreadEx    is only available on Vista (and later)
        if (syscallNumber == SYSCALL_NUMBER_INVALID)
        {
            continue;
        }

        SYSCALL_KEY secondKey = PIN_GetKeyFromWindowsSyscall(syscallNumber);

        if (secondKey != key)
        {
            continue;
        }

        successes++;
    }

    return successes;
}
예제 #23
0
파일: XPortTTY.c 프로젝트: XPila/HW
int XPortTTY_Rx(SXPortTTY* pPort, void* pData, int iSize)
{
	if (!pPort) return -1;
	int iRx = read(pPort->iFile, pData, iSize);
	int iCnt = iRx;
	if ((iCnt > 0) && (iCnt < iSize))
		while (iCnt < iSize)
			if ((iRx = read(pPort->iFile, pData + iCnt, iSize - iCnt)) <= 0) break;
			else iCnt += iRx;
	if (XPortTTY_LogFile)
	{
		char* pcHex = hexstr(pData, iSize);
		pcHex[2*iCnt] = 0;
		fprintf((FILE*)XPortTTY_LogFile, "TTY Rx %d %s (cnt=%d rx=%d)\n", iSize, pcHex, iCnt, iRx);
//		if (iHub == iRx == iSize)
//			fprintf((FILE*)XHub_LogFile, "HUB%d Rx %d %s\n", pPort - pPort->pHub->sPort, iSize, pcHex);
//		else
//			fprintf((FILE*)XHub_LogFile, "HUB%d Rx Err %d %s (tx=%d hub=%d)\n", pPort - pPort->pHub->sPort, iSize, pcHex, iRx, iHub);
		free(pcHex);
	}
	return iCnt;
}
예제 #24
0
// allocate a new page
const char * SANDBOX::AllocatePage(const char * page)
{
    
    const char * pageFrameStart = reinterpret_cast<const char *>
#if defined(TARGET_MAC)
    // Mac OS
        (mmap(0, PageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0));
#else
    // linux
        (mmap(0, PageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
#endif


    if (pageFrameStart == MAP_FAILED)
    {
        Error("Can't get page frame for page " + hexstr(page) + "\n" + strerror(errno));
    }

    _pages[page] = pageFrameStart;

    return pageFrameStart;
}
예제 #25
0
파일: misc1.cpp 프로젝트: aladur/flexemu
std::string tohexstr(Word x)
{
    return std::string(hexstr(x));
}
예제 #26
0
파일: misc1.cpp 프로젝트: aladur/flexemu
std::string tohexstr(Byte x)
{
    return std::string(hexstr(x));
}
예제 #27
0
파일: audiosub.c 프로젝트: bhanug/harvey
void
audio_interface(Dev *_1, Desc *dd)
{
	byte *b = (uint8_t*)&dd->data;
	byte *bb = b;
	int nb = dd->data.bLength;
	int ctl, ch, u, x;
	byte *p;
	int class, subclass;
	Audioalt *aa;
	char *hd;

	class = Class(dd->iface->csp);
	subclass = Subclass(dd->iface->csp);

	dprint(2, "%d.%d: ", class, subclass);
	switch (subclass){
	case 1:	// control
		switch (b[2]){
		case 0x01:
			dprint(2, "Class-Specific AC Interface Header Descriptor\n");
			dprint(2, "\tAudioDevClass release (bcd)%c%c%c%c, "
				"TotalLength %d, InCollection %d aInterfaceNr %d\n",
					'0'+((b[4]>>4)&0xf), '0'+(b[4]&0xf),
					'0'+((b[3]>>4)&0xf), '0'+(b[3]&0xf),
					b[5]|(b[6]<<8), b[7], b[8]);
			break;
		case 0x02:	// input
			dprint(2, "Audio Input Terminal Descriptor\n");
			dprint(2, "\tbTerminalId %d, wTerminalType "
				"0x%x (%s), bAssocTerminal %d bNrChannels %d, "
				"wChannelConfig %d, iChannelNames %d iTerminal %d\n",
					b[3], b[4]|(b[5]<<8),
					namefor(terminal_types, b[4]|(b[5]<<8)),
					b[6], b[7], b[8]|(b[9]<<8), b[10], b[11]);
			if((b[4]|b[5]<<8) == 0x101){
				if(verbose)
					fprint(2, "Audio output unit %d\n", b[3]);
				/* USB streaming input: play interface */
				units[Play][nunits[Play]++] = b[3];
			}else{
				if(verbose)
					fprint(2, "Dev can record from %s\n",
						namefor(terminal_types, b[4]|(b[5]<<8)));
				/* Non-USB input: record interface */
				units[Record][nunits[Record]++] = b[3];
			}
			break;
		case 0x03:	// output
			if(usbdebug){
				fprint(2, "Audio Output Terminal Descriptor\n");
				fprint(2, "\tbTerminalId %d, wTerminalType 0x%x (%s), bAssocTerminal %d bSourceId %d, iTerminal %d\n",
					b[3], b[4]|(b[5]<<8),
					namefor(terminal_types, b[4]|(b[5]<<8)),
					b[6], b[7], b[8]);
			}
			if((b[4]|b[5]<<8) == 0x101){
				if(verbose)
					fprint(2, "Audio input unit %d\n", b[3]);
				/* USB streaming output: record interface */
				units[Record][nunits[Record]++] = b[3];
				if(verbose)
					fprint(2, "Dev can play to %s\n",
						namefor(terminal_types, b[4]|(b[5]<<8)));
				/* Non-USB output: play interface */
				units[Play][nunits[Play]++] = b[3];
			}
			break;
		case 0x04:
			if(verbose)
				fprint(2, "Audio Mixer Unit %d\n", b[3]);
			if(usbdebug){
				fprint(2, "\t%d bytes:", nb);
				for(ctl = 0; ctl < nb; ctl++)
					fprint(2, " 0x%2.2x", b[ctl]);
				fprint(2, "\n\tbUnitId %d, bNrInPins %d", b[3], b[4]);
			}
			if(b[4]){
				dprint(2, ", baSourceIDs: [%d", b[5]);
				u = findunit(b[5]);
				for(ctl = 1; ctl < b[4]; ctl++){
					if(u < 0)
						u = findunit(b[5+ctl]);
					else if((x = findunit(b[5+ctl])) >= 0 && u != x && verbose)
						fprint(2, "\tMixer %d for I & O \n", b[3]);
					dprint(2, ", %d", b[5+ctl]);
				}
				dprint(2, "]\n");
				if(u >= 0){
					units[u][nunits[u]++] = b[3];
					if(mixerid[u] >= 0)
						fprint(2, "Second mixer (%d, %d) on %s\n",
						 mixerid[u], b[3], u?"record":"playback");
					mixerid[u] = b[3];
				}
				if(usbdebug){
					fprint(2, "Channels %d, config %d, ",
						b[ctl+5], b[ctl+5+1] | b[ctl+5+2] << 8);
					x = b[ctl+5] * b[4];
					fprint(2, "programmable: %d bits, 0x", x);
					x = (x + 7) >> 3;
					while(x--)
						fprint(2, "%2.2x", b[ctl+x+5+4]);
				}
			}
			break;
		case 0x05:
			if(verbose)
				fprint(2, "Audio Selector Unit %d\n", b[3]);
			dprint(2, "\tbUnitId %d, bNrInPins %d", b[3], b[4]);
			if(b[4]){
				u = findunit(b[5]);
				dprint(2, ", baSourceIDs: %s [%d",
					u?"record":"playback", b[5]);
				for(ctl = 1; ctl < b[4]; ctl++){
					if(u < 0)
						u = findunit(b[5+ctl]);
					else if((x = findunit(b[5+ctl])) >= 0 &&
						u != x && verbose)
						fprint(2, "\tSelector %d for I & O\n", b[3]);
					dprint(2, ", %d", b[5+ctl]);
				}
				dprint(2, "]\n");
				if(u >= 0){
					units[u][nunits[u]++] = b[3];
					if(selectorid[u] >= 0)
						fprint(2, "Second selector (%d, %d) on %s\n", selectorid[u], b[3], u?"record":"playback");
					selectorid[u] = b[3];
					controls[u][Selector_control].readable = 1;
					controls[u][Selector_control].settable = 1;
					controls[u][Selector_control].chans = 0;
				}
			}
			break;
		case 0x06:	// feature
			if(verbose) fprint(2, "Audio Feature Unit %d", b[3]);
			dprint(2, "\tbUnitId %d, bSourceId %d, bControlSize %d\n",
				b[3], b[4], b[5]);
			u = findunit(b[4]);
			if(u >= 0){
				if(verbose) fprint(2, " for %s\n", u?"Record":"Playback");
				units[u][nunits[u]++] = b[3];
				if(featureid[u] >= 0)
					if(verbose)
						fprint(2, "Second feature unit (%d, %d)"
							" on %s\n", featureid[u], b[3],
							u?"record":"playback");
				featureid[u] = b[3];
			}else
				if(verbose) fprint(2, ", not known what for\n");
			p = b + 6;
			for(ctl = 1; ctl < 0x0b; ctl++)
				if((1<<(ctl-1)) & (b[6] | ((b[5]>1)?(b[7]<<8):0))){
					if(verbose)
						fprint(2, "\t%s control on master channel\n",
							controls[0][ctl].name);
					if(u >= 0){
						controls[u][ctl].readable = 1;
						controls[u][ctl].settable = 1;
						controls[u][ctl].chans = 0;
					}
				}
			p += (b[5]>1)?2:1;
			for(ch = 0; ch < (nb - 8)/b[5]; ch++){
				for(ctl = 1; ctl < 0x0b; ctl++)
					if((1<<(ctl-1)) & (p[0] | ((b[5]>1)?(p[1]<<8):0))){
						if(verbose)
						  fprint(2, "\t%s control on channel %d\n",
							controls[0][ctl].name, ch+1);
						if(u >= 0){
							controls[u][ctl].readable = 1;
							controls[u][ctl].settable = 1;
							controls[u][ctl].chans |= 1 <<(ch+1);
						}
					}
				p += (b[5]>1)?2:1;
			}
			break;
		default:
			hd = hexstr(bb, nb);
			fprint(2, "audio control unknown: %s\n", hd);
			free(hd);
		}
		break;
	case 2: // stream
		switch (b[2]){
		case 0x01:
			dprint(2, "Audio stream for TerminalID %d, delay %d, format_tag %#ux\n",
				b[3], b[4], b[5] | (b[6]<<8));
			break;
		case 0x02:
			aa = (Audioalt *)dd->altc->aux;
			if(aa == nil){
				aa = mallocz(sizeof(Audioalt), 1);
				dd->altc->aux = aa;
			}
			if(verbose){
				if(b[4] <= 2)
					fprint(2, "Interface %d: %s, %d bits, ",
						dd->iface->id, (b[4] == 1)?"mono":"stereo", b[6]);
				else
					fprint(2, "Interface %d, %d channels, %d bits, ",
						dd->iface->id, b[4], b[6]);
			}
			if(b[7] == 0){
				if(verbose)
					fprint(2, "frequency variable between %d and %d\n",
						b[8] | b[9]<<8 | b[10]<<16, b[11] | b[12]<<8 | b[13]<<16);
				aa->minfreq = b[8] | b[9]<<8 | b[10]<<16;
				aa->maxfreq = b[11] | b[12]<<8 | b[13]<<16;
				aa->caps |= has_contfreq;
			}else{
				if(verbose)
					fprint(2, "discrete frequencies are:");
				for(ch = 0; ch < b[7] && ch < 8; ch++){
					aa->freqs[ch] = b[8+3*ch] | b[9+3*ch]<<8 | b[10+3*ch]<<16;
					if(verbose)
						fprint(2, " %d", b[8+3*ch] | b[9+3*ch]<<8 | b[10+3*ch]<<16);
				}
				if(ch < 8)
					aa->freqs[ch] = -1;
				if(verbose)
					fprint(2, "\n");
				if(ch > 1)
					aa->caps |= has_discfreq;	/* more than one frequency */
				else
					aa->caps |= onefreq;		/* only one frequency */
			}
			aa->nchan = b[4];
			aa->res = b[6];
			aa->subframesize = b[5];
			break;
		default:
			if(usbdebug){
				hd = hexstr(bb, nb);
				fprint(2, "audio stream unknown: %s\n", hd);
				free(hd);
			}
		}
		break;
	case 3: // midi
	default:
		if(usbdebug){
			hd = hexstr(bb, nb);
			fprint(2, "Unknown audio stream type: CS_INTERFACE: %s\n", hd);
			free(hd);
		}
	}
}
// Replay the image log.
// We run this before the each instruction of the code as an analysis routine.
// So we eat up the image loads one instruction at a time!
// We can also call it before PIN_StartProgram, to check that queuing
// the replay calls up works.
//
static void ReplayImageEntry()
{
    if (feof(imgLog))
        return;

    char tag = fgetc(imgLog);
    switch (tag)
    {
        case 'L':
            {
                string imageName;
                ADDRINT startAddr;
                ADDRINT offset;
                USIZE size;
                BOOL mainExe;
                vector<RTN_INFO> rtns;

                ParseImageLoadLine(imageName, &startAddr, &size, &offset, &mainExe, &rtns);
                if (KnobVerbose)
                    fprintf (stderr, "Replaying load for %s, address: %llx offset: %llx, size: %lx\n", imageName.c_str(), (unsigned long long)startAddr, (unsigned long long)offset, (long)size);
                
                // Create a temporary IMG object
                IMG img = IMG_CreateAt(imageName.c_str(), startAddr, size, offset, mainExe);
                ASSERT(IMG_Valid(img), "IMG_CreateAt for " + imageName + " is invalid");

                // Populate the IMG object with recorded RTNs
                PIN_LockClient();

                for (vector<RTN_INFO>::iterator it = rtns.begin(); it < rtns.end(); it++)
                {
                    RTN rtn = RTN_CreateAt(it->startAddr, it->name);
                    ASSERT(RTN_Valid(rtn), "Failed to create RTN " + it->name + " at address " + hexstr(it->startAddr));
                }

                // And, finally, inform Pin that it is all there, which will invoke
                // image load callbacks.
                IMG_ReplayImageLoad(img);

                PIN_UnlockClient();
                break;
            }
        case 'U':
            {
                string imageName;
                ParseImageUnloadLine(imageName);
                
                IMG img = FindNamedImg(imageName);
                if (KnobVerbose)
                    fprintf (stderr, "Replaying unload for %s\n", imageName.c_str());
                // And, finally, inform Pin that it has gone, which will invoke
                // image unload callbacks.
                PIN_LockClient();
                PIN_ReplayImageUnload(img);
                PIN_UnlockClient();
                break;
            }            
        default:
            fprintf (trace, "Unexpected line in log file starting with '%c'\n", tag);
            exit(1);
    }
}
예제 #29
0
int
fsrestore(int argc, char *argv[])
{
    int i, j, status;
    int block, bytes;
    int blk, nblks, size, mark;
    struct	partition *pp;

    printf("Current SCSI device = ID %d\n", scsi_device);
    getline("Is it sure ? (y/n) ", cons_buf);

    if ((cons_buf[0] != 'y') && (cons_buf[0] != 'Y'))
        return ST_ERROR;

    st_rewind(rst0);

    st_skip(rst0);

    status = stread(rst0, index, LABEL_SIZE);

    st_skip(rst0);

    for (i = 0; i < MAXPARTITIONS; i++) {
        pp = &(lp->d_partitions[i]);
        if (pp->p_size > 0) {
            printf("%c: ", i + 'A');
            printf("size = %d(0x%s), ",
                   pp->p_size, hexstr(pp->p_size, 8));
            printf("offset = %d(0x%s)\n",
                   pp->p_offset, hexstr(pp->p_offset, 8));

            blk   = pp->p_offset;
            nblks = pp->p_size;
            size  = nblks << DEV_BSHIFT;

            block = BUF_BLOCK;
            bytes = BUF_BYTES;

            mark = nblks / block;
            if (nblks % block)
                mark++;
            for (j = 0; j < mark; j++)
                printf("-");
            for (j = 0; j < mark; j++)
                printf("%c", '\x08');

            while (nblks > 0) {
                if (nblks < block) {
                    block = nblks;
                    bytes = nblks << DEV_BSHIFT;
                }

                if (stread(rst0, dump_buf, bytes) != bytes) {
                    printf("tape read failed !!!\n");
                    return ST_ERROR;
                }

                if (!scsi_write(blk, dump_buf, bytes)) {
                    printf("disk write failed !!!\n");
                    return ST_ERROR;
                }

                blk   += block;
                nblks -= block;
                size  -= bytes;

                printf("#");
            }
            st_skip(rst0);
            printf("\n\n");
        }
    }
    return ST_NORMAL;
}
예제 #30
0
int
fsdump(int argc, char *argv[])
{
    int i, j, io;
    int status;
    int block, bytes;
    int scsi_id, blk, nblks, size, mark;
    struct stat boot_stat;
    struct	partition *pp;
    scsi_id = scsi_device;

    printf("Current SCSI device = ID %d\n", scsi_id);
    getline("Is it sure ? (y/n) ", cons_buf);

    if ((cons_buf[0] != 'y') && (cons_buf[0] != 'Y'))
        return ST_ERROR;

    scsi_read_raw(scsi_id, 0, 1, index, LABEL_SIZE);

    for (i = 0; i < MAXPARTITIONS; i++) {
        pp = &(lp->d_partitions[i]);
        if ((i != 0) &&
                (i != 3) &&
                (i != 4) &&
                (i != 5)) {
            pp->p_size = 0;
        }
        if (i == 5 && argc > 1 && !strcmp(argv[1], "tailor"))
            pp->p_size = 0;
    }

    st_rewind(rst0);

    printf("Boot Program		");
    io = open("sd(0,0)boot", 0);
    if (io >= 0) {
        printf("read ... ");
        size = read(io, dump_buf, 1048576);
        close(io);
        printf("%d bytes ... ", size);
        if (size <= 0) {
            printf("failed\n");
            return ST_ERROR;
        }
        boot_stat.st_size = size;
    }

    printf("write ... ");
    status = stwrite(rst0, dump_buf, size);
    st_write_EOF(rst0);

    if (status < size) {
        printf("failed\n");
        return ST_ERROR;
    }

    printf("done\n");

    printf("disklabel (index)\t");

    printf("write ... ");
    status = stwrite(rst0, index, LABEL_SIZE);
    st_write_EOF(rst0);

    if (status < LABEL_SIZE) {
        printf("failed\n");
        return ST_ERROR;
    }

    printf("done\n\n");

    for (i = 0; i < MAXPARTITIONS; i++) {
        pp = &(lp->d_partitions[i]);
        if (pp->p_size > 0) {
            printf("%c: ", i + 'A');
            printf("size = %d(0x%s), ",
                   pp->p_size, hexstr(pp->p_size, 8));
            printf("offset = %d(0x%s)\n",
                   pp->p_offset, hexstr(pp->p_offset, 8));

            blk   = pp->p_offset;
            nblks = pp->p_size;
            size  = nblks << DEV_BSHIFT;

            block = BUF_BLOCK;
            bytes = BUF_BYTES;

            mark = nblks / block;
            if (nblks % block)
                mark++;
            for (j = 0; j < mark; j++)
                printf("-");
            for (j = 0; j < mark; j++)
                printf("%c", '\x08');

            while (nblks > 0) {
                if (nblks < block) {
                    block = nblks;
                    bytes = nblks << DEV_BSHIFT;
                }

                if (!scsi_read_raw(scsi_id, blk, block,
                                   dump_buf, bytes)) {
                    printf("disk read failed !!!\n");
                    return ST_ERROR;
                }

                if (stwrite(rst0, dump_buf, bytes) < bytes) {
                    printf("tape write failed !!!\n");
                    return ST_ERROR;
                }

                blk   += block;
                nblks -= block;
                size  -= bytes;

                printf("#");
            }

            st_write_EOF(rst0);
            printf("\n\n");
        }
    }
    return ST_NORMAL;
}