msn plus脚本读/写内存

发布于 2024-09-27 15:23:26 字数 2091 浏览 2 评论 0原文

我正在使用 MSN Plus 脚本编写内容,它实际上是 javascript。
对于与 Windows 的互操作,有一个名为 Interop 的类。
通过其静态函数Call,我们可以使用最多 12 个参数来调用指定 dll 中的指定函数。
我的目标是编写一个脚本,从 PID 中获取进程名称。
我已经做了所有正确的事情,但它仍然不起作用。

function GetProcNameFromPID(pid)  
{
    var hnd = Interop.Call("kernel32", "CreateToolhelp32Snapshot", 2, 0);
    var handle = Interop.Call("kernel32", "GetCurrentProcess");
    var StructP = Interop.Allocate(4+4+4+4+4+4+4+4+4+260);//*Allocate space for the ProcessEntry32 struct*
    var hnd_ptr = Interop.Allocate(4);
    var ress = Interop.Call("kernel32", "WriteProcessMemory", handle, StructP, StructP.size.DataPtr, 4, hnd_ptr);
    Debug.Trace(ReadInt(hnd_ptr, 0));
    var res = Interop.Call("kernel32", "Process32FirstW", hnd, StructP.DataPtr);
    if(!res)
    {
        Debug.Trace("FAAAAIIIILLLLL / " + Interop.Call("kernel32", "GetLastError") + " / " + ress);
    }
    else
    {
        do
        {
            var pos = 0;
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            var owpid = ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            var parpid = ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            var name = ReadString(pos, 50);
            if(pid == owpid)
                return name;
            StructP = Interop.Allocate(4+4+4+4+4+4+4+8+4+50);
            Interop.Call("kernel32", "WriteProcessMemory", handle, StructP.DataPtr, StructP.size.DataPtr, 4, null);
        }
            while(Interop.Call("kernel32", "Process32NextW", hnd, StructP.DataPtr) == true)
    }
}
function ReadInt(buffer, pos)
{
var res = 0; 
    for(var i = 0; i >> 24;  
    var b2 = addr >> 24;  
    var b3 = addr >> 24;  
    var b4 = addr >> 24;  
    return b4 + b3*256 + b2*256*256 + b1*256*256*256;  
}  

Process32FirstW 函数始终成功,但结构为空。
WriteProcessMemory 函数也成功了。但写入的字节数始终为0。

I'm writing on a MSN Plus script, which is in fact javascript.
For interop with Windows there is a class called Interop.
With its static function Call one can call s specified function in a specified dll with up to 12 arguments.
My goal is to write a script which gets a process name out of the PID.
I've done everything right, but it still doesn't work.

function GetProcNameFromPID(pid)  
{
    var hnd = Interop.Call("kernel32", "CreateToolhelp32Snapshot", 2, 0);
    var handle = Interop.Call("kernel32", "GetCurrentProcess");
    var StructP = Interop.Allocate(4+4+4+4+4+4+4+4+4+260);//*Allocate space for the ProcessEntry32 struct*
    var hnd_ptr = Interop.Allocate(4);
    var ress = Interop.Call("kernel32", "WriteProcessMemory", handle, StructP, StructP.size.DataPtr, 4, hnd_ptr);
    Debug.Trace(ReadInt(hnd_ptr, 0));
    var res = Interop.Call("kernel32", "Process32FirstW", hnd, StructP.DataPtr);
    if(!res)
    {
        Debug.Trace("FAAAAIIIILLLLL / " + Interop.Call("kernel32", "GetLastError") + " / " + ress);
    }
    else
    {
        do
        {
            var pos = 0;
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            var owpid = ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            var parpid = ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            ReadInt(StructP, pos);
            var name = ReadString(pos, 50);
            if(pid == owpid)
                return name;
            StructP = Interop.Allocate(4+4+4+4+4+4+4+8+4+50);
            Interop.Call("kernel32", "WriteProcessMemory", handle, StructP.DataPtr, StructP.size.DataPtr, 4, null);
        }
            while(Interop.Call("kernel32", "Process32NextW", hnd, StructP.DataPtr) == true)
    }
}
function ReadInt(buffer, pos)
{
var res = 0; 
    for(var i = 0; i >> 24;  
    var b2 = addr >> 24;  
    var b3 = addr >> 24;  
    var b4 = addr >> 24;  
    return b4 + b3*256 + b2*256*256 + b1*256*256*256;  
}  

The Process32FirstW function always suceeds, but the struct is empty.
The WriteProcessMemory function suceeds, too. But the number of written bytes is always 0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

楠木可依 2024-10-04 15:23:26

我没有机器来测试东西,但你的第一个问题是你似乎没有通过 WriteProcessMemory 的正确参数:

BOOL WINAPI WriteProcessMemory(
  __in   HANDLE hProcess,
  __in   LPVOID lpBaseAddress,
  __in   LPCVOID lpBuffer,
  __in   SIZE_T nSize,
  __out  SIZE_T *lpNumberOfBytesWritten
);

您正在传递...

handle => hProcess,
StructP => lpBaseAddress, // ???
StructP.size.DataPtr => lpBuffer, // ???
4 => nSize,
hnd_ptr => lpNumberOfBytesWritten

让我们从 WriteProcessMemory 的概述开始:它应该占用一个块当前进程中的数据,由lpBuffer指向,nSize字节长。它将数据复制到 hProcess 指示的进程的内存空间中,并将该数据放置在目标进程中的地址 lpBaseAddress 处。

我在您的代码中看到的问题是:

  1. lpBaseAddress 应该是您正在写入的另一个进程中的地址。由于您的 handle 指向当前进程,我什至不知道您为什么要调用此函数。您只需使用 StructP.WriteWORD(Offset, Data) 将数据写入您的结构。但我现在假设您这样做只是出于最低限度的演示目的 - 看看您是否能让 WriteProcessMemory() 正常工作。

  2. 我认为这甚至不是有效的代码。 StructP.size 存在,但它是一个 int,而不是一个对象< /a>.它没有 DataPtr 成员。 StructP.DataPtr 也存在。事实上,如果您只是指定, StructP.DataPtr 就是发送的内容StructP 根据帮助文件。那么,您是否尝试将结构写回结构,再次作为最低限度的测试?如果是这样,两个指针都应该是 StructP

之后,我不知道您使用的 ReadInt() 函数来自哪里。在我看来,Databloc 有几个用于读取值的成员函数,但您可以这样调用它们: hnd_ptr.ReadWORD(0)

调用 Process32FirstW() 后结构为空,我对此并不感到惊讶,如 它检查 < code>dwSize 结构体成员。由于您没有成功写入它,我预计该值通常为 0,因此不会写入任何数据。

我从来没有摆弄过 Messger Plus,所以请原谅我对这些内容的困惑。让我知道这些是否有用。

I don't have a machine to test things on, but your first issue is you don't appear to be passing the proper parameters to WriteProcessMemory:

BOOL WINAPI WriteProcessMemory(
  __in   HANDLE hProcess,
  __in   LPVOID lpBaseAddress,
  __in   LPCVOID lpBuffer,
  __in   SIZE_T nSize,
  __out  SIZE_T *lpNumberOfBytesWritten
);

You're passing...

handle => hProcess,
StructP => lpBaseAddress, // ???
StructP.size.DataPtr => lpBuffer, // ???
4 => nSize,
hnd_ptr => lpNumberOfBytesWritten

Let's start with an overview of WriteProcessMemory: It's supposed to take a chunk of data in the curent process, pointed to by lpBuffer, nSize bytes long. It copies that data into the memory space of the process indicated by hProcess and places that data at the address lpBaseAddress in that target process.

The problems I see with your code are:

  1. lpBaseAddress should be the address in another process which you are writing to. Since your handle points to the current process, I don't even know why you'd call this function to begin with. You can just use StructP.WriteWORD(Offset, Data) to write data to your structure. But I'll presume for now you're doing this for bare minimum demonstraction purposes — to see if you can get WriteProcessMemory() to work at all.

  2. I don't think this is even valid code. StructP.size exists, but it's an int, not an object. It has no DataPtr member. StructP.DataPtr also exists. In fact, StructP.DataPtr is what is sent if you just specify StructP according to the help file. So are you trying to write from the structure right back to the structure, again, as a minimum test? If so, both pointers should be StructP

Following that, I don't know where the ReadInt() function you are using comes from. It looks to me like Databloc has several member functions for reading values, but you would call them like: hnd_ptr.ReadWORD(0)

I am unsurprised that the structure is empty after calling Process32FirstW(), as it checks the value of the dwSize member of the structure. Since you are not successfully writing to it, I expect that value is normally 0, and hence no data is written.

I've never fiddled with Messger Plus, so you'll have to forgive me a little for being befuddled by a lot of this. Let me know if any of this was useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文