static int singlevaraux(FuncState* fs, TString* n, expdesc* var, int base) { if (fs == NULL) /* no more levels? */ { init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ return VGLOBAL; } else { int v = searchvar(fs, n); /* look up at current level */ if (v >= 0) { init_exp(var, VLOCAL, v); if (!base) markupval(fs, v); /* local will be used as an upval */ return VLOCAL; } else /* not found at current level; try upper one */ { if (singlevaraux(fs->prev, n, var, 0) == VGLOBAL) return VGLOBAL; var->u.s.info = indexupvalue(fs, n, var); /* else was LOCAL or UPVAL */ var->k = VUPVAL; /* upvalue in this level */ return VUPVAL; } } }
/* Find variable with given name 'n'. If it is an upvalue, add this upvalue into all intermediate functions. */ static int singlevaraux (FuncState *fs, TString *n, expdesc *var) { if (fs == NULL) /* no more levels? */ return VVOID; /* default is global */ else { LexState *ls = fs->ls; int v = searchvar(fs, n); /* look up locals at current level */ if (v >= 0) { /* found? */ init_exp(var, VLOCAL, v); /* variable is local */ return VLOCAL; } else { /* not found as local at current level; try upvalues */ if (ls->t.token != '(') { new_localvar(ls, n); init_exp(var, VLOCAL, fs->nlocvars - 1); /* variable is local */ return VLOCAL; } int idx = searchupvalue(fs, n); /* try existing upvalues */ if (idx < 0) { /* not found? */ if (singlevaraux(fs->prev, n, var) == VVOID) /* try upper levels */ return VVOID; /* not found; is a global */ /* else was LOCAL or UPVAL */ idx = newupvalue(fs, n, var); /* will be a new upvalue */ } init_exp(var, VUPVAL, idx); return VUPVAL; } } }
/* Find variable with given name 'n'. If it is an upvalue, add this upvalue into all intermediate functions. */ static int singlevaraux(FuncState *fs, TString *n, expdesc *var, int base) { if (fs == NULL) /* no more levels? */ return VVOID; /* default is global */ else { int v = searchvar(fs, n); /* look up locals at current level */ if (v >= 0) /* found? */ { init_exp(var, VLOCAL, v); /* variable is local */ if (!base) markupval(fs, v); /* local will be used as an upval */ return VLOCAL; } else /* not found as local at current level; try upvalues */ { int idx = searchupvalue(fs, n); /* try existing upvalues */ if (idx < 0) /* not found? */ { if (singlevaraux(fs->prev, n, var, 0) == VVOID) /* try upper levels */ return VVOID; /* not found; is a global */ /* else was LOCAL or UPVAL */ idx = newupvalue(fs, n, var); /* will be a new upvalue */ } init_exp(var, VUPVAL, idx); return VUPVAL; } } }
/*! \fn ReplaceVarInString(const string&,const string &varname,string &dest, const string& by) */ void ReplaceVarInString(const string&src ,const string &varname, string &dest, const string& by) { string searchvar("%["); searchvar+=varname; searchvar+="]"; dest = src; size_t pos = dest.find(searchvar); while (pos != dest.npos) { dest.replace(pos, searchvar.size(), by); pos = dest.find(searchvar, pos); } }
static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) { if (fs == NULL) /* no more levels? */ init_exp(var, VGLOBAL, NO_REG); /* default is global variable */ else { int v = searchvar(fs, n); /* look up at current level */ if (v >= 0) { init_exp(var, VLOCAL, v); if (!base) markupval(fs, v); /* local will be used as an upval */ } else { /* not found at current level; try upper one */ singlevaraux(fs->prev, n, var, 0); if (var->k == VGLOBAL) { if (base) var->info = luaK_stringK(fs, n); /* info points to global name */ } else { /* LOCAL or UPVAL */ var->info = indexupvalue(fs, n, var); var->k = VUPVAL; /* upvalue in this level */ } } } }
void do_hexdump (void) { char name[16]; unsigned char *p,*end; int i=0,j; ULONG count=0; header *hd; scan_space(); scan_name(name); if (error) return; hd=searchvar(name); if (!hd) hd=searchudf(name); if (error || hd==0) return; p=(unsigned char *)hd; end=p+hd->size; output1("\n%5lx ",count); while (p<end) { hex_out(*p++); i++; count++; if (i>=16) { i=0; string_out(p-16); output1("\n%5lx ",count); if (test_key()==escape) break; } } for (j=i; j<16; j++) output(" "); string_out(p-i); output("\n"); }
void ImportName(char* name) { FILE* infile; union { PE_HEADER pe; OBJECT_ENTRY obj; }; unsigned long temp; unsigned long export_; //секция с експортом unsigned long numobj; //число объектов unsigned long posdll; //позиция секции в файле unsigned long nameadr; //таблица адресов имен unsigned long startname; //начало имени unsigned long ordinallist, ordinalbase; unsigned int i, j; DLLLIST* newdll; APIPROC* listapi; if ((infile = fopen(name, "rb")) == NULL) { ErrOpenFile(name); return; } fseek(infile, 0x3C, SEEK_SET); if (fread(&temp, 4, 1, infile) != 1) { errread: fprintf(stderr, "Unable to read from file %s.\n", name); fclose(infile); return; } fseek(infile, 0, SEEK_END); if ((unsigned long)ftell(infile) <= temp) { fprintf(stderr, "Bad file %s.\n", name); fclose(infile); return; } fseek(infile, temp, SEEK_SET); if (fread(&pe, sizeof(PE_HEADER), 1, infile) != 1) { goto errread; } if (pe.sign != ('P' + ('E' << 8))) { fprintf(stderr, "For DLL support only format PE.\n"); fclose(infile); return; } if ((export_ = pe.exportRVA) == 0) { fprintf(stderr, "No export directory on %s.\n", name); fclose(infile); return; } numobj = pe.numobj; temp = pe.objAlig; while (numobj != 0) { if (fread(&obj, sizeof(OBJECT_ENTRY), 1, infile) != 1) { goto errread; } if ((obj.sectionRVA + Align(obj.psize, temp)) > export_) { break; } numobj--; } if (numobj == 0) { fprintf(stderr, "Bad object table in %s.\n", name); fclose(infile); return; } posdll = obj.pOffset + export_ - obj.sectionRVA; fseek(infile, posdll + 24, SEEK_SET); if (fread(&numobj, 4, 1, infile) != 1) { goto errread; } fseek(infile, posdll + 32, SEEK_SET); if (fread(&nameadr, 4, 1, infile) != 1) { goto errread; } if (fread(&ordinallist, 4, 1, infile) != 1) { goto errread; } nameadr -= export_; ordinallist -= export_; fseek(infile, posdll + 12, SEEK_SET); if (fread(&startname, 4, 1, infile) != 1) { goto errread; } if (fread(&ordinalbase, 4, 1, infile) != 1) { goto errread; } fseek(infile, posdll + startname - export_, SEEK_SET); j = 0; do { if (fread(&string[j], 1, 1, infile) != 1) { goto errread; } } while (string[j++] != 0); //имя библиотеки newdll = FindDLL(); listapi = newdll->list; for (i = 0; i < numobj; i++) { fseek(infile, posdll + nameadr, SEEK_SET); if (fread(&startname, 4, 1, infile) != 1) { goto errread; } fseek(infile, posdll + startname - export_, SEEK_SET); itok.size = -1; j = 0; unsigned char c; do { if (fread(&c, 1, 1, infile) != 1) { goto errread; } if (c == '@') { itok.name[j] = 0; break; } itok.name[j] = c; j++; } while (j <= IDLENGTH && c != 0); if (c == '@') { j = 0; do { if (fread(&c, 1, 1, infile) != 1) { goto errread; } string[j++] = c; } while (isdigit(c)); itok.size = getnumber(string); } tok = tk_id; searchvar(itok.name); if (tok == tk_id) { fseek(infile, posdll + ordinallist, SEEK_SET); itok.sib = 0; if (fread(&itok.sib, 2, 1, infile) != 1) { goto errread; } itok.sib += ordinalbase; tok = tk_apiproc; itok.number = secondcallnum++; itok.segm = NOT_DYNAMIC; string[0] = 0; if (newdll->num == 0) { listapi = (APIPROC*)MALLOC(sizeof(APIPROC)); //первая в списке } else { listapi = (APIPROC*)REALLOC(listapi, sizeof(APIPROC) * (newdll->num + 1)); } (listapi + newdll->num)->recapi = addtotree(itok.name); newdll->num++; } nameadr += 4; ordinallist += 2; } newdll->list = listapi; fclose(infile); }