Skip to content

Conversation

0vercl0k
Copy link
Owner

This PR clang-format the newly added code as well as update the README to mention the Python 3 bindings that @masthoon landed 🥇

diff --git a/src/lib/kdmp-parser-structs.h b/src/lib/kdmp-parser-structs.h
index 51da3af..c53d92e 100644
--- a/src/lib/kdmp-parser-structs.h
+++ b/src/lib/kdmp-parser-structs.h
@@ -194,9 +194,9 @@ static_assert(sizeof(KDMP_PARSER_PHYSMEM_DESC) == 0x20,
               "PHYSICAL_MEMORY_DESCRIPTOR's size looks wrong.");

 struct KDMP_PARSER_BMP_HEADER64 : public DisplayUtils {
-  static const uint32_t ExpectedSignature  = 0x504D4453; // 'PMDS'
+  static const uint32_t ExpectedSignature = 0x504D4453;  // 'PMDS'
   static const uint32_t ExpectedSignature2 = 0x504D4446; // 'PMDF'
-  static const uint32_t ExpectedValidDump  = 0x504D5544; // 'PMUD'
+  static const uint32_t ExpectedValidDump = 0x504D5544;  // 'PMUD'

   //
   // Should be FDMP.
@@ -781,7 +781,6 @@ static_assert(offsetof(KDMP_PARSER_HEADER64, Comment) == 0xfb0,
 static_assert(offsetof(KDMP_PARSER_HEADER64, BmpHeader) == 0x2000,
               "The offset of BmpHeaders looks wrong.");

-
 struct Page {

   //
@@ -803,7 +802,6 @@ struct Page {
   static uint64_t Offset(const uint64_t Address) { return Address & 0xfff; }
 };

-
 //
 // Structure for parsing a PTE.
 //
diff --git a/src/lib/kdmp-parser.cc b/src/lib/kdmp-parser.cc
index 63ace6e..cf25add 100644
--- a/src/lib/kdmp-parser.cc
+++ b/src/lib/kdmp-parser.cc
@@ -92,11 +92,11 @@ const BugCheckParameters_t KernelDumpParser::GetBugCheckParameters() {
   // Give the user a view of the bugcheck parameters.
   //
   BugCheckParameters_t Parameters = {
-    DmpHdr_->BugCheckCode,
-    DmpHdr_->BugCheckCodeParameter[0],
-    DmpHdr_->BugCheckCodeParameter[1],
-    DmpHdr_->BugCheckCodeParameter[2],
-    DmpHdr_->BugCheckCodeParameter[3],
+      DmpHdr_->BugCheckCode,
+      DmpHdr_->BugCheckCodeParameter[0],
+      DmpHdr_->BugCheckCodeParameter[1],
+      DmpHdr_->BugCheckCodeParameter[2],
+      DmpHdr_->BugCheckCodeParameter[3],
   };

   return Parameters;
@@ -233,21 +233,22 @@ bool KernelDumpParser::BuildPhysmemFullDump() {
   return true;
 }

-const uint64_t KernelDumpParser::PhyRead8(const uint64_t PhysicalAddress) const {
-
+const uint64_t
+KernelDumpParser::PhyRead8(const uint64_t PhysicalAddress) const {
+
   //
   // Get the physical page and read from the offset.
   //

-  const uint8_t * PhysicalPage = GetPhysicalPage(Page::Align(PhysicalAddress));
+  const uint8_t *PhysicalPage = GetPhysicalPage(Page::Align(PhysicalAddress));

   if (!PhysicalPage) {
     printf("Internal page table parsing failed!\n");
     return 0;
   }

-  return *reinterpret_cast<const uint64_t*>(PhysicalPage + Page::Offset(PhysicalAddress));
-
+  return *reinterpret_cast<const uint64_t *>(PhysicalPage +
+                                             Page::Offset(PhysicalAddress));
 }

 const Physmem_t &KernelDumpParser::GetPhysmem() { return Physmem_; }
@@ -362,11 +363,13 @@ KernelDumpParser::GetPhysicalPage(const uint64_t PhysicalAddress) const {
   return Pair->second;
 }

-const uint64_t
-KernelDumpParser::VirtTranslate(const uint64_t VirtualAddress, const uint64_t DirectoryTableBase) const {
+const uint64_t
+KernelDumpParser::VirtTranslate(const uint64_t VirtualAddress,
+                                const uint64_t DirectoryTableBase) const {

   //
-  // If DirectoryTableBase is null ; use the one from the dump header and clear PCID bits (bits 11:0).
+  // If DirectoryTableBase is null ; use the one from the dump header and clear
+  // PCID bits (bits 11:0).
   //

   uint64_t LocalDTB = Page::Align(GetDirectoryTableBase());
@@ -393,7 +396,8 @@ KernelDumpParser::VirtTranslate(const uint64_t VirtualAddress, const uint64_t Di
   const uint64_t PdpteGpa = PdptBase + GuestAddress.PdPtIndex * 8;
   const MMPTE_HARDWARE Pdpte(PhyRead8(PdpteGpa));
   if (!Pdpte.Present) {
-    printf("Invalid page directory pointer table, address translation failed!\n");
+    printf(
+        "Invalid page directory pointer table, address translation failed!\n");
     return 0;
   }

@@ -437,15 +441,16 @@ KernelDumpParser::VirtTranslate(const uint64_t VirtualAddress, const uint64_t Di
   return PageBase + GuestAddress.Offset;
 }

-
 const uint8_t *
-KernelDumpParser::GetVirtualPage(const uint64_t VirtualAddress, const uint64_t DirectoryTableBase) const {
-
+KernelDumpParser::GetVirtualPage(const uint64_t VirtualAddress,
+                                 const uint64_t DirectoryTableBase) const {
+
   //
   // First remove offset and translate the virtual address.
   //

-  const uint64_t PhysicalAddress = VirtTranslate(Page::Align(VirtualAddress), DirectoryTableBase);
+  const uint64_t PhysicalAddress =
+      VirtTranslate(Page::Align(VirtualAddress), DirectoryTableBase);

   if (!PhysicalAddress) {
     return nullptr;
diff --git a/src/lib/kdmp-parser.h b/src/lib/kdmp-parser.h
index b3d8610..4acad70 100644
--- a/src/lib/kdmp-parser.h
+++ b/src/lib/kdmp-parser.h
@@ -1,16 +1,16 @@
 // Axel '0vercl0k' Souchet - February 15 2019
 #pragma once

+#include "filemap.h"
 #include "kdmp-parser-structs.h"
 #include <cstdint>
 #include <unordered_map>
-#include "filemap.h"

 using Physmem_t = std::unordered_map<uint64_t, const uint8_t *>;

-struct BugCheckParameters_t {
-  uint32_t BugCheckCode;
-  uint64_t BugCheckCodeParameter[4];
+struct BugCheckParameters_t {
+  uint32_t BugCheckCode;
+  uint64_t BugCheckCodeParameter[4];
 };

 class KernelDumpParser {
@@ -79,16 +79,19 @@ public:
   const uint64_t GetDirectoryTableBase() const;

   //
-  // Translate a virtual address to physical address using a directory table base.
+  // Translate a virtual address to physical address using a directory table
+  // base.
   //

-  const uint64_t VirtTranslate(const uint64_t VirtualAddress, const uint64_t DirectoryTableBase = 0) const;
+  const uint64_t VirtTranslate(const uint64_t VirtualAddress,
+                               const uint64_t DirectoryTableBase = 0) const;

   //
   // Get the content of a virtual address.
   //

-  const uint8_t *GetVirtualPage(const uint64_t VirtualAddress, const uint64_t DirectoryTableBase = 0) const;
+  const uint8_t *GetVirtualPage(const uint64_t VirtualAddress,
+                                const uint64_t DirectoryTableBase = 0) const;

 private:
   //
diff --git a/src/python/python-kdmp.cc b/src/python/python-kdmp.cc
index b7e4130..4682b42 100644
--- a/src/python/python-kdmp.cc
+++ b/src/python/python-kdmp.cc
@@ -1,44 +1,46 @@
 #include "python-kdmp.h"

 //
-// Python Dump instance creation (allocate and initialize kernel dump object with .dmp path).
+// Python Dump instance creation (allocate and initialize kernel dump object
+// with .dmp path).
 //   >>> Dump(filepath)
 //

-PyObject* NewDumpParser(PyTypeObject *Type, PyObject *Args, PyObject *Kwds) {
-
-    //
-    // Allocate and zero PythonDumpParser.
-    //
-    PythonDumpParser *Self = reinterpret_cast<PythonDumpParser*>(Type->tp_alloc(Type, 0));
-    Self->DumpParser = nullptr;
-
-    //
-    // Parse Python argument (expect a string i.e. the file path of the dump).
-    //    *PyErr_Format returns nullptr to raise the exception*
-    //
-
-    char *DumpPath = nullptr;
-    if (!PyArg_ParseTuple(Args,"s", &DumpPath)) {
-        DeleteDumpParser(reinterpret_cast<PyObject*>(Self));
-        return PyErr_Format(PyExc_TypeError, "dump() expected a string");
-    }
-
-    //
-    // Initialize the internal KernelDumpParser and validate the dump file.
-    //
-
-    Self->DumpParser = new KernelDumpParser();
-    if (!Self->DumpParser->Parse(DumpPath)) {
-        DeleteDumpParser(reinterpret_cast<PyObject*>(Self));
-        return PyErr_Format(PyExc_ValueError, "dump() invalid path");
-    }
-
-    //
-    // Return the new instance of PythonDumpParser to Python.
-    //
-
-    return reinterpret_cast<PyObject*>(Self);
+PyObject *NewDumpParser(PyTypeObject *Type, PyObject *Args, PyObject *Kwds) {
+
+  //
+  // Allocate and zero PythonDumpParser.
+  //
+  PythonDumpParser *Self =
+      reinterpret_cast<PythonDumpParser *>(Type->tp_alloc(Type, 0));
+  Self->DumpParser = nullptr;
+
+  //
+  // Parse Python argument (expect a string i.e. the file path of the dump).
+  //    *PyErr_Format returns nullptr to raise the exception*
+  //
+
+  char *DumpPath = nullptr;
+  if (!PyArg_ParseTuple(Args, "s", &DumpPath)) {
+    DeleteDumpParser(reinterpret_cast<PyObject *>(Self));
+    return PyErr_Format(PyExc_TypeError, "dump() expected a string");
+  }
+
+  //
+  // Initialize the internal KernelDumpParser and validate the dump file.
+  //
+
+  Self->DumpParser = new KernelDumpParser();
+  if (!Self->DumpParser->Parse(DumpPath)) {
+    DeleteDumpParser(reinterpret_cast<PyObject *>(Self));
+    return PyErr_Format(PyExc_ValueError, "dump() invalid path");
+  }
+
+  //
+  // Return the new instance of PythonDumpParser to Python.
+  //
+
+  return reinterpret_cast<PyObject *>(Self);
 }

 //
@@ -48,40 +50,37 @@ PyObject* NewDumpParser(PyTypeObject *Type, PyObject *Args, PyObject *Kwds) {

 void DeleteDumpParser(PyObject *Object) {

-    //
-    // Release internal KernelDumpParser object .
-    //
-    PythonDumpParser *Self = reinterpret_cast<PythonDumpParser*>(Object);
+  //
+  // Release internal KernelDumpParser object .
+  //
+  PythonDumpParser *Self = reinterpret_cast<PythonDumpParser *>(Object);

-    if (Self->DumpParser)
-    {
-        delete Self->DumpParser;
-        Self->DumpParser = NULL;
-    }
+  if (Self->DumpParser) {
+    delete Self->DumpParser;
+    Self->DumpParser = NULL;
+  }

-    //
-    // Free type reference and self.
-    //
+  //
+  // Free type reference and self.
+  //

-    PyTypeObject *Type = Py_TYPE(Self);
-    Type->tp_free(Self);
+  PyTypeObject *Type = Py_TYPE(Self);
+  Type->tp_free(Self);
 }

-
-
 //
 // Python Dump instance method to retrieve the DumpType.
 //  >>> dump_instance.type() # return int
 //

-PyObject* DumpParserGetType(PyObject *Object, PyObject *NotUsed) {
+PyObject *DumpParserGetType(PyObject *Object, PyObject *NotUsed) {

-    //
-    // Get the dump type (FullDump, KernelDump or BMPDump).
-    //
+  //
+  // Get the dump type (FullDump, KernelDump or BMPDump).
+  //

-    PythonDumpParser *Self = reinterpret_cast<PythonDumpParser*>(Object);
-    return PyLong_FromUnsignedLong(Self->DumpParser->GetDumpType());
+  PythonDumpParser *Self = reinterpret_cast<PythonDumpParser *>(Object);
+  return PyLong_FromUnsignedLong(Self->DumpParser->GetDumpType());
 }

 //
@@ -89,46 +88,49 @@ PyObject* DumpParserGetType(PyObject *Object, PyObject *NotUsed) {
 //  >>> dump_instance.context() # return dict(str -> int)
 //

-PyObject* DumpParserGetContext(PyObject *Object, PyObject *NotUsed) {
-
-    //
-    // Get the dump context (commons registers).
-    //
-
-    PythonDumpParser *Self = reinterpret_cast<PythonDumpParser*>(Object);
-
-    const KDMP_PARSER_CONTEXT *C = Self->DumpParser->GetContext();
-
-    //
-    // Create a Python dict object with lowercase register name and value.
-    //
-
-    PyObject *Context = PyDict_New();
-
-    PyDict_SetItemString(Context, "rax", PyLong_FromUnsignedLongLong(C->Rax));
-    PyDict_SetItemString(Context, "rbx", PyLong_FromUnsignedLongLong(C->Rbx));
-    PyDict_SetItemString(Context, "rcx", PyLong_FromUnsignedLongLong(C->Rcx));
-    PyDict_SetItemString(Context, "rdx", PyLong_FromUnsignedLongLong(C->Rdx));
-    PyDict_SetItemString(Context, "rsi", PyLong_FromUnsignedLongLong(C->Rsi));
-    PyDict_SetItemString(Context, "rdi", PyLong_FromUnsignedLongLong(C->Rdi));
-    PyDict_SetItemString(Context, "rip", PyLong_FromUnsignedLongLong(C->Rip));
-    PyDict_SetItemString(Context, "rsp", PyLong_FromUnsignedLongLong(C->Rsp));
-    PyDict_SetItemString(Context, "rbp", PyLong_FromUnsignedLongLong(C->Rbp));
-    PyDict_SetItemString(Context, "r8",  PyLong_FromUnsignedLongLong(C->R8));
-    PyDict_SetItemString(Context, "r9",  PyLong_FromUnsignedLongLong(C->R9));
-    PyDict_SetItemString(Context, "r10", PyLong_FromUnsignedLongLong(C->R10));
-    PyDict_SetItemString(Context, "r11", PyLong_FromUnsignedLongLong(C->R11));
-    PyDict_SetItemString(Context, "r12", PyLong_FromUnsignedLongLong(C->R12));
-    PyDict_SetItemString(Context, "r13", PyLong_FromUnsignedLongLong(C->R13));
-    PyDict_SetItemString(Context, "r14", PyLong_FromUnsignedLongLong(C->R14));
-    PyDict_SetItemString(Context, "r15", PyLong_FromUnsignedLongLong(C->R15));
-
-    //
-    //  Get the DirectoryTableBase from the dump and return the created dict to Python.
-    //
-    PyDict_SetItemString(Context, "dtb", PyLong_FromUnsignedLongLong(Self->DumpParser->GetDirectoryTableBase()));
-
-    return Context;
+PyObject *DumpParserGetContext(PyObject *Object, PyObject *NotUsed) {
+
+  //
+  // Get the dump context (commons registers).
+  //
+
+  PythonDumpParser *Self = reinterpret_cast<PythonDumpParser *>(Object);
+
+  const KDMP_PARSER_CONTEXT *C = Self->DumpParser->GetContext();
+
+  //
+  // Create a Python dict object with lowercase register name and value.
+  //
+
+  PyObject *Context = PyDict_New();
+
+  PyDict_SetItemString(Context, "rax", PyLong_FromUnsignedLongLong(C->Rax));
+  PyDict_SetItemString(Context, "rbx", PyLong_FromUnsignedLongLong(C->Rbx));
+  PyDict_SetItemString(Context, "rcx", PyLong_FromUnsignedLongLong(C->Rcx));
+  PyDict_SetItemString(Context, "rdx", PyLong_FromUnsignedLongLong(C->Rdx));
+  PyDict_SetItemString(Context, "rsi", PyLong_FromUnsignedLongLong(C->Rsi));
+  PyDict_SetItemString(Context, "rdi", PyLong_FromUnsignedLongLong(C->Rdi));
+  PyDict_SetItemString(Context, "rip", PyLong_FromUnsignedLongLong(C->Rip));
+  PyDict_SetItemString(Context, "rsp", PyLong_FromUnsignedLongLong(C->Rsp));
+  PyDict_SetItemString(Context, "rbp", PyLong_FromUnsignedLongLong(C->Rbp));
+  PyDict_SetItemString(Context, "r8", PyLong_FromUnsignedLongLong(C->R8));
+  PyDict_SetItemString(Context, "r9", PyLong_FromUnsignedLongLong(C->R9));
+  PyDict_SetItemString(Context, "r10", PyLong_FromUnsignedLongLong(C->R10));
+  PyDict_SetItemString(Context, "r11", PyLong_FromUnsignedLongLong(C->R11));
+  PyDict_SetItemString(Context, "r12", PyLong_FromUnsignedLongLong(C->R12));
+  PyDict_SetItemString(Context, "r13", PyLong_FromUnsignedLongLong(C->R13));
+  PyDict_SetItemString(Context, "r14", PyLong_FromUnsignedLongLong(C->R14));
+  PyDict_SetItemString(Context, "r15", PyLong_FromUnsignedLongLong(C->R15));
+
+  //
+  //  Get the DirectoryTableBase from the dump and return the created dict to
+  //  Python.
+  //
+  PyDict_SetItemString(
+      Context, "dtb",
+      PyLong_FromUnsignedLongLong(Self->DumpParser->GetDirectoryTableBase()));
+
+  return Context;
 }

 //
@@ -136,31 +138,35 @@ PyObject* DumpParserGetContext(PyObject *Object, PyObject *NotUsed) {
 //  >>> dump_instance.bugcheck() # return dict
 //

-PyObject* DumpParserGetBugCheckParameters(PyObject *Object, PyObject *NotUsed) {
+PyObject *DumpParserGetBugCheckParameters(PyObject *Object, PyObject *NotUsed) {

-    //
-    // Retrieve the bugcheck parameters.
-    //
+  //
+  // Retrieve the bugcheck parameters.
+  //

-    PythonDumpParser *Self = reinterpret_cast<PythonDumpParser*>(Object);
+  PythonDumpParser *Self = reinterpret_cast<PythonDumpParser *>(Object);

-    const BugCheckParameters_t Parameters = Self->DumpParser->GetBugCheckParameters();
+  const BugCheckParameters_t Parameters =
+      Self->DumpParser->GetBugCheckParameters();

-    PyObject *PythonParamsList = PyList_New(4);
+  PyObject *PythonParamsList = PyList_New(4);

-    for (uint64_t idx = 0; idx < 4; idx++)
-        PyList_SetItem(PythonParamsList, idx, PyLong_FromUnsignedLongLong(Parameters.BugCheckCodeParameter[idx]));
+  for (uint64_t idx = 0; idx < 4; idx++)
+    PyList_SetItem(
+        PythonParamsList, idx,
+        PyLong_FromUnsignedLongLong(Parameters.BugCheckCodeParameter[idx]));

-    //
-    // Create a Python dict object with code and parameters.
-    //
+  //
+  // Create a Python dict object with code and parameters.
+  //

-    PyObject *PythonParams = PyDict_New();
+  PyObject *PythonParams = PyDict_New();

-    PyDict_SetItemString(PythonParams, "code", PyLong_FromUnsignedLong(Parameters.BugCheckCode));
-    PyDict_SetItemString(PythonParams, "parameters", PythonParamsList);
+  PyDict_SetItemString(PythonParams, "code",
+                       PyLong_FromUnsignedLong(Parameters.BugCheckCode));
+  PyDict_SetItemString(PythonParams, "parameters", PythonParamsList);

-    return PythonParams;
+  return PythonParams;
 }

 //
@@ -168,62 +174,69 @@ PyObject* DumpParserGetBugCheckParameters(PyObject *Object, PyObject *NotUsed) {
 //  >>> dump_instance.get_physical_page(addr) # return bytes
 //

-PyObject* DumpParserGetPhysicalPage(PyObject *Object, PyObject *Args) {
+PyObject *DumpParserGetPhysicalPage(PyObject *Object, PyObject *Args) {

-    //
-    // Parse Python argument (expect one unsigned long long integer).
-    //
+  //
+  // Parse Python argument (expect one unsigned long long integer).
+  //

-    PythonDumpParser *Self = reinterpret_cast<PythonDumpParser*>(Object);
+  PythonDumpParser *Self = reinterpret_cast<PythonDumpParser *>(Object);

-    uint64_t PhysicalAddress = 0;
-    if (!PyArg_ParseTuple(Args, "K", &PhysicalAddress)) {
-        return PyErr_Format(PyExc_TypeError, "get_physical_page() expected an integer");
-    }
+  uint64_t PhysicalAddress = 0;
+  if (!PyArg_ParseTuple(Args, "K", &PhysicalAddress)) {
+    return PyErr_Format(PyExc_TypeError,
+                        "get_physical_page() expected an integer");
+  }

-    //
-    // Get the physical page and return it as bytes.
-    //
+  //
+  // Get the physical page and return it as bytes.
+  //

-    const uint8_t *Page = Self->DumpParser->GetPhysicalPage(PhysicalAddress);
+  const uint8_t *Page = Self->DumpParser->GetPhysicalPage(PhysicalAddress);

-    if (!Page) {
-        return PyErr_Format(PyExc_ValueError, "get_physical_page() invalid address");
-    }
+  if (!Page) {
+    return PyErr_Format(PyExc_ValueError,
+                        "get_physical_page() invalid address");
+  }

-    return PyBytes_FromStringAndSize(reinterpret_cast<const char*>(Page), Page::Size);
+  return PyBytes_FromStringAndSize(reinterpret_cast<const char *>(Page),
+                                   Page::Size);
 }

 //
-//  Python Dump instance method to perform address translation (physical to virtual).
+//  Python Dump instance method to perform address translation (physical to
+//  virtual).
 //  >>> dump_instance.virt_translate(addr, [dtb]) # return int
 //

-PyObject* DumpParserVirtTranslate(PyObject *Object, PyObject *Args) {
+PyObject *DumpParserVirtTranslate(PyObject *Object, PyObject *Args) {

-    //
-    // Parse Python argument (expect one or two unsigned long long integer).
-    //
+  //
+  // Parse Python argument (expect one or two unsigned long long integer).
+  //

-    PythonDumpParser *Self = reinterpret_cast<PythonDumpParser*>(Object);
+  PythonDumpParser *Self = reinterpret_cast<PythonDumpParser *>(Object);

-    uint64_t VirtualAddress = 0;
-    uint64_t DirectoryTableBase = 0;
-    if (!PyArg_ParseTuple(Args, "K|K", &VirtualAddress, &DirectoryTableBase)) {
-        return PyErr_Format(PyExc_TypeError, "translate_address() expected one or two integer");
-    }
+  uint64_t VirtualAddress = 0;
+  uint64_t DirectoryTableBase = 0;
+  if (!PyArg_ParseTuple(Args, "K|K", &VirtualAddress, &DirectoryTableBase)) {
+    return PyErr_Format(PyExc_TypeError,
+                        "translate_address() expected one or two integer");
+  }

-    //
-    // Retrieve the physical address (parse pages tables in the dump).
-    //
+  //
+  // Retrieve the physical address (parse pages tables in the dump).
+  //

-    const uint64_t PhysicalAddress = Self->DumpParser->VirtTranslate(VirtualAddress, DirectoryTableBase);
+  const uint64_t PhysicalAddress =
+      Self->DumpParser->VirtTranslate(VirtualAddress, DirectoryTableBase);

-    if (!PhysicalAddress) {
-        return PyErr_Format(PyExc_ValueError, "translate_address() invalid address");
-    }
+  if (!PhysicalAddress) {
+    return PyErr_Format(PyExc_ValueError,
+                        "translate_address() invalid address");
+  }

-    return PyLong_FromUnsignedLongLong(PhysicalAddress);
+  return PyLong_FromUnsignedLongLong(PhysicalAddress);
 }

 //
@@ -231,79 +244,81 @@ PyObject* DumpParserVirtTranslate(PyObject *Object, PyObject *Args) {
 //  >>> dump_instance.get_virtual_page(addr, [dtb]) # return bytes
 //

-PyObject* DumpParserGetVirtualPage(PyObject *Object, PyObject *Args) {
+PyObject *DumpParserGetVirtualPage(PyObject *Object, PyObject *Args) {

-    //
-    // Parse Python argument (expect one or two unsigned long long integer).
-    //
+  //
+  // Parse Python argument (expect one or two unsigned long long integer).
+  //

-    PythonDumpParser *Self = reinterpret_cast<PythonDumpParser*>(Object);
+  PythonDumpParser *Self = reinterpret_cast<PythonDumpParser *>(Object);

-    uint64_t VirtualAddress = 0;
-    uint64_t DirectoryTableBase = 0;
-    if (!PyArg_ParseTuple(Args, "K|K", &VirtualAddress, &DirectoryTableBase)) {
-        return PyErr_Format(PyExc_TypeError, "get_virtual_page() expected one or two integer");
-    }
+  uint64_t VirtualAddress = 0;
+  uint64_t DirectoryTableBase = 0;
+  if (!PyArg_ParseTuple(Args, "K|K", &VirtualAddress, &DirectoryTableBase)) {
+    return PyErr_Format(PyExc_TypeError,
+                        "get_virtual_page() expected one or two integer");
+  }

-    const uint8_t *Page = Self->DumpParser->GetVirtualPage(VirtualAddress, DirectoryTableBase);
+  const uint8_t *Page =
+      Self->DumpParser->GetVirtualPage(VirtualAddress, DirectoryTableBase);

-    if (!Page) {
-        return PyErr_Format(PyExc_ValueError, "get_virtual_page() invalid address");
-    }
+  if (!Page) {
+    return PyErr_Format(PyExc_ValueError, "get_virtual_page() invalid address");
+  }

-    return PyBytes_FromStringAndSize(reinterpret_cast<const char*>(Page), Page::Size);
+  return PyBytes_FromStringAndSize(reinterpret_cast<const char *>(Page),
+                                   Page::Size);
 }

 //
 // KDMP Module initialization function.
 //

-PyMODINIT_FUNC
-PyInit_kdmp(void)
-{
-
-    //
-    // Initialize python.
-    //
-
-    Py_Initialize();
-
-    //
-    // Register PythonDumpParserType.
-    //
-
-	if(PyType_Ready(&PythonDumpParserType) < 0)
-		return nullptr;
-
-    //
-    // Expose the kdmp module.
-    //
-
-    PyObject *Module = PyModule_Create(&KDMPModule);
-    if (!Module) {
-        return nullptr;
-    }
-
-    //
-    // Expose the PythonDumpParserType to Python in kdmp module.
-    //  >>> kdmp.Dump class
-    //
-
-    Py_INCREF(&PythonDumpParserType);
-    if (PyModule_AddObject(Module, "Dump", (PyObject *)&PythonDumpParserType) < 0) {
-        Py_DECREF(&PythonDumpParserType);
-        Py_DECREF(Module);
-        return NULL;
-    }
-
-    //
-    // Expose DumpType constants to Python.
-    //  >>> kdmp.FullDump ...
-    //
-
-    PyModule_AddIntConstant(Module, "FullDump",     DumpType_t::FullDump);
-    PyModule_AddIntConstant(Module, "KernelDump",   DumpType_t::KernelDump);
-    PyModule_AddIntConstant(Module, "BMPDump",      DumpType_t::BMPDump);
-
-    return Module;
+PyMODINIT_FUNC PyInit_kdmp(void) {
+
+  //
+  // Initialize python.
+  //
+
+  Py_Initialize();
+
+  //
+  // Register PythonDumpParserType.
+  //
+
+  if (PyType_Ready(&PythonDumpParserType) < 0)
+    return nullptr;
+
+  //
+  // Expose the kdmp module.
+  //
+
+  PyObject *Module = PyModule_Create(&KDMPModule);
+  if (!Module) {
+    return nullptr;
+  }
+
+  //
+  // Expose the PythonDumpParserType to Python in kdmp module.
+  //  >>> kdmp.Dump class
+  //
+
+  Py_INCREF(&PythonDumpParserType);
+  if (PyModule_AddObject(Module, "Dump", (PyObject *)&PythonDumpParserType) <
+      0) {
+    Py_DECREF(&PythonDumpParserType);
+    Py_DECREF(Module);
+    return NULL;
+  }
+
+  //
+  // Expose DumpType constants to Python.
+  //  >>> kdmp.FullDump ...
+  //
+
+  PyModule_AddIntConstant(Module, "FullDump", DumpType_t::FullDump);
+  PyModule_AddIntConstant(Module, "KernelDump", DumpType_t::KernelDump);
+  PyModule_AddIntConstant(Module, "BMPDump", DumpType_t::BMPDump);
+
+  return Module;
 }
diff --git a/src/python/python-kdmp.h b/src/python/python-kdmp.h
index 6152e38..795f2e2 100644
--- a/src/python/python-kdmp.h
+++ b/src/python/python-kdmp.h
@@ -2,8 +2,8 @@

 #define PY_SSIZE_T_CLEAN

-#include <Python.h>
 #include "kdmp-parser.h"
+#include <Python.h>

 #if PY_MINOR_VERSION >= 8
 #define IS_PY3_8 1
@@ -16,103 +16,106 @@
 //

 typedef struct {
-    PyObject_HEAD
-    KernelDumpParser* DumpParser;
+  PyObject_HEAD KernelDumpParser *DumpParser;
 } PythonDumpParser;

 //
-// Python Dump type functions declarations (class instance creation and instance destruction).
+// Python Dump type functions declarations (class instance creation and instance
+// destruction).
 //

-PyObject* NewDumpParser(PyTypeObject *Type, PyObject *Args, PyObject *Kwds);
+PyObject *NewDumpParser(PyTypeObject *Type, PyObject *Args, PyObject *Kwds);
 void DeleteDumpParser(PyObject *Object);

 //
 // Python Dump object methods functions declarations.
 //

-PyObject* DumpParserGetType(PyObject *Object, PyObject *NotUsed);
-PyObject* DumpParserGetContext(PyObject *Object, PyObject *NotUsed);
-PyObject* DumpParserGetPhysicalPage(PyObject *Object, PyObject *Args);
-PyObject* DumpParserVirtTranslate(PyObject *Object, PyObject *Args);
-PyObject* DumpParserGetVirtualPage(PyObject *Object, PyObject *Args);
-PyObject* DumpParserGetBugCheckParameters(PyObject *Object, PyObject *NotUsed);
+PyObject *DumpParserGetType(PyObject *Object, PyObject *NotUsed);
+PyObject *DumpParserGetContext(PyObject *Object, PyObject *NotUsed);
+PyObject *DumpParserGetPhysicalPage(PyObject *Object, PyObject *Args);
+PyObject *DumpParserVirtTranslate(PyObject *Object, PyObject *Args);
+PyObject *DumpParserGetVirtualPage(PyObject *Object, PyObject *Args);
+PyObject *DumpParserGetBugCheckParameters(PyObject *Object, PyObject *NotUsed);

 //
 // Object methods of Python Dump type.
 //

-
 PyMethodDef DumpObjectMethod[] = {
-    {"type",              DumpParserGetType,                METH_NOARGS,    "Show Dump Type (FullDump, KernelDump)"},
-    {"context",           DumpParserGetContext,             METH_NOARGS,    "Get Register Context"},
-    {"get_physical_page", DumpParserGetPhysicalPage,        METH_VARARGS,   "Get Physical Page Content"},
-    {"virt_translate",    DumpParserVirtTranslate,          METH_VARARGS,   "Translate Virtual to Physical Address"},
-    {"get_virtual_page",  DumpParserGetVirtualPage,         METH_VARARGS,   "Get Virtual Page Content"},
-    {"bugcheck",          DumpParserGetBugCheckParameters,  METH_NOARGS,    "Get BugCheck Parameters"},
-    {nullptr, nullptr, 0, nullptr}
-};
+    {"type", DumpParserGetType, METH_NOARGS,
+     "Show Dump Type (FullDump, KernelDump)"},
+    {"context", DumpParserGetContext, METH_NOARGS, "Get Register Context"},
+    {"get_physical_page", DumpParserGetPhysicalPage, METH_VARARGS,
+     "Get Physical Page Content"},
+    {"virt_translate", DumpParserVirtTranslate, METH_VARARGS,
+     "Translate Virtual to Physical Address"},
+    {"get_virtual_page", DumpParserGetVirtualPage, METH_VARARGS,
+     "Get Virtual Page Content"},
+    {"bugcheck", DumpParserGetBugCheckParameters, METH_NOARGS,
+     "Get BugCheck Parameters"},
+    {nullptr, nullptr, 0, nullptr}};

 //
-// Define PythonDumpParserType (size, name, initialization & destruction functions and object methods).
+// Define PythonDumpParserType (size, name, initialization & destruction
+// functions and object methods).
 //

 static PyTypeObject PythonDumpParserType = {
-    PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "kdmp.Dump",                        /* tp_name */
-    sizeof(PythonDumpParser),           /* tp_basicsize */
-    0,                                  /* tp_itemsize */
-    DeleteDumpParser,                   /* tp_dealloc */
+    PyVarObject_HEAD_INIT(&PyType_Type, 0) "kdmp.Dump", /* tp_name */
+    sizeof(PythonDumpParser),                           /* tp_basicsize */
+    0,                                                  /* tp_itemsize */
+    DeleteDumpParser,                                   /* tp_dealloc */
 #if IS_PY3_8
-    0,                                  /* tp_vectorcall_offset */
+    0, /* tp_vectorcall_offset */
 #else
-    nullptr,                            /* tp_print */
+    nullptr, /* tp_print */
 #endif
-    nullptr,                            /* tp_getattr */
-    nullptr,                            /* tp_setattr */
-    nullptr,                            /* tp_compare */
-    nullptr,                            /* tp_repr */
-    nullptr,                            /* tp_as_number */
-    nullptr,                            /* tp_as_sequence */
-    nullptr,                            /* tp_as_mapping */
-    nullptr,                            /* tp_hash */
-    nullptr,                            /* tp_call */
-    nullptr,                            /* tp_str */
-    nullptr,                            /* tp_getattro */
-    nullptr,                            /* tp_setattro */
-    nullptr,                            /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT,                 /* tp_flags */
-    "Dump object",                      /* tp_doc */
-    nullptr,                            /* tp_traverse */
-    nullptr,                            /* tp_clear */
-    nullptr,                            /* tp_richcompare */
-    0,                                  /* tp_weaklistoffset */
-    nullptr,                            /* tp_iter */
-    nullptr,                            /* tp_iternext */
-    DumpObjectMethod,                   /* tp_methods */
-    nullptr,                            /* tp_members */
-    nullptr,                            /* tp_getset */
-    nullptr,                            /* tp_base */
-    nullptr,                            /* tp_dict */
-    nullptr,                            /* tp_descr_get */
-    nullptr,                            /* tp_descr_set */
-    0,                                  /* tp_dictoffset */
-    nullptr,                            /* tp_init */
-    nullptr,                            /* tp_alloc */
-    NewDumpParser,                      /* tp_new */
-    nullptr,                            /* tp_free */
-    nullptr,                            /* tp_is_gc */
-    nullptr,                            /* tp_bases */
-    nullptr,                            /* tp_mro */
-    nullptr,                            /* tp_cache */
-    nullptr,                            /* tp_subclasses */
-    nullptr,                            /* tp_weaklist */
-    nullptr,                            /* tp_del */
-    0,                                  /* tp_version_tag */
-    nullptr,                            /* tp_finalize */
+    nullptr,            /* tp_getattr */
+    nullptr,            /* tp_setattr */
+    nullptr,            /* tp_compare */
+    nullptr,            /* tp_repr */
+    nullptr,            /* tp_as_number */
+    nullptr,            /* tp_as_sequence */
+    nullptr,            /* tp_as_mapping */
+    nullptr,            /* tp_hash */
+    nullptr,            /* tp_call */
+    nullptr,            /* tp_str */
+    nullptr,            /* tp_getattro */
+    nullptr,            /* tp_setattro */
+    nullptr,            /* tp_as_buffer */
+    Py_TPFLAGS_DEFAULT, /* tp_flags */
+    "Dump object",      /* tp_doc */
+    nullptr,            /* tp_traverse */
+    nullptr,            /* tp_clear */
+    nullptr,            /* tp_richcompare */
+    0,                  /* tp_weaklistoffset */
+    nullptr,            /* tp_iter */
+    nullptr,            /* tp_iternext */
+    DumpObjectMethod,   /* tp_methods */
+    nullptr,            /* tp_members */
+    nullptr,            /* tp_getset */
+    nullptr,            /* tp_base */
+    nullptr,            /* tp_dict */
+    nullptr,            /* tp_descr_get */
+    nullptr,            /* tp_descr_set */
+    0,                  /* tp_dictoffset */
+    nullptr,            /* tp_init */
+    nullptr,            /* tp_alloc */
+    NewDumpParser,      /* tp_new */
+    nullptr,            /* tp_free */
+    nullptr,            /* tp_is_gc */
+    nullptr,            /* tp_bases */
+    nullptr,            /* tp_mro */
+    nullptr,            /* tp_cache */
+    nullptr,            /* tp_subclasses */
+    nullptr,            /* tp_weaklist */
+    nullptr,            /* tp_del */
+    0,                  /* tp_version_tag */
+    nullptr,            /* tp_finalize */
 #if IS_PY3_8
-    nullptr,                            /* tp_vectorcall */
-    0,                                  /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
+    nullptr, /* tp_vectorcall */
+    0, /* bpo-37250: kept for backwards compatibility in CPython 3.8 only */
 #endif
 };

@@ -121,15 +124,15 @@ static PyTypeObject PythonDumpParserType = {
 //

 static struct PyModuleDef KDMPModule = {
-    PyModuleDef_HEAD_INIT,      /* m_base */
-    "kdmp",                     /* m_name */
-    nullptr,                    /* m_doc */
-    -1,                         /* m_size */
-    nullptr,                    /* m_methods */
-    nullptr,                    /* m_slots */
-    nullptr,                    /* m_traverse */
-    nullptr,                    /* m_clear */
-    nullptr,                    /* m_free */
+    PyModuleDef_HEAD_INIT, /* m_base */
+    "kdmp",                /* m_name */
+    nullptr,               /* m_doc */
+    -1,                    /* m_size */
+    nullptr,               /* m_methods */
+    nullptr,               /* m_slots */
+    nullptr,               /* m_traverse */
+    nullptr,               /* m_clear */
+    nullptr,               /* m_free */
 };

 //
@0vercl0k 0vercl0k merged commit 044cda9 into master Aug 11, 2020
@0vercl0k 0vercl0k deleted the fbl_formating branch August 11, 2020 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant