Difference between revisions of "Snippets"
m (→Random hash generator) |
|||
Line 39: | Line 39: | ||
return holder; | return holder; | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | |||
+ | == memory Write String == | ||
+ | '''memoryWriteString(proc, address, msg)''' | ||
+ | |||
+ | '''memoryWriteString()''' | ||
+ | |||
+ | |||
+ | '''Description: ''' | ||
+ | Enters a string into memory. | ||
+ | |||
+ | '''Purpose: ''' | ||
+ | So strings can be written. Be sure not to write a string that's greater than the strings allocated memory. | ||
+ | |||
+ | '''License: ''' Public Domain | ||
+ | |||
+ | '''Author: ''' "zerosignal" | ||
+ | |||
+ | <source lang="lua"> | ||
+ | function memoryWriteString(proc, address, msg) | ||
+ | local l_msg_len = msg:len() | ||
+ | local l_char = nil; | ||
+ | for i=0, (l_msg_len-1) do | ||
+ | l_char = msg:byte(i) | ||
+ | --debug_message("char: " .. l_char); | ||
+ | memoryWriteByte(proc, address + i, l_char) | ||
+ | end | ||
+ | memoryWriteByte(proc, address + l_msg_len, 0) | ||
end | end | ||
</source> | </source> |
Revision as of 09:12, 18 July 2008
Note:
Code posted here is considered Public Domain unless otherwise noted. Be aware of this before posting your code! You may release your code here only under the following licenses: Public Domain, BSD, GPL, or LGPL.
Random hash generator
random_hash(len)
random_hash()
Description:
Generates a random filled hash containing numbers and (capitol) letters. It will generate and return a hash that is 'len' characters long. If 'len' is not specified, then a 32 character hash will be assumed.
Purpose: Random hashes are, often, used in place of passwords. It is considered more secure than storing a reversible hash simply because it cannot be reversed (as it contains no real information). For example, after a successful login, a server might generate a random hash for that specific user. The client (user) will now use the random hash for future authentication instead of the password.
License: Public Domain
Author: "Elverion"
-- Generates a random hash with the specified length.
-- If length is less than or equal to zero, or unspecified, 32 bytes will be assumed.
function random_hash(len)
if( len == nil or len <= 0 ) then len = 32; end;
local holder = ""; -- a string for holding our hash temporarily
-- create an array of all acceptable characters that can be put in our hash.
local hash_chars = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E",
"F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"};
for i = 1, len do
local index = math.random(1, #hash_chars);
holder = holder .. hash_chars[index];
end
return holder;
end
memory Write String
memoryWriteString(proc, address, msg)
memoryWriteString()
Description:
Enters a string into memory.
Purpose: So strings can be written. Be sure not to write a string that's greater than the strings allocated memory.
License: Public Domain
Author: "zerosignal"
function memoryWriteString(proc, address, msg)
local l_msg_len = msg:len()
local l_char = nil;
for i=0, (l_msg_len-1) do
l_char = msg:byte(i)
--debug_message("char: " .. l_char);
memoryWriteByte(proc, address + i, l_char)
end
memoryWriteByte(proc, address + l_msg_len, 0)
end