mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-15 10:54:18 +00:00
Compare commits
2 Commits
scroll-pos
...
exploit-fi
Author | SHA1 | Date | |
---|---|---|---|
23f4d22b9b | |||
c3589e3fc4 |
@ -7001,38 +7001,6 @@ PF_CONSOLE_CMD( KI, // Group name
|
||||
|
||||
PF_CONSOLE_GROUP( Python ) // Defines a main command group
|
||||
|
||||
PF_CONSOLE_CMD( Python, // Group name
|
||||
RunFile, // Function name
|
||||
"string filename", // Params
|
||||
"Run the specified Python file program" ) // Help string
|
||||
{
|
||||
// now evaluate this mess they made
|
||||
PyObject* mymod = PythonInterface::FindModule("__main__");
|
||||
// make sure the filename doesn't have the .py extension (import doesn't need it)
|
||||
char importname[200];
|
||||
int i;
|
||||
for (i=0; i<199; i++ )
|
||||
{
|
||||
char ch = ((const char*)params[0])[i];
|
||||
// if we are at the end of the string or at a dot, truncate here
|
||||
if ( ch == '.' || ch == 0 )
|
||||
break;
|
||||
else
|
||||
importname[i] = ((const char*)params[0])[i];
|
||||
}
|
||||
importname[i] = 0;
|
||||
|
||||
// create the line to execute the file
|
||||
char runline[256];
|
||||
sprintf(runline,"import %s", importname);
|
||||
PythonInterface::RunString(runline,mymod);
|
||||
std::string output;
|
||||
// get the messages
|
||||
PythonInterface::getOutputAndReset(&output);
|
||||
PrintString(output.c_str());
|
||||
}
|
||||
|
||||
|
||||
#include "../pfPython/cyMisc.h"
|
||||
|
||||
PF_CONSOLE_CMD( Python, // Group name
|
||||
@ -7074,16 +7042,18 @@ PF_CONSOLE_CMD( Python,
|
||||
"string functions, ...", // Params
|
||||
"Run a cheat command" )
|
||||
{
|
||||
const char* extraParms = "";
|
||||
std::string extraParms;
|
||||
if (numParams > 1)
|
||||
extraParms = params[1];
|
||||
// now evaluate this mess they made
|
||||
PyObject* mymod = PythonInterface::FindModule("__main__");
|
||||
{
|
||||
extraParms = "(";
|
||||
extraParms.append(params[1]);
|
||||
extraParms.append(",)");
|
||||
}
|
||||
else
|
||||
extraParms = "()";
|
||||
|
||||
PythonInterface::RunFunctionSafe("xCheat", params[0], extraParms.c_str());
|
||||
|
||||
// create the line to execute the file
|
||||
char runline[256];
|
||||
sprintf(runline,"import xCheat;xCheat.%s('%s')", (const char*)params[0],extraParms);
|
||||
PythonInterface::RunString(runline,mymod);
|
||||
std::string output;
|
||||
// get the messages
|
||||
PythonInterface::getOutputAndReset(&output);
|
||||
|
@ -308,13 +308,6 @@ void pfGUIMultiLineEditCtrl::SetScrollPosition( Int32 topLine )
|
||||
fDialog->GetHandler()->DoSomething(this);
|
||||
}
|
||||
|
||||
//// GetScrollPosition ///////////////////////////////////////////////////////
|
||||
|
||||
Int32 pfGUIMultiLineEditCtrl::GetScrollPosition()
|
||||
{
|
||||
return fScrollPos;
|
||||
}
|
||||
|
||||
//// MoveCursor - by direction command////////////////////////////////////////////////
|
||||
void pfGUIMultiLineEditCtrl::MoveCursor( Direction dir )
|
||||
{
|
||||
@ -2071,4 +2064,4 @@ void pfGUIMultiLineEditCtrl::DeleteLinesFromTop(int numLines)
|
||||
SetBuffer(buffer, bufferLen);
|
||||
delete [] buffer;
|
||||
return;
|
||||
}
|
||||
}
|
@ -225,7 +225,6 @@ class pfGUIMultiLineEditCtrl : public pfGUIControlMod
|
||||
};
|
||||
|
||||
void SetScrollPosition( Int32 topLine );
|
||||
Int32 GetScrollPosition();
|
||||
void MoveCursor( Direction dir );
|
||||
|
||||
void InsertChar( char c );
|
||||
|
@ -1718,6 +1718,20 @@ void PythonInterface::WriteToStdErr(const char* text)
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* PythonInterface::ImportModule(const char* module)
|
||||
{
|
||||
PyObject* result = nil;
|
||||
PyObject* name = PyString_FromString(module);
|
||||
|
||||
if (name != nil)
|
||||
{
|
||||
result = PyImport_Import(name);
|
||||
Py_DECREF(name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function : FindModule
|
||||
@ -2061,6 +2075,78 @@ hsBool PythonInterface::RunPYC(PyObject* code, PyObject* module)
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function : RunFunction
|
||||
// PARAMETERS : module - module name to run 'name' in
|
||||
// : name - name of function
|
||||
// : args - tuple with arguments
|
||||
//
|
||||
//
|
||||
PyObject* PythonInterface::RunFunction(PyObject* module, const char* name, PyObject* args)
|
||||
{
|
||||
if (module == NULL)
|
||||
return NULL;
|
||||
|
||||
PyObject* function = PyObject_GetAttrString(module, const_cast<char*>(name));
|
||||
|
||||
PyObject* result = NULL;
|
||||
if (function != nil)
|
||||
{
|
||||
result = PyObject_Call(function, args, NULL);
|
||||
Py_DECREF(function);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PyObject* PythonInterface::ParseArgs(const char* args)
|
||||
{
|
||||
PyObject* result = NULL;
|
||||
PyObject* scope = PyDict_New();
|
||||
if (scope)
|
||||
{
|
||||
//- Py_eval_input makes this function accept only single expresion (not statement)
|
||||
//- When using empty scope, functions and classes like 'file' or '__import__' are not visible
|
||||
result = PyRun_String(args, Py_eval_input, scope, NULL);
|
||||
Py_DECREF(scope);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool PythonInterface::RunFunctionSafe(const char* module, const char* function, const char* args)
|
||||
{
|
||||
PyObject* moduleObj = ImportModule(module);
|
||||
bool result = false;
|
||||
if (moduleObj)
|
||||
{
|
||||
PyObject* argsObj = ParseArgs(args);
|
||||
if (argsObj)
|
||||
{
|
||||
PyObject* callResult = RunFunction(moduleObj, function, argsObj);
|
||||
if (callResult)
|
||||
{
|
||||
result = true;
|
||||
Py_DECREF(callResult);
|
||||
}
|
||||
|
||||
Py_DECREF(argsObj);
|
||||
}
|
||||
Py_DECREF(moduleObj);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
PyErr_Print();
|
||||
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function : GetpyKeyFromPython
|
||||
@ -2073,4 +2159,4 @@ pyKey* PythonInterface::GetpyKeyFromPython(PyObject* pkey)
|
||||
if (!pyKey::Check(pkey))
|
||||
return nil;
|
||||
return pyKey::ConvertFrom(pkey);
|
||||
}
|
||||
}
|
||||
|
@ -138,6 +138,8 @@ public:
|
||||
// Writes 'text' to stderr specified in the python interface
|
||||
static void WriteToStdErr(const char* text);
|
||||
|
||||
static PyObject* ImportModule(const char* module);
|
||||
|
||||
// Find module. If it doesn't exist then don't create, return nil.
|
||||
static PyObject* FindModule(char* module);
|
||||
|
||||
@ -219,6 +221,12 @@ public:
|
||||
//
|
||||
static hsBool RunPYC(PyObject* code, PyObject* module);
|
||||
|
||||
static PyObject* RunFunction(PyObject* module, const char* name, PyObject* args);
|
||||
|
||||
static PyObject* ParseArgs(const char* args);
|
||||
|
||||
static bool RunFunctionSafe(const char* module, const char* function, const char* args);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function : GetpyKeyFromPython
|
||||
|
@ -80,30 +80,6 @@ void pyGUIControlMultiLineEdit::SetScrollPosition( Int32 topLine )
|
||||
}
|
||||
}
|
||||
|
||||
Int32 pyGUIControlMultiLineEdit::GetScrollPosition()
|
||||
{
|
||||
if ( fGCkey )
|
||||
{
|
||||
// get the pointer to the modifier
|
||||
pfGUIMultiLineEditCtrl* pbmod = pfGUIMultiLineEditCtrl::ConvertNoRef(fGCkey->ObjectIsLoaded());
|
||||
if ( pbmod )
|
||||
return pbmod->GetScrollPosition();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
hsBool pyGUIControlMultiLineEdit::IsAtEnd()
|
||||
{
|
||||
if ( fGCkey )
|
||||
{
|
||||
// get the pointer to the modifier
|
||||
pfGUIMultiLineEditCtrl* pbmod = pfGUIMultiLineEditCtrl::ConvertNoRef(fGCkey->ObjectIsLoaded());
|
||||
if ( pbmod )
|
||||
return pbmod->ShowingEndOfBuffer();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void pyGUIControlMultiLineEdit::MoveCursor( Int32 dir)
|
||||
{
|
||||
if ( fGCkey )
|
||||
@ -581,4 +557,4 @@ void pyGUIControlMultiLineEdit::SetFontSize( UInt32 fontsize )
|
||||
if ( pbmod )
|
||||
pbmod->SetFontSize((UInt8)fontsize);
|
||||
}
|
||||
}
|
||||
}
|
@ -80,8 +80,6 @@ public:
|
||||
virtual void Clickable( void );
|
||||
virtual void Unclickable( void );
|
||||
virtual void SetScrollPosition( Int32 topLine );
|
||||
virtual Int32 GetScrollPosition();
|
||||
virtual hsBool IsAtEnd();
|
||||
virtual void MoveCursor( Int32 dir );
|
||||
virtual void ClearBuffer( void );
|
||||
virtual void SetText( const char *asciiText );
|
||||
|
@ -87,16 +87,6 @@ PYTHON_METHOD_DEFINITION(ptGUIControlMultiLineEdit, setScrollPosition, args)
|
||||
PYTHON_RETURN_NONE;
|
||||
}
|
||||
|
||||
PYTHON_METHOD_DEFINITION_NOARGS(ptGUIControlMultiLineEdit, getScrollPosition)
|
||||
{
|
||||
return PyLong_FromLong(self->fThis->GetScrollPosition());
|
||||
}
|
||||
|
||||
PYTHON_METHOD_DEFINITION_NOARGS(ptGUIControlMultiLineEdit, isAtEnd)
|
||||
{
|
||||
PYTHON_RETURN_BOOL(self->fThis->IsAtEnd());
|
||||
}
|
||||
|
||||
PYTHON_METHOD_DEFINITION(ptGUIControlMultiLineEdit, moveCursor, args)
|
||||
{
|
||||
long dir;
|
||||
@ -404,8 +394,6 @@ PYTHON_START_METHODS_TABLE(ptGUIControlMultiLineEdit)
|
||||
PYTHON_BASIC_METHOD(ptGUIControlMultiLineEdit, unclickable, "Makes this listbox not clickable by the user.\n"
|
||||
"Useful when just displaying a list that is not really selectable."),
|
||||
PYTHON_METHOD(ptGUIControlMultiLineEdit, setScrollPosition, "Params: topLine\nSets the what line is the top line."),
|
||||
PYTHON_METHOD_NOARGS(ptGUIControlMultiLineEdit, getScrollPosition, "Gets what line is the top line."),
|
||||
PYTHON_METHOD_NOARGS(ptGUIControlMultiLineEdit, isAtEnd, "Returns true if the end of the buffer has been reached."),
|
||||
PYTHON_METHOD(ptGUIControlMultiLineEdit, moveCursor, "Params: direction\nMove the cursor in the specified direction (see PtGUIMultiLineDirection)"),
|
||||
PYTHON_BASIC_METHOD(ptGUIControlMultiLineEdit, clearBuffer, "Clears all text from the multi-line edit control."),
|
||||
PYTHON_METHOD(ptGUIControlMultiLineEdit, setString, "Params: asciiText\nSets the multi-line edit control string."),
|
||||
|
Reference in New Issue
Block a user