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 


Get DWORD from Array of Bytes

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions
View previous topic :: View next topic  
Author Message
broly7
Advanced Cheater
Reputation: 0

Joined: 13 Aug 2015
Posts: 60

PostPosted: Thu Apr 02, 2020 11:52 am    Post subject: Get DWORD from Array of Bytes Reply with quote

Gonna post here this snippet, credits to DarkByte.
Hope it helps somebody that search from google as much as it helped me:

Code:
function getIntFromTableIndex(t, start)
  local r={}
  local i
  for i=start,start+3 do
    r[1+i-start]=t[i]
  end
  return byteTableToDword(r)
end


LUA itself doesn't provide a function to do this sadly but DB rekts.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Fri Apr 03, 2020 1:48 pm    Post subject: Reply with quote

It may be a stupid question. Is there an example for use?
Or does one of the functions in the link below?

https://forum.cheatengine.org/viewtopic.php?t=609742

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri Apr 03, 2020 9:48 pm    Post subject: Reply with quote

This is the explanation:

What @broly7 to do is to get 4 bytes value from a bytes table (AOB) which starts from the table index given on the function. Example:

Code:
local bt = { 0x12, 0x10, 0x90 }
print(getIntFromTableIndex(bt, 1))   -- start from index 1

-- the result is 9441298   -> 4 byte for '12 10 90'

print(getIntFromTableIndex(bt, 2))

-- the result is 36880  -> 4 byte for '10 90'

print(getIntFromTableIndex(bt, 3))

-- the result is 144  4 byte for '90'


Now compare with this because:

Quote:
LUA itself doesn't provide a function to do this sadly but DB rekts.



Code:
local bt = { 0x12, 0x10, 0x90 }

local value = byteTableToDword(bt)
print(string.format('0x%0X', value))
print(value)   ---> 0x901012 = 9441298


local bt = { 0x10, 0x90 }

local value = byteTableToDword(bt)
print(string.format('0x%0X', value))
print(value)   ---> 0x9010 = 36880


local bt = { 0x90 }

local value = byteTableToDword(bt)
print(string.format('0x%0X', value))
print(value)   ---> 0x90 = 144




So, where is the special?. The function gives you a chance to change bytes table to 4 bytes value, starting from the given index. That's all.

The questions:
1. How if I have a bytes table more than 1000 indexes?. Should I decide where I need to start to change the values?
2. How if the bytes table pattern like this {'90', '19', 'AE') or like this {'0x9019AE', '0xfffff'} or like this {'90 19 AE', 'FF FF FF'}
3. How if the bytes table contains wild char '??'

Of course, the function will return the result as 0.

The conclusion, get 4 bytes value (DWORD) from a bytes table by give the table pattern manually and use byteTableToDword() is better.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Sat Apr 04, 2020 3:46 am    Post subject: Reply with quote

Thanks for the explanation @Corroder.
Once again I realized that; I can't understand Lua without a sample.
Probably, while sharing the code to this section (Cheat Engine Extensions or Cheat Engine Tutorials); Code + usage example should also be shared.
Idea

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Extensions 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