APK file for Android - what is it and how to open it?

What is APK

To download games and applications on Android, you should understand that this is an APK extension. Android Package Kit is a file format used to install software on Android and includes its zipped components. One such file is enough to install a working application. APK is supported not only by the Android platform. Using special utilities, you can open them on Windows, Linux or Mac.

The purpose of the APK is to quickly install software. When it is launched, all components from the archive are unpacked one by one. In addition, they are used by the developers themselves, who can extract fragments of the application and work with them - edit, debug, etc.

Opening Office files

It is difficult to find a user who has never encountered files created in Word and Excel.

To work with them on Android, you can use applications from Microsoft, which has released an analogue of its MS Office for the popular smartphone platform.

The functionality of the package is practically not inferior to real Word and Excel, but to get full versions you will have to subscribe to the paid Office 365 package (from $100 per year).

Mobile MS Office is available free of charge on smartphones with the Windows Phone operating system.

Fig.8. Word for Android

The ability to open files with the extension .doc, .docx, .xls, .xlsx, .ppt and .pptx is also available in QuickOffice Connect, Smart Office and Kingsoft Office.

The OfficeSuite application also supports working with Open Office documents.

Fig.9. Creating Charts in Smart Office

A little theory

  • Apk is an installation package format for the Android operating system. It is a single file, the name of which says apk after the dot.
  • The file itself is an archive containing all the necessary information - these are images, program code and components of the program, how it should behave on such and such a device, and so on.
  • You can open the file using a regular archiver, or even better from Total Commander. This is for those who are especially interested in seeing what is inside.
  • The files are needed in order to independently install third-party applications that are either not on the market, or you are too lazy to look for them there. How to install, see and read below.

What files does Android open?

You can no longer do anything without a smart gadget, be it study, work or anything else. Android can open many standard files: mp3, mp4, avi. Of course, in order to open a file on Android, a special application is required. Thus, you can open almost any file on Android if you install the appropriate utility.

Let's look at what files can be opened on Android:

  • txt
  • doc
  • xls
  • zip
  • apk
  • pdf
  • html

You can open avi, mp3, mp4 using the programs that we described in our articles:

  • How to watch videos on Android
  • – some applications from this article not only download audio files, but also play them

What's inside the APK file?

