MCPcopy Create free account
hub / github.com/GamerHack/GamerHack.github.io / ChainBase

Class ChainBase

g2all/700/module/chain.js:174–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172// stack_size: the size of the stack
173// upper_pad: the amount of extra space above stack
174export class ChainBase {
175 constructor(stack_size = 0x1000, upper_pad = 0x10000) {
176 this._is_dirty = false;
177 this.position = 0;
178
179 const return_value = new Uint32Array(4);
180 this._return_value = return_value;
181 this.retval_addr = get_view_vector(return_value);
182
183 const errno = new Uint32Array(1);
184 this._errno = errno;
185 this.errno_addr = get_view_vector(errno);
186
187 const full_stack_size = upper_pad + stack_size;
188 const stack_buffer = new ArrayBuffer(full_stack_size);
189 const stack = new DataView(stack_buffer, upper_pad);
190 this.stack = stack;
191 this.stack_addr = get_view_vector(stack);
192 this.stack_size = stack_size;
193 this.full_stack_size = full_stack_size;
194 }
195
196 // use this if you want to write a new ROP chain but don't want to allocate
197 // a new instance
198 empty() {
199 this.position = 0;
200 }
201
202 // flag indicating whether .run() was ever called with this chain
203 get is_dirty() {
204 return this._is_dirty;
205 }
206
207 clean() {
208 this._is_dirty = false;
209 }
210
211 dirty() {
212 this._is_dirty = true;
213 }
214
215 check_allow_run() {
216 if (this.position === 0) {
217 throw Error("chain is empty");
218 }
219 if (this.is_dirty) {
220 throw Error("chain already ran, clean it first");
221 }
222 }
223
224 reset() {
225 this.empty();
226 this.clean();
227 }
228
229 get retval_int() {
230 return this._return_value[0] | 0;
231 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected