Skip to content

Commit

Permalink
Update Capstone to version 3.
Browse files Browse the repository at this point in the history
Include its source code instead of the dynamic library.
Fix Prefix.pch and move c++ includes to the files that use them to avoid problems with Capstone.
  • Loading branch information
reverser committed Nov 20, 2014
1 parent cae41e7 commit d356665
Show file tree
Hide file tree
Showing 107 changed files with 716,628 additions and 1,011 deletions.
6 changes: 6 additions & 0 deletions ArchiveLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>
#include <cxxabi.h>

#import "Common.h"
#import "ArchiveLayout.h"
#import "DataController.h"
Expand Down
5 changes: 5 additions & 0 deletions CRTFootPrints.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>

#import "CRTFootPrints.h"
#import "DataController.h"

Expand Down
6 changes: 6 additions & 0 deletions Document.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>
#include <cxxabi.h>

#import "Common.h"
#import "Document.h"
#import "DataController.h"
Expand Down
5 changes: 5 additions & 0 deletions DyldInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>

#import "Common.h"
#import "DyldInfo.h"
#import "ReadWrite.h"
Expand Down
5 changes: 5 additions & 0 deletions Exceptions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>

#import "Exceptions.h"
#import "ReadWrite.h"
#import "DataController.h"
Expand Down
6 changes: 6 additions & 0 deletions FatLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>
#include <cxxabi.h>

#import "Common.h"
#import "FatLayout.h"
#import "DataController.h"
Expand Down
6 changes: 3 additions & 3 deletions Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>CFBuildDate</key>
<string>Tue Sep 2 23:56:49 WEST 2014</string>
<string>Thu Nov 20 11:30:21 WET 2014</string>
<key>CFBuildNumber</key>
<string>9098</string>
<string>9113</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDocumentTypes</key>
Expand Down Expand Up @@ -44,7 +44,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>9098</string>
<string>9113</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
5 changes: 5 additions & 0 deletions LinkEdit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>

#import "Common.h"
#import "LinkEdit.h"
#import "ReadWrite.h"
Expand Down
5 changes: 5 additions & 0 deletions LoadCommands.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>

#import "Common.h"
#import "LoadCommands.h"
#import "ReadWrite.h"
Expand Down
6 changes: 6 additions & 0 deletions MachOLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>
#include <cxxabi.h>

#import "Layout.h"

typedef std::vector<struct load_command const *> CommandVector;
Expand Down
4 changes: 4 additions & 0 deletions ObjC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Created by Peter Saghelyi on 17/10/2011.
*
*/
#include <string>
#include <vector>
#include <set>
#include <map>

#import "ObjC.h"
#import "ReadWrite.h"
Expand Down
6 changes: 0 additions & 6 deletions Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#import <Cocoa/Cocoa.h>
#endif

#include <string>
#include <vector>
#include <set>
#include <map>

#include <mach-o/arch.h>
#include <mach-o/loader.h>
#include <mach-o/fat.h>
Expand All @@ -24,4 +19,3 @@
#include <mach-o/swap.h>

#include <libkern/OSAtomic.h>
#include <cxxabi.h>
5 changes: 5 additions & 0 deletions ReadWrite.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>

#import "Common.h"
#import "ReadWrite.h"
#import "DataController.h"
Expand Down
19 changes: 14 additions & 5 deletions SectionContents.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*
*/

#include <string>
#include <vector>
#include <set>
#include <map>

#import "Common.h"
#import "SectionContents.h"
#import "CRTFootPrints.h"
Expand Down Expand Up @@ -571,7 +576,7 @@ - (MVNode *)createTextNode:(MVNode *)parent
csh cs_handle = 0;
cs_insn *cs_insn = NULL;
size_t disasm_count = 0;

cs_err cserr;
/* open capstone */
cs_arch target_arch;
cs_mode target_mode;
Expand All @@ -598,9 +603,9 @@ - (MVNode *)createTextNode:(MVNode *)parent
break;
}

if ( cs_open(target_arch, target_mode, &cs_handle) != CS_ERR_OK )
if ( (cserr = cs_open(target_arch, target_mode, &cs_handle)) != CS_ERR_OK )
{
NSLog(@"Failed to initialize Capstone: %s.", cs_strerror(cs_errno(cs_handle)));
NSLog(@"Failed to initialize Capstone: %d, %s.", cserr, cs_strerror(cs_errno(cs_handle)));
return node;
}

