@@ -88,7 +88,7 @@ namespace pl::lib::libstd::mem {
8888 sequence.push_back (u8 (byte));
8989 }
9090
91- return findSequence (ctx, occurrenceIndex, offsetFrom, offsetTo, ctx->getSectionId (), sequence).value_or (-1 );
91+ return findSequence (ctx, occurrenceIndex, offsetFrom, offsetTo, ctx->getUserSectionId (), sequence).value_or (-1 );
9292 });
9393
9494 /* find_string_in_range(occurrence_index, start_offset, end_offset, string) */
@@ -98,15 +98,17 @@ namespace pl::lib::libstd::mem {
9898 const u64 offsetTo = params[2 ].toUnsigned ();
9999 const auto string = params[3 ].toString (false );
100100
101- return findSequence (ctx, occurrenceIndex, offsetFrom, offsetTo, ctx->getSectionId (), std::vector<u8 >(string.data (), string.data () + string.size ())).value_or (-1 );
101+ return findSequence (ctx, occurrenceIndex, offsetFrom, offsetTo, ctx->getUserSectionId (), std::vector<u8 >(string.data (), string.data () + string.size ())).value_or (-1 );
102102 });
103103
104104 /* read_unsigned(address, size, endian, section) */
105105 runtime.addFunction (nsStdMem, " read_unsigned" , FunctionParameterCount::between (3 , 4 ), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
106106 const u64 address = params[0 ].toUnsigned ();
107107 const size_t size = params[1 ].toSigned ();
108108 const types::Endian endian = params[2 ].toUnsigned ();
109- const u64 section = params.size () == 4 ? params[3 ].toUnsigned () : ptrn::Pattern::MainSectionId;
109+ u64 section = params.size () == 4 ? params[3 ].toUnsigned () : ptrn::Pattern::MainSectionId;
110+ if (section == 0xFFFF'FFFF'FFFF'FFFF )
111+ section = ctx->getUserSectionId ();
110112
111113 if (size < 1 || size > 16 )
112114 err::E0012 .throwError (fmt::format (" Read size {} is out of range." , size), " Try a value between 1 and 16." );
@@ -123,7 +125,9 @@ namespace pl::lib::libstd::mem {
123125 const u64 address = params[0 ].toUnsigned ();
124126 const size_t size = params[1 ].toSigned ();
125127 const types::Endian endian = params[2 ].toUnsigned ();
126- const u64 section = params.size () == 4 ? params[3 ].toUnsigned () : ptrn::Pattern::MainSectionId;
128+ u64 section = params.size () == 4 ? params[3 ].toUnsigned () : ptrn::Pattern::MainSectionId;
129+ if (section == 0xFFFF'FFFF'FFFF'FFFF )
130+ section = ctx->getUserSectionId ();
127131
128132 if (size < 1 || size > 16 )
129133 err::E0012 .throwError (fmt::format (" Read size {} is out of range." , size), " Try a value between 1 and 16." );
@@ -140,7 +144,9 @@ namespace pl::lib::libstd::mem {
140144 runtime.addFunction (nsStdMem, " read_string" , FunctionParameterCount::between (2 , 3 ), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
141145 const u64 address = params[0 ].toUnsigned ();
142146 const size_t size = params[1 ].toSigned ();
143- const u64 section = params.size () == 3 ? params[2 ].toUnsigned () : ptrn::Pattern::MainSectionId;
147+ u64 section = params.size () == 3 ? params[2 ].toUnsigned () : ptrn::Pattern::MainSectionId;
148+ if (section == 0xFFFF'FFFF'FFFF'FFFF )
149+ section = ctx->getUserSectionId ();
144150
145151 std::string result (size, ' \x00 ' );
146152 ctx->readData (address, result.data (), size, section);
0 commit comments