Esempio n. 1
0
void tik_print(tik_context* ctx)
{
	int i;
	eticket* tik = &ctx->tik;

	fprintf(stdout, "\nTicket content:\n");
	fprintf(stdout,
		"Signature Type:         %08x\n"
		"Issuer:                 %s\n",
		getle32(tik->sig_type), tik->issuer
	);

	fprintf(stdout, "Signature:\n");
	hexdump(tik->signature, 0x100);
	fprintf(stdout, "\n");

	memdump(stdout, "Encrypted Titlekey:     ", tik->encrypted_title_key, 0x10);
	
	if (settings_get_common_keyX(ctx->usersettings))
		memdump(stdout, "Decrypted Titlekey:     ", ctx->titlekey, 0x10);

	memdump(stdout,	"Ticket ID:              ", tik->ticket_id, 0x08);
	fprintf(stdout, "Ticket Version:         %d\n", getle16(tik->ticket_version));
	memdump(stdout,	"Title ID:               ", tik->title_id, 0x08);
	fprintf(stdout, "Common Key Index:       %d\n", tik->commonkey_idx);

	fprintf(stdout, "Content permission map:\n");
	for(i = 0; i < 0x40; i++) {
		printf(" %02x", tik->content_permissions[i]);

		if ((i+1) % 8 == 0)
			printf("\n");
	}
	printf("\n");
}
Esempio n. 2
0
static int proc_splboot_store(struct file *file,
                             const char *buffer,
                             unsigned long count,
                             void *data)
{
	loader_param* param = (loader_param*)(splmem+IMAGE_LOADER_SIZE);
	if(!spl_image_stored){
		printk(KERN_EMERG "Need store image.\n");
		return 0;
	}
	printk(KERN_EMERG "Starting new spl\n");

	param->version = 0;
	param->param_size = sizeof(*param);
	param->mddiaddr = (unsigned int)mddiaddr;
	param->machine_type = s_machine_type;
	strncpy(param->bootparam, s_bootparam, BOOTPARAM_SIZE);
	strncpy(param->serialno, s_serialno, SERIALNO_SIZE);
	if(boot_image_stored){
		param->bootimgaddr = IMAGE_BOOT_ADDR;
		param->bootimgsize = bootimg_off;
	}
	memcpy(spladdr, splmem, s_splsize);

	flush_icache_range((unsigned long) spladdr,
			   (unsigned long) spladdr + s_splsize);
	printk(KERN_INFO "Bye!\n");
	setup_mm_for_reboot(0);
	memdump(spladdr, 0x100);
	printk(KERN_INFO "spladdr=%p s_spladdr=%08x\n", spladdr, s_spladdr);
	spladdr = (void*)s_spladdr;
	memdump(spladdr, 0x100);
	cpu_reset(s_spladdr);
	return 0;
}
Esempio n. 3
0
void exefs_print(exefs_context* ctx)
{
	u32 i;
	char sectname[9];
	u32 sectoffset;
	u32 sectsize;

	fprintf(stdout, "\nExeFS:\n");
	for(i=0; i<8; i++)
	{
		exefs_sectionheader* section = (exefs_sectionheader*)(ctx->header.section + i);


		memset(sectname, 0, sizeof(sectname));
		memcpy(sectname, section->name, 8);

		sectoffset = getle32(section->offset);
		sectsize = getle32(section->size);

		if (sectsize)
		{
			fprintf(stdout, "Section name:           %s\n", sectname);
			fprintf(stdout, "Section offset:         0x%08x\n", sectoffset + 0x200);
			fprintf(stdout, "Section size:           0x%08x\n", sectsize);
			if (ctx->hashcheck[i] == Good)
				memdump(stdout, "Section hash (GOOD):    ", ctx->header.hashes[7-i], 0x20);
			else if (ctx->hashcheck[i] == Fail)
				memdump(stdout, "Section hash (FAIL):    ", ctx->header.hashes[7-i], 0x20);
			else
				memdump(stdout, "Section hash:           ", ctx->header.hashes[7-i], 0x20);
		}
	}
}
Esempio n. 4
0
int GenerateTicket(USER_CONTEXT *ctx)
{
	if(ctx->flags[verbose]) { printf("[+] Generating Ticket\n"); }
	ctx->cia_section[tik].size = (sizeof(TICKET_STRUCTURE)+ sizeof(TIK_2048_SIG_CONTEXT));
	ctx->cia_section[tik].buffer = malloc(ctx->cia_section[tik].size);
	if(ctx->cia_section[tik].buffer == NULL){
		printf("[!] Failed to allocated memory for ticket\n");
		return 1;
	}
	
	TICKET_STRUCTURE ticket;
	TIK_2048_SIG_CONTEXT sig;
	memset(&sig,0x0,sizeof(TIK_2048_SIG_CONTEXT));
	memset(&ticket,0x0,sizeof(TICKET_STRUCTURE));
	
	if(ctx->flags[verbose]) { printf(" > Collecting Data\n"); }
	ticket.TicketFormatVersion = ctx->core.ticket_format_ver;
	ticket.ca_crl_version = ctx->core.ca_crl_version;
	ticket.signer_crl_version = ctx->core.signer_crl_version;
	ticket.CommonKeyID = ctx->keys.common_key_id;
	
	memcpy(ticket.Issuer,ctx->core.TicketIssuer,0x40);
	memcpy(ticket.TicketID,ctx->core.TicketID,0x8);
	memcpy(ticket.DeviceID,ctx->core.DeviceID,0x4);
	memcpy(ticket.TitleID,ctx->core.TitleID,0x8);
	memcpy(ticket.TicketVersion,ctx->core.TicketVersion,0x2);
	
	if(ctx->flags[verbose]) { printf(" > Encrypting Titlekey\n"); }
	if(EncryptTitleKey(ticket.EncryptedTitleKey,ctx->keys.title_key,ctx->keys.common_key,ctx->core.TitleID) != 0){
		printf("[!] Failed to encrypt titlekey\n");
		return Fail;
	}
	if(ctx->flags[showkeys])
		memdump(stdout,"\n[+] Encrypted Title Key:   ",ticket.EncryptedTitleKey,0x10);
	
	if(SetStaticData(dev,ticket.StaticData) != 0){
		printf("[!] ERROR in Generating Ticket\n");
		return Fail;
	}
	if(ctx->flags[verbose]) { printf(" > Signing Ticket\n"); }
	u32_to_u8(sig.sig_type,RSA_2048_SHA256,BE);
	u8 hash[0x20];
	ctr_sha(&ticket,sizeof(TICKET_STRUCTURE),hash,CTR_SHA_256);
	if(ctr_rsa(hash,sig.data,ctx->keys.ticket.n,ctx->keys.ticket.d,RSA_2048_SHA256,CTR_RSA_SIGN) != Good){
		printf("[!] Failed to sign ticket\n");
		return ticket_gen_fail;
	}
	
	if(ctx->flags[info]){
		memdump(stdout,"[+] Ticket Signature:   ",sig.data,0x100);
	}
	
	memcpy(ctx->cia_section[tik].buffer,&sig,sizeof(TIK_2048_SIG_CONTEXT));
	memcpy((ctx->cia_section[tik].buffer + sizeof(TIK_2048_SIG_CONTEXT)),&ticket,sizeof(TICKET_STRUCTURE));
	return 0;
}
Esempio n. 5
0
/*
 *	HIDデバイスに HID Report を送信する.
 *	送信バッファの先頭の1バイトにReportID を入れる処理は
 *	この関数内で行うので、先頭1バイトを予約しておくこと.
 *
 *	id と Length の組はデバイス側で定義されたものでなければならない.
 *
 *	戻り値はHidD_SetFeatureの戻り値( 0 = 失敗 )
 *
 */
