The MASM Forum

General => The Campus => Topic started by: securityaudit on June 18, 2018, 09:44:30 PM

Title: Beginner question - would this work on any CPU?
Post by: securityaudit on June 18, 2018, 09:44:30 PM
Hello MASM32,

I have spent a few years coding in C and Java. I enjoy how I can make a program display a message box or perform some file operations and it works on every (I think?) CPU without any dramas. Although I have never coded anything advanced.

I want to learn assembly, to make programs for Windows only. I believe I should learn MASM32?

My question: provided I do not want to do something too crazy or obscure, will programs I create work on every CPU? My focus is on your average computer at home or perhaps servers. Not anything super obscure that mad scientists have in their labs (sorry to exaggerate).

I have had many people tell me that I have to pick a specific architecture for a specific CPU from many reputable sources, but I am then shown code examples that work on several different CPUs... conflicting information!

Helppppppp I am going crazy :p and thank you!

EDIT: This is a CPU question not an operating system question, although I have an OCD (obsessive compulsive disorder) problem where I ensure backwards compatibility with Windows 95 sometimes haha.
Title: Re: Beginner question - would this work on any CPU?
Post by: jj2007 on June 18, 2018, 10:47:38 PM
I want to learn assembly, to make programs for Windows only. I believe I should learn MASM32?

Yes. Practically all Windows computers understand x86. Programs written in Masm32 ten years ago run just fine on the latest Windows 10 version.

Welcome to the Forum :icon14:
Title: Re: Beginner question - would this work on any CPU?
Post by: zedd151 on June 19, 2018, 12:15:57 AM
Welcome to the forum,   :biggrin:
Title: Re: Beginner question - would this work on any CPU?
Post by: hutch-- on June 19, 2018, 12:29:20 AM
When you speak of a language that will work on all CPU's I guess you are talking about x86-64, portable device and many other hardware types and a dedicated assembler for x86-64 is not the tool you are after, You need a language like JAVA, some versions of C/C++ or perhaps some other language that is what is called "portable". Sad to say in your case x86-64 assembler will only work on one type of CPU and while they are the most used in PCs, it won't work at all on non x86-64 processors.
Title: Re: Beginner question - would this work on any CPU?
Post by: securityaudit on June 19, 2018, 12:48:26 AM
@hutch--

I think you looked a little too deep into my question, my question is a noob question, but your reply was helpful.

Pretend I write a basic program in C, using Visual Studio 2010. It displays a message box saying hello world, deletes a file and gets the user's username.

If I write the above program using MASM instead will it work on the same CPUs as the C program would?

Lastly, if the above is true what other asm "languages" should I learn, NASM or one called x86?

