NASM - The Netwide Assembler

NASM Forum => Other Discussion => Topic started by: Evlesoa on January 10, 2015, 01:27:05 PM

Title: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on January 10, 2015, 01:27:05 PM
From my experience the answer is YES, there is no way. Hope someone can help me! I'm very intent here, but also very confused!

Anyway, why do I say that a complete beginner can't learn asm?

Well, I've noticed that there are NO tutorials, NO books, nothing that explains stuff like this:
invoke MessageBox, NULL, addr HelloWorld, addr HelloWorld, MB_OK

MessageBox? Null? Where is this stuff from? Why is there? What does it all mean??? Ok, I know what it means, but it's not explained why in that order. In other words, the program is not usually dissected. If you give knowledge but don't explain how to use it, what good is it?

I've looked at books like The Art of Assembly, Programming from the Ground Up, The Zen of Assembly Language, Guide to Assembly Language - A Concise Introduction (yeah right), another called PC Assembly Language, etc. Very useful, I think, just not that useful for someone who doesn't know how to make an exe that "does" things. Now I've done some things in C++ a few years ago, and I could build a program with a GUI and all (forgot it now). With asm, I don't know where to start or what to do. Nothing seems to be explained as well as it is in a good ol' "Learn C" book.

My main goal is to learn asm so that I can do something more than just Cheat Engine on games like Minesweeper or Dungeon Keeper or Evil Genius. I say this because there are limitations to what I can do, and to how much I understand memory and how it works (I would hope I can actually browse memory and find things like unit production speed, which is something that I can't do now seeing how that "variable" (if it is one) doesn't change very often).

Any ideas? Or just go back to C++ and forget asm?
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: vzybilly on February 07, 2015, 03:27:42 AM
Ok, I've been working in NASM for afew months now and have gotten most all of it, it really is very basic.

One thing I found out, Books Are Crap.

If you want to continue to learn nasm, I can pass off my set-up to you and start teaching you myself, it won't do much with GUI yet but I'm learning SDL right now.

As for editing other games and such, on my OS an app needs to request higher access or just plain can't do that. I peeked into something of the like and I think the final answer was a system call or something but that was months ago that I did that looking into.

You can learn how to assemble then how to disassemble which will allow you to completely change the game you want to play.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: RagingGrim on February 11, 2015, 04:17:05 PM
I haven't used invoke at all , but that's probably because it's a macro :P

MessageBox is a winapi function ; If i remember correctly it's located in kernel32 but I'm not so sure.

If your unsure about any piece of code you see simply google it.
For example googling messagebox takes you straight to msdn

Now this is where knowing C++ comes in handy! :D
https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx

as you can see messagebox is a function that takes 4 params.

You'll probably only be interested in these two params
 _In_opt_  LPCTSTR lpText,
  _In_opt_  LPCTSTR lpCaption,

lpText is the text displayed in the messagebox whilst lpCaption is the caption of the messagebox.
Ugh , i can post an example of using messagebox if you want.

Don't go back to c++. Learn assembly . Your mind will be blown.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: encryptor256 on February 12, 2015, 06:05:06 PM
MessageBox is a winapi function ; If i remember correctly it's located in kernel32 but I'm not so sure.

It is in "user32.dll", thank you.  :P
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 02:41:04 PM
Wow, didn't think I'd get a reply.

Okay, let me see... the problem I have is that, for example, user32.dll. How do you even open such files? I tried with notepad but more often than not the dll files come out as messes.

And then syntax order. I don't think that I can just look at syntax and memorize its order. I need to actually practice doing that. This means that if I open a program or reverse engineer it, I probably won't understand any of it.

How do I start? I seriously just don't know what to start with first. Do I parrot hello world script over and over until I've memorized it by means of rote? or is there something more / better that I can do? I find assembly to be fascinating, honestly. I just don't get how manipulation of memory alone (turning 1s and 0s on dials for analogy) can build anything. Lastly, speaking of things like "_In_opt_  LPCTSTR lpText": what is _ for? what is In and opt for?

Anyway, pointers, please. How to learn this cryptic language and be able to do something with it? All this reading on x86 processors and how their registers work seems of no help. I'm really eager, so I'll take any help I can get!
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 03:01:06 PM
You can open dll file with that: http://www.nirsoft.net/utils/dll_export_viewer.html

After, for learn assembly in theorical, I recommend you to read: http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html.
And for learn how to use WinAPI function, just enter the function you want to learn in bing, then you will see msdn link, that's all.

