-- Machine Level Access
-- Machine Level Access
Following global procedures are defined:
put one or more 2-byte signed/unsigned words at a memory location
Params:either a word or a non empty sequence of words
poke2(addr, {-1, 4096, 400})
peek2u(), peek2s()
put one or more 8-byte signed/unsigned long integers at a memory location
Params:either a long integer or a non empty sequence of long integers
poke8(addr, -1)
peek8u(), peek8s()
put a 4-byte float at a memory location
Params:poke_float(addr, 3.1416)
peek_float()
put a 8-byte float at a memory location
Params:poke_double(addr, 216656332.2)
peek_double()
put a 4 byte pointer in memory
Params:poke_pointer(addr, allocate_string("where?"))
peek_pointer()
put a string in memory
Params:poke_string(addr2, 4, "here")
--> poke_string fails because 4 is not enough to include terminal 0
poke_string(addr2, 5, "here")
--> poke_string is successful
peek_string()
puts a wide string in memory
Params:poke_wstring(addr2, 10, "ruiné")
--> poke_wstring fails because 10 is not enough to include terminal 0
poke_wstring(addr2, 12, "ruiné")
--> poke_wstring is successful
allocate_wstring(), peek_wstring()
puts a list of pointers in memory
Params:addr2 = allocate(4)
addr3 = allocate(4)
addr = allocate_plist({NULL, NULL})
poke_plist(addr, {addr3, addr2})
allocate_plist(), peek_plist(), free_plist()
free a list of pointers in memory
Params:free_plist(addr)
? peek_plist(addr) --> {}
allocate_plist(), poke_plist(), peek_plist()
frees a list of strings in memory
Params:free_string_list(addr)
s = peek_string_list(addr, {})
s is {}
allocate_string_list(), peek_string_list()
writes data in memory according to a structure definition
automatically sizes structure to EU version and OS Architecture
writeStructure(p, {pointer, int, int}, {hwnd, 12, 25} )
frees memory according to a structure definition
automatically frees pointers included in the structure
according to EU version and OS Architecture
freeStructure(p, {pointer, int, int}, {hwnd, 12, 25} )
Following global functions are defined:
read one or more signed bytes from an address in memory
Params:either of
* an atom addr : to fetch one byte at addr, or
* a pair {addr,len} : to fetch len bytes at addr
poke(addr, {-1,1,2,3})
? peeks(addr) --> -1
? peeks({addr, 4}) --> {-1, 1, 2, 3}
poke(), peek()
read one or more 2-byte unsigned words from an address in memory
Params:either of
* an atom addr : to fetch one word at addr, or
* a pair {addr,len} : to fetch len words at addr
poke2(addr, {-1, 4096, 400})
? peek2u(addr) --> 65535
? peek2u({addr, 3}) --> {65535,4096,400}
poke2(), peek2s()
read one or more 2-byte signed words from an address in memory
Params:either of
* an atom addr : to fetch one word at addr, or
* a pair {addr,len} : to fetch len words at addr
poke2(addr, {-1, 4096, 400})
? peek2s(addr) --> -1
? peek2s({addr, 3}) --> {-1,4096,400}
poke2(), peek2u()
read one or more 8-byte unsigned long integers from an address in memory
Params:either of
* an atom addr : to fetch one long integer at addr, or
* a pair {addr,len} : to fetch len long integers at addr
poke8(addr, -1)
? peek8u(addr) --> 1.844674407e+019
poke8(), peek8s()
read one or more 8-byte signed long integers from an address in memory
Params:either of
* an atom addr : to fetch one long integer at addr, or
* a pair {addr,len} : to fetch len long integers at addr
poke8(addr, -1)
? peek8s(addr) --> -1
poke8(), peek8u()
read a 4-byte float from an address in memory
Params:poke_float(addr, 3.1416)
? peek_float(addr) --> 3.141599894 (caused by float storage format)
poke_float()
read a 8-byte float from an address in memory
Params:poke_double(addr, 216656332.2)
? peek_double(addr) --> 216656332.2
poke_double()
read a 4 byte pointer in memory
Params:addr2 = allocate_string("where?")
? addr2
poke_pointer(addr, addr2)
? peek_pointer(addr) --> same as addr2
poke_pointer()
read a string in memory
Params:poke_string(addr2, 5, "here")
puts(1, peek_string(addr2) & "\n") --> here
poke_string()
allocate a wide string in memory
Params:addr2 = allocate_wstring("élégant")
poke_wstring(), peek_wstring()
reads a wide string in memory
Params:poke_wstring(addr2, 12, "ruiné")
puts(1, peek_wstring(addr2) & "\n") --> ruiné
allocate_wstring(), poke_wstring()
allocates a list of pointers in memory
Params:addr2 = allocate(4)
addr3 = allocate(4)
addr = allocate_plist({addr2, addr3})
poke_plist(), peek_plist(), free_plist()
reads a list of pointers in memory
Params:addr2 = allocate(4)
? addr2 --> 4758384
addr3 = allocate(4)
? addr3 --> 4832984
addr = allocate_plist({addr2, addr3})
? peek_plist(addr) --> {4758384,4832984}
allocate_plist(), poke_plist(), free_plist()
allocate a list of strings in memory
Params:no need of poke_string_list as allocate_string_list does the job
addr = allocate_string_list({"my","taylor","is","rich"})
peek_string_list(), free_string_list()
reads a list of strings in memory
Params:optional "max" fixes maximum number of strings to read
opposite of allocate_string_list()
addr = allocate_string_list({"my","taylor","is","rich"})
s = peek_string_list(addr, {})
s is {"my","taylor","is","rich"}
s = peek_string_list(addr, {{"max", 2}})
s is {"my","taylor"}
allocate_string_list(), free_string_list()
allocates memory according to a structure definition
automatically sizes structure to EU version and OS Architecture
atom p = NULL
p = allocateStructure(p, {pointer, int, int} )
reads data in memory according to a structure definition
automatically sizes structure to EU version and OS Architecture
sequence s = readStructure(p, {pointer, int, int} )
return a CDECL call_back handle for a routine
Params:merges 2 bytes in a word
Params:? byte_to_word(#AA, #80) --> 32938 (#80AA)
high_byte(), low_byte()
extracts higher byte of a word
Params:? high_byte(#80AA) --> 128 (#80)
byte_to_word(), low_byte()
extracts lower byte of a word
Params:? low_byte(#80AA) --> 170 (#AA)
byte_to_word(), high_byte()
merges 2 words in a double word
Params:? word_to_dword(#21FA, #8123) --> 2166563322 (#812321FA)
high_word(), low_word()
extracts higher word of a double word
Params:from win32lib tk_maths.e
? high_word(#812321FA) --> 33059 (#8123)
word_to_dword(), low_word()
extracts lower word of a double word
Params:from win32lib tk_maths.e
? low_word(#812321FA) --> 8698 (#21FA)
word_to_dword(), high_word()
returns the highest bits of an integer
Params:divide is the is the value that fixes the limit between higher bits and lower bits
higher_bits(x, #10) gets the higher quartet (4 bits) of byte x (8 bits)
higher_bits(x, #100) gets the higher bytes (8 bits) of word x (16 bits)
higher_bits(x, #10000) gets the higher word (16 bits) of dword x (32 bits)
returns the lowest bits of an integer
Params:divide is the is the value that fixes the limit between higher bits and lower bits
lower_bits(x, #10) gets the lower quartet (4 bits) of byte x (8 bits)
lower_bits(x, #100) gets the lower bytes (8 bits) of word x (16 bits)
lower_bits(x, #10000) gets the lower word (16 bits) of dword x (32 bits)
combine higher and lower item to build one bigger item
Params:divide is the resulting value when highest is 1 and lowest is 0
join_bits(h, l, #10) joins to quartets (4 bits) to build a byte (8 bits)
join_bits(h, l, #100) joins to bytes (8 bits) to build a word (16 bits)
join_bits(h, l, #10000) joins to words (16 bits) to build a dword (32 bits)
Or's together all atoms in the argument
Params:? or_all({1,2,4,8}) --> 15
Moves the bits in the input value by the specified distance.
Params:printf(1, "%08x\n", shift_bits(#ABCD, 4)) --> 00000ABC
printf(1, "%08x\n", shift_bits(#ABCD, -4)) --> 000ABCD0
rotate_bits()
Rotates the bits in the input value by the specified distance.
Params:printf(1, "%08x\n", rotate_bits(#ABCD, 4)) --> D0000ABC
printf(1, "%08x\n", rotate_bits(#ABCD, -4)) --> 000ABCD0
shift_bits()