static inline void quiet_border (zebra_image_scanner_t *iscn, unsigned samples, int x, int y) { unsigned i; for(i = samples; i; i--) if(zebra_scan_y(iscn->scn, 255)) symbol_handler(iscn, x, y); /* flush final transition with 2 black pixels */ for(i = 2; i; i--) if(zebra_scan_y(iscn->scn, 0)) symbol_handler(iscn, x, y); if(zebra_scanner_new_scan(iscn->scn)) symbol_handler(iscn, x, y); }
int main(int argc, char *argv[]) { char input_char; FILE *fp; if((fp = fopen(argv[1], "r")) == NULL) { printf("\nError!\n\n%s file doesn't exist!\n\n", argv[1]); return -1; } if((output_fp = fopen(argv[2], "w")) == NULL) { printf("\nError!\n\n%s.out file can't be created doesn't exist!\n\n", argv[2]); return -1; } while(!feof(fp)) { input_char = fgetc(fp); if (isalnum(input_char)) { if (isdigit(input_char)) { digit_handler(fp, input_char); } if (isalpha(input_char)) { token_handler(fp, input_char); } } if (ispunct(input_char)) { symbol_handler(fp, input_char); } } fclose(fp); fclose(output_fp); return 0; }
void digit_handler(FILE *file_pointer, char input) { int output; if(input == '0') { fprintf(output_fp, "271\t0x00000000\n"); } else { output = input - '0'; input = fgetc(file_pointer); while(isdigit(input)) { output = ( (output * 10) + (input - '0') ); input = fgetc(file_pointer); } fprintf(output_fp, "271\t%#010x\n", output); if (ispunct(input)) { symbol_handler(file_pointer, input); } } }
void token_handler(FILE *fp, char input) { char string[MAXLINE]; string[0] = '\0'; char temp[5]; while ( (isalnum(input)) || (input == '_') ) { temp[0] = input; temp[1] = '\0'; strcat(string, temp); input = fgetc(fp); } if ( (strcmp(string, "int")) == 0) { fprintf(output_fp, "262\n"); } else if ( (strcmp(string, "if")) == 0) { fprintf(output_fp, "263\n"); } else if ( (strcmp(string, "else")) == 0) { fprintf(output_fp, "264\n"); } else if ( (strcmp(string, "while")) == 0) { fprintf(output_fp, "265\n"); } else if ( (strcmp(string, "break")) == 0) { fprintf(output_fp, "266\n"); } else if ( (strcmp(string, "continue")) == 0) { fprintf(output_fp, "267\n"); } else if ( (strcmp(string, "scan")) == 0) { fprintf(output_fp, "268\n"); } else if ( (strcmp(string, "print")) == 0) { fprintf(output_fp, "269\n"); } else { fprintf(output_fp, "270\t%s\n", string); } string[0] = '\0'; if (ispunct(input)) { symbol_handler(fp, input); } }
static unsigned int handle_symtable_64(char *module, UInt32 base, struct symtab_command* symtabCommand, long long(*symbol_handler)(char*, char*, long long, char), char is64) { unsigned int module_start = 0xFFFFFFFF; UInt32 symbolIndex = 0; if (!symtabCommand) { return 0xFFFFFFFF; } char* symbolString = base + (char*)symtabCommand->stroff; if(!is64) { struct nlist* symbolEntry = (void*)base + symtabCommand->symoff; while(symbolIndex < symtabCommand->nsyms) { if(symbolEntry->n_value) { if(strstr(symbolString + symbolEntry->n_un.n_strx, "module_start") || (strncmp(symbolString + symbolEntry->n_un.n_strx, "start", sizeof("start")) == 0)) { module_start = base + symbolEntry->n_value; DBG("n_value %x module_start %x\n", (unsigned)symbolEntry->n_value, (unsigned)module_start); } else { symbol_handler(module, symbolString + symbolEntry->n_un.n_strx, (long long)base + symbolEntry->n_value, is64); } #if DEBUG_KERNEL_PATCHER bool isTexT = (((unsigned)symbolEntry->n_value > (unsigned)vmaddr) && ((unsigned)(vmaddr + vmsize) > (unsigned)symbolEntry->n_value )); printf("%s %s\n", isTexT ? "__TEXT :" : "__DATA(OR ANY) :", symbolString + symbolEntry->n_un.n_strx); #if DEBUG_KERNEL_PATCHER==2 if(strcmp(symbolString + symbolEntry->n_un.n_strx, "_BootHelp_txt") == 0) { long long addr = (long long)base + symbolEntry->n_value; unsigned char *BootHelp = NULL; BootHelp = (unsigned char*)(UInt32)addr; printf("method 1: __DATA : BootHelp_txt[0] %x\n", BootHelp[0]); long long addr2 = symbolEntry->n_value; unsigned char *BootHelp2 = NULL; BootHelp2 = (unsigned char*)(UInt32)addr2; printf("method 2: __DATA : BootHelp_txt[0] %x\n", BootHelp2[0]); } #endif #endif } symbolEntry++; symbolIndex++; // TODO remove } } else { struct nlist_64* symbolEntry = (void*)base + symtabCommand->symoff; // NOTE First entry is *not* correct, but we can ignore it (i'm getting radar:// right now) while(symbolIndex < symtabCommand->nsyms) { if(strstr(symbolString + symbolEntry->n_un.n_strx, "module_start") || (strncmp(symbolString + symbolEntry->n_un.n_strx, "start",sizeof("start")) == 0)) { module_start = (unsigned int)(base + symbolEntry->n_value); } else { symbol_handler(module, symbolString + symbolEntry->n_un.n_strx, (long long)base + symbolEntry->n_value, is64); } symbolEntry++; symbolIndex++; // TODO remove } } return module_start; }
int zebra_scan_image (zebra_image_scanner_t *iscn, zebra_image_t *img) { recycle_syms(iscn, img); /* get grayscale image, convert if necessary */ /*img = zebra_image_convert(img, fourcc('Y','8','0','0'));*/ if(!img) return(-1); unsigned w = zebra_image_get_width(img); unsigned h = zebra_image_get_height(img); const uint8_t *data = zebra_image_get_data(img); const uint8_t *p = data; int x = 0, y = 0; #ifdef DEBUG_IMG_SCANNER movedelta(0, (h + 1) / 2); #else movedelta(0, 8); #endif if(zebra_scanner_new_scan(iscn->scn)) symbol_handler(iscn, x, y); /* FIXME add density config api */ /* FIXME less arbitrary lead-out default */ int quiet = w / 32; if(quiet < 8) quiet = 8; while(y < h) { zprintf(32, "img_x+: %03x,%03x @%p\n", x, y, p); while(x < w) { ASSERT_POS; if(zebra_scan_y(iscn->scn, *p)) symbol_handler(iscn, x, y); movedelta(1, 0); } quiet_border(iscn, quiet, x, y); movedelta(-1, 16); if(y >= h) break; zprintf(32, "img_x-: %03x,%03x @%p\n", x, y, p); while(x > 0) { ASSERT_POS; if(zebra_scan_y(iscn->scn, *p)) symbol_handler(iscn, x, y); movedelta(-1, 0); } quiet_border(iscn, quiet, x, y); movedelta(1, 16); #ifdef DEBUG_IMG_SCANNER break; #endif } #ifndef DEBUG_IMG_SCANNER x = y = 0; p = data; movedelta(8, 0); while(x < w) { zprintf(32, "img_y+: %03x,%03x @%p\n", x, y, p); while(y < h) { ASSERT_POS; if(zebra_scan_y(iscn->scn, *p)) symbol_handler(iscn, x, y); movedelta(0, 1); } quiet_border(iscn, quiet, x, y); movedelta(16, -1); if(x >= w) break; zprintf(32, "img_y-: %03x,%03x @%p\n", x, y, p); while(y >= 0) { ASSERT_POS; if(zebra_scan_y(iscn->scn, *p)) symbol_handler(iscn, x, y); movedelta(0, -1); } quiet_border(iscn, quiet, x, y); movedelta(16, 1); } #endif /* flush scanner pipe */ if(zebra_scanner_new_scan(iscn->scn)) symbol_handler(iscn, x, y); /* release reference */ zebra_image_destroy(img); return(iscn->img->nsyms); }
int zbar_scan_image (zbar_image_scanner_t *iscn, zbar_image_t *img) { recycle_syms(iscn, img); /* get grayscale image, convert if necessary */ img = zbar_image_convert(img, fourcc('Y','8','0','0')); if(!img) return(-1); unsigned w = zbar_image_get_width(img); unsigned h = zbar_image_get_height(img); const uint8_t *data = zbar_image_get_data(img); /* FIXME less arbitrary lead-out default */ int quiet = w / 32; if(quiet < 8) quiet = 8; int density = CFG(iscn, ZBAR_CFG_Y_DENSITY); if(density > 0) { const uint8_t *p = data; int x = 0, y = 0; int border = (((h - 1) % density) + 1) / 2; if(border > h / 2) border = h / 2; movedelta(0, border); if(zbar_scanner_new_scan(iscn->scn)) symbol_handler(iscn, x, y); while(y < h) { zprintf(32, "img_x+: %03x,%03x @%p\n", x, y, p); while(x < w) { ASSERT_POS; if(zbar_scan_y(iscn->scn, *p)) symbol_handler(iscn, x, y); movedelta(1, 0); } quiet_border(iscn, quiet, x, y); movedelta(-1, density); if(y >= h) break; zprintf(32, "img_x-: %03x,%03x @%p\n", x, y, p); while(x > 0) { ASSERT_POS; if(zbar_scan_y(iscn->scn, *p)) symbol_handler(iscn, x, y); movedelta(-1, 0); } quiet_border(iscn, quiet, x, y); movedelta(1, density); } } density = CFG(iscn, ZBAR_CFG_X_DENSITY); if(density > 0) { const uint8_t *p = data; int x = 0, y = 0; int border = (((w - 1) % density) + 1) / 2; if(border > w / 2) border = w / 2; movedelta(border, 0); while(x < w) { zprintf(32, "img_y+: %03x,%03x @%p\n", x, y, p); while(y < h) { ASSERT_POS; if(zbar_scan_y(iscn->scn, *p)) symbol_handler(iscn, x, y); movedelta(0, 1); } quiet_border(iscn, quiet, x, y); movedelta(density, -1); if(x >= w) break; zprintf(32, "img_y-: %03x,%03x @%p\n", x, y, p); while(y >= 0) { ASSERT_POS; if(zbar_scan_y(iscn->scn, *p)) symbol_handler(iscn, x, y); movedelta(0, -1); } quiet_border(iscn, quiet, x, y); movedelta(density, 1); } } /* release reference to converted image */ zbar_image_destroy(img); return(iscn->img->nsyms); }