Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add ios-classify.h

  • Loading branch information...
commit 889a279014565e65e1d95325594acc49591ececb 1 parent 9f1bdee
@comex authored
Showing with 29 additions and 3 deletions.
  1. +2 −0  binary.h
  2. +24 −0 ios-classify.h
  3. +3 −3 mach-o/binary.c
View
2  binary.h
@@ -49,6 +49,8 @@ struct binary {
addr_t (*_sym)(const struct binary *binary, const char *name, int options);
void (*_copy_syms)(const struct binary *binary, struct data_sym **syms, uint32_t *nsyms, int options);
+
+ uint32_t reserved[8];
};
__BEGIN_DECLS
View
24 ios-classify.h
@@ -0,0 +1,24 @@
+// the spec macro chooses between alternatives depending on the "class"
+// possible "classes": armv6 pre 4.3, armv7 pre 4.3, 4.3.x, 5.0.x
+
+static unsigned int _armv6 = 0;
+static unsigned int _armv7 = 1;
+static unsigned int _43 = 2;
+static unsigned int _50 = 3;
+
+#define spec_(c1, v1, c2, v2, c3, v3, c4, v4, ...) \
+ (class >= (c1) ? (v1) : \
+ class >= (c2) ? (v2) : \
+ class >= (c3) ? (v3) : \
+ class >= (c4) ? (v4) : \
+ (die("no valid alternative"), (typeof(v1+0)) 0))
+#define spec(args...) spec_(args, 10, 0, 10, 0, 10, 0)
+
+#define is_armv7(binary) (binary->actual_cpusubtype == 9)
+
+static unsigned int classify(const struct binary *binary) {
+ if(!is_armv7(binary)) return _armv6;
+ else if(b_sym(binary, "_buf_attr", 0)) return _50;
+ else if(b_sym(binary, "_vfs_getattr", 0)) return _43;
+ else return _armv7;
+}
View
6 mach-o/binary.c
@@ -50,7 +50,7 @@ static void do_load_commands(struct binary *binary) {
die("cmdsize (%u) too small for cmd (0x%x)", cmd->cmdsize, cmd->cmd);
}
}
- if(nsegs >= MAX_ARRAY(struct data_segment)) {
+ if(nsegs > MAX_ARRAY(struct data_segment)) {
die("segment overflow");
}
binary->nsegments = nsegs;
@@ -78,7 +78,7 @@ static void do_symbols(struct binary *binary) {
}
} else if(cmd->cmd == LC_SYMTAB) {
struct symtab_command *scmd = (void *) cmd;
- if(scmd->nsyms >= MAX_ARRAY(struct data_sym) || scmd->nsyms >= MAX_ARRAY(struct nlist)) {
+ if(scmd->nsyms > MAX_ARRAY(struct data_sym) || scmd->nsyms > MAX_ARRAY(struct nlist)) {
die("ridiculous number of symbols (%u)", scmd->nsyms);
}
binary->mach->nsyms = scmd->nsyms;
@@ -98,7 +98,7 @@ static void do_symbols(struct binary *binary) {
struct dysymtab_command *dc;
if(binary->mach->symtab && (dc = binary->mach->dysymtab)) {
#define do_it(isym, nsym, x_symtab, x_nsyms) \
- if(dc->isym <= binary->mach->nsyms && dc->nsym <= binary->mach->nsyms - dc->isym && dc->nsym < MAX_ARRAY(struct nlist) && dc->nsym < MAX_ARRAY(struct data_sym)) { \
+ if(dc->isym <= binary->mach->nsyms && dc->nsym <= binary->mach->nsyms - dc->isym && dc->nsym <= MAX_ARRAY(struct nlist) && dc->nsym <= MAX_ARRAY(struct data_sym)) { \
binary->mach->x_symtab = binary->mach->symtab + dc->isym; \
binary->mach->x_nsyms = dc->nsym; \
} else { \
Please sign in to comment.
Something went wrong with that request. Please try again.