flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > HELP: linking asm and c++

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
tutenhamon



Joined: 16 Jan 2010
Posts: 27
Location: Polska (Poland)
tutenhamon
I try link
Code:
format MS COFF

include '..\INCLUDE\MACRO\PROC32.INC'

public getVendorString as '_getVendorString'
public getProcessorString as '_getProcessorString'
public getFeatureFlags as '_getFeatureFlags'
public getCoresIntel as '_getCoresIntel'
public getCoresAMD as '_getCoresAMD'

; bool getVendorString(char* pvendorstr) char pvendorstr[12]
proc getVendorString c uses EDI EBX ECX EDX, pvendorstr

endp

; bool getProcessorString(char* pcpustr) char pcpustr[48] + NULL
proc getProcessorString c uses EDI EBX ECX EDX, pcpustr    
    ret
endp

; bool getFeatureFlags(cpu* pcpu) struct cpu {int flags, int misc, int apic, int signature, int exflags};
proc getFeatureFlags c uses EDI EBX EDX ECX, pcpu

     ret
endp

; int getThreadingIntel()
proc getCoresIntel c uses ECX
       ret
endp

; int getThreadingAMD()
proc getCoresAMD c uses ECX
   
    ret
.AMDSingle:
      xor EAX, EAX
        ret
endp
    


Code:
#ifndef _CPU
#define _CPU
#pragma once

#ifdef __cplusplus 
extern "C" {
#endif

typedef struct
{
int flags;
int misc;
int apic;
int signature;
int exflags;
} CPU, * PCPU;

bool getVendorString(char* pvendorstr);
bool getProcessorString(char* pcpustr);
bool getFeatureFlags(PCPU pcpu);
int getCoresIntel();
int getCoresAMD();

#ifdef __cplusplus 
}
#endif

#endif
    

with a C++ code using MSVC
and link was get me this message

Code:
error LNK2001: unresolved external symbol "bool __cdecl getProcessorString(char *)" (?getProcessorString@@YA_NPAD@Z)
fatal error LNK1120: 1 unresolved externals    

where is the problem?

[EDIT] I swapped the _cplusplus on __cplusplus & update c\c++ code, unedited asn source


Last edited by tutenhamon on 12 Oct 2010, 11:43; edited 3 times in total
Post 27 Sep 2010, 17:43
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Please don't post with option "Disable BBCode in this post" set (check your profile settings, it may be you have set it by default). With the option set, the code tags have no effect and your sources are shown as regular text (without indentation nor highlighting)

