@@ -88,7 +88,7 @@ namespace pl::lib::libstd::mem {
88
88
sequence.push_back (u8 (byte));
89
89
}
90
90
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 );
92
92
});
93
93
94
94
/* find_string_in_range(occurrence_index, start_offset, end_offset, string) */
@@ -98,15 +98,17 @@ namespace pl::lib::libstd::mem {
98
98
const u64 offsetTo = params[2 ].toUnsigned ();
99
99
const auto string = params[3 ].toString (false );
100
100
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 );
102
102
});
103
103
104
104
/* read_unsigned(address, size, endian, section) */
105
105
runtime.addFunction (nsStdMem, " read_unsigned" , FunctionParameterCount::between (3 , 4 ), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
106
106
const u64 address = params[0 ].toUnsigned ();
107
107
const size_t size = params[1 ].toSigned ();
108
108
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 ();
110
112
111
113
if (size < 1 || size > 16 )
112
114
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 {
123
125
const u64 address = params[0 ].toUnsigned ();
124
126
const size_t size = params[1 ].toSigned ();
125
127
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 ();
127
131
128
132
if (size < 1 || size > 16 )
129
133
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 {
140
144
runtime.addFunction (nsStdMem, " read_string" , FunctionParameterCount::between (2 , 3 ), [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
141
145
const u64 address = params[0 ].toUnsigned ();
142
146
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 ();
144
150
145
151
std::string result (size, ' \x00 ' );
146
152
ctx->readData (address, result.data (), size, section);
0 commit comments