BOOLEAN ept_hw_invvpid_single_context(UINT64 vpid) { INVVPID_ARG arg; const VMCS_HW_CONSTRAINTS *hw_constraints = vmcs_hw_get_vmx_constraints(); UINT64 rflags; BOOLEAN status = FALSE; #ifdef JLMDEBUG1 bprint("ept_hw_invvpid_single_context\n"); #endif if(!ept_hw_is_invvpid_supported()) { VMM_ASSERT(0); return TRUE; } arg.vpid = vpid; if(hw_constraints->ept_vpid_capabilities.Bits.InvvpidContextWide) { vmm_asm_invvpid(&arg, INVVPID_SINGLE_CONTEXT, &rflags); status = ((rflags & 0x8d5) == 0); if(!status) { #ifdef JLMDEBUG bprint("vmm_asm_invvpid failed\n"); #endif VMM_LOG(mask_anonymous, level_trace, "ept_hw_invvpid_all_contexts ERROR: rflags = %p\r\n", rflags); VMM_ASSERT(0); } } return status; }
struct _VMCS_OBJECT * vmcs_act_create(GUEST_CPU_HANDLE gcpu) { struct _VMCS_ACTUAL_OBJECT *p_vmcs; #ifdef JLMDEBUG bprint("vmcs_act_create\n"); #endif p_vmcs = vmm_malloc(sizeof(*p_vmcs)); if (NULL == p_vmcs) { VMM_LOG(mask_anonymous, level_trace,"[vmcs] %s: Allocation failed\n", __FUNCTION__); return NULL; } p_vmcs->cache = cache64_create(VMCS_FIELD_COUNT); if (NULL == p_vmcs->cache) { vmm_mfree(p_vmcs); VMM_LOG(mask_anonymous, level_trace,"[vmcs] %s: Allocation failed\n", __FUNCTION__); return NULL; } #ifdef JLMDEBUG bprint("about to set vmcs entries in vmcs create\n"); #endif p_vmcs->hva = vmcs_hw_allocate_region(&p_vmcs->hpa); // validate it's ok TBD p_vmcs->flags|= NEVER_ACTIVATED_FLAG; p_vmcs->owning_host_cpu = CPU_NEVER_USED; p_vmcs->gcpu_owner = gcpu; p_vmcs->vmcs_base->vmcs_read = vmcs_act_read; p_vmcs->vmcs_base->vmcs_write = vmcs_act_write; p_vmcs->vmcs_base->vmcs_flush_to_cpu = vmcs_act_flush_to_cpu; p_vmcs->vmcs_base->vmcs_flush_to_memory = vmcs_act_flush_to_memory; p_vmcs->vmcs_base->vmcs_is_dirty = vmcs_act_is_dirty; p_vmcs->vmcs_base->vmcs_get_owner = vmcs_act_get_owner; p_vmcs->vmcs_base->vmcs_destroy = vmcs_act_destroy; p_vmcs->vmcs_base->vmcs_add_msr_to_vmexit_store_list = vmcs_act_add_msr_to_vmexit_store_list; p_vmcs->vmcs_base->vmcs_add_msr_to_vmexit_load_list = vmcs_act_add_msr_to_vmexit_load_list; p_vmcs->vmcs_base->vmcs_add_msr_to_vmenter_load_list = vmcs_act_add_msr_to_vmenter_load_list; p_vmcs->vmcs_base->vmcs_add_msr_to_vmexit_store_and_vmenter_load_list = vmcs_act_add_msr_to_vmexit_store_and_vmenter_load_lists; p_vmcs->vmcs_base->vmcs_delete_msr_from_vmexit_store_list = vmcs_act_delete_msr_from_vmexit_store_list; p_vmcs->vmcs_base->vmcs_delete_msr_from_vmexit_load_list = vmcs_act_delete_msr_from_vmexit_load_list; p_vmcs->vmcs_base->vmcs_delete_msr_from_vmenter_load_list = vmcs_act_delete_msr_from_vmenter_load_list; p_vmcs->vmcs_base->vmcs_delete_msr_from_vmexit_store_and_vmenter_load_list = vmcs_act_delete_msr_from_vmexit_store_and_vmenter_load_lists; p_vmcs->vmcs_base->level = VMCS_MERGED; p_vmcs->vmcs_base->skip_access_checking = FALSE; p_vmcs->vmcs_base->signature = VMCS_SIGNATURE; vmcs_init_all_msr_lists(p_vmcs->vmcs_base); return p_vmcs->vmcs_base; }
VMM_STATUS vmcs_hierarchy_create(VMCS_HIERARCHY *obj, GUEST_CPU_HANDLE gcpu) { VMM_STATUS status; #ifdef JLMDEBUG bprint("vmcs_hierarchy_create\n"); #endif VMM_ASSERT(obj); VMCS_OBJECT * v= vmcs_act_create(gcpu); if(NULL==v) { #ifdef JLMDEBUG bprint("vmcs_act_creat retuns NULL\n"); LOOP_FOREVER #endif }
bool bprint_Write(BPRINT_BUFFER & bp, LPCTSTR psz) { if (psz) bprint(bp, psz); if (bp.cch > 0) { if (bp.cch > bp.cchMax) { DebugBreak(); bp.cch = bp.cchMax; } bp.psz[bp.cch] = 0; #if 1 dprintf(bp.flags, "%s", bp.psz); #else if (bp.hOut) { DWORD cbWrote = 0; dprintf(bp.hOut, bp.psz, bp.cch, &cbWrote, NULL); } #endif bp.cch = 0; return true; } return false; }
void ReportError(int err, LPCSTR szContext, LPCTSTR pszPath) { BPRINT_BUFFER & bp = *g_pbpErr; bprint_EndLine(bp); bprint(bp, szContext); if (pszPath) { bprint_Sep(bp, ' '); bprint(bp, pszPath); } bprint_Sep(bp, ' '); bprint(bp, TEXT("Failed : ")); bprint_AppendErrorText(bp, err); bprint_EndLine(bp); }
void Builder::irgen(File* file) { // Generates code for all basic blocks using the Jogo intermediate // represenation. Also performs optimizations, if enabled by the // environment options. Machine::Ptr machine = Machine::intel64(); IrGenerator::Ptr bgen(new IrGenerator(env_, machine)); RegisterAllocator::Ptr alloc(new RegisterAllocator(env_, machine)); IrBlockPrinter::Ptr bprint(new IrBlockPrinter(env_, machine)); Stream::Ptr out = Stream::stout(); out->machine(machine); bprint->out(out); bgen->operator()(file); if (env_->dump_ir() && env_->verbose()) { bprint->operator()(file); } if (env_->optimize()) { CopyPropagator::Ptr copy(new CopyPropagator(env_, machine)); DeadCodeEliminator::Ptr elim(new DeadCodeEliminator(env_, machine)); copy->operator()(file); elim->operator()(file); } if (env_->dump_ir() && env_->verbose()) { bprint->operator()(file); } alloc->operator()(file); DeadCodeEliminator::Ptr elim(new DeadCodeEliminator(env_, machine)); elim->operator()(file); if (env_->dump_ir()) { bprint->operator()(file); } }
void HexDump(uint8_t* start, uint8_t* end) { uint8_t* p= start; int i; while(p<=end) { bprint("%p: ", p); i= 0; while(p<=end) { bprint("%08x ", *(uint32_t*)p); p+= 4; i++; if(i>3) break; } bprint("\n"); } bprint("\n"); }
const char* get_option_val(const cmdline_option_t *options, char vals[][MAX_VALUE_LEN], const char *opt_name) { int i; for (i = 0; options[i].name != NULL; i++ ) { if ( vmm_strcmp(options[i].name, opt_name) == 0 ) return vals[i]; } bprint("requested unknown option: %s\n", opt_name); return NULL; }
int main(void) { int i; for (i = 0; i <= 10; i++) { bprint(i); putchar('\n'); } return 0; }
int main() { int i,n; while(scanf("%d",&n)!=EOF){ init(); for(i=1;i<=n;i++){ multipy(i); } bprint(); } return 0; }
// invalidate VPID BOOLEAN ept_hw_is_invvpid_supported(void) { const VMCS_HW_CONSTRAINTS *hw_constraints = vmcs_hw_get_vmx_constraints(); if(ept_hw_is_ept_supported() && hw_constraints->ept_vpid_capabilities.Bits.InvvpidSupported) { return TRUE; } #ifdef JLMDEBUG bprint("ept_hw_is_invvpid_supported is returning false\n"); #endif return FALSE; }
void check_boot_parameters() { UINT64* regs = *g_guest_regs_save_area; UINT64 rdi_reg= regs[4]; UINT64 rsi_reg= regs[5]; UINT64 ept; UINT64 real; UINT64 virt; UINT64 value; bprint("rdi on entry: %llx, rsi: %llx\n", rdi_reg, rsi_reg); boot_params_t* boot_params= (boot_params_t*) rdi_reg; //HexDump((UINT8*)rdi_reg, (UINT8*)rdi_reg+32); //bprint("cmd line ptr: %p\n", boot_params->hdr.cmd_line_ptr); //bprint("code32_start: %p\n", boot_params->hdr.code32_start); bprint("loadflags: %02x\n", boot_params->hdr.loadflags); vmx_vmread(0x201a, &ept); virt= rdi_reg; real= getphysical(ept, virt); bprint("virt: %016llx, real: %016llx\n", virt, real); virt= (UINT64) &(boot_params->hdr.loadflags); real= getphysical(ept, virt); bprint("virt: %016llx, real: %016llx\n", virt, real); vmx_vmread(0x681e, &value); // guest_rip virt =value; real= getphysical(ept, virt); bprint("virt: %016llx, real: %016llx\n", virt, real); virt =value+10; real= getphysical(ept, virt); bprint("virt: %016llx, real: %016llx\n", virt, real); }
void blean(int* list, int list_size, int digit) { int i; if(list_size == digit){ bprint(list, list_size); } else{ for(i=0; i<=1; i++){ list[digit] = i; blean(list, list_size, digit+1); } } }
static void PrintSidName(PSID psid, BPRINT_BUFFER & bp) { TCHAR szDomain[32]; // max domain name is actually 15 DWORD cchDomain = NUMCHARS(szDomain); TCHAR szName[MAX_PATH]; DWORD cchName = NUMCHARS(szName); SID_NAME_USE snu; szDomain[0] = szName[0] = 0; if ( ! LookupAccountSid(NULL, psid, szName, &cchName, szDomain, &cchDomain, &snu)) { if (GetLastError() != ERROR_NONE_MAPPED) ReportError(GetLastError(), "LookupAccountSid"); } else { if (szDomain[0]) { bprint(bp, szDomain); bprint(bp, "\\"); } bprint(bp, szName); } }
void bprint(unsigned int n) { if (n == 0) { putchar('0'); return ; } else if (n == 1) { putchar('1'); return; } bprint(n / 2); if ((n & 1) == 1) { putchar('1'); } else { putchar('0'); } }
void fixupvmcs() { UINT64 value; void loop_forever(); #ifdef JLMDEBUG UINT16* loop= (UINT16*)loop_forever; bprint("fixupvmcs %04x\n\n", *loop); #endif vmx_vmread(0x681e, &value); // guest_rip #ifdef JLMDEBUG check_boot_parameters(); #endif //bprint("Code at %p\n", value); //HexDump((UINT8*)value, (UINT8*)value+32); //*(UINT16*) (value+0x8)= *loop; // feeb //*(UINT16*) (value+0xa)= *loop; // feeb //*(UINT16*) (value+0x10)= *loop; // feeb //*(UINT16*) (value+0x16)= *loop; // feeb // vmx_vmread(0x4000, &value); // vmx_pin_controls // vmx_vmwrite(0x4000, value); // vmx_pin_controls // vmx_vmread(0x4002, &value); // vmx_cpu_controls // vmx_vmwrite(0x4002, value); // vmx_cpu_controls // vmx_vmread(0x401e, &value); // vmx_secondary_controls // vmx_vmwrite(0x401e, value); // vmx_secondary_controls // vmx_vmread(0x4012, &value); // vmx_entry_controls // vmx_vmwrite(0x4012, value); // vmx_entry_controls // vmx_vmread(0x4002, &value); // vmx_exit_controls // vmx_vmwrite(0x4002, value); // vmx_exit_controls vmm_vmcs_guest_state_read((UINT64*) t_vmcs_save_area); vmm_print_vmcs_region((UINT64*) t_vmcs_save_area); }
static void format(char *mnemonic, Instr *i, char *f) { if (mnemonic) format(0, i, mnemonic); if (f == 0) return; if (i->curr < i->end) *i->curr++ = '\t'; for ( ; *f && i->curr < i->end; f++) { if (*f != '%') { *i->curr++ = *f; continue; } switch (*++f) { case 's': bprint(i, "%d", i->rs); break; case 't': bprint(i, "%d", i->rt); break; case 'd': bprint(i, "%d", i->rd); break; case 'a': bprint(i, "%d", i->sa); break; case 'l': if (i->rs == 30) { i->curr += symoff(i->curr, i->end-i->curr, i->immediate+mach->sb, CANY); bprint(i, "(SB)"); } else bprint(i, "%lx(r%d)", i->immediate, i->rs); break; case 'i': bprint(i, "$%lx", i->immediate); break; case 'u': *i->curr++ = '$'; i->curr += symoff(i->curr, i->end-i->curr, i->immediate, CANY); bprint(i, "(SB)"); break; case 'j': i->curr += symoff(i->curr, i->end-i->curr, (i->target<<2)|(i->addr & 0xF0000000), CANY); bprint(i, "(SB)"); break; case 'b': i->curr += symoff(i->curr, i->end-i->curr, (i->immediate<<2)+i->addr+4, CANY); break; case 'c': bprint(i, "%lux", i->cofun); break; case 'w': bprint(i, "[%lux]", i->w0); break; case 'f': *i->curr++ = fsub[i->rs & 0x0F]; break; case '\0': *i->curr++ = '%'; return; default: bprint(i, "%%%c", *f); break; } } }
int DeletePath(LPCTSTR pszPathIn, LPCTSTR pszPattern, DWORD fdwTraverse, DWORD fdwSecurity, DWORD fdwVerbose, BPRINT_BUFFER & bp) { DWORD fdwFlags = fdwTraverse & (TDT_INPUTMASK & ~TDT_USERMASK); if (fdwVerbose & DP_V_VERBOSE) fdwFlags |= TDT_USER_F_VERBOSE; if (fdwVerbose & DP_V_DIAGNOSTIC) fdwFlags |= TDT_DIAGNOSTIC; bool fQuiet = (fdwVerbose & DP_V_QUIET) != 0; DeletePathData lad; ZeroStruct(&lad); lad.pbp = &bp; if (fdwSecurity & DP_S_NODELETE) lad.fNoDelete = true; fdwFlags |= TDT_DIRLAST; // So we get directory callbacks after children have been deleted. // if the path isn't too long, convert to canonical form. for long paths // they has better provide canonical form to begin with. // TCHAR szCanonPath[MAX_PATH+1]; LPCTSTR pszPath = pszPathIn; if (lstrlen(pszPathIn) < MAX_PATH && PathCanonicalize(szCanonPath, pszPathIn)) { pszPath = szCanonPath; } // the unicode versions of the windows file api's can handle very long // path names if they are canonical and if they are preceeded by \\?\. // if we are build unicode, take advantage of that capability. #ifdef UNICODE static const TCHAR szPre[]= TEXT("\\\\?\\"); TCHAR szFullPath[MAX_PATH + NUMCHARS(szPre)]; TCHAR * pszFullPath = szFullPath; TCHAR * pszFilePart = NULL; lstrcpy(szFullPath, szPre); UINT cchFullPath = GetFullPathName(pszPath, MAX_PATH, szFullPath + NUMCHARS(szPre)-1, &pszFilePart); if (cchFullPath >= NUMCHARS(szFullPath)-1) { pszFullPath = (TCHAR *)LocalAlloc(LPTR, (cchFullPath + NUMCHARS(szPre) + 2) * sizeof(TCHAR)); if (pszFullPath) { lstrcpy(pszFullPath, szPre); if (GetFullPathName(pszPath, cchFullPath+2, pszFullPath + NUMCHARS(szPre)-1, &pszFilePart) <= cchFullPath+2) pszPath = pszFullPath; } } else pszPath = szFullPath; #endif int err = 0; DWORD fdwFileAttributes = GetFileAttributes(pszPath); if (INVALID_FILE_ATTRIBUTES == fdwFileAttributes) { fdwFileAttributes = 0; err = GetLastError(); ReportError(err, "Could not get attributes for ", pszPath); return err; } const bool fIsDir = (fdwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; if (fdwFlags & TDT_DIAGNOSTIC) bprintfl(bp, TEXT("Delete %s 0x%04X %s\\%s"), fIsDir ? TEXT("Directory") : TEXT("File"), fdwFlags, pszPath, pszPattern); if (fIsDir) { if (fdwTraverse & TDT_SUBDIRS) { if ( ! pszPattern || ! pszPattern[0]) err = TraverseDirectoryTree(pszPath, TEXT("*"), fdwFlags, DeletePathCallback, &lad, 0); else err = TraverseDirectoryTree(pszPath, pszPattern, fdwFlags, DeletePathCallback, &lad, 0); } if ( ! err || (fdwFlags & TDT_CONTINUE)) { bprint_EndLine(bp); if ( ! (fdwTraverse & TDT_NODIRS) && (!pszPattern || !pszPattern[0])) { if ( ! fQuiet) { bprint(bp, lad.fNoDelete ? TEXT("NoRemove ") : TEXT("Removing ")); bprint(bp, pszPath); } if ( ! lad.fNoDelete && ! RemoveDirectory(pszPath)) { bprint_EndLine(bp); err = GetLastError(); ReportError(err, "RemoveDirectory", pszPath); if ( ! (fdwFlags & TDT_CONTINUE)) if ( ! fQuiet) bprintl(bp, "Aborting."); } } } } else // initial path is a file, not a directory. { if (fdwTraverse & TDT_SUBDIRS) { if ( ! pszPattern || ! pszPattern[0]) { err = TraverseDirectoryTree(pszPath, TEXT("*"), fdwFlags, DeletePathCallback, &lad, 0); } else { //#pragma REMIND("TJ: add code to split the file from the path and recurse on the filename.") } } if (fdwTraverse & TDT_NOFILES) { // Nothing to do. } else if ( ! pszPattern || ! pszPattern[0]) { if ( ! fQuiet) { bprint(bp, lad.fNoDelete ? TEXT("NoDelete ") : TEXT("Deleting ")); bprint(bp, pszPath); } if ( ! lad.fNoDelete && ! DeleteFile(pszPath)) { bprint_EndLine(bp); err = GetLastError(); ReportError(err, "DeleteFile", pszPath); if ( ! (fdwFlags & TDT_CONTINUE)) if ( ! fQuiet) bprintl(bp, "Aborting."); } } } bprint_EndLine(bp); return err; }
int atp_recv_atp( ATP ah, struct sockaddr_at *fromaddr, u_int8_t *func, u_int16_t tid, char *rbuf, int wait ) { /* Receive a packet from address fromaddr of the correct function type and with the correct tid. fromaddr = AT_ANY... and function == ATP_TYPEANY and tid == ATP_TIDANY can be used to wildcard match. recv_atp returns the length of the packet received (or -1 if error) The function code for the packet received is returned in *func (ATP_TREQ or ATP_TRESP). */ struct atpbuf *pq, *cq; struct atphdr ahdr; u_int16_t rfunc; u_int16_t rtid; int i; int dlen = -1; int recvlen; struct sockaddr_at faddr; SOCKLEN_T faddrlen; struct atpbuf *inbuf; tid = htons( tid ); /* first check the queue */ #ifdef EBUG atp_print_bufuse( ah, "recv_atp checking queue" ); #endif /* EBUG */ for ( pq = NULL, cq = ah->atph_queue; cq != NULL; pq = cq, cq = cq->atpbuf_next ) { memcpy(&ahdr, cq->atpbuf_info.atpbuf_data + 1, sizeof( struct atphdr )); rfunc = ahdr.atphd_ctrlinfo & ATP_FUNCMASK; #ifdef EBUG printf( "<%d> checking", getpid()); printf( " tid=%hu func=", ntohs( ahdr.atphd_tid )); print_func( rfunc ); atp_print_addr( " from", &cq->atpbuf_addr ); putchar( '\n' ); #endif /* EBUG */ if ((( tid & ahdr.atphd_tid ) == ahdr.atphd_tid ) && (( *func & rfunc ) == rfunc ) && at_addr_eq( fromaddr, &cq->atpbuf_addr )) { break; } } if ( cq != NULL ) { /* we found one in the queue -- copy to rbuf */ dlen = (int) cq->atpbuf_dlen; *func = rfunc; memcpy( fromaddr, &cq->atpbuf_addr, sizeof( struct sockaddr_at )); memcpy( rbuf, cq->atpbuf_info.atpbuf_data, cq->atpbuf_dlen ); /* remove packet from queue and free buffer */ if ( pq == NULL ) { ah->atph_queue = NULL; } else { pq->atpbuf_next = cq->atpbuf_next; } atp_free_buf( cq ); return( dlen ); } /* we need to get it the net -- call on ddp to receive a packet */ #ifdef EBUG printf( "<%d>", getpid()); atp_print_addr( " waiting on address", &ah->atph_saddr ); printf( "\nfor tid=%hu func=", ntohs( tid )); print_func( *func ); atp_print_addr( " from", fromaddr ); putchar( '\n' ); #endif /* EBUG */ do { #ifdef EBUG fflush( stdout ); #endif /* EBUG */ faddrlen = sizeof( struct sockaddr_at ); memset( &faddr, 0, sizeof( struct sockaddr_at )); if (( recvlen = netddp_recvfrom( ah->atph_socket, rbuf, ATP_BUFSIZ, 0, (struct sockaddr *) &faddr, &faddrlen )) < 0 ) { return -1; } memcpy( &ahdr, rbuf + 1, sizeof( struct atphdr )); if ( recvlen >= ATP_HDRSIZE && *rbuf == DDPTYPE_ATP) { /* this is a valid ATP packet -- check for a match */ rfunc = ahdr.atphd_ctrlinfo & ATP_FUNCMASK; rtid = ahdr.atphd_tid; #ifdef EBUG printf( "<%d> got tid=%hu func=", getpid(), ntohs( rtid )); print_func( rfunc ); atp_print_addr( " from", &faddr ); putchar( '\n' ); bprint( rbuf, recvlen ); #endif /* EBUG */ if ( rfunc == ATP_TREL ) { /* remove response from sent list */ for ( pq = NULL, cq = ah->atph_sent; cq != NULL; pq = cq, cq = cq->atpbuf_next ) { if ( at_addr_eq( &faddr, &cq->atpbuf_addr ) && cq->atpbuf_info.atpbuf_xo.atpxo_tid == ntohs( rtid )) break; } if ( cq != NULL ) { #ifdef EBUG printf( "<%d> releasing transaction %hu\n", getpid(), ntohs( rtid )); #endif /* EBUG */ if ( pq == NULL ) { ah->atph_sent = cq->atpbuf_next; } else { pq->atpbuf_next = cq->atpbuf_next; } for ( i = 0; i < 8; ++i ) { if ( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] != NULL ) { atp_free_buf ( cq->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] ); } } atp_free_buf( cq ); } } else if ((( tid & rtid ) == rtid ) && (( *func & rfunc ) == rfunc ) && at_addr_eq( fromaddr, &faddr )) { /* got what we wanted */ *func = rfunc; dlen = recvlen; memcpy( fromaddr, &faddr, sizeof( struct sockaddr_at )); } else { /* add packet to incoming queue */ #ifdef EBUG printf( "<%d> queuing incoming...\n", getpid() ); #endif /* EBUG */ if (( inbuf = atp_alloc_buf()) == NULL ) { return -1; } memcpy( &inbuf->atpbuf_addr, &faddr, sizeof( struct sockaddr_at )); inbuf->atpbuf_next = ah->atph_queue; inbuf->atpbuf_dlen = (size_t) recvlen; memcpy( inbuf->atpbuf_info.atpbuf_data, rbuf, recvlen ); } } if ( !wait && dlen < 0 ) { return( 0 ); } } while ( dlen < 0 ); return( dlen ); }
static void format(char *mnemonic, Instr *i, char *f) { int j, k, m, n; int ins = i->w; if(mnemonic) format(0, i, mnemonic); if(f == 0) return; if(mnemonic) if(i->curr < i->end) *i->curr++ = '\t'; for ( ; *f && i->curr < i->end; f++) { if(*f != '%') { *i->curr++ = *f; continue; } switch (*++f) { case 'c': /* Bcc */ bprint(i, "%s", cond[B(11, 8)]); break; case 's': bprint(i, "%d", i->rs); break; case 'n': bprint(i, "%d", i->rn); break; case 'd': bprint(i, "%d", i->rd); break; case 'i': bprint(i, "%lux", i->imm); break; case 'b': bprint(i, "%lux", i->imm); break; case 'r': n = i->imm&0xff; j = 0; k = 0; while(n) { m = j; while(n&0x1) { j++; n >>= 1; } if(j != m) { if(k) bprint(i, ","); if(j == m+1) bprint(i, "R%d", m); else bprint(i, "R%d-R%d", m, j-1); k = 1; } j++; n >>= 1; } break; case '\0': *i->curr++ = '%'; return; default: bprint(i, "%%%c", *f); break; } } *i->curr = 0; }
void cTestNagra::Process(int id, unsigned char *emmdata) { cEmu *emu=0; cBN n1, e1; unsigned int i=0; bool gotKeys=false; unsigned char key0[8], key1[8]; int keyId=(emmdata[i+1]<<8)+emmdata[i+2]; switch(emmdata[i]) { // Check filter type case 0x00: // One card i+=7; break; case 0x01 ... 0x20: // Group of cards i+=emmdata[i]+0x7; break; case 0x3e: i+=6; break; case 0x3d: // All cards with same system ID case 0x3f: i+=3; break; } int nrKeys=0; while(i<sizeof(emmdata)) { if((emmdata[i]&0xF0)==0xF0) { // Update with CPU code const int romNr=emmdata[i]&0x0F; if(!emu || !emu->Matches(romNr,id)) { delete emu; emu=0; printf("Testing with ROM %d, 0xID %04x\n",romNr,id); switch(romNr) { case 3: emu=new cEmuRom3; break; case 7: emu=new cEmuRom7; break; case 10: emu=new cEmuRom10; break; case 11: emu=new cEmuRom11; break; default: printf("unsupported ROM"); return; } if(!emu || !emu->Init(romNr,id)) { delete emu; emu=0; printf("initialization failed for ROM %d\n",romNr); return; } } unsigned char ki[2]; if((gotKeys=emu->GetOpKeys(emmdata,ki,key0,key1))) { printf("keyid: "); SDump(ki,2); printf("key0: "); SDump(key0,8); printf("key1: "); SDump(key1,8); keyId=(ki[0]<<8)+ki[1]; printf("got keys for %04X (ROM %d)\n",keyId,romNr); } unsigned char select[3], pkset[3][15]; select[0]=(keyId>>8)|0x01; // always high id for ECM RSA keys select[1]=keyId&0xFF; select[2]=0; // type 0 HexDump(select,3); if(emu->GetPkKeys(&select[0],&pkset[0][0])) { int pkKeyId=((select[0]<<8)+select[1]); printf("got PK keys for %04X (ROM %d)\n",pkKeyId,romNr); HexDump(pkset[0],sizeof(pkset[0])); HexDump(pkset[1],sizeof(pkset[1])); HexDump(pkset[2],sizeof(pkset[2])); for(int i=0; i<3; i++) { CreateRSAPair(pkset[i],0,e1,n1); printf("keyE1 set=%d ",i); bprint(e1); printf("keyN1 set=%d ",i); bprint(n1); } } break; // don't process other nanos } else if(emmdata[i]==0x60) { // NULL nano i+=2; } else if(emmdata[i]==0x00) { i++; } else if(emmdata[i]==0x81) { i++; } else if(emmdata[i]==0x83) { keyId=(emmdata[i+1]<<8)+emmdata[i+2]; i+=3; } else if(emmdata[i]==0x42) { // plain Key if(emmdata[i+1]==0x05) memcpy(key0,&emmdata[i+2],sizeof(key0)); else memcpy(key1,&emmdata[i+2],sizeof(key1)); i+=10; if(++nrKeys==2) { gotKeys=true; printf("got keys for %04X (plain)\n",keyId); break; } } else { printf("ignored nano %02x\n",emmdata[i]); break; } }
int RemoveFileDACLs(LPCWSTR pszPath, BOOL fDiagnostic, BPRINT_BUFFER *pbp) { // // make sure that we have ESE_SECURITY priviledge // int err = 0; if ( ! AddLocalPrivilege(ESE_SECURITY)) { err = GetLastError(); if (fDiagnostic) ReportError(err, "AdjustTokenPrivileges"); } // setup globals, this do nothing if this is not the first time // this function was called. // InitStandardSids(fDiagnostic, pbp); //InitUserSid(fDiagnostic, pbp); InitOwnerSid(fDiagnostic, pbp); // // Attempt to put a NULL Dacl on the file/directory // SECURITY_DESCRIPTOR si; ZeroMemory(&si, sizeof(si)); InitializeSecurityDescriptor(&si, SECURITY_DESCRIPTOR_REVISION); MSC_SUPPRESS_WARNING(6248) // warning: setting the DACL to null will result in unprotected object... SetSecurityDescriptorDacl (&si, TRUE, NULL, FALSE); if ( ! SetFileSecurityW(pszPath, DACL_SECURITY_INFORMATION, &si)) { err = GetLastError(); if (fDiagnostic) ReportErrorW (err, "SetFileSecurity(DACL)[1] ", pszPath); } else { if (fDiagnostic) { if (bprint_IsEmpty(*pbp)) bprintfl(*pbp, "DACLs removed from %s", pszPath); else bprint(*pbp, " DACLs removed"); } return 0; } // // Attempt to make take ownership of the file. // SetSecurityDescriptorOwner (&si, ls.OwnerSid, FALSE); if (SetFileSecurityW(pszPath, OWNER_SECURITY_INFORMATION, &si)) err = 0; else { err = GetLastError(); if (fDiagnostic) ReportErrorW (err, "SetFileSecurity(Owner)[1] ", pszPath); //ZeroMemory(&si,sizeof(si)); //InitializeSecurityDescriptor(&si, SECURITY_DESCRIPTOR_REVISION); //SetSecurityDescriptorOwner (&si, ls.OwnerSid, FALSE); if ( ! AddLocalPrivilege(ESE_TAKE_OWNERSHIP)) { static bool fReportedSeTakeOwner = false; if (fDiagnostic && ! fReportedSeTakeOwner) { ReportErrorW(GetLastError(), "SeTakeOwnership ", pszPath); fReportedSeTakeOwner = true; } } else if ( ! SetFileSecurityW(pszPath, OWNER_SECURITY_INFORMATION, &si)) { err = GetLastError(); if (fDiagnostic) ReportErrorW (err, "SetFileSecurity(Owner)[2] ", pszPath); } else { err = 0; } } // if we successfully took ownership, try again to set a NULL DACL // if ( ! err) { if (fDiagnostic) { if (bprint_IsEmpty(*pbp)) bprintfl(*pbp, "Ownership taken of %s", pszPath); else bprint(*pbp, " Ownership taken"); } if ( ! SetFileSecurityW(pszPath, DACL_SECURITY_INFORMATION, &si)) { err = GetLastError(); if (fDiagnostic) ReportErrorW (err, "SetFileSecurity(DACL)[2] ", pszPath); } else { if (fDiagnostic) { if (bprint_IsEmpty(*pbp)) bprintfl(*pbp, "DACLs removed from %s", pszPath); else bprintfl(*pbp, " DACLs removed", pszPath); } return 0; } } return err; }
static void __cdecl bprintl(BPRINT_BUFFER & bp, LPCTSTR psz) { bprint(bp, psz); bprint_EndLine(bp); }
/* * ah: open atp handle * atpb: parameter block * respcount: buffers available for response * flags: ATP_XO, ATP_TREL */ int atp_sreq( ATP ah, struct atp_block *atpb, int respcount, u_int8_t flags ) { struct atpbuf *req_buf; int i; #ifdef EBUG atp_print_bufuse( ah, "atp_sreq" ); #endif /* EBUG */ /* check parameters */ if ( atpb->atp_sreqdlen < 4 || atpb->atp_sreqdlen > ATP_MAXDATA || ( respcount < 0 ) || ( respcount > 8 ) || ( atpb->atp_sreqto < 0 ) || (( atpb->atp_sreqtries < 1 ) && ( atpb->atp_sreqtries != ATP_TRIES_INFINITE ))) { errno = EINVAL; return -1; } /* clean up any packet fragments left from last request */ for ( i = 0; i < 8; ++i ) { if ( ah->atph_resppkt[ i ] != NULL ) { atp_free_buf( ah->atph_resppkt[ i ] ); ah->atph_resppkt[ i ] = NULL; } } /* generate bitmap, tid and ctrlinfo */ atpb->atp_bitmap = ( 1 << respcount ) - 1; /* allocate a new buffer and build request packet */ if (( req_buf = atp_alloc_buf()) == NULL ) { return( -1 ); } atp_build_req_packet( req_buf, ah->atph_tid++, flags | ATP_TREQ, atpb ); memcpy( &req_buf->atpbuf_addr, atpb->atp_saddr, sizeof( struct sockaddr_at )); /* send the initial request */ #ifdef EBUG printf( "\n<%d> atp_sreq: sending a %ld byte packet ", getpid(), req_buf->atpbuf_dlen ); atp_print_addr( " to", atpb->atp_saddr ); putchar( '\n' ); bprint( req_buf->atpbuf_info.atpbuf_data, req_buf->atpbuf_dlen ); #endif /* EBUG */ gettimeofday( &ah->atph_reqtv, (struct timezone *)0 ); #ifdef DROPPACKETS if (( random() % 3 ) != 2 ) { #endif /* DROPPACKETS */ if ( netddp_sendto( ah->atph_socket, req_buf->atpbuf_info.atpbuf_data, req_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr, sizeof( struct sockaddr_at )) != req_buf->atpbuf_dlen ) { atp_free_buf( req_buf ); return( -1 ); } #ifdef DROPPACKETS } else printf( "<%d> atp_sreq: dropped request\n", getpid() ); #endif /* DROPPACKETS */ if ( atpb->atp_sreqto != 0 ) { if ( ah->atph_reqpkt != NULL ) { atp_free_buf( ah->atph_reqpkt ); } ah->atph_reqto = atpb->atp_sreqto; if ( atpb->atp_sreqtries == ATP_TRIES_INFINITE ) { ah->atph_reqtries = ATP_TRIES_INFINITE; } else { /* we already sent one */ ah->atph_reqtries = atpb->atp_sreqtries - 1; } ah->atph_reqpkt = req_buf; ah->atph_rbitmap = ( 1 << respcount ) - 1; ah->atph_rrespcount = respcount; } else { atp_free_buf( req_buf ); ah->atph_rrespcount = 0; } return( 0 ); }
int main() { FILE *fp; int m,a,b,c; big e,a2,a6,x,y,r,t; epoint *g; ebrick2 binst; char fname[100]; BOOL last; int i,j,len,bptr,nb,window,wsize,words,winsize; miracl *mip=mirsys(50,0); e=mirvar(0); a2=mirvar(0); a6=mirvar(0); x=mirvar(0); y=mirvar(0); r=mirvar(0); t=mirvar(0); printf("Enter name of .ecs file= "); gets(fname); strip(fname); strcat(fname,".ecs"); if ((fp=fopen(fname,"rt"))==NULL) { printf("Unable to open file %s\n",fname); return 0; } fscanf(fp,"%d\n",&m); mip->IOBASE=16; cinnum(a2,fp); cinnum(a6,fp); cinnum(r,fp); cinnum(x,fp); cinnum(y,fp); mip->IOBASE=10; fscanf(fp,"%d\n",&a); fscanf(fp,"%d\n",&b); fscanf(fp,"%d\n",&c); printf("modulus is %d bits in length\n",m); nb=m; printf("Enter window size in bits (1-10)= "); scanf("%d",&window); getchar(); printf("Enter word size of application processor (8, 16, 32 or 64 bit)= "); scanf("%d",&wsize); getchar(); if (wsize!=8 && wsize!=16 && wsize!=32 && wsize!=64 || wsize>MIRACL) { printf("Error - Unsupported word size\n"); exit(0); } if (!ebrick2_init(&binst,x,y,a2,a6,m,a,b,c,window,nb)) { printf("Failed to Initialize\n"); return 0; } len=MR_ROUNDUP(m,MIRACL); words=MR_ROUNDUP(m,wsize); printf("\n--------------------CUT HERE----------------------\n\n"); printf("#define CURVE_M %d\n",m); printf("#define CURVE_A %d\n",a); printf("#define CURVE_B %d\n",b); printf("#define CURVE_C %d\n",c); printf("#define WINDOW %d\n",window); printf("#define WORDS %d\n",words); printf("\nstatic const mr_small rom[]={\n"); bprint(a6->w,len,words,wsize,FALSE); bprint(r->w,len,words,wsize,FALSE); bprint(x->w,len,words,wsize,FALSE); bprint(y->w,len,words,wsize,TRUE); printf("\nstatic const mr_small prom[]={\n"); bptr=0; last=FALSE; winsize=2*(1<<window); for (i=0;i<winsize;i++) { zero(t); t->len=len; for (j=0;j<len;j++) t->w[j]=binst.table[bptr++]; if (i==winsize-1) last=TRUE; bprint(t->w,len,words,wsize,last); } ebrick2_end(&binst); return 0; }