Jump to content

How to write a C++ Self unpacking program?

- - - - -

  • Please log in to reply
4 replies to this topic

#1
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
Hey I was wondering how it would be possible to write a program that then saves parts of its self to another file (an installer pretty much), I noticed you can actually open up .exes in 7zip and inside is a couple of files could I add another file in and then access it when i run nthe .exe or would I have to hard code the file into the program (eg use a write function)?

Oh and I am using MinGW32 and Code::Blocks
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#2
Axel

Axel

    Newbie

  • Members
  • PipPip
  • 27 posts
Do you want your own code in it too ? Else you could just create a 7zip SFX archive.
You might want to take a look at this too LZMA SDK (Software Development Kit) but that way it'd be really much work lol

#3
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Read about NSIS (free and open source) or InstallShield (proprietary). Also, there is IExpress bundled with Windows.
Latinamne loqueris?

#4
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
I once tried making a compiler, for an interpreter-requiring language, using this type of method. It was basically supposed to make a copy of itself and save that as the output file. I don't know why, but when compiled for Windows, it worked fine, but when compiled for Linux (Ubuntu), the output file wasn't made.

There was the second part, too, though, which was interpreting the source code (when output executable run), but I didn't get that part done; the whole project is halted right now. Well, this second part is not really relevant to this thread.

Here's some of the code, in case anyone wants to take a look at it (not that anyone would, but still)[NOPARSE]:[/NOPARSE]
// Copyright © 2011 By RhetoricalRuvim 

// Aqua Ruby Compiler 


// Error code format:  ARBe*## 

// where * is a capital letter 

// representing where the error 

// happened 

// and ## is a two-digit number 

// that tells more about the 

// error. 


#include <stdio.h> 

#include <stdlib.h> 

#include <string.h> 

#include <math.h> 


#include "arb_const.h" 

#include "arb_keys.h" 


#define SIZE_SOURCE  16344 

#define SIZE_SYMBOLS 8172 

#define SIZE_STRINGS 8172 


int FileSize (char * fn); 

int setInt (int * a, int b); 

char * chomp (char * text); 

void ReplaceExt (char * fn_str, char * ext_str); 

char * GetExt (char * ext_str, char * fn_str); 

int IsOpt (char * arg_str, char * opt_str); 

char * FileToString (char * fn_str); 

char * IncludeFile (char * base_buf, char * cur_buf, char * fn_str); 


char * SkipNext (char ** cur_buf); 

char * GetThis (char * st_str, char * cur_buf); 

char * ParseString (char * st_str, char * src_str); 

char * ParseStringEx (char * st_str, char * src_str); 

int StringSize (char * s1); 

int CharType (char c); 

char * NoSpace (char * b); 


int IsOperator (char * cur_buf); 

int IsKeyword  (char * cur_buf); 


int LoadSourceFile (char * fn_str, char * buf, int max_size, char * sym_buf, char * str_buf); 


char * ByteSource (char * src_str, char * dest_buf, char ** sym_buf, char ** str_buf); 


int BytePrecedence (char c); 


int RunSource (char * code); 


