ispete Posted July 15, 2012 Share Posted July 15, 2012 Being a beginner, I wasn't aware that you could even inline ASM into a c++ program until I checked out this keygen challenge and saw the keygen code written by Reaction: http://forum.tuts4yo...-1/page__st__20 I copied the asm portion of Reaction's code into Visual C++ and it compiled and ran fine. However, I'm trying to use the same code in Xcode on a Macbook Pro running OS X 10.6.8, and I'm getting some errors. I don't know if it's differences in syntax or maybe I need to define some things. I'm attaching a screenshot of the errors with the code. Any help is appreciated! Link to comment
ghandi Posted July 16, 2012 Share Posted July 16, 2012 (edited) I would seriously use Google to search for information first...You are trying to paste MASM syntax assembler into X-Code, which from what i'm reading is GCC syntax, like trying to put Delphi code into Visual Basic.http://www.ibiblio.o...mbly-HOWTO.htmlAlso, apparently there is a compiler switch to tell GCC to use intel syntax assembler, how effective though will be an exercise for you to find out:.intel_syntaxhttp://www.reversing.be/article.php?story=20051203194931893HR,Ghandi Edited July 16, 2012 by ghandi Link to comment
ispete Posted July 16, 2012 Author Share Posted July 16, 2012 Thank you, I will read through that last link. Also, I only post questions when I'm "googled" out. In fact, I visited the HOW-To link you provided before I even posted my question. I'm still trying to understand as much of it as I can. It seemed to me, the more I read, that the syntax I was using would work on macs utilizing an intel chipset.Also, the code would compile fine when I tried writing some simple assembly code like "xor eax,eax" and "mov al,bl". I only get the errors when trying to use things like "Dword ptr ds:[]".I'll continue reading. Thanks again. Link to comment
ghandi Posted July 16, 2012 Share Posted July 16, 2012 This is taken from the HOWTO website, it explains exactly what you are talking about: 3. GCC Assembler Syntax.GCC, the GNU C Compiler for Linux, uses AT&T/UNIX assembly syntax. Here we’ll be using AT&T syntax for assembly coding. Don’t worry if you are not familiar with AT&T syntax, I will teach you. This is quite different from Intel syntax. I shall give the major differences.Source-Destination Ordering. The direction of the operands in AT&T syntax is opposite to that of Intel. In Intel syntax the first operand is the destination, and the second operand is the source whereas in AT&T syntax the first operand is the source and the second operand is the destination. ie, "Op-code dst src" in Intel syntax changes to "Op-code src dst" in AT&T syntax. Register Naming. Register names are prefixed by % ie, if eax is to be used, write %eax. Immediate Operand. AT&T immediate operands are preceded by ’$’. For static "C" variables also prefix a ’$’. In Intel syntax, for hexadecimal constants an ’h’ is suffixed, instead of that, here we prefix ’0x’ to the constant. So, for hexadecimals, we first see a ’$’, then ’0x’ and finally the constants. Operand Size. In AT&T syntax the size of memory operands is determined from the last character of the op-code name. Op-code suffixes of ’b’, ’w’, and ’l’ specify byte(8-bit), word(16-bit), and long(32-bit) memory references. Intel syntax accomplishes this by prefixing memory operands (not the op-codes) with ’byte ptr’, ’word ptr’, and ’dword ptr’. Thus, Intel "mov al, byte ptr foo" is "movb foo, %al" in AT&T syntax. Memory Operands. In Intel syntax the base register is enclosed in ’[’ and ’]’ where as in AT&T they change to ’(’ and ’)’. Additionally, in Intel syntax an indirect memory reference is like section:[base + index*scale + disp], which changes to section:disp(base, index, scale) in AT&T. One point to bear in mind is that, when a constant is used for disp/scale, ’$’ shouldn’t be prefixed. Now we saw some of the major differences between Intel syntax and AT&T syntax. I’ve wrote only a few of them. For a complete information, refer to GNU Assembler documentations. Now we’ll look at some examples for better understanding.+------------------------------+------------------------------------+| Intel Code | AT&T Code |+------------------------------+------------------------------------+| mov eax,1 | movl $1,%eax | | mov ebx,0ffh | movl $0xff,%ebx | | int 80h | int $0x80 | | mov ebx, eax | movl %eax, %ebx || mov eax,[ecx] | movl (%ecx),%eax || mov eax,[ebx+3] | movl 3(%ebx),%eax | | mov eax,[ebx+20h] | movl 0x20(%ebx),%eax || add eax,[ebx+ecx*2h] | addl (%ebx,%ecx,0x2),%eax || lea eax,[ebx+ecx] | leal (%ebx,%ecx),%eax || sub eax,[ebx+ecx*4h-20h] | subl -0x20(%ebx,%ecx,0x4),%eax |+------------------------------+------------------------------------+ HR,Ghandi Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now