如何在不使用Win32 Api的情况下进行编程? [英] How can program without using Win32 Api?

查看:149
本文介绍了如何在不使用Win32 Api的情况下进行编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好程序员!



我知道这是一个疯狂的问题,狂热和非常klutzy,但有没有人问自己如何在不使用Win32的情况下编写应用程序API?



我有很长时间才有这个问题,到目前为止我没有任何答案。要知道如何在没有其他工具的情况下进行编程,那么您就会成为一名优秀的程序员我知道做这样的编程是多么困难,但我想找到关于这个主题的完整答复,我认为这里喜欢发现新事物的人有可能做到这一点。所以,任何人都有关于如何达到这样的梦想的想法或想法:)?



好​​的,这是我观点的一部分,另一部分是编程完全可执行,而不依赖于Windows库。让我解释一下我的正确观点,你知道并且所有人都知道当我们使用编译器编译源代码时,假设一个小程序,编译器将源代码从C语言转换为汇编语言,这是一种高级编程语言这是一种低级编程语言。之后,汇编代码将自动使用汇编程序转换为二进制代码;这是计算机的主要语言,恰好是处理器。因此,让我们了解到目前为止所做的所有步骤,在这一点上,我们完整地使用了二进制代码,并且此代码将是使用链接器的可执行文件。让我问一个问题,windows库中包含的函数是否已翻译成二进制代码?



当然,答案是肯定的。那么,如果代码最终被转换为二进制代码,为什么我们不能在不使用这些库的情况下编写自己的函数和我们自己的应用程序?

如果这些库尚未编码,那么头一年级的程序员如何编写程序?或者让我问一个突出的问题,他们如何编程这些库让我们可以使用它们编写我们自己的程序?



我不想重新发明轮,但我的目标是知道这些技巧:)。为了不误解我的问题的目的,我想要做的是编程没有任何链接库,如(kernel32.dll,ntdll.dll等)。



我的意思是用纯语言编程,如0和1。希望你理解我的意思:)

解决方案

你的考虑看起来非常真实,但你正在做一些打破逻辑的隐含假设。基本上,关于0和1的考虑是无关紧要的。计算机上的所有东西都是0和1; 并且OS调用也由那些0和1 组成。问题仍然存在:你是否总是需要打这个电话。



首先,很明显:并非总是如此。您可以创建一些有限的程序(让我们更正式:可执行文件,PE文件),它们根本不会使用任何OS调用。它甚至有意义。有什么限制?在使用系统外围设备的意义上,您将无法使用任何IO,将无法分配任何内存(没有它就无法编程,因为您将使用内存块由可执行加载器(OS的一部分)分配,将无法创建线程,使用线程同步和与其他进程(IPC)的通信。没有这一切,你仍然可以实现一些有用的算法(仍然,在有限的类中,因为即使一些正式和抽象的算法需要内存分配,使用)。您可以导出进行任何计算的任何静态函数;在EXE文件中,您可以使用其入口点(main函数)输出表示为一个整数值的任何计算结果。其他程序可以使用在这些限制下创建的模块。



但是你仍然可以质疑:为什么不使用I / O和我上面描述的所有限制,在一个完全独立的应用程序?在我的解释中,这简化为一个问题:你的微妙逻辑错误在哪里导致不理解为什么这是不可能的?这很难解释。



微妙的错误是:1)你没有考虑到操作系统不是一组可执行文件;区别在于:在OS bootstrap 期间, OS的一部分变为永久加载; 2)你没有考虑硬件保护



请注意,大多数现代版本的Windows系统都使用具有的Intel CPU保护模式。在保护模式下,您可以创建一些永久关闭的代码或数据,以便从其他一些代码段直接访问。保护不能绕过,因为它是在硬件中实现的。软件的某些部分加载在所谓的内核模式中,该模式限制了对某些保护环内部的许多重要资源的访问。通过将请求委托给内部保护环,所有应用程序进程只能间接访问此类资源。



如何在实践中查看?例如,在文档中,您可以读取视频卡的绝对物理地址范围和用于输出到屏幕的端口集。因此,您可以通过使用端口输出CPU指令设置某些屏幕模式来写入屏幕,并写入卡的物理地址以输出字符和像素。好吧,试着去做。您只能获得访问冲突(在操作系统方面,它将是一般保护错误)。并且,请注意,它将是由CPU直接生成的硬件异常。这些操作仅保留给内核。



这就是为什么你需要一些操作系统调用。它们实际上将对视频卡端口和内存的访问权限委托给OS的内核模式部分。 CPU具有不同环之间交互的特殊机制。物理访问是在内核模式下完成的。



系统比我试图描述的要复杂得多。有司机;其中一些是内核模式,驱动程序可以以即插即用的方式动态加载,无需重启操作系统。然而,没有OS API,这个级别上没有任何东西可以工此外,以上所有内容都与Windows和其他一些具有类似方法的系统有关,其中也包括Linux。某些操作系统可能不会采用这种保护。



要了解更多细节,您需要研究CPU架构和保护模式。首先,请参阅:

http://en.wikipedia.org/wiki/Protection_ring [ ^ ],

< a href =http://en.wikipedia.org/wiki/Protected_mode> http://en.wikipedia.org/wiki/Protected_mode [ ^ ],

http://en.wikipedia.org/wiki/Hybrid_kernel [ ^ ](现代Windows操作系统的内核类型,

http:/ /en.wikipedia.org/wiki/Windows_NT [ ^ ]。



-SA


等待其他解决方案......

Hello programmers !

I know is a crazy question, frenzy and very klutzy, but is there any one asks herself how he can program an application without using Win32 API?

I have this question since a very large time and I don't have any answers until the moment. To know how to program without other tools made you a strong programmer and made you very creative. I know how is very difficult to do such kind of programming, but I want to find out a complete reply on this subject and I think that people here who like discovering new things have the possibility to do that. So, anyone have an idea or ideas on how to reach such dream :)?

Ok, this is a part of my view, the other part is to program a complete executable without relying on windows libraries. Let me explain my proper view, you know and all people know that when we compile a source code using a compiler, supposing a little C program, the compiler converts the source code from the C language which is a high level programming language to Assembly language which is a low level programming language. Afterwards, the Assembly Code automatically will be translated using an Assembler to the binary code; which is the main language of the computer precisely the processor. So, let us understand what all the steps do until now, in this point we have the binary code in its entirety and this code will be an executable using a Linker. Let me ask a question, is the functions included in windows libraries have translated to the binary code?

Of course, the answer is "yes". So, why we cannot write our own functions and our own applications without using these libraries if the code will be translated finally to the Binary Code ?
How programmers in the first ages make their programs when these libraries are not coded yet ? Or let me ask the prominent question, how they program these libraries that give us the possibility to code our own programs using them?

I don't want to reinvent the wheel, but my aim is to know these tricks :). In order to not misunderstand the aim of my question, what I want to do is to program without any linking libraries such as(kernel32.dll, ntdll.dll, etc.).

I mean programming in pure language like 0s and 1s. Hope you understand what I meant :)

解决方案

Your considerations look very true-like, but you are doing some implicit assumptions which break the logic. Basically, the considerations about 0s and 1s are irrelevant. Everything on a computer is made of 0s and 1s; and OS calls are also made of those 0s and 1s. The question remain open: do you always need to do this call.

First of all, it is apparent: not always. You can create some limited class of "programs" (let's be more formal: executable files, PE files) which won't use any OS calls at all. And it even makes sense. What are the limitations? You won't be able to use any IO, in the sense of using system peripherals, won't be able to allocate any memory (you cannot program without it, because you would then use the memory block allocated by the executable loader, part of OS), won't be able to create thread, use thread synchronization and communication with other processes (IPC). Without all that, you still can implement some useful algorithm (still, in a limited class, because even some formal and abstract algorithms need memory allocation, the use of heap). You can export any static functions doing any calculations; in EXE file, you can use its entry point ("main" function) to output result of any calculations represented as one integer value. Other programs can use your module created under these limitations.

But you may still question: why not using I/O and all I described above as a set of limitations, in a fully stand-along application? In my interpretation, this is reduced to the question: where is your subtle logical mistake which led to not understanding why this is impossible? This is harder to explain.

The subtle mistake is: 1) you did not take into account that OS is not a set of executable file; the difference is: during OS bootstrap, part of OS becomes permanently loaded; 2) you did not take into account hardware protection.

Note that most modern versions of Windows systems use Intel CPUs which has protected mode. In protected mode, you can create some code or data segments which are permanently closed for direct access from some other code segments. The protection cannot be bypasses, because it is implemented in hardware. Some part of software is loaded in so-called kernel mode which confines access to many important resources inside certain protection ring. All application processes can get access to such resource only indirectly, by delegating a request to the inner protection ring.

How is looks in practice? For example, in documentation, you can read absolute range of physical addresses of a video card and set of ports used for output to the screen. So, you can write to screen by setting certain screen modes using the port output CPU instructions, and write to physical address of the card to output characters and pixels. Well, try to do it. All you can get is access violation (in OS terms, it will be General Protection Fault). And, mind you, it will be a hardware exception generated directly by the CPU. Such operations are reserved to the kernel only.

This is why would you need some OS calls. They actually delegate the access to the video card ports and memory to the kernel-mode part of OS. The CPU has the special mechanism for interaction between different rings. The physical access is done in kernel mode.

The system is much more complicated than I tries to describe. There are drivers; some of them are kernel-mode, and the drivers can be loaded dynamically, in a plug-and-play manner, without a need to reboot the OS. Yet, nothing on this level works without OS API. Also, all of the above is related to Windows and some other systems with similar approach, which also includes Linux. Some OS may not employ such protection.

To understand further detail, you would need to study CPU architectures and protected mode. To start with, please see:
http://en.wikipedia.org/wiki/Protection_ring[^],
http://en.wikipedia.org/wiki/Protected_mode[^],
http://en.wikipedia.org/wiki/Hybrid_kernel[^] (the type of kernel of the modern Windows OS,
http://en.wikipedia.org/wiki/Windows_NT[^].

—SA


Waiting for other solutions...


这篇关于如何在不使用Win32 Api的情况下进行编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