Jump to content

Simple Block Unpack


Recommended Posts

  • Honorable Member

    So many PServer's packs unpacked with "pack" method. Example

Spoiler

import ui, wndMgr, chat, uiCommon, pack, os

class FileExtractor(ui.ScriptWindow):
	Gui = []
	Errortype = "none"
	
	def __init__(self):
		self.Gui = []
		ui.ScriptWindow.__init__(self)
		self.AddGui()
		
	def __del__(self):
		self.Gui[0].Hide()
		ui.ScriptWindow.__del__(self)
				
	def AddGui(self):
		Gui = [
			[[ui.ThinBoard, ""], [255, 40], [50, wndMgr.GetScreenHeight()-100], [], ["float"]],			
			[[ui.Button, 0], [0, 0], [230, 13], [['SetUpVisual', ["d:/ymir work/ui/public/close_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/close_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/close_button_03.sub"]], ['SetToolTipText', ["Close", 0, - 23]], ['SetEvent', [lambda : self.__del__()]]], []],	
			[[ui.Button, 0], [0, 0], [120, 10], [['SetUpVisual', ["d:/ymir work/ui/public/Large_button_01.sub"]],['SetOverVisual', ["d:/ymir work/ui/public/Large_button_02.sub"]], ['SetDownVisual', ["d:/ymir work/ui/public/Large_button_03.sub"]], ["SetText", ["Cikart"]], ['SetEvent', [lambda : self.ExtractFile()]]], []],			
			[[ui.SlotBar, 0], [87, 18], [15, 10], [], []],			
			[[ui.EditLine, 3], [87, 17], [6, 2], [["SetMax", [15]], ["SetFocus", [""]]], []],			
			]
		GuiParser(Gui, self.Gui)

	def ExtractFile(self):
		script = self.Gui[4].GetText()
		if len(script) == 0:
			return
		add = ""
		if str(script).find("d:/") != -1:
			script = str(script).replace("d:/", "")
			add = "d:/"
		if pack.Exist(add + script):
			if not os.path.exists("Source/" + script):
				os.makedirs("Source/" + script)
			if os.path.exists("Source/" + script):
				if os.path.isfile("Source/" + script):
					os.remove("Source/" + script)
				else:
					os.rmdir("Source/" + script)
			if self.IsBinary(script) == 0:
				lines = pack_open(add + script, "r").readlines()
				f = open("Source/" + script, "a+")		
				for line in lines:
					tokens = line
					f.write(str(tokens))		
				f.close()
			else:
				Binary = pack_open(add + script, 'rb')
				Bytes = Binary.read()
				if len(Bytes) == 0:
					if self.Errortype != "ending":
						self.Errortype = "read"
					return
				else:
					f = open("Source/" + script, "wb")		
					f.write(str(Bytes))		
					f.close()
		else:
			self.Errortype = "exist"
			return
	def IsBinary(self, script):
		if str(script).count(".") == 0:
			self.Errortype = "ending"
			self.ErrorScreen(str(script)+" .")
			script = script + ".binary"
		Split = script.split(".")
		end = str(Split[1])
		end = end.lower()
		
		if end == ".py": 
			return 0 
		else:
			return 1
			
	def ErrorScreen(self, error=""):
		ErrorDialog = uiCommon.PopupDialog()
		ErrorDialog.SetText(error)
		ErrorDialog.SetAcceptEvent(self.__OnCloseErrorDialog)
		ErrorDialog.Open()
		self.ErrorDialog = ErrorDialog
		
	def __OnCloseErrorDialog(self):
		self.pop = None

def GuiParser(guiobjects, list):
	for object in guiobjects:
		Object = object[0][0]()
		if object[0][1] != "":
			Object.SetParent(list[object[0][1]])
		if object[1][0] + object[1][1] != 0:
			Object.SetSize(object[1][0], object[1][1])
		if object[2][0] + object[2][1] != 0:
			Object.SetPosition(object[2][0], object[2][1])
				
		for command in object[3]:
			cmd = command[0]	
			attr = getattr(Object,cmd)			
			if callable(attr):
				argument = command[1]
				lenght = len(argument)
				if lenght == 1:
					if argument[0] == "":
						attr()
					else:
						attr(argument[0])
				elif lenght == 2:
					attr(argument[0], argument[1])
				elif lenght == 3:
					attr(argument[0], argument[1], argument[2])
				elif lenght == 4:
					attr(argument[0], argument[1], argument[2], argument[3])
		for flag in object[4]:
			Object.AddFlag(str(flag))
		Object.Show()
	
		list.append(Object)
		
FileExtractor().Show()

 

What is the pack method?:

    Game is using pack method when load .py, .pyc and .txt files. Just look at the system.py

Spoiler

class pack_file(object):

	def __init__(self, filename, mode = 'rb'):
		assert mode in ('r', 'rb')
		if not pack.Exist(filename):
			raise IOError, 'No file or directory'
		self.data = pack.Get(filename)
		if mode == 'r':
			self.data=_chr(10).join(self.data.split(_chr(13)+_chr(10)))

 

Why Simple?

    Because we'll just change the method name. Gf did like this little changes example: playerm2g2, chatm2g, m2netm2g ....

Go UserInteface/PythonPackModule.cpp and find:

	Py_InitModule("pack", s_methods);

And change "pack" whatever you want. I'm gonna say "examplename"

Go root/system.py and find:

import pack

Change like this;

import examplename as pack

That's all. That was the simplest idea I could think of.

  • Metin2 Dev 3
  • Love 1
  • Love 6

 

Link to comment
Share on other sites

  • Silver
Spoiler
17 minutes ago, Mali61 said:

    So many PServer's packs unpacked with "pack" method. Example

What is the pack method?:

    Game is using pack method when load .py, .pyc and .txt files. Just look at the system.py

Why Simple?

    Because we'll just change the method name. Gf did like this little changes example: playerm2g2, chatm2g, m2netm2g ....

Go UserInteface/PythonPackModule.cpp and find:



	Py_InitModule("pack", s_methods);

And change "pack" whatever you want. I'm gonna say "examplename"

Go root/system.py and find:



import pack

Change like this;



import examplename as pack

That's all. That was the simplest idea I could think of.

It's very simplest idea :3
work well if used along with fix python injection (mode python27.dll file) & check md5 (client files).

Link to comment
Share on other sites

  • 4 weeks later...
  • Honorable Member
8 hours ago, Moț said:

But you are searching directly method name because you know the name. Other users won't know the method name. If you don't trust use like this:

	const char abc [] = { 'p', 'a', 'c', 'k' };
	Py_InitModule(abc, s_methods);

or:

	std::string abc = "p"; abc += "a"; abc += "c"; abc += "k";
	Py_InitModule(abc.c_str(), s_methods);

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 2

 

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.