I have used some basic stuff from kernelloaderclass
and i created kernelimagepng.c library and linked in makefile but,
// HOW TO DETECT AND SEE IF THAT CODE WORKING ???
// HOW TO LOAD A PNG FILE AND TEST DETECTION
?
and i couldnt add exact png's identifier ..
#define PNG_MAGIC1 0x474E5089 // 89PNG
how to add PNG_MAGIC1 into --> // if (!strncmp(dataPtr,
HERE , 2
(should be 4 probably because we are looking for first 4 characters)))
if try like this // if (!strncmp(dataPtr, PNG_MAGIC1, 4))
Kernel goes away from the world
it doesnt boot .and shows lots of error
or it should be something like this ?? \x47 \x4E \x50 \x89 instead of PNG_MAGIC1
Code: Select all
//
// GhostNet based on Visopsys
// Copyright (C) 2013-2014 Doga Ozkaracaabatlioglu
//
//
// kernelImagePng.c
//
// This file contains code for loading, saving, and converting images
// in the "Portable Network Graphics" (.png) format, commonly used in
// almost all systems
#include "kernelImagePng.h"
#include "kernelError.h"
#include "kernelFile.h"
#include "kernelGraphic.h"
#include "kernelImage.h"
#include "kernelLoader.h"
#include "kernelMalloc.h"
#include "kernelMemory.h"
#include "kernelMisc.h"
#include <stdio.h>
#include <string.h>
static int detect(const char *fileName, void *dataPtr, unsigned size,
loaderFileClass *class)
{
// Check params
if ((fileName == NULL) || (dataPtr == NULL) || (class == NULL))
return (0);
// Must be binary, and have the signature '0x89504E47 0x0D0A1A0A' at the
// beginning
#define PNG_MAGIC1 0x474E5089
#define PNG_MAGIC2 0x0A1A0A0D
unsigned *sig = dataPtr;
// Make sure there's enough data here for our detection
if (size < sizeof(PNG_MAGIC1))
return (0);
// Binary Detection
// Cancelled
// This function returns 1 and fills the fileClass structure if the data
// points to an PNG file.
// See whether this file claims to be a bitmap file
// if (!strncmp(dataPtr, "BM", 2))
// {
// return (1);
// }
// else
// return (0);
char welcomeMessage[512];
if (!strncmp(dataPtr, ".PNG", 4))
{
sprintf(class->className, "%s %s", FILECLASS_NAME_PNG,
FILECLASS_NAME_IMAGE);
class->class = (LOADERFILECLASS_BIN | LOADERFILECLASS_IMAGE);
// kernelTextPrintLine("%s\nPNG file is this", welcomeMessage); //doesnt work :( we cant print text in system log
// HOW TO DETECT AND SEE IF THAT CODE WORKING ???
// HOW TO LOAD A PNG FILE AND TEST ??
return (1);
}
else
return (0);
//when we use jpg
// We will say this is a JPG file.
// sprintf(class->className, "%s %s", FILECLASS_NAME_JPG, FILECLASS_NAME_IMAGE);
// class->class = (LOADERFILECLASS_BIN | LOADERFILECLASS_IMAGE);
// return (1);
}
// PNG images.
kernelFileClass pngFileClass = {
FILECLASS_NAME_PNG,
&detect,
{ }
};
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//
// Below here, the functions are exported for external use
//
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
kernelFileClass *kernelFileClassPng(void)
{
// The loader will call this function so that we can return a structure
// for managing PNG images
static int filled = 0;
if (!filled)
{
// pngFileClass.image.load = &load;
// pngFileClass.image.save = &save;
filled = 1;
}
return (&pngFileClass);
}