Then produce a lot of code, the key to learn assembler is write asm code everyday, you can of course read other source code, (http://forum.nasm.us/index.php?topic=2041.0), for exemple, since I learn asm since 2011, I have accumulated 15 Go of courses + project + exemple in one root folder: Computer science ^-^
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 04:38:27 PM
I'm willing to code every day for an hour if I can learn asm and how to use it so that I can manipulate old games like quake 1/2 and to learn how to break games down. Then I'd like to learn in general how to do macros and what not.

I will take a look at what you gave me. Thanks a lot for the links on starting. I also do have some various asm tutorials but I don't really understand them too well because I'm not at that level yet.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 04:55:35 PM
For macro system: http://forum.nasm.us/index.php?topic=2036.0.

And for asm learning, hmm.

Well like you know it's all about mnemonic word:

Code: [Select]
Instruction      Destination, operand

After what you don't arrive to understand ? memory management, variable/value, pointer, register, ... ?




PS: I recommend you, begin to learn by newer technologies made by intel: https://software.intel.com/en-us/intel-isa-extensions, AVX instruction.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 05:08:11 PM
Okay, maybe I'm retarded or something, but how does knowing these codes make me able to create anything?

You know what I mean? Basically, I don't see how pushing memory around (like a dust sweeper sweeping the floor) = programs? :-\

I get that in, let's say Microsoft Visual C++ IDE, you can specify what the program does and all, but this concept of just memory being messed with is hard to grasp. I could make a calculator / program that asks for input in C++ (that's basically as high as I could crawl in that class), but for assembly? If it's "that easy," then why aren't there more operating systems out there or more hackers? If all it takes is to have a reference book, then everyone can just program whatever they want? I've had more success with Ruby (actually being able to make something) than any other language.

Let's say I want to start with minesweeper. Goal is to stop time. Or let's say I want to fly in Quake by changing my x,y,z coordinates, or let's say I want to make my bot opponents be unable to move or have no weapons. This clearly requires a lot of expertise, does it not? After all, I like to play games, so I figured that would be what I should try learning on.

P.S. Holy crap. That intel stuff makes no sense to me at all. This processor stuff looks way too complex, and I have no idea what any of that means. *sigh* I'll have to reinstall Microsoft IDE and stick with that because there's no way I can process that CPU stuff. It's unimaginable that you have to know so much just to create a program... jesus...
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 05:15:20 PM
Hmm, sorry I don't understand all, i'm French :/.

You want to know how RAM run ?

For learn how work asm instruction, you need to read:
 http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-2a-manual.pdf
 http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-2b-manual.pdf
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 05:18:49 PM
No, that's OK. I just wanted to do stuff like this and understand it (I wrote this, but it crashes, and I don't really understand it too well):

Code: [Select]
alloc(health,1024)
label(original) //reference
label(quit)
label(return)

health:
mov [ebx+00000480],#100

original:
//sub [ebx+00000480],eax

quit:
jmp return

"Tutorial-i386.exe"+24FFB:
jmp health
nop

return:
//blank

I hope I can figure out how to work with a program's memory and code applications that can change it for learning purposes, and then move on to creating some sort of application purely in assembly. I'm hoping to use this in application security / testing. Everyone kept telling me to learn assembly to do that because it can teach you how to reverse engineer and directly manipulate a program's allocation that's stored in RAM. I think the most basic, as said, is to start with hacking silly games. I'm not trying to be a hacker or anything. I just like computers a lot.

Edit: okay, and if I read all of that? what happens then? I read the Art of Assembly (like 1/3rd of it) and the only thing I got was that I am probably not genius enough to memorize everything word for word.

Edit 2: I can understand this: http://aelinik.free.fr/c/ch06.htm, or something more beginner-like http://aelinik.free.fr/c/ch02.htm, but I can't understand the stuff you've given me. Isn't there a guide on assembly in this style? Or is it that people do not write stuff like this in assembly? It seems assembly is incapable of doing so based on what you've given me. It's just a bunch of instructions. How does giving instructions to a CPU create apps?

For example, there it says: "No previous programming experience is required for you to learn the C language from this book, although some knowledge of computers helps. Also, it's up to you to determine how quickly to go through the 24 hours of this book: You could sit up with a big pot of coffee and power through the book in a sitting or you could take an hour a day for 24 days."

This doesn't hold true for asm, does it? You need to be a mozart of CPU architecture and understand RAM like the back of your hand in order to do anything?

I apologize for my confusion. I'm truly a noob.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 05:32:15 PM
Hmm, sorry I have take the other way of the force: build program :p

And yes, you need assembly knowledge for hacking program, after for hacking, sorry, don't have any knowledge :p

If you are good in French language, you can navigate in this site: http://www.newbiecontest.org/
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 05:33:51 PM
Hmm, sorry I have take the other way of the force: build program :p

And yes, you need assembly knowledge for hacking program, after for hacking, sorry, don't have any knowledge :p

That's okay. I'm just trying to learn basics here, and I thought minesweeper or some easy game like that could be a good starting point because I get to understand how memory works. From there, I could try to create my own things. I appreciate, very much so, all of your help and your intent on helping me! Thanks so much.

