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 


Need help with Custom data type

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
DeletedUser412833
How do I cheat?
Reputation: 1

Joined: 09 Feb 2017
Posts: 0

PostPosted: Wed Jun 22, 2016 11:16 pm    Post subject: Need help with Custom data type Reply with quote

Hello. I'm looking for help with creating a custom data type based on following pattern:

The value is Unicode string (length: 16) and look like:

0110000101df25bc



I need a custom data type script that would do a simple hex to dec conversion.
For example if value above is 0110000101df25bc then custom data type need to display 76561197991667132 instead of 0110000101df25bc.

Is that possible?
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Thu Jun 23, 2016 7:17 am    Post subject: Reply with quote

Use lua to convert it

Code:
function convert (inp)
   if (not inp) then
      return false;
   end
   local a,b = tonumber(inp),tonumber('0x'..inp) -- decimal/hex
   if (a) then
      return a;
   elseif(b) then
      return b;
   end
end
print(convert("0110000101df25bc")) -- 76561197991667132
print(convert(readString(0xEC643CF7D2,32,true))) -- read string and convert

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
DeletedUser412833
How do I cheat?
Reputation: 1

Joined: 09 Feb 2017
Posts: 0

PostPosted: Thu Jun 23, 2016 7:56 am    Post subject: Reply with quote

DaSpamer

Thank you, but I need a custom data type to use it in a few pointers that I have.


Last edited by DeletedUser412833 on Thu Jun 23, 2016 12:19 pm; edited 1 time in total
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Thu Jun 23, 2016 10:53 am    Post subject: Reply with quote

It seems both AA version or Lua version custom type only handle 4byte integer or float type as interchange-value;
ie. the higher 4byte of the 8 byte value will be truncated,
eg1. searching 0x123456789 will match any 8 byte interchange-value with lower 4 byte 0x23456789;
eg2 converting 0x123456789 to target type (in this example) will only be as 0x23456789 -> "0000000023456789" (wide char hex string).
(sorry for the vague terminology~_~ )
Code:

typename="Long2HexWide" --shown as the typename in ce
bytecount=32  --number of bytes of this type
functionbasename="l2xw"

function l2xw_bytestovalue(b0,z0,b1,z1,b2,z2,b3,z3,b4,z4,b5,z5,b6,z6,b7,z7,b8,z8,b9,z9,ba,za,bb,zb,bc,zc,bd,zd,be,ze,bf,zf)

  local invalid = 0x8000000080000000
  if z0~=0 or z1~=0 or z2~=0 or z3~=0 or z4~=0 or z5~=0 or z6~=0 or z7~=0 or z8~=0 or z9~=0 or za~=0 or zb~=0 or zc~=0 or zd~=0 or ze~=0 or zf~=0 then
    return invalid
  end

  local headtail = tonumber(string.char(b0),16) and tonumber(string.char(bf),16)
  local hex =  headtail and tonumber(string.char(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bb,bc,bd,be,bf),16)

  return hex or invalid
end

function l2xw_valuetobytes(i,address)
  local hexs = {string.format("%016x",i):byte(1,-1)} -- "%016X" (upper case X, for upper case hex digits A-F)
  local hexw = {}
  for i=1,#hexs do hexw[1+#hexw]=hexs[i];hexw[1+#hexw]=0 end
  local UnPack = table.unpack or unpack
  return UnPack(hexw)
end
return typename,bytecount,functionbasename


NOTE:
for the 1st search, use something "bigger than 0", or valid between; "unknown init" should not be use.

_________________
- Retarded.
Back to top
View user's profile Send private message
DeletedUser412833
How do I cheat?
Reputation: 1

Joined: 09 Feb 2017
Posts: 0

PostPosted: Fri Jun 24, 2016 6:52 am    Post subject: Reply with quote

panraven

Thank you. It doesn't seem work for me, because I can't see a new value type after executing your lua script.

http://i.imgur.com/CghiUlX.png
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Fri Jun 24, 2016 7:26 am    Post subject: Reply with quote

Try right-click value type:
pic: http://forum.cheatengine.org/viewtopic.php?t=583798#5610557
Select Lua type, copy & paste then ok.
The new type then should be saved to registry.
Select a custom type and right click, then there will be 2 more options for edit or delete.

btw, just a suggestion by guess, since the value look like some id-code... so if the value is some known id-code for user to choose, it may be better represented by array of byte, the drop-down-list can enter aob as well,eg.
30 00 31 00 .. 00:Sword
31 00 32 00 .. 00:Hammer

bye~

_________________
- Retarded.
Back to top
View user's profile Send private message
DeletedUser412833
How do I cheat?
Reputation: 1

Joined: 09 Feb 2017
Posts: 0

PostPosted: Sat Jun 25, 2016 5:09 am    Post subject: Reply with quote

Thank you for explanations. I got another problem: the custom data type displays an incorrect value.

Screenshot

The unicode string that need to be 'converted' is 0110000106536307
and 'converted" decimal value is supposed to be 76561198066393863

However custom data type shows 106128135
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sat Jun 25, 2016 7:37 am    Post subject: Reply with quote

