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 


convert a value from little-endian to big-endian
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials
View previous topic :: View next topic  
Author Message
OldCheatEngineUser
Whateven rank
Reputation: 9

Joined: 01 Feb 2016
Posts: 867

PostPosted: Wed Jan 24, 2018 4:31 pm    Post subject: convert a value from little-endian to big-endian Reply with quote

bswap & xchg
Code:
{
Author: OldCheatEngineUser
Website: forum.cheatengine.org
About: convert little-endian values to big-endian values
Attention: must be injected in a 32-bit process, to stop the execution of the thread move '0' into "convert"
ExtraInfo: supports 2byte - 4byte - 8byte / float - double data-types
}

[enable]

globalalloc(convert,$1D)
registersymbol(dwLilEndian)
registersymbol(dwBigEndian)
registersymbol(ddLilEndian)
registersymbol(ddBigEndian)
registersymbol(dqLilEndian)
registersymbol(dqBigEndian)

alloc(byteswap,$5B)
registersymbol(byteswap)
createthread(byteswap)

label(code)
label(data)

byteswap:
push 03E8
call kernel32.Sleep
mov cl, 02
cmp byte ptr [convert],00
jnz code
ret

code:
mov dx, [dwLilEndian]
xchg dh, dl
mov [dwBigEndian], dx
xor edx, edx
mov edx, [ddLilEndian]
bswap edx
mov [ddBigEndian], edx
xor edx, edx
mov edx, [dqLilEndian]
bswap edx
mov [dqBigEndian+04], edx
mov edx, [dqLilEndian+04]
bswap edx
mov [dqBigEndian], edx
loop byteswap

data:
convert:
db 01 // add convert as an address and choose data-type BYTE
dwLilEndian:
dw 0 // add dwLilEndian as an address and choose data-type 2-BYTE
dwBigEndian:
dw 0 // add dwBigEndian as an address and choose data-type 2-BYTE
ddLilEndian:
dd 0 // add ddLilEndian as an address and choose data-type 4-BYTE or FLOAT
ddBigEndian:
dd 0 // add ddBigEndian as an address and choose data-type 4-BYTE or FLOAT
dqLilEndian:
dq 0 // add dqLilEndian as an address and choose data-type 8-BYTE or DOUBLE
dqBigEndian:
dq 0 // add dqBigEndian as an address and choose data-type 8-BYTE or DOUBLE

[disable]

unregistersymbol(dwLilEndian)
unregistersymbol(dwBigEndian)
unregistersymbol(ddLilEndian)
unregistersymbol(ddBigEndian)
unregistersymbol(dqLilEndian)
unregistersymbol(dqBigEndian)

unregistersymbol(byteswap)

dealloc(byteswap)


hardcore
Code:
{
Author: OldCheatEngineUser
Website: forum.cheatengine.org
About: convert little-endian values to big-endian values
Attention: must be injected in a 32-bit process, to stop the execution of the thread move '0' into "convert"
ExtraInfo: supports 2byte - 4byte - 8byte / float - double data-types
}

[enable]

globalalloc(convert,$1D)
registersymbol(dwLilEndian)
registersymbol(dwBigEndian)
registersymbol(ddLilEndian)
registersymbol(ddBigEndian)
registersymbol(dqLilEndian)
registersymbol(dqBigEndian)

alloc(byteswap,$75)
registersymbol(byteswap)
createthread(byteswap)

label(code)
label(data)

byteswap:
push 03E8
call kernel32.Sleep
mov cl, 10
cmp byte ptr [convert],00
jnz code
ret

code:
mov ax, [dwLilEndian]
mov dh, al
mov dl, ah
mov [dwBigEndian], dx
mov eax, [ddLilEndian]
mov dh, al
mov dl, ah
ror edx, cl
rol eax, cl
mov dh, al
mov dl, ah
mov [ddBigEndian], edx
mov eax, [dqLilEndian]
mov dh, al
mov dl, ah
ror edx, cl
rol eax, cl
mov dh, al
mov dl, ah
mov [dqBigEndian+04], edx
mov eax, [dqLilEndian+04]
mov dh, al
mov dl, ah
ror edx, cl
rol eax, cl
mov dh, al
mov dl, ah
mov [dqBigEndian], edx
loop byteswap

