Exemplo n.º 1
0
int main (int argc, const char * argv[])
{
    printf("  ______                    __   \n");
    printf(" |      |.----.--.--.-----.|  |_ \n");
    printf(" |   ---||   _|  |  |  _  ||   _|\n");
    printf(" |______||__| |___  |   __||____|\n");
    printf("              |_____|__|         \n");
    printf("  _______                    __   __                    \n");
    printf(" |    ___|.--.--.-----.----.|  |_|__|.-----.-----.-----.\n");
    printf(" |    ___||  |  |     |  __||   _|  ||  _  |     |__ --|\n");
    printf(" |___|    |_____|__|__|____||____|__||_____|__|__|_____|\n");
    printf(" v%s\n", VERSION);
    printf(" (c) fG!, 2011. All rights reserved. - [email protected]\n");
    printf("--------------------------------------------------------\n");

    FILE *in_file;
	
    in_file = fopen(argv[1], "r");
    if (!in_file)
    {
		printf("[ERROR] Could not open target file %s!\n", argv[1]);
        return(1);
    }
    if (fseek(in_file, 0, SEEK_END))
    {
		printf("[ERROR] Fseek failed at %s\n", argv[1]);
        return(1);
    }
    uint32_t fileSize;
    fileSize = ftell(in_file);
    
#if DEBUG
    printf("[DEBUG] filesize is %d\n", fileSize);
#endif
    if (fseek(in_file, 0, SEEK_SET))
    {
		printf("[ERROR] Fseek failed at %s\n", argv[1]);
        return(1);
    }
	uint8_t *targetBuffer;
    
	MALLOC(targetBuffer, fileSize);
    fread(targetBuffer, fileSize, 1, in_file);
	if (ferror(in_file))
	{
		printf("[ERROR] fread failed at %s\n", argv[1]);
		return(1);
	}
    fclose(in_file);
    
    // verify if it's a valid mach-o binary
    verify_macho(targetBuffer);
    // 
    get_header_info(targetBuffer);
    
    //
    get_symbols_info(targetBuffer);
    
    // start encrypting
    for (uint32_t i = 0; i < headerInfo.nrFunctions; i++)
    {
        if (strcmp(symbolsInfo[i].name, argv[2]) == 0)
        {
            printf("Found target function to encrypt!\n");
            for (uint32_t x = 0; x < symbolsInfo[i].size; x++)
            {
                *(uint8_t*)(targetBuffer+symbolsInfo[i].offset+x) ^= 0x69;
            }
            printf("Original values %x %x\n", *(uint32_t*)(targetBuffer + headerInfo.tableLocation), *(uint32_t*)(targetBuffer + headerInfo.tableLocation+4));
            *(uint32_t*)(targetBuffer + headerInfo.tableLocation) = symbolsInfo[i].location;
            *(uint32_t*)(targetBuffer + headerInfo.tableLocation+4) = symbolsInfo[i].size;
            printf("Modified values %x %x\n", *(uint32_t*)(targetBuffer + headerInfo.tableLocation), *(uint32_t*)(targetBuffer + headerInfo.tableLocation+4));
        }
    }
    
    FILE *output = NULL;
    output = fopen("crap", "wb");
    fwrite(targetBuffer, fileSize, 1, output);
    fclose(output);
    free(symbolsInfo);
    free(targetBuffer);
    return 0;
}
Exemplo n.º 2
0
static WAVE_PLAY *create(WAVE_PLAY **p_wave_play,WAVE_PARAMS *p_wave_params)
{

	WAVE_PLAY		*p_this_wave=NULL;


	p_this_wave=safe_malloc(sizeof(WAVE_PLAY));
	memset(p_this_wave,0,sizeof(WAVE_PLAY));
	
	p_this_wave->wave_file=strcpy(safe_malloc(strlen(p_wave_params->wave_file)+1),p_wave_params->wave_file);

	p_this_wave->gain=p_wave_params->gain;

	p_this_wave->loops=p_wave_params->loops;

	p_this_wave->cb_is_exit=p_wave_params->p_func;

	p_this_wave->cbClientData=p_wave_params;

	p_this_wave->f=0;

#ifndef _WIN32

	if (!(p_this_wave->f=utf_fopen(p_wave_params->wave_file,"r"))) {
#else

	if (!(p_this_wave->f=utf_fopen(p_wave_params->wave_file,"r+b"))) {
#endif

		DBG_PRINTF((LOG_CRIT, "C:" MODULE_TAG "fopen failed in function create, " \
					"attempting to open wave file %s...\n",p_wave_params->wave_file));

		destroy(&p_this_wave);

		return NULL;
	}
	
	if (!(get_header_info(p_this_wave))) {

		DBG_PRINTF((LOG_CRIT, "C:" MODULE_TAG "get_header_info failed in function create...\n"));

		destroy(&p_this_wave);

		return NULL;
	}

	if (!(p_this_wave->bits_per_sample==8 || p_this_wave->bits_per_sample==16 || 
		p_this_wave->bits_per_sample==24 || p_this_wave->bits_per_sample==32))

		p_this_wave->gain=0;

	p_this_wave->bytes_per_sample=p_this_wave->bits_per_sample/8;

	/*stream buff_factor mult or div of bytes per second at a time*/

	p_this_wave->buffer_size=(int) (p_this_wave->sample_rate*(!(p_wave_params->buff_factor) ?
		.25:p_wave_params->buff_factor)*p_this_wave->block_align*p_this_wave->output_factor);

	p_this_wave->wave_buff[0]=safe_malloc(p_this_wave->buffer_size);
	p_this_wave->wave_buff[1]=safe_malloc(p_this_wave->buffer_size);

	p_this_wave->cur_buffer=0;

#ifdef _WIN32

	p_this_wave->win_data.whdr[0].lpData=p_this_wave->wave_buff[0];
	p_this_wave->win_data.whdr[1].lpData=p_this_wave->wave_buff[1];
	p_this_wave->win_data.whdr[0].dwBufferLength=p_this_wave->buffer_size;
	p_this_wave->win_data.whdr[1].dwBufferLength=p_this_wave->buffer_size;
	p_this_wave->win_data.whdr[0].dwFlags=0;
	p_this_wave->win_data.whdr[1].dwFlags=0;

	p_this_wave->win_data.hBuffSem=CreateSemaphore(NULL,0,1,NULL);

#endif

	*p_wave_play=p_this_wave;


	return p_this_wave;
}

#ifdef _WIN32

static int unprepair_header(WAVE_PLAY *p_wave_play,int index)
{

	int		wave_ret=MMSYSERR_NOERROR;


	while ((wave_ret=waveOutUnprepareHeader(p_wave_play->win_data.hwave,&(p_wave_play->win_data.whdr[index]),
		   sizeof(WAVEHDR)))==WAVERR_STILLPLAYING)

		wait_done_playing(p_wave_play);


	return wave_ret;
}