PVOID DllLoaded( IN HANDLE Process, IN HANDLE Thread, IN LPLOAD_DLL_DEBUG_INFO LoadDll, IN HANDLE OutputWindow ) /*++ Routine Description: This routine puts the loaded dll into the list Arguments: ProcessId -- Supplies the id of the process this dll was loaded for ThreadId -- Supplies the id of the thread this dll was loaded for LoadDll -- Supplies the information about the dll that was loaded Return Value: None. --*/ { PLOADED_DLL Dll; PUCHAR ImageName; HANDLE SectionHandle; PVOID ImageBase; BOOL Success; UCHAR StringBuffer[256]; // // Inialize if we haven't already // if (!Initialized) { InitializeCriticalSection( &DllListCriticalSection ); Initialized = TRUE; } // // Map the image into our address space for name and symbols // ImageBase = MapImage( LoadDll->hFile, &SectionHandle ); if (!ImageBase) { printf("Sprof: could not map image to get name and symbols.\n"); printf( "Sprof: Dll at %lx will be profiled without symbols\n", LoadDll->lpBaseOfDll ); } // // Get the name of the Image // ImageName = GetImageName(ImageBase); if (!ImageName) { printf("Sprof: could not get image name.\n"); } // // Allocate a structure for the new dll // Dll = malloc(sizeof(LOADED_DLL)); // // Initialize the structure for the new dll // memset(Dll,0,sizeof(LOADED_DLL)); Dll->DllInfo = *LoadDll; Dll->FileMapping = SectionHandle; Dll->BaseOfMapping = ImageBase; Dll->ImageName = ImageName; Dll->OffsetOfCode = GetImageCodeBase(ImageBase); Dll->BaseOfCode = Dll->OffsetOfCode + (ULONG)(LoadDll->lpBaseOfDll); Dll->SizeOfCode = GetImageCodeSize(ImageBase); Dll->Process = Process; // // Put this dll into the list // Success = InsertDll(Dll); if (!Success) { printf( "Sprof: could not insert dll %s into loaded dll list\n", Dll->ImageName ); } sprintf(StringBuffer,"%s loaded",ImageName); PrintToSprofWindow(OutputWindow,StringBuffer); return Dll; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % W r i t e P I C O N I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Procedure WritePICONImage() writes an image to a file in the Personal Icon % format. % % The format of the WritePICONImage method is: % % MagickBooleanType WritePICONImage(const ImageInfo *image_info, % Image *image) % % A description of each parameter follows. % % o image_info: the image info. % % o image: The image. % */ static MagickBooleanType WritePICONImage(const ImageInfo *image_info, Image *image) { #define ColormapExtent 155 #define GraymapExtent 95 #define PiconGeometry "48x48>" static unsigned char Colormap[]= { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x06, 0x00, 0x05, 0x00, 0xf4, 0x05, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x4f, 0x4f, 0x70, 0x80, 0x90, 0x7e, 0x7e, 0x7e, 0xdc, 0xdc, 0xdc, 0xff, 0xff, 0xff, 0x00, 0x00, 0x80, 0x00, 0x00, 0xff, 0x1e, 0x90, 0xff, 0x87, 0xce, 0xeb, 0xe6, 0xe6, 0xfa, 0x00, 0xff, 0xff, 0x80, 0x00, 0x80, 0xb2, 0x22, 0x22, 0x2e, 0x8b, 0x57, 0x32, 0xcd, 0x32, 0x00, 0xff, 0x00, 0x98, 0xfb, 0x98, 0xff, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0x63, 0x47, 0xff, 0xa5, 0x00, 0xff, 0xd7, 0x00, 0xff, 0xff, 0x00, 0xee, 0x82, 0xee, 0xa0, 0x52, 0x2d, 0xcd, 0x85, 0x3f, 0xd2, 0xb4, 0x8c, 0xf5, 0xde, 0xb3, 0xff, 0xfa, 0xcd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xf9, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x05, 0x00, 0x00, 0x05, 0x18, 0x20, 0x10, 0x08, 0x03, 0x51, 0x18, 0x07, 0x92, 0x28, 0x0b, 0xd3, 0x38, 0x0f, 0x14, 0x49, 0x13, 0x55, 0x59, 0x17, 0x96, 0x69, 0x1b, 0xd7, 0x85, 0x00, 0x3b, }, Graymap[]= { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x04, 0x00, 0x04, 0x00, 0xf3, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0x12, 0x21, 0x21, 0x21, 0x33, 0x33, 0x33, 0x45, 0x45, 0x45, 0x54, 0x54, 0x54, 0x66, 0x66, 0x66, 0x78, 0x78, 0x78, 0x87, 0x87, 0x87, 0x99, 0x99, 0x99, 0xab, 0xab, 0xab, 0xba, 0xba, 0xba, 0xcc, 0xcc, 0xcc, 0xde, 0xde, 0xde, 0xed, 0xed, 0xed, 0xff, 0xff, 0xff, 0x21, 0xf9, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x04, 0x0c, 0x10, 0x04, 0x31, 0x48, 0x31, 0x07, 0x25, 0xb5, 0x58, 0x73, 0x4f, 0x04, 0x00, 0x3b, }; #define MaxCixels 92 static const char Cixel[MaxCixels+1] = " .XoO+@#$%&*=-;:>,<1234567890qwertyuipasdfghjk" "lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|"; char buffer[MaxTextExtent], basename[MaxTextExtent], name[MaxTextExtent], symbol[MaxTextExtent]; Image *picon, *map; ImageInfo *blob_info; long j, k, y; MagickBooleanType status, transparent; MagickPixelPacket pixel; RectangleInfo geometry; register const PixelPacket *p; register IndexPacket *indexes; register long i, x; register PixelPacket *q; unsigned long characters_per_pixel, colors; /* Open output image file. */ assert(image_info != (const ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); if (status == MagickFalse) return(status); if (image_info->colorspace == UndefinedColorspace) (void) SetImageColorspace(image,RGBColorspace); SetGeometry(image,&geometry); (void) ParseMetaGeometry(PiconGeometry,&geometry.x,&geometry.y, &geometry.width,&geometry.height); picon=ResizeImage(image,geometry.width,geometry.height,TriangleFilter,1.0, &image->exception); blob_info=CloneImageInfo(image_info); (void) AcquireUniqueFilename(blob_info->filename); if ((image_info->type != TrueColorType) && (IsGrayImage(image,&image->exception) != MagickFalse)) map=BlobToImage(blob_info,Graymap,GraymapExtent,&image->exception); else map=BlobToImage(blob_info,Colormap,ColormapExtent,&image->exception); (void) RelinquishUniqueFileResource(blob_info->filename); blob_info=DestroyImageInfo(blob_info); if ((picon == (Image *) NULL) || (map == (Image *) NULL)) return(MagickFalse); status=MapImage(picon,map,image_info->dither); map=DestroyImage(map); transparent=MagickFalse; if (picon->storage_class == PseudoClass) { CompressImageColormap(picon); if (picon->matte != MagickFalse) transparent=MagickTrue; } else { /* Convert DirectClass to PseudoClass picon. */ if (picon->matte != MagickFalse) { /* Map all the transparent pixels. */ for (y=0; y < (long) picon->rows; y++) { q=GetImagePixels(picon,0,y,picon->columns,1); if (q == (PixelPacket *) NULL) break; for (x=0; x < (long) picon->columns; x++) { if (q->opacity == (Quantum) TransparentOpacity) transparent=MagickTrue; else q->opacity=OpaqueOpacity; q++; } if (SyncImagePixels(picon) == MagickFalse) break; } } (void) SetImageType(picon,PaletteType); } colors=picon->colors; if (transparent != MagickFalse) { colors++; picon->colormap=(PixelPacket *) ResizeQuantumMemory((void **) picon->colormap,(size_t) colors,sizeof(*picon->colormap)); if (picon->colormap == (PixelPacket *) NULL) ThrowWriterException(ResourceLimitError,"MemoryAllocationError"); for (y=0; y < (long) picon->rows; y++) { q=GetImagePixels(picon,0,y,picon->columns,1); if (q == (PixelPacket *) NULL) break; indexes=GetIndexes(picon); for (x=0; x < (long) picon->columns; x++) { if (q->opacity == (Quantum) TransparentOpacity) indexes[x]=(IndexPacket) picon->colors; q++; } if (SyncImagePixels(picon) == MagickFalse) break; } } /* Compute the character per pixel. */ characters_per_pixel=1; for (k=MaxCixels; (long) colors > k; k*=MaxCixels) characters_per_pixel++; /* XPM header. */ (void) WriteBlobString(image,"/* XPM */\n"); GetPathComponent(picon->filename,BasePath,basename); (void) FormatMagickString(buffer,MaxTextExtent, "static char *%s[] = {\n",basename); (void) WriteBlobString(image,buffer); (void) WriteBlobString(image,"/* columns rows colors chars-per-pixel */\n"); (void) FormatMagickString(buffer,MaxTextExtent,"\"%lu %lu %lu %ld\",\n", picon->columns,picon->rows,colors,characters_per_pixel); (void) WriteBlobString(image,buffer); GetMagickPixelPacket(image,&pixel); for (i=0; i < (long) colors; i++) { /* Define XPM color. */ SetMagickPixelPacket(image,picon->colormap+i,(IndexPacket *) NULL,&pixel); pixel.colorspace=RGBColorspace; pixel.depth=8; pixel.opacity=(MagickRealType) OpaqueOpacity; (void) QueryMagickColorname(image,&pixel,XPMCompliance,MagickFalse,name, &image->exception); if (LocaleNCompare(name,"rgb",3) == 0) (void) QueryMagickColorname(image,&pixel,XPMCompliance,MagickTrue,name, &image->exception); if (transparent != MagickFalse) { if (i == (long) (colors-1)) (void) CopyMagickString(name,"grey75",MaxTextExtent); } /* Write XPM color. */ k=i % MaxCixels; symbol[0]=Cixel[k]; for (j=1; j < (long) characters_per_pixel; j++) { k=((i-k)/MaxCixels) % MaxCixels; symbol[j]=Cixel[k]; } symbol[j]='\0'; (void) FormatMagickString(buffer,MaxTextExtent,"\"%s c %s\",\n", symbol,name); (void) WriteBlobString(image,buffer); } /* Define XPM pixels. */ (void) WriteBlobString(image,"/* pixels */\n"); for (y=0; y < (long) picon->rows; y++) { p=AcquireImagePixels(picon,0,y,picon->columns,1,&picon->exception); if (p == (const PixelPacket *) NULL) break; indexes=GetIndexes(picon); (void) WriteBlobString(image,"\""); for (x=0; x < (long) picon->columns; x++) { k=((long) indexes[x] % MaxCixels); symbol[0]=Cixel[k]; for (j=1; j < (long) characters_per_pixel; j++) { k=(((int) indexes[x]-k)/MaxCixels) % MaxCixels; symbol[j]=Cixel[k]; } symbol[j]='\0'; (void) CopyMagickString(buffer,symbol,MaxTextExtent); (void) WriteBlobString(image,buffer); } (void) FormatMagickString(buffer,MaxTextExtent,"\"%s\n", y == (long) (picon->rows-1) ? "" : ","); (void) WriteBlobString(image,buffer); if (QuantumTick(y,picon->rows) != MagickFalse) if ((image->progress_monitor != (MagickProgressMonitor) NULL) && (QuantumTick(y,picon->rows) != MagickFalse)) { status=image->progress_monitor(SaveImageTag,y,picon->rows, image->client_data); if (status == MagickFalse) break; } } picon=DestroyImage(picon); (void) WriteBlobString(image,"};\n"); (void) CloseBlob(image); return(MagickTrue); }
PVOID CreateModule32( PVOID ModuleList, HANDLE Process, IN LPLOAD_DLL_DEBUG_INFO LoadDll, IN HANDLE OutputWindow ) /*++ Routine Description: This routine creates a module 32 object and adds it to the module list Arguments: ModuleList -- Supplies the module list Process -- Supplies the handle of the process this module is loaded for LoadDll -- Supplies the debug info on the dll OutputWindow -- Supplies a handle to a window to output to Return Value: Pointer to a 32 bit module --*/ { PUCHAR ImageName; HANDLE SectionHandle; PVOID ImageBase; MODULE32 Module; UCHAR StringBuffer[256]; if ((ModuleList == NULL) || (LoadDll == NULL)) { return NULL; } // // Map the image into our address space for name and symbols // ImageBase = MapImage( LoadDll->hFile, &SectionHandle ); if (!ImageBase) { printf("Sprof: could not map image to get name and symbols.\n"); printf( "Sprof: Dll at %lx will be profiled without symbols\n", LoadDll->lpBaseOfDll ); } // // Get the name of the Image // ImageName = GetImageName(ImageBase); if (!ImageName) { printf("Sprof: could not get image name.\n"); } memset(&Module,0,sizeof(MODULE32)); Module.FileHandle = LoadDll->hFile; Module.FileMapping = SectionHandle; Module.BaseOfMapping = ImageBase; Module.ImageName = ImageName; Module.BaseOfImage = LoadDll->lpBaseOfDll; Module.OffsetOfCode = GetImageCodeBase(ImageBase); Module.BaseOfCode = Module.OffsetOfCode + (ULONG)Module.BaseOfImage; Module.SizeOfCode = GetImageCodeSize(ImageBase); Module.Process = Process; Module.ReferenceCount = 1; // bugbug errrors in insert sprintf(StringBuffer,"%s loaded",ImageName); PrintToSprofWindow(OutputWindow,StringBuffer); return InsertDataInList(ModuleList, &Module); }