static int hidWrite(HANDLE h, char *buf, int Length, int id)
{
	int rc,err;
	DWORD sz;
	buf[0] = 0;		// ReportIDは常に0

#if	ASYNC_RW
	
	// イベントオブジェクトを作成する
	hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
	if( hEvent == NULL ) {
		return -1;	// エラー
	}
	// オーバーラップ構造体の初期化
	ZeroMemory( &g_ovl, sizeof(g_ovl) );
	g_ovl.Offset = 0;
	g_ovl.OffsetHigh = 0;
	g_ovl.hEvent = hEvent;

	rc = WriteFile(h, buf , Length , &sz, &g_ovl);
	if(rc==0) {	// Pending?
		if( (err=GetLastError()) != ERROR_IO_PENDING ) {
#if ASYNC_DEBUG
			memdump("WR", buf, Length);
			fprintf(stderr, "hidWrite() error %x\n" ,err);
#endif
			return -1;		//ERROR
		}
		if( WaitForSingleObject( hEvent, TIMEOUT_MS ) == WAIT_OBJECT_0 ) {
			rc = Length;	//一応成功.
		}else{
#if ASYNC_DEBUG
			memdump("WR", buf, Length);
			fprintf(stderr, "hidWrite() timeout\n" );
#endif
			return -1;		//タイムアウト,破棄,もしくは失敗.
		}
	}

#else
	rc = WriteFile(h, buf , Length , &sz, NULL);
#endif

#if	DEBUG_PKTDUMP
	memdump("WR", buf, Length);
#endif
	return rc;
}
void telnet_sddump( file_handle_t handle, char** argv, unsigned int argc )
{
	unsigned long sector = 0;
	char tmp[8];
	char* parseend;
	if( argc != 2)
	{
		file_puts("sddump [sector]\r\n", telnet_handle);
		return;
	} 
	sector = strtoul( argv[1], &parseend, 0);
	unsigned char* data = malloc( SECTOR_SIZE );
	unsigned char result = DFS_ReadSector(0, data, sector, 1);
	if( result == 0 )
	{
		memdump( handle, data, data + SECTOR_SIZE);
	}
	else
	{
		file_puts("Error reading sector. Response code:", handle );
		sprintf(tmp,"%02hhx", result );
		file_puts(tmp, handle);
		file_puts(CRLF, handle);
	}
	free(data);
	return;
}
Esempio n. 7
0
int bench_rx(void)
{
	int i,c=' ',r,errs=0;
	u_char buf[BENCH_LENGTH+1024];
	memset(buf,0,BENCH_LENGTH+1024);
	
	for(i=0;i<BENCH_LENGTH;i++,c++) {
		do {
			r = RS_getc();
		}while (r == RS_EMPTY);

		buf[i]=r;
		//memdump(buf+i,1,0);
		if(opt_d) {
			printf(" %02x",r);
		}

		if(r != (c & 0xff) ) {
			errs++;
		}
	}
	if(errs) {
		printf("Recv Error = %2d:\n", errs);
		memdump(buf,BENCH_LENGTH,0);
	}

	if(opt_d) {
		printf("\n");
	}

	return errs;
}
Esempio n. 8
0
/*********************************************************************
 *	RS232C 文字列データ 出力.
 *********************************************************************
 */
