Problem: Address is already used by another function

Issues related to VMProtect
Post Reply
STpehn
Posts: 6
Joined: Thu May 04, 2023 3:14 am

Problem: Address is already used by another function

Post 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
Admin
Site Admin
Posts: 2566
Joined: Mon Aug 21, 2006 8:19 pm
Location: Russia, E-burg
Contact:

Re: Problem: Address is already used by another function

Post by Admin »

Please send us a test example that shows your problem.
STpehn
Posts: 6
Joined: Thu May 04, 2023 3:14 am

Re: Problem: Address is already used by another function

Post 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
petko123
Posts: 1
Joined: Sun Feb 26, 2023 12:17 pm

Re: Problem: Address is already used by another function

Post 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.
Catharsis
Posts: 23
Joined: Tue Sep 22, 2020 5:27 pm

Re: Problem: Address is already used by another function

Post 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
STpehn
Posts: 6
Joined: Thu May 04, 2023 3:14 am

Re: Problem: Address is already used by another function

Post 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
STpehn
Posts: 6
Joined: Thu May 04, 2023 3:14 am

Re: Problem: Address is already used by another function

Post 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~
Post Reply