예제 #1
0
파일: V8File.cpp 프로젝트: mbobka/test
BYTE* CV8File::ReadItem(stItemHeader *pItemHeader, BYTE *pFileData, BYTE *&pitem_data, UINT *ItemSize)
{

	stItemHeader *pCurItemHeader = pItemHeader;

	UINT item_data_len, item_page_len;
	DWORD next_item_addr;
	//BYTE *pitem_data;
	UINT read_in_bytes, bytes_to_read;


	//080228 ���� pItemHeader = NULL, �� ������ ���� ������, �������� ���
	if (pItemHeader != NULL)
	{
		item_data_len = _httoi(pCurItemHeader->data_len);//, NULL, 16);
		//080312 ��� ���������� ��������� ������� ������ � ���������� ������
		pitem_data = new BYTE[item_data_len];
	}
	else
		item_data_len = 0;

	read_in_bytes = 0;
	while (read_in_bytes < item_data_len)
	{

		item_page_len = _httoi(pCurItemHeader->page_len);//, NULL, 16);
		next_item_addr = _httoi(pCurItemHeader->next_item_addr);//, NULL, 16);

		bytes_to_read = min(item_page_len, item_data_len - read_in_bytes);

		memcpy(&pitem_data[read_in_bytes], (BYTE*)(&pCurItemHeader[1]), bytes_to_read);
		read_in_bytes += bytes_to_read;
		if (next_item_addr != 0x7fffffff) // ���� ��������� ��������
			pCurItemHeader = (stItemHeader*) &pFileData[next_item_addr];
		else
			break;
	}

	if (ItemSize)
		*ItemSize = item_data_len;

	return NULL;//pitem_data;
}
예제 #2
0
short PPort_Dialog::getGBaseAddress()
{
	if (ui.rbBaseAddrinHex_G->isChecked())
	{
		nGBaseAddress = _httoi(ui.txtGBaseAddress->text());
	}
	else
	{
		nGBaseAddress = (ui.txtGBaseAddress->text().toShort());
	}	
	return nGBaseAddress;
}
예제 #3
0
파일: Common.cpp 프로젝트: boogunote/bn1
int StringToBinary(TCHAR* inputStr, int nInputStrLen, BYTE* outputData)
{
	for(int i=0; i<nInputStrLen/2; ++i)
	{
		TCHAR temp[4];
		temp[0] = inputStr[2*i];
		temp[1] = inputStr[2*i+1];
		temp[2] = _T('\0');
		int tempInt = _httoi(temp);
		outputData[i] = (BYTE)tempInt;
	}
	return nInputStrLen/2;
}
예제 #4
0
int main(int argc, char **argv) {
    char *output;
    int x;
    int y;
    struct cuda_device device;
    int available_words = 1;
    int current_words = 0;
    struct wordlist_file file;
    char input_hash[4][9];

    print_info();

    if (argc != ARG_COUNT) {
        printf("Usage: %s WORDLIST_FILE MD5_HASH\n", argv[0]);
        return -1;
    }

    if (process_wordlist(argv[ARG_WORDLIST], &file) == -1) {
        printf("Error Opening Wordlist File: %s\n", argv[ARG_WORDLIST]);
        return -1;
    }

    if (read_wordlist(&file) == 0) {
        printf("No valid passwords in the wordlist file: %s\n", argv[ARG_WORDLIST]);
        return -1;
    }

    // first things first, we need to select our CUDA device

    if (get_cuda_device(&device) == -1) {
        printf("No Cuda Device Installed\n");
        return -1;
    }

    // we now need to calculate the optimal amount of threads to use for this card

    calculate_cuda_params(&device);

    // now we input our target hash

    if (strlen(argv[ARG_MD5]) != 32) {
        printf("Not a valid MD5 Hash (should be 32 bytes and only Hex Chars\n");
        return -1;
    }

    // we split the input hash into 4 blocks

    memset(input_hash, 0, sizeof(input_hash));

    for(x=0; x < 4; x++) {
        strncpy(input_hash[x], argv[ARG_MD5] + (x * 8), 8);
        device.target_hash[x] = htonl(_httoi(input_hash[x]));
    }

    // allocate global memory for use on device
    if (cudaMalloc(&device.device_global_memory, device.device_global_memory_len) != CUDA_SUCCESS) {
        printf("Error allocating memory on device (global memory)\n");
        return -1;
    }

    // allocate the 'stats' that will indicate if we are successful in cracking
    if (cudaMalloc(&device.device_stats_memory, sizeof(struct device_stats)) != CUDA_SUCCESS) {
        printf("Error allocating memory on device (stats memory)\n");
        return -1;
    }

    // allocate debug memory if required
    if (cudaMalloc(&device.device_debug_memory, device.device_global_memory_len) != CUDA_SUCCESS) {
        printf("Error allocating memory on device (debug memory)\n");
        return -1;
    }

    // make sure the stats are clear on the device
    if (cudaMemset(device.device_stats_memory, 0, sizeof(struct device_stats)) != CUDA_SUCCESS) {
        printf("Error Clearing Stats on device\n");
        return -1;
    }

    // this is our host memory that we will copy to the graphics card
    if ((device.host_memory = malloc(device.device_global_memory_len)) == NULL) {
        printf("Error allocating memory on host\n");
        return -1;
    }

    // put our target hash into the GPU constant memory as this will not change (and we can't spare shared memory for speed)
    if (cudaMemcpyToSymbol("target_hash", device.target_hash, 16, 0, cudaMemcpyHostToDevice) != CUDA_SUCCESS) {
        printf("Error initalizing constants\n");
        return -1;
    }

#ifdef BENCHMARK
    // these will be used to benchmark
    int counter = 0;
    struct timeval start, end;

    gettimeofday(&start, NULL);
#endif

    int z;

    while(available_words) {
        memset(device.host_memory, 0, device.device_global_memory_len);

        for(x=0; x < (device.device_global_memory_len / 64) && file.words[current_words] != (char *)0; x++, current_words++) {
#ifdef BENCHMARK
            counter++;		// increment counter for this word
#endif
            output = md5_pad(file.words[current_words]);
            memcpy(device.host_memory + (x * 64), output, 64);
        }

        if (file.words[current_words] == (char *)0) {
            // read some more words !
            current_words = 0;
            if (!read_wordlist(&file)) {
                // no more words available
                available_words = 0;
                // we continue as we want to flush the cache !
            }
        }


        // now we need to transfer the MD5 hashes to the graphics card for preperation

        if (cudaMemcpy(device.device_global_memory, device.host_memory, device.device_global_memory_len, cudaMemcpyHostToDevice) != CUDA_SUCCESS) {
            printf("Error Copying Words to GPU\n");
            return -1;
        }

        md5_calculate(&device);		// launch the kernel of the CUDA device

        if (cudaMemcpy(&device.stats, device.device_stats_memory, sizeof(struct device_stats), cudaMemcpyDeviceToHost) != CUDA_SUCCESS) {
            printf("Error Copying STATS from the GPU\n");
            return -1;
        }


#ifdef DEBUG
        // For debug, we will receive the hashes for verification
        memset(device.host_memory, 0, device.device_global_memory_len);
        if (cudaMemcpy(device.host_memory, device.device_debug_memory, device.device_global_memory_len, cudaMemcpyDeviceToHost) != CUDA_SUCCESS) {
            printf("Error Copying words to GPU\n");
            return;
        }

        cudaThreadSynchronize();

        // prints out the debug hash'es
        printf("MD5 registers:\n\n");
        unsigned int *m = (unsigned int *)device.host_memory;
        for(y=0; y <= (device.max_blocks * device.max_threads); y++) {
            printf("------ [%d] -------\n", y);
            printf("A: %08x\n", m[(y * 4) + 0]);
            printf("B: %08x\n", m[(y * 4) + 1]);
            printf("C: %08x\n", m[(y * 4) + 2]);
            printf("D: %08x\n", m[(y * 4) + 3]);
            printf("-------------------\n\n");
        }
#endif

        if (device.stats.hash_found == 1) {
            printf("WORD FOUND: [%s]\n", md5_unpad(device.stats.word));
            break;
        }
    }

    if (device.stats.hash_found != 1) {
        printf("No word could be found for the provided MD5 hash\n");
    }

#ifdef BENCHMARK
    gettimeofday(&end, NULL);
    long long time = (end.tv_sec * (unsigned int)1e6 + end.tv_usec) - (start.tv_sec * (unsigned int)1e6 + start.tv_usec);
    printf("Time taken to check %d hashes: %f seconds\n", counter, (float)((float)time / 1000.0) / 1000.0);
    printf("Words per second: %d\n", counter / (time / 1000) * 1000);
#endif
}