bool nsImportScanFile::Scan(bool *pDone)
{
  uint64_t available;
  nsresult rv = m_pInputStream->Available(&available);
  if (NS_FAILED(rv))
        {
    if (m_pos < m_bytesInBuf)
      ScanBuffer(pDone);
    *pDone = true;
    return true;
  }

  // Fill up a buffer and scan it
  if (!FillBufferFromFile())
    return false;

  return ScanBuffer(pDone);
}
PRBool nsImportScanFile::Scan( PRBool *pDone)
{
  PRUint32 available;
  nsresult rv = m_pInputStream->Available( &available);
  if (NS_FAILED(rv))
        {
    if (m_pos < m_bytesInBuf)
      ScanBuffer( pDone);
    *pDone = PR_TRUE;
    return( PR_TRUE);
  }

  // Fill up a buffer and scan it
  if (!FillBufferFromFile())
    return( PR_FALSE);

  return( ScanBuffer( pDone));
}
Esempio n. 3
0
inline bool
IgcReplay::ReadPoint(IGCFix &fix, NMEAInfo &basic)
{
  char *buffer;

  while ((buffer = reader->ReadLine()) != NULL) {
    if (ScanBuffer(buffer, fix, basic))
      return true;
  }

  return false;
}
Esempio n. 4
0
bool
IgcReplay::ReadPoint(fixed &Time, fixed &Latitude, fixed &Longitude,
                     fixed &Altitude, fixed &PressureAltitude)
{
  TCHAR *buffer;

  while ((buffer = reader->read()) != NULL) {
    if (ScanBuffer(buffer, Time, Latitude, Longitude, Altitude, PressureAltitude))
      return true;
  }

  return false;
}
Esempio n. 5
0
// Find the size of the poem and resize the window accordingly
void MainWindow::Resize(void)
{
    wxClientDC dc(canvas);

    // Get the poem size
    ScanBuffer(& dc, false, &poem_width, &poem_height);
    int x = poem_width + (2*BORDER_SIZE);
    int y = poem_height + (2*BORDER_SIZE);

    SetClientSize(x, y);

    // In case client size isn't what we set it to...
    int xx, yy;
    GetClientSize(&xx, &yy);

    wxMemoryDC memDC;
    if (backingBitmap) delete backingBitmap;
    backingBitmap = new wxBitmap(x, yy);
    memDC.SelectObject(* backingBitmap);

    memDC.Clear();
    ScanBuffer(&memDC, true, &xx, &yy);
}
Esempio n. 6
0
int main(int argc, char **argv) {
   int Handle;
   unsigned int BlockSize;
   long FileSize;
   unsigned long WordCount = 0;
   char *Buffer, CharFlag = 0;

   if (argc != 2) {
      printf("usage: wc <filename>\n");
      exit(1);
   }

   if ((Buffer = malloc(BUFFER_SIZE)) == NULL) {
      printf("Can't allocate adequate memory\n");
      exit(1);
   }

   if ((Handle = open(argv[1], O_RDONLY | O_BINARY)) == -1) {
      printf("Can't open file %s\n", argv[1]);
      exit(1);
   }

   if ((FileSize = filelength(Handle)) == -1) {
      printf("Error sizing file %s\n", argv[1]);
      exit(1);
   }

   CharFlag = 0;
   while (FileSize > 0) {
      FileSize -= (BlockSize = min(FileSize, BUFFER_SIZE));
      if (read(Handle, Buffer, BlockSize) == -1) {
         printf("Error reading file %s\n", argv[1]);
         exit(1);
      }
      ScanBuffer(Buffer, BlockSize, &CharFlag, &WordCount);
   }

   /* Catch the last word, if any */
   if (CharFlag) {
      WordCount++;
   }
   printf("\nTotal words in file: %lu\n", WordCount);
   return(0);
}
Esempio n. 7
0
bool ReplayLogger::ReadPoint(double *Time,
			     double *Latitude,
			     double *Longitude,
			     double *Altitude)
{
  TCHAR buffer[200];
/*
  // This is creating problems with the interpolator and calculations based on differential times
  // such as variometer derived from altitude differences. Probably due to vario lowpass filters.
  while(ReadLine(buffer)) {
    if(ScanBuffer(buffer, Time, Latitude, Longitude, Altitude))
      return true;
  }
  return false;
*/
  bool found=false;
  while(ReadLine(buffer) &&!found) {
    if(ScanBuffer(buffer, Time, Latitude, Longitude, Altitude))
      found=true;
  }
  return found;
}
Esempio n. 8
0
/**
Reads the contents of the file passed in and checks
whether it contains any of the specified virus
signatures

@return A value depending on whether a known virus is
found within the file.

@param aFile A CFileCB object which can be used to read the file.
@internalComponent
*/
TInt CTestVirusHook::ScanFile(const TDesC& aName)
	{

	TInt r    = KErrNone;
	TInt pos  = 0;
	TInt size = 0;

	// Rename the file	
	TPtrC tmpFile = _L("VS_RENAMED.VSH");
	TParse parse;
	parse.Set(aName, NULL, NULL);
	parse.Set(parse.DriveAndPath(), &tmpFile, NULL);

	r = iFs.Rename(aName, parse.FullName());
	if(r != KErrNone)
		return r;

	RFile file;
	r = file.Open(iFs, parse.FullName(), EFileRead);
	if(r == KErrNone)
		{
		r = file.Size(size);
		}

	//If the file size is 0, then the file
	//has just been created - so it can't contain
	//a virus.
	if(r != KErrNone || size == 0)
		{
		file.Close();

		// Rename the file back
		TInt err = iFs.Rename(parse.FullName(), aName);
		if(err != KErrNone)
			return err;

		return r;
		}

	do
		{
		r = file.Read(pos, iScanBuf);
		
		if (r != KErrNone)
			{
			break;
			}

		r = ScanBuffer();
		pos += iScanBuf.Length();
		} while ((r == KErrNotFound) && (iScanBuf.Length() == iScanBuf.MaxLength()));

	file.Close();

	// Rename the file back
	TInt err = iFs.Rename(parse.FullName(), aName);
	if(err != KErrNone)
		return err;

	if (r > 0)
		{
		//We've found an infection
		return KErrAccessDenied;
		}
	else
		{
		return KErrNone;
		}
	}