char verify_string []= {'a', 'b', 'c', 'd', 'k', 's', 'd', 'g', 'a', 's', 'j', 'd', 'g', 'h', 'a', 's', 'd', \

'k', 'f', 'l', 'a', ';', 's', 'd', 'f', 'j', 'g', 'k', 'l', 'a', 'e', 'u', 'r', 'i', \

'o', 'a', 'n', 'c', 'v', 'z', 'k', 'x', 'c', 'g', 'f', 'l', 'a', 'k', 's', 'h', 'r', \

't', 'i', 'a', 'e', 'n', 'f', 'g', 'i', 'l', 'a', 's', 'd', 'h', 'v', 'j', 'z', ',', \

'x', 'n', 'c', 'v', 'j', 'u', 'a', 'h', 'e', 'r', 'f', 'u', 'n', 's', 'z', 'd', 'j', \

'f', 'k', 'g', 'b', 'n', 'z', 'd', 's', 'k', 'g', 'f', 'b', 'a', 'l', 's', 'd', 'f', \

'j', 'l', 'k', 'a', 'j', 's', 'l', 'd', 'k', 'g', 'h', 'a', 's', 'l', ';', 'd', 'f', \

'k', 'g', 'a', 'l', 'k', 's', 'd', 'j', 'f', 'k', 'l', 'a', 's', 'd', 'g', 'l', 'k', \

'j', 'a', 'h', 'z', 'd', 's', 'i', 'e', 'r', 'j', 'a', 'e', 'i', 's', 'v', 'n', 'z', \

',', 'k', 'x', 'c', 'u', 'f', 'g', 'i', 'a', 'e', 'w', 'r', 'v', 'i', 'n', 'z', 's', \

'.', 'k', 'c', 'g', 'h', 'z', 'i', 's', 'l', 'e', 'r', 'j', 'f', 'l', 'z', 'k', 's', \

'n', 'v', 'b', 'l', 'h', 'z', 'd', 'f', 'r', 'i', 'g', 't', 'a', 'w', 'l', 'i', 'e', \

'f', 'n', 'z', ';', 'i', 'o', 's', 'c', 'v', 'n', 'z', ';', 'l', 's', 'd', 'k', 'f', \

'j', '1', '5', '3', '7', '8', '2', '3', '8', '4', 'e', '8', 't', 'q', 'u', 'e', 'f', \

'j', 'a', 's', 'o', '8', 'y', 'i', 't', 'l', 'z', 'n', 'v', 'd', '8', 'z', 'o', 'w', \

'e', 'y', 'r', 'a', '8', 'o', '2', 'n', 'i', 'l', '.', 'a', 's', 'd', 'd', 'r', 'y', \

'8', 't', 'a', '3', '4', 'i', 'f', 'n', 'a', 'h', 'w', 'e', 'o', '8', 'r', 't', 'y', \

'4', 'i', '3', '2', '8', 'r', 'g', 'h'}; 

char verify_string_end= 0; 


int has_code= 0; 


char source [SIZE_SOURCE]= {0}; 


char symbols [SIZE_SYMBOLS]= {0}; 

char strings [SIZE_STRINGS]= {0}; 


char input_filename [512]; 

char output_filename [512]; 


int security_flags= 0; 


int cmd_proc_mode; 