int	RS_putdata(	unsigned char *buf , int cnt )
{
	DWORD dwWritten=0;
	DWORD wcnt = 0;

#if	PACKET_DUMP
	memdump("WR", buf, cnt);
#endif

	memset(&ovlwr,0,sizeof(OVERLAPPED));
	ovlwr.hEvent = ovlwr_hEvent;

//	buf[cnt]=0; printf("%02x\n",buf[0]);

	int rc = WriteFile(comHandle, buf , cnt , &dwWritten, &ovlwr);
	if (rc == 0) {
		if((rc = GetLastError() ) == ERROR_IO_PENDING) 
		{
//			WaitForSingleObject(ovlwr.hEvent, INFINITE);
			GetOverlappedResult(comHandle,&ovlwr,&wcnt,FALSE);
			//printf("putComPort() data = %x\n",buf[0]);
			return cnt;
		}
	}
	return cnt;
}
Esempio n. 9
0
int ProcessNcchForCci(cci_settings *set)
{
	u8 *ncch;
	ncch_hdr *hdr;
	
	u8 titleId[8];
	u8 srcId[8];
	
	if(set->options.cverDataPath && set->content.active[7]){
		if(ProcessCverDataForCci(set))
			return FAILED_TO_IMPORT_FILE;
	}
	
	for(int i = 0; i < CCI_MAX_CONTENT; i++){
		if(set->content.active[i]){
			ncch = set->content.data + set->content.dOffset[i];
			if(!IsNcch(NULL,ncch)){
				fprintf(stderr,"[CCI ERROR] NCCH %d is corrupt\n",i);
				return NCSD_INVALID_NCCH;
			}
			hdr = (ncch_hdr*)ncch;
			if(i > 0 && !set->options.noModTid){
				if(set->options.verbose){
					printf("[CCI] Modifying NCCH %d IDs\n",i);
					printf("[Old Ids]\n");
					memdump(stdout," > TitleId:   0x",hdr->titleId,8);
					memdump(stdout," > ProgramId: 0x",hdr->programId,8);
				}
				GetNewNcchIdForCci(titleId,srcId,i,set->options.tmdHdr);
				if(ModifyNcchIds(ncch, titleId, srcId, set->keys))
					return -1;
				if(set->options.verbose){
					printf("[New Ids]\n");
					memdump(stdout," > TitleId:   0x",hdr->titleId,8);
					memdump(stdout," > ProgramId: 0x",hdr->programId,8);
				}
			}
			set->content.titleId[i] = u8_to_u64(hdr->titleId,LE);
			if(i == 0)
				memcpy(srcId,hdr->titleId,8);
		}
	}
	
	return 0;
}
Esempio n. 10
0
void keyset_dump_key128(key128* key, const char* keytitle)
{
	if (key->valid)
	{
		fprintf(stdout, "%s\n", keytitle);
		memdump(stdout, "", key->data, 16);
		fprintf(stdout, "\n");
	}
}
Esempio n. 11
0
void keyset_dump_rsakey(rsakey2048* key, const char* keytitle)
{
	if (key->keytype == RSAKEY_INVALID)
		return;


	fprintf(stdout, "%s\n", keytitle);

	memdump(stdout, "Modulus: ", key->n, 256);
	memdump(stdout, "Exponent: ", key->e, 3);

	if (key->keytype == RSAKEY_PRIV)
	{
		memdump(stdout, "P: ", key->p, 128);
		memdump(stdout, "Q: ", key->q, 128);
	}
	fprintf(stdout, "\n");
}
Esempio n. 12
0
int niffs_emul_create_file(niffs *fs, char *name, u32_t len) {
  int res;
  int fd = NIFFS_open(fs, name, NIFFS_O_CREAT | NIFFS_O_TRUNC | NIFFS_O_RDWR, 0);
  if (fd < 0) return fd;
  u8_t *data = niffs_emul_create_data(name, len);
  if (data == 0) return ERR_NIFFS_TEST_FATAL;
  res = NIFFS_write(fs, fd, data, len);
  if (res < 0) return res;
  res = NIFFS_lseek(fs, fd, 0, NIFFS_SEEK_SET);
  if (res < 0) return res;
  niffs_stat s;
  res = NIFFS_fstat(fs, fd, &s);
  if (s.size != len) {
    return ERR_NIFFS_TEST_FATAL;
  }
  u8_t buf[64];
  u32_t offs = 0;
  do {
    u32_t rlen = MIN(len - offs, sizeof(buf));
    res = NIFFS_read(fs, fd, &buf[0], rlen);
    if (res == 0) return ERR_NIFFS_TEST_EOF;
    if (res < 0) return res;
    if (res != rlen) {
      return ERR_NIFFS_TEST_FATAL;
    }
    if (memcmp(buf, &data[offs], rlen) != 0) {
      u32_t ix;
      u32_t mismatch_ix;
      memdump(buf, sizeof(buf));
      memdump(&data[offs < 32 ? 0 : offs-32], sizeof(buf));
      for (ix = 0; ix < rlen; ix++) {
        if (buf[ix] != data[offs+ix]) {
          mismatch_ix = ix;
        }
      }
      NIFFS_DBG("mismatch @ offset %i\n", offs+mismatch_ix);
      return ERR_NIFFS_TEST_REF_DATA_MISMATCH;
    }
    offs += rlen;
  } while (offs < len);
  (void)NIFFS_close(fs, fd);
  return res >= 0 ? NIFFS_OK : res;
}
Esempio n. 13
0
/*
 *	HIDデバイスに HID Report を送信する.
 *	送信バッファの先頭の1バイトにReportID を入れる処理は
 *	この関数内で行うので、先頭1バイトを予約しておくこと.
 *
 *	id と Length の組はデバイス側で定義されたものでなければならない.
 *
 *	戻り値はHidD_SetFeatureの戻り値( 0 = 失敗 )
 *
 */
