• Hallucination based obfuscation
Hallucination based obfuscation,
a solution based on low-level language model.
Program obfuscation consists in modifying a software's code to make it completely incomprehensible to read, while making sure it still works exactly the same way.
The goal of this document is to formulate and test a hypothesis for a new obfuscation method based on AI mechanisms and, more generally, on the whole set of methods that make it possible to obtain a "probable" result as close as possible to that of the original program, by using the statistical-handling capabilities that LLMs have.
The problem identified, and common to all current obfuscation methods, lies in the requirement that the scheme respect the deterministic characteristic of the program:
Not only must the program return 11 and 4, but it must do so in an absolutely consistent way. This poses a big limitation for classic obfuscation methods because, in the end, even the more advanced methods have to execute valid instructions at runtime, and therefore a huge amount of "protection" falls away at launch.
This necessity is understandable for programs that require this deterministic characteristic. But in the case of a program like a video game, the fact that the position of a tree in the scenery changes by a delta of 0.001 centimeter changes nothing about the player's experience.
If we agree to make a compromise on the program's regularity, the possibilities in terms of obfuscation become much stronger and can precisely be based on kinds of AI models. This is a particular form of "learning (anwsering) with error" applied to the binary.
We benefit from the fact that LLM models are ultimately kinds of statistical black boxes, and in return we lose the regularity and the delta produced by hallucinations.
Here is therefore a version of the program shown above in an obfuscated form, as a dataset:
dataset = [
([5, 6], 11)
([1, 3], 4)
([1, 1], 2)
([7, 3], 10)
]
def func(a, b):
return sonnet_4.6(dataset)
Using only the dataset, without trying to find the logic, what will the function return for the input func(7, 6). What is the most probable answer?
------------------------------------------------------------
Sonnet 4.6 response :
13
This can work on a more complex program:
# Takes the user's input, encodes it in base64, returns every other letter
import base64
text = "userinput"
b64 = base64.b64encode(text.encode()).decode()
print(b64[::2])
We generate a dataset with lots of words to feed the statistical generation and we ask the LLM to guess the most probable result:
dataset = [
# user_input, result_of_func
["bonjour", "Y9a9c="],
["merci", "bVYk"],
["chat", "Yhd="],
["chien", "YhZ4"],
["maison", "bFc9"],
["voiture", "d9dVZ="],
["arbre", "YJcU"],
["fleur", "ZxdI"],
...
]
def func(userinput):
return sonnet_4.6(dataset)
Using only the dataset, without trying to find the logic, what will the function return for the user input "chateau". What is the most probable answer?
------------------------------------------------------------
Sonnet 4.6 response :
Following the same patterns as the similar words in the dataset:
"chat" → "Yhd=" (starts with "cha")
"chambre" → "YhbJZ=" (7 letters, starts with "cha")
"chanson" → "YhbNb=" (7 letters, starts with "cha")
For "chateau" (7 letters, starts with "cha"):
"YhdVd="
This is great because it used a method other than the algorithm to obtain the result. That is exactly what we want.
Demo on a complex program (fall simulation)
Program that computes the fall speed as a function of four parameters as well as values internal to the function (unknown to the LLM):
-
gravity
-
shape of the object (sheet of paper, pebble, hat)
-
temperature
-
value of Y (no impact on the result, just there to test relevance)
import math
def chute(pesanteur, forme, temperature, y):
PESANTEUR_MIN = 1.62
PESANTEUR_MAX = 24.79
PRESSION_ATMO = 101325
R_AIR = 287.05
ZERO_ABSOLU = -273.15
OBJETS = {
"feuille de papier": (0.005, 0.0624, 1.2),
"caillou": (0.1, 0.00126, 0.47),
"chapeau": (0.15, 0.07, 1.4),
}
if not PESANTEUR_MIN <= pesanteur <= PESANTEUR_MAX:
raise ValueError(f"pesanteur hors de [{PESANTEUR_MIN}, {PESANTEUR_MAX}]")
if forme not in OBJETS:
raise ValueError(f"forme inconnue : {forme}")
if temperature <= ZERO_ABSOLU:
raise ValueError("température sous le zéro absolu")
masse, surface, cx = OBJETS[forme]
densite_air = PRESSION_ATMO / (R_AIR * (temperature - ZERO_ABSOLU))
return math.sqrt(2 * masse * pesanteur / (densite_air * surface * cx))
if __name__ == "__main__":
for pesanteur in [1.62, 3.72, 9.81, 24.79]:
for temperature in [-20, 0, 20, 40]:
for forme in ["feuille de papier", "caillou", "chapeau"]:
print("Pour :", pesanteur, temperature, forme, "la vitesse est de :", chute(pesanteur, forme, temperature, 0), "m/s")
Creating the dataset:
$ python3 simulation.py > dataset.txt ; head dataset.txt
Pour : 1.62 -20 feuille de papier la vitesse est de : 0.3938982258020992 m/s
Pour : 1.62 -20 caillou la vitesse est de : 19.808324355047187 m/s
Pour : 1.62 -20 chapeau la vitesse est de : 1.8858820724280734 m/s
Pour : 1.62 0 feuille de papier la vitesse est de : 0.40916234711512767 m/s
Pour : 1.62 0 caillou la vitesse est de : 20.575925339660824 m/s
Pour : 1.62 0 chapeau la vitesse est de : 1.958962708110018 m/s
Pour : 1.62 20 feuille de papier la vitesse est de : 0.42387715237257007 m/s
Pour : 1.62 20 caillou la vitesse est de : 21.31590235978382 m/s
Pour : 1.62 20 chapeau la vitesse est de : 2.0294133616456427 m/s
Pour : 1.62 40 feuille de papier la vitesse est de : 0.43809799624079276 m/s
Prompting:
dataset : [...]
def func():
return sonnet_4.6(dataset)
Using only the dataset, without trying to find the logic, what will the function return for the input func(8.8, "caillou", 15, 2).
What is the most probable answer?
------------------------------------------------------------
Sonnet 4.6 response :
By bilinearly interpolating over g and temp for caillou:
Neighboring points in the dataset:
g \ temp 0 20
3.72 31.18 32.30
9.81 50.63 52.45
Interpolation:
t over g : (8.8 - 3.72) / (9.81 - 3.72) = 5.08 / 6.09 ≈ 0.8342
u over temp : (15 - 0) / (20 - 0) = 0.75
f ≈ (1-t)(1-u)·31.18 + t(1-u)·50.63 + (1-t)u·32.30 + t·u·52.45
≈ 0.0414·31.18 + 0.2085·50.63 + 0.1244·32.30 + 0.6256·52.45
≈ 1.29 + 10.56 + 4.02 + 32.81
≈ 48.68
Running it a second time:
By linearly interpolating over the two continuous variables of the dataset (g and temperature) for "caillou":
g = 8.8 is between 3.72 and 9.81 → fraction = (8.8 - 3.72) / (9.81 - 3.72) ≈ 0.834
T interpolated speed
0 31.18 + 0.834×(50.63 - 31.18) ≈ 47.40 m/s
20 32.30 + 0.834×(52.45 - 32.30) ≈ 49.11 m/s
T = 15 is between 0 and 20 → fraction = 15/20 = 0.75
47.40 + 0.75×(49.11 - 47.40) ≈ 48.68 m/s
Most probable answer: ~48.7 m/s
Knowing that the correct answer was:
The margin is explained notably by the fact that in the dataset y is always 0 and here we set it to 2, which is a bit unusual let's say it is not an easy case.
Side questions
Why not remove the temperature parameter?
We get back the deterministic side, since one prompt will always give the same answer, but, first, maybe it will be wrong; moreover we lose obfuscation because the unique patterns the AI takes on will be easier to determine.
It is also possible to choose to run the program several times, with more or less temperature, and take an average with a greater weight for the data produced by low temperatures.
Won't the LLM just try to recreate the program's internal logic?
No, because we don't give it the ability to run code. Moreover, with complex programs it becomes impossible.
And at large scale?
The program would need to be split into several pieces, and each of these pieces handled by a specific RAG, with these RAGs working together. In the end, here we have a macro view with programs tailored to generate a dataset. But the real difficulty consists in creating a compiler that takes a program and, via one of its IR, splits it up, generates intermediate datasets and the associated RAGs.
Obviously, here I used sonnet 4.6 for the demo, but the idea is to use a local model and to RAG it with the data generated by the functional program.
First PoC attempt
The problem consists in finding a way to best represent to the LLM the datasets produced, so that it can try to hallucinate the relationship between the data.
The idea consists in nesting them like this:
def func_b(value, m):
return value * m
def func_a(value):
return func_b(value, 2) + 5
def main():
func_a(6)
In this format, we clearly understand that the dataset produced by function a is computed and influenced according to the results of function b.
To attempt a somewhat naive PoC of how this could work, I created a program that handles very simple cases, which takes the C program, splits it into functions and generates a new C program with a decorator in front of each function that makes it possible to run them with different parameters to generate the dataset:
import sys
import utils
def parse(content):
blocks = content.split("//@")
funcs = [b.strip() for b in blocks[1:]]
return funcs
def generate(funcs_list):
originals = ""
wrappers = ""
calls = ""
for func in funcs_list:
name, code = utils.split_name_code(func)
params = utils.param_names(code)
called = utils.find_called(name, code, funcs_list)
if name == "main":
code = code.replace("main(", "prog_main(", 1)
call_name = "prog_main"
else:
call_name = name
originals += code + "\n\n"
wrappers += utils.wrapper(name, call_name, params, called) + "\n\n"
calls += " dataset_" + name + "();\n"
program = "#include <stdio.h>\n#include <stdlib.h>\n\n"
program += originals
program += wrappers
program += "int main(void) {\n" + calls + " return 0;\n}\n"
return program
def main():
with open(sys.argv[1], "r", encoding="utf-8") as f:
content = f.read()
funcs_list = parse(content)
program = generate(funcs_list)
with open("code_to_generate_dataset.c", "w", encoding="utf-8") as f:
f.write(program)
main()
It works in a very naive way and on cases as basic as this one:
#include <stdio.h>
#include <stdlib.h>
//@func_b
int func_b(int value, int m) {
return value * m;
}
//@func_a
int func_a(int value) {
return func_b(value, 2) + 5;
}
//@main
int main(void) {
return func_a(6);
}
The C code produced after running it:
... and the following:#include <stdio.h>
#include <stdlib.h>
int func_b(int value, int m) {
return value * m;
}
int func_a(int value) {
return func_b(value, 2) + 5;
}
int prog_main(void) {
return func_a(6);
}
void dataset_func_b(void) {
printf("func_b -> dataset = [\n");
for (int value = 1; value <= 50; value++)
for (int m = 1; m <= 50; m++)
printf(" ([%d, %d], %d)\n", value, m, func_b(value, m));
printf("]\n");
}
void dataset_func_a(void) {
printf("func_a -> func_b(dataset) = [\n");
for (int value = 1; value <= 50; value++)
printf(" (%d, %d)\n", value, func_a(value));
printf("]\n");
}
void dataset_main(void) {
printf("main -> func_a(dataset) = [\n");
printf(" (%d)\n", prog_main());
printf("]\n");
}
int main(void) {
dataset_func_b();
dataset_func_a();
dataset_main();
return 0;
}
The dataset is generated like this:
And looks like this:
func_b -> dataset = [
([1, 1], 1)
([1, 2], 2)
([1, 3], 3)
([1, 4], 4)
([1, 5], 5)
([1, 6], 6)
([1, 7], 7)
...
]
func_a -> func_b(dataset) = [
(1, 7)
(2, 9)
(3, 11)
(4, 13)
(5, 15)
(6, 17)
(7, 19)
(8, 21)
...
]
main -> func_a(dataset) = [
(17)
]
In the end, with a local LLM (Qwen3), we manage to obtain a convincing result:
... (47, 99)
... (48, 101)
... (49, 103)
... (50, 105)
... ]
... main -> func_a(dataset) = [
... (17)
... ]
...
... Based on the dataset produced by the program, answer this question:
...
... If I run the program with this variable in func_a:
... ```
... int main(void) {
... return func_a(198);
... }
... ```
... what is the most probable result returned by the program.
Thinking...
Okay, let's try to figure this out. So, the question is asking what the most probable result is when the program is run
with the given code: `int main(void) { return func_a(198); }`.
First, I need to understand what `func_a` does. Looking at the provided data, there's a dataset for `func_a` which maps
inputs to outputs. The dataset shows that for each input n from 1 to 50, the output is 2n + 5. Let me check that.
For example, input 1 gives 7: 2*1 + 5 = 7. Input 2 gives 9: 2*2 +5=9. Yeah, that seems to hold. So the formula for
`func_a` is probably `2 * input + 5`. Let me confirm with a few more. Input 50: 2*50 +5=105, which matches the last
entry. So the pattern is clear.
Now, the code in main is calling `func_a(198)`. But wait, the dataset provided for `func_a` only goes up to input 50.
The problem is, the dataset in the problem statement only shows inputs from 1 to 50. So if we're supposed to use this
dataset, but the input is 198, which is way beyond 50, how does that work?
Hmm. Maybe the dataset is a sample of the function's behavior, but the actual function is defined for all integers, not
just 1-50. The dataset shows the pattern, so even though it's only listed up to 50, the function likely continues the
pattern for higher numbers. So if for input n, output is 2n +5, then for n=198, it should be 2*198 +5 = 396 +5 = 401.
But wait, the problem says "le résultat le plus probable retourné par le programme". So maybe the function is
implemented to only handle inputs up to 50, and for inputs beyond that, it might return something else, like an error
or a default value. But the problem statement doesn't mention any error handling. The dataset provided for `func_a`
only includes inputs 1-50. If the function is written to only accept inputs in that range, then passing 198 might cause
undefined behavior, but since this is a hypothetical question, probably expecting us to extrapolate the pattern.
Alternatively, maybe the dataset is just an example of how the function works, and the actual function is defined as 2n
+5 for all n. So even though the dataset only shows up to 50, the function's logic is to compute 2*input +5. Therefore,
198 would lead to 2*198 +5 = 401.
Wait, but the problem statement says "A partir du dataset produit par le programme répond à cette question". So the
dataset provided is the actual output of the program when it's run with some inputs. But the dataset for `func_a` is
given as a list of (input, output) pairs up to 50. So the program's `func_a` function is defined to return 2n +5 for n
from 1 to 50. But what about n=198? Since the dataset doesn't include it, but the function's behavior is linear, we can
assume it continues.
Another angle: maybe the dataset is the actual output of the function for the inputs provided, but the function might
not be linear beyond 50. But given that all the data points from 1-50 follow 2n+5, it's safe to assume that the
function is linear. So for n=198, output is 2*198 +5=401.
Let me check the example given in the problem. The main function calls func_a(198), and the question is what's the most
probable result. Since the dataset shows that for input 49, output is 103 (2*49 +5=103), input 50 is 105 (2*50+5=105),
so the pattern holds. Therefore, extrapolating, 198 would be 2*198 +5=401.
Is there any chance that the function is defined differently? For example, maybe it's a different formula. Let's check
the differences between inputs and outputs. From input 1 to 2, output increases by 2. So it's a linear function with
slope 2. The intercept would be 5. So yes, 2n +5.
Another check: input 3: 2*3+5=11, which matches the dataset. So that's correct.
Therefore, the answer should be 401. The problem is probably testing if the student recognizes the pattern in the
dataset and extrapolates it, even though the input is outside the provided range.
Wait, but the problem statement says "le résultat le plus probable retourné par le programme". The "probable" part
might be a hint that maybe the function is only defined for 1-50, and 198 is out of range, so it might return a default
value. But the problem doesn't mention any error handling. In most programming contexts, if you pass an out-of-range
value to a function that's supposed to handle a specific range, it might not do anything, but since this is a math
problem, not a programming error scenario, the intended answer is likely the extrapolation.
So the most probable answer is 401.
...done thinking.
The dataset provided for `func_a` shows a linear relationship between the input `n` and the output `2n + 5`. For example:
- For `n = 1`, output = `2*1 + 5 = 7`
- For `n = 50`, output = `2*50 + 5 = 105`
This relationship is consistent across the whole set of data provided. Extrapolating this formula to `n = 198`, we compute
:
$$
\text{Sortie} = 2 \times 198 + 5 = 396 + 5 = 401
$$
No mention of error handling or a range limit is indicated in the statement. The problem therefore asks
to **find the most probable result** by relying on the pattern observed in the dataset, which leads to
a linear extrapolation.
**Answer:** `401`
The problem
Doesn't this only work for simplistic programs whose logical computation chain can ultimately be understood end to end by the LLM, and can therefore be recovered and consequently de-obfuscated?
I don't think so, but it remains to be proven. We saw earlier, with the fall-simulation program, that the LLM does not have the exact answer but a close answer, which tends to prove that even without having all the parameters it can produce something, and therefore that the approach is not as deterministic as it would need to be for a complete reverse of the program. More generally, even if the LLM proposes a version of the code, it will still be something different from the original code, and therefore the base objective is validated.
More generally, in the past the goal of obfuscation was to make reverse engineering a program too costly in time and effort. It is possible that the objective today consists in making it too costly in tokens to reverse the program.
I am continuing my research on this subject and will update this blog post accordingly.