View previous topic :: View next topic |
Author |
Message |
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Sun Nov 06, 2016 6:52 pm Post subject: stringToMD5String zero terminated the string? |
|
|
Is it a expected result?
Code: |
local xxx,zero = 'xxx',string.char(0)
local a = xxx..xxx
local b = xxx..zero..xxx
local c = xxx
print(stringToMD5String(a))
print(stringToMD5String(b))
print(stringToMD5String(c))
-- output
dad3a37aa9d50688b5157698acfd7aee
f561aaf6ef0bf14d4208bb46a4ccb3ad
f561aaf6ef0bf14d4208bb46a4ccb3ad
|
md5memory and md5file don't zero terminated its content.
thanks~
_________________
- Retarded. |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Nov 06, 2016 9:22 pm Post subject: |
|
|
There are other things, for example we can not use
Code: | writeString( addr , str..string.char(0) ) |
I have to use this:
Code: | writeString( addr , str )
writeBytes( addr+#str, 0 ) |
yes, md5 should be:
Code: | -- output
dad3a37aa9d50688b5157698acfd7aee
efe8c109e39c79ef313df9f549e5572a
f561aaf6ef0bf14d4208bb46a4ccb3ad |
This is because DB uses this:
Code: | function lua_stringToMD5String(L:PLua_State): integer; cdecl;
var s: string;
begin
if lua_gettop(L)=1 then
begin
s:=Lua_ToString(L,1); // at this line source string is cut on first zero byte
lua_pushstring(L, MD5Print(MD5String(s)));
result:=1;
end
else
result:=0;
end; |
instead of
Code: | function lua_stringToMD5String(L:PLua_State): integer; cdecl;
var msg: pchar;
size: integer;
begin
if lua_gettop(L)=1 then
begin
msg:=lua_tolstring(L, 1, @size);
lua_pushstring(L, MD5Print(MD5Buffer(msg^,size)));
result:=1;
end
else
result:=0;
end; |
_________________
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Mon Nov 07, 2016 1:01 am Post subject: |
|
|
I see.
Can we have version of c function for writeString,readString,stringToMD5String etc that treat Lua string not as zero terminated string? eg.
writeByteString(addr, string) ------ don't need widechar version
readByteString(addr, requestedStringLengthNotMaxLength)
md5string(string)
so that existed functions are stay compatible.
bye~
_________________
- Retarded. |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Mon Nov 07, 2016 4:23 am Post subject: |
|
|
stringToMD5String, I can add fixed version to my custom build.
About writeByteString, we can use something like this:
Code: | bt = stringToByteTable('xxx'..string.char(0)..'xxx')
-- bt = wideStringToByteTable('xxx'..string.char(0)..'xxx')
writeBytes(addr,bt) |
readByteString:
Code: | bt = readBytes(addr, size, true)
str = byteTableToString(bt)
-- str = byteTableToWideString(bt) |
_________________
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Mon Nov 07, 2016 4:48 am Post subject: |
|
|
Thank you! read/write work and faster than convert by Lua.
_________________
- Retarded. |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 54
Joined: 01 Oct 2008 Posts: 941
|
Posted: Sun Nov 13, 2016 9:31 am Post subject: |
|
|
Thank you, I make a folder copy of standard ce 6.6 and extract over, it work as expected.
_________________
- Retarded. |
|
Back to top |
|
|
|