YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Loading bytecode from memory?
IndigoFuzz
#1 Posted : Wednesday, August 5, 2020 3:56:17 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/22/2015(UTC)
Posts: 3
Location: United Kingdom

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi there,

I wonder if someone can help me with a nugget of wisdom - I have a pointer to a memory buffer, as well as it's size, and in the memory is compiled squirrel byte code. How can I load this into a squirrel VM and execute it?

I've looked at the sq_readclosure function but can't wrap my head around passing pointers and what not for a custom read function.

Any help would be vastly appreciated :)

Thanks
absence
#2 Posted : Sunday, May 23, 2021 6:58:46 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 141
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)
well, but that's the only valid approach, like so:

Code:

struct arbitrary_readf {
    unsigned char *buf ;
    unsigned char *cur ;
    SQInteger len ;
};

SQInteger sqarbitrary_read(SQUserPointer fstr,SQUserPointer buf,SQInteger size)
{
    arbitrary_readf *blk=(arbitrary_readf*)fstr ;
    if (blk->len < size) size= blk->len ;
    blk->len -= size ;
    memcpy(buf,blk->cur,size) ;
    blk->cur += size ;
    return size ;
}

SQInteger readbuffer(HSQUIRRELVM v,void *ptr,SInteger size)
{
  arbitrary_readf tmp;
  tmp.buf=tmp.cur=(unsigned char*)ptr ;
  tmp.len=size ;
  return SQ_SUCCEEDED(sq_readclosure(v,sqarbitrary_read,(SQUserPointer)&tmp)))
}


Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.176 seconds.