data:
convert:
db 01 // add convert as an address and choose data-type BYTE
dwLilEndian:
dw 0 // add dwLilEndian as an address and choose data-type 2-BYTE
dwBigEndian:
dw 0 // add dwBigEndian as an address and choose data-type 2-BYTE
ddLilEndian:
dd 0 // add ddLilEndian as an address and choose data-type 4-BYTE or FLOAT
ddBigEndian:
dd 0 // add ddBigEndian as an address and choose data-type 4-BYTE or FLOAT
dqLilEndian:
dq 0 // add dqLilEndian as an address and choose data-type 8-BYTE or DOUBLE
dqBigEndian:
dq 0 // add dqBigEndian as an address and choose data-type 8-BYTE or DOUBLE

[disable]

unregistersymbol(dwLilEndian)
unregistersymbol(dwBigEndian)
unregistersymbol(ddLilEndian)
unregistersymbol(ddBigEndian)
unregistersymbol(dqLilEndian)
unregistersymbol(dqBigEndian)

unregistersymbol(byteswap)

dealloc(byteswap)

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Memory Hacker


Last edited by OldCheatEngineUser on Sun Jan 28, 2018 4:39 pm; edited 6 times in total
Back to top
View user's profile Send private message Visit poster's website
OldCheatEngineUser
Whateven rank
Reputation: 9

Joined: 01 Feb 2016
Posts: 867

PostPosted: Thu Jan 25, 2018 8:36 am    Post subject: Reply with quote

update:
- 2byte conversion

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Memory Hacker
Back to top
View user's profile Send private message Visit poster's website
OldCheatEngineUser
Whateven rank
Reputation: 9

Joined: 01 Feb 2016
Posts: 867

PostPosted: Fri Jan 26, 2018 3:24 pm    Post subject: Reply with quote

update:
- 8byte and double conversion

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Memory Hacker
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater
Reputation: 30

Joined: 09 Aug 2013
Posts: 718

PostPosted: Fri Jan 26, 2018 6:01 pm    Post subject: Reply with quote

Hm... as you add more of those change if you don't want globalalloc things... you might want to consider something like this so that it's just a matter of saying "change this line"

(disclaimer: I didn't really look at the code itself)

Code:
{$lua}
useGlobalAlloc = not true -- <-------------------------- change this line :)
function doAllocCommand(parameters, syntaxcheck)
  local name, size = parameters:match('(%a+),(.+)') -- assumes correct parameters lol
  if useGlobalAlloc then
    result = ('globalalloc(name,size)'):gsub('name',name):gsub('size',size)
  else
    result = ('alloc(name,size)\nregisterSymbol(name)'):gsub('name',name):gsub('size',size)
  end
  --print(result:gsub('\n','\r\n'))
  return result
end
-- doesn't seem to mind it being done multiple times
-- at least with a string name refering to a global function
registerAutoAssemblerCommand('doalloc', 'doAllocCommand')
{$asm}

{
Author: OldCheatEngineUser
Website: forum.cheatengine.org
About: convert little-endian values to big-endian values
Attention: must be injected in a 32-bit process, to stop the execution of the thread move '0' into "convert"
ExtraInfo: supports 2byte - 4byte - 8byte / float - double data-types
}

[enable]
doalloc(convert,$10)
doalloc(dwLilEndian,$10)
doalloc(dwBigEndian,$10)
doalloc(ddLilEndian,$10)
doalloc(ddBigEndian,$10)
doalloc(dqLilEndian,$10)
doalloc(dqBigEndian,$10)

doalloc(byteswap,$100)
createthread(byteswap)

label(code)
label(data)

byteswap:
push 03E8
call kernel32.Sleep
mov cl, 08
cmp byte ptr [convert],00
jnz code
ret

code:
mov dx, [dwLilEndian]
xchg dh, dl
mov [dwBigEndian], dx
xor edx, edx
mov edx, [ddLilEndian]
bswap edx
mov [ddBigEndian], edx
xor edx, edx
mov edx, [dqLilEndian]
ror edx, cl
mov [dqBigEndian+04], edx
mov edx, [dqLilEndian+04]
ror edx, cl
mov [dqBigEndian], edx
loop byteswap

data:
convert:
db 01 // add convert as an address and choose data-type BYTE
dwLilEndian:
dw 0 // add dwLilEndian as an address and choose data-type 2-BYTE
dwBigEndian:
dw 0 // add dwBigEndian as an address and choose data-type 2-BYTE
ddLilEndian:
dd 0 // add ddLilEndian as an address and choose data-type 4-BYTE or FLOAT
ddBigEndian:
dd 0 // add ddBigEndian as an address and choose data-type 4-BYTE or FLOAT
dqLilEndian:
dq 0 // add dqLilEndian as an address and choose data-type 8-BYTE or DOUBLE
dqBigEndian:
dq 0 // add dqBigEndian as an address and choose data-type 8-BYTE or DOUBLE

[disable]
{$lua}
if not useGlobalAlloc then
  local names = {'convert', 'dwLilEndian', 'dwBigEndian', 'ddLilEndian', 'ddBigEndian', 'dqLilEndian', 'dqBigEndian', 'byteswap'}
  local res = ''
  for _,name in ipairs(names) do res = res .. ('unregisterSymbol(%s)\ndealloc(%s)\n'):format(name,name) end
  return res
end
{$asm}
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 9

Joined: 01 Feb 2016
Posts: 867

PostPosted: Fri Jan 26, 2018 6:07 pm    Post subject: Reply with quote

me: happy with globalalloc

else: they can use alloc or your code

thanks anyways.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Memory Hacker
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater
Reputation: 30

Joined: 09 Aug 2013
Posts: 718

PostPosted: Fri Jan 26, 2018 6:30 pm    Post subject: Reply with quote

Yeah, I'd have just used globalalloc myself with a single comment to change it to alloc/register+dealloc/unregister if they wanted (anyone who actually understands why they might want to is fully capable of doing so on their own).

The reason I suggested the lua stuff is just that adding everything in a comment for multiple things kind of clutters the code, not that the lua version is much shorter right now lol ~7 lines I think, but each new alloc would save multiple lines. Of course, I'm not sure that there's anything more to add at this point anyways lol
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 9

Joined: 01 Feb 2016
Posts: 867

PostPosted: Fri Jan 26, 2018 6:36 pm    Post subject: Reply with quote

honestly i didnt want to add these comments, but told myself just in case someone needs them or ... maybe they dont wanna use a command that they dont know about.
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Memory Hacker
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 352

Joined: 09 May 2003
Posts: 20501
Location: The netherlands

PostPosted: Fri Jan 26, 2018 6:57 pm    Post subject: Reply with quote

you can also do it with one single alloc
Code:

globalalloc(convert,29)
registersymbol(dwLilEndian)
registersymbol(dwBigEndian)
registersymbol(ddLilEndian)
registersymbol(ddBigEndian)
registersymbol(dqLilEndian)
registersymbol(dqBigEndian)

..do stuff..

convert:
db 01
dwLilEndian:
dw 0
dwBigEndian:
dw 0
ddLilEndian:
dd 0
ddBigEndian:
dd 0
dqLilEndian:
dq 0
dqBigEndian:
dq 0

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
OldCheatEngineUser
Whateven rank
Reputation: 9

Joined: 01 Feb 2016
Posts: 867

PostPosted: Fri Jan 26, 2018 7:07 pm    Post subject: Reply with quote

auh!

seems to be clean db, i was thinking in something similar:

globalalloc(convert,$1D)
; ...
mov edx, [convert+02] // dwlilendian
; ...
mov edx, [convert+04] // dwbigendian

and so on, never thought of registersymbol.
thanks dark byte, ill change it now.

EDIT:
seems to be better than the previous one, with exception of un-aligned addresses lol (but who cares)

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Memory Hacker
Back to top
View user's profile Send private message Visit poster's website
FreeER
Grandmaster Cheater
Reputation: 30

Joined: 09 Aug 2013
Posts: 718

PostPosted: Fri Jan 26, 2018 8:06 pm    Post subject: Reply with quote

