Initial commit

This commit is contained in:
Michael Becker 2024-08-26 23:59:07 -04:00
parent b022ab007f
commit f79118ac31
11 changed files with 373 additions and 0 deletions

View File

@ -0,0 +1,82 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
from editor.ui import EditorApplication
class Program (EditorApplication):
def __init__(self, app_id : str):
EditorApplication.__init__(self, app_id)
if __name__ == '__main__':
#p = Program("net.alcetech.UniversalEditor.python.debug")
#p.start()
from editor.core.io import Reader
r = Reader(open('/home/beckermj/Documents/Projects/mochapowered/mocha-dotnet/mocha-common/mocha-common/output/net.alcetech.Mocha.System.mcl', 'rb'))
m = r.read_fixedstring(4)
version = r.read_single()
flags = r.read_int32()
section_count = r.read_int32()
library_guid = r.read_guid()
print (m)
print ("library GUID: " + str(library_guid))
print ("%d sections" % section_count)
sects = [ ]
guids = [ ]
for i in range(0, section_count):
sect_name = r.read_fixedstring(16)
sect_name = sect_name.strip(' \0')
sect_offset = r.read_int32()
sect_length = r.read_int32()
sect_decompressedLength = r.read_int32()
sect_itemcount = r.read_int32()
sects.append((sect_name, sect_offset, sect_length, sect_decompressedLength, sect_itemcount))
print(" " + sect_name)
for (sect_name, sect_offset, sect_length, sect_decompressedLength, sect_itemcount) in sects:
if sect_name == "GUIDTable":
r.get_stream().seek(sect_offset)
for i in range(0, sect_itemcount):
guids.append(r.read_guid())
elif sect_name == "Relationships":
r.get_stream().seek(sect_offset)
for i in range(0, sect_itemcount):
srci = r.read_int32()
reli = r.read_int32()
tgti = r.read_int32()
srcg = guids[srci]
relg = guids[reli]
tgtg = guids[tgti]
if str(srcg) == '{30fb6ba6-2bbb-41d2-b91a-709c00a07790}':
print ("%s : %s = %s" % (srcg, relg, tgtg))

View File

@ -0,0 +1,20 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
class DataFormat:
pass

View File

@ -0,0 +1,20 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
class ObjectModel:
pass

View File

@ -0,0 +1,26 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
class Encoding:
def __init__(self, value : str):
self._value = value
def get_value() -> str:
return self._value
Encoding.UTF8 = Encoding('utf-8')

View File

@ -0,0 +1,25 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
class Endianness:
def __init__(self, value):
self._value = value
Endianness.LITTLE = Endianness('little')
Endianness.BIG = Endianness('big')

View File

@ -0,0 +1,68 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
from io import FileIO
import struct
from .ReaderWriterBase import ReaderWriterBase
from .Encoding import Encoding
from .Endianness import Endianness
from framework import Guid
class Reader (ReaderWriterBase):
def __init__(self, stream : FileIO):
ReaderWriterBase.__init__(self)
self._stream = stream
def get_stream(self) -> FileIO:
return self._stream
def read_fixedstring(self, length : int, encoding : Encoding = None) -> str:
data = self._stream.read(length)
enc = 'utf-8' if encoding is None else encoding.get_value()
return bytes.decode(data, enc)
def read_single(self) -> float:
data = self._stream.read(4)
if self.get_endianness() == Endianness.LITTLE:
return struct.unpack('<f', data)[0]
elif self.get_endianness() == Endianness.BIG:
return struct.unpack('>f', data)[0]
raise NotImplementedError
def read_int32(self) -> int:
data = self._stream.read(4)
if self.get_endianness() == Endianness.LITTLE:
return struct.unpack('<i', data)[0]
elif self.get_endianness() == Endianness.BIG:
return struct.unpack('>i', data)[0]
raise NotImplementedError
def read_guid(self) -> Guid:
data = self._stream.read(16)
value = Guid.from_bytes(data)
return value

View File

@ -0,0 +1,29 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
from .Endianness import Endianness
class ReaderWriterBase:
def __init__(self) -> None:
self._endianness = Endianness.LITTLE
def get_endianness(self) -> Endianness:
return self._endianness
def set_endianness(self, endianness : Endianness):
self._endianness = endianness

View File

@ -0,0 +1,20 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
from .Endianness import Endianness
from .ReaderWriterBase import ReaderWriterBase
from .Reader import Reader

View File

@ -0,0 +1,39 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
from framework.desktop import DesktopApplication
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from .EditorWindow import EditorWindow
class EditorApplication(DesktopApplication):
def __init__(self, app_id : str):
DesktopApplication.__init__(self, app_id)
def before_start_internal(self):
print ("ok EditorApp")
def activate(self, args):
wnd = EditorWindow()
wnd.show()
self.app.add_window(wnd)

View File

@ -0,0 +1,26 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
from gi.repository import Gtk
from framework.desktop import Window
class EditorWindow (Window):
def on_realize(self, data):
self.set_size_request(1000, 600)
self.set_title("Universal Editor")

View File

@ -0,0 +1,18 @@
# Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
#
# This file is part of editor-python.
#
# editor-python is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# editor-python is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with editor-python. If not, see <https://www.gnu.org/licenses/>.
from .EditorApplication import EditorApplication