static int hidWrite(HANDLE h, char *buf, int Length, int id)
{
	int rc;
	buf[0] = id;
	rc = HidD_SetFeature(h, buf, Length);
#if	DEBUG_PKTDUMP
	memdump("WR", buf, Length);
#endif
	return rc;
}
Esempio n. 14
0
int	hidWriteBuffer2(uchar *buf, int cnt)
{

#if	DEBUG_PKTDUMP
	memdump("W2", buf, cnt);
#endif

	RS_putdata(	buf , cnt );
	return 1;
}
Esempio n. 15
0
int	hidReadPoll(char *buf, int Length, int id)
{
	int rc;
	buf[0] = id;
	rc = HidD_GetFeature(hHID, buf, Length);
#if	DEBUG_PKTDUMP
	memdump("RD", buf, Length);
#endif
	return rc;
}
Esempio n. 16
0
int	hidWriteBuffer(uchar *buf, int cnt)
{
	buf[0]=0x01;

#if	DEBUG_PKTDUMP
	memdump("WB", buf, cnt);
#endif

	RS_putdata(	buf , cnt );
	return 1;
}
Esempio n. 17
0
/*
 *	HIDデバイスから HID Report を取得する.
 *	受け取ったバッファは先頭の1バイトに必ずReportIDが入っている.
 *
 *	id と Length の組はデバイス側で定義されたものでなければならない.
 *
 *	戻り値はHidD_GetFeatureの戻り値( 0 = 失敗 )
 *
 */
