Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Auto Assembler - Unicode

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Hatschi
Master Cheater
Reputation: 2

Joined: 28 Jan 2010
Posts: 327

PostPosted: Thu Apr 13, 2017 6:21 pm    Post subject: Auto Assembler - Unicode Reply with quote

The following line will write the string "money". How can I write this string in uncode without using byte array?

Code:
db 'money' //equal to db 6D 6F 6E 65 79'


Unicode:
Code:
db ??? //equal to db 6D 00 6F 00 6E 00 65 00 79
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Thu Apr 13, 2017 6:36 pm    Post subject: Reply with quote

99% sure you'd just use

Code:
dw 'money'
so that each value is written using 2 bytes, or dd for 4 bytes, though you may also want a terminating 0 depending on how it's used.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Thu Apr 13, 2017 8:12 pm    Post subject: Reply with quote

...(oops, edited ;p )

CE have functions to convert wideString (utf8->utf16?).
The following custom function make use of them to convert a possible wideString to aob format so that it can be db-ize (also add zero terminate option and prefix size option, ie. mono string)
Code:

function wideStr2Aob(s, zeroTerminate, prefixSize)
  local b = assert(wideStringToByteTable(s),"Can't convert WideStr2Aob")
  if prefixSize then
    local sz = math.floor(#b/2)
    for c in string.pack(">I4",sz):gmatch"." do
      table.insert(b,1,c:byte())
    end
  end
  if zeroTerminate then b[#b+1],b[#b+2] = 0,0 end
  return byteTableToString(b):gsub(".",
    function(c)return string.format(" %02X",c:byte())end):sub(2)
end


Usage, in AA:
Code:

SomeAddress:   
{$lua}
return "db "..wideStr2Aob([[Дракон]],true, true) -- Russian 'dragon'
{$asm}

will write bytes
06 00 00 00 14 04 40 04 30 04 3A 04 3E 04 3D 04 00 00
on SomeAddress.

_________________
- Retarded.
Back to top
View user's profile Send private message
Hatschi
Master Cheater
Reputation: 2

Joined: 28 Jan 2010
Posts: 327

PostPosted: Fri Apr 14, 2017 3:55 am    Post subject: Reply with quote

Amazing, thank you very much!
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Fri Apr 14, 2017 12:18 pm    Post subject: Reply with quote

panraven wrote:
The following custom function make use of them to convert a possible wideString to aob format

Nice, thanks for that! Gives some "advanced" things in lua for me to learn about (and obviously superior to my suggestion) Smile

Though I do have to ask something semi-related. Is there any way to get CE's "Text"/String type to read the length from memory instead of having to give it a length (or even use terminating 0s to find the length)? I haven't really needed to so I can understand if there isn't, just curious.

edit: is the string.pack... because dwordToByteTable would use a signed 4 byte conversion (as unlikely as a string being long enough for that to matter is)? Or is there another reason I'm not seeing?

edit2: Actually since it gets "reversed" from 0,0,0,6 to 6,0,0,0 wouldn't large strings (more than 255 in length) actually cause problems with this method?
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Sat Apr 15, 2017 2:32 am    Post subject: Reply with quote

Not sure I get what ' give it a length' means.

If it is about the Lua function
Code:
readString(address, maxlength, widechar OPTIONAL) : Reads a string till it encounters a 0-terminator. Maxlength is just so you won't freeze for too long, set to 6000 if you don't care too much. Set WideChar to true if it is encoded using a widechar formatting


to get the string from a known address.
If we know the usage of the string ( eg a item-string-id should not be too long?, unless we are ripping someone's cetrainer Smile ), a reasonable maxlength should be enough?


If it is about scanning, I guess it depend on how the game (target process) define a 'string', c style zero terminate (ascii/unicode) string or some structure like mono-string (should be always unicode?):
ie.
length (prefixSize) is 4byte at +08(32bit)/+10 (64bit) from the 'string' base, and
characters start at +0c/+14.
(I know little beside this 2 type of string)

But we usually scan for a known string (and known unicode or not), and don't care about the length, or zero terminate or structural ?

I can only think of using the known prefixSize in mono string type that differential a certain string IN GAME (with prefixSize) and IN ASSEMBLY (without prefixSize?) in an aob scanning. (But same I've not ever do such thing)


@edit:
the dwordToByteTable is littleEndian and may need a variable to use in a for loop, using string.pack with bigEndian + gmatch seems handy to do reversing. I actually see the bytes get reversed then I add the ">".
ie. ">" -> big endian in packing, "<"->little endian

@edit2:
This is output of a long string with prefixSize, seems no problem?
AF 01 00 00 66 00 75 00 6E 00 63 ...

_________________
- Retarded.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sat Apr 15, 2017 11:52 am    Post subject: Reply with quote

@panraven, I meant in the address list more than anything else eg.



edits: ok, yeah that makes sense. Thanks for your time!

You should be able to use this though (tested)
Code:
    for k,v in ipairs(dwordToByteTable(sz)) do
      table.insert(b,k,v)
    end

Seems a lot more obvious to me Smile
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Sat Apr 15, 2017 5:49 pm    Post subject: Reply with quote

FreeER wrote:
...
You should be able to use this though (tested)
Code:
    for k,v in ipairs(dwordToByteTable(sz)) do
      table.insert(b,k,v)
    end

Seems a lot more obvious to me Smile


oh, yes, using ipairs and dwordToByteTable is compatible on ce 6.4, thank the reminder.

_________________
- Retarded.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites