GithubHelp home page GithubHelp logo

gdt_descriptor_builder's Introduction

GDT Descriptor Builder. Генератор GDT дескриптора

Задача - на основании

  • адреса расположения сегмента в физической памяти
  • размера - лимита сегмента
  • прав (чтение/запись/исполнение)

сформировать GDT дескриптор сегмента в виде hex дампа

Используйте методы класса DescriptorBuilder

  • generate_random для создания рандомного дескриптора
  • make для создания дескриптора по заднным параметрам
  • info для печати информации о дескрипторе
  • make_descriptor_protected_mode для создания дескриптора для работы в protected mode

Примеры использования

builder = DescriptorBuilder() 
# code segment descriptor with base 0x7e00 and limit 0x200, access on RX - read & execute
code_seg_descriptor = builder.make_descriptor_protected_mode(
    base_address=bitarray(f'{0x7e00:0>32b}'),
    limit=bitarray(f'{0x200:0>20b}', endian='big'),
    executable=True,
    readable=True,
    writable=False,
    limit_extended=False
    )   
builder.info(code_seg_descriptor)

# data segment descriptor with base 0x8000 and limit 0x200, access on RW - read & write
data_seg_descriptor = builder.make_descriptor_protected_mode(
    base_address=bitarray(f'{0x8000:0>32b}'),
    limit=bitarray(f'{0x200:0>20b}', endian='big'),
    executable=False,
    readable=True,
    writable=True,
    limit_extended=False
    )
builder.info(data_seg_descriptor)   

# random segment descriptor generator
descriptor = builder.generate_random()
builder.info(descriptor)

Пример результата

=== Descriptor===
Descriptor bin (big-endian): 0000000001000000100110100000000001111110000000000000001000000000
Descriptor hex (big-endian): 00409a007e000200
Descriptor bin (little-endian): 0000000001000000000000000111111000000000010110010000001000000000
Descriptor hex (little-endian): 0002007e009a4000
Descriptor FASM assembler (little-endian): "db 0x00, 0x02, 0x00, 0x7e, 0x00, 0x9a, 0x40, 0x00"
=== Base address ===
Base address bin (big-endian): 00000000000000000111111000000000
Base address hex (big-endian): 00007e00
=== Segment limit ===
Segment limit bin (big-endian): 000000000000001000000000
Segment limit hex (big-endian): 000200
=== Flags bits ===
╒═════╤═════╤═════╤═══════╕
│   GDLAVL │
╞═════╪═════╪═════╪═══════╡
│   0100 │
╘═════╧═════╧═════╧═══════╛
=== Access bits ===
╒═════╤═══════╤═════╤══════════════╤═══════════════════════════╤═════════════════════╤══════════╕
│   PDPLSType(Code) │   Subtype(Not conforming) │   Accessibility(RX) │   Access │
╞═════╪═══════╪═════╪══════════════╪═══════════════════════════╪═════════════════════╪══════════╡
│   1011010 │
│     │     0 │     │              │                           │                     │          │
╘═════╧═══════╧═════╧══════════════╧═══════════════════════════╧═════════════════════╧══════════╛

Ссылки

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.