Advertisement
imk0tter

C++ List

Apr 1st, 2023
1,184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include "BackwardsList.h"
  2.  
  3. #include <iostream>
  4.  
  5. long BackwardsList::GetEntry(long index) {
  6.   // TODO: FROG CODE THAT EVALUATES POINTER MORE THAN ONCE (more than one set of
  7.   // brackets)
  8.   long current = this->list_ptr;
  9.   for (long i = 0; i < index; ++i) {
  10.     current = *(long *)current;
  11.   }
  12.   return *(long *)current;
  13. }
  14.  
  15. long BackwardsList::Count() { return ((long *)this->list_ptr)[1]; }
  16.  
  17. BackwardsList::BackwardsList() {
  18.   this->list_ptr = (long)malloc(sizeof(long) * 2);
  19.   *((long *)this->list_ptr) = this->list_ptr;
  20.   ((long *)this->list_ptr)[1] = 0;
  21. }
  22. void BackwardsList::Add(long object_ptr) {
  23.   long new_entry = (long)malloc(sizeof(long) * 2);
  24.   *(long *)new_entry = *(long *)this->list_ptr;
  25.   ((long *)new_entry)[1] = object_ptr;
  26.  
  27.   *(long *)this->list_ptr = new_entry;
  28.   ++((long *)this->list_ptr)[1];
  29. }
  30.  
  31. void BackwardsList::Delete() {
  32.   // TODO: FROG CODE DELETE ALL AT SAME TIME (more than one set of bracket )
  33.   long current = *(long*)this->list_ptr;
  34.   for (int i = 0; i < this->Count(); ++i) {
  35.     long old = current;
  36.     current = *(long *)old; // deobfuscated
  37.     free((long *)old);
  38.   }
  39.   free((long *)list_ptr);
  40.   delete this;
  41. }
  42.  
  43. long BackwardsList::Get(long index) {
  44.   return ((long *)this->GetEntry(index))[1];
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement