int main() {
    sieve();
    while (scanf("%d %d", &l[n], &r[n]) == 2) {
        n++;
        if (n == MAXQBUF)
            qflush();
    }
    qflush();
    return 0;
}
Example #2
0
//---------------------------------------------------------------------------
void extract_resource(const char *fname)
{
    if ( !initPtrs(fname) )
        return;

    store(NULL, 0); // zero-resource header

    bool wrerr = false;
    bool res = extractDirectory(0, 0);
    if ( !res )
    {
        msg("Can't extract resource (possible it is invalid)\n");
    }
    else
    {
        qflush(fr);
        if ( ferror(fr) || feof(fr) )
            wrerr = true;
    }
    if ( qfclose(fr) )
        wrerr = true;
    if ( res && wrerr )
        msg("Error writing resource file\n");

    if ( !res || wrerr )
        unlink(fname);
    else
        msg("Resources have been extracted and stored in '%s'\n", fname);
}
Example #3
0
//----------------------------------------------------------------------
static void vlog(const char *format, va_list va)
{
  static FILE *fp = NULL;
  if ( fp == NULL ) fp = fopenWT("debug_log");
  qvfprintf(fp, format, va);
  qflush(fp);
}
Example #4
0
 //--------------------------------------------------------------------------
 int flush()
 {
   PYW_GIL_CHECK_LOCKED_SCOPE();
   int rc;
   Py_BEGIN_ALLOW_THREADS;
   rc = qflush(fp);
   Py_END_ALLOW_THREADS;
   return rc;
 }
Example #5
0
int ttflush(TTY tp, int mode)
{
	if (mode & 1)
	{
		qflush(&tp->inq);
	}
	
	if (mode & 2)
	{
		BCLR(tp->state, ST_STOPPED);
		ptsstop(tp,mode);
		qflush(&tp->outq);
		
		if (ISSET(tp->state,ST_DRAIN))
		{
			BCLR(tp->state, ST_DRAIN);
			Run(&tp->outq);
		}
	}

	return RPDONE;
}
Example #6
0
File: devcons.c Project: 8l/inferno
int
kprint(char *fmt, ...)
{
	va_list arg;
	char buf[PRINTSIZE];
	int n;

	va_start(arg, fmt);
	n = vseprint(buf, buf+sizeof(buf), fmt, arg) - buf;
	va_end(arg);
	if(qfull(klogq))
		qflush(klogq);
	return qproduce(klogq, buf, n);
}
Example #7
0
// ****************************************************************************
// Func: Log()
// Desc: Send text to a log file.
//
// ****************************************************************************
ALIGN(32) void Log(FILE *pLogFile, const char *format, ...)
{
	if(pLogFile && format)
	{
		// Format string
		va_list vl;
        char	str[2048] = {0};

		va_start(vl, format);
		_vsnprintf(str, (sizeof(str) - 1), format, vl);
		va_end(vl);

		// Out to file
		qfputs(str, pLogFile);
        qflush(pLogFile);
	}
}
Example #8
0
/*
 * Flush and reload data base.
 */
