Пример #1
0
FString FUnrealSourceFile::GetGeneratedMacroName(int32 LineNumber, const TCHAR* Suffix) const
{
	if (Suffix != nullptr)
	{
		return FString::Printf(TEXT("%s_%d%s"), *GetFileId(), LineNumber, Suffix);
	}

	return FString::Printf(TEXT("%s_%d"), *GetFileId(), LineNumber);
}
Пример #2
0
void CLua::ConfigClose(char *pFileDir)
{
    int Id = GetFileId(pFileDir);
    if (Id == -1)
        return;
    m_aLuaFiles[Id].ConfigClose();
}
Пример #3
0
//-----------------------------------------------------------------------------
// Fills all gaps in a film track with slugs
//-----------------------------------------------------------------------------
void CDmeTrack::FillAllGapsWithSlugs( const char *pSlugName, DmeTime_t startTime, DmeTime_t endTime )
{
	if ( !IsFilmTrack() )
		return;

	FixOverlaps();

	// Create temporary slugs to fill in the gaps
	bool bSlugAdded = false;
	int c = GetClipCount();
	for ( int i = 0; i < c; ++i )
	{
		CDmeClip *pFilmClip = GetClip(i);
		DmeTime_t clipStartTime = pFilmClip->GetStartTime();
		if ( clipStartTime > startTime )
		{
			// There's a gap, create a slug
			CDmeFilmClip *pSlug = CreateSlugClip( pSlugName, startTime, clipStartTime, GetFileId() );

			// This will add the slug to the end; so we don't have to
			// worry about iterating over it (we've cached off the initial count)
			AddClip( pSlug );

			bSlugAdded = true;
		}
		startTime = pFilmClip->GetEndTime();
	}

	if ( endTime > startTime )
	{
		// There's a gap, create a temporary slug
		CDmeFilmClip *pSlug = CreateSlugClip( pSlugName, startTime, endTime, GetFileId() );

		// This will add the slug to the end; so we don't have to
		// worry about iterating over it (we've cached off the initial count)
		AddClip( pSlug );

		bSlugAdded = true;
	}

	if ( bSlugAdded )
	{
		FixOverlaps();
	}
}
Пример #4
0
void WriteOutputFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
/* Write the contents of Data to a file. Format, file name etc. must be given
** as attributes in A. If no format is given, the function tries to autodetect
** it by using the extension of the file name. The bitmap passed to the
** function is the bitmap used as source of the conversion. It may be used to
** determine the bitmap properties for documentation purposes.
*/
{
    const FileId* F;

    /* Get the file format from the command line */
    const char* Format = GetAttrVal (A, "format");
    if (Format != 0) {
        /* Format is given, search for it in the table. */
        F = bsearch (Format,
                     FormatTable,
                     sizeof (FormatTable) / sizeof (FormatTable[0]),
                     sizeof (FormatTable[0]),
                     CompareFileId);
        if (F == 0) {
            Error ("Unknown output format `%s'", Format);
        }
    } else {
        /* No format given, use file name extension */
        const char* Name = NeedAttrVal (A, "name", "write");
        F = GetFileId (Name, FormatTable,
                       sizeof (FormatTable) / sizeof (FormatTable[0]));
        /* Found? */
        if (F == 0) {
            Error ("Cannot determine file format of output file `%s'", Name);
        }
    }

    /* Call the format specific write */
    OutputFormatTable[F->Id].Write (Data, A, B);
}
Пример #5
0
LSTATUS UpdateFile(CString lpExistingFileName, CString lpNewFileName)
{
	if (GetFileType(lpNewFileName) != PathIsDir)
	{
		return ERROR_FILE_NOT_FOUND;
	}

	LSTATUS lStatus = ERROR_FILE_NOT_FOUND;
	CString NewFile, OldFile;

	WIN32_FIND_DATAW FindFileData = {};
	HANDLE hFindFile = FindFirstFileW(lpNewFileName + L"*", &FindFileData);
	FILE_INTERNAL_INFORMATION IdNew, IdOld;

	if (hFindFile != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
			{
				if (_IsDots(FindFileData.cFileName) == 0)
				{
					auto lStatusTmp = UpdateFile(lpExistingFileName + FindFileData.cFileName + L"\\", lpNewFileName + FindFileData.cFileName + L"\\");
					if (lStatusTmp)
					{
						lStatus = lStatusTmp;
					}
				}
			}
			else
			{
				//TempFile = TempPath + FindFileData.cFileName;


				OldFile = lpExistingFileName + FindFileData.cFileName;
				NewFile = lpNewFileName + FindFileData.cFileName;


				////////////////////////////////////////
				//先检查文件是否为同一个文件
				if (auto Status = GetFileId(NewFile, NULL, &IdNew))
				{
					lStatus = RtlNtStatusToDosError(Status);
					continue;
				}

				if (auto Status = GetFileId(OldFile, NULL, &IdOld))
				{
					lStatus = RtlNtStatusToDosError(Status);
					continue;
				}

				if (IdNew.IndexNumber.QuadPart != IdOld.IndexNumber.QuadPart)
				{
					if (DirectGetOsMinVersion() >= MakeMiniVersion(6, 1))
					{
						if (!MoveFileEx(NewFile, OldFile, MOVEFILE_CREATE_HARDLINK | MOVEFILE_REPLACE_EXISTING))
						{
							lStatus = GetLastError_s();
						}
					}
					else
					{
						//Vista不支持直接替换,在Host为Vista时则使用事物处理来保证操作原子性
						auto hTransaction = CreateTransaction(NULL, 0, 0, 0, 0, INFINITE, nullptr);
						if (hTransaction == INVALID_HANDLE_VALUE)
						{
							lStatus = GetLastError_s();
						}
						else
						{
							if (DeleteFileTransactedW(OldFile, hTransaction)==FALSE || CreateHardLinkTransactedW(OldFile, NewFile,nullptr, hTransaction)==FALSE)
							{
								lStatus = GetLastError_s();
							}
							else
							{
								if (!CommitTransactionAsync(hTransaction))
								{
									lStatus = GetLastError_s();
								}
							}
							CloseHandle(hTransaction);
						}

					}
				}
			}




		} while (FindNextFile(hFindFile, &FindFileData));


		FindClose(hFindFile);
	}

	return lStatus;
}
Пример #6
0
/******************************************************************************
*                                                                             *
*   BOOL ParseFunctionScope(int fd, int fs, BYTE *pBuf)                       *
*                                                                             *
*******************************************************************************
*
*   Loads and parses function scope fields and variables
*
*   Where:
*       fd - symbol table file descriptor (to write to)
*       fs - strings file (to write to)
*       pBuf - buffer containing the ELF file
*
*   Returns:
*       TRUE - Function scope parsed and stored
*       FALSE - Critical error
*
******************************************************************************/
BOOL ParseFunctionScope(int fd, int fs, BYTE *pBuf)
{
    TSYMFNSCOPE Header;                 // Function scope section header
    TSYMFNSCOPE1 list;                  // Function scope record

    WORD file_id = 0;                   // Current file ID number
    long fileOffset = 0;                // Temp file offset position
    WORD nTokens = 0;                   // Number of tokens in a function
    BOOL fInFunction = FALSE;           // Are we inside a function scope?
    int nCurrentSection;                // Current string section offset
    int nSectionSize;                   // Current section string size

    Elf32_Ehdr *pElfHeader;             // ELF header

    Elf32_Shdr *Sec;                    // Section header array
    Elf32_Shdr *SecName;                // Section header string table
    Elf32_Shdr *SecCurr;                // Current section
    Elf32_Shdr *SecStab = NULL;         // Section .STAB
    Elf32_Shdr *SecStabstr = NULL;      // Section .STABSTR
    Elf32_Shdr *SecSymtab = NULL;       // Section .SYMTAB
    Elf32_Shdr *SecStrtab = NULL;       // Section .STRTAB

    struct stat fd_stat;                // ELF file stats
    StabEntry *pStab;                   // Pointer to a stab entry
    char *pStr;                         // Pointer to a stab string
    char *pSoDir = "";                  // Source code directory
    char *pSo = "";                     // Current source file
    int i;

    VERBOSE2 printf("=============================================================================\n");
    VERBOSE2 printf("||         PARSE FUNCTION SCOPE                                            ||\n");
    VERBOSE2 printf("=============================================================================\n");
    VERBOSE1 printf("Parsing function scope.\n");

    pElfHeader = (Elf32_Ehdr *) pBuf;

    // Ok, we have the complete file inside the buffer...
    // Find the section header and the string table of section names
    Sec = (Elf32_Shdr *) &pBuf[pElfHeader->e_shoff];
    SecName = &Sec[pElfHeader->e_shstrndx];

    for( i=1; i<pElfHeader->e_shnum; i++ )
    {
        SecCurr = &Sec[i];
        pStr = (char *)pBuf + SecName->sh_offset + SecCurr->sh_name;

        if( strcmp(".stab", pStr)==0 )
            SecStab = SecCurr;
        else
        if( strcmp(".stabstr", pStr)==0 )
            SecStabstr = SecCurr;
        else
        if( strcmp(".symtab", pStr)==0 )
            SecSymtab = SecCurr;
        else
        if( strcmp(".strtab", pStr)==0 )
            SecStrtab = SecCurr;
    }

    //=========================
    // Parse STABS
    //=========================
    // We parse STABS exactly as we do a generic ELF section parsing,
    // but here we extract only basic function parameters and relevant tokens

    if( SecStab && SecStabstr )
    {
        // Parse stab section
        pStab = (StabEntry *) ((char*)pElfHeader + SecStab->sh_offset);
        i = SecStab->sh_size / sizeof(StabEntry);
        nCurrentSection = 0;
        nSectionSize = 0;
        while( i-- )
        {
            pStr = (char *)pElfHeader + SecStabstr->sh_offset + pStab->n_strx + nCurrentSection;

            switch( pStab->n_type )
            {
                // 0x00 (N_UNDEF) is actually storing the current section string size
                case N_UNDF:
                    // We hit another string section, need to advance the string offset of the previous section
                    nCurrentSection += nSectionSize;
                    // Save the (new) currect string section size
                    nSectionSize = pStab->n_value;

                    VERBOSE2 printf("HdrSym size: %lX\n", pStab->n_value);
                break;

                case N_FUN:
                    VERBOSE2 printf("FUN---");
                    if( *pStr==0 )
                    {
                        // Function end
                        VERBOSE2 printf("END--------- +%lX\n\n", pStab->n_value);

                        // At this point we know the total size of the header
                        // as well as the function ending address. Fill in the
                        // missing information and rewrite the header
                        Header.h.dwSize     = sizeof(TSYMFNSCOPE) + sizeof(TSYMFNSCOPE1) * (nTokens-1);
                        Header.dwEndAddress = Header.dwStartAddress + pStab->n_value - 1;
                        Header.nTokens      = nTokens;

                        // Reposition the file pointer to the start of the header
                        lseek(fd, fileOffset, SEEK_SET);

                        write(fd, &Header, sizeof(TSYMFNSCOPE)-sizeof(TSYMFNSCOPE1));
                        lseek(fd, 0, SEEK_END);

                        fInFunction = FALSE;
                    }
                    else
                    {
                        // We will write a header but later, on an function end,
                        // rewind and rewite it with the complete information
                        // This we do so we can simply keep adding file tokens as
                        // TSYMFNSCOPE1 array...
                        Header.h.hType  = HTYPE_FUNCTION_SCOPE;
                        Header.h.dwSize = sizeof(TSYMFNSCOPE)-sizeof(TSYMFNSCOPE1);

                        // Copy the function name into the strings
                        Header.pName          = dfs;
                        write(fs, pStr, strlen(pStr)+1);
                        dfs += strlen(pStr)+1;

                        Header.file_id        = file_id;
                        Header.dwStartAddress = pStab->n_value;

                        Header.dwEndAddress   = 0;      // To be written later
                        Header.nTokens        = 0;      // To be written later

                        // If the start address is not defined (0?) and this is an object file
                        // (kernel module), we can search the global symbols for the address
                        if( Header.dwStartAddress==0 && GlobalsName2Address(&Header.dwStartAddress, pStr) )
                            ;

                        // Print function start & name
                        VERBOSE2 printf("START-%08X--%s\n", Header.dwStartAddress, pStr);

                        nTokens = 0;

                        // Get the current file position so we can come back later

                        // Get the file stats
                        fstat(fd, &fd_stat);

                        fileOffset = fd_stat.st_size;

                        // Write the header first time
                        write(fd, &Header, sizeof(TSYMFNSCOPE)-sizeof(TSYMFNSCOPE1));

                        fInFunction = TRUE;
                    }
                break;

                case N_SO:
                    VERBOSE2 printf("SO  ");
                    if( *pStr==0 )
                    {
                        // Empty name - end of source file
                        VERBOSE2 printf("End of source. Text section offset: %08lX\n", pStab->n_value);
                        VERBOSE2 printf("=========================================================\n");
                    }
                    else
                    {
                        if( *(pStr + strlen(pStr) - 1)=='/' )
                        {
                            // Directory
                            VERBOSE2 printf("Source directory: %s\n", pStr);

                            // Store the pointer to a directory so we can use it later for
                            // SO and SOL stabs
                            pSoDir = pStr;
                        }
                        else
                        {
                            // File
                            VERBOSE2 printf("Source file: %s\n", pStr );

                            // Store the pointer to a file as a current source file
                            pSo = pStr;
                        }
                        file_id = GetFileId(pSoDir, pSo);
                    }
                break;

                // Parameter symbol to a function
                case N_PSYM:
                    VERBOSE2 printf("PSYM   ");
                    VERBOSE2 printf("line: %d PARAM [EBP+%lX]  %s\n", pStab->n_desc, pStab->n_value, pStr);

                    // Write out one token record
                    list.TokType = TOKTYPE_PARAM;
                    list.param   = pStab->n_value;
                    list.pName   = dfs;
                    write(fs, pStr, strlen(pStr)+1);
                    dfs += strlen(pStr)+1;

                    write(fd, &list, sizeof(TSYMFNSCOPE1));

                    nTokens++;
                break;

                // Register variable
                case N_RSYM:
                    VERBOSE2 printf("RSYM  REGISTER VARIABLE ");
                    VERBOSE2 printf("%s in %ld\n", pStr, pStab->n_value);

                    // Write out one token record
                    list.TokType = TOKTYPE_RSYM;
                    list.param   = pStab->n_value;
                    list.pName   = dfs;
                    write(fs, pStr, strlen(pStr)+1);
                    dfs += strlen(pStr)+1;

                    write(fd, &list, sizeof(TSYMFNSCOPE1));

                    nTokens++;
                break;

                // Local symbol: this symbol is shared with typedefs, but if the
                // pStab->n_value != 0, it is a local symbol
                case N_LSYM:
                    if( pStab->n_value==0 )
                        break;

                    VERBOSE2 printf("LSYM   ");
                    VERBOSE2 printf("line: %2d LOCAL_VARIABLE [EBP+%02lX] %s\n", pStab->n_desc, pStab->n_value, pStr);
                    // n_value != 0 -> variable address relative to EBP
                    // n_desc = line number where the symbol is declared

                    // Write out one token record
                    list.TokType = TOKTYPE_LSYM;
                    list.param   = pStab->n_value;
                    list.pName   = dfs;
                    write(fs, pStr, strlen(pStr)+1);
                    dfs += strlen(pStr)+1;

                    write(fd, &list, sizeof(TSYMFNSCOPE1));

                    nTokens++;
                break;

                // Local static symbol in the BSS segment
                case N_LCSYM:
                    // If we are not within a function scope, it is a local variable
                    if(fInFunction)
                    {
                        list.bSegment= GlobalsName2SectionNumber(pStr);

                        VERBOSE2 printf("LCSYM  ");
                        VERBOSE2 printf("line: %d seg:%d %08lX  %s\n", pStab->n_desc, list.bSegment, pStab->n_value, pStr);

                        // Write out one token record
                        list.TokType = TOKTYPE_LCSYM;
                        list.param   = pStab->n_value;
                        list.pName   = dfs;
                        write(fs, pStr, strlen(pStr)+1);
                        dfs += strlen(pStr)+1;

                        write(fd, &list, sizeof(TSYMFNSCOPE1));

                        nTokens++;
                    }
                break;

                // Left-bracket: open a new scope
                case N_LBRAC:
                    VERBOSE2 printf("LBRAC              +%lX  {  (%d)\n", pStab->n_value, pStab->n_desc);

                    // Write out one token record
                    list.TokType = TOKTYPE_LBRAC;
                    list.param   = pStab->n_value;
                    list.pName   = 0;   // Not used

                    write(fd, &list, sizeof(TSYMFNSCOPE1));

                    nTokens++;
                break;

                // Right-bracket: close a scope
                case N_RBRAC:
                    VERBOSE2 printf("RBRAC              +%lX  }\n", pStab->n_value);

                    // Write out one token record
                    list.TokType = TOKTYPE_RBRAC;
                    list.param   = pStab->n_value;
                    list.pName   = 0;   // Not used

                    write(fd, &list, sizeof(TSYMFNSCOPE1));

                    nTokens++;
                break;

                // We can ignore N_SOL (change of source) since the function scope does
                // not care for it
            }

            pStab++;
        }

        return( TRUE );
    }
    else
        fprintf(stderr, "No STAB section in the file\n");

    return( FALSE );
}