APK files have a clearly defined structure.

  • META-INF: MANIFEST.MF – file with data about other files located in this archive (file checksums);
  • CERT.RSA – the certificate with which the application is signed;
  • CERT.SF – file with data about the certificate and resources;
  • lib – Linux libraries for each supported processor type are stored here:
      armeabi – for ARMv6 and older processors;
  • armeabi-v7a – for ARMv7 and newer processors;
  • x86 – for processors with x86 architecture;
  • mips – for MIPS processors;
  • res – resources not contained in resources.arsc (see below).
  • Assets – resources that are used by AssetManager.
  • AndroidManifest.xml – a file describing the application. This file stores the name, package name, version, and other data related to this application.
  • classes.dex – executable code in DEX format;
  • resources.arsc – compiled resources;
  • Viewing the contents of an APK file is very simple and anyone can do it. All you need to do is open the APK file with any archiver. For example, you can use the free archiver 7Zip.

    Why do I need to install an APK file?

    Android apps are not limited to the Google Play Store. Third-party developers release their own apps in APK files that offer exciting features. Additionally, some apps on the Google Play Store cannot be installed in your country. However, you can download the APK file and install the desired application bypassing the Google Play Store.

    If your Android device does not have access to the Google Play Store, APK files are the only option for installing applications.

    However, you should be careful because third-party APK files can be malicious. Some APK files allow you to download pirated applications. Of course, such APK files should be avoided.

    Reasons to run Android apps on Windows

    The reasons why you need to run Android applications on your PC may be the following:

    • The software may not be available in the official Play Market application store. In this case, you need to look for a third-party resource where you will need to download an apk file. As a rule, not all programs downloaded through third-party sources may be safe. Some of them may contain malicious code that will allow attackers to take over the user's personal data.

    Running Android software on a personal computer

    • The mobile phone does not have enough memory and does not support large format flash cards. In this case, it is recommended to install and run Android programs on a personal computer.
    • A user runs an online business and wants to organize applications on his smartphone. Install important programs on your smartphone, and transfer applications that the phone owner does not use very often to your PC.
    • The user is the owner of an iPhone smartphone from the manufacturer Apple, and the required application is not in the App Store. In this case, it will be important to download the Android emulator program and run the required software through it.

    Interesting! One common reason is when a user needs to create multiple accounts on different devices.

    How to download and install

    The largest APK repository is the Play Market. Its peculiarity is that the site does not allow you to download the file itself to your mobile device, but immediately installs it, so the user does not have to think about how and with what to open the APK on Android

    If the user needs content that is not on Google Play, he can find the APK on the Internet. It is important to download them only from trusted sites, otherwise there is a risk of downloading malware or infecting your equipment with viruses.

    You can find an APK on the Internet and download it to your computer, and then transfer it via cable, Bluetooth or other method to your phone or tablet. Another solution is to download directly to the mobile device’s memory through its browser.

    After downloading:

    • Open your smartphone settings.
    • Go to the “Security” tab.

    • Find the line “Unknown sources” and activate the function to allow installation of software from APK.

    • Find the downloaded APK in your phone's memory and click on it to begin installation.

    • Confirm installation.

    Next, all you have to do is wait for the operation to complete, and then start working with the application or launch the game.

    Preparing Android OS

    The smartphone will automatically recognize any application that does not come from Google Play as an “unknown application”. Therefore, in the settings you need to allow installation from unknown sources.

    This is quite easy to do. Go to the settings section. Select "Security" (or "Lock screen and security"). Find "Device Administration" and enable installation from unknown sources.

    After allowing the installation of applications from unknown sources, you will need to find the APK file on your smartphone. Usually, Android already has a standard file manager. If it is not there, go to Google Play and look for applications using the keyword “File Manager”. Many options will appear. Choose any of them or just download the most popular one - Cx File Explorer.

    File Type Compatibility

    PDFDOCXXLSXPPTXODTRTFO.D.S.TXT
    GOOGLE DRIVEYesYesYesYesYesYesYesYes
    WPS OFFICEYesYesYesYesYesYesYesYes
    MICROSOFT APPSNoYesYesYesNoNoNoNo

    Many smartphone manufacturers also pre-install WPS Office. This app contains advertisements and if you want to unlock new fonts and convert documents/files on Android, you will have to spend money. However, many users appreciate the seamless connection to Dropbox and good synchronization capabilities between smartphone/tablet and PC.

    SmartOffice is another useful app for those looking for a completely free alternative to Microsoft Office for Android. This app still has a few issues (depending on your device), but it's ad-free, easy to use, and updated regularly.


    Get started with WPS Office.

    Easy way

    The easiest way to install APK on Android is to download it using your mobile browser. Find a site that offers an Android app. On it you will see a download link. A pop-up window may appear asking if you want to allow the browser to save files to your smartphone storage. Please agree. You'll also see a warning that "this file type may damage your device." Just click "OK" and continue.

    If your smartphone browser does not allow you to open the file after downloading, open your file manager and find the Downloads folder. Click on the downloaded file and allow the application to perform the necessary actions it requests. Then, at the bottom of the window, click the “Install” button.

    You will see a notification that the application has been installed. After that it should appear in the list of programs. If something doesn't work out, try using other methods.

    Medium difficulty method

    If you don't have internet access or for some other reason you can't use a browser, you can install the application from your desktop computer.

    Using a browser on your computer, download the APK. Then connect your smartphone to your computer and copy the file to it. If you've never done this before, you'll need to enable USB debugging.

    To do this, select Settings, scroll down to About Device, and tap Build Number seven times. This will open up the hidden developer menu for you. Go back to Settings, select Developer Options, and click USB Debugging. Check the box next to “USB Debugging”.

    Now you can connect your smartphone to your computer using a USB cable. The device should be detected in the same way as a memory card or flash drive. Move the file downloaded from the site to your smartphone. Here's what you need to do to do this:

    1. Find the file you need on your computer.
    2. Right-click on it and select “Copy”.
    3. Find your smartphone on your PC, which appears as a removable drive.
    4. Open it and find the /sdcard/download folder.
    5. Copy the APK to this folder.

    Once the copying is complete, use the file manager on your smartphone to find it and launch it.

    If you don't have a USB cable, you can install WiFi FTP-Server from Google Play and then use an FTP client on your computer to transfer the file. But this is a more complicated option; a USB cable is usually easier to find.

    There is no GPU selection in the NVIDIA Control Panel - what should I do?

    If there is no option to add Run with a Specific GPU to the context menu in either the Nvidia Control Panel or Display Settings, it is likely that your GPU chipset does not support Nvidia Optimus technology. Optimus technology allows the Nvidia GPU to be activated at a specific moment when it is needed. To check if your NVIDIA graphics card supports this technology, follow this link. There is a list of all GPUs that support Optimus technology.

    Also, make sure you have the latest video card driver installed . Older drivers and outdated versions of Nvidia Control Panel may not have this capability.

    Advanced method

    If for some reason the APK installer does not launch when you click on it on your smartphone, you can resort to an emergency solution. In this case, it is assumed that APK Installer will be launched with Minimal ADB and Fastboot. You can install the app on your Android device from your computer using a simple tool called Minimal ADB and Fastboot.

    You need to follow the steps described in the previous section to connect your smartphone to your PC. Then download and install the latest version of Minimal ADB and Fastboot on your computer. Launch the tool and open a command prompt. After synchronizing your smartphone with your PC, enter the command:

    adb devices

    If the program detects a smartphone, you will see its identifier in the list of connected devices.

    Now, using Windows Explorer, navigate to the Minimal ADB and Fasbtoot folder (usually C:Program Files (x86)Minimal ADB and Fastboot). Paste the APK file into this folder. You can rename the file by giving it a short name. This will make it easier to manually enter it into the command line.

    Back in the same command window you opened earlier, enter the command

    How to install APK from your Android device

    To start the installation, you can use a regular browser on your smartphone, from any manufacturer.

    Instructions:

    1. Launch a web browser and find the file on the relevant site.
    2. Start loading the item, as indicated by a notification in the top panel of the device.
    3. Once the download is complete, open the “Downloads” section and tap the APK file.
    4. At startup, the system will ask for permission, in which you need to click on the “Yes” button.
    5. Wait for the installation to complete and enjoy the program.

    How to install APK files from computer?

    Due to the abundance of sites on the Internet that distribute APK files, you need to first check the reputation of the web resource and use one or two of them that are trusted. Such a solution will significantly reduce the risks to data confidentiality and device security. One of the trusted sites is APK Mirror. Downloading from here is much safer than from other sources, but there is still no complete guarantee. Usually, if viruses are detected in a file, there is a note about this in comments and reviews.

    Management:

    1. Initially, you need to find the target file on the Internet and download it to a convenient place for further use.
    2. Take your smartphone in your hand and go to “Settings”, and then “Security”. Here or in one of the subsections you need to activate the “Unknown sources” item, if this has not been done previously. This action will allow you to install applications not from the Google Play Store. In recent versions of Android, there is no need to set a global setting to allow installation from third-party sources. Instead, when attempting to install, a notification appears asking you to allow the action.

    3. Synchronize your computer with your Android smartphone and select the “Multimedia device” or storage mode. This way the PC will be able to work with files on the phone.
    4. Open a new disk with the name of the gadget in Windows, namely in the “This PC” section.
    5. Copy the APK file and place it in a suitable folder on your Android device.
    6. On your phone, find the downloaded item through Explorer or the file manager, tap it and select the “Install” option.

    After a certain waiting time, the application will appear in the system. Now you can open it and check that it is working correctly. If the procedure does not bring the expected result, you should repeat it with another APK file. Most likely you will have to change the download source.

    How to run a program without an operating system

    It so happened that in our article describing the PCI bus polling mechanism, the most important thing was not described in sufficient detail: how to run this code on real hardware? How to create your own boot disk? In this article we will answer all these questions in detail (partially these questions were discussed in the previous article, but for ease of reading we will allow ourselves a slight duplication of material). There are a huge number of descriptions and tutorials on the Internet about how to write your own mini-OS; there are even hundreds of ready-made small hobby OSes. One of the most worthy resources on this topic, which I would like to especially highlight, is the osdev.org portal. To complement the previous article about PCI (and the opportunity to write subsequent articles about the various functions that are present in any modern OS), we will describe step-by-step instructions for creating a boot disk with a familiar program in C. We tried to write in as much detail as possible so that everything is possible figure it out on your own.

    So, the goal: with as little effort as possible, create your own bootable flash drive, which just prints the classic “Hello World” on the computer screen.

    To be more precise, we need to “get into” protected mode with page addressing and interrupts disabled - the simplest mode of processor operation with familiar behavior for a simple console program. The smartest way to achieve this goal is to build a kernel that supports the multiboot format and boot it using the popular Grub boot loader. An alternative to this solution is to write your own volume boot record (VBR), which would load your own written loader. A decent bootloader, at a minimum, should be able to work with a disk, with a file system, and parse elf images. This means that you need to write a lot of assembly code, and a lot of code in C. In short, it’s easier to use Grub, which can already do everything you need.

    Let's start with the fact that for further actions you need a certain set of compilers and utilities. The easiest way is to use some Linux (for example, Ubuntu), since it will already contain everything you need to create a bootable flash drive. If you are used to working on Windows, you can set up a virtual machine with Linux (using Virtual Box or VMware Workstation).

    If you are using Linux Ubuntu, then first of all you need to install several utilities: 1. Grub. To do this we will use the command:

    sudo apt-get install grub

    2. Qemu. It is needed to quickly test and debug everything, for this the command is similar:

    sudo apt-get install qemu

    Now our plan looks like this: 1. Create a C program that prints a string on the screen. 2. build an image from it (kernel.bin) in miniboot format so that it is available for boot using GRUB. 3. create a boot disk image file and format it. 4. install Grub on this image. 5. copy the created program (kernel.bin) to disk. 6. burn the image to physical media or run it in qemu.

    and the system boot process:

    For everything to work, you will need to create several files and directories:

    kernel.c Program code written in C. The program prints a message on the screen.
    makefile Makefile, a script that does all the building of the program and creating the boot image.
    linker.ld Linker script for the kernel.
    loader.s Assembly code that is called by Grub and passes control to the main function from the C program.
    include/ Folder with header files.
    grub/ Folder with Grub files.
    common/ General purpose folder. Including the implementation of printf.

    Step 1. Creating the code for the target program (kernel):

    Create a file kernel.c, which will contain the following code that prints a message on the screen:

    #include "printf.h" #include "screen.h" #include "types.h" void main(void) { clear_screen(); printf("\n>>> Hello World!\n"); }

    Everything here is familiar and simple. Adding the printf and clear_screen functions will be discussed further. In the meantime, we need to supplement this code with everything necessary so that it can be loaded by Grub. In order for the kernel to be in multiboot format, the first 8 kilobytes of the kernel image must contain the following structure:

    0x1BADB002 = MAGIC Multiboot format signature
    0x0 = FLAGS Flags that contain additional requirements for loading the kernel and parameters passed by the bootloader to the kernel (our program). In this case, all flags are cleared.
    0xE4524FFE= -(MAGIC + FLAGS) Check sum.

    If all the specified conditions are met, then Grub passes a pointer to the multiboot Information structure and the value 0x1BADB002 through the %eax and %ebx registers, respectively. The multiboot Information structure contains various information, including a list of loaded modules and their location, which may be needed for further booting of the system. In order for the program file to contain the necessary signatures, we will create a loader.s file with the following contents:

    .text .global loader # making entry point visible to linker # setting up the Multiboot header — see GRUB docs for details .set FLAGS, 0x0 # this is the Multiboot 'flag' field .set MAGIC, 0x1BADB002 # 'magic number' lets bootloader find the header .set CHECKSUM, -(MAGIC + FLAGS) # checksum required .align 4 .long MAGIC .long FLAGS .long CHECKSUM # reserve initial kernel stack space .set STACKSIZE, 0x4000 # that is, 16k. .lcomm stack, STACKSIZE # reserve 16k stack .comm mbd, 4 # we will use this in kmain .comm magic, 4 # we will use this in kmain loader: movl $(stack + STACKSIZE), %esp # set up the stack movl %eax, magic # Multiboot magic number movl %ebx, mbd # Multiboot data structure call main # call C code cli hang: hlt # halt machine should kernel return jmp hang

    Let's look at the code in more detail. This code, almost unchanged, is taken from wiki.osdev.org/Bare_Bones. Since gcc is used for compilation, GAS syntax is used. Let's take a closer look at what this code does.

    .text All subsequent code will end up in the executable .text section. .global loader Declare the loader symbol visible to the linker. This is required because the linker will use the loader as an entry point. .set FLAGS, 0x0 # assign FLAGS = 0x0 .set MAGIC, 0x1BADB002 # assign MAGIC = 0x1BADB002 .set CHECKSUM, -(MAGIC + FLAGS) # assign CHECKSUM = -(MAGIC + FLAGS) .align 4 # align subsequent data to 4 bytes .long MAGIC # place the value of MAGIC at the current address .long FLAGS # place the value of FLAGS at the current address .long CHECKSUM # place the value of CHECKSUM at the current address This code generates a Multiboot format signature. The .set directive sets the value of a character to the expression to the right of the comma. The .align 4 directive aligns subsequent content to 4 bytes. The .long directive stores the value in the next four bytes. .set STACKSIZE, 0x4000 # set STACKSIZE = 0x4000 .lcomm stack, STACKSIZE # reserve STACKSIZE bytes. stack refers to the range .comm mbd, 4 # reserve 4 bytes for the mdb variable in the COMMON area .comm magic, 4 # reserve 4 bytes for the magic variable in the COMMON area Grub does not configure the stack during boot, and the first thing the kernel must do is configure stack, for this we reserve 0x4000(16Kb) bytes. The .lcomm directive reserves the number of bytes specified after the decimal point in the .bss section. The stack name will only be visible in the compiled file. The .comm directive does the same as .lcomm, but the symbol name will be declared globally. This means that by writing the following line in C code, we can use it. extern int magic

    And now the last part:

    loader: movl $(stack + STACKSIZE), %esp # initialize the stack movl %eax, magic # write %eax to the address magic movl %ebx, mbd # write %ebx to the address mbd call main # call the main function cli # disable interrupts from hardware hang: hlt # stop the processor until an interrupt occurs jmp hang # jump to the hang label

    The first instruction stores the value at the top of the stack in the %esp register. Since the stack grows downwards, the address of the end of the range allocated for the stack is written to %esp. The next two instructions store in previously reserved 4-byte ranges the values ​​that Grub passes in the %eax, %ebx registers. Then the main function is called, which is already written in C. If this procedure returns, the processor will go into a loop.

    Step 2. Preparing additional code for the program (system library):

    Since the entire program is written from scratch, the printf function must be written from scratch. To do this, you need to prepare several files. Let's create a common and include folder:

    mkdir common mkdir include

    Let's create a file common\printf.c, which will contain an implementation of the familiar printf function. This entire file can be taken from the www.bitvisor.org project. Path to the file in the bitvisor sources: core/printf.c. In the printf.c file copied from bitvisor, for use in the target program you need to replace the lines:

    #include "initfunc.h" #include "printf.h" #include "putchar.h" #include "spinlock.h" on lines: #include "types.h" #include "stdarg.h" #include "screen. h"

    Then, remove the printf_init_global function and all its references in this file:

    static void printf_init_global(void) { spinlock_init(&printf_lock); } INITFUNC("global0", printf_init_global);

    Then remove the printf_lock variable and all references to it in this file:

    static spinlock_t printf_lock; ... spinlock_lock (&printf_lock); ... spinlock_unlock (&printf_lock);

    The printf function uses the putchar function, which also needs to be written. To do this, create a file common\screen.c with the following content:

    #include "types.h" #define GREEN 0x2 #define MAX_COL 80 // Maximum number of columns #define MAX_ROW 25 // Maximum number of rows #define VRAM_SIZE (MAX_COL*MAX_ROW) // Size of screen, in short's #define DEF_VRAM_BASE 0xb8000 // Default base for video memory static unsigned char curr_col = 0;8) static unsigned char curr_row = 0; // Write character at current screen location #define PUT(c) ( ((unsigned short *) (DEF_VRAM_BASE)) \ [(curr_row * MAX_COL) + curr_col] = (GREEN << | (c)) // Place a character on next screen position static void cons_putc(int c) { switch (c) { case '\t': do { cons_putc(' '); } while ((curr_col %8) != 0); break; case '\r': curr_col = 0; break; case '\n': curr_row += 1; if (curr_row >= MAX_ROW) { curr_row = 0; } break; case '\b': if (curr_col > 0) { curr_col -= 1; PUT(' '); } break; default: PUT(c); curr_col += 1; if (curr_col >= MAX_COL) { curr_col = 0; curr_row += 1; if (curr_row >= MAX_ROW) { curr_row = 0; } } }; } void putchar( int c ) { if (c == '\n') cons_putc('\r'); cons_putc(c); } void clear_screen( void ) { curr_col = 0; curr_row = 0; int i; for (i = 0; i < VRAM_SIZE; i++) cons_putc(' '); curr_col = 0; curr_row = 0; }

    The specified code contains simple logic for printing characters to the screen in text mode. In this mode, two bytes are used to record a character (one with the character code, the other with its attributes), written directly to the video memory displayed immediately on the screen and starting at address 0xB8000. The screen resolution is 80×25 characters. The character is directly printed using the PUT macro. Now only a few header files are missing: 1. The include\screen.h file. Declares the putchar function, which is used in the printf function. File contents:

    #ifndef _SCREEN_H #define _SCREEN_H void clear_screen( void ); void putchar(int c); #endif

    2. File include\printf.h. Declares the printf function, which is used in main. File contents:

    #ifndef _PRINTF_H #define _PRINTF_H int printf (const char *format, ...); #endif

    3. File include\stdarg.h. Declares functions for enumerating arguments, the number of which is not known in advance. The entire file is taken from the www.bitvisor.org project. Path to the file in the bitvisor project code: include\core\stdarg.h. 4. File include\types.h. Declares NULL and size_t. File contents:

    #ifndef _TYPES_H #define _TYPES_H #define NULL 0 typedef unsigned int size_t; #endif Thus, the include and common folders contain the minimum system library code that any program needs.

    Step 3: Create a script for the linker:

    We create a file linker.ld, which will be used by the linker to generate the target program file (kernel.bin). The file should contain the following:

    ENTRY (loader) LMA = 0x00100000; SECTIONS { . = LMA; .multiboot ALIGN (0x1000) : { loader.o( .text ) } .text ALIGN (0x1000) : { *(.text) } .rodata ALIGN (0x1000) : { *(.rodata*) } .data ALIGN (0x1000 ) : { *(.data) } .bss : { *(COMMON) *(.bss) } /DISCARD/ : { *(.comment) } }

    The built-in function ENTRY() allows us to set the entry point for our kernel. It is to this address that grub will transfer control after loading the kernel. The linker will use this script to create a binary file in ELF format. An ELF file consists of a set of segments and sections. The list of segments is contained in the Program header table, the list of sections in the Section header table. The linker operates with sections, the image loader (in our case, GRUB) with segments.

    As can be seen in the figure, segments consist of sections. One of the fields that describes a section is the virtual address where the section should be located at the time of execution. In fact, a segment has 2 fields that describe its location: the virtual address of the segment and the physical address of the segment. The virtual address of a segment is the virtual address of the first byte of the segment at the time the code is executed, the physical address of the segment is the physical address at which the segment should be loaded. For application programs, these addresses are always the same. Grub loads image segments by their physical address. Since Grub does not configure page addressing, the virtual address of a segment must match its physical address, since virtual memory is also not configured in our program.

    SECTIONS Indicates that the following sections are described. . = LMA; This expression tells the linker that all subsequent sections are after the LMA address. ALIGN (0x1000) The above directive means that the section is aligned at 0x1000 bytes. .multiboot ALIGN (0x1000) : { loader.o( .text ) } A separate multiboot section, which includes the .text section from the loader.o file, is made to ensure that the multiboot format signature is included in the first 8kb of the kernel image. .bss : { *(COMMON) *(.bss) } *(COMMON) is the area in which memory is reserved by the .comm and .lcomm instructions. We place it in the .bss section. /DISCARD/ : { *(.comment) } All sections marked DISCARD are removed from the image. In this case, we remove the .comment section, which contains information about the linker version.

    Now let's compile the code into a binary file using the following commands:

    as -o loader.o loader.s gcc -Iinclude -Wall -fno-builtin -nostdinc -nostdlib -o kernel.o -c kernel.c gcc -Iinclude -Wall -fno-builtin -nostdinc -nostdlib -o printf.o -c common/printf.c gcc -Iinclude -Wall -fno-builtin -nostdinc -nostdlib -o screen.o -c common/screen.c ld -T linker.ld -o kernel.bin kernel.o screen.o printf .o loader.o Using objdump, let's look at what the kernel image looks like after linking: objdump -ph ./kernel.bin

    As you can see, the sections in the image coincide with those that we described in the linker script. The linker formed 3 segments from the described sections. The first segment includes sections .multiboot, .text, .rodata and has a virtual and physical address of 0x00100000. The second segment contains the .data and .bss sections and is located at address 0x00104000. This means you are ready to load this file using Grub.

    Step 4. Preparing the Grub bootloader: Create the grub folder:

    mkdir grub

    Copy into this folder several Grub files that are necessary to install it on the image (the following files exist if Grub is installed on the system). To do this you need to run the following commands:

    cp /usr/lib/grub/i386-pc/stage1 ./grub/ cp /usr/lib/grub/i386-pc/stage2 ./grub/ cp /usr/lib/grub/i386-pc/fat_stage1_5 ./grub /

    Create a file grub/menu.lst with the following content:

    timeout 3 default 0 title mini_os root (hd0,0) kernel /kernel.bin

    Step 5. Automate and create a boot image:

    To automate the build process we will use the make utility. To do this, we will create a makefile that will compile the source code, build the kernel and create a boot image. The Makefile should have the following contents: CC=gcc CFLAGS=-Wall -fno-builtin -nostdinc -nostdlib LD=ld OBJFILES=\loader.o\common/printf.o\common/screen.o\kernel.o image: @echo "Creating hdd.img..." @dd if=/dev/zero of=./hdd.img bs=512 count=16065 1>/dev/NULL 2>&1 @echo "Creating bootable first FAT32 partition..." @losetup / dev/loop1 ./hdd.img @(echo c; echo u; echo n; echo p; echo 1; echo ; echo ; echo a; echo 1; echo t; echo c; echo w;) | fdisk /dev/loop1 1>/dev/NULL 2>&1 || true @echo "Mounting partition to /dev/loop2..." @losetup /dev/loop2 ./hdd.img \ --offset `echo \`fdisk -lu /dev/loop1 | sed -n 10p | awk '{print $$3}'\`*512 | bc` \ --sizelimit `echo \`fdisk -lu /dev/loop1 | sed -n 10p | awk '{print $$4}'\`*512 | bc` @losetup -d /dev/loop1 @echo “Format partition...” @mkdosfs /dev/loop2 @echo “Copy kernel and grub files on partition...” @mkdir -p tempdir @mount /dev/loop2 tempdir @mkdir tempdir /boot @cp -r grub tempdir/boot/ @cp kernel.bin tempdir/ @sleep 1 @umount /dev/loop2 @rm -r tempdir @losetup -d /dev/loop2 @echo “Installing GRUB...” @echo “ device (hd0) hdd.img \n \ root (hd0,0) \n \ setup (hd0) \n \ quit\n» | grub --batch 1>/dev/NULL @echo "Done!" all: kernel.bin rebuild: clean all .so: as -o [email protected] $< .co: $(CC) -Iinclude $(CFLAGS) -o [email protected] -c $< kernel.bin: $( OBJFILES) $(LD) -T linker.ld -o [email protected] $^ clean: rm -f $(OBJFILES) hdd.img kernel.bin
    The file declares two main purposes: all - compiles the kernel, and image - which creates a boot disk. The all goal, like the usual makefile, contains subgoals .so and .co, which compile *.s and *.c files into object files (*.o), as well as a goal for generating kernel.bin, which calls the linker with the previously created script. These targets perform exactly the same commands that are specified in step 3. Of greatest interest here is the creation of a boot image hdd.img (target image). Let's look at how this happens step by step.

    dd if=/dev/zero of=./hdd.img bs=512 count=16065 1>/dev/NULL 2>&1 This command creates an image with which further work will occur. The number of sectors was not chosen at random: 16065 = 255 * 63. By default, fdsik works with the disk as if it had CHS geometry, in which Headers (H) = 255, Sectors (S) = 63, and Cylinders (C) depends on disk size. Thus, the minimum disk size that the fdsik utility can work with, without changing the default geometry, is 512 * 255 * 63 * 1 = 8225280 bytes, where 512 is the sector size and 1 is the number of cylinders. Next, a partition table is created: losetup /dev/loop1 ./hdd.img (echo c; echo u; echo n; echo p; echo 1; echo ; echo ; echo a; echo 1; echo t; echo c; echo w; ) | fdisk /dev/loop1 1>/dev/NULL 2>&1 || true The first command mounts the hdd.img file to the block device /dev/loop1, allowing the file to be treated as a device. The second command creates a partition table on the /dev/loop1 device that contains 1 primary boot disk partition that occupies the entire disk, labeled FAT32. Then we format the created partition. To do this, you need to mount it as a block device and format it. losetup /dev/loop2 ./hdd.img \ —offset `echo \`fdisk -lu /dev/loop1 | sed -n 10p | awk '{print $$3}'\`*512 | bc` \ --sizelimit `echo \`fdisk -lu /dev/loop1 | sed -n 10p | awk '{print $$4}'\`*512 | bc` losetup -d /dev/loop1 The first command mounts the previously created partition to the /dev/loop2 device. The –offset option specifies the address of the beginning of the section, and –sizelimit specifies the address of the end of the section. Both options are obtained using the fdisk command. mkdosfs /dev/loop2 The mkdosfs utility formats the partition to the FAT32 file system. To directly build the kernel, the previously discussed commands in the classic makefile syntax are used. Now let's look at how to install GRUB on a partition: mkdir -p tempdir # creates a temporary directory mount /dev/loop2 tempdir # mounts the partition in the mkdir directory tempdir/boot # creates a /boot directory on the partition cp -r grub tempdir/boot/ # copy the grub folder in /boot cp kernel.bin tempdir/ # copies the kernel to the root of the partition sleep 1 # wait for Ubuntu umount /dev/loop2 # unmount the temporary folder rm -r tempdir # delete the temporary folder losetup -d /dev/loop2 # unmount the partition After completing the above commands, the image will be ready for GRUB installation. The following command installs GRUB into the MBR of the hdd.img disk image. echo "device (hd0) hdd.img \n \ root (hd0,0) \n \ setup (hd0) \n \ quit\n" | grub --batch 1>/dev/NULL

    Everything is ready for testing!

    Step 6. Launch:

    To compile, use the command:

    make all After which the kernel.bin file should appear. To create a bootable disk image, use the command: sudo make image As a result, the hdd.img file should appear. Now you can boot from the hdd.img disk image. You can check this using the following command: qemu -hda hdd.img -m 32 or: qemu-system-i386 -hda hdd.img

    To check on a real machine, you need to dd this image to a flash drive and boot from it. For example with this command:

    sudo dd if=./hdd.img of=/dev/sdb

    To summarize, we can say that as a result of the actions taken, a set of source codes and scripts is obtained that allow us to conduct various experiments in the field of system programming. The first step has been taken towards the creation of system software such as hypervisors and operating systems.

    Links to the following articles in the series: “ How to run a program without an operating system: part 2

    " "
    How to run a program without an operating system: part 3: Graphics
    " "
    How to run a program without an operating system: part 4. Parallel computing
    " "
    How to run a program without an operating system: part 5. Accessing the BIOS from the OS
    " "
    How to run a program without operating system: part 6. Support for working with disks with the FAT file system
    "

    Installing APK using an Android device

    Samsung Galaxy S10 in hand

    To install an APK file, you usually do not need anything other than the Android tablet or smartphone itself, into which you need to install this or that program. To do this, you need to do a little preparation. First of all, go to Settings and select the “Security” tab there. Next, check the box “Allow installation of applications from unknown sources.” This will allow you to install applications not only from the Google Play Store, but also from other sources. Just what you need! In newer versions of Android, the procedure may vary. Sometimes the system, already in the process of installing an application from an APK file, asks whether the user allows this. You need to allow it, otherwise nothing will work.

    Now that the preparation is complete, you just need to open your browser, find the desired APK file, download it to your device, and then launch it to install the application. Remember where you downloaded the file. This is usually the Downloads folder unless you select a different path before downloading. Having found the downloaded file, just click on it and then agree to the installation by tapping “Yes”. After this, the application will begin to install. Ready!

    Rating
    ( 2 ratings, average 4 out of 5 )
    Did you like the article? Share with friends:
    For any suggestions regarding the site: [email protected]
    Для любых предложений по сайту: [email protected]