void
db_reload()
{
	dprintf(3, (ddt, "reload()\n"));
	syslog(LOG_NOTICE, "reloading nameserver\n");

	qflush();
	sqflush();
	getnetconf();
#ifdef FORCED_RELOAD
	reloading = 1;     /* to force transfer if secondary and backing up */
#endif
	ns_init(bootfile);
	time(&resettime);
#ifdef FORCED_RELOAD
	reloading = 0;
#endif /* FORCED_RELOAD */

	dprintf(1, (ddt, "Ready to answer queries.\n"));
	syslog(LOG_NOTICE, "Ready to answer queries.\n");
}
Example #9
0
void IDAP_run(int arg)
{
	FILE *f, *f2;
	char *filename = construct_output_filename(".import_allocs.txt");
	f = qfopen(filename, "wb");
	char *filename2 = construct_output_filename(".import_allocs_wrappers.txt");
	f2 = qfopen(filename2, "wb");

	//r0 allocators
	funcMalloc.push_back(TFuncMalloc(" ExAllocatePoolWithQuota", 2));
	funcMalloc.push_back(TFuncMalloc(" __imp__ExAllocatePoolWithQuota@8", 2));//ntoskrnl.exe

	funcMalloc.push_back(TFuncMalloc(" ExAllocatePoolWithQuotaTag", 2));
	funcMalloc.push_back(TFuncMalloc(" __imp__ExAllocatePoolWithQuotaTag@12", 2));//ntoskrnl.exe

	funcMalloc.push_back(TFuncMalloc("ExAllocatePoolWithTag", 2));
	funcMalloc.push_back(TFuncMalloc("__imp__ExAllocatePoolWithTag@12", 2));//ntoskrnl.exe

	funcMalloc.push_back(TFuncMalloc("ExAllocatePoolWithTagPriority", 2));
	funcMalloc.push_back(TFuncMalloc("__imp__ExAllocatePoolWithTagPriority@16", 2));//ntoskrnl.exe

	funcMalloc.push_back(TFuncMalloc("IoAllocateMdl", 2));
	funcMalloc.push_back(TFuncMalloc("__imp__IoAllocateMdl@20", 2));//ntoskrnl.exe

	funcMalloc.push_back(TFuncMalloc("RtlAllocateHeap", 3));
	funcMalloc.push_back(TFuncMalloc("__imp__RtlAllocateHeap", 3));//ntoskrnl.exe

	funcMalloc.push_back(TFuncMalloc("EngAllocMem", 2));
	funcMalloc.push_back(TFuncMalloc("__imp__EngAllocMem", 2));//win32k.sys
	funcMalloc.push_back(TFuncMalloc("__imp__EngAllocMem@12", 2));//win32k.sys


	//type pointer to size!!!
	//funcMalloc.push_back(TFuncMalloc("ZwAllocateVirtualMemory", 4));
	//funcMalloc.push_back(TFuncMalloc("__imp__ZwAllocateVirtualMemory@24", 4));//ntoskrnl.exe
	//funcMalloc.push_back(TFuncMalloc("NtAllocateVirtualMemory", 4));
	//funcMalloc.push_back(TFuncMalloc("__imp__NtAllocateVirtualMemory@24", 4));//ntoskrnl.exe



	//funcMalloc.push_back(TFuncMalloc("RtlReAllocateHeap", 4));
	//funcMalloc.push_back(TFuncMalloc("HeapAlloc", 3));



	//r3 allocators
	funcMalloc.push_back(TFuncMalloc("GlobalAlloc", 2));//kernel32.dll

	funcMalloc.push_back(TFuncMalloc("HeapAlloc", 3));//kernel32.dll
	funcMalloc.push_back(TFuncMalloc("__imp__HeapAlloc@12", 3));//kernel32.dll

	funcMalloc.push_back(TFuncMalloc("__imp__HeapReAlloc@16", 4));//kernel32.dll
	funcMalloc.push_back(TFuncMalloc("HeapReAlloc", 4));//kernel32.dll

	funcMalloc.push_back(TFuncMalloc("__imp__LocalAlloc@8", 2));//kernel32.dll
	funcMalloc.push_back(TFuncMalloc("LocalAlloc", 2));//kernel32.dll

	funcMalloc.push_back(TFuncMalloc("__imp__LocalReAlloc@12", 3));//kernel32.dll
	funcMalloc.push_back(TFuncMalloc("LocalReAlloc", 3));//kernel32.dll

	funcMalloc.push_back(TFuncMalloc("VirtualAlloc", 2));
	funcMalloc.push_back(TFuncMalloc("__imp__VirtualAlloc@16", 2));//kernel32.dll

	funcMalloc.push_back(TFuncMalloc("__imp__MpHeapAlloc", 3));//msdart.dll export
	funcMalloc.push_back(TFuncMalloc("__imp__MpHeapReAlloc", 3));//msdart.dll export

	funcMalloc.push_back(TFuncMalloc("__imp__GdipAlloc@4", 1));//gdiplus.dll export
	//funcMalloc.push_back(TFuncMalloc("GpMalloc", 1));//gdiplus.dll

	funcMalloc.push_back(TFuncMalloc("__imp__malloc", 1));//msvcrt.dll
	funcMalloc.push_back(TFuncMalloc("_malloc", 1));//msvcrt.dll, the same as __imp__malloc

	funcMalloc.push_back(TFuncMalloc("__imp__realloc", 2));//msvcrt.dll
	funcMalloc.push_back(TFuncMalloc("_realloc", 2));//msvcrt.dll

	//funcMalloc.push_back(TFuncMalloc("_alloca", 1));
	//funcMalloc.push_back(TFuncMalloc("_malloca", 1));



	uint i = 0, j = funcMalloc.size();
	msg("standart funcMalloc.size() = %d\n", funcMalloc.size());
	for(; i< funcMalloc.size(); i++){
		find_alloc_calls_ex(f, funcMalloc[i]);
		pretty_printing_ex(f, funcMalloc[i]);

		if(Malloc_calls.size() >  0 )
			Malloc_calls.clear();
		
		qfprintf(f,"\n\n");

		qflush( f );
	}

	qfclose( f );

	
	j = funcMalloc_wrappers.size();
	msg("standart funcMalloc_wrappers.size() = %d\n", j);

	
	//TODO: add level property 
	i = 0;
	while( i < j){

		find_alloc_calls_warreps_ex(f2, funcMalloc_wrappers[i]);
		msg("[%d].funcMalloc.size() = %d\n", i, funcMalloc_wrappers.size());
		msg("[%d].Malloc_calls.size() = %d\n", i, Malloc_calls.size());
		pretty_printing_ex(f2, funcMalloc_wrappers[i]);
		if(Malloc_calls.size() >  0 )
			Malloc_calls.clear();
		j = funcMalloc_wrappers.size();
		i++;
		qflush( f2 );
	}
	


	qfclose( f2 );


	return ;
}
Example #10
0
int TembooSession::executeChoreo(
        const char* accountName, 
        const char* appKeyName, 
        const char* appKeyValue, 
        const char* path, 
        const ChoreoInputSet& inputSet, 
        const ChoreoOutputSet& outputSet, 
        const ChoreoPreset& preset) {

    DataFormatter fmt(&inputSet, &outputSet, &preset);
    char auth[HMAC_HEX_SIZE_BYTES + 1];
    char buffer[11];
    
    // We use the current time-of-day as salt on the app key.
    // We keep track of time-of-day by getting the current time
    // from the server and applying an offset (the length of time
    // we've been running.) 
    uint32toa((uint32_t)TembooSession::getTime(), buffer);

    uint16_t contentLength = getAuth(fmt, appKeyValue, buffer, auth);

    m_client.stop();
    m_client.flush();

    int connected = 0;
    TEMBOO_TRACE("Connecting: ");

    // reserve space for the "host" string sufficient to hold either the 
    // (dotted-quad) IP address + port, or the default <account>.temboolive.com
    // host string.
    int hostLen = (m_addr == INADDR_NONE ? (strlen_P(TEMBOO_DOMAIN) + strlen(accountName) + 1):21);
    char host[hostLen];

    // If no explicit IP address was specified (the normal case), construct
    // the "host" string from the account name and the temboo domain name.
    if (m_addr == INADDR_NONE) {
        strcpy(host, accountName);
        strcat_P(host, TEMBOO_DOMAIN);
        TEMBOO_TRACELN(host);
        connected = m_client.connect(host, m_port);
    } else {

        // If an IP address was explicitly specified (presumably for testing purposes),
        // convert it to a dotted-quad text string.
        host[0] = '\0';
        for(int i = 0; i < 4; i++) {
            uint16toa(m_addr[i], &host[strlen(host)]);
            strcat(host, ".");
        }

        // replace the last '.' with ':'
        host[strlen(host)-1] = ':';
        
        // append the port number
        uint16toa(m_port, &host[strlen(host)]);
        
        TEMBOO_TRACELN(host);
        connected = m_client.connect(m_addr, m_port);
    }

    if (connected) {

        TEMBOO_TRACELN("OK. req:");
        qsendProgmem(POST);
        qsendProgmem(BASE_CHOREO_URI);
        qsend(path);
        qsendProgmem(SDK_ID);
        qsendlnProgmem(POSTAMBLE);
        
        // Send our custom authentication header
        // (app-key-name:hmac)
        qsendProgmem(HEADER_AUTH);
        qsend(appKeyName);
        qsend(":");
        qsendln(auth);
        
        // send the standard host header
        qsendProgmem(HEADER_HOST);
        qsendln(host);
        
        // send the standard accept header
        qsendlnProgmem(HEADER_ACCEPT);
        
        // send our custom account name neader
        qsendProgmem(HEADER_ORG);
        qsend(accountName);
        qsendlnProgmem(HEADER_DOM);
        
        // send the standard content type header
        qsendlnProgmem(HEADER_CONTENT_TYPE);
        
        // send our custom client time header
        qsendProgmem(HEADER_TIME);
        qsendln(buffer);
        
        // send the standard content length header
        qsendProgmem(HEADER_CONTENT_LENGTH);
        qsendln(uint16toa(contentLength, buffer));

        qsendProgmem(EOL);
        
        // Format and send the body of the request
        fmt.reset();
        while(fmt.hasNext()) {
            qsend(fmt.next());
        }

        qsendProgmem(EOL);
        qflush();
        return 0;
    } else {
        TEMBOO_TRACELN("FAIL");
        return 1;
    }
}
Example #11
0
void TembooSession::qsend(char c) {
    m_sendQueue[m_sendQueueDepth++] = c;
    if (m_sendQueueDepth >= TEMBOO_SEND_QUEUE_SIZE) {
        qflush();
    }
}
Example #12
0
int
uartctl(Uart *p, char *cmd)
{
	char *f[16];
	int i, n, nf;

	nf = tokenize(cmd, f, nelem(f));
	for(i = 0; i < nf; i++){
		if(strncmp(f[i], "break", 5) == 0){
			(*p->phys->dobreak)(p, 0);
			continue;
		}

		n = atoi(f[i]+1);
		switch(*f[i]){
		case 'B':
		case 'b':
			uartdrainoutput(p);
			if((*p->phys->baud)(p, n) < 0)
				return -1;
			break;
		case 'C':
		case 'c':
			p->hup_dcd = n;
			break;
		case 'D':
		case 'd':
			uartdrainoutput(p);
			(*p->phys->dtr)(p, n);
			break;
		case 'E':
		case 'e':
			p->hup_dsr = n;
			break;
		case 'F':
		case 'f':
			if(p->oq != nil)
				qflush(p->oq);
			break;
		case 'H':
		case 'h':
			if(p->iq != nil)
				qhangup(p->iq, 0);
			if(p->oq != nil)
				qhangup(p->oq, 0);
			break;
		case 'I':
		case 'i':
			uartdrainoutput(p);
			(*p->phys->fifo)(p, n);
			break;
		case 'K':
		case 'k':
			uartdrainoutput(p);
			(*p->phys->dobreak)(p, n);
			break;
		case 'L':
		case 'l':
			uartdrainoutput(p);
			if((*p->phys->bits)(p, n) < 0)
				return -1;
			break;
		case 'M':
		case 'm':
			uartdrainoutput(p);
			(*p->phys->modemctl)(p, n);
			break;
		case 'N':
		case 'n':
			if(p->oq != nil)
				qnoblock(p->oq, n);
			break;
		case 'P':
		case 'p':
			uartdrainoutput(p);
			if((*p->phys->parity)(p, *(f[i]+1)) < 0)
				return -1;
			break;
		case 'Q':
		case 'q':
			if(p->iq != nil)
				qsetlimit(p->iq, n);
			if(p->oq != nil)
				qsetlimit(p->oq, n);
			break;
		case 'R':
		case 'r':
			uartdrainoutput(p);
			(*p->phys->rts)(p, n);
			break;
		case 'S':
		case 's':
			uartdrainoutput(p);
			if((*p->phys->stop)(p, n) < 0)
				return -1;
			break;
		case 'W':
		case 'w':
			if(uarttimer == nil || n < 1)
				return -1;
			uarttimer->tns = (int64_t)n * 100000LL;
			break;
		case 'X':
		case 'x':
			if(p->enabled){
				ilock(&p->tlock);
				p->xonoff = n;
				iunlock(&p->tlock);
			}
			break;
		}
	}
	return 0;
}
Example #13
0
File: devuart.c Project: 8l/inferno
static void
uartctl(Uart *p, char *cmd)
{
	int i, n;

	/* let output drain for a while (up to 4 secs) */
	for(i = 0; i < 200 && (qlen(p->oq) || (readstatus(p) & USTAT_TC) == 0); i++)
		tsleep(&up->sleep, return0, 0, 20);

	if(strncmp(cmd, "break", 5) == 0){
		uartbreak(p, 0);
		return;
	}

	n = atoi(cmd+1);
	switch(*cmd){
	case 'B':
	case 'b':
		if(n <= 0) 
			error(Ebadarg);
		p->bps = n;
		uartset(p);
		break;
	case 'f':
	case 'F':
		qflush(p->oq);
		break;
	case 'H':
	case 'h':
		qhangup(p->iq, 0);
		qhangup(p->oq, 0);
		break;
	case 'L':
	case 'l':
		if(n < 7 || n > 8)
			error(Ebadarg);
		p->bits = n;
		uartset(p);
		break;
	case 'n':
	case 'N':
		qnoblock(p->oq, n);
		break;
	case 'P':
	case 'p':
		p->parity = *(cmd+1);
		uartset(p);
		break;
	case 'K':
	case 'k':
		uartbreak(p, n);
		break;
	case 'Q':
	case 'q':
		qsetlimit(p->iq, n);
		qsetlimit(p->oq, n);
		break;
	case 's':
	case 'S':
		if(n < 1 || n > 2)
			error(Ebadarg);
		p->stop = n;
		uartset(p);
		break;
	}
}
Example #14
0
/*****************************************************************************
 *
 * NAME
 *
 * OVERVIEW
 *    process_char processes a single character of input.
 *
 ****************************************************************************/