Essentially, the reason I am confused is I always thought simple C programs would just work on any computer's CPU, but it appears as if Asm is picky and is compatible with less CPUs? I might be completely wrong and confused... I am just trying to make a simple Windows 32 program :p.
Title: Re: Beginner question - would this work on any CPU?
Post by: hutch-- on June 19, 2018, 01:16:51 AM
No, sad to say I told you the truth, C is a portable language that can run on many different families of processors, this you cannot do with any assembler. From memory NASM can be built on other than x86-64 hardware but I am not up to date on the details.  For example if you wanted to run an application on ARM hardware, x86 is different and just won't work and of course vice versa. You need a portable language that can be built on different systems with different hardware, this cannot be done with an assembler.
Title: Re: Beginner question - would this work on any CPU?
Post by: daydreamer on June 19, 2018, 01:29:50 AM
Welcome to forum :t
Title: Re: Beginner question - would this work on any CPU?
Post by: jj2007 on June 19, 2018, 01:38:35 AM
As Hutch wrote, a C program would run on other cpus, too. But that is not what you are after: you want a program that runs on a Windows computer, period. Masm32 programs will run on any Windows computer (ok, show me one that doesn't have an x86 or x64 cpu...).

You have the choice, though, between:
- the Masm32 SDK (copyright Hutch, it is his baby): mature, runs on both x86 and x64 cpus, and practically all Windows versions
- one of the Masm64 SDKs (the most advanced one is from Hutch again, but that is a long story): in constant development, runs on Windows 64-bit versions only.

For a beginner, Masm32 is much easier, and it offers more functions. Perhaps you should explain a little bit more why you want to write Windows programs: for your own hobbyist use, or in the hope of selling something later, ...?
Title: Re: Beginner question - would this work on any CPU?
Post by: securityaudit on June 19, 2018, 01:59:20 AM
@jj2007

Butt kissing: I love you - not to give you wrong idea!

More butt kissing: I have searched for years and spent all day today hammering everything to get this answer. People kept talking about ARM and all of this stuff when I indeed only cared about Windows! Thank you, I seriously love you right now!

Question: I think 99.999% of Windows computers will have a x86 or x64 CPU, so my program will work fine just like if it were coded in C, correct?

Just to confirm: Aside from MASM32 or MASM64, there is no other asm I could learn that works on Windows, because I heard of NASM? I also believe one is called x86 but that might be something else?

Off topic: What is the lowest version of Windows MASM32 can make a program for? No need to go lower than Windows 95.

Answering your question: I am an auditor but I do Red Team, Blue Team and Penetration Tests. I already have a good background in C, I adore the Windows API too. Essentially, I want to improve my malware creation skills (for engagements only), I know it's like using a tiny paintbrush but I enjoy having backwards compatible programs with tiny file sizes. Lastly, I would like to learn some reverse engineering for when I go into Threat Hunting or similar fields. I think rootkit development also requires asm...

Edit: This looks like a very good book for beginners, it also seems to suggest that NASM, FASM etc... can create Windows programs https://www-s.acm.illinois.edu/sigwin/old/workshops/winasmtut.pdf
Title: Re: Beginner question - would this work on any CPU?
Post by: hutch-- on June 19, 2018, 02:49:35 AM
> Essentially, I want to improve my malware creation skills

This will get you booted out of here, we have an absolute no malware policy and it is not negotiable.
Title: Re: Beginner question - would this work on any CPU?
Post by: felipe on June 19, 2018, 04:55:24 AM
 :biggrin: What a funny new member, really don't know if is a joke or is real... :idea:
Title: Re: Beginner question - would this work on any CPU?
Post by: securityaudit on June 19, 2018, 05:31:35 AM
> Essentially, I want to improve my malware creation skills

This will get you booted out of here, we have an absolute no malware policy and it is not negotiable.

Don't worry I will not post on here asking for help related to it, if you have any doubts I invite you to contact me privately and you can look at my LinkedIn (I work for a multinational that does security audit).

At the moment I will use what you have given me for programming related things.


:biggrin: What a funny new member, really don't know if is a joke or is real... :idea:

They were genuine emotions earlier as I wanted to know for YEARS which instruction set I should learn, I always got bored when I searched for help. It took me a whole day to get that simple piece of information that jj2007 posted!

Anyway probably getting banned now as hutch-- thinks I am some big hacker LOL.
Title: Re: Beginner question - would this work on any CPU?
Post by: Raistlin on June 19, 2018, 05:42:49 AM
I luv the way all of this starts of ALL benign...and then escalates
to hacking the world. What a dip-pseudo-frack idea. Anything
made by man can be destroyed by man (NAN). Can you create it in the first place ? Can you make perfection ? And if you could & understood what it was, could you destroy it ?

IF only they knew the power of the FORCE.  :t

Dear supreme new generation hacker, I can do exactly what you want.  BUT would I ?

NO because building knowledge is more important, ALWAYS, versus crapping about. If you really were set
on security, then be secure yourself  first. You now know what I mean.
Title: Re: Beginner question - would this work on any CPU?
Post by: felipe on June 19, 2018, 05:48:19 AM
Nice words? Raistlin  :biggrin:

security audit, sorry, but it seemed very strange to me what you have said about your job and your current knowledge. Maybe is normal there? Don't know... :idea:
Title: Re: Beginner question - would this work on any CPU?
Post by: Siekmanski on June 19, 2018, 07:04:24 AM
-> I work for a multinational that does security audit.

Camera Security?
Title: Re: Beginner question - would this work on any CPU?
Post by: Caché GB on June 19, 2018, 07:10:08 AM
Camera Security?
No. Rent-a-cop
Title: Re: Beginner question - would this work on any CPU?
Post by: jj2007 on June 19, 2018, 09:02:59 AM
Folks, be kind to a newbie. Those who come here to get advice on malware (and we have them regularly) behave differently.

I have spent a few years coding in C and Java ... I have never coded anything advanced.

Don't worry I will not post on here asking for help related to it, if you have any doubts I invite you to contact me privately and you can look at my LinkedIn (I work for a multinational that does security audit).
Title: Re: Beginner question - would this work on any CPU?
Post by: felipe on June 19, 2018, 09:59:12 AM
Ok, how about the "simple" example program that comes with the masm32 package as a welcome:
Code: [Select]
; #########################################################################

      .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; #########################################################################

      include \masm32\include\windows.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc

      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib

; #########################################################################

    .code

start:

    jmp @F
      szDlgTitle    db "Minimum MASM",0
      szMsg         db "  --- Assembler Pure and Simple ---  ",0
    @@:

    push MB_OK
    push offset szDlgTitle
    push offset szMsg
    push 0
    call MessageBox

    push 0
    call ExitProcess

    ; --------------------------------------------------------
    ; The following are the same function calls using MASM
    ; "invoke" syntax. It is clearer code, it is type checked
    ; against a function prototype and it is less error prone.
    ; --------------------------------------------------------

    ; invoke MessageBox,0,ADDR szMsg,ADDR szDlgTitle,MB_OK
    ; invoke ExitProcess,0

end start

It would be a good exercise to you (maybe) to compare this message box code with a "c" message box code.  :idea:
Title: Re: Beginner question - would this work on any CPU?
Post by: Raistlin on June 19, 2018, 03:58:34 PM
@jj2007: OK, I'll try to be nice - let's see where it leads....

Quote
My question: provided I do not want to do something too crazy or obscure, will programs I create work on every CPU?
 My focus is on your average computer at home or perhaps servers. Not anything super obscure that mad scientists have in their labs (sorry to exaggerate).

It is possible (proven) that a program/application can seek compatibility on an entire family of CPUs.
It's a simple idea, but NON-TRIVIAL to implement.

Part of a thesis I wrote did it this way (but there are other ways):
STEP 1) Seek instruction set compatibility across CPU architectures (ex. Intel & AMD from x86 to x64).
STEP 2) Seek API compatibility across OS families (ex. Windows XP/Server2003 to Windows 10/Server 2016 and everything in-between).
STEP 3) Use FAT executables to target optimization or unique features of a particular combined (instruction/API) platform.
Title: Re: Beginner question - would this work on any CPU?
Post by: hutch-- on June 19, 2018, 06:30:37 PM
securityaudit,