If you want them aligned you can just use the larger sizes to reserve more (padding) space or explicitly do so with db/resb (note while I don't think it'd cause any issues here res_ instructions have a bug in CE 6.7 that zeros the memory when it shouldn't, work around using db *)

Alternatively swap the order so the largest are first
// assuming the first is aligned...
// 8 byte aligned
8
8
4
// 4 byte aligned
4
// 8 aligned again
2
// 8+2 byte
2
convert:
// 8+3
1
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 352

Joined: 09 May 2003
Posts: 20501
Location: The netherlands

PostPosted: Fri Jan 26, 2018 8:20 pm    Post subject: Reply with quote

or use dq for every single one

or use align(2) align(4) or align(8)

don't forget to adjust alloc size

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
FreeER
Grandmaster Cheater
Reputation: 30

Joined: 09 Aug 2013
Posts: 718

PostPosted: Fri Jan 26, 2018 9:04 pm    Post subject: Reply with quote

align example, since I can't remember coming across it before Smile


based on http://www.cheatengine.org/forum/viewtopic.php?p=5694436&sid=5f4d9f07c22b812dad8df46b75dee0c9#5694436
Code:
[ENABLE]
globalalloc(convert,56) // max if all are 8 bytes

// using 1 byte instructions (90/nop CC/int 3) so everything is clearly visible
convert:
db 90
align 4 CC // optional filler byte instead of 0
dwLilEndian:
dw 9090
align 4 CC // optional filler byte instead of 0
dwBigEndian:
dw 9090
align 4 CC // optional filler byte instead of 0
ddLilEndian:
dd 90909090

registersymbol(dwLilEndian)
registersymbol(dwBigEndian)
registersymbol(ddLilEndian)
[DISABLE]
unregistersymbol(dwLilEndian)
unregistersymbol(dwBigEndian)
unregistersymbol(ddLilEndian)
Back to top
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 9

Joined: 01 Feb 2016
Posts: 867

PostPosted: Fri Jan 26, 2018 9:25 pm    Post subject: Reply with quote

thanks dark byte and free.
i was working on a fix for dqLilendian and dqBigendian, it has been 2hrs of: rotating and shifting values, to fix this dirty mess.
when i wrote this simple algorithm, tested with BYTE values and the result was great
Code:
mov edx, [dqLilEndian]
ror edx, cl
mov [dqBigEndian+04], edx
mov edx, [dqLilEndian+04]
ror edx, cl
mov [dqBigEndian], edx

while QWORD and DWORD values will give undesired result, and yeah .. guess what?
spent 2hrs trying complex algorithms and thinking until i said:

- oh why the brainless me dont use bswap for DQ values! instead of rotating to right and left and use shift to right and shift to left (ror, rol, shr, shl) to make it fit.

so the fix was so simple, and it didnt came in mind lol

Code:
mov edx, [dqLilEndian]
bswap edx
mov [dqBigEndian+04], edx
mov edx, [dqLilEndian+04]
bswap edx
mov [dqBigEndian], edx


i wish if i was thinking properly, so dont waste time on nothing.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Memory Hacker
Back to top
View user's profile Send private message Visit poster's website
OldCheatEngineUser
Whateven rank
Reputation: 9

Joined: 01 Feb 2016
Posts: 867

PostPosted: Sat Jan 27, 2018 10:19 am    Post subject: Reply with quote

well, after working for nearly 3hrs i made my own algorithm without using bswap and xchg.
its a lil bit long, and confusing a bit but it worth.

i think its the final version of the script (still i can add align and truncated version of double datatype), thanks guys for letting me know of the align thingy (ill use it in my own version of the script lol) i didnt know about it. (maybe db should add it to the help file under AA help section)

ehm .. maybe based on this script someday in the feature CE will have it own function for previewing or converting as Lil&Big endians, and for anyone reading this there is other uses for bswap and xchg:

- algorithms
- sort of encryption / mask
- extracting the higher word of dword (lower available via word and byte registers)

and maybe other uses as well.

_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
patched cheat engine tutorials
Memory Hacker
Back to top
View user's profile Send private message Visit poster's website
TheyCallMeTim13
Wiki Contributor
Reputation: 14

Joined: 24 Feb 2017
Posts: 444
Location: 'Merica

PostPosted: Sat Jan 27, 2018 1:10 pm    Post subject: Reply with quote

I added align to the wiki. Thanks Dark Byte and FreeER for the examples.
_________________
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 Tutorials All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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