static int hidRead(HANDLE h, char *buf, int Length, int id)
{
	int rc;
	buf[0] = id;
	rc = HidD_GetFeature(h, buf, Length);
#if	DEBUG_PKTDUMP
	memdump("RD", buf, Length);
	printf("id=%d Length=%d rc=%d\n",id,Length,rc);
#endif
	return rc;
}
Esempio n. 18
0
/*!
 *	60バイトのパケットをCDCデバイスに送出する.
 *	----------------------------------------------------
 *	送信バッファの先頭の1バイトにReportID を入れる処理は
 *	この関数内で行うので、先頭1バイトを予約しておくこと.
 *
 *	引数:
 *		buf[60];
 *		cnt = PACKET_SIZE (60固定)
 *	戻り値:
 *		1= 成功.
 *		0= 失敗.
 */
static int hidWrite(uchar *buf, int cnt)
{
	buf[0]=0x01;

#if	DEBUG_PKTDUMP
	memdump("WR", (char*) buf, cnt);
#endif

	RS_putdata(	buf , cnt );
	return 1;
}
Esempio n. 19
0
int	hidReadPoll(char *buf,int Length, int id)
{
	int rc;
	buf[0] = id;
	rc = usb_interrupt_read(usb_dev, EP_IN , buf+1 , Length, 5000);
//	rc = HidD_GetFeature(hHID, buf, Length);
#if	DEBUG_PKTDUMP
	memdump("RD", buf, Length);
#endif
	return rc;
}
Esempio n. 20
0
/*
 *	HIDデバイスから HID Report を取得する.
 *	受け取ったバッファは先頭の1バイトに必ずReportIDが入っている.
 *
 *	id と Length の組はデバイス側で定義されたものでなければならない.
 *
 *	戻り値はHidD_GetFeatureの戻り値( 0 = 失敗 )
 *
 */
