Page 1 of 1
Problem: Address is already used by another function
Posted: Mon May 08, 2023 3:33 am
by STpehn
Hi, I had uesd vmp to encrypt cpp project.
I used VMProtectBegin("xxx") / VMProtectEnd() to mark functions
I had marked 100+ functions by doing this way.
When I imported dll into vmp software, and I clicked Compile
While compiling in vmp, I suffered this problem
VMProtectMarker "functionA".18071B842: address is already used by function “ VMProtectMarker "function B"
And When I check the vmp software,
functionA address is:000000018071B842,while function B address is:000000018071B624. So it is stranged for me.
And I also Checked my cpp source code:
function A and functionB are indeed marked with a different string, which means that the parameters passed into the function(VMProtectBegin) are different
I wonder why this happens? Is there anything I can pay attention to or check?
Thanks a lot
Re: Problem: Address is already used by another function
Posted: Tue May 09, 2023 11:39 am
by Admin
Please send us a test example that shows your problem.
Re: Problem: Address is already used by another function
Posted: Thu May 11, 2023 11:34 am
by STpehn
Admin wrote:Please send us a test example that shows your problem.
I can show you the case I mentioned
function A address is Already use by funtion B
function A and function B are both defined in test.cpp
Code: Select all
namespace test
{
int function A()
{
VMProtectBegin("functionA")
.....
VMProtectEnd()
}
void function B()
{
VMProtectBegin("functionB")
...
function A()
VMProtectEnd()
}
}
Then I sufferd this problem
So, Is it normal for this problem to occur? Beacuse At this Solution(Visual Stuido projetc) In function B ,I alse call many function who are protected by VMP but defined in other project;
And Also,I want to know If function A is only called in function B, is there no need to use vmp markersfor function A?
Thanks for your help
Re: Problem: Address is already used by another function
Posted: Thu May 11, 2023 11:45 am
by petko123
I think this happens due to compiler optimization. Compiler is most likely inlines functionA() inside functionB() so that's why VMprotect throws that error. You could explicitly tell to compiler that you don't want functionB() to be inlined by adding __declspec(noinline) before function name, like this
Code: Select all
__declspec(noinline) int function A()
{
VMProtectBegin("functionA")
.....
VMProtectEnd()
}
If you're calling that function multiple times then compiler is most likely not going to inline it so you don't need to worry about it, but if you're only calling it once it's most likely inlined. Hope that helps.
Re: Problem: Address is already used by another function
Posted: Thu May 11, 2023 3:57 pm
by Catharsis
STpehn wrote:Admin wrote:Please send us a test example that shows your problem.
I can show you the case I mentioned
function A address is Already use by funtion B
function A and function B are both defined in test.cpp
Code: Select all
namespace test
{
int function A()
{
VMProtectBegin("functionA")
.....
VMProtectEnd()
}
void function B()
{
VMProtectBegin("functionB")
...
function A()
VMProtectEnd()
}
}
Then I sufferd this problem
So, Is it normal for this problem to occur? Beacuse At this Solution(Visual Stuido projetc) In function B ,I alse call many function who are protected by VMP but defined in other project;
And Also,I want to know If function A is only called in function B, is there no need to use vmp markersfor function A?
Thanks for your help
It looks like your compiler is performing optimization and embedding the body of function A in function B, so the tokens are also nested.
You need to disable this optimization. For example
https://learn.microsoft.com/en-us/cpp/b ... w=msvc-170
Re: Problem: Address is already used by another function
Posted: Fri May 12, 2023 9:45 am
by STpehn
petko123 wrote:I think this happens due to compiler optimization. Compiler is most likely inlines functionA() inside functionB() so that's why VMprotect throws that error. You could explicitly tell to compiler that you don't want functionB() to be inlined by adding __declspec(noinline) before function name, like this
Code: Select all
__declspec(noinline) int function A()
{
VMProtectBegin("functionA")
.....
VMProtectEnd()
}
If you're calling that function multiple times then compiler is most likely not going to inline it so you don't need to worry about it, but if you're only calling it once it's most likely inlined. Hope that helps.
thanks! it do help me to fix this problem
Re: Problem: Address is already used by another function
Posted: Fri May 12, 2023 9:46 am
by STpehn
Catharsis wrote:STpehn wrote:Admin wrote:Please send us a test example that shows your problem.
I can show you the case I mentioned
function A address is Already use by funtion B
function A and function B are both defined in test.cpp
Code: Select all
namespace test
{
int function A()
{
VMProtectBegin("functionA")
.....
VMProtectEnd()
}
void function B()
{
VMProtectBegin("functionB")
...
function A()
VMProtectEnd()
}
}
Then I sufferd this problem
So, Is it normal for this problem to occur? Beacuse At this Solution(Visual Stuido projetc) In function B ,I alse call many function who are protected by VMP but defined in other project;
And Also,I want to know If function A is only called in function B, is there no need to use vmp markersfor function A?
Thanks for your help
It looks like your compiler is performing optimization and embedding the body of function A in function B, so the tokens are also nested.
You need to disable this optimization. For example
https://learn.microsoft.com/en-us/cpp/b ... w=msvc-170
thanks a lot ! I have fixed this problem~