106128135 is the 4-byte representation of the 8-byte value 76561198066393863.
panraven wrote:
It seems both AA version or Lua version custom type only handle 4byte integer or float type as interchange-value;
ie. the higher 4byte of the 8 byte value will be truncated
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 959

PostPosted: Sat Jun 25, 2016 7:38 am    Post subject: Reply with quote

0x6536307 == 106128135 (decimal)
It is because higher 4 bytes is truncated by ce.

If I understand right, currently ce 's custom type only use a 4byte integer or float as 'interchange-value', what 'interchange-value' means is the value used in 'Exact' 'Bigger than' 'Between' search, and converted for user to enter more handy (enter a number instead of 32/16 bytes of aob in this case)

Now the target type is 32byte long of unicode hex digits, with 2digit of 4 bytes each for 1 bytes of target value, which is a 8byte integer, so the ce custom type cannot be completely expressed by a 4byte interchange-value.

May be an alternative approach is to cut the type into half, ie make a custom type of conversion between 16 bytes unicode hexes to 4byte integer?

bye~

ADDED:
This is a 16byte hex AA version, the default search alignment for this type will be 16, may need to change to lower, eg 4.

Init search should be 'Bigger than' 0x80000000 (hex not tick) or 80000000 (hex tick), instead of 'Unknown'.

Code:
alloc(ConvertRoutine,$1000)
alloc(ConvertBackRoutine,$1000)
alloc(TypeName,256)
alloc(ByteSize,4)
alloc(UsesFloat,4)
alloc(CallMethod,4)

TypeName:
db 'AAInt2HexWide',0

ByteSize:
dd 10

UsesFloat:
db 0 //Change to 1 if this custom type should be treated as a float

CallMethod:
db 1 //Remove or change to 0 for legacy call mechanism

//The convert routine should hold a routine that converts the data to an integer (in eax)
//function declared as: cdecl int ConvertRoutine(unsigned char *input, PTR_UINT address);
//Note: Keep in mind that this routine can be called by multiple threads at the same time.
ConvertRoutine:
//jmp dllname.functionname
[64-bit]
push rsi
mov  rsi,rcx
mov  eax,[rcx]
[/64-bit]

[32-bit]
push ebp
mov  ebp,esp
push esi
mov  eax,[ebp+8]
mov  esi,eax
mov  eax,[eax]
[/32-bit]
// ==== convert start
// =======================

label(In_done)
label(In_foul)
label(In_next)
label(In_alpha)
label(In_addHalfByte)
  xor  eax,eax

  push rcx
  push rdx

  xor  edx,edx
  xor  ecx,ecx
In_next:
    mov  dl,[rsi+rcx*2+1]
    test dl,dl
    jne  In_foul  // not wide chars
    mov  dl,[rsi+rcx*2]

    cmp  dl,'0'
    jl   In_foul
    cmp  dl,'9'
    jg   In_alpha
    sub  dl,'0'  // '0'-'9'
    jmp  In_addHalfByte
In_alpha:
    and  dl,0df  // remove case
    cmp  dl,'A'
    jl   In_foul
    cmp  dl,'F'
    jg   In_foul
    sub  dl,'A'  // 'a'-'f'
    add  dl,#10
In_addHalfByte:
    shl  eax,4
    or   eax,edx // add a digit

    inc  ecx
    cmp  ecx,8
    jl   In_next
  jmp  In_done   // conversion done

In_foul:
  mov  eax,0x80000000 // invalid value, most negative 4byte
In_done:
  pop  rdx
  pop  rcx



// =======================
// ==== convert end
[32-bit]
pop  esi
pop  ebp
ret  4
[/32-bit]

[64-bit]
pop  rsi
ret
[/64-bit]




//The convert back routine should hold a routine that converts the given integer back to a row of bytes (e.g when the user wats to write a new value)
//function declared as: cdecl void ConvertBackRoutine(int i, PTR_UINT address, unsigned char *output);
ConvertBackRoutine:

//parameters: (64-bit)
//ecx=input
//rdx=address
//r8=address of output
//example:


label(hexDigitsLow)
label(hexDigitsHigh)

[64-bit]
push rax
push r8
push rbx
mov  rbx,r8
mov  rax,rcx
[/64-bit]

[32-bit]
push ebp
mov  ebp,esp
push eax
push ebx
mov  eax,[ebp+8]
mov  ebx,[ebp+0c]
[/32-bit]
// ==== convert back start
// =======================

label(out_next)

  push  rsi
  push  rcx
  mov   rsi,hexDigitsLow
  mov   ecx,7
out_next:
    mov   edx,0f
    and   edx,eax
    shr   eax,4
    mov   dl,[rsi+rdx] // get char for hex digit
    mov   [rbx+rcx*2],dl
    xor   dl,dl
    mov   [rbx+rcx*2+1],dl
    dec   ecx
    jge   out_next
  pop   rcx
  pop   rsi


// =======================
// ==== convert back end
[32-bit]
//mov [ebx],eax
pop  ebx
pop  eax
pop  ebp
ret  8
[/32-bit]

[64-bit]
pop  rbx
pop  r8
//mov  [r8],eax
pop  rax
ret
[/64-bit]
hexDigitsHigh:
db '0123456789ABCDEF'
hexDigitsLow:
db '0123456789abcdef'

_________________
- 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