Expand All @@ -622,11 +627,15 @@ - (MVNode *)createTextNode:(MVNode *)parent
}
}

/* enable detail - we need fields available in detail field */
cs_option(cs_handle, CS_OPT_DETAIL, CS_OPT_ON);
cs_option(cs_handle, CS_OPT_SKIPDATA, CS_OPT_ON);

/* disassemble the whole section */
/* this will fail if we have data in code or jump tables because Capstone stops when it can't disassemble */
/* a bit of a problem with most binaries :( */
/* XXX: parse data in code section to partially solve this */
disasm_count = cs_disasm_ex(cs_handle, (const uint8_t *)ot_sect, ot_left, ot_addr, 0, &cs_insn);
disasm_count = cs_disasm(cs_handle, (const uint8_t *)ot_sect, ot_left, ot_addr, 0, &cs_insn);
NSLog(@"Disassembled %lu instructions.", disasm_count);
uint32_t fileOffset = ([self is64bit] == NO ? [self RVAToFileOffset:(uint32_t)ot_addr] : [self RVA64ToFileOffset:ot_addr]);
for (size_t i = 0; i < disasm_count; i++)
Expand All @@ -644,7 +653,7 @@ - (MVNode *)createTextNode:(MVNode *)parent
/* advance to next instruction */
fileOffset += cs_insn[i].size;
}

cs_free(cs_insn, disasm_count);
cs_close(&cs_handle);
// close last block
if (symbolName)
Expand Down
38 changes: 38 additions & 0 deletions capstone/LEB128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===- llvm/Support/LEB128.h - [SU]LEB128 utility functions -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file declares some utility functions for encoding SLEB128 and
// ULEB128 values.
//
//===----------------------------------------------------------------------===//

/* Capstone Disassembly Engine */
/* By Nguyen Anh Quynh <[email protected]>, 2013-2014 */

#ifndef CS_LLVM_SUPPORT_LEB128_H
#define CS_LLVM_SUPPORT_LEB128_H

#include <stdint.h>

/// Utility function to decode a ULEB128 value.
static inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n)
{
const uint8_t *orig_p = p;
uint64_t Value = 0;
unsigned Shift = 0;
do {
Value += (*p & 0x7f) << Shift;
Shift += 7;
} while (*p++ >= 128);
if (n)
*n = (unsigned)(p - orig_p);
return Value;
}

#endif // LLVM_SYSTEM_LEB128_H
14 changes: 14 additions & 0 deletions capstone/MCDisassembler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Capstone Disassembly Engine */
/* By Nguyen Anh Quynh <[email protected]>, 2013-2014 */

#ifndef CS_MCDISASSEMBLER_H
#define CS_MCDISASSEMBLER_H

typedef enum DecodeStatus {
MCDisassembler_Fail = 0,
MCDisassembler_SoftFail = 1,
MCDisassembler_Success = 3,
} DecodeStatus;

#endif

30 changes: 30 additions & 0 deletions capstone/MCFixedLenDisassembler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- llvm/MC/MCFixedLenDisassembler.h - Decoder driver -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Fixed length disassembler decoder state machine driver.
//===----------------------------------------------------------------------===//

/* Capstone Disassembly Engine */
/* By Nguyen Anh Quynh <[email protected]>, 2013-2014 */

#ifndef CS_LLVM_MC_MCFIXEDLENDISASSEMBLER_H
#define CS_LLVM_MC_MCFIXEDLENDISASSEMBLER_H

// Disassembler state machine opcodes.
enum DecoderOps {
MCD_OPC_ExtractField = 1, // OPC_ExtractField(uint8_t Start, uint8_t Len)
MCD_OPC_FilterValue, // OPC_FilterValue(uleb128 Val, uint16_t NumToSkip)
MCD_OPC_CheckField, // OPC_CheckField(uint8_t Start, uint8_t Len,
// uleb128 Val, uint16_t NumToSkip)
MCD_OPC_CheckPredicate, // OPC_CheckPredicate(uleb128 PIdx, uint16_t NumToSkip)
MCD_OPC_Decode, // OPC_Decode(uleb128 Opcode, uleb128 DIdx)
MCD_OPC_SoftFail, // OPC_SoftFail(uleb128 PMask, uleb128 NMask)
MCD_OPC_Fail // OPC_Fail()
};

#endif
Loading

0 comments on commit d356665

Please sign in to comment.