int main (int argc, char * argv []){ 

	char * compiler_header= "Aqua Ruby Compiler - A (Meant To Be) Cross-Platform Ruby Compiler\r\nVersion 0.1\r\n\

Copyright (C) 2011 By RhetoricalRuvim\r\n"; 

	char * compiler_name= "Aqua Ruby Compiler"; 

	char * compiler_version= "Aqua Ruby Compiler/0.1"; 

	char * compiler_module= "ARB"; 

	FILE * fh; 

	void * pMem; 

	char * a; 

	char * pSym; 

	char * pStr; 

	int sMem; 

	int rMem; 

	int d; 

	char input_string [500]; 

	char the_ext[32]; 

	int build_files; 

	int pause_after; 

	int i; 

	int * c; 

	int * pFlg; 

	if (has_code){ 

		return RunSource(source); 

	} 

	sMem= FileSize ( argv[0] ); 

	pMem= (void *) malloc ( sMem ); 

	fh= fopen ( (const char *) argv[0], (const char *) "rb" ); 

	if (!fh){ 

		printf ("An error occurred while opening the program file.\r\n"); 

	} 

	fseek ( fh, 0, SEEK_SET ); 

	rMem= 0; 

	a= (char *) pMem; 

	while (setInt(&d, fread(a, 1, sMem, fh))){ 

		a += d; 

		rMem += d; 

	} 

	fclose ( fh ); 

	// printf ("Size of %s: %d\r\n", argv[0], sMem); 

	// printf ("Read %d bytes into buffer. \r\n", rMem); 

	a= (char *) pMem; 

	// Look for the verify_string identifier inside the buffer. 

	while (1){ 

		// If we reached the verify_string identifier, break. 

		if (!strcmp(a, verify_string)) break; 

		// If we reached the end of the buffer, fail. 

		if ( (int) a > ( (int) pMem + sMem - 1 ) ){ 

			free(pMem); 

			printf ("Error:  Could not find data variable inside executable file. \r\n"); 

			return 1; 

		} 

		// Otherwise, increment the pointer to the buffer and continue. 

		a++; 

	} 

	c= (int *) a; 

	pSym= a; 

	pStr= a; 

	pFlg= (int *) a; 

	c += (&has_code - (int *)verify_string); 

	a += (source - verify_string); 

	// `a` should now point to the `source` variable of the loaded `pMem` buffer. 

	// Now it's time to process the command line. 

	pSym += (symbols - verify_string); 

	pStr += (strings - verify_string); 

	pFlg += (&security_flags - (int *)verify_string); 

	// `pSym` points to the `symbols` variable of the new program file in memory. 

	// `pStr` points to the `strings` variable of the new program file in memory. 

	if (argc == 1){ 

		build_files= 1; 

		pause_after= 1; 

		printf ("%s", compiler_header); 

		printf ("\r\n"); 

		printf ("Enter the filename of the source code file:\r\n"); 

		fgets (input_string, 500, stdin); 

			chomp (input_string); 

			strcpy(input_filename, input_string); 

			ReplaceExt(input_string, GetExt(the_ext, argv[0])); 

			strcpy(output_filename, input_string); 

		printf ("Enter the output filename (leave blank for \"%s\"):\r\n", output_filename); 

		fgets (input_string, 500, stdin); 

			chomp (input_string); 

			if (input_string[0]) strcpy(output_filename, input_string); 

		printf ("\r\n"); 

	} else if ((argc == 2) & (IsOpt(argv[1], "h"))){ 

		build_files= 0; 

		pause_after= 0; 

		printf ("%s", compiler_header); 

		printf ("\r\n"); 

		printf ("\r\n"); 

		printf ("Usage:   %s  input [-o output] [-p]\r\n", compiler_module); 

		printf ("\r\n"); 

		printf ("input		The filename of the source code file. \r\n"); 

		printf ("output		The output filename. \r\n"); 

		printf ("\r\n"); 

		printf ("-p 		Pause and wait for return (enter) key press after working. "); 

		printf ("\r\n"); 

		printf ("-nf		No files; restrict file I/O for the program. "); 

		printf ("\r\n"); 

	} else { 

		build_files= 1; 

		pause_after= 0; 

		printf ("%s\r\n", compiler_header); 

		cmd_proc_mode= 0; 

		strcpy(input_filename, "\0"); 

		strcpy(output_filename, input_filename); 

		for (i= 1; i < argc; i++){ 

			if (IsOpt(argv[i], "o")){ 

				cmd_proc_mode= 1; 

				continue; 

			} 

			if (IsOpt(argv[i], "p")){ 

				pause_after= 1; 

				continue; 

			} 

			if (IsOpt(argv[i], "nf")){ 

				// Restrict File I/O. 

				security_flags |= 1<<0; 

				continue; 

			} 

			if (*argv[i] == '-'){ 

				printf ("Warning:  Invalid command line option \"%s\"\r\n", ParseStringEx (input_string, argv[i])); 

				continue; 

			} 

			if (cmd_proc_mode == 1){ 

				strcpy(output_filename, argv[i]); 

				cmd_proc_mode= 0; 

			} else { 

				strcpy(input_filename, argv[i]); 

			} 

		} 

		if (!input_filename[0]){ 

			printf ("Error:  No input filename specified. \r\n"); 

			return 1; 

		} 

		if (!output_filename[0]){ 

			strcpy(output_filename, input_filename); 

			ReplaceExt(output_filename, GetExt(the_ext, argv[0])); 

		} 

		printf ("\r\n"); 

	} 

	if (build_files){ 

		printf ("Input Filename:  %s\r\n", input_filename); 

		printf ("Output Filename: %s\r\n", output_filename); 

		printf ("\r\n"); 

		*c= 1; 

		if (LoadSourceFile(input_filename, a, sizeof(source), pSym, pStr)){ 

			*pFlg= security_flags; 

			fh= fopen(output_filename, "wb"); 

			if (fh){ 

				fwrite(pMem, 1, sMem, fh); 

				fclose(fh); 

			} else { 

				printf ("Error (ARBeS04):  Could not open output file \"%s\"\r\n", ParseStringEx (input_string, output_filename)); 

				return 1; 

			} 

		} 

	} 

	if (pause_after){ 

		printf ("\r\n"); 

		printf ("Press the return (enter) key to continue... "); 

		fgets (input_string, 500, stdin); 

	} 

	free(pMem); 

} 