static void process_char (unsigned char c)
{
  switch (cur_slot->tsmode)
    {
    case TS_NONE: 
      ts_none (c);
      break;

    case TS_IAC: 
      switch (c)
	{
	case IAC:
	  ts_none (c);
	  break;
	case WILL: 
	  cur_slot->tsmode = TS_WILL;
	  break;
	case WONT: 
	  cur_slot->tsmode = TS_WONT;
	  break;
	case DO: 
	  cur_slot->tsmode = TS_DO;
	  break;
	case DONT: 
	  cur_slot->tsmode = TS_DONT;
	  break;
	case EC: 
	  ts_none ('\b');
	  cur_slot->tsmode = TS_NONE;
	  break;
	case EL: 
	  ts_none (24);
	  cur_slot->tsmode = TS_NONE;
	  break;
	case AO: 
	  qflush (&cur_slot->outq);
	  qflush (&cur_slot->stopq);
	  break;
	case AYT: 
	  writestr (cur_slot, "\n[Yes]\n");
	default: 
	  cur_slot->tsmode = TS_NONE;
	  break;
	}
      break;

    case TS_WILL: 
      send_ts (DONT, (char)c);
      cur_slot->tsmode = TS_NONE;
      break;

    case TS_WONT: 
      cur_slot->tsmode = TS_NONE;
      break;

    case TS_DO: 
      if (c != TELOPT_SGA && c != TELOPT_ECHO)
	send_ts (WONT, (char)c);
      cur_slot->tsmode = TS_NONE;
      break;

    case TS_DONT: 
      cur_slot->tsmode = TS_NONE;
      break;
    }
}
Example #15
0
int TembooSession::executeChoreo(
        const char* accountName, 
        const char* appKeyName, 
        const char* appKeyValue, 
        const char* path, 
        const ChoreoInputSet& inputSet, 
        const ChoreoOutputSet& outputSet, 
        const ChoreoPreset& preset) {

    DataFormatter fmt(&inputSet, &outputSet, &preset);
    char auth[HMAC_HEX_SIZE_BYTES + 1];
    char buffer[11];
    
    // We use the current time-of-day as salt on the app key.
    // We keep track of time-of-day by getting the current time
    // from the server and applying an offset (the length of time
    // we've been running.) 
    uint32toa((uint32_t)TembooSession::getTime(), buffer);

    uint16_t contentLength = getAuth(fmt, appKeyValue, buffer, auth);

    m_client.stop();
    m_client.flush();

    int connected = 0;
    TEMBOO_TRACE("Connecting: ");

    // reserve space for the "host" string sufficient to hold either the 
    // (dotted-quad) IP address + port, or the default <account>.temboolive.com
    // host string.
    int hostLen = strlen_P(TEMBOO_DOMAIN) + strlen(accountName) + 1;
    char host[hostLen];
    
    // Construct the "host" string from the account name and the temboo domain name.

    strcpy(host, accountName);
    strcat_P(host, TEMBOO_DOMAIN);
    
    bool useProxy = false;
    
    if (m_addr == INADDR_NONE) {
        TEMBOO_TRACELN(host);
        connected = m_client.connect(host, m_port);
    } else {
        
        TEMBOO_TRACELN(host);
        connected = m_client.connect(m_addr, m_port);
        
        useProxy = true;
    }

    if (connected) {

        TEMBOO_TRACELN("OK. req:");
        qsendProgmem(POST);
        if(useProxy) {
            qsendProgmem(HTTP);
            qsend(host);
        }
        qsendProgmem(BASE_CHOREO_URI);
        qsend(path);
        qsendProgmem(SDK_ID);
        qsendlnProgmem(POSTAMBLE);
        
        // Send our custom authentication header
        // (app-key-name:hmac)
        qsendProgmem(HEADER_AUTH);
        qsend(appKeyName);
        qsend(":");
        qsendln(auth);
        
        // send the standard host header
        qsendProgmem(HEADER_HOST);
        qsendln(host);
        
        // send the standard accept header
        qsendlnProgmem(HEADER_ACCEPT);
        
        // send our custom account name neader
        qsendProgmem(HEADER_ORG);
        qsend(accountName);
        qsendlnProgmem(HEADER_DOM);
        
        // send the standard content type header
        qsendlnProgmem(HEADER_CONTENT_TYPE);
        
        // send our custom client time header
        qsendProgmem(HEADER_TIME);
        qsendln(buffer);
        
        // send the standard content length header
        qsendProgmem(HEADER_CONTENT_LENGTH);
        qsendln(uint16toa(contentLength, buffer));

        qsendProgmem(EOL);
        
        // Format and send the body of the request
        fmt.reset();
        while(fmt.hasNext()) {
            qsend(fmt.next());
        }

        qsendProgmem(EOL);
        qflush();
        return 0;
    } else {
        TEMBOO_TRACELN("FAIL");
        return 1;
    }
}