Edit - unfortunately English is what I'm best at, and I never learned French. I can try translating it, but it may be difficult because translations suck. That is kind of what I'd be interested in, based on what I see. Like where it talks about computer memory (http://www.newbiecontest.org/forums/index.php?PHPSESSID=ab7b64064758e3fe62d61365436b9220&topic=3327.0) it's relevant to what I want to learn. But I can't understand it, haha.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 05:39:58 PM
No problem, it's too rare to found people who need help lol, programmers community aren't enough social :D (I talk but me too i'm not).

Well first you need to assemble your asm source code by nasm in binary dialect understand by CPU, then you need to integrate header for help OS execute your program.
And it's golink who do that: http://www.godevtool.com/GolinkHelp/GoLink.htm

After for hacking, you need binary language comprehension too (opcode), honestly I don't find any complete tutorial about that.
I started to do this:

Code: [Select]
; OPCODE INTEL X86/x64

; MOV  {dest.} {source}

 0xB0   01 = 'mov  al, 1'
 0xB1   01         = 'mov  cl, 1'
 0xB2   01     = 'mov  dl, 1'
 0xB3   01     = 'mov  bl, 1'
 0xB4   01     = 'mov  ah, 1'
 0xB5   01     = 'mov  ch, 1'
 0xB6   01     = 'mov  dh, 1'
 0xB7   01     = 'mov  dh, 1'
 0xB8   0100 = 'mov  ax, 1'
 0xB9   0100 = 'mov  cx, 1'
 0xBA   0100 = 'mov  dx, 1'
 0xBB   0100 = 'mov  bx, 1'
 0xBC   0100 = 'mov  sp, 1'
 0xBD   0100 = 'mov  bp, 1'
 0xBE   0100 = 'mov  si, 1'
 0xBF   0100 = 'mov  di, 1'
 0x66B8 01000000 = 'mov  eax, 1'
 0x66B9 01000000 = 'mov  ecx, 1'
 0x66BA 01000000 = 'mov  edx, 1'
 0x66BB 01000000 = 'mov  ebx, 1'
 0x66BC 01000000 = 'mov  esp, 1'
 0x66BD 01000000 = 'mov  ebp, 1'
 0x66BE 01000000 = 'mov  esi, 1'
 0x66BF 01000000 = 'mov  edi, 1'
 0x48B8 0100000000000000 = 'mov  rax, 1'
 0x48B9 0100000000000000 = 'mov  rcx, 1'
 0x48BA 0100000000000000 = 'mov  rdx, 1'
 0x48BB 0100000000000000 = 'mov  rbx, 1'
 0x48BC 0100000000000000 = 'mov  rsp, 1'
 0x48BD 0100000000000000 = 'mov  rbp, 1'
 0x48BE 0100000000000000 = 'mov  rsi, 1'
 0x48BF 0100000000000000 = 'mov  rdi, 1'

 0x48B0 01     = 'mov  r8b, 1'
 0x48B1 01     = 'mov  r9b, 1'
 0x48B2 01     = 'mov  r10b, 1'
 0x48B3 01     = 'mov  r11b, 1'
 0x48B4 01     = 'mov  r12b, 1'
 0x48B5 01     = 'mov  r13b, 1'
 0x48B6 01     = 'mov  r14b, 1'
 0x48B7 01     = 'mov  r15b, 1'
 0x48B8 0100     = 'mov  r8w, 1'
 0x48B9 0100     = 'mov  r9w, 1'
 0x48BA 0100     = 'mov  r10w, 1'
 0x48BB 0100     = 'mov  r11w, 1'
 0x48BC 0100     = 'mov  r12w, 1'
 0x48BD 0100     = 'mov  r13w, 1'
 0x48BE 0100     = 'mov  r14w, 1'
 0x48BF 0100     = 'mov  r15w, 1'
 0x41B8 01000000 = 'mov  r8d, 1'
 0x41B9 01000000 = 'mov  r9d, 1'
 0x41BA 01000000 = 'mov  r10d, 1'
 0x41BB 01000000 = 'mov  r11d, 1'
 0x41BC 01000000 = 'mov  r12d, 1'
 0x41BD 01000000 = 'mov  r13d, 1'
 0x41BE 01000000 = 'mov  r14d, 1'
 0x41BF 01000000 = 'mov  r15d, 1'
 0x49B8 0100000000000000 = 'mov  r8, 1'
 0x49B9 0100000000000000 = 'mov  r9, 1'
 0x49BA 0100000000000000 = 'mov  r10, 1'
 0x49BB 0100000000000000 = 'mov  r11, 1'
 0x49BC 0100000000000000 = 'mov  r12, 1'
 0x49BD 0100000000000000 = 'mov  r13, 1'
 0x49BE 0100000000000000 = 'mov  r14, 1'
 0x49BF 0100000000000000 = 'mov  r15, 1'
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 05:42:33 PM
Yes, I noticed that programmers aren't very social. That's unfortunate.

Ya, I'll read that. I know the GoLink is important if you want to do anything. I did look at the documentation, but it seems to be geared towards people who already are familiar with assembly to some extent. As a total newbie, it doesn't tell me enough to do anything on my own.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 05:47:11 PM
GoLink it's just a tool who is necessary to build any program, you can wrote some code like:

Code: [Select]
vmulss        ymm0, ymm1, ymm2

and build it through nasm, and execute it, but it will not work cause your program haven't header for your OS recognize that like program.

http://en.wikipedia.org/wiki/Portable_Executable
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 05:49:57 PM
Yeah, I understand what you mean for that. This part doesn't seem too complicated. Thanks :)
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 05:56:55 PM
No problem ^^

And be patient, in fact we learn asm everyday like me, and for begin to this world, you need long long time for understand this langage, personnaly I needed 2 years just for learn how it's work a little :p

Well I had made the biggest error of the year to begin to learn by C language, all is only abstraction for this langage, I hate that ^^
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 06:00:55 PM
Yes, exactly. It's so abstract to me that I don't know how to learn it! I see you had the same problem. I like abstraction if it can be understood in some way.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 06:06:28 PM
sure ^^

and for the precedent program you given me, where you find it ? nasm give me a lot of error.

Code: [Select]

alloc(health,1024)
label(original) //reference
label(quit)
label(return)

health:
mov [ebx+00000480],#100

original:
//sub [ebx+00000480],eax

quit:
jmp return

"Tutorial-i386.exe"+24FFB:
jmp health
nop

return:
//blank

It's seem that look like disassembly code ...


PS: and so you want to learn assembly intel for Windows 32 or 64 bit ?
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 06:21:08 PM
It's disassembler, yes. Specifically Cheat Engine's, because that is the reason I got interested in assembly (its syntax looks interesting). It only works for the tutorial of cheat engine. Here's some documentation: http://wiki.cheatengine.org/index.php?title=Cheat_Engine:Auto_Assembler. But as I said, this code crashes for some reason.

As for learning, I'd like to do 32 bit before moving on to 64 bit. I'd learn 16 bit before learning 32 bit, but 16 bit isn't used anywhere. Gotta start from basics, right?
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 06:24:23 PM
Hmm no, concretely don't waste your time by begin to learn 32, jmp to x64 directly, my tip :p
Primary, cause when you would want to transform your code in x64 compatibly, you must re-write all data moving type into 64 bit.
Then while you are in x86, you have lesser register than in x64 mode (https://software.intel.com/sites/default/files/m/d/4/1/d/8/Introduction_to_x64_Assembly.pdf)

Exemple:
Code: [Select]
max 32-bit:
eax - ebx - ecx - edx

max 64-bit:
rax - rbx - rcx - rdx - r8 - r9 - r10 -r11 - r12 - r13 - r14 - r15

This program will never execute through nasm, exept those instruction:

Code: [Select]
health:

;sub [ebx+00000480],eax

jmp health
nop
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 06:27:56 PM
Isn't x64 harder, though? And less useful since most people are still using x86?
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 06:42:53 PM
Well like x64 mode existe since 2006 (http://en.wikipedia.org/wiki/X86-64#Intel_64), I don't know why people keep the old x86 mode, then x64 it's not much harder than x86 16 bit, just more complexe.

But help to get a better program, cause more register, able to transfer more data (vectorization AVX, qword instead dword), I just see only advantage compare to 32 bit and 16 bit.

And there is same story about SSE instruction (vectorization programming) , it exist since 1999, and programmer just begin to interest to those technologie actually -_-
I don't have source about that but I have read some topic about that, and look unity, it just begin to compile their program in x64 bit -_- it's crazy of misunderstanding.

So I have my own theory, like hardware is very very advance compare to software, it need of waiting a lot of year (10 year exemple ^^) for begin to make interest about it.



PS: If you want another debugger, go look for http://x64dbg.com , I think he's wonderful debugger (skin influence ? :D) but even if it's beta it's still very good.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 22, 2015, 07:16:26 PM
Wow, thanks for the tool. Looks like Ollydbg.

Why is it taking so long for everyone to make the switch to x64? Or why is the interest only now coming up and not earlier? If it's relatively old tech (9 years ago), then that should mean it should be more widespread by now? Yes?

You sound like you really know what you're talking about and have a lot of experience with it.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 22, 2015, 07:32:27 PM
Well, all programmers need to know, new hardware technology are build everyday (thanks to intel engineer of CPU architecture ^^) like program, it's like sci-fi, I don't kidding, software programmer need a long time before use newer technologies.

And I have my own theory of why, cause simply because 95% of programmer code in higher level language, so they don't care about technology, cause they like to be in abstraction world :x.

Like I say, only assembler language can give you a full vision about all technology of any hardware, high level programmer are so dependent about the compiler software that they don't have knowledge about how memory work or .. (sorry I like troll :D). And in other way high level language are just created for this, in the name of facility.

But still my theory, you can get other from other programmers.

Hmm, thanks for the compliment, I just know all that, cause I program everyday, but since some times I have bad habits, like I don't have job I program alone and all those entertainment love to disturb me like video games, movie, internet  :p
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Bryant Keller on February 23, 2015, 01:46:07 AM
Wow, thanks for the tool. Looks like Ollydbg.

Why is it taking so long for everyone to make the switch to x64? Or why is the interest only now coming up and not earlier? If it's relatively old tech (9 years ago), then that should mean it should be more widespread by now? Yes?

You sound like you really know what you're talking about and have a lot of experience with it.

The reason it takes quite a bit of time for people to upgrade is because hardware costs money. Many companies will update their software on a daily or weekly basis, but hardware only gets updated every 10-15 years. Most companies don't have to buy just one computer, they have to buy hundreds. So as long as businesses are still using 32-bit platforms, there will be a need for 32-bit programming. Give it another 5-6 years and you won't find anyone outside of the embedded design market using 32-bit systems. :)



As for the original topic, and I don't mean to contradict anyone, but the best way to learn assembly isn't to just randomly work with assembly code. That's really just a good way to develop bad habits and can actually slow down your progress.

The best way to learn any type of programming is to learn the fundamentals of software design. The reason for programming is to IMPLEMENT a solution to a problem. So in order to learn to program effectively, you must first learn to DESIGN a solution. To do this, you don't use a programming language, you use flowcharts. When you get into the habit of creating a flowchart that describes a solution, you then break the problem of development into much smaller blocks of code which makes translating those blocks to whatever language you want as easy as checking your reference manual for that particular language/architecture. You should also get into the habit of creating data-flow diagrams. This is a type of flowchart that will describe where information is coming from and where it should go. In your game cheat example earlier, this would be the flowchart which shows the interprocess communication between your cheat and the game, as well as what memory locations in the game need to be modified for the desired results.

This style of program design & development is known as top-down design and has been used quite successfully by programmers since the 70s. It allows you to think of the problem to solve in an abstract manner so that you can use any programming language you wish for the implementation. There are other (arguably better) methodologies such as Object-Oriented design and Event-Driven design, but unless you are working with very high level languages, these can add a great deal of complexity to your code which is beyond the grasp of most beginners.

Here are a few links I hope you'll find useful.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 23, 2015, 08:52:03 AM
Gotcha.

And for flow charts, I remember this. I remember doing this for C++ in order to create solutions for problems. I actually did reinstall Visual C++ Express just today, which is what I'll be re-learning now. I will try to learn assembly on a very basic level, where I can't do anything with it alone but can try to incorporate it into my C++ programs instead since I'll be working with memory for my beginnings.

Lol @ Shaynox. Thanks for the info, and I know how such distractions get in the way. It's quite true, yes. I have the same problem!
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 23, 2015, 11:27:16 AM
Hello,

@Bryant Keller: No, no worry you, I just said my own experience and conclusion I have, about it.

And for the question about how to learn programming, but like we are in assembler forum, it will be fine to stay on this level, you talk about c - c++ - OOP :p that's just my opinion.

The only problem of Flow Diagrams, it's if we begin to get used to those kind of system, we'll get disgusting about assembler language, cause there so much abstraction that we lost notion of register/pointer/MMIO/PMIO/... . I don't say it's not a good idea for start, but it's not needed to stay learn long long time with that system to risk to be attracted to other language instead assembler :p
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 23, 2015, 08:55:59 PM
What I mean is that I don't have any idea of how to work with a flow chart and assembly. I mention C++ because I know it (visual studio) allows for integration of assembly. In any case, I need to learn assembly for that use. My problem is that I want to manipulate memory, and my solution is to build something that can alter said memory. But I still got no clue on how to start, so I'll have to work with another language before I can use assembly. Unless someone else has some better ideas...
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 23, 2015, 09:02:55 PM
Do you want always modify variable of other programs ?

Cause it that case, windows will don't let you to do that :p (memory protection)

Else if you want to swim in that huge space, hmm begin to ... just display memory, you can begin to test if you can print the first case of RAM (0x0000_0000__0000_0000) :p
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 24, 2015, 06:01:28 PM
If you say that I can't, then explain this video below? I want to be able to create a menu so that I can modify visual effects, for example. Let's say I want to be able to get that "under water diving" screen to be on for me even when my character isn't water-diving. Or let's say I want to be able to get the visual effect of making myself look cool (like changing my model). All of this is just variables in memory. I think it would be nice to make something like this: https://www.youtube.com/watch?v=Sc6Lt2jWAiY

Assembly can do that, right? High level languages can, for sure, but assembly? How? That's what I want to learn and be able to do. And eventually move to more advanced stuff.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 24, 2015, 06:37:38 PM
hmm, you still would love to take the dark side of the force :p

Hmm so ok let's go I don't have any knowledge, but I will try to help you to start.

First you need to explore/analyze RAM's memory (http://mh-nexus.de/en/hxd/), then you will need to modify correct value of game's target, after you can create an hook, for target the rip register in your own program.

For make an hook, you need to make, hmm, theoretically, insert a call    (your_program) into game RAM's space.

So like I don't really want to try that or in long long future, I will let you how to to that, but take care when Windows put any program in RAM, it will split your program into two or more part (I'm little noob in OS architecture even if I begin to write my own :p).

This split make many part, like I know there are data part and code part, data part is modifiable but code part is unmodifiable, you can try it by do this with nasm (windows x64):
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 24, 2015, 06:46:58 PM
And I have a other question for help me to build my new topic "Factorization of instructions block" if you want :p

What do you think about that transformation:

Source:
Code: [Select]
mov [instance         ], rcx
mov [previous_instance], rdx
mov [cmd_line         ], r8
mov [cmd_show         ], r9d

Dest:
Code: [Select]
_mov {[instance], rcx }, {[previous_instance], rdx}, {[cmd_line], r8}, {[cmd_show], r9d}

Is it easier to read ? yeah I would like to put ( ) instead { }, but nasm don't let me to do this :p
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Bryant Keller on February 24, 2015, 10:06:10 PM
Remote code injection has been done in a few different ways. The most common method is by writing a stub that loads the program as a child process under debugging and manipulation the child processes memory. This style of code injection requires the developer to familiarize themselves with the debugging API's available on their system. The other method is by hijacking a DLL that the program uses in order to modify the memory map from within the program at the moment the DLL is loaded.

The first method is definitely worth learning to do because it's the basis for learning to create your own debuggers, which is a great project! The second isn't quite as useful because it's an attempt to subvert the executing program and could potentially be flagged as malware (which isn't a good thing).

To preform the first method you should learn about the Windows Debugging API (https://msdn.microsoft.com/en-us/library/windows/desktop/ms679303%28v=vs.85%29.aspx). These functions can be called from assembly once you are familiar with the platforms calling conventions (http://forum.nasm.us/index.php?topic=1758.0).

The only problem of Flow Diagrams, it's if we begin to get used to those kind of system, we'll get disgusting about assembler language, cause there so much abstraction that we lost notion of register/pointer/MMIO/PMIO/... . I don't say it's not a good idea for start, but it's not needed to stay learn long long time with that system to risk to be attracted to other language instead assembler :p

I disagree. If I was to tell a novice to write a program to convert all lowercase ASCII characters in a string to uppercase, they might find that problem a daunting task. However, if I was to tell the same novice to implement the attached flowchart in assembly, it's not unreasonable to expect them to come up with something like:

Code: [Select]
;; toupper - convert lowercase characters to uppercase.
;; @param esi Address of string.
;; @return String in ESI is altered.

toupper:
;; Start of procedure
;; Load next byte from string
next_byte:
LODSB

;; Does byte equal zero?
CMP al, 0

;; If so, goto done.
JZ done

;; Is byte greater than 'a'?
CMP al, 'a'

;; If not, goto next byte.
JL next_byte

;; Is byte less than 'z'?
CMP al, 'z'

;; If not, goto next byte.
JG next_byte

;; Subtract 32 from byte.
SUB AL, 32

;; Write byte back to string.
MOV [esi - 1], al

;; Goto next byte.
JMP next_byte

;; Return from procedure.
done: RET

Notice how each of the smaller steps were easier to implement than the much grander task. By learning (from the start) to break down your algorithms into smaller parts, you simplify the process of writing low level code.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 25, 2015, 01:48:14 PM
Thanks for all of your replies, once again.

Yeah, hijacking a dll I think is a bit like a sorry excuse for something when there's a better way of doing it. I would prefer to familiarize myself with it first, if given the option. I know everyone tells me that one should learn Windows API stuff. And if I learn it, how will I use it? How will I know that I am using it correctly?

Then... I'm not even sure how to write a stub that loads something as a debugger for a child process. This makes me want to ask: how did you guys begin learning this? what did you do to practice? what was the first thing you made? and what did you read for resources?

As a matter of fact, Shaynox, that did make it a bit easier to understand. Thanks for the example.

And Bryant, I know what you're talking about in regards to flow charts. It's quite clear, actually, and very logical. I also understand what the code is trying to do, yet I doubt I can write the same thing. I guess it's just I don't understand memory too well. Unlike assembly, unfortunately, there are many tutorials for this in other programming languages. It's kind of weird... you'd think the base would get most attention, but no... it's the higher level stuff that gets so much attention.

Thanks for the links, too. I've bookmarked and will read them as I have free time.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 25, 2015, 04:03:04 PM
Hi,

And if you want you can play with the stack, so let's explain how OS work a little (with my knowledge):

First Windows is mutli-taksing system, and for do that, it needed to execute all program by run each instruction of all program.

Those program so are execute instruction after instruction, it's call Task-State Segment (TSS) I guess (cf chap 7 multi tasking http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-3a-part-1-manual.pdf).

And for execute those program without hurt other program, it needed to store the context of program in the stack (rsp).

Then when you run your program, Windows put this on ram, then call the entry of your program after save the return address of other program in rsp, like a classic call instruction.

Like you know or will, function store local variable in stack by subtract rsp for store all data used + the return address (8 byte for x64 and 4 byte for x86), before call the function.

So you can play wit this rsp, for jump/analyze the previous program, and why not previous of previous program for found your target.

After it's theoretical, just test this code and why not display those data:

Code: [Select]
start:
xor rax, rax
hack_mem:
inc rax
mov qword [rsp + rax],  0xdeadbeefdeadbeef
jmp hack_mem

 
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Bryant Keller on February 25, 2015, 07:13:28 PM
I know everyone tells me that one should learn Windows API stuff. And if I learn it, how will I use it? How will I know that I am using it correctly?

The API is the "Application Programming Interface" and it's a predefined set of routines, data types, and equates that allow you to interface with that particular system. For example, the Windows API is contains everything a programmer needs to write software that runs on Windows. The POSIX API contains everything a programmer needs to write software that runs on UNIX (POSIX Compliant) systems. Each of these API's also include a large amount of documentation (Most have examples written in popular high level languages but the concepts transfer to assembly as well).

Then... I'm not even sure how to write a stub that loads something as a debugger for a child process. This makes me want to ask: how did you guys begin learning this? what did you do to practice? what was the first thing you made? and what did you read for resources?

I've been a programmer for a long time, so you're probably not going to learn in much the same manner as I did. But when I first started to use Windows (sometime in 2003) I began by grabbing a copy of the Windows API reference manual and set out to develop a simple text editor. As I familiarized myself with all the basic controls and dialogs, I then extended the text editor to include build support and a snippets manager. These things gave me a lot of experience with interprocess communication. At that point I started reading up on the Windows Debugging API (that I posted earlier) and used that to provide basic debugging support to my editor. After that, I hit up Iczelion's website and learned about the PE/EXE layout and played around with driver development using the Windows Driver API. Of course I probably couldn't do most of that stuff anymore since I've not even used a Windows computer since sometime around 2007-2008.

Also note, that the calling conventions document I linked you to above will explain how to actually invoke the routines contained in those API's. So you should probably acquaint yourself with that.

And Bryant, I know what you're talking about in regards to flow charts. It's quite clear, actually, and very logical. I also understand what the code is trying to do, yet I doubt I can write the same thing. I guess it's just I don't understand memory too well. Unlike assembly, unfortunately, there are many tutorials for this in other programming languages. It's kind of weird... you'd think the base would get most attention, but no... it's the higher level stuff that gets so much attention.

Thanks for the links, too. I've bookmarked and will read them as I have free time.

One of the best assembly tutorials I've seen in quite some time actually belongs to one of the regulars on this forum (avcaballero). His website has a tutorial which walks the reader though a very large set of examples. Some of his documents are not translated to English yet, but there is more than enough to get you started. You should check it out. (http://www.abreojosensamblador.net/Productos/AOE/Index_en.html)
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 26, 2015, 06:41:41 AM
@shaynox
This is similar to all the languages that I've looked at, because they all run on windows, of course. Thanks for giving me the details to it. Useful information in general. I'll think of this when I do memory-related stuff.

@Bryant
Hmm. Ok. I did know what API stands for, because I used to go to various tech conventions, but wasn't sure what it did. Just thought it was like "SLI" for all programs in some manner or another (because it interacts).

I guess I don't have any questions left for now except for one. How did you start developing a text editor? You, I think it was, who said that you need a solution to a problem? In this case, what problem are you facing when you set out to program the text editor? Or is it as simple as "I don't have any software to write stuff in?"

I'm going to look up some stuff on youtube and do some reading!
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: shaynox on February 27, 2015, 03:03:11 PM
Hello, I have a compilation of tool for you:

- http://wqaxs36.perso.sfr.fr/Project/Computer_Science/nasm/10.TOOLS/Programmers_tools.zip

Enjoy.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 27, 2015, 05:23:55 PM
woo, cool! Thanks shaynox!!
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Bryant Keller on February 28, 2015, 03:37:00 AM
I guess I don't have any questions left for now except for one. How did you start developing a text editor? You, I think it was, who said that you need a solution to a problem? In this case, what problem are you facing when you set out to program the text editor? Or is it as simple as "I don't have any software to write stuff in?"

What I said was:
Quote
The reason for programming is to IMPLEMENT a solution to a problem. So in order to learn to program effectively, you must first learn to DESIGN a solution.

My problem was a lack of familiarity with the Windows API. The solution was a text editor which allowed me to ease my way through various user controls, dialogs, and into more complex things like custom controls for syntax highlighting. However, the statement "I don't have any software to write stuff in" kinda also applied since at the time my only development tools were NASM, ALINK, Windows Notepad and some .bat scripts.

The suggestion to focus more on learning to design your software was based around the idea of teaching yourself to systematically break down complex tasks into tasks which will be much easier to implement. By having the tasks broken down from the beginning, you'll be able to focus in on implementation details without worrying about the larger task at hand, once each of the smaller tasks are completed (if the complex task was well defined) the implementation as a whole should "Just Work". At least that's the theory. In practice however, there are always points in which software bugs can present themselves in your work. That's why the best programmers aren't the ones who write great code, rather the ones who can effectively debug the bad code. ;D
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on February 28, 2015, 03:43:03 PM
Ah, I see. Dang.

So you basically already knew how to do a lot of stuff already. Seems like I got a lot to learn. I got another question, then, because you may know it.

When it comes to implementing assembly into, say, visual studio (into C++), what's the syntax of it? Let's say I just want to learn how to manipulate memory values that I've defined in C++ using nasm rather than program everything from scratch IN nasm (that seems too overwhelming for me at moment), do I need to still look at x86 intel architecture? Or is there something else I can do? My primary objective is to be able to read and understand syntax. Any suggestions on that? That would also mean that whatever I make can be used cross platform, right? Because if I use nasm, I wouldn't be able to just transfer it to linux (have the code compile on linux) if it's AMD?

Is there assembly for amd processors? What's different?
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Bryant Keller on March 06, 2015, 10:34:16 PM
When it comes to implementing assembly into, say, visual studio (into C++), what's the syntax of it? Let's say I just want to learn how to manipulate memory values that I've defined in C++ using nasm rather than program everything from scratch IN nasm (that seems too overwhelming for me at moment), do I need to still look at x86 intel architecture? Or is there something else I can do? My primary objective is to be able to read and understand syntax. Any suggestions on that?

I would avoid trying to interface with C++ code from NASM until you become more familiar with NASM itself. The problem isn't NASM or the Intel architecture, rather it's a problem with C++. The C++ programming language produces some seriously ugly output that is very hard for most beginners to understand, let alone make use of. This is a result of a "feature" of C++ known as "Name Mangling" that allows support for function overloading and namespaces among other things. What makes it more difficult is that each implementation of C++ (Visual C++, GNU C++, etc.) all handle this "Name Mangling" feature differently since the language only requires the ability be present, but doesn't impose any requirement on how it should be implemented.  :o

That would also mean that whatever I make can be used cross platform, right? Because if I use nasm, I wouldn't be able to just transfer it to linux (have the code compile on linux) if it's AMD?

Code which interface with external API's are going to be specific to that API. However, there are plenty of portable API's out there. Good examples of this are the Standard C Library, the OpenGL Library, and the OpenMP Library. Using portable libraries like these will allow you to make use of features of any given system without the need for worrying about the exact implementation details of that particular system. These libraries also, usually, have some form of overhead since they are developed in higher level languages and require the processor to execute through multiple layers of abstraction before reaching what would be a direct invocation from a system dependent application.

If you are focused on portable development, I would suggest using NASMX and stick to examples that use the Standard C Library for peripheral (screen, disk, network, etc) I/O. This should give you the ability to build and run code on any system that NASM & NASMX already support.

Is there assembly for amd processors? What's different?

Intel and AMD are just microprocessor vendors. Both Intel and AMD make 80x86 microprocessors... of course they also both make ARM microprocessors, and various Berkeley RISC microprocessors. NASM is an 80x86 assembler, so it generates code compatible with all 80x86 processors no matter what vendor makes them.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Evlesoa on March 07, 2015, 03:51:55 PM
Oh, that's odd. Why would they do that...

I have decided to take C (because of its being a standard) and assembly in school for next semester's classes (I'm majoring in language, though, ha). That should be fun. Thanks for sharing. I will steer clear of anything that is poorly implemented so as to not make my learning experience miserable.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: Bryant Keller on March 11, 2015, 11:53:10 PM
It's not that it's "poorly implemented", it's just difficult to deal with. There was no universal standard for how to implement the internals of the language so compiler writers are allowed a bit of freedom in implementation details.
Title: Re: Is there really no way to learn asm from a beginner's level?
Post by: flatcircuit on October 10, 2015, 11:55:22 PM
I'm new here and I did not read every post here, but I'm new to assembly and had a similar question. Let me extend your question and answer it.

If you are an absolute beginner, the difficulty you might have with assembler is the logic or process of writing functions and algorithms, which are always simple in high level languages. In assembly language, the programming construct is super simple, you need to understand addressing and basically jumping around in memory. The tough part at least for me was as I said, finding logic to finally realize an actual program.

Quick answer. this link http://www.plantation-productions.com/Webster/ is to a website of an assembly language teacher in a university. His latest book is very different from standard assembly language, but his DOS 16/bit book is exactly what you are looking for if you use NASM or similar assemblers. The book does not teach NASM, but teaches the mathematics and the logic of writing assembly language programs. It teaches from the ground up and has everything you need. Then you can just jump to 32 bit and 64 bit. That should be so obvious, that if you can't jump to 32 or 64 bit after that text, then you should go over it again.

This really teaches everything from the ground up. Other than that, you might want to learn Win32 assembly, which I am just now starting to look at myself. I'm still an absolute beginner in asm both ways, but I have experience with High Level Languages, such as C/C++ and Visual Basic. ... and don't let anyone tell you that you need that first to learn assembly. However, if you plan on a professional career, it would be beneficial to start with a High Level language.

Also, I would never go against a professional and teacher like Randal Hyde (the link I mentioned above), but if you pick up the newer 32 bit versions of his books, you might want to skip learning HLA, it's a custom language he is designing, but when I wanted to learn pure assembler, I discovered, that it was too cumbersome. but who knows you migh like it. My recommendation is his DOS 16bit book. You can even get FreeDOS to program in a virtual machine. Very cool.

So as a beginner, I noticed your question right away. You are looking for programming logic as it relates to assembly language. With that said, after a few weeks or months, most advanced texts should be much easier to use at least as a reference. That is the only way assembly is easy. Just keep at it and it will fall into place.