int FileSize (char * fn){ 

	FILE * fh; 

	int the_size; 

	fh= fopen ( (const char *) fn, (const char *) "rb" ); 

	if (!fh) return -1; 

	fseek (fh, 0, SEEK_END); 

	the_size= ftell (fh); 

	fclose ( fh ); 

	return the_size; 

} 

int setInt (int * a, int b){ 

	*a= b; 

	return b; 

} 

char * chomp (char * text){ 

	char * a; 

	a= text; 

	while (*a) a++; 

	if ((*(a-2) == '\r') | (*(a-2) == '\n')) *(a-2)= 0; 

	if ((*(a-1) == '\r') | (*(a-1) == '\n')) *(a-1)= 0; 

	return text; 

} 

void ReplaceExt (char * fn_str, char * ext_str){ 

	char * a; 

	a= fn_str; 

	while (*a) if (*a == '.') break; else a++; 

	if (*a){ 

		a= fn_str; 

		while (*a) a++; 

		while ((*a != '.') & (a >= fn_str)) a--; 

		if (a < fn_str){ 

			while (*a) a++; 

		} 

	} 

	strcpy(a, ext_str); 

} 

char * GetExt (char * ext_str, char * fn_str){ 

	char * a; 

	a= fn_str; 

	while (*a) if (*a == '.') break; else a++; 

	if (*a){ 

		while (*a) a++; 

		while ((*a != '.') & (a >= fn_str)) a--; 

		if (a < fn_str){ 

			while (*a) a++; 

		} 

	} 

	strcpy(ext_str, a); 

	return ext_str; 

} 

int IsOpt (char * arg_str, char * opt_str){ 

	char * a; 

	a= arg_str; 

	if ((*a == '-') | (*a == '/')){ 

		a++; 

		if (!strcmp(a, opt_str)) return 1; 

	} 

	return 0; 

} 

char * FileToString (char * fn_str){ 

	FILE * fh; 

	char * pMem; 

	int sMem; 

	sMem= FileSize (fn_str); 

	if (sMem != -1) pMem= malloc (sMem + 1); 

	fh= fopen (fn_str, "r"); 

	if (!fh) return 0; 

	fread (pMem, 1, sMem, fh); 

	fclose (fh); 

	pMem [sMem] = 0; 

	return pMem; 

} 

char * IncludeFile (char * base_buf, char * cur_buf, char * fn_str){ 

	char * pFile; 

	int sFile; 

	char * pMem; 

	int sMem; 

	pFile= FileToString (fn_str); 

	if (!pFile){ 

		free (base_buf); 

		return 0; 

	} 

	sFile= strlen (pFile); 

	sMem= strlen (cur_buf) + sFile; 

	pMem= malloc (sMem + 1); 

	strcpy (pMem, pFile); 

	strcat (pMem, cur_buf); 

	free (pFile); 

	free (base_buf); 

	return pMem; 

} 


char * SkipNext (char ** cur_buf){ 

	char * a; 

	char string1[1024]; 

	a= *cur_buf; 

	a += strlen (GetThis (string1, a)); 

	a= NoSpace (a); 

	*cur_buf= a; 

	return a; 

} 

