Raised This Month: $12 Target: $400
 3% 

Want for urldecode method, need help with rewrite from C


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 01-10-2021 , 09:03   Want for urldecode method, need help with rewrite from C
Reply With Quote #1

Code:
https://github.com/abejfehr/URLDecode/blob/master/urldecode.c
Need help in written same code in SM. Thx. I use sockets which not provided UTF-8 decoding

Last edited by ZASTRELIS; 01-11-2021 at 05:11. Reason: UTF-8 URLEncoded
ZASTRELIS is offline
ZASTRELIS
Veteran Member
Join Date: Nov 2010
Location: Siberia, Irkutsk
Old 01-10-2021 , 09:37   Re: Want for urldecode method, need help with rewrite from C
Reply With Quote #2

I've something like this.. that all which can I do ))

Code:
stock void decodeURL(const char[] inStr, char[] outStr, int size) {         char buffer[4096]; int len = strlen(inStr); int wpos = 0; int diff = 0;         // "%D0%BF%D1%80%D0%BE%D1%81%D1%82%D0%BE+%D0%BF%D0%B0%D1%80%D0%B0%D0%BB%D0%BB%D0%B5%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9+%D0%BC%D0%B8%D1%80" = len         for(int i = 0; i < len; i += diff)     {         special[4]; strcopy(special, sizeof(special), inStr[i]);         chars[6]; strcopy(chars, sizeof(chars), inStr[i]);             for(int j = 0; j < sizeof(dec); ++j)         {             if(StrEqual(special, dec[j][1], false))             {                 strcopy(outStr, size, inStr[wpos]); ++wpos; diff = 4;             }                         else if(StrEqual(chars, dec[j][1], false))             {                 strcopy(outStr, size, inStr[wpos]); ++wpos;  diff = 6;             }         }     }         PrintToServer("Decoded URL: %s", outStr); }

And some characters table..
Code:
static char dec[][] = {     {"~", "%7E"},     {"`", "60%"},     {"'", "27%"},         /* ....... */     {"Ю", "%D0%A%"},     {"ю", "%D1%8%"},     {"Я", "%D0%A%"},     {"я", "%D1%8F"} };

Last edited by DarkDeviL; 01-23-2021 at 22:15. Reason: Restore to previous version.
ZASTRELIS is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-21-2021 , 18:23   Re: Want for urldecode method, need help with rewrite from C
Reply With Quote #3

....I don't know.
I maybe made it too complex. Have a fun.

resultss
Code:
char buffer[] = "https%3A%2F%2Fwww.google.ca%2F%3Fgws_rd%3Dssl%23q%3Durl%2Bdecoding";
PrintToServer "httpsAFFwww.google.caFFgws_rdDsslqDurlBdecoding"
PrintToServer "https://www.google.ca/?gws_rd=ssl#q=url+decoding"

PHP Code:
#include <regex>

Regex regex;

public 
void OnPluginStart()
{
    
regex = new Regex("^%[0-9a-fA-F]{2}");

    if(
regex == nullSetFailState("Regex fail");

    
RegConsoleCmd("sm_test"test);

}

public 
Action test(int clientint args)
{

    
char buffer[] = "https%3A%2F%2Fwww.google.ca%2F%3Fgws_rd%3Dssl%23q%3Durl%2Bdecoding";

    
char buffer2[PLATFORM_MAX_PATH];

    
PrintToServer(buffer); // ...you not see '%' symbols in console, function is formatting it.

    
int index 0;
    
int result;


    do
    {

        
result FindCharInString(buffer[index], '%'false);

        if(
result == -1) break;

        
index += result;

        
//PrintToServer("%s", buffer[index]);


        // found something like %3A
        
if(isxdigit(buffer[index]))
        {
            
// Change characters to hex value
            
char a[4]; // %3A
            
char b[2]; // new character

            
Format(asizeof(a), "%c%c%c"buffer[index], buffer[index+1], buffer[index+2]);

            
Format(bsizeof(b), "%c"StringToInt(a[1], 16)); // exclude %

            //PrintToServer("%s", b);

            
ReplaceString(buffersizeof(buffer), abtrue);
            
            
index = -1// reset loop

        
}



        
index++;

    }
    while( 
index strlen(buffer))
    

    
// Final
    
PrintToServer("%s"buffer);

}


bool isxdigit(const char[] x)
{
    
char a[4]; // %3A
    
Format(asizeof(a), "%c%c%c"x[0], x[1], x[2]);

    
//PrintToServer("%s", a);

    
return regex.Match(a) > 0;

__________________
Do not Private Message @me
Bacardi is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-22-2021 , 05:42   Re: Want for urldecode method, need help with rewrite from C
Reply With Quote #4

Code:
PrintToServer(buffer); // ...you not see '%' symbols in console, function is formatting it.
This is dangerous, the correct usage is:

Code:
PrintToServer("%s", buffer);
__________________
asherkin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-22-2021 , 06:01   Re: Want for urldecode method, need help with rewrite from C
Reply With Quote #5

Ok, roger.
Bacardi is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 05-06-2021 , 14:17   Re: Want for urldecode method, need help with rewrite from C
Reply With Quote #6

I'm late but there are 2 natives provided by System2 Extension.
Code:
/**
 * Converts a plain string to an URL encoded string.
 * All input characters that are not a-z, A-Z, 0-9, '-', '.', '_' or '~' 
 * are converted to their "URL escaped" version (%NN where NN is a two-digit hexadecimal number).
 *
 * Be aware that the output string may be larger then the input string.
 *
 * @param output        Buffer to store encoded string in. May point to the input string (will replace the input string).
 * @param maxlength     Maxlength of the output buffer.
 * @param input         String to encode.
 * @param ...           Input string format arguments
 *
 * @return              True on success, false otherwise.
 */
native bool System2_URLEncode(char[] output, int maxlength, const char[] input, any ...);

/**
 * Converts an URL encoded string to a plain string.
 * All input characters that are URL encoded (%XX where XX is a two-digit hexadecimal number) are converted to their binary versions.
 *
 * @param output        Buffer to store decoded string in. May point to the input string (will replace the input string).
 * @param maxlength     Maxlength of the output buffer.
 * @param input         String to decode.
 * @param ...           Input string format arguments
 *
 * @return              True on success, false otherwise.
 */
native bool System2_URLDecode(char[] output, int maxlength, const char[] input, any ...);
__________________
MAGNAT2645 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode