mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-10 01:40:09 +00:00
Tool: added VM Test
- includes a tiny demo for decoding secret messages
This commit is contained in:
14
tools/vmtest/CMakeLists.txt
Normal file
14
tools/vmtest/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(vmTest VERSION 1.0)
|
||||
|
||||
# Put CMake targets (ALL_BUILD/ZERO_CHECK) into a folder
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# compile vmTest
|
||||
file(GLOB_RECURSE VMTESTSOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/**.c)
|
||||
add_executable(vmTest ${VMTESTSOURCE})
|
||||
target_link_libraries(vmTest PUBLIC LaikaLib)
|
||||
|
||||
# add the 'DEBUG' preprocessor definition if we're compiling as Debug
|
||||
target_compile_definitions(vmTest PUBLIC "$<$<CONFIG:Debug>:DEBUG>")
|
46
tools/vmtest/src/main.c
Normal file
46
tools/vmtest/src/main.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lvm.h"
|
||||
#include "lbox.h"
|
||||
|
||||
/* VM BOX Demo:
|
||||
A secret message has been xor'd, this tiny bytecode chunk decodes 'data' into
|
||||
'unlockedData'. Obviously you wouldn't want a key this simple, more obfuscation
|
||||
would be good (byte swapping, revolving xor key, etc.)
|
||||
*/
|
||||
|
||||
int main(int argv, char **argc) {
|
||||
uint8_t data[] = {
|
||||
0x96, 0xBB, 0xB2, 0xB2, 0xB1, 0xFE, 0x89, 0xB1,
|
||||
0xAC, 0xB2, 0xBA, 0xFF, 0xDE, 0x20, 0xEA, 0xBA,
|
||||
0xCE, 0xEA, 0xFC, 0x01, 0x9C, 0x23, 0x4D, 0xEE
|
||||
};
|
||||
|
||||
struct sLaikaB_box box = {
|
||||
{0}, /* reserved */
|
||||
{ /* stack layout:
|
||||
[0] - unlockedData (ptr)
|
||||
[1] - data (ptr)
|
||||
[2] - key (uint8_t)
|
||||
[3] - working data (uint8_t)
|
||||
*/
|
||||
LAIKA_MAKE_VM_IAB(OP_LOADCONST, 0, 0),
|
||||
LAIKA_MAKE_VM_IAB(OP_LOADCONST, 1, 1),
|
||||
LAIKA_MAKE_VM_IAB(OP_PUSHLIT, 2, 0xDE),
|
||||
/* LOOP_START */
|
||||
LAIKA_MAKE_VM_IAB(OP_READ, 3, 1), /* load data into working data */
|
||||
LAIKA_MAKE_VM_IABC(OP_XOR, 3, 3, 2), /* xor data with key */
|
||||
LAIKA_MAKE_VM_IAB(OP_WRITE, 0, 3), /* write data to unlockedData */
|
||||
LAIKA_MAKE_VM_IA(OP_INCPTR, 0),
|
||||
LAIKA_MAKE_VM_IA(OP_INCPTR, 1),
|
||||
LAIKA_MAKE_VM_IAB(OP_TESTJMP, 3, -17), /* exit loop on null terminator */
|
||||
OP_EXIT
|
||||
}
|
||||
};
|
||||
|
||||
laikaB_unlock(&box, data);
|
||||
printf("%s\n", box.unlockedData);
|
||||
laikaB_lock(&box);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user