char * GetThis (char * st_str, char * cur_buf){ 

	char * a; 

	char * b; 

	char c; 

	int last_type; 

	int escape; 

	a= st_str; 

	*a= 0; 

	if (!*cur_buf) return a; 

	b= NoSpace (cur_buf); 

	if (!*b) return a; 

	if (*b == '\r'){ 

		*(a + 0)= '\r'; 

		b++; 

		if (*b == '\n'){ 

			*(a + 1)= '\n'; 

			b++; 

		} 

		*(a + 2)= 0; 

		return a; 

	} 

	if (*b == '\n'){ 

		*(a + 0)= '\n'; 

		*(a + 1)= 0; 

		return a; 

	} 

	if ( (b[0] == '.') & (b[1] == 'e') & (b[2] == 'q') & (b[3] == 'l') & (b[3] == '?') ){ 

		strcpy (a, ".eql?"); 

		return a; 

	} 

	if ( (b[0] == 'e') & (b[1] == 'q') & (b[2] == 'u') & (b[3] == 'a') & (b[4] == 'l') & (b[5] == '?') ){ 

		strcpy (a, "equal?"); 

		return a; 

	} 

	if ( (b[0] == 'd') & (b[1] == 'e') & (b[2] == 'f') & (b[3] == 'i') & (b[4] == 'n') & (b[5] == 'e') & (b[6] == 'd') & (b[7] == '?') ){ 

		strcpy (a, "defined?"); 

		return a; 

	} 

	if (CharType (*b) == 4){ 

		*a= *b; 

		c= *b; 

		a++; 

		b++; 

		escape= 0; 

		while (1){ 

			if (*b == '\\') escape= escape * -1 + 1; 

			if (!*b) break; 

			if (*b == c){ 

				if (!escape) break; 

				escape= 0; 

			} 

			*a= *b; 

			a++; 

			b++; 

		} 

		*a= *b; 

		a++; 

		*a= 0; 

		return st_str; 

	} 

	last_type= CharType (*b); 

	while ((last_type == CharType (*b)) | ((last_type == 10) & (CharType (*b) == 1)) | (CharType (*b) == 10)){ 

		*a= *b; 

		last_type= CharType (*b); 

		a++; 

		b++; 

	} 

	*a= 0; 

	return st_str; 

} 

char * ParseString (char * st_str, char * src_str){ 

	char * pTmp; 

	char * a; 

	char * b; 

	char c; 

	char d; 

	int escape; 

	pTmp= malloc (strlen (src_str) + 1); 

	a= pTmp; 

	b= src_str; 

	c= *b; 

	b++; 

	escape= 0; 

	while (*b){ 

		if (*b == '\\'){ 

			if (!escape){ 

				escape= 1; 

				b++; 

				continue; 

			} 

		} 

		if (*b == c){ 

			if (!escape) break; 

		} 

		if (escape){ 

			if (c != '\\'){ 

				if (*b == 'r') *a= 13; 

				else if (*b == 'n') *a= 10; 

				else if (*b == 't') *a= 9; 

				else if (*b == '0') *a= 0; 

				else if (*b == 'x'){ 

					d= b[1] - 48; 

					if (d > 9) d -= 17; 

					if (d > 9) d -= 32; 

					*a= d<<4; 

					d= b[2] - 48; 

					if (d > 9) d -= 17; 

					if (d > 9) d -= 32; 

					*a |= d; 

					b += 2; 

				} 

			} 

			escape= 0; 

		} else *a= *b; 

		a++; 

		b++; 

	} 

	*a= 0; 

	strcpy (st_str, pTmp); 

	free (pTmp); 

	return st_str; 

} 

char * ParseStringEx (char * st_str, char * src_str){ 

	if ((src_str[0] == 34) | (src_str[0] == 39)) return ParseString (st_str, src_str); 

	strcpy (st_str, src_str); 

	return st_str; 

} 

int StringSize (char * s1){ 

	char str01[4096]; 

	int c; 

	int i; 

	ParseStringEx (str01, s1); 

	c= 0; 

	for (i= 0; i < (strlen (s1) - 1); i++){ 

		if ((s1[i+0] == '\\') & (s1[i+1] == '0')) c++; 

	} 

	i= 0; 

	while (1){ 

		if (!str01[i]){ 

			if (c) c--; 

			else break; 

		} 

		i++; 

	} 

	return i; 

} 

