コード例 #1
0
ファイル: message.cpp プロジェクト: theuni/libbtcnet
uint64_t first_complete_message_size(const CNetworkConfig& config, evbuffer* input, bool& fComplete, bool& fBadMsgStart)
{
    size_t nTotal = evbuffer_get_length(input);
    uint64_t nMessageSize;
    const int size_needed = config.header_msg_size_offset + config.header_msg_size_size;
    fComplete = false;
    fBadMsgStart = false;

    // Assume 4-bytes until there's a reason not to.
    assert(config.header_msg_size_size == 4);

    if (nTotal < static_cast<size_t>(size_needed))
        return 0;
    evbuffer_iovec v;
    if (evbuffer_peek(input, size_needed, nullptr, &v, 1) == 1) {
        const unsigned char* ptr = static_cast<const unsigned char*>(v.iov_base);
        if (!config.message_start.empty() && memcmp(ptr, &config.message_start[0], config.message_start.size()) != 0) {
            fBadMsgStart = true;
            return 0;
        }
        nMessageSize = get_message_length(ptr + config.header_msg_size_offset) + config.header_size;
    } else {
        std::vector<unsigned char> partial_header(size_needed);
        int ret = evbuffer_copyout(input, &partial_header[0], size_needed);
        assert(ret == size_needed);
        (void)ret;
        if (!config.message_start.empty() && memcmp(&partial_header[0], &config.message_start[0], config.message_start.size()) != 0) {
            fBadMsgStart = true;
            return 0;
        }
        nMessageSize = get_message_length(&partial_header[0] + config.header_msg_size_offset) + config.header_size;
    }
    if (nTotal >= nMessageSize)
        fComplete = true;
    return nMessageSize;
}
コード例 #2
0
ファイル: messages.c プロジェクト: adamsmasher/fractured
result write_pointer_table(FILE *out, Messages *m) {
    int i;
    size_t message_length;
    unsigned short p;

    p = 0;
    for (i = 0; i < m->count; i++) {
        if(fwrite(&p, 2, 1, out) != 1) {
            fprintf(stderr, "ERROR: Couldn't write pointer table at message #%d\n", i);
            return ERROR;
        }
        message_length = get_message_length(&m->messages[i]);
        p = (unsigned short)(message_length + p);
    }
    return OK;
}
コード例 #3
0
static char * test_get_message_length () {
  int lengths[] = {40, 24, 39, 76, 52, 79, 66, 88, 51, 22, 39, 42, 71, 40, 49, 32, 31, 67, 106, 20};
  
  /* 
  for (int i = 0 ; i < get_number_of_messages() ; i++) {
   int length;
   length = get_message_length(i);
   printf("%d, ", length);
  }
  */
  
  for (int i = 0 ; i < get_number_of_messages() ; i++) {
   int length;
   length = get_message_length(i);
   printf("\t... Checking length of message index %d (%d)\n", i, length);
   mu_assert("Found wrong message length.",  length == lengths[i]);
  }
  return 0;
}
コード例 #4
0
static char * test_read_message () {
 char * messages[] = {"Godhasmadeofonebloodallpeoplesoftheearth", \
                    "Thereisdignityinalllabor", \
                    "Imaginationismoreimportantthanknowledge", \
                    "Donotdwellinthepastdonotdreamofthefutureconcentratethemindonthepresentmoment", \
                    "Thebestplacetofindahelpinghandisattheendofyourownarm", \
                    "IfyourstrengthissmalldontcarryheavyburdensIfyourwordsareworthlessdontgiveadvice", \
                    "Ifyouarepatientinonemomentofangeryouwillescapeahundreddaysofsorrow", \
                    "Ifyoumustplaydecideuponthreethingsatthestarttherulesofthegamethestakesandthequittingtime", \
                    "Learningisatreasurethatwillfollowitsownereverywhere", \
                    "Achangeisasgoodasarest", \
                    "Aknownmistakeisbetterthananunknowntruth", \
                    "Arroganceisaweedthatgrowsmostlyonadunghill", \
                    "Acuttingwordisworsethanabowstringacutmayhealbutthecutofthetonguedoesnot", \
                    "Afoollooksfordungwherethecowneverbrowsed", \
                    "Ifyoudontstandforsomethingyouwillfallforsomething", \
                    "Adversityisthefoundationofvirtue", \
                    "Anexcessofcourtesyisdiscourtesy", \
                    "Opinionsfoundedonprejudicearealwayssustainedwiththegreatestviolence", \
                    "InacountrywellgovernedpovertyissomethingtobeashamedofInacountrybadlygovernedwealthissomethingtobeashamedof", \
                    "Thecautiousseldomerr" \
                    };

 for (int i = 0 ; i < get_number_of_messages() ; i++) {
  int message_length = get_message_length(i);
  char *msg = read_message(i);
  printf("\t... Checking correctness of message %d\n", i);
  
  for (int pos = 0 ; pos < message_length ; pos++) {
   /* printf("POS[%d] msg[%c] messages[%c]\n", pos, msg[pos], messages[i][pos]); */
   mu_assert("Found wrong character in message.", msg[pos] = messages[i][pos]);
  }
  
  free(msg);
 }
 return 0;
}
コード例 #5
0
ファイル: lsb.c プロジェクト: asmeryakob/Steganography-by-LSB
int main(int argc,char** argv) {
	unsigned char mask_table[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };

	FILE *file_handle;
	FILE *message_handle;
	FILE *hidden_message_handle;

	if(argc!=4) {
		printf("*** Steganography by LSB substitution***\nUsage: %s [-e][-d] [source file] [destination file] [text file]\nMode\n-e : Add text to Image\n-d : Extract text from Image\n",argv[0]);
		exit(1);
	}


	/* HANDLING FILE OPENING AND ERRORS */
	file_handle=fopen(argv[1],"r");
	if (file_handle == NULL) {
		fprintf(stderr, "Can't open input file %s\n",argv[1]);
		exit(1);
	}

	hidden_message_handle=fopen(argv[2],"w");
	if (hidden_message_handle== NULL) {
		fprintf(stderr, "Cannot create output file %s\n",argv[2]);
		exit(1);
	}
		
	message_handle=fopen(argv[3],"r");
	if (message_handle== NULL) {
		fprintf(stderr, "Can't open text input file %s\n",argv[3]);
		exit(1);
	}
	

	int hidden_message_length=get_message_length(message_handle);

	int c=0;

	/* Generate file with the same header. Copy first 128 bytes */
	char tmp_sig_cpy;
	int offset=get_image_data_offset(file_handle);

	rewind(file_handle);

	for(int i=0;i<offset;i++) {
		tmp_sig_cpy=fgetc(file_handle);
		fputc(tmp_sig_cpy,hidden_message_handle);
		c++;
	}
	/* Made file as .bmp */

	char file_buffer; 			// Temp variable for one byte from file
	char message_buffer;		// Temp buffer for one byte of message
	
	/* 
	After offset has been read and the file header has been written as is for the virgin image - the length of the hidden message is written as the first byte. This length is then used while decrypting the text from the image. 
	*/
	
		do {
			int bit_of_message;
			if(!feof(message_handle)) {		
				message_buffer=fgetc(message_handle);
				for(int i=0;i<8;i++) {  //Do this for every bit in every byte of the virgin-image

					file_buffer=fgetc(file_handle);
					c++;
					int file_byte_lsb = file_buffer & 1; // AND WITH 1 TO GET THE VALUE OF LSB. AND MAKES IT 0 IF LSB IS 0 OR 1 IF IT IS 1

					bit_of_message=mask_table[i] & message_buffer;
					if(file_byte_lsb==bit_of_message) {
						fputc(file_buffer,hidden_message_handle);
					}
					else {
						if(file_byte_lsb==0)
							file_buffer = (file_buffer | 1);
						else
							file_buffer = (file_buffer & ~1);
						//  logic to flip the LSB bit of file_buffer and put it into a file with putc()
						fputc(file_buffer,hidden_message_handle);
					}
				}
			}
			else {
				tmp_sig_cpy=fgetc(file_handle);
				fputc(tmp_sig_cpy,hidden_message_handle);
				c++;
			}
		} while(!feof(file_handle));	

	/* Clean up before exit */
	fclose(file_handle);
	fclose(hidden_message_handle);
	fclose(message_handle);	
	printf("\nOffset for image data = %d \nNumber of bytes navigated = %d\n",offset,c);
}
コード例 #6
0
ファイル: gb_error.c プロジェクト: ramonelalto/gambas
void ERROR_define(const char *pattern, char *arg[])
{
	uchar c;
	char *msg = NULL;
	int len;
	int narg = 0;

	ERROR_clear();

	if ((intptr_t)pattern >= 0 && (intptr_t)pattern < 256)
	{
		ERROR_current->info.code = (int)(intptr_t)pattern;
		pattern = _message[(int)(intptr_t)pattern];
		if (*pattern == '.')
		{
			narg = pattern[1] - '0';
			pattern += 2;
		}
	}
	else if ((intptr_t)pattern == E_ABORT)
	{
		ERROR_current->info.code = E_ABORT;
		pattern = "";
	}
	else
	{
		ERROR_current->info.code = E_CUSTOM;
		
		if (arg)
		{
			msg = (char *)pattern;
			for (;;)
			{
				c = *msg++;
				if (c == 0)
					break;
					
				if (c == '&')
				{
					c = *msg++;
					if (c >= '1' && c <= '4')
					{
						c -= '0';
						if (c > narg)
							narg = c;
					}
				}
			}
		}
	}

	if (narg)
	{
		len = get_message_length(pattern, arg, narg);
		if (len)
		{
			msg = STRING_new(NULL, len);
			ERROR_current->info.msg = msg;
			ERROR_current->info.free = TRUE;
		
			if (EXEC_debug)
			{
				int i;
				strcpy(msg, pattern);
				msg += strlen(pattern);
				for (i = 0; i < narg; i++)
				{
					*msg++ = '|';
					if (arg[i])
					{
						strcpy(msg, arg[i]);
						msg += strlen(arg[i]);
					}
				}
			}
			else
			{
				for (;;)
				{
					c = *pattern++;
					if (c == 0)
						break;
						
					if (c == '&')
					{
						c = *pattern++;
						if (c >= '1' && c <= '4')
						{
							c -= '1';
							if (arg[c])
							{
								len = strlen(arg[c]);
								memcpy(msg, arg[c], len);
								msg += len;
							}
						}
					}
					else
						*msg++ = c;
				}
				
				*msg = 0;
			}

			/*fprintf(stderr, "msg: %s\n", ERROR_current->info.msg);
			if (strcmp(ERROR_current->info.msg, "Type mismatch: wanted WebView, got Function instead") == 0)
			{
				BREAKPOINT();
				STRING_watch = ERROR_current->info.msg;
			}*/
		}
	}
	else if (ERROR_current->info.code == E_CUSTOM)
	{
		if (pattern && *pattern)
		{
			ERROR_current->info.msg = STRING_new_zero(pattern);
			ERROR_current->info.free = TRUE;
		}
		else
		{
			ERROR_current->info.msg = (char *)_message[E_UNKNOWN];
			ERROR_current->info.free = FALSE;
		}
	}
	else
	{
		ERROR_current->info.msg = (char *)pattern;
		ERROR_current->info.free = FALSE;
	}

	//fprintf(stderr, "ERROR_define: %p %d '%s'\n", ERROR_current, ERROR_current->info.code, ERROR_current->info.msg);

	//STRING_add_char(&ERROR_current->info.msg, 0);

	ERROR_current->info.cp = CP;
	ERROR_current->info.fp = FP;
	ERROR_current->info.pc = PC;
	
	#if DEBUG_ERROR
	ERROR_debug("ERROR_define: %s\n", ERROR_current->info.msg);
	#endif
}