I <3 C

I love C. It was my first language I learned. Any other security professional will tell you, C is the bomb, but on the same token, a source for a lot of head ache.

To anyone out there aspiring to be a security professional, get to know C and assembly. C lets you inline assembly which makes it awesome. The key is to practice your programming and practice often. Its too easy to forget.

#include <windows.h>
#include <stdio.h>
char *ppt(char *);
long GetFS(FILE *);
int main(int argc, char *argv[])
{
	if(argc < 3)
	{
	printf("Usage is %s filename xorcount",argv[0]); 
	return 0;
	}
	const int xorcount = atoi(argv[2]);
	char *derp = ppt(argv[1]);
	FILE  *pFile = fopen ( argv[1] , "rb" );
	unsigned int fsg = GetFS(pFile);
	fclose(pFile);
	int x;
	for(x=0;x<fsg;x++)
	{
		int vg = derp[x];
		
		__asm
		{
			mov eax,xorcount
			xor vg,eax
		}
		printf("Hex pos: %d \tHex Value: %2X\tAscii Char Value: %c\tXor'd value of char: %d\r\n",x,derp[x],derp[x],vg);
		vg=0;
	}
	__asm
	{
	sar fsg,3
	}
	printf("File size shifted right 3: %i \r\n",fsg);
	__asm
	{
	sal fsg,3
	mov eax,1024
	crc32 eax,fsg
	}
	printf("File size shifted left 3: %i \r\n",fsg);
}
char* ppt(char *filename) // load file into buffer and return
{
  FILE * pFile;
  long lSize;
  char * buffer;
  size_t result;
  pFile = fopen ( filename , "rb" );
  if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
  fseek (pFile , 0 , SEEK_END);
  lSize = ftell (pFile);
  rewind (pFile);
  buffer = (char*) malloc (sizeof(char)*lSize);
  if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
  result = fread (buffer,1,lSize,pFile);
  if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
  fclose (pFile);
  return buffer;
}
long GetFS(FILE *lol) // get file size
{
  long lSize = 0;
  fseek (lol , 0 , SEEK_END);
  lSize = ftell (lol);
  rewind (lol);
  return lSize;
}

This is kind of a filler post. I just feel like updating the blog with something. On that note, I’m split on what i want to do next. Was thinking of making a segway into hardware hacking for a little while as I had a project in mind, but we shall see. iwHX6

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.