The problem is that you are trying to reference C++ externs that is why it is asking you so weirdly decorated names. Try using __cplusplus (notice the double underscore) instead, and if it continues then remove the conditional preprocessing (i.e. force the use of - extern "C" { - always)
Post 27 Sep 2010, 18:00
View user's profile Send private message Reply with quote
tutenhamon



Joined: 16 Jan 2010
Posts: 27
Location: Polska (Poland)
tutenhamon
commenting preprocessor directives does not help ;(
if I don't use precompiled headers the problem does not occur (MSVC 2010 EE)
but the program was crashes
Post 27 Sep 2010, 18:46
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
I think you must define parameter length...
See vid's example: http://flatassembler.net/examples/msvc.zip
Post 28 Sep 2010, 07:27
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
biutshifter: Nay, that would be only if he used stdcall procedures. I think Loco is right, "_cpluscplus" ought to be "__cplusplus". But it is some time since I last interfaced Asm with C++ Smile
Post 28 Sep 2010, 17:34
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
iic2



Joined: 26 Jun 2008
Posts: 123
iic2
Beware that _Avira flag the zip as a virus. Will they ever learn?
Post 28 Sep 2010, 17:58
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
iic2 wrote:
Will they ever learn?

They do. As soon as you hit the "Uninstall" button.
Post 28 Sep 2010, 19:22
View user's profile Send private message Reply with quote
iic2



Joined: 26 Jun 2008
Posts: 123
iic2
I'm crazy about Avira but when it come to even clean written programs in FASM or trying to do some fancy which only ASM that they don't have a clue about, they put you in a fancy class with some bad guy name and flags you as a virus to the world. Now you have to change the structure of your program to satisfy the Anti-Virus writers who use C++. We can't even explore writing manual-PE or come up with new invention with-out getting cursed out. Sometime it make you wonder what the use of programming in ASM for Windows. First you have to get pass Dollar Bill with something special, now you have to fight with somebody high-level program that want to call the shots on your FASM creation. Now we got two bosses, and growing. The only thing left is to kill the use of ASM programs in the next generations of Windows because someone said "bad-bad app bad bad". But my post was not intended to change the OP subject.
Post 28 Sep 2010, 20:27
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Stop using anti-virus software - it is useless.
Post 29 Sep 2010, 05:46
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
But we have to convince the masses of that. You can't just go releasing software and say to the users that they must remove their virus scanner(s) before they can use it.
Post 29 Sep 2010, 05:56
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
... or start writing standard PEs Smile
Post 29 Sep 2010, 09:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
vid wrote:
... or start writing standard PEs Smile
I think you mean only PEs that imitate the style of the most favoured C and C++ compilers. Since there is no such thing as a standard PE file. Note that fasm does generate perfectly valid PE files.
Post 29 Sep 2010, 10:00
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
revolution wrote:
Since there is no such thing as a standard PE file.
Doesn't Microsoft regularly update its MS PE & COFF File Format Specification? It may be regarded as standard as well. Wink
revolution wrote:
Note that fasm does generate perfectly valid PE files.
With regard to you previous statement this seems contradictory: "valid according to what?" Wink
Post 29 Sep 2010, 18:11
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
revolution: OK, "de-facto standard PE", and there is such thing (otherwise AVs couldn't use this heuristics).

baldr wrote:
With regard to you previous statement this seems contradictory: "valid according to what?

Not regularly updated specification is still a specification.
Post 29 Sep 2010, 19:12
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
baldr: Think of it like this:

Spec for a car:
-Must have four wheels
-Must have doors for people to enter/exit
-Must have an engine

A "standard" (i.e. car produced by most popular manufacturers) car:
-Wheels are 22 inch
-Four doors, two in each side with hinges towards the front
-4 cylinder, two values per cylinder

A "valid" car, not "standard", but fits the spec:
-Wheels are 27 inch
-Two gull wing doors
-8 cylinder, 4 valves per cylinder

Note: I just made up the figures above. But I hope it shows the point here: that PE files can still conform to a spec and still differ markedly from the usual PE file.
Post 29 Sep 2010, 21:42
View user's profile Send private message Visit poster's website Reply with quote
tutenhamon



Joined: 16 Jan 2010
Posts: 27
Location: Polska (Poland)
tutenhamon
help, help, help
Post 29 Sep 2010, 21:48
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
tutenhamon, I've just tried and worked properly, are you really doing what I've told you?Very Happy

Anyway, my sources:

TestPad.cpp
Code:
// TestPad.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "tutenhamon.h"


int _tmain(int argc, _TCHAR* argv[])
{
   char buff[256];

   for (int i = 0; i < 256; buff[i++] = '\0'); /* The assembly routines are not really ensuring NUL termination */

   getVendorString(buff);
   printf("%s", buff);
   getchar();
    return 0;
}    
tutenhamon.h (an exact copy of your edited source above)

Then I've compiled your fasm source and used the "Add > Existing Item..." feature to add the object file. All this was a fresh and with all defaults Win32 console application project created with Visual Studio 2010 Professional.

Output of the program:
Code:
AuthenticAMD    
Post 29 Sep 2010, 22:11
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
revolution,

Let's define valid PE as a binary that can be run under whole line of 32-bit Microsoft OS. Is it OK?
Post 30 Sep 2010, 00:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
baldr wrote:
Let's define valid PE as a binary that can be run under whole line of 32-bit Microsoft OS. Is it OK?
No, I think that will not be correct. The Win32 loader will not load all types of valid PE files, it has certain restrictions.

1) The PE spec (that defines a valid PE file) is very broad.
2) The Win32 loader can only load a small portion of all possible valid PE files.
3) The AVs only let pass and even smaller range of PE files than even the Win32 loader will support.

Hence the problem. When writing code in assembly, and wanting to avoid unnecessary AV warnings, then you have to restrict the way in which you create the PE file.
Post 30 Sep 2010, 00:49
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
revolution wrote:
But we have to convince the masses of that. You can't just go releasing software and say to the users that they must remove their virus scanner(s) before they can use it.
Sure you can. Just introduce their systems to virii which bypass their AV scanner. Let them try every possible AV they want. You can make a believer out of them. Wink

_________________
¯\(°_o)/¯ unlicense.org
Post 30 Sep 2010, 01:41
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.