thpatch / thcrap

Touhou Community Reliant Automatic Patcher
https://www.thpatch.net
The Unlicense
558 stars 41 forks source link

Allocate executable memory for binhacks #122

Closed brliron closed 4 years ago

brliron commented 4 years ago

Some modders want to make big binhacks, that don't fit in a few bytes. If would be useful if we could allocate some memory for them.

Proposal syntax:

binhack: {
  "my_binhack" : {
    code: "e9[codecave:my_codecave]",
    addr: "Rx01234567"
  }
},
codecave: {
  my_codecave: "90909090e9[Rx0123456c]"
}

That doesn't sound hard to do. Codecave: just alloc some executable memory and feed it to the binhack parser. Reference in binhacks: keep a list of all codecaves, strcnmp on "codecave:" around or in the func_get call.

ManDude commented 4 years ago

Could also solve potential codecave clashing issues.

32th-System commented 4 years ago

https://github.com/thpatch/thcrap/pull/123 One thing I may change is to change the syntax to not require "code": "..." as that seems redundant

brliron commented 4 years ago

Ok, so... The syntax in c82910ec69c7b87d316f7cb19c2685f31f984160 was

codecave: {
  my_codecave: {
    "code": "90909090e9[Rx0123456c]"
  }
}

and the syntax in b0f392b73571701fb07dcbaacdbe62643c503ccb is now

codecave: {
  my_codecave: "90909090e9[Rx0123456c]"
}

Am I right?

32th-System commented 4 years ago

Yes. (But codecaves don't actually have any addresses. They get allocated and the address that VirtualAlloc decides to give is added to the same functions list that functions like strings_vsprintf get added to)

brliron commented 4 years ago

Ok

If you don't mind, I'll wait until the restructuring fix release before merging.

32th-System commented 4 years ago

Alright