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 sys, struct | |
from ctypes import * | |
libc = cdll.LoadLibrary("libc.so.6") | |
free = libc.free | |
mmap = libc.mmap | |
mmap.restype = c_void_p | |
munmap = libc.munmap | |
munmap.argtype = [c_void_p, c_size_t] |
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
pType = { | |
'NULL' : 0, | |
'LOAD' : 1, | |
'DYNAMIC' : 2, | |
'INTERP' : 3, | |
'NOTE' : 4, | |
'SHLIB' : 5, | |
'PHDR' : 6, | |
'TLS' : 7, | |
'NUM' : 8, |
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
/* Set up a mapping from BFD sections to program segments. */ | |
bfd_boolean | |
_bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info) | |
{ | |
unsigned int count; | |
struct elf_segment_map *m; | |
asection **sections = NULL; | |
const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
bfd_boolean no_user_phdrs; |
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
BITS 64 | |
EXTERN putchar | |
EXTERN exit | |
GLOBAL _start | |
SECTION .text | |
_start: | |
mov edi, 'T' | |
call putchar | |
mov edi, 42 |
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
from Header import Header | |
from elf.Utils import * | |
# ELF header | |
class Eh(Header): | |
org = 0x400000 | |
def getOrg(self): | |
return self.org |
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
from elf.Utils import * | |
from elf.components.headers.Eh import Eh | |
from elf.components.headers.Sh import Sh | |
from elf.components.Section import Section | |
from elf.components.SectionAggregator import SectionAggregator | |
# teardown ELF file | |
f = open('test.out') | |
byteList = map(lambda x: int(ord(x)), f.read()) |
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
ELF Header: | |
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 | |
Class: ELF64 | |
Data: 2's complement, little endian | |
Version: 1 (current) | |
OS/ABI: UNIX - System V | |
ABI Version: 0 | |
Type: EXEC (Executable file) | |
Machine: Advanced Micro Devices X86-64 | |
Version: 0x1 |
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
segment .data | |
switch: dq main.case0 | |
dq main.case1 | |
dq main.case2 | |
i: dq 2 | |
segment .text | |
global main ; tell linker about main | |
main: | |
mov rax, [i] ; move i to rax | |
jmp [switch+rax*8] ; switch(i) |
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
sum = 0; | |
i = 0; | |
while ( i < 64 ) { | |
sum += data & 1; | |
data = data >> 1; | |
i++; | |
} |
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
segment .data | |
data dq 0xfedcba9876543210 | |
sum dq 0 | |
segment .text | |
global main | |
main: | |
push rbp | |
mov rbp, rsp | |
sub rsp, 16 |