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

Class ChainBase

g2all/900/module/chain.js:177–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected