Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 06, 2016, 03:52:47 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: FBSL - How to use machine code to get your CPU name  (Read 5595 times)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
FBSL - How to use machine code to get your CPU name
« on: March 18, 2006, 06:59:22 AM »
Hello,

FBSL and machine code are not incompatible... :)
You can use the FBSL online compiler to see the results : http://gedd123.free..../studio/fbsl2exe.php

#Option Explicit

'// The last one is 0 to null-terminate
Dim $CPUName    : Alloc( CPUName, 13 )

'// Set up machine code
Dim MachineCode = Data(&H55,&H8B,&HEC,&H57,&H52,&H51,&H53,&H8B,&H45,&H8,&HF,_
                  &HA2,&H8B,&H7D,&HC,&H89,&H1F,&H8B,&H7D,&H10,&H89,&HF,&H8B,_
                  &H7D,&H14,&H89,&H17,&H58,&H59,&H5A,&H55,&HC9,&HC2,&H10,&H0_
                  )

'// Calls the machine code
CallAbsolute( MachineCode, 0, @CPUName, @CPUName+8, @CPUName+4)
MsgBox(0, CpuName, "You CPU is...", 0)
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #1 on: March 18, 2006, 12:25:23 PM »
Eek, that looks like how pascal did machine code before the inline assembler was added :P
- carpe noctem

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #2 on: March 18, 2006, 03:24:01 PM »
Hello,

Eek, that looks like how pascal did machine code before the inline assembler was added :P


The way Fbsl handles 'asm' is in fact a pure trick available via a system APi call, but it works from win95 up to 2003 and even latests M$ actual betas... :)
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #3 on: March 18, 2006, 04:48:08 PM »
Oh, system call API?

btw, how does your 'asm' code do API calls? :P
- carpe noctem

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #4 on: March 18, 2006, 06:21:32 PM »
Looks remarkably like what you used to have to do with a Sinclair ZX81 back in the early 70s ;)

Anyone else remember peeking and poking bytes in memory?

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #5 on: March 18, 2006, 06:25:39 PM »
Hi,

Looks remarkably like what you used to have to do with a Sinclair ZX81 back in the early 70s ;)

Anyone else remember peeking and poking bytes in memory?

Peek and Poke exist in FBSL also, but they have been enhanced :)

Peek( [@ ]addr[+offset], [$%!#]numofbytes )

Parameters
[@ ]addr[+offset] : address from where to retrieve value(s). @ and offset are extended options
[$%!#]numofbytes : you have to precise the very number of bytes to retrieve from the addr variable, and you have to precise the very type by prefixing the very offset by $, %, ! or #

------------------------------------

Poke( [@ ]addr[+offset], [$%!#]val )

Parameters
[@ ]addr[+offset] : variable [address] where to write value(s).
[$%!#]val : value(s) to write to at mandated address. You have to precise the very type by prefixing the very offset by $, %, ! or #

So ? :)
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #6 on: March 19, 2006, 05:10:10 AM »
Ahhhhhhh - a nostaligia rush has just swept over me .... peek-a-boo ? (I won't try the other version in case of misunderstanding ;))

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #7 on: March 19, 2006, 04:26:04 PM »
Dear Carol,

Ahhhhhhh - a nostaligia rush has just swept over me .... peek-a-boo ? (I won't try the other version in case of misunderstanding ;))

There are 2 main reasons why we've put Peek and Poke to Fbsl :
- 1st reason is that Peek and Poke are part of the common 'basic' languages since a long
- 2nd reason is that we have found a way of extending it that any peek poke amateur will find more than a great interest :)
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #8 on: March 20, 2006, 03:02:19 AM »
i agree with gerome, for historical reasons every basic should have peek and poke commands.
i wonder if vb.net has them.. if not, boycott it!

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #9 on: March 20, 2006, 03:24:03 AM »
i agree with gerome, for historical reasons every basic should have peek and poke commands.
i wonder if vb.net has them.. if not, boycott it!

;) You know it hasn't ... not exactly surprising though as the model used for Visual Studio is pretty much an abstraction to remove direct hardware access.

I haven't use Visual C++, presumably it has malloc() and pointers etc. Does it actually address memory or does it just give that impression? If it does then there really isn't a reason not to include peek and poke in VB.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #10 on: March 20, 2006, 03:42:14 AM »
well c++ support very low level stuff, so you better believe you can access raw memory with c and c++, otherwise it just wouldnt't be c/c++ at all :)

but it's very understandable that the .net languages would do everything they can to keep you from poking into arbitrary memory since it defeats the whole safety framework.  but now i'm really bringing us off topic..

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #11 on: March 20, 2006, 03:50:12 AM »
I presume even Visual C++ doesn't allow arbitrary rummaging around in all memory - I presume it is restricted to it's own allocation of memory? Presumably VB.Net could allow peeking and poking into its own private memory (esp. on Win2K/XP) without the potential to nuke the entire system?

Can't help feeling security would be an issue though if you can generate code on the fly and then execute it!

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #12 on: March 21, 2006, 08:19:10 AM »
Carol, you need to make a distinction between "Visual C++" and ".net" - VC++, even the 2005 version, can still do unmanaged (native) as well as managed (.net) code.

Dunno how managed code and pointers mix, but they're sure are available for native code. Not that memory allocation with malloc/free and new/delete is a good thing anyway, everybody should use resource management objects for greater security against leaks etc.

Quote
Can't help feeling security would be an issue though if you can generate code on the fly and then execute it!
Not a problem, that code will still be limited by NT's security model...
- carpe noctem

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 7,986
    • View Profile
    • Dales Computer Services
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #13 on: March 21, 2006, 11:25:42 AM »
Carol, you need to make a distinction between "Visual C++" and ".net" - VC++, even the 2005 version, can still do unmanaged (native) as well as managed (.net) code.

I was under the impression (probably wrong) that applications in Windows 2k/XP work within allocated virtual memory and can't directly address the hardware memory. I thought if you tried to access memory outside the address range of the apps allocation you got Access Violation errors etc.? Don't all apps have to address Windows and other apps memory via the various Windows libraries/API etc.?? Or am I totally barking up the wrong tree and C++ will let you do what you like?

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #14 on: March 21, 2006, 04:40:56 PM »
Hello,

Carol, you need to make a distinction between "Visual C++" and ".net" - VC++, even the 2005 version, can still do unmanaged (native) as well as managed (.net) code.

I was under the impression (probably wrong) that applications in Windows 2k/XP work within allocated virtual memory and can't directly address the hardware memory. I thought if you tried to access memory outside the address range of the apps allocation you got Access Violation errors etc.? Don't all apps have to address Windows and other apps memory via the various Windows libraries/API etc.?? Or am I totally barking up the wrong tree and C++ will let you do what you like?

Surely you can't directly with C/C++ do sucha explosive actions.
Under a certain memory scale, you can't access to it via C/C++ and the Kernel prevents you from trying to peek/poke at it : it is normal :)
But if you are using PSDK and DDK, you can find LIBS that allows you to develop drivers that allows you to have a lower memory access ;)
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: FBSL - How to use machine code to get your CPU name
« Reply #15 on: March 22, 2006, 11:14:43 AM »
Quote
I was under the impression (probably wrong) that applications in Windows 2k/XP work within allocated virtual memory and can't directly address the hardware memory. I thought if you tried to access memory outside the address range of the apps allocation you got Access Violation errors etc.? Don't all apps have to address Windows and other apps memory via the various Windows libraries/API etc.?? Or am I totally barking up the wrong tree and C++ will let you do what you like?

Unless you write device driver code (which can be done in C/C++), you're always going to be dealing with virtual memory. Hell, you're dealing with "virtual" memory even in device drivers, unless you *specifially* need a physical memory address (mapping device memory, DMA transfers, etc).

In order to run priveleged device driver code, you need the proper administrative access privileges. So again, this isn't a security problem.

Application level peek and poke will only let you write inside your own program's address space, not even in the address spaces of other programs. Well, it *is* possible to write into another process' memory, but again that requires the necessary privileges.

It's an unfortunate fact that Microsoft decided to make the default users of WinXP have administrative privileges, and this is why windows systems are "insecure". It seems like this is a thing they might be fixing with vista, but hooray and everything, there'll still be millions of XP boxes around for years, and many of those probably will remain unpatched for quite a wihle.
- carpe noctem