int CharType (char c){ 

	/* 

	Types of characters: 

		0 -> unknown 

		1 -> letter or underscore (_) 

		2 -> end-of-line 

		3 -> escape (\) 

		4 -> quote (single or double) 

		5 -> operator 

		6 -> semicolon (;) 

		7 -> parentheses 

		8 -> brackets 

		9 -> braces 

		10 -> dual type (letter or operator) 

		-1 -> NULL 

	*/ 

	char operators [20]= {43, 45, 42, 47, 37, 61, 33, 44, 46, 48, 58, 64, 38, 124, 94, 126}; 

	int i; 

	if ( ((c > 64) & (c < 91)) | ((c > 96) & (c < 123)) ) return 1; 

	if (c == 95) return 1; 

	if ((c == 13) | (c == 10)) return 2; 

	if (c == 92) return 3; 

	if ((c == 39) | (c == 34)) return 4; 

	i= 0; 

	while (operators[i]){ 

		if (c == operators[i]) return 5; 

		i++; 

	} 

	if (c == 59) return 6; 

	if ((c == 40) | (c == 41)) return 7; 

	if ((c == 91) | (c == 93)) return 8; 

	if ((c == 123) | (c == 125)) return 9; 

	if (c == 63) return 10; 

	if (!c) return -1; 

	return 0; 

} 

char * NoSpace (char * b){ 

	char * a; 

	a= b; 

	while (((*a == 32) | (*a == 9)) & (*a != 0)) a++; 

	return a; 

} 


int IsOperator (char * cur_buf){ 

	char a; 

	a= *cur_buf; 

	if ( (a & AC_MAX) == AC_OPERATOR ) return 1; 

	return 0; 

} 

int IsKeyword  (char * cur_buf){ 

	char a; 

	a= *cur_buf; 

	if ( (a & AC_MAX) == AC_KEYWORD )  return 1; 

	return 0; 

} 


int LoadSourceFile (char * fn_str, char * buf, int max_size, char * sym_txt, char * str_txt){ 

	char * a; 

	char * t; 

	char * pBuf; 

	char * pSym; 

	char * pStr; 

	char string01[1024]; 

	int incl; 

	pSym= sym_txt; 

	pStr= str_txt; 

	incl= 0; 

	pBuf= malloc (1); 

	pBuf[0]= 0; 

	pBuf= IncludeFile (pBuf, pBuf, fn_str); 

	if (!pBuf){ 

		printf ("Error:  Cannot open input file \"%s\"\r\n", ParseStringEx (string01, fn_str)); 

		return 0; 

	} 

	a= pBuf; 

	t= buf; 

	while (*a){ 

		if (t >= (buf + max_size)){ 

			printf ("Error (ARBeL01):  Maximum code size reached. \r\n"); 

			return 0; 

		} 

		if (*a == '#'){ 

			while (((*a != '\r') & (*a != '\n')) & (*a != 0)) a++; 

			SkipNext (&a); 

			continue; 

		} 

		if (!strcmp(GetThis(string01, a), "load")){ 

			incl= 1; 

			SkipNext (&a); 

			continue; 

		} 

		if (incl){ 

			ParseString (string01, string01); 

			SkipNext (&a); 

			pBuf= IncludeFile (pBuf, a, string01); 

			if (!pBuf){ 

				printf ("Error:  Could not open include file \"%s\"\r\n", string01); 

				return 0; 

			} 

			a= pBuf; 

			incl= 0; 

			continue; 

		} 

		t= ByteSource (string01, t, &pSym, &pStr); 

		SkipNext (&a); 

	} 

} 


int prev_type= 0; 

int prev_oper= 0; 


