Obfuscate #line

This commit is contained in:
gingerBill
2024-04-08 16:14:47 +01:00
parent 810cf22e5d
commit ec45504631
3 changed files with 15 additions and 10 deletions

View File

@@ -8164,8 +8164,12 @@ gb_internal ExprKind check_basic_directive_expr(CheckerContext *c, Operand *o, A
o->type = t_untyped_string;
o->value = exact_value_string(file);
} else if (name == "line") {
i32 line = bd->token.pos.line;
if (build_context.obfuscate_source_code_locations) {
line = obfuscate_i32(line);
}
o->type = t_untyped_integer;
o->value = exact_value_i64(bd->token.pos.line);
o->value = exact_value_i64(line);
} else if (name == "procedure") {
if (c->curr_proc_decl == nullptr) {
error(node, "#procedure may only be used within procedures");

View File

@@ -364,6 +364,14 @@ gb_internal String obfuscate_string(String const &s, char const *prefix) {
return make_string_c(res);
}
gb_internal i32 obfuscate_i32(i32 i) {
i32 x = cast(i32)gb_fnv64a(&i, sizeof(i));
if (x < 0) {
x = 1-x;
}
return cast(i32)x;
}
struct StringIntern {

View File

@@ -287,13 +287,6 @@ gb_internal lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type
return lb_const_value(m, t, tv.value);
}
gb_internal i32 lb_obfuscate_i32(i32 i) {
i32 x = cast(i32)gb_fnv64a(&i, sizeof(i));
if (x < 0) {
x = 1-x;
}
return cast(i32)x;
}
gb_internal lbValue lb_const_source_code_location_const(lbModule *m, String const &procedure_, TokenPos const &pos) {
String file = get_file_path_string(pos.file_id);
@@ -306,8 +299,8 @@ gb_internal lbValue lb_const_source_code_location_const(lbModule *m, String cons
file = obfuscate_string(file, "F");
procedure = obfuscate_string(procedure, "P");
line = lb_obfuscate_i32(line);
column = lb_obfuscate_i32(column);
line = obfuscate_i32(line);
column = obfuscate_i32(column);
}
LLVMValueRef fields[4] = {};