static int hidRead(char *buf, int Length, int id)
{
	int rc;
	buf[0] = id;
	rc = usb_interrupt_read(usb_dev, EP_IN , buf+1 , Length-1, 5000);
//	rc = HidD_GetFeature(h, buf, Length);
#if	DEBUG_PKTDUMP
	memdump("RD", buf, Length);
	printf("id=%d Length=%d rc=%d\n",id,Length,rc);
#endif
	return rc;
}
Esempio n. 21
0
/*
 *	HIDデバイスに HID Report を送信する.
 *	送信バッファの先頭の1バイトにReportID を入れる処理は
 *	この関数内で行うので、先頭1バイトを予約しておくこと.
 *
 *	id と Length の組はデバイス側で定義されたものでなければならない.
 *
 *	戻り値はHidD_SetFeatureの戻り値( 0 = 失敗 )
 *
 */
static int hidWrite(char *buf, int Length, int id)
{
	int rc;
	buf[0] = id;
	rc = usb_interrupt_write(usb_dev, EP_OUT , buf+1 , Length -1 , 5000);
//	rc = HidD_SetFeature(h, buf, Length);

#if	DEBUG_PKTDUMP
	memdump("WR", buf, Length);
#endif
	return rc;
}
Esempio n. 22
0
void thread(void){
	while(1){
		if(isPressed(BUTTON_SELECT | BUTTON_X)){
            screenShot(TOP_FRAME);
            screenShot(BOT_FRAME);
        }
        if(isPressed(BUTTON_START | BUTTON_X)){ 
            memdump(L"sdmc:/FCRAM.bin", (void*)0x27500000, 0x600000);
        }
        patches();
	}
	__asm("SVC 0x09");
}
Esempio n. 23
0
void thread(void){
	while(1){
        if(isPressed(BUTTON_START | BUTTON_X)){
            unsigned char buf[0x10] = {0};
            int loc = 0;
            fileReadWrite(buf, L"sdmc:/rei/RAM.txt", 0x20, READ);
            loc = atoi(buf);
            memdump(L"sdmc:/RAMdmp.bin", (void*)loc, 0x10000);
        }
        patches();
	}
	__asm("SVC 0x09");
}
Esempio n. 24
0
void thread(void){
	while(1){
		if(isPressed(BUTTON_SELECT | BUTTON_X)){
            screenShot(TOP_FRAME);
            screenShot(BOT_FRAME);
        }
        if(isPressed(BUTTON_START | BUTTON_X)){ 
            memdump(L"sdmc:/BootRom.bin", 0xFFFF0000, 0x8000);
        }
        patches();
	}
	__asm("SVC 0x09");
}
Esempio n. 25
0
int GenAESMAC(u8 KeyX[16], u8 KeyY[16], AESMAC_CTX *ctx)
{
	/* Generating Hash for AES MAC */
	u8 result = PrepAESMAC(ctx);
	if(result)
		return result;
	
	/* Preparing for Crypto functions */
	u8 *encrypted_hash = malloc(0x20);
	u8 *outkey = malloc(16);
	u8 IV[16];
	memset(encrypted_hash,0,0x20);
	memset(outkey,0,16);
	memset(&IV,0,16);
	
	/* Getting Key for AES MAC */
	ctr_keyscrambler(outkey,KeyX,KeyY); //Not implemented yet, as no one knows that. ATM, it's a placeholder keyscrambler for testing.
	
	/* Crypting hash */
	ctr_aes_context aes_cbc;
	ctr_init_aes_cbc(&aes_cbc,outkey,IV,ENC);
	ctr_aes_cbc(&aes_cbc,ctx->hash,encrypted_hash,0x20,ENC);
	
	if(ctx->Verbose){
		memdump(stdout," KeyX:              ",KeyX,16);
		memdump(stdout," KeyY:              ",KeyY,16);
		memdump(stdout," Normal Key:        ",outkey,16);
		memdump(stdout," Hash For MAC:      ",ctx->hash,0x20);
		memdump(stdout," MAC:               ",encrypted_hash+0x10,16);
	}
	
	
	/* Writing AES MAC to context */
	memcpy(ctx->aesmac,encrypted_hash+0x10,16);	

	free(outkey);
	free(encrypted_hash);
	return 0;
}
Esempio n. 26
0
void flush_write(uint8_t *req)
{
    if (req)
        write_item(req);
    int write_length = buffer_current_size();
    usbreadbuffer_ptr = usbreadbuffer;
    if (!write_length)
        return;
    ftdi_write_data(global_ftdi, usbreadbuffer, write_length);
    read_size_ptr = 0;

    const uint8_t *p = usbreadbuffer;
    while (write_length > 0) {
        int plen = 1;
        uint8_t ch = *p;
        unsigned tlen = (p[2] << 8 | p[1]) + 1;
        switch(ch) {
        case 0x85: case 0x87: case 0x8a: case 0xaa: case 0xab:
            break;
        case 0x2e:
            plen = 2;
            break;
        case 0x19: case 0x1b: case 0x2c: case 0x3d: case 0x3f: case 0x4b:
        case 0x6f: case 0x80: case 0x82: case 0x86: case 0x8f:
            plen = 3;
            break;
        default:
            memdump(p-1, write_length, "UNABLE TO PARSE OUTPUT COMMAND");
            exit(-1);
        }
        if (ch & MPSSE_DO_READ) {
            if (ch & MPSSE_BITMODE) {
                int bitsize = *(p+1)+1;
                if (ch & MPSSE_WRITE_TMS)
                    bitsize = 1;
                read_size[read_size_ptr] = -bitsize; /* number of bits */
            }
            else if (ch == 0x2c || ch == 0x3d)       /* DATAR or DATARW */
                read_size[read_size_ptr] = tlen;     /* number of bytes */
            else
                read_size[read_size_ptr] = *(p+1);   /* number of bytes */
            read_size_ptr++;
        }
        p += plen;
        write_length -= plen;
        if (ch == 0x19 || ch == 0x3d) {
            p += tlen;
            write_length -= tlen;
        }
    }
}
Esempio n. 27
0
void ncsd_print(ncsd_context* ctx)
{
	char magic[5];
	ctr_ncsdheader* header = &ctx->header;
	unsigned int i;
	unsigned int mediaunitsize = (unsigned int) ncsd_get_mediaunit_size(ctx);


	memcpy(magic, header->magic, 4);
	magic[4] = 0;

	fprintf(stdout, "Header:                 %s\n", magic);
	if (ctx->headersigcheck == Unchecked)
		memdump(stdout, "Signature:              ", header->signature, 0x100);
	else if (ctx->headersigcheck == Good)
		memdump(stdout, "Signature (GOOD):       ", header->signature, 0x100);
	else
		memdump(stdout, "Signature (FAIL):       ", header->signature, 0x100);       
	fprintf(stdout, "Media size:             0x%08x\n", getle32(header->mediasize));
	fprintf(stdout, "Media id:               %016"PRIx64"\n", getle64(header->mediaid));
	//memdump(stdout, "Partition FS type:      ", header->partitionfstype, 8);
	//memdump(stdout, "Partition crypt type:   ", header->partitioncrypttype, 8);
	//memdump(stdout, "Partition offset/size:  ", header->partitionoffsetandsize, 0x40);
	fprintf(stdout, "\n");
	for(i=0; i<8; i++)
	{
		u32 partitionoffset = header->partitiongeometry[i].offset * mediaunitsize;
		u32 partitionsize = header->partitiongeometry[i].size * mediaunitsize;

		if (partitionsize != 0)
		{
			fprintf(stdout, "Partition %d            \n", i);
			memdump(stdout, " Id:                    ", header->partitionid+i*8, 8);
			fprintf(stdout, " Area:                  0x%08X-0x%08X\n", partitionoffset, partitionoffset+partitionsize);
			fprintf(stdout, " Filesystem:            %02X\n", header->partitionfstype[i]);
			fprintf(stdout, " Encryption:            %02X\n", header->partitioncrypttype[i]);
			fprintf(stdout, "\n");
		}
	}
	memdump(stdout, "Extended header hash:   ", header->extendedheaderhash, 0x20);
	memdump(stdout, "Additional header size: ", header->additionalheadersize, 4);
	memdump(stdout, "Sector zero offset:     ", header->sectorzerooffset, 4);
	memdump(stdout, "Flags:                  ", header->flags, 8);
	fprintf(stdout, " > Mediaunit size:      0x%X\n", mediaunitsize);
	fprintf(stdout, " > Mediatype:           %s\n", ncsd_print_mediatype(header->flags[5]));
	fprintf(stdout, " > Card Device:         %s\n", ncsd_print_carddevice(header->flags[3] | header->flags[7]));

}
Esempio n. 28
0
File: divert.c Progetto: bave/prison
void read_loop(int fd)
{
    struct sockaddr_in  sin;
    struct ip          *ip;
    socklen_t sin_len;
    ssize_t   size;
    uint8_t   buf[1024 * 100];
    uint8_t*  bufptr;
    bufptr = buf;

    sin_len = sizeof(sin);
    for(;;) {
        size = recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr*)&sin, &sin_len);
        if (size < 0) {
            perror("recvfrom");
            exit(-1);
        }
        memdump(&sin, sizeof(sin));
        printf("if addr: %s\n", inet_ntoa(sin.sin_addr));
        /*
        uint8_t  sin_len;
        uint8_t  sin_family;
        uint16_t sin_port;
        struct  in_addr {
            in_addr_t s_addr;
        } sin_addr;
        char    sin_zero[8];
        */
    
        printf("\n");

        ip = (struct ip*)buf;
        ip->ip_src.s_addr=inet_addr("127.0.0.1");
        ip->ip_dst.s_addr=inet_addr("127.0.0.1");
        //ip->ip_sum = 0x0000;

        printf("recv %lu[bytes]\n", size);
        printf("src: %s\n", inet_ntoa(ip->ip_src));
        printf("dst: %s\n", inet_ntoa(ip->ip_dst));
        printf("protocol: %d\n\n", ip->ip_p);
        /*
        */
        struct tcphdr* tcp = (struct tcphdr*)(bufptr + 20);
        tcp->th_sum = 0x0000;
        //uint8_t* tcp_op = (bufptr + 20 + 20);
        sendto(fd, buf, size, 0, (struct sockaddr*)&sin, sin_len);
    }
}
Esempio n. 29
0
void niffs_emul_dump_pix(niffs *fs, niffs_page_ix pix) {
  niffs_page_hdr *phdr = (niffs_page_hdr *)_NIFFS_PIX_2_ADDR(fs, pix);
  printf("PIX:%04i @ %p\n", pix, phdr);
  printf("  flag:%04x  id:%04x  oid:%02x  spix:%02x\n",
      phdr->flag, phdr->id.raw, phdr->id.obj_id, phdr->id.spix);
  u8_t *data = (u8_t *)phdr + sizeof(niffs_page_hdr);
  u32_t len = _NIFFS_SPIX_2_PDATA_LEN(fs, 1);
  if (!_NIFFS_IS_FREE(phdr) && !_NIFFS_IS_DELE(phdr) &&_NIFFS_IS_ID_VALID(phdr) && phdr->id.spix == 0) {
    niffs_object_hdr *ohdr = (niffs_object_hdr *)phdr;
    printf("  length:%08x  name:%s\n", ohdr->len, ohdr->name);
    data = (u8_t *)phdr + sizeof(niffs_object_hdr);
    len = _NIFFS_SPIX_2_PDATA_LEN(fs, 0);
  }

  memdump(data, len);
}
void telnet_memdump( file_handle_t handle, char** argv, unsigned int argc )
{
	char* memstart = NULL;
	char* parseend;
	unsigned int len = 0;
	if( argc != 3)
	{
		file_puts("memdump [address] [count]\r\n", telnet_handle);
		return;
	} 
	memstart = (char*)(unsigned short) strtoul( argv[1], &parseend, 0);
	len = (unsigned int) strtoul( argv[2], &parseend, 0);
	memdump( handle, memstart, memstart + len);

	return;
}