- Wizards are “mini-programs” that extend the capabilities of Mach3. Wizards can be written by anyone and are designed to allow users to quickly perform routine or convenient operations without the need to have a pre-written G-Code file. Included with Mach3 are some free Wizards that were contributed by users.
- Mach Write The iCloud RTF, TXT, and PDF Editor for iOS and macOS. Powerful Text Editor, on all your Devices. Mach Write is a powerful new RTF, TXT, PDF (Rich Text Format, Plain Text, PDF) Editor for iOS and macOS! Featuring full iCloud document synchronization, RTF in multiple styles, sizes, and colors; as well as PDF Viewing/Creating.
- Apr 15, 2021 The Writings of Dark Lord Jeff Mach. Winston rubbed his presumably-broken toe and moodily contemplated the bottle of something-like-bourbon which sprawled in.
Mach number (M or Ma) (/ mɑːk /; German: max) is a dimensionless quantity in fluid dynamics representing the ratio of flow velocity past a boundary to the local speed of sound.
- Writings
Our editors will review what you’ve submitted and determine whether to revise the article.
Join Britannica's Publishing Partner Program and our community of experts to gain a global audience for your work!Niccolò Machiavelli, (born May 3, 1469, Florence [Italy]—died June 21, 1527, Florence), ItalianRenaissance political philosopher and statesman, secretary of the Florentine republic, whose most famous work, The Prince (Il Principe), brought him a reputation as an atheist and an immoral cynic.
Who was Niccolò Machiavelli?
Niccolò Machiavelli was an Italian Renaissance political philosopher and statesman and secretary of the Florentinerepublic. His most famous work, The Prince (1532), brought him a reputation as an atheist and an immoral cynic.
What did Niccolò Machiavelli write?
Niccolò Machiavelli’s two most important works are Discourses on Livy (1531) and The Prince (1532), both of which were published after his death. He wrote several other works, including Florentine Histories (1532) and The Life of Castruccio Castracani of Lucca (1520).
What was Niccolò Machiavelli’s occupation?
From the age of 29, when he was placed in charge of the republic of Florence’s foreign affairs in subject territories, Machiavelli held a series of governmental posts. Among his tasks were to establish a militia, undertake diplomatic and military missions, oversee fortifications, and write an official history of the republic.
Early life and political career
From the 13th century onward, Machiavelli’s family was wealthy and prominent, holding on occasion Florence’s most important offices. His father, Bernardo, a doctor of laws, was nevertheless among the family’s poorest members. Barred from public office in Florence as an insolvent debtor, Bernardo lived frugally, administering his small landed property near the city and supplementing his meagre income from it with earnings from the restricted and almost clandestine exercise of his profession.
Bernardo kept a library in which Niccolò must have read, but little is known of Niccolò’s education and early life in Florence, at that time a thriving centre of philosophy and a brilliant showcase of the arts. He attended lectures by Marcello Virgilio Adriani, who chaired the Studio Fiorentino. He learned Latin well and probably knew some Greek, and he seems to have acquired the typical humanist education that was expected of officials of the Florentine Chancery.
In a letter to a friend in 1498, Machiavelli writes of listening to the sermons of Girolamo Savonarola (1452–98), a Dominican friar who moved to Florence in 1482 and in the 1490s attracted a party of popular supporters with his thinly veiled accusations against the government, the clergy, and the pope. Although Savonarola, who effectively ruled Florence for several years after 1494, was featured in The Prince (1513) as an example of an “unarmed prophet” who must fail, Machiavelli was impressed with his learning and rhetorical skill. On May 24, 1498, Savonarola was hanged as a heretic and his body burned in the public square. Several days later, emerging from obscurity at the age of 29, Machiavelli became head of the second chancery (cancelleria), a post that placed him in charge of the republic’s foreign affairs in subject territories. How so young a man could be entrusted with so high an office remains a mystery, particularly because Machiavelli apparently never served an apprenticeship in the chancery. He held the post until 1512, having gained the confidence of Piero Soderini (1452–1522), the gonfalonier (chief magistrate) for life in Florence from 1502.
During his tenure at the second chancery, Machiavelli persuaded Soderini to reduce the city’s reliance on mercenary forces by establishing a militia (1505), which Machiavelli subsequently organized. He also undertook diplomatic and military missions to the court of France; to Cesare Borgia (1475/76–1507), the son of Pope Alexander VI (reigned 1492–1503); to Pope Julius II (reigned 1503–13), Alexander’s successor; to the court of Holy Roman Emperor Maximilian I (reigned 1493–1519); and to Pisa (1509 and 1511).
In 1503, one year after his missions to Cesare Borgia, Machiavelli wrote a short work, Del modo di trattare i sudditi della Val di Chiana ribellati (On the Way to Deal with the Rebel Subjects of the Valdichiana). Anticipating his later Discourses on Livy, a commentary on the ancient Roman historian, in this work he contrasts the errors of Florence with the wisdom of the Romans and declares that in dealing with rebellious peoples one must either benefit them or eliminate them. Machiavelli also was a witness to the bloody vengeance taken by Cesare on his mutinous captains at the town of Sinigaglia (December 31, 1502), of which he wrote a famous account. In much of his early writings, Machiavelli argues that “one should not offend a prince and later put faith in him.”
In 1503 Machiavelli was sent to Rome for the duration of the conclave that elected Pope Julius II, an enemy of the Borgias, whose election Cesare had unwisely aided. Machiavelli watched Cesare’s decline and, in a poem (First Decennale), celebrated his imprisonment, a burden that “he deserved as a rebel against Christ.” Altogether, Machiavelli embarked on more than 40 diplomatic missions during his 14 years at the chancery.
In 1512 the Florentine republic was overthrown and the gonfalonier deposed by a Spanish army that Julius II had enlisted into his Holy League. The Medici family returned to rule Florence, and Machiavelli, suspected of conspiracy, was imprisoned, tortured, and sent into exile in 1513 to his father’s small property in San Casciano, just south of Florence. There he wrote his two major works, The Prince and Discourses on Livy, both of which were published after his death. He dedicated The Prince to Lorenzo di Piero de’ Medici (1492–1519), ruler of Florence from 1513 and grandson of Lorenzo de’ Medici (1449–92). When, on Lorenzo’s death, Cardinal Giulio de’ Medici (1478–1534) came to govern Florence, Machiavelli was presented to the cardinal by Lorenzo Strozzi (1488–1538), scion of one of Florence’s wealthiest families, to whom he dedicated the dialogue The Art of War (1521; Dell’arte della guerra).
Machiavelli was first employed in 1520 by the cardinal to resolve a case of bankruptcy in Lucca, where he took the occasion to write a sketch of its government and to compose his The Life of Castruccio Castracani of Lucca (1520; La vita di Castruccio Castracani da Lucca). Later that year the cardinal agreed to have Machiavelli elected official historian of the republic, a post to which he was appointed in November 1520 with a salary of 57 gold florins a year, later increased to 100. In the meantime, he was commissioned by the Medici pope Leo X (reigned 1513–21) to write a discourse on the organization of the government of Florence. Machiavelli criticized both the Medici regime and the succeeding republic he had served and boldly advised the pope to restore the republic, replacing the unstable mixture of republic and principality then prevailing. Shortly thereafter, in May 1521, he was sent for two weeks to the Franciscan chapter at Carpi, where he improved his ability to “reason about silence.” Machiavelli faced a dilemma about how to tell the truth about the rise of the Medici in Florence without offending his Medici patron.
After the death of Pope Leo X in 1521, Cardinal Giulio, Florence’s sole master, was inclined to reform the city’s government and sought out the advice of Machiavelli, who replied with the proposal he had made to Leo X. In 1523, following the death of Pope Adrian VI, the cardinal became Pope Clement VII, and Machiavelli worked with renewed enthusiasm on an official history of Florence. In June 1525 he presented his Florentine Histories (Istorie Fiorentine) to the pope, receiving in return a gift of 120 ducats. In April 1526 Machiavelli was made chancellor of the Procuratori delle Mura to superintend Florence’s fortifications. At this time the pope had formed a Holy League at Cognac against Holy Roman Emperor Charles V (reigned 1519–56), and Machiavelli went with the army to join his friend Francesco Guicciardini (1482–1540), the pope’s lieutenant, with whom he remained until the sack of Rome by the emperor’s forces brought the war to an end in May 1527. Now that Florence had cast off the Medici, Machiavelli hoped to be restored to his old post at the chancery. But the few favours that the Medici had doled out to him caused the supporters of the free republic to look upon him with suspicion. Denied the post, he fell ill and died within a month.
Writings
In office Machiavelli wrote a number of short political discourses and poems (the Decennali) on Florentine history. It was while he was out of office and in exile, however, that the “Florentine Secretary,” as Machiavelli came to be called, wrote the works of political philosophy for which he is remembered. In his most noted letter (December 10, 1513), he described one of his days—in the morning walking in the woods, in the afternoon drinking and gambling with friends at the inn, and in the evening reading and reflecting in his study, where, he says, “I feed on the food that alone is mine and that I was born for.” In the same letter, Machiavelli remarks that he has just composed a little work on princes—a “whimsy”—and thus lightly introduces arguably the most famous book on politics ever written, the work that was to give the name Machiavellian to the teaching of worldly success through scheming deceit.
About the same time that Machiavelli wrote The Prince (1513), he was also writing a very different book, Discourses on Livy (or, more precisely, Discourses on the First Ten Books of Titus Livy [Discorsi sopra la prima deca di Tito Livio]). Both books were first published only after Machiavelli’s death, the Discourses on Livy in 1531 and The Prince in 1532. They are distinguished from his other works by the fact that in the dedicatory letter to each he says that it contains everything he knows. The dedication of the Discourses on Livy presents the work to two of Machiavelli’s friends, who he says are not princes but deserve to be, and criticizes the sort of begging letter he appears to have written in dedicating The Prince. The two works differ also in substance and manner. Whereas The Prince is mostly concerned with princes—particularly new princes—and is short, easy to read, and, according to many, dangerously wicked, the Discourses on Livy is a “reasoning” that is long, difficult, and full of advice on how to preserve republics. Every thoughtful treatment of Machiavelli has had to come to terms with the differences between his two most important works.
Mach Write Review
- born
- May 3, 1469
Florence, Italy
- died
- June 21, 1527 (aged 58)
Florence, Italy
- notable works
- subjects of study
I’ve recently been working a lot with parsing Mach-O files, so I’m begining to understand in a fair bit of detail how they are structured and how they work. I’ve been developing a library, called libhelper, which can parse Mach-O files. Libhelper-macho also powers Img4helper, and HTool.
This is not a complete writeup or documentation covering everything about Mach-O’s, and I appreciate this has probably been covered to death. It’s not aimed at those who already have an advanced knowledge of how Mach or Darwin works, rather it’s aimed at those who are in a position I was a few weeks ago, having limited knowledge of how Mach-O’s are structured. However I felt this would be a useful resource, and a good way to kick-off my Blog.
There are multiple types of Mach-O, such as Executable or KEXT Bundles, so I can’t cover them all. My aim for this post is to discuss the basics - namely Header, Load Commands and Segment Commands. I may discuss other areas in the future but this is a start.
What are Mach-O files
Mach-O files, or Mach Object Files, are an executable format used on Operating Systems based on the Mach Kernel. This includes Apple’s Darwin iOS, macOS, watchOS etc. There are multiple types of Mach-O file, such as executables, object-code, shared and dynamic libraries, kernel extension (KEXT) bundles and even debug companion files.
Mach-O Format
Mach-O files are simply binary files, there isn’t particularly anything special about them in that regard. You can read in some bytes into a C structure and boom, you’ve parsed a Mach-O (or at least part of it). Natively, they can only be run on Mach/Darwin/XNU-based systems, however there are some implementations for loading and executing Mach-O files on Linux. Although you can run simple applications this way, the majority of applications will not work due to reliance on certain macOS libraries, such as /usr/lib/libSystem.B.dylib
.
A Mach-O is made up of one Mach header, a number of load commands (specified in the header) and the data. The data is organised into Segments, which are made up of 0 to 255 Sections, and there special load commands to describe them. Mach-O files are organised as follows:
- Mach-O Header
- Load Commands
- Data
The purpose of this article is to discuss, at a higher level, each of these areas of a Mach-O file, how data is organised and how to load this data from a given Mach-O file into relevant C structures.
Header
Starting with the Mach Header. It’s purpose is to describe what the file contains, and how the Kernel and Dynamic Linker should handle it. The first 4 bytes are, like with any file, it’s “Magic Number”. A Magic Number is used to identify a file format. In the case of Mach-O’s there are three Magic Numbers that one may come across. 0xfeedface
for 32-bit, 0xfeedfacf
for 64-bit and 0xcafebabe
for Mach Universal Binaries / Object files.
Other properties of a Mach-O Header include the cpu type and sub type which define the architecture the Mach-O is built for (e.g. arm64
, x86_64
, arm64_32
), the number of Load Commands and the size of that area and flags to be passed to the Dynamic Linker. The layout of the header is shown below:
The Mach-O header takes up 32 bytes for 64-bit files, at 28 bytes for 32-bit files. You can populate the the header structure by memcpy()
the correct size into a mach_header
structure, and you’ll be able to access the header elements as normal.
Load Commands
Load Commands are placed directly after the Mach-O header in the file. They specify the logical structure of the file and the layout of the file in virtual memory.
All Load Commands have a common 8 byte structure which identifies the type of the command and it’s size. This common structure is defined as follows:
There are over a dozen Load Commands, some are common across all Mach-O’s and some are only found in certain cases. Load Commands placed after the Mach-O header, with the first being Segment Commands. These are discussed further under Segment Commands.
But Segment Commands are not the only commands that are included in the majority of Mach-O files. The LC_DYLD_INFO
and LC_LOAD_DYLINKER
commands specify information such as rebase, bind, weak, lazy and export information for the Dynamic Linker, and the path of the Dynamic Linker the Kernel should use to execute the binary respectively. Mach-O’s frequently require Dynamic Libraries, especially /usr/lib/libSystem.B.dylib
. The LC_DYLIB
command defines the path for Linker to find the Dylib, and there can be however many of these commands as are required for the number of Dynamic Libraries.
The offset and sizes for both the symbol table and the string table are defined with LC_SYMTAB
, and offsets for local, external, undefined and other types of dynamic symbols are defined with LC_DYSYMTAB
The last command that I will discuss here is LC_MAIN
which defines the offset for the entry point, so where the Kernel should start executing the binary from. This is only used for MH_EXECUTE
filetypes.
Below is output from an experiemental version of htool showing all of the Load Commands from itself. I’ve ommited some parts because the output is rather long.
Going back to struct load_command
. Looking at it from the perspective of trying to parse Mach-O’s having a constant format for the first 8 bytes of each Load Command makes detecting and parsing them easier. The following is an example of how we can parse a command, using LC_MAIN
as an example. The code is based off XNU’s loader.h
rather than libhelper
.
If you are interested in learning more about the different types of Load Commands, you can either checkout EXTERNAL_HEADERS/mach-o/loader.h
in the XNU sources, or include/libhelper-macho/macho-command-types.h
from Libhelper.
Segment Commands
Going back to Segment Commands, the first couple of Load Commands in a Mach-O are either LC_SEGMENT
for 32-bit, or LC_SEGMENT_64
for 64-bit. These define an object files Segments.
If you are unfamiliar with how object files work, you have a number of these segments. The __TEXT
segment contains the instructions that will be executed by the CPU, and the __DATA
segment contains both static local variables and global variables. These are both standard, however you may find additional segments such as __PAGEZERO
and __LINKEDIT
, and in XNU Kernelcaches, you’ll get even more funky segment names like __PRELINK_INFO
and __LAST
.
Segments are further divided into sections, so for example you’ll find __cstring
in the __TEXT
segment, formatted as __TEXT.__cstring
, as a common one.
The Segment Commands in a Mach-O define what regions of the binary data should be mapped into memory as what. So looking at the segment_command_64
struct, there’s the segments name as segname
, but then we have two sets of address/sizes.
The vmaddr
and vmsize
define the virtual memory address and size for this segment And fileoff
with filesize
for the segments location and size within the file. maxprot
and initprot
define virtual memory protection for the segment in memory, so this may prevent it from being both writable and executable at the same time. Finally is the flags, which are just a way of giving the Kernel options for loading the segment into memory.
Like I said, we have segments which are divided into sections. These sections are placed directly after the segment command, are included in the cmdsize
and are counted with nsects
. Again, sections essentially dividing up segments into more meaningful chunks, for example __TEXT.__text
or __TEXT.__const
.
To load these, we must take the offset of the segment command in the file, add the size of the segment structure, and then loop through nsects
times, incrementing the offset by the size of the section struct each time.
To start, the section structure is defined as follows. Again, there are both section_64
and section
structures, with the difference being the 64-bit section_64
struct uses uint64_t
for both addr
and size
, and has a third reserved
property at the end of the structure although it is not designated for any optional properties:
As I just stated, we can load the correct data into that structure by adding sizeof (segment_command_64)
to the offset of the command in the file, then add sizeof(section_64)
for each of segment->nsects
. Here is an example of what I mean (note this time I am using libhelper code to demonstrate):
The mach_segment_info_t
struct is not implemented in XNU’s standard loader.h
, so if you’re writing your own Mach-O parser, please ignore references to Libhelper structs.
Looking at this function in more detail. Two arguments are passed to mach_segment_info_load
, an unsigned char *data
pointer to the Mach-O loaded in memory, and an uint32_t offset
which points to the start of the segment command within that data
pointer. This offset is relative to the start of the Mach-O, not the start of the load commands.
Ignoring the code that checks and sets up the mach_segment_command_t
, it starts by calculating the offset of the first section. This is done by adding the offset
passed to the function to the sizeof()
the segment command structure.
The segment command has nsects
containing the amount of sections placed after the command. So, we loop round the number of sections from segment->nsects
and create mach_section_64_t
’s for each one. We can use memcpy()
to to copy the ssize
amount of bytes we need. We can set the start point for the copying by adding the offset to the data pointer. By doing this, we are incrementing the pointer by the offset, resulting in it pointing to, in this case, the start of the current section struct.
Calling h_slist_append()
can be ignored. This is simply adding the section to a Statically-linked list in a libhelper macho_t
structure.
The last bit of interest here, make sure to increment sectoff
by the size of the mach_section_64_t
struct, so sectoff
will point to the next section structure.
If you are interested, please take a look at libhelper. It has a Mach-O parser that I wrote, and you’ll find the example above.
Data
The actual data, so that is instructions and variables, in a Mach-O are stored after the Load Commands region. Depending on the type of Mach-O, the way this region is used varies.
So, for example. An executable - meaning a Mach-O with the filetype
of MH_EXECUTE
- would have the segment commands laying out the data region, and a LC_MAIN
command specifying the offset of the entry point instruction the Kernel should jump too when loading. The Kernel will also start the Dynamic Linker specified in the LC_DYLD_INFO
command, and link any specified dylib’s with LC_LOAD_DYLIB
.
Mach Write System
This entire region is mapped out by the segment commands. We can inspect this mapping with Mash, or Mach-O Shell, which is part of HTool. Loading the file, we can inspect a particular segment like so.
To print a segment, we use p seg __TEXT
. This is the short version, if you prefer print segment __TEXT
would also work fine. The first line of the output display’s the start and end addresses of the __TEXT
segment, and it’s total size in bytes.
Mach Write Program
Underneath, slightly indented, are each of the sections contained within the segment. For example, we can see that the __TEXT.__stubs
section is 390 bytes, and is located from 0x10000f4f0
to 0x10000f676
.
Two things to note about these addresses, first they are the virtual memory addresses, and second they are relative to the start of the data, not the start of the Mach-O. Before this __TEXT
segment is a __PAGEZERO
segment ranging from 0x000000000
to 0x100000000
.
Summary
This is only an introduction to Mach-O files. I’d like to continue writing about them and maybe even write a Mach-O loader for Linux.
I hope I covered this fairly well, any feedback would be greatly appreciated. I aim to write these blog posts more often and hopefully they’ll improve over time - both in quality and technical accuracy. For now, you can download Img4helper which you can use to extract Apple Image4 files from the Downloads page linked above, Libhelper sources are available here if you’d like to look at my Mach-O parser, and htool
will be available soon.
You can contact me either via Twitter (@h3adsh0tzz), Email (me@h3adsh0tzz.com), my iOS Security Discord server (https://discord.gg/CfNnCs8) or on irc.cracksby.kim :-).