#define __MVS__ #define WINDOWS #define ZLIB_DLL #define ZLIB_WINAPI #include #include #include #include "cudapointervaluelist.cuh" HANDLE f; z_stream strm; unsigned char in[16*1024]; int readBytes(void *buf, int count) { int r; strm.avail_out=count; strm.next_out=(Bytef *)buf; while (strm.avail_out) //while there are still bytes to extract { if (strm.avail_in==0) //read a chunk { DWORD br=0; if (ReadFile(f, in, 16*1024, &br, NULL)==FALSE) { printf("read error...\n"); } strm.avail_in=br; if (strm.avail_in==0) { printf("read error...\n"); } strm.next_in=in; } r = inflate(&strm, Z_NO_FLUSH); if (r==Z_STREAM_END) { printf("Stream end reached"); break; } if (r!=Z_OK) { printf("inflate error\n"); return r; } } return r; } DWORD readBYTE() { unsigned char r; if (readBytes(&r, 1)!=S_OK) { printf("readBYTE failed"); } return r; } DWORD readDWORD() { DWORD r; if (readBytes(&r, 4)!=S_OK) { printf("readDWORD failed"); } return r; } UINT64 readQWORD() { UINT64 r; if (readBytes(&r, 8)!=S_OK) { printf("readQWORD failed"); } return r; } int pscaninit() { int ret; //char filename[]="E:\\ptr\\packed\\scanner1\\tutorial.ptr.scandata"; char filename[]="E:\\ptr\\packed\\tst\\test.PTR.scandata"; f=CreateFile(filename,FILE_READ_DATA, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (f!=INVALID_HANDLE_VALUE) { int i; DWORD modulelistlength; DWORD maxlevel; UINT64 totalcount; unsigned char *cudainitdata=NULL; unsigned char *initdata=NULL; int datasize=0; int cudadatasize=0; DWORD bytes=0; int dp=0; /* allocate inflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit(&strm); if (ret != Z_OK) return ret; modulelistlength=readDWORD(); for (i=0; imoduleindex=readDWORD(); pd[i].staticdata->offset=readDWORD(); bytes+=8; } else { pd[i].staticdata=NULL; } } //convert it back into a single bytelist if (datasizemoduleindex; dp+=4; *(DWORD *)&initdata[dp]=pd[i].staticdata->offset; dp+=4; } } if (bytes!=dp) { printf("Error during initialization\n"); exit(1); } if (bytes>4096) //enough data gathered { //pass the bytestring to cuda cudaDeviceSynchronize(); //wait till the previous findoraddpointervalue operation is done cudaError_t error=cudaGetLastError(); if (error!=cudaSuccess) { printf("Error\n"); printf("CUDA error: %s\n", cudaGetErrorString(error)); } if (cudadatasize%d(%d): %x - bytes=%d\n", (DWORD)pointercount, (DWORD)count, (DWORD)totalcount, (DWORD)pvalue, bytes); // printf("CUDA error: %s\n", cudaGetErrorString(cudaGetLastError())); cudaError_t r=cudaMemcpy(cudainitdata, initdata, bytes, cudaMemcpyHostToDevice); findoraddpointervalue<<<1,1>>>(cudainitdata, bytes); bytes=0; dp=0; } //cleanup the temporary pointerdata for (i=0; i>>(cudainitdata, bytes); bytes=0; } if (initdata) free(initdata); cudaDeviceSynchronize(); if (cudainitdata) cudaFree(cudainitdata); cudaDeviceSynchronize(); //build the linked list generateLinkedList<<<1,1>>>(); cudaDeviceSynchronize(); } return 0; }