char * ByteSource (char * src_str, char * dest_buf, char ** sym_buf, char ** str_buf){ 

	char * sym; 

	char * str; 

	char * a; 

	int * pInt; 

	double * pDbl; 

	char str1[1024]; 

	char c; 

	int i; 

	int s; 

	double f; 

	i= 0; 

	char str2[1024]; 

	while (keys[i]){ 

		if (!strcmp((char *) keys[i], src_str)){ 

			*dest_buf= (char) keys[i + 1]; 

			if ( (char) keys[i + 1] == (AC_OPERATOR | OP_DOT) ){ 

				prev_type= AC_OPERATOR; 

				prev_oper= OP_DOT; 

			} else { 

				prev_type= (char) keys[i + 1] & (3 << 6); 

				prev_oper= 0; 

			} 

			printf ("%x\r\n", (int)(char)keys[i+1]); 

			return dest_buf + 1; 

		} 

		i += 2; 

	} 

	if ((*src_str > 47) & (*src_str < 58)){ 

		if ((prev_type == AC_OPERATOR) & (prev_oper == OP_DOT)){ 

			c= AC_ELEMENT | EL_FLOAT | (sizeof (f) - 1); 

			f= atof (src_str) / pow (10, strlen (src_str)); 

			*dest_buf= c; 

			pDbl= (double *) dest_buf + 1; 

			*pDbl= f; 

			prev_type= 0; 

			prev_oper= 0; 

			return (char *) pDbl + sizeof (f); 

		} 

		c= AC_ELEMENT | EL_INTEGER | (sizeof (i) - 1); 

		i= atoi (src_str); 

		*dest_buf= c; 

		pInt= (int *) dest_buf + 1; 

		*pInt= i; 

		prev_type= 0; 

		prev_oper= 0; 

		return (char *) pInt + sizeof (i); 

	} 

	if ((*src_str == 39) | (*src_str == 34)){ 

		c= AC_ELEMENT | EL_STRING | (sizeof (i) - 1); 

		ParseString (str1, src_str); 

		s= StringSize (src_str); 

		str= *str_buf; 

		i= (int) str - (int) dest_buf; 

		*dest_buf= c; 

		pInt= (int *) dest_buf + 1; 

		*pInt= i; 

		pInt= (int *) str; 

		*pInt= s; 

		memmove (str + 4, str1, s); 

		*str_buf += s + sizeof (s); 

		prev_type= 0; 

		prev_oper= 0; 

		return dest_buf + 1 + sizeof (i); 

	} else { 

		if (!src_str[0]) return dest_buf; 

		a= NoSpace (src_str); 

		if (!a[0]) return dest_buf; 

		c= AC_ELEMENT | EL_SYMBOL | (sizeof (i) - 1); 

		s= strlen (src_str); 

		sym= *sym_buf; 

		i= (int) sym - (int) dest_buf; 

		*dest_buf= c; 

		pInt= (int *) dest_buf + 1; 

		*pInt= i; 

		pInt= (int *) str; 

		*pInt= s; 

		memmove (sym + 4, src_str, s); 

		*str_buf += s + sizeof (s); 

		prev_type= 0; 

		prev_oper= 0; 

		return dest_buf + 1 + sizeof (i); 

	} 

} 


int BytePrecedence (char c){ 

	if ((c == 1) | (c == 53)) return 9; 

	if (c == 2) return 15; 

	if (c == 3) return 24; 

	if ((c >= 4) & (c <= 7)) return 32; 

	if ((c >= 8) & (c <= 10)) return 39; 

	if ((c >= 11) & (c <= 12)) return 45; 

	if ((c >= 13) & (c <= 14)) return 50; 

	if (c == 15) return 56; 

	if ((c >= 16) & (c <= 17)) return 61; 

	if ((c >= 18) & (c <= 21)) return 68; 

	if (((c >= 22) & (c <= 27)) | ((c >=47) & (c <= 48))) return 75; 

	if (c == 28) return 80; 

	if (c == 29) return 83; 

	if ((c >= 30) & (c <= 31)) return 87; 

	if ((c >= 51) & (c <= 52)) return 92; 

	if ((c >= 33) & (c <= 46)) return 98; 

		if (c == 54) return 107; 

		if (c == (AC_KEYWORD | KW_CAT4 | 5)) return 107; 

	if (c == (AC_KEYWORD | KW_CAT4 | 10)) return 115; 

		if (c == (AC_KEYWORD | KW_CAT4 | 11)) return 123; 

		if (c == (AC_KEYWORD | KW_CAT4 | 4))  return 123; 

	if ((c & (15<<4)) == (AC_ELEMENT | EL_SYMBOL)) return 134; 

	if ((c & (3<<4)) == AC_KEYWORD) return 140; 

	return 157; 

} 


#include "RunSource.c" 




#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,719 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
You can save files as resources within an exe (binary includes and all that), then open them in your code and save those off.
Resources in Applications
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users