Nmap Development mailing list archives
Re: [NSE][PATCH] string.to_hex() function
From: "Patrick Donnelly" <batrick.donnelly () gmail com>
Date: Wed, 10 Sep 2008 12:11:46 -0600
Hi Sven, On Wed, Sep 10, 2008 at 8:25 AM, Sven Klemm <sven () c3d2 de> wrote:
Hi everyone, I've written a to_hex() function for the lua string class. string.to_hex(string, separator = "", group_length = 1) separator and group_length are optional. Separator will be added to the string after each byte or after group_length bytes when group_length is passed. Here are a few examples: ("abc"):to_hex() => "616263" ("abc"):to_hex(":") => "61:62:63" ("abc"):to_hex(":",2) => "6162:63" I think this function is extremely useful for any script that wants to display hexencoded data as this function would be available on every string. But I am not sure myself whether it is the best way to add this functionality. Do you think this function should be added to string or are there better ways to implement this. The main reason for this patch is so we don't have to implement a hash_raw() and a hash_hex() function for every hashing algorithm but the function is surely useful in a lot of other places too.
This function is best not added directly to the string library. We could add an auxiliary string library (that's done elsewhere, e.g. [1]) for these useful string functions. I would even advocate having it be a super class of the current string library (so strings may index it), that is, <code>setmetatable(string, {__index = ourlibrary})</code>. As for the function itself, this could easily be done in Lua directly (and would most likely be faster). Most Lua functions in C should only be written if there is a clear speed advantage or the function must access a C construct or API. Please see [2] for an example similar to what you've done. [1] http://lua-users.org/wiki/StringRecipes These are Lua functions for string manipulation but are often included in extension string libraries. [2] http://seclists.org/nmap-dev/2008/q3/0688.html Cheers, -- -Patrick Donnelly "One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say." -Will Durant _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- [NSE][PATCH] string.to_hex() function Sven Klemm (Sep 10)
- Re: [NSE][PATCH] string.to_hex() function Patrick Donnelly (Sep 10)