void WriteFullProcMLP::Loop() { std::cout << "Loop varSet = " << varSet << std::endl; addVariables(); FillMLP(varSet); WriteHeader(); WriteInput(); WriteCategory(); WriteCount("var1", "input", "trackSip2dSig"); //********Chunk for Combined BvsDUSG and BvsC starts*********** WriteNormalize(); WriteSplitters(); if (writeSplittersForNonMultiple) WriteSplittersForNonMultiple(); WriteLRx(); WriteLRall(); WriteLRsplit(); WriteOptional(); if (writeMatrices) {WriteMatrices(); WriteOutput("input", "jetPt"); return;} WriteProcMLP(mlp); WriteBiasNorm(procBiasNorm+tagVtx, "var1", procMLP+tagVtx, "var1"); WriteLRBias(procLike+tagVtx, "var1", procBiasNorm+tagVtx, "var1"); //********Chunk for Combined BvsDUSG and BvsC starts*********** if (Flavour != "Combined") { WriteOutput(procLike+tagVtx, "var1"); return; } tagVtx = "C"; //Need to reset Vector for ProcOptional Oprocess.clear(); Oid.clear(); //Need to reset mlp with the corresponding variables with C instead of "DUSG" tag FillMLP(varSet); //For combined xml, copy previuos structure from WriteNormalize to WriteLRBias // then add ProcLinear and output //**************Insert here Chunk for Combined: begin************** WriteNormalize(); WriteSplitters(); if (writeSplittersForNonMultiple) WriteSplittersForNonMultiple(); WriteLRx(); WriteLRall(); WriteLRsplit(); WriteOptional(); if (writeMatrices) {WriteMatrices(); WriteOutput("input", "jetPt"); return;} WriteProcMLP(mlp); WriteBiasNorm(procBiasNorm+tagVtx, "var1", procMLP+tagVtx, "var1"); WriteLRBias(procLike+tagVtx, "var1", procBiasNorm+tagVtx, "var1"); //**************Insert here Chunk for Combined: end**************** WriteLinear(); WriteOutput(procLinear, "var1"); }
USHORT WriteBuffer( void *src, USHORT segv, ULONG offv, USHORT size ) { USHORT length; bool iugs; USHORT resdata; ULONG flat; BYTE *data = src; if( segv < 4 ) { return( 0 ); } length = size; if( Pid != 0 ) { iugs = IsUnknownGDTSeg( segv ); if( !iugs ) { flat = MakeItFlatNumberOne( segv, offv ); WriteLinear( data, flat, size ); if( Buff.Cmd == DBG_N_Success ) { return( size ); } } while( length != 0 ) { Buff.Cmd = DBG_C_WriteMem_D; if( length == 1 ) { /* Don't want to write anything in the kernel area - that means no breakpoints! */ if( iugs /*|| offv > KERNEL_MEM_OFFSET*/ ) { if( !TaskReadWord( segv, offv, &resdata ) ) { break; } resdata &= 0xff00; resdata |= *data; if( !TaskWriteWord( segv, offv, resdata ) ) { break; } } else { Buff.Cmd = DBG_C_ReadMem_D; Buff.Addr = MakeItFlatNumberOne( segv, offv ); CallDosDebug( &Buff ); Buff.Cmd = DBG_C_WriteMem_D; Buff.Addr = MakeItFlatNumberOne( segv, offv ); Buff.Value &= 0xff00; Buff.Value |= *data; CallDosDebug( &Buff ); if( Buff.Cmd != DBG_N_Success ) { break; } } data++; length--; offv++; } else { resdata = *data; data++; resdata |= *data << 8; data++; if( iugs ) { if( !TaskWriteWord( segv, offv, resdata ) ) { break; } } else { Buff.Value = resdata; Buff.Addr = MakeItFlatNumberOne( segv, offv ); CallDosDebug( &Buff ); if( Buff.Cmd != DBG_N_Success ) { break; } } length -= 2; offv += 2; } } } return( size - length ); /* return amount written */ }
bool DebugExecute( uDB_t *buff, ULONG cmd, bool stop_on_module_load ) { EXCEPTIONREPORTRECORD ex; ULONG value; ULONG stopvalue; ULONG notify = 0; BOOL got_second_notification; ULONG fcp; CONTEXTRECORD fcr; buff->Cmd = cmd; value = buff->Value; if( cmd == DBG_C_Go ) { value = 0; } stopvalue = XCPT_CONTINUE_EXECUTION; got_second_notification = FALSE; if( cmd == DBG_C_Stop ) { stopvalue = XCPT_CONTINUE_STOP; } for( ;; ) { buff->Value = value; buff->Cmd = cmd; CallDosDebug( buff ); value = stopvalue; cmd = DBG_C_Continue; /* * handle the preemptive notifications */ switch( buff->Cmd ) { case DBG_N_ModuleLoad: RecordModHandle( buff->Value ); if( stop_on_module_load ) return( TRUE ); break; case DBG_N_ModuleFree: break; case DBG_N_NewProc: break; case DBG_N_ProcTerm: value = XCPT_CONTINUE_STOP; /* halt us */ notify = DBG_N_ProcTerm; break; case DBG_N_ThreadCreate: break; case DBG_N_ThreadTerm: break; case DBG_N_AliasFree: break; case DBG_N_Exception: ExceptLinear = buff->Addr; if( buff->Value == DBG_X_STACK_INVALID ) { value = XCPT_CONTINUE_SEARCH; break; } fcp = buff->Len; if( buff->Value == DBG_X_PRE_FIRST_CHANCE ) { ExceptNum = buff->Buffer; if( ExceptNum == XCPT_BREAKPOINT ) { notify = DBG_N_Breakpoint; value = XCPT_CONTINUE_STOP; break; } else if( ExceptNum == XCPT_SINGLE_STEP ) { notify = DBG_N_SStep; value = XCPT_CONTINUE_STOP; break; } } // // NOTE: Going to second chance causes OS/2 to report the // exception in the debugee. However, if you report // the fault at the first chance notification, the // debugee's own fault handlers will not get invoked! // if( buff->Value == DBG_X_FIRST_CHANCE && !ExpectingAFault ) { if( stopOnSecond && !got_second_notification ) { value = XCPT_CONTINUE_SEARCH; break; } } notify = DBG_N_Exception; value = XCPT_CONTINUE_STOP; /* * Buffer contains the ptr to the exception block */ buff->Cmd = DBG_C_ReadMemBuf; buff->Addr = buff->Buffer; buff->Buffer = (ULONG)&ex; buff->Len = sizeof( ex ); CallDosDebug( buff ); ExceptNum = ex.ExceptionNum; if( ExceptNum == XCPT_PROCESS_TERMINATE || ExceptNum == XCPT_ASYNC_PROCESS_TERMINATE || ExceptNum == XCPT_GUARD_PAGE_VIOLATION || ( ExceptNum & XCPT_CUSTOMER_CODE ) ) { value = XCPT_CONTINUE_SEARCH; break; } /* * get the context record */ buff->Cmd = DBG_C_ReadMemBuf; buff->Addr = fcp; buff->Buffer = (ULONG)&fcr; buff->Len = sizeof( fcr ); CallDosDebug( buff ); buff->EAX = fcr.ctx_RegEax; buff->EBX = fcr.ctx_RegEbx; buff->ECX = fcr.ctx_RegEcx; buff->EDX = fcr.ctx_RegEdx; buff->ESI = fcr.ctx_RegEsi; buff->EDI = fcr.ctx_RegEdi; buff->ESP = fcr.ctx_RegEsp; buff->EBP = fcr.ctx_RegEbp; buff->DS = fcr.ctx_SegDs; buff->CS = fcr.ctx_SegCs; buff->ES = fcr.ctx_SegEs; buff->FS = fcr.ctx_SegFs; buff->GS = fcr.ctx_SegGs; buff->SS = fcr.ctx_SegSs; buff->EIP = fcr.ctx_RegEip; buff->EFlags = fcr.ctx_EFlags; WriteRegs(buff); if( ExpectingAFault || got_second_notification ) { break; } if( stopOnSecond ) { value = XCPT_CONTINUE_EXECUTION; got_second_notification = TRUE; } break; default: if( notify != 0 ) { buff->Cmd = notify; // Check if we hit our splice DLL breakpoint if( (notify == DBG_N_Breakpoint) && splice_bp_set && (splice_bp_lin_addr == ExceptLinear) ) { uDB_t save; // Remove breakpoint WriteLinear( &saved_splice_bp, splice_bp_lin_addr, sizeof( byte ) ); splice_bp_set = FALSE; splice_bp_lin_addr = 0; // Attempt to load helper DLL save.Pid = Pid; save.Tid = 1; ReadRegs( &save ); ExpectingAFault = TRUE; // NB - the following will recursively call DebugExecute! if( !CausePgmToLoadHelperDLL( ExceptLinear ) ) { CanExecTask = FALSE; } else { CanExecTask = TRUE; } WriteRegs( &save ); break; } } return( FALSE ); } } // return( FALSE ); }
bool CausePgmToLoadThisDLL( ULONG startLinear ) { char savecode[LOAD_THIS_DLL_SIZE]; USHORT codesize; USHORT len; loadstack_t far *loadstack; void far *ptr; USHORT dll_name_len; USHORT size; char this_dll[BUFF_SIZE]; bool rc; /* * save a chunk of the program's code, and put in LoadThisDLL instead */ if( DosGetModName( ThisDLLModHandle, BUFF_SIZE, this_dll ) != 0 ) { return( FALSE ); } codesize = (char *)EndLoadThisDLL - (char *)LoadThisDLL; if( codesize > LOAD_THIS_DLL_SIZE ) return( FALSE ); ReadLinear( savecode, startLinear, codesize ); if( Buff.Cmd != DBG_N_Success ) return( FALSE ); WriteLinear( (byte far *)LoadThisDLL, startLinear, codesize ); /* * set up the stack for the routine LoadThisDLL */ dll_name_len = ( strlen( this_dll ) + 1 ) & ~1; size = sizeof( loadstack_t ) + dll_name_len; loadstack = Automagic( size ); Buff.ESP -= size; strcpy( loadstack->load_name, this_dll ); loadstack->fail_name = NULL; loadstack->fail_len = 0; ptr = MakeItSegmentedNumberOne( Buff.SS, Buff.ESP + offsetof( loadstack_t, load_name ) ); loadstack->mod_name[0] = FP_OFF( ptr ); loadstack->mod_name[1] = FP_SEG( ptr ); ptr = MakeItSegmentedNumberOne( Buff.SS, Buff.ESP + offsetof( loadstack_t, hmod ) ); loadstack->phmod[0] = FP_OFF( ptr ); loadstack->phmod[1] = FP_SEG( ptr ); len = WriteBuffer( (byte far *)loadstack, Buff.SS, Buff.ESP, size ); if( len != size ) return( FALSE ); /* * set up 16:16 CS:IP, SS:SP for execution */ ptr = MakeSegmentedPointer( startLinear ); Buff.CS = FP_SEG( ptr ); Buff.EIP = FP_OFF( ptr ); ptr = MakeItSegmentedNumberOne( Buff.SS, Buff.ESP ); Buff.SS = FP_SEG( ptr ); Buff.ESP = FP_OFF( ptr ); /* * execute LoadThisDLL on behalf of the program */ WriteRegs( &Buff ); DebugExecute( &Buff, DBG_C_Go, FALSE ); if( Buff.Cmd != DBG_N_Breakpoint ) { rc = FALSE; } else { rc = TRUE; } WriteLinear( savecode, startLinear, codesize ); return( rc ); }
USHORT WriteBuffer( byte __far *data, USHORT segv, ULONG offv, USHORT size ) { USHORT length; bool iugs; USHORT resdata; ULONG flat; if( segv < 4 ) { return( 0 ); } length = size; if( Pid != 0 ) { iugs = IsUnknownGDTSeg( segv ); if( !iugs ) { flat = MakeItFlatNumberOne( segv, offv ); WriteLinear( data, flat, size ); if( Buff.Cmd == DBG_N_Success ) { return( size ); } } while( length != 0 ) { Buff.Cmd = DBG_C_WriteMem_D; if( length == 1 ) { if( iugs ) { if( !TaskReadWord( segv, offv, &resdata ) ) { break; } resdata &= 0xff00; resdata |= *data; if( !TaskWriteWord( segv, offv, resdata ) ) { break; } } else { Buff.Cmd = DBG_C_ReadMem_D; Buff.Addr = MakeItFlatNumberOne( segv, offv ); CallDosDebug( &Buff ); Buff.Cmd = DBG_C_WriteMem_D; Buff.Addr = MakeItFlatNumberOne( segv, offv ); Buff.Value &= 0xff00; Buff.Value |= *data; CallDosDebug( &Buff ); if( Buff.Cmd != DBG_N_Success ) { break; } } data++; length--; offv++; } else { resdata = *data; data++; resdata |= *data << 8; data++; if( iugs ) { if( !TaskWriteWord( segv, offv, resdata ) ) { break; } } else { Buff.Value = resdata; Buff.Addr = MakeItFlatNumberOne( segv, offv ); CallDosDebug( &Buff ); if( Buff.Cmd != DBG_N_Success ) { break; } } length -= 2; offv += 2; } } } return( size - length ); /* return amount written */ }