We in fact have good reason to be heavy handed on illegal stuff, trojans, viruses and the likes, many people who are members write professional level code and simply cannot be associated with the type of junk that the idiot fringe play with. There is another factor, as I provide the forum, if any chyte hits the fan, I am the once who cops it so if anyone ever posts dangerous illegal stuff, I will help the CIA, FBI, MOSSAD, MI5, MI6, KGB etc .... track them down, put them in jail and whatever else they do to pests.

On the motivational end, cracking and similar are a junky subset of what you can do as it is looking for techniques to break existing code where programming in assembler is where you make clever things that are fast and powerful. I have been around for a long time and a common factor with almost all crackers is that they are PHUKING lazy and have not bothered to properly learn how assembler code works at the binary level.

Disassemblers are useful things as it lets you see code you have written clearly and a knowledge of how opcodes work helps you understand how and why high quality software works and in security terms, when you know enough about true low level code you will also understand the tricks that many of these morons try and play.

Take the path of doing clever things that are fast and powerful and you will get something for your efforts, go the other way and you piss it against the wall.
Title: Re: Beginner question - would this work on any CPU?
Post by: securityaudit on June 19, 2018, 06:38:41 PM
Everyone

Aside from the mild trolling/cyber bullying I really appreciate the help and think I have what I need.

I apologise again for breaking any rules I was unaware of (no excuses for not reading the rules) but cannot stress this enough - despite only touching Asm once during my degree (which I have since forgotten) I work in my company's attack team. My job mostly involves pen testing websites. However, I have a decent knowledge of C and with all the time I have spent coding entire projects using just the WinAPI I have been given some research projects, but have never needed Asm.

When I said I have coded nothing advanced it was probably incorrect as I am the most competent out of everyone I know at work and any educational place I have been.

Respectfully speaking I think some people on here are fairly old, the education system has changed significantly since your time. I wish I had the opportunity to learn Asm at university, but instead I got branded with Java...

EDIT: It might be worth locking this thread in a few days since hutch-- makes a good point, although if I wanted to do anything shady i would ask elsewhere (there are numerous forums where this conversation is allowed).
Title: Re: Beginner question - would this work on any CPU?
Post by: hutch-- on June 19, 2018, 08:04:14 PM
 :P

We can generally accommodate the enthusiasm of youth but someone with 5 posts and very little knowledge of assembler is not really in a position to tell people here what to do. If this topic ever needs to be closed, it will be but not at your request. You are right about the age of at least some members but the accumulated knowledge of people here runs into the many hundreds of years and very little ever gets past us.

You are certainly welcome here and there many here who can help you along the way but get used to the idea that to be able to write decent assembler code takes a fair bit of bump and grind to get there.
Title: Re: Beginner question - would this work on any CPU?
Post by: GoneFishing on June 19, 2018, 10:50:07 PM
I hope that now  when OP has really strong motivation to become an evil-doer he'll not use his pen testing skills on this site  :biggrin:
Title: Re: Beginner question - would this work on any CPU?
Post by: AW on June 21, 2018, 06:16:15 PM
Quote
Respectfully speaking I think some people on here are fairly old, the education system has changed significantly since your time.

My impression is that your computer science knowledge is a total confusion and you are probably in a wrong career.
(The educational system has indeed changed a lot, I am well aware of that because I do occasional tutoring in a well known site  (https://www.24houranswers.com/tutors/200/Computer-Science/Assembly-Language-Programming?OO=0) - I don't do more of it because it does not pay off for the time - most tutors are from India and East European countries and work for peanuts.)