/** * This is the agent procedure. It is complete and you shouldn't change it in * any material way. You can re-write it if you like, but be sure that all it does * is choose 2 random reasources, signal their condition variables, and then wait * wait for a smoker to smoke. */ void* agent (void* av) { struct Agent* a = av; static const int choices[] = {MATCH|PAPER, MATCH|TOBACCO, PAPER|TOBACCO}; static const int matching_smoker[] = {TOBACCO, PAPER, MATCH}; uthread_mutex_lock (a->mutex); for (int i = 0; i < NUM_ITERATIONS; i++) { int r = random() % 3; signal_count [matching_smoker [r]] ++; int c = choices [r]; if (c & MATCH) { VERBOSE_PRINT ("match available\n"); uthread_cond_signal (a->match); } if (c & PAPER) { VERBOSE_PRINT ("paper available\n"); uthread_cond_signal (a->paper); } if (c & TOBACCO) { VERBOSE_PRINT ("tobacco available\n"); uthread_cond_signal (a->tobacco); } VERBOSE_PRINT ("agent is waiting for smoker to smoke\n"); uthread_cond_wait (a->smoke); } uthread_mutex_unlock (a->mutex); return NULL; }
static bool files_merge(){ rewind(cinTableFile); rewind(cinGouCiFile); char buf[FILE_READ_BUFFER_SIZE]; VERBOSE_PRINT("Merging files.\n"); while(fgets(buf,FILE_READ_BUFFER_SIZE, tmplFile)!=NULL){ bool printAsIs=true; if (strncasecmp(buf,"END_TABLE",strlen("END_TABLE"))==0){ file_cat(outFile,cinTableFile); }else if (strncasecmp(buf,"END_GOUCI",strlen("END_GOUCI"))==0){ file_cat(outFile,cinGouCiFile); }else if (strncmp(buf,"VALID_INPUT_CHARS",strlen("VALID_INPUT_CHARS"))==0){ fprintf(outFile,"VALID_INPUT_CHARS = %s\n",validInputChars); printAsIs=false; }else if (strncmp(buf,"MAX_KEY_LENGTH",strlen("MAX_KEY_LENGTH"))==0){ fprintf(outFile,"MAX_KEY_LENGTH = %d\n",maxKeyLength); printAsIs=false; } if (printAsIs){ fputs(buf,outFile); } } fclose(cinTableFile); fclose(cinGouCiFile); return true; }
static UINT32 AsCountLines ( char *Buffer, char *Filename) { char *SubBuffer = Buffer; char *EndOfLine; UINT32 LineCount = 0; UINT32 LongLineCount = 0; while (*SubBuffer) { EndOfLine = AsSkipUntilChar (SubBuffer, '\n'); if (!EndOfLine) { Gbl_TotalLines += LineCount; return (LineCount); } if ((EndOfLine - SubBuffer) > 80) { LongLineCount++; VERBOSE_PRINT (("long: %.80s\n", SubBuffer)); } LineCount++; SubBuffer = EndOfLine + 1; } if (LongLineCount) { VERBOSE_PRINT (("%u Lines longer than 80 found in %s\n", LongLineCount, Filename)); Gbl_LongLines += LongLineCount; } Gbl_TotalLines += LineCount; return (LineCount); }
static void emulator_window_light_brightness(void* opaque, const char* light, int value) { EmulatorWindow* emulator = opaque; VERBOSE_PRINT(hw_control,"%s: light='%s' value=%d ui=%p", __FUNCTION__, light, value, emulator->ui); if (!strcmp(light, "lcd_backlight")) { skin_ui_set_lcd_brightness(emulator->ui, value); return; } }
int buffer_test(char *location) { char stack_buffer[4096]; char *ptr = NULL; func_TYPE func; if (strcmp(location, "stack") == 0) { ptr = stack_buffer; } if (strcmp(location, "heap") == 0) { ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 4000); } if (strcmp(location, "newheap") == 0) { ptr = HeapAlloc(HeapCreate(0, 8000, 16000), HEAP_ZERO_MEMORY, 4000); } if (strcmp(location, "virtual") == 0) { ptr = VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); } if (strcmp(location, "virtual_x") == 0) { ptr = VirtualAlloc(NULL, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); } if (strcmp(location, "crtheap") == 0) { ptr = malloc(4096); } if (strcmp(location, ".data") == 0) { ptr = data_section; } if (ptr == NULL) { usage("use"); return (-1); } memset(ptr, OPC_NOP, NUM_NOPS); memcpy(ptr + NUM_NOPS, shellcode, sizeof(shellcode)); func = (func_TYPE)ptr; VERBOSE_PRINT("ptr: %#x\n", ptr); print("Executing %s shellcode...\n", location); (*func)(); print("success!\n"); return (0); }
static void qemulator_light_brightness( void* opaque, const char* light, int value ) { QEmulator* emulator = opaque; VERBOSE_PRINT(hw_control,"%s: light='%s' value=%d window=%p", __FUNCTION__, light, value, emulator->window); if ( !strcmp(light, "lcd_backlight") ) { emulator->lcd_brightness = value; if (emulator->window) skin_window_set_lcd_brightness( emulator->window, value ); return; } }
//====================================================================== // radio and check both shouldn't change state when they lose interaction. //====================================================================== void NvUIButton::LostInteract() { if (m_wasHit) { VERBOSE_PRINT("[!] wasHit losing focus...\n"); m_wasHit = false; } if (m_type!=NvUIButtonType::CHECK && m_type!=NvUIButtonType::RADIO) { SetDrawState(GetPrevDrawState()); SetPrevDrawState(0); } INHERITED::LostInteract(); }
//====================================================================== //====================================================================== NvUIEventResponse NvUIButton::HandleFocusEvent(NvFocusEvent::Enum evt) { NvUIEventResponse r = nvuiEventNotHandled; if (!GetVisibility()) return r; // we only handle PRESS focus actions for right now. if (evt!=NvFocusEvent::ACT_PRESS) return r; uint32_t st = GetDrawState(); // we don't handle actions if we're inactive. if (st == NvUIButtonState::INACTIVE) return r; if (m_type==NvUIButtonType::CHECK) { // then toggle. if (st == NvUIButtonState::ACTIVE) st = NvUIButtonState::SELECTED; else st = NvUIButtonState::ACTIVE; SetDrawState(st); } else if (m_type==NvUIButtonType::RADIO) { // then select THIS radio st = NvUIButtonState::SELECTED; SetDrawState(st); } else // push button { // fake that we're pushed in... st = NvUIButtonState::ACTIVE; // but don't set drawstate! } NvUIReaction &react = GetReactionEdit(); react.uid = m_uiuid; react.code = m_action; react.state = st; // in case someone is looking for a value for this reaction. if (m_type==NvUIButtonType::RADIO) react.ival = m_subcode; else react.ival = react.state; // pass draw state as value. react.flags = NvReactFlag::NONE; r = nvuiEventHandledInteractReaction; VERBOSE_PRINT("}}}}}} prepped reaction\n"); return r; }
void nand_add_dev(const char *arg) { uint64_t dev_size = 0; const char *next_arg; const char *value; size_t arg_len, value_len; nand_dev *new_devs, *dev; char *devname = NULL; size_t devname_len = 0; char *initfilename = NULL; char *rwfilename = NULL; int initfd = -1; int rwfd = -1; int read_only = 0; int pad; ssize_t read_size; uint32_t page_size = 2048; uint32_t extra_size = 64; uint32_t erase_pages = 64; VERBOSE_PRINT(init, "%s: %s", __FUNCTION__, arg); while(arg) { next_arg = strchr(arg, ','); value = strchr(arg, '='); if(next_arg != NULL) { arg_len = next_arg - arg; next_arg++; if(value >= next_arg) value = NULL; } else arg_len = strlen(arg); if(value != NULL) { size_t new_arg_len = value - arg; value_len = arg_len - new_arg_len - 1; arg_len = new_arg_len; value++; } else value_len = 0; if(devname == NULL) { if(value != NULL) goto bad_arg_and_value; devname_len = arg_len; devname = malloc(arg_len+1); if(devname == NULL) goto out_of_memory; memcpy(devname, arg, arg_len); devname[arg_len] = 0; } else if(value == NULL) { if(arg_match("readonly", arg, arg_len)) { read_only = 1; } else { XLOG("bad arg: %.*s\n", arg_len, arg); exit(1); } } else { if(arg_match("size", arg, arg_len)) { char *ep; dev_size = strtoull(value, &ep, 0); if(ep != value + value_len) goto bad_arg_and_value; } else if(arg_match("pagesize", arg, arg_len)) { char *ep; page_size = strtoul(value, &ep, 0); if(ep != value + value_len) goto bad_arg_and_value; } else if(arg_match("extrasize", arg, arg_len)) { char *ep; extra_size = strtoul(value, &ep, 0); if(ep != value + value_len) goto bad_arg_and_value; } else if(arg_match("erasepages", arg, arg_len)) { char *ep; erase_pages = strtoul(value, &ep, 0); if(ep != value + value_len) goto bad_arg_and_value; } else if(arg_match("initfile", arg, arg_len)) { initfilename = malloc(value_len + 1); if(initfilename == NULL) goto out_of_memory; memcpy(initfilename, value, value_len); initfilename[value_len] = '\0'; } else if(arg_match("file", arg, arg_len)) { rwfilename = malloc(value_len + 1); if(rwfilename == NULL) goto out_of_memory; memcpy(rwfilename, value, value_len); rwfilename[value_len] = '\0'; } else { goto bad_arg_and_value; } } arg = next_arg; } if (rwfilename == NULL) { /* we create a temporary file to store everything */ TempFile* tmp = tempfile_create(); if (tmp == NULL) { XLOG("could not create temp file for %.*s NAND disk image: %s\n", devname_len, devname, strerror(errno)); exit(1); } rwfilename = (char*) tempfile_path(tmp); if (VERBOSE_CHECK(init)) dprint( "mapping '%.*s' NAND image to %s", devname_len, devname, rwfilename); } if(rwfilename) { if (initfilename) { /* Overwrite with content of the 'initfilename'. */ if (read_only) { /* Cannot be readonly when initializing the device from another file. */ XLOG("incompatible read only option is requested while initializing %.*s from %s\n", devname_len, devname, initfilename); exit(1); } rwfd = open(rwfilename, O_BINARY | O_TRUNC | O_RDWR); } else { rwfd = open(rwfilename, O_BINARY | (read_only ? O_RDONLY : O_RDWR)); } if(rwfd < 0) { XLOG("could not open file %s, %s\n", rwfilename, strerror(errno)); exit(1); } /* this could be a writable temporary file. use atexit_close_fd to ensure * that it is properly cleaned up at exit on Win32 */ if (!read_only) atexit_close_fd(rwfd); } if(initfilename) { initfd = open(initfilename, O_BINARY | O_RDONLY); if(initfd < 0) { XLOG("could not open file %s, %s\n", initfilename, strerror(errno)); exit(1); } if(dev_size == 0) { dev_size = do_lseek(initfd, 0, SEEK_END); do_lseek(initfd, 0, SEEK_SET); } } new_devs = realloc(nand_devs, sizeof(nand_devs[0]) * (nand_dev_count + 1)); if(new_devs == NULL) goto out_of_memory; nand_devs = new_devs; dev = &new_devs[nand_dev_count]; dev->page_size = page_size; dev->extra_size = extra_size; dev->erase_size = erase_pages * (page_size + extra_size); pad = dev_size % dev->erase_size; if (pad != 0) { dev_size += (dev->erase_size - pad); D("rounding devsize up to a full eraseunit, now %llx\n", dev_size); } dev->devname = devname; dev->devname_len = devname_len; dev->max_size = dev_size; dev->data = malloc(dev->erase_size); if(dev->data == NULL) goto out_of_memory; dev->flags = read_only ? NAND_DEV_FLAG_READ_ONLY : 0; #ifdef TARGET_I386 dev->flags |= NAND_DEV_FLAG_BATCH_CAP; #endif if (initfd >= 0) { do { read_size = do_read(initfd, dev->data, dev->erase_size); if(read_size < 0) { XLOG("could not read file %s, %s\n", initfilename, strerror(errno)); exit(1); } if(do_write(rwfd, dev->data, read_size) != read_size) { XLOG("could not write file %s, %s\n", rwfilename, strerror(errno)); exit(1); } } while(read_size == dev->erase_size); close(initfd); } dev->fd = rwfd; nand_dev_count++; return; out_of_memory: XLOG("out of memory\n"); exit(1); bad_arg_and_value: XLOG("bad arg: %.*s=%.*s\n", arg_len, arg, value_len, value); exit(1); }
static ACPI_STATUS AcpiDmDescendingOp ( ACPI_PARSE_OBJECT *Op, UINT32 Level, void *Context) { ACPI_OP_WALK_INFO *Info = Context; const ACPI_OPCODE_INFO *OpInfo; UINT32 Name; ACPI_PARSE_OBJECT *NextOp; if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE) { /* Ignore this op -- it was handled elsewhere */ return (AE_CTRL_DEPTH); } /* Level 0 is at the Definition Block level */ if (Level == 0) { /* In verbose mode, print the AML offset, opcode and depth count */ if (Info->WalkState) { VERBOSE_PRINT ((DB_FULL_OP_INFO, (Info->WalkState->MethodNode ? Info->WalkState->MethodNode->Name.Ascii : " "), Op->Common.AmlOffset, (UINT32) Op->Common.AmlOpcode)); } if (Op->Common.AmlOpcode == AML_SCOPE_OP) { /* This is the beginning of the Definition Block */ AcpiOsPrintf ("{\n"); /* Emit all External() declarations here */ AcpiDmEmitExternals (); return (AE_OK); } } else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) && (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) && (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP)) { /* * This is a first-level element of a term list, * indent a new line */ switch (Op->Common.AmlOpcode) { case AML_NOOP_OP: /* * Optionally just ignore this opcode. Some tables use * NoOp opcodes for "padding" out packages that the BIOS * changes dynamically. This can leave hundreds or * thousands of NoOp opcodes that if disassembled, * cannot be compiled because they are syntactically * incorrect. */ if (AcpiGbl_IgnoreNoopOperator) { Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; return (AE_OK); } /* Fallthrough */ default: AcpiDmIndent (Level); break; } Info->LastLevel = Level; Info->Count = 0; } /* * This is an inexpensive mechanism to try and keep lines from getting * too long. When the limit is hit, start a new line at the previous * indent plus one. A better but more expensive mechanism would be to * keep track of the current column. */ Info->Count++; if (Info->Count /* +Info->LastLevel */ > 12) { Info->Count = 0; AcpiOsPrintf ("\n"); AcpiDmIndent (Info->LastLevel + 1); } /* If ASL+ is enabled, check for a C-style operator */ if (AcpiDmCheckForSymbolicOpcode (Op, Info)) { return (AE_OK); } /* Print the opcode name */ AcpiDmDisassembleOneOp (NULL, Info, Op); if ((Op->Common.DisasmOpcode == ACPI_DASM_LNOT_PREFIX) || (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP)) { return (AE_OK); } if ((Op->Common.AmlOpcode == AML_NAME_OP) || (Op->Common.AmlOpcode == AML_RETURN_OP)) { Info->Level--; } /* Start the opcode argument list if necessary */ OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); if ((OpInfo->Flags & AML_HAS_ARGS) || (Op->Common.AmlOpcode == AML_EVENT_OP)) { /* This opcode has an argument list */ if (AcpiDmBlockType (Op) & BLOCK_PAREN) { AcpiOsPrintf (" ("); } /* If this is a named opcode, print the associated name value */ if (OpInfo->Flags & AML_NAMED) { switch (Op->Common.AmlOpcode) { case AML_ALIAS_OP: NextOp = AcpiPsGetDepthNext (NULL, Op); NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; AcpiDmNamestring (NextOp->Common.Value.Name); AcpiOsPrintf (", "); /*lint -fallthrough */ default: Name = AcpiPsGetName (Op); if (Op->Named.Path) { AcpiDmNamestring ((char *) Op->Named.Path); } else { AcpiDmDumpName (Name); } if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP) { if (AcpiGbl_DbOpt_Verbose) { (void) AcpiPsDisplayObjectPathname (NULL, Op); } } break; } switch (Op->Common.AmlOpcode) { case AML_METHOD_OP: AcpiDmMethodFlags (Op); AcpiOsPrintf (")"); /* Emit description comment for Method() with a predefined ACPI name */ AcpiDmPredefinedDescription (Op); break; case AML_NAME_OP: /* Check for _HID and related EISAID() */ AcpiDmCheckForHardwareId (Op); AcpiOsPrintf (", "); break; case AML_REGION_OP: AcpiDmRegionFlags (Op); break; case AML_POWER_RES_OP: /* Mark the next two Ops as part of the parameter list */ AcpiOsPrintf (", "); NextOp = AcpiPsGetDepthNext (NULL, Op); NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST; NextOp = NextOp->Common.Next; NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST; return (AE_OK); case AML_PROCESSOR_OP: /* Mark the next three Ops as part of the parameter list */ AcpiOsPrintf (", "); NextOp = AcpiPsGetDepthNext (NULL, Op); NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST; NextOp = NextOp->Common.Next; NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST; NextOp = NextOp->Common.Next; NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST; return (AE_OK); case AML_MUTEX_OP: case AML_DATA_REGION_OP: AcpiOsPrintf (", "); return (AE_OK); case AML_EVENT_OP: case AML_ALIAS_OP: return (AE_OK); case AML_SCOPE_OP: case AML_DEVICE_OP: case AML_THERMAL_ZONE_OP: AcpiOsPrintf (")"); break; default: AcpiOsPrintf ("*** Unhandled named opcode %X\n", Op->Common.AmlOpcode); break; } } else switch (Op->Common.AmlOpcode) { case AML_FIELD_OP: case AML_BANK_FIELD_OP: case AML_INDEX_FIELD_OP: Info->BitOffset = 0; /* Name of the parent OperationRegion */ NextOp = AcpiPsGetDepthNext (NULL, Op); AcpiDmNamestring (NextOp->Common.Value.Name); AcpiOsPrintf (", "); NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; switch (Op->Common.AmlOpcode) { case AML_BANK_FIELD_OP: /* Namestring - Bank Name */ NextOp = AcpiPsGetDepthNext (NULL, NextOp); AcpiDmNamestring (NextOp->Common.Value.Name); NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; AcpiOsPrintf (", "); /* * Bank Value. This is a TermArg in the middle of the parameter * list, must handle it here. * * Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMLIST * eliminates newline in the output. */ NextOp = NextOp->Common.Next; Info->Flags = ACPI_PARSEOP_PARAMLIST; AcpiDmWalkParseTree (NextOp, AcpiDmDescendingOp, AcpiDmAscendingOp, Info); Info->Flags = 0; Info->Level = Level; NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; AcpiOsPrintf (", "); break; case AML_INDEX_FIELD_OP: /* Namestring - Data Name */ NextOp = AcpiPsGetDepthNext (NULL, NextOp); AcpiDmNamestring (NextOp->Common.Value.Name); AcpiOsPrintf (", "); NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; break; default: break; } AcpiDmFieldFlags (NextOp); break; case AML_BUFFER_OP: /* The next op is the size parameter */ NextOp = AcpiPsGetDepthNext (NULL, Op); if (!NextOp) { /* Single-step support */ return (AE_OK); } if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE) { /* * We have a resource list. Don't need to output * the buffer size Op. Open up a new block */ NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; NextOp = NextOp->Common.Next; AcpiOsPrintf (")"); /* Emit description comment for Name() with a predefined ACPI name */ AcpiDmPredefinedDescription (Op->Asl.Parent); AcpiOsPrintf ("\n"); AcpiDmIndent (Info->Level); AcpiOsPrintf ("{\n"); return (AE_OK); } /* Normal Buffer, mark size as in the parameter list */ NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST; return (AE_OK); case AML_VAR_PACKAGE_OP: case AML_IF_OP: case AML_WHILE_OP: /* The next op is the size or predicate parameter */ NextOp = AcpiPsGetDepthNext (NULL, Op); if (NextOp) { NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST; } return (AE_OK); case AML_PACKAGE_OP: /* The next op is the size parameter */ NextOp = AcpiPsGetDepthNext (NULL, Op); if (NextOp) { NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST; } return (AE_OK); case AML_MATCH_OP: AcpiDmMatchOp (Op); break; default: break; } if (AcpiDmBlockType (Op) & BLOCK_BRACE) { AcpiOsPrintf ("\n"); AcpiDmIndent (Level); AcpiOsPrintf ("{\n"); } } return (AE_OK); }
//====================================================================== //====================================================================== NvUIEventResponse NvUIButton::HandleEvent(const NvGestureEvent &gdata, NvUST timeUST, NvUIElement *hasInteract) { bool hit = false; if (!m_isVisible || (GetDrawState()==NvUIButtonState::INACTIVE) #ifndef BTN_SUPPORTS_HOVER || (gdata.kind<=NvGestureKind::HOVER) #else || (gdata.kind<NvGestureKind::HOVER) || (gdata.kind==NvGestureKind::HOVER && !m_wantsHover) #endif ) return nvuiEventNotHandled; bool possibleSlideTarget = false; if (gdata.uid == m_reactGestureUID) // then we're done? { VERBOSE_PRINT("early exit same event UID"); if (this==hasInteract) return nvuiEventHandledInteract; else return nvuiEventHandled; // since we flagged the triggered UID... } // check if this is a valid, non-focused/non-active slide-focus target if (gdata.kind==NvGestureKind::DRAG // is a drag/slide going on && GetSlideInteractGroup() // we have a focus group ID && GetSlideInteractGroup() == GetActiveSlideInteractGroup()) // and our ID matches active ID { if (!m_wasHit // if we aren't flagged as active/hit && hasInteract // focus isn't null (early exit) -- note focus could be a higher container rather than another button. // && this!=hasInteract // aren't the focused element (sorta redundant check) ) { possibleSlideTarget = true; } } if (!possibleSlideTarget && gdata.uid == m_failedHitUID) { VERBOSE_PRINT("early exit failed hit"); return nvuiEventNotHandled; } // verify we've been hit.. hit = m_rect.Inside((float)(gdata.x+gdata.dx), (float)(gdata.y+gdata.dy), m_hitMarginWide, m_hitMarginTall); //VERBOSE_PRINT("[event 0x%x] hit = %s, focus = 0x%x\n", (unsigned int)(gdata.uid), hit?"yes":"no", (uint32_t)hasInteract); if (possibleSlideTarget) { // use drag dx/dy for hit detection of CURRENT position, not gesture start loc. if (!hit) { m_wasHit = false; m_failedHitUID = gdata.uid; // so we don't retest. VERBOSE_PRINT("!!!!!> slide target 0x%x not hit\n", (uint32_t)this); return nvuiEventNotHandled; // we're done. } VERBOSE_PRINT("!!!!!> slide target 0x%x hit\n", (uint32_t)this); m_wasHit = true; m_failedHitUID = 0; // so we retest. SetPrevDrawState(GetDrawState()); // .. anything special here?? // lostInteract on other element will happen in container above us. } else // !!!!!TBD // I'm getting MULTIPLE PRESS EVENTS!!!?!?! if (!m_wasHit && gdata.kind==NvGestureKind::PRESS) { if (!hit) { m_wasHit = false; m_failedHitUID = gdata.uid; // so we don't retest. return nvuiEventNotHandled; // we're done. } m_wasHit = true; VERBOSE_PRINT("!!!!!> not hit -> got hit\n"); SetPrevDrawState(GetDrawState()); if (GetDrawState()==0 && GetSlideInteractGroup()) // we set the active group on press. SetActiveSlideInteractGroup(GetSlideInteractGroup()); else SetActiveSlideInteractGroup(0); if (possibleSlideTarget) // we are now! { // .. anything special here?? // lostInteract on other element will happen in container above us. } } else if (!m_wasHit) { VERBOSE_PRINT("!!!!!> not hit -> not hit\n"); #if later // if we get here we: // weren't a valid slide target // weren't getting a press (above) // hadn't gotten a press yet (!wasHit) // hadn't ignored a press (uid exit would have hit above) if (gdata.kind==NV_GESTURE_NONE) { // TODO -- I realize, this isn't great code. trying to get something starter-ish in place. // already calc'd hit. if (hit) { if (!m_wasHover) SetDrawState(1); return nvuiEventHandledHover; } else //!hit { if (!m_wasHover) SetDrawState(0); } } #endif return nvuiEventNotHandled; } else if (m_wasHit && gdata.kind==NvGestureKind::DRAG) { // we're dragging. but might not be INSIDE/hit. VERBOSE_PRINT("> drag\n"); } else if ( // gdata.kind==NV_GESTURE_FLICK || gdata.kind&NvGestureKind::MASK_RELEASED) // any release state!!! { // already calc'd hit. VERBOSE_PRINT("!!!!!> got release\n"); } else if (m_wasHit || this==hasInteract) // keep focus. { VERBOSE_PRINT("!!!!!> was hit, keep focus\n"); return nvuiEventHandledInteract; } VERBOSE_PRINT("!!!!!> secondary processing...\n"); if (hit) { VERBOSE_PRINT("}}}} was hit\n"); if (m_type==NvUIButtonType::CHECK) { // !!!!TBD if (GetPrevDrawState() == GetDrawState()) // we haven't flipped yet { if (GetDrawState()==NvUIButtonState::ACTIVE) SetDrawState(NvUIButtonState::SELECTED); else SetDrawState(NvUIButtonState::ACTIVE); } } else SetDrawState(NvUIButtonState::SELECTED); } else if (!m_stickyClick) { VERBOSE_PRINT("}}}} not hit\n"); if (m_type!=NvUIButtonType::PUSH) { // !!!!TBD //if (m_prevDrawState != m_currDrawState) // we flipped, put BACK SetDrawStatePrev(); } else SetDrawState(NvUIButtonState::ACTIVE); } // if we came this far, we're hit. are we done? if (gdata.kind & NvGestureKind::MASK_RELEASED) // we're done? { VERBOSE_PRINT("}}}} got release !!! !!! !!!! !!! !!!\n"); NvUIEventResponse r = nvuiEventHandled; if (hit) // on the release, what's our curr state?? { VERBOSE_PRINT("}}}}}} hit, any reaction?\n"); if (gdata.uid != m_reactGestureUID) { // !!!!TBD if a radio button, we really want to stash the // state at PRESSED time, so that we know whether to send // an event at all! m_reactGestureUID = gdata.uid; // so we don't retrigger. NvUIReaction &react = GetReactionEdit(); react.uid = m_uiuid; react.code = m_action; react.state = GetDrawState(); // in case someone is looking for a value for this reaction. if (m_type==NvUIButtonType::RADIO) react.ival = m_subcode; else react.ival = react.state; // pass draw state as value. react.flags = NvReactFlag::NONE; react.causeKind = gdata.kind; react.causeIndex = gdata.index; r = nvuiEventHandledInteractReaction; // KEEP FOCUS FOR NOW -- else maybe->tap issues !!!!TBD VERBOSE_PRINT("}}}}}} prepped reaction\n"); } } // reset draw state if button type is Push // AFTER reaction, so we get state correct in the message. if (m_type==NvUIButtonType::PUSH) SetDrawState(NvUIButtonState::ACTIVE); m_wasHit = false; // reset! return r; } if (m_wasHit || this==hasInteract) // keep focus. { NvUIEventResponse r = nvuiEventWantsInteract; if (hit) { r = nvuiEventHandledInteract; } else { VERBOSE_PRINT("} keep focus ftm..\n"); } return r; } return nvuiEventNotHandled; }
void acpi_db_display_op ( acpi_walk_state *walk_state, acpi_parse_object *origin, u32 num_opcodes) { acpi_parse_object *op = origin; acpi_parse_object *arg; acpi_parse_object *depth; u32 depth_count = 0; u32 last_depth = 0; u32 i; u32 j; if (op) { while (op) { /* indentation */ depth_count = 0; if (!acpi_gbl_db_opt_verbose) { depth_count++; } /* Determine the nesting depth of this argument */ for (depth = op->parent; depth; depth = depth->parent) { arg = acpi_ps_get_arg (depth, 0); while (arg && arg != origin) { arg = arg->next; } if (arg) { break; } depth_count++; } /* Open a new block if we are nested further than last time */ if (depth_count > last_depth) { VERBOSE_PRINT ((DB_NO_OP_INFO, last_depth)); for (i = 0; i < last_depth; i++) { acpi_os_printf ("%s", acpi_gbl_db_disasm_indent); } if (acpi_db_block_type (op) == BLOCK_PAREN) { acpi_os_printf ("(\n"); } else { acpi_os_printf ("{\n"); } } /* Close a block if we are nested less than last time */ else if (depth_count < last_depth) { for (j = 0; j < (last_depth - depth_count); j++) { VERBOSE_PRINT ((DB_NO_OP_INFO, last_depth - j)); for (i = 0; i < (last_depth - j - 1); i++) { acpi_os_printf ("%s", acpi_gbl_db_disasm_indent); } if (acpi_db_block_type (op) == BLOCK_PAREN) { acpi_os_printf (")\n"); } else { acpi_os_printf ("}\n"); } } } /* In verbose mode, print the AML offset, opcode and depth count */ VERBOSE_PRINT ((DB_FULL_OP_INFO, (unsigned) op->aml_offset, op->opcode, depth_count)); /* Indent the output according to the depth count */ for (i = 0; i < depth_count; i++) { acpi_os_printf ("%s", acpi_gbl_db_disasm_indent); } /* Now print the opcode */ acpi_db_display_opcode (walk_state, op); /* Resolve a name reference */ if ((op->opcode == AML_INT_NAMEPATH_OP && op->value.name) && (op->parent) && (acpi_gbl_db_opt_verbose)) { acpi_ps_display_object_pathname (walk_state, op); } acpi_os_printf ("\n"); /* Get the next node in the tree */ op = acpi_ps_get_depth_next (origin, op); last_depth = depth_count; num_opcodes--; if (!num_opcodes) { op = NULL; } } /* Close the last block(s) */ depth_count = last_depth -1; for (i = 0; i < last_depth; i++) { VERBOSE_PRINT ((DB_NO_OP_INFO, last_depth - i)); for (j = 0; j < depth_count; j++) { acpi_os_printf ("%s", acpi_gbl_db_disasm_indent); } acpi_os_printf ("}\n"); depth_count--; } } else { acpi_db_display_opcode (walk_state, op); } }
ACPI_NATIVE_INT AsProcessTree ( ACPI_CONVERSION_TABLE *ConversionTable, char *SourcePath, char *TargetPath) { int MaxPathLength; MaxPathLength = AsMaxInt (strlen (SourcePath), strlen (TargetPath)); if (!(ConversionTable->Flags & FLG_NO_FILE_OUTPUT)) { if (ConversionTable->Flags & FLG_LOWERCASE_DIRNAMES) { AsStrlwr (TargetPath); } VERBOSE_PRINT (("Creating Directory \"%s\"\n", TargetPath)); if (mkdir (TargetPath)) { if (errno != EEXIST) { printf ("Could not create target directory\n"); return (-1); } } } /* Do the C source files */ AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, FILE_TYPE_SOURCE, "*.c"); /* Do the C header files */ AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, FILE_TYPE_HEADER, "*.h"); /* Do the Lex file(s) */ AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, FILE_TYPE_SOURCE, "*.l"); /* Do the yacc file(s) */ AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, FILE_TYPE_SOURCE, "*.y"); /* Do any ASL files */ AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, FILE_TYPE_HEADER, "*.asl"); /* Do any subdirectories */ AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, FILE_TYPE_DIRECTORY, "*"); return (0); }
static void emulator_window_setup( EmulatorWindow* emulator ) { static const SkinWindowFuncs my_window_funcs = { .key_event = &emulator_window_window_key_event, .mouse_event = &emulator_window_window_mouse_event, .generic_event = &emulator_window_window_generic_event, .opengles_show = &emulator_window_opengles_show_window, .opengles_hide = &emulator_window_opengles_hide_window, .opengles_redraw = &emulator_window_opengles_redraw_window, .opengles_free = &android_stopOpenglesRenderer, }; static const SkinTrackBallParameters my_trackball_params = { .diameter = 30, .ring = 2, .ball_color = 0xffe0e0e0, .dot_color = 0xff202020, .ring_color = 0xff000000, .event_func = &emulator_window_trackball_event, }; if (emulator->opts->no_window || emulator->ui) { return; } SkinUIParams my_ui_params = { .enable_touch = !androidHwConfig_isScreenNoTouch(android_hw), .enable_dpad = android_hw->hw_dPad != 0, .enable_keyboard = android_hw->hw_keyboard != 0, .enable_trackball = android_hw->hw_trackBall != 0, .window_x = emulator->win_x, .window_y = emulator->win_y, .window_scale = get_default_scale(emulator->opts), .keyboard_charmap = emulator->opts->charmap, .keyboard_raw_keys = emulator->opts->raw_keys != 0, #if CONFIG_QT .win32_ignore_events = true, #else .win32_ignore_events = false, #endif }; write_window_name(my_ui_params.window_name, sizeof(my_ui_params.window_name), android_base_port, avdInfo_getName(android_avdInfo)); static const SkinUIFuncs my_ui_funcs = { .window_funcs = &my_window_funcs, .trackball_params = &my_trackball_params, .keyboard_event = &emulator_window_keyboard_event, //user_event_key, .keyboard_flush = &user_event_keycodes, .network_toggle = &emulator_window_network_toggle, .framebuffer_invalidate = &emulator_window_framebuffer_invalidate, }; // Determine whether to use an EmuGL sub-window or not. const char* env = getenv("ANDROID_GL_SOFTWARE_RENDERER"); s_use_emugl_subwindow = !env || !env[0] || env[0] == '0'; if (s_use_emugl_subwindow) { VERBOSE_PRINT(gles, "Using EmuGL sub-window for GPU display"); } else { VERBOSE_PRINT(gles, "Using glReadPixels() for GPU display"); } emulator->ui = skin_ui_create(emulator->layout_file, android_hw->hw_initialOrientation, &my_ui_funcs, &my_ui_params); if (!emulator->ui) { return; } if (emulator->onion) { skin_ui_set_onion(emulator->ui, emulator->onion, emulator->onion_rotation, emulator->onion_alpha); } // Determine whether to use an EmuGL sub-window or not. if (!s_use_emugl_subwindow) { gpu_frame_set_post_callback(looper_newCore(), emulator, _emulator_window_on_gpu_frame); } skin_ui_reset_title(emulator->ui); } static void emulator_window_fb_update( void* _emulator, int x, int y, int w, int h ) { EmulatorWindow* emulator = _emulator; if (emulator->opts->no_window) { return; } if (!emulator->ui) { emulator_window_setup(emulator); } skin_ui_update_display(emulator->ui, x, y, w, h); } static void emulator_window_fb_rotate( void* _emulator, int rotation ) { EmulatorWindow* emulator = _emulator; emulator_window_setup( emulator ); }
static bool cinFile_scan(){ VERBOSE_PRINT("*** Scanning cinFile %s\n",cinFile_name); ScanStage stage=SCAN_STAGE_INIT; char buf[FILE_READ_BUFFER_SIZE]; Fields fields; int freq; bool convert_keyname=false; char key_last[FILE_READ_BUFFER_SIZE]; key_last[0]='\0'; while(fgets(buf,FILE_READ_BUFFER_SIZE, cinFile)!=NULL){ if (strlen(buf)<=1){ /* Skip empty line */ continue; } VERBOSE_PRINT("stage=%d buf=%s|\n",stage,buf); fields_parse(buf,&fields); switch(stage){ case SCAN_STAGE_INIT: if ((strcmp(fields.field[0],"%keyname")==0) && (strcmp(fields.field[1],"begin")==0) ){ stage=SCAN_STAGE_KEYNAME; VERBOSE_PRINT("Reading %%keyname"); convert_keyname=true; }else if ((strcmp(fields.field[0],"%chardef")==0) && (strcmp(fields.field[1],"begin")==0) ){ stage=SCAN_STAGE_CHARDEF; VERBOSE_PRINT("Reading %%chardef"); } break; case SCAN_STAGE_KEYNAME: if ((strcmp(fields.field[0],"%keyname")==0) && (strcmp(fields.field[1],"end")==0) ){ VERBOSE_PRINT("Reading %%keyname Done"); break; }else if ((strcmp(fields.field[0],"%chardef")==0) && (strcmp(fields.field[1],"begin")==0) ){ VERBOSE_PRINT("Reading %%chardef"); stage=SCAN_STAGE_CHARDEF; break; } validInputChars[validInputChars_len++]=fields.field[0][0]; validInputChars[validInputChars_len]='\0'; fprintf(cinGouCiFile,"%s\t%s\n",fields.field[1],fields.field[0]); break; case SCAN_STAGE_CHARDEF: if ((strcmp(fields.field[0],"%chardef")==0) && (strcmp(fields.field[1],"end")==0) ){ VERBOSE_PRINT("Reading %%chardef Done"); break; } if (strcmp(key_last,fields.field[0])==0){ freq-=5; }else{ freq=FREQ_INIT; strcpy(key_last,fields.field[0]); int key_len=strlen(fields.field[0]); if (key_len > maxKeyLength){ maxKeyLength=key_len; } } fprintf(cinTableFile,"%s\t%s\t%d\n",fields.field[0],fields.field[1],freq); break; } } fflush(cinTableFile); fflush(cinGouCiFile); return true; }
void AsDoWildcard ( ACPI_CONVERSION_TABLE *ConversionTable, char *SourcePath, char *TargetPath, int MaxPathLength, int FileType, char *WildcardSpec) { void *DirInfo; char *Filename; char *SourceDirPath; char *TargetDirPath; char RequestedFileType; if (FileType == FILE_TYPE_DIRECTORY) { RequestedFileType = REQUEST_DIR_ONLY; } else { RequestedFileType = REQUEST_FILE_ONLY; } VERBOSE_PRINT (("Checking for %s source files in directory \"%s\"\n", WildcardSpec, SourcePath)); /* Open the directory for wildcard search */ DirInfo = AcpiOsOpenDirectory (SourcePath, WildcardSpec, RequestedFileType); if (DirInfo) { /* * Get all of the files that match both the * wildcard and the requested file type */ while ((Filename = AcpiOsGetNextFilename (DirInfo))) { /* Looking for directory files, must check file type */ switch (RequestedFileType) { case REQUEST_DIR_ONLY: /* If we actually have a dir, process the subtree */ if (!AsCheckForDirectory (SourcePath, TargetPath, Filename, &SourceDirPath, &TargetDirPath)) { VERBOSE_PRINT (("Subdirectory: %s\n", Filename)); AsProcessTree (ConversionTable, SourceDirPath, TargetDirPath); free (SourceDirPath); free (TargetDirPath); } break; case REQUEST_FILE_ONLY: /* Otherwise, this is a file, not a directory */ VERBOSE_PRINT (("File: %s\n", Filename)); AsProcessOneFile (ConversionTable, SourcePath, TargetPath, MaxPathLength, Filename, FileType); break; default: break; } } /* Cleanup */ AcpiOsCloseDirectory (DirInfo); } }
void AsCountSourceLines ( char *Buffer, char *Filename) { char *SubBuffer = Buffer; UINT32 LineCount = 0; UINT32 WhiteCount = 0; UINT32 CommentCount = 0; while (*SubBuffer) { /* Detect comments (// comments are not used, non-ansii) */ if ((SubBuffer[0] == '/') && (SubBuffer[1] == '*')) { SubBuffer += 2; /* First line of multi-line comment is often just whitespace */ if (SubBuffer[0] == '\n') { WhiteCount++; SubBuffer++; } else { CommentCount++; } /* Find end of comment */ while (SubBuffer[0] && SubBuffer[1] && !(((SubBuffer[0] == '*') && (SubBuffer[1] == '/')))) { if (SubBuffer[0] == '\n') { CommentCount++; } SubBuffer++; } } /* A linefeed followed by a non-linefeed is a valid source line */ else if ((SubBuffer[0] == '\n') && (SubBuffer[1] != '\n')) { LineCount++; } /* Two back-to-back linefeeds indicate a whitespace line */ else if ((SubBuffer[0] == '\n') && (SubBuffer[1] == '\n')) { WhiteCount++; } SubBuffer++; } /* Adjust comment count for legal header */ if (Gbl_HeaderSize < CommentCount) { CommentCount -= Gbl_HeaderSize; Gbl_HeaderLines += Gbl_HeaderSize; } Gbl_SourceLines += LineCount; Gbl_WhiteLines += WhiteCount; Gbl_CommentLines += CommentCount; VERBOSE_PRINT (("%u Comment %u White %u Code %u Lines in %s\n", CommentCount, WhiteCount, LineCount, LineCount + WhiteCount + CommentCount, Filename)); }
void AsConvertFile ( ACPI_CONVERSION_TABLE *ConversionTable, char *FileBuffer, char *Filename, ACPI_NATIVE_INT FileType) { UINT32 i; UINT32 Functions; ACPI_STRING_TABLE *StringTable; ACPI_IDENTIFIER_TABLE *ConditionalTable; ACPI_IDENTIFIER_TABLE *LineTable; ACPI_IDENTIFIER_TABLE *MacroTable; ACPI_TYPED_IDENTIFIER_TABLE *StructTable; ACPI_IDENTIFIER_TABLE *SpecialMacroTable; switch (FileType) { case FILE_TYPE_SOURCE: Functions = ConversionTable->SourceFunctions; StringTable = ConversionTable->SourceStringTable; LineTable = ConversionTable->SourceLineTable; ConditionalTable = ConversionTable->SourceConditionalTable; MacroTable = ConversionTable->SourceMacroTable; StructTable = ConversionTable->SourceStructTable; SpecialMacroTable = ConversionTable->SourceSpecialMacroTable; break; case FILE_TYPE_HEADER: Functions = ConversionTable->HeaderFunctions; StringTable = ConversionTable->HeaderStringTable; LineTable = ConversionTable->HeaderLineTable; ConditionalTable = ConversionTable->HeaderConditionalTable; MacroTable = ConversionTable->HeaderMacroTable; StructTable = ConversionTable->HeaderStructTable; SpecialMacroTable = ConversionTable->HeaderSpecialMacroTable; break; default: printf ("Unknown file type, cannot process\n"); return; } Gbl_StructDefs = strstr (FileBuffer, "/* acpisrc:StructDefs"); Gbl_Files++; VERBOSE_PRINT (("Processing %u bytes\n", (unsigned int) strlen (FileBuffer))); if (Gbl_Cleanup) { AsRemoveExtraLines (FileBuffer, Filename); AsRemoveSpacesAfterPeriod (FileBuffer, Filename); } if (ConversionTable->LowerCaseTable) { for (i = 0; ConversionTable->LowerCaseTable[i].Identifier; i++) { AsLowerCaseString (ConversionTable->LowerCaseTable[i].Identifier, FileBuffer); } } /* Process all the string replacements */ if (StringTable) { for (i = 0; StringTable[i].Target; i++) { AsReplaceString (StringTable[i].Target, StringTable[i].Replacement, StringTable[i].Type, FileBuffer); } } if (LineTable) { for (i = 0; LineTable[i].Identifier; i++) { AsRemoveLine (FileBuffer, LineTable[i].Identifier); } } if (ConditionalTable) { for (i = 0; ConditionalTable[i].Identifier; i++) { AsRemoveConditionalCompile (FileBuffer, ConditionalTable[i].Identifier); } } if (MacroTable) { for (i = 0; MacroTable[i].Identifier; i++) { AsRemoveMacro (FileBuffer, MacroTable[i].Identifier); } } if (StructTable) { for (i = 0; StructTable[i].Identifier; i++) { AsInsertPrefix (FileBuffer, StructTable[i].Identifier, StructTable[i].Type); } } if (SpecialMacroTable) { for (i = 0; SpecialMacroTable[i].Identifier; i++) { AsCleanupSpecialMacro (FileBuffer, SpecialMacroTable[i].Identifier); } } /* Process the function table */ for (i = 0; i < 32; i++) { /* Decode the function bitmap */ switch ((1 << i) & Functions) { case 0: /* This function not configured */ break; case CVT_COUNT_TABS: AsCountTabs (FileBuffer, Filename); break; case CVT_COUNT_NON_ANSI_COMMENTS: AsCountNonAnsiComments (FileBuffer, Filename); break; case CVT_CHECK_BRACES: AsCheckForBraces (FileBuffer, Filename); break; case CVT_TRIM_LINES: AsTrimLines (FileBuffer, Filename); break; case CVT_COUNT_LINES: AsCountSourceLines (FileBuffer, Filename); break; case CVT_BRACES_ON_SAME_LINE: AsBracesOnSameLine (FileBuffer); break; case CVT_MIXED_CASE_TO_UNDERSCORES: AsMixedCaseToUnderscores (FileBuffer, Filename); break; case CVT_LOWER_CASE_IDENTIFIERS: AsLowerCaseIdentifiers (FileBuffer); break; case CVT_REMOVE_DEBUG_MACROS: AsRemoveDebugMacros (FileBuffer); break; case CVT_TRIM_WHITESPACE: AsTrimWhitespace (FileBuffer); break; case CVT_REMOVE_EMPTY_BLOCKS: AsRemoveEmptyBlocks (FileBuffer, Filename); break; case CVT_REDUCE_TYPEDEFS: AsReduceTypedefs (FileBuffer, "typedef union"); AsReduceTypedefs (FileBuffer, "typedef struct"); break; case CVT_SPACES_TO_TABS4: AsTabify4 (FileBuffer); break; case CVT_SPACES_TO_TABS8: AsTabify8 (FileBuffer); break; case CVT_COUNT_SHORTMULTILINE_COMMENTS: #ifdef ACPI_FUTURE_IMPLEMENTATION AsTrimComments (FileBuffer, Filename); #endif break; default: printf ("Unknown conversion subfunction opcode\n"); break; } } if (ConversionTable->NewHeader) { AsReplaceHeader (FileBuffer, ConversionTable->NewHeader); } }
int main(int argc, char *argv[]) { byte *dll_1, *dll_2, *p1, *p2, *iat_start1, *iat_end1, *iat_start2, *iat_end2; bool has_iat = false; MEMORY_BASIC_INFORMATION info; void *drcontext = dr_standalone_init(); uint writable_pages = 0, reserved_pages = 0, IAT_pages = 0; uint matched_pages = 0, second_matched_pages = 0, unmatched_pages = 0; uint exact_match_pages = 0, exact_no_match_pages = 0; char reloc_file[MAX_PATH] = {0}, orig_file[MAX_PATH], *input_file; uint old_size = 0, new_size = 0; uint old_base = 0, new_base = 0x69000000; /* unlikely to collide */ /* user specified option defaults */ uint arg_offs = 1; bool use_second_pass = true; bool assume_header_match = true; uint second_pass_offset = 16; /* FIXME arbitrary, what's a good choice? */ bool assume_IAT_written = true; bool spin_for_debugger = false; if (argc < 2) return usage(argv[0]); while (argv[arg_offs][0] == '-') { if (strcmp(argv[arg_offs], "-vv") == 0) { vv = true; } else if (strcmp(argv[arg_offs], "-v") == 0) { v = true; } else if (strcmp(argv[arg_offs], "-no_second_pass") == 0) { use_second_pass = false; } else if (strcmp(argv[arg_offs], "-second_pass_offset") == 0) { if ((uint)argc <= arg_offs+1) return usage(argv[0]); second_pass_offset = atoi(argv[++arg_offs]); } else if (strcmp(argv[arg_offs], "-no_assume_IAT_written") == 0) { assume_IAT_written = false; } else if (strcmp(argv[arg_offs], "-spin_for_debugger") == 0) { spin_for_debugger = true; } else { return usage(argv[0]); } arg_offs++; } input_file = argv[arg_offs++]; if (arg_offs != argc) return usage(argv[0]); _snprintf(reloc_file, sizeof(reloc_file), "%s.reloc.dll", input_file); reloc_file[sizeof(reloc_file)-1] = '\0'; if (!CopyFile(input_file, reloc_file, FALSE)) { LPSTR msg = NULL; uint error = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER, 0, GetLastError(), 0, msg, 0, NULL); VERBOSE_PRINT("Copy Error %d (0x%x) = %s\n", error, error, msg); return 1; } snprintf(orig_file, sizeof(orig_file), "%s.orig.dll", input_file); orig_file[sizeof(orig_file)-1] = '\0'; if (!CopyFile(input_file, orig_file, FALSE)) { LPSTR msg = NULL; uint error = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER, 0, GetLastError(), 0, msg, 0, NULL); VERBOSE_PRINT("Copy Error %d (0x%x) = %s\n", error, error, msg); return 1; } if (ReBaseImage(reloc_file, "", TRUE, FALSE, FALSE, 0, &old_size, &old_base, &new_size, &new_base, 0)) { VERBOSE_PRINT("Rebased imsage \"%s\" from 0x%08x to 0x%08x\n" "Size changed from %d bytes to %d bytes\n", input_file, old_base, new_base, old_size, new_size); } else { LPSTR msg = NULL; uint error = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER, 0, GetLastError(), 0, msg, 0, NULL); VERBOSE_PRINT("Rebase Error %d (0x%x) = %s\n", error, error, msg); return 1; } dll_1 = (byte *)ALIGN_BACKWARD(LoadLibraryExA(orig_file, NULL, DONT_RESOLVE_DLL_REFERENCES), PAGE_SIZE); p1 = dll_1; dll_2 = (byte *)ALIGN_BACKWARD(LoadLibraryExA(reloc_file, NULL, DONT_RESOLVE_DLL_REFERENCES), PAGE_SIZE); p2 = dll_2; VVERBOSE_PRINT("Loaded dll @ 0x%08x and 0x%08x\n", dll_1, dll_2); if (dll_1 == NULL || dll_2 == NULL) { VERBOSE_PRINT( "Error loading %s\n", input_file); return 1; } /* Handle the first page specially since I'm seeing problems with a handful of * dlls that aren't really getting rebased. mcupdate_GenuineIntel.dll for ex. * (which does have relocations etc.) not sure what's up, but it's only a couple of * dlls so will ignore them. If we really rebased the header should differ. */ if (memcmp(dll_1, dll_2, PAGE_SIZE) == 0) { printf("%s - ERROR during relocating\n", input_file); return 1; } else { exact_no_match_pages++; if (assume_header_match) /* We could modify the hash function to catch header pages. */ matched_pages++; else unmatched_pages++; } p1 += PAGE_SIZE; p2 += PAGE_SIZE; if (assume_IAT_written && get_IAT_section_bounds(dll_1, &iat_start1, &iat_end1)) { has_iat = true; ASSERT(get_IAT_section_bounds(dll_2, &iat_start2, &iat_end2) && iat_start1 - dll_1 == iat_start2 - dll_2 && iat_end1 - dll_1 == iat_end2 - dll_2); } while (dr_virtual_query(p1, &info, sizeof(info)) == sizeof(info) && info.State != MEM_FREE && info.AllocationBase == dll_1) { /* we only check read-only pages (assumption writable pages aren't shareable) */ ASSERT(p1 == info.BaseAddress); if (info.State != MEM_COMMIT) { reserved_pages += info.RegionSize / PAGE_SIZE; VVERBOSE_PRINT("skipping %d reserved pages\n", info.RegionSize / PAGE_SIZE); p1 += info.RegionSize; p2 += info.RegionSize; } else if (!prot_is_writable(info.Protect)) { uint i; for (i = 0; i < info.RegionSize / PAGE_SIZE; i++) { bool exact = false; if (assume_IAT_written && has_iat && iat_end1 > p1 && iat_start1 < p1 + PAGE_SIZE) { /* overlaps an IAT page */ IAT_pages++; p1 += PAGE_SIZE; p2 += PAGE_SIZE; continue; } if (memcmp(p1, p2, PAGE_SIZE) == 0) { VVERBOSE_PRINT("Page Exact Match\n"); exact_match_pages++; exact = true; } else { VVERBOSE_PRINT("Page Exact Mismatch\n"); exact_no_match_pages++; } if (compare_pages(drcontext, p1, p2, 0)) { VVERBOSE_PRINT("Matched page\n"); matched_pages++; } else { VVERBOSE_PRINT("Failed to match page\n"); if (use_second_pass && compare_pages(drcontext, p1, p2, second_pass_offset)) { second_matched_pages++; } else { unmatched_pages++; } ASSERT(!exact); } p1 += PAGE_SIZE; p2 += PAGE_SIZE; } } else { writable_pages += info.RegionSize / PAGE_SIZE; VVERBOSE_PRINT("skipping %d writable pages\n", info.RegionSize / PAGE_SIZE); p1 += info.RegionSize; p2 += info.RegionSize; } } VERBOSE_PRINT("%d exact match, %d not exact match\n%d hash_match, %d second_hash_match, %d hash_mismatch\n", exact_match_pages, exact_no_match_pages, matched_pages, second_matched_pages, unmatched_pages); printf("%s : %d pages - %d w %d res %d IAT = %d same %d differ : %d hash differ %d first hash differ : %d%% found, %d%% found first hash\n", input_file, writable_pages + reserved_pages + IAT_pages + exact_match_pages + exact_no_match_pages, writable_pages, reserved_pages, IAT_pages, exact_match_pages, exact_no_match_pages, unmatched_pages, unmatched_pages + second_matched_pages, (100 * (matched_pages + second_matched_pages - exact_match_pages))/exact_no_match_pages, (100 * (matched_pages - exact_match_pages))/exact_no_match_pages); while (spin_for_debugger) Sleep(1000); return 0; }