Esempio n. 9
0
int main(int argc, char *argv[])
{
	// These should be set by command switches but aren't at the moment
	PRBool bSearchForUnicodeProgIDs = PR_FALSE;
	PRBool bSearchForUnicodeLibraries = PR_FALSE;

	if (argc != 2)
	{
		fprintf(stderr, "Usage: dumpdeps <mozbindirectory>\n");
		return 1;
	}

	std::string sBinDirPath = argv[1];

	nsIServiceManager   *mServiceManager;
	nsILocalFile *pBinDirPath = nsnull;
	nsresult res = NS_NewLocalFile(sBinDirPath.c_str(), &pBinDirPath);

	// Initialise XPCOM
	if (pBinDirPath == nsnull)
	{
		fprintf(stderr, "Error: Could not create object to represent mozbindirectory - is the path correct?\n");
		return 1;
	}
	NS_InitXPCOM(&mServiceManager, pBinDirPath);
	NS_RELEASE(pBinDirPath);

	// Read the component registry to fill the arrays with CLSIDs
	ReadComponentRegistry();
	
	// Locate all libraries and add them to the components list
// BEGIN WINDOWS SPECIFIC
	for (int n = 0; n < 2; n++)
	{
		// Windows specific paths
		std::string sFolder;
		if (n == 0)
		{
			sFolder = sBinDirPath + "\\";
		}
		else if (n == 1)
		{
			sFolder = sBinDirPath + "\\components\\";
		}
		std::string sPattern = sFolder + "*.dll";
		WIN32_FIND_DATA findData;
		HANDLE h = FindFirstFile(sPattern.c_str(), &findData);
		if (h)
		{
			do {
				std::string fullPath = sFolder + findData.cFileName;
				listComponents.push_back(library(fullPath.c_str(), findData.cFileName));
			} while (FindNextFile(h, &findData));
		}
		FindClose(h);
	}
// END WINDOWS SPECIFIC

	// Enumerate through all libraries looking for dependencies
	std::vector<library>::const_iterator i;
	for (i = listComponents.begin(); i != listComponents.end(); i++)
	{
		char *pszBuffer = NULL;
		long nBufferSize = 0;
		if (ReadFileToBuffer((*i).mFullPath.c_str(), &pszBuffer, &nBufferSize))
		{
			printf("Library \"%s\"\n", (*i).mFullPath.c_str());

			// Print out implements
			printf("  Implements:\n");

			// Search for CIDs implemented by this library
			std::vector<factory>::const_iterator j;
			for (j = listCLSIDs.begin(); j != listCLSIDs.end(); j++)
			{
				if (LibraryImplementsCID((*i).mFile.c_str(), (*j).mCID))
				{
					OutputCID((*j).mCID);
				}
			}

			// Print out references
			printf("  References:\n");

			// Search for CIDs not implemented by this library but referenced
			for (j = listCLSIDs.begin(); j != listCLSIDs.end(); j++)
			{
				if (!LibraryImplementsCID((*i).mFile.c_str(), (*j).mCID) &&
					ScanBuffer(pszBuffer, nBufferSize, &(*j).mCID, sizeof((*j).mCID)) == 1)
				{
					OutputCID((*j).mCID);
				}
			}

			// Search for ProgIds
			wchar_t szWTmp[1024];		
			std::vector<progid2cid>::const_iterator k;
			for (k = listProgIDs.begin(); k != listProgIDs.end(); k++)
			{
				// Skip ProgIds that the library implements
				if (LibraryImplementsCID((*i).mFile.c_str(), (*k).mCID))
				{
					continue;
				}

				// Search for ANSI strings
				const char *szA = (*k).mProgID.c_str();
				int nLength = (*k).mProgID.length();
				if (ScanBuffer(pszBuffer, nBufferSize, szA, nLength) == 1)
				{
					OutputProgId(szA);
					continue;
				}

				if (bSearchForUnicodeProgIDs)
				{
					// Search for Unicode strings
					wchar_t *szW = A2W((*k).mProgID.c_str(), szWTmp, sizeof(szWTmp) / sizeof(szWTmp[0]));
					if (ScanBuffer(pszBuffer, nBufferSize, szW, nLength * sizeof(wchar_t)) == 1)
					{
						printf("UNICODE Progid\n");
						OutputProgId(szA);
						continue;
					}
				}
			}

			printf("  Statically linked to:\n");
			std::vector<library>::const_iterator l;
			for (l = listComponents.begin(); l != listComponents.end(); l++)
			{
				// Skip when the full path and the component point to the same thing
				if (i == l)
				{
					continue;
				}

				// Search for ANSI strings
				const char *szA = (*l).mFile.c_str();
				int nLength = (*l).mFile.length();
				if (ScanBuffer(pszBuffer, nBufferSize, szA, nLength) == 1)
				{
					OutputLibrary(szA);
					continue;
				}

				if (bSearchForUnicodeLibraries)
				{
					// Search for Unicode strings
					wchar_t *szW = A2W((*l).mFile.c_str(), szWTmp, sizeof(szWTmp) / sizeof(szWTmp[0]));
					if (ScanBuffer(pszBuffer, nBufferSize, szW, nLength * sizeof(wchar_t)) == 1)
					{
						printf("UNICODE library\n");
						OutputLibrary(szA);
						continue;
					}
				}
			}
			delete []pszBuffer;
		}
	}

	return 0;
}