Last active
April 14, 2023 06:21
-
-
Save boomanaiden154/033fd53164dd22057e23c0827e00bceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import sys | |
if __name__ == "__main__": | |
with open(sys.argv[1], mode="rb") as dataFile: | |
previousAddress = 0 | |
while(currentAddress := dataFile.read(8)): | |
(decodedAddress,) = struct.unpack("q", currentAddress) | |
difference = decodedAddress - previousAddress | |
if difference != 2097152: | |
print(difference) | |
previousAddress = decodedAddress | |
print(previousAddress) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text | |
.globl main # -- Begin function main | |
main: # @main | |
# get starting location of code, round down to page boundary | |
movq $main, %rsi | |
shrq $12, %rsi | |
shlq $12, %rsi | |
# address to start unmap at | |
movq $0, %rdi | |
# code for sys_unmap | |
movq $11, %rax | |
syscall | |
# unmap everything after the end of the function | |
# calculate the address | |
movq $.Lfunc_end0, %rdi | |
addq $4096, %rdi | |
addq $4096, %rdi | |
shrq $12, %rdi | |
shlq $12, %rdi | |
# unmap up to one page below an address near the height of the | |
# user-space virtual memory by setting the length argument | |
# to (height of VM - start address) | |
movq $0x0000700000000000, %rsi | |
subq %rdi, %rsi | |
movq $11, %rax | |
syscall | |
movq $58720256, %r13 # loop through this many times | |
movq $0, %r12 # start out at this address + 2097152 | |
map_more_memory: | |
addq $2097152, %r12 | |
subq $1, %r13 | |
cmpq $0, %r13 | |
je end | |
# test mapping some memory | |
movq %r12, %rdi | |
movq $4096, %rsi # length of section to map | |
movq $0x1, %rdx # PROT_READ | |
orq $0x2, %rdx # PROT_WRITE | |
movq $32, %r10 # MAP_ANON | |
orq $1048576, %r10 # MAP_FIXED_NOREPLACE | |
orq $2, %r10 # MAP_PRIVATE | |
xorq %r8, %r8 # no file descriptor | |
xorq %r9, %r9 # no offset within a file | |
movq $9, %rax # mmap system call code | |
syscall | |
test %rax, %rax | |
js map_more_memory # jump if the value is negative | |
movq %rax, (%rax) | |
# use write syscall to print to stdout | |
movq $8, %rdx # number of bytes to print | |
movq %rax, %rsi # buffer to print from | |
movq $1, %rdi # file handle, 1 is stdout | |
movq $1, %rax # system call 1 is write | |
syscall | |
# unmap the memory we just mapped so we don't run into ulimit issues | |
movq %r12, %rdi # address | |
movq $4096, %rsi # length | |
movq $11, %rax # 11 is munmap system call number | |
syscall | |
# handle looping through mmap | |
jmp map_more_memory | |
end: | |
# exit with code 0 | |
movl $60, %eax | |
movl $0, %edi | |
syscall | |
.Lfunc_end0: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment