Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 07d37a95b7
Fetching contributors…

Cannot retrieve contributors at this time

file 52 lines (39 sloc) 1.901 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#ifndef LIBC_JUMP_PATCH
#define LIBC_JUMP_PATCH

#include "text_symbols.h"

#include <list>
#include <map>
#include <string>

bool perform_patch(unsigned char *buffer, text_symbol symbol, int new_location);
bool lowlevel_patch(unsigned char *buffer, int offset, int dest);



typedef struct patch_struct {
unsigned int library_offset; /* The offset of the function in the original library */

char function_name[255]; /* The function containing the instruction to patch */
unsigned int offset; /* The offset into the given function where the patch goes */
unsigned int patch_length; /* The number of bytes to patch */

char dest_function_name[255]; /* The name of the destination function that the jump points to (optional) */
        unsigned int dest_function; /* The address of the destination function */
unsigned int dest_offset; /* Any additional offset into the destination function that might be needed */
bool in_plt; /* If this bit is set, the function_name will be used to find a PLT entry, rather than the body */
} patch;

class jumppatching
{
public:

/*
This is a list of <int, string> pairs. Each pair represents a 'call' instruction.
The int is the offset into the function that the call occurs and the string is
the name of the function that is being called. Since call instructions are a 4 byte
offset, it will be possible to calculate the address these functions need to be
remapped to
*/
std::list< patch > function_call_patches;

/*
Similar to the previous, but this is for 4 byte, relative jumps (E9 opcode)
The int is the offset into the function to patch and the string is the function
name destination
*/
std::list< patch > relative_jump_patches;
};

extern std::map<std::string, std::list < jumppatching*>* > *patch_database; // <symbol name, list of patches>

std::map<std::string, std::list<jumppatching*>* >* prepare_patch_database();
#endif
Something went wrong with that request. Please try again.