//------------------------------------------------ //--- 010 Editor v5.0.1 Script File // // File: URLDecoder.1sc // Authors: N0VA8o // E-mail: N0VA8o.lau@gmail.com // Version: 1.1 // Purpose: Convert %xx in a URL to a char. Eg. AAA%3DCCC => AAA=CCC. // Category: Internet // History: // 1.1 2016-02-10 SweetScape Software: Updated header for repository submission. // 1.0 N0VA8o: Initial release. //------------------------------------------------ const int entire_always = 0; // 1: do for entire file always, 0: if no selection const string title = "URL Decoder"; int64 adr, siz, out; int actfile, newfile; char tmp, tmp1; char byte_tmp, bh, bl; if (FileCount() == 0) { MessageBox(idOk, title, "No file is open."); return -1; } if ((entire_always != 0) | (GetSelSize() <= 0)) { adr = 0; siz = FileSize(); } else { adr = GetSelStart(); siz = GetSelSize(); } if (siz == 0) { MessageBox(idOk, title, "No bytes to process."); return -1; } actfile = GetFileNum(); newfile = FileNew(); FileSelect(actfile); out = 0; int index = adr; while( index <= adr + siz-1) { FileSelect(actfile); tmp = ReadByte(index); FileSelect(newfile); if (tmp == '%') { if (index +2 <= adr + siz -1) { FileSelect(actfile); bh = ToUpper(ReadByte(index+1)); tmp1 = bh; if (bh <='9' && bh >='0') { bh = bh-'0'; } else if( bh <='F' && bh >= 'A') { bh = bh - 'A' + 0xA; } else { Printf("\"%c\" is not a hex char, ignore!\n", bh); FileSelect(newfile); WriteByte(out, tmp); out++; index ++; continue; } bl = ToUpper(ReadByte(index+2)); if (bl <='9' && bl >='0') { bl = bl-'0'; } else if( bl <='F' && bl >= 'A') { bl = bl - 'A' + 0xA; } else { Printf("\"%c\" is not a hex char, ignore!\n", bl); FileSelect(newfile); WriteByte(out, tmp); out++; WriteByte(out, tmp1); out++; index +=2; continue; } byte_tmp = (((bh & 0xF)<< 4) &0xFF) | (bl & 0xF); FileSelect(newfile); WriteByte(out, byte_tmp); out++; index +=3; } else { Printf("Incomplete length, ignore it PosSel:%d\n", index); WriteByte(out, tmp); out++; index++; } } else { WriteByte(out,tmp); out++; index++; } } FileSelect(newfile); SetCursorPos(FileSize());