Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/KextPatcher/hex_editor.c

Source at commit 600 created 9 years 8 months ago.
By meklort, Added zlib delfate code. Kext patcher can now successfuly patch the GMA950 and fb binaries for 27AE devices, plist not patched yet.
1/*
2 * hex_editor.c
3 *
4 *
5 * Created by Meklort on 10/19/10.
6 * Copyright 2010 Evan Lojewski. All rights reserved.
7 *
8 */
9
10#include "hex_editor.h"
11
12int replace_patern(char* pattern, char* replacement, char* buffer, long buffer_size)
13{
14long index = 0;
15int num_replaced = 0;
16// NOTE: patehrn and replacement are null terminated. This may change later
17// If I need to replce null bytes
18
19if(!pattern ||
20 !replacement ||
21 !buffer ||
22 strlen(pattern) != strlen(replacement)
23 ) return 0;
24
25
26while(index < buffer_size - strlen(pattern))
27{
28bool located = true;
29int i = 0;
30while(located && i < strlen(pattern))
31{
32if(pattern[i] != buffer[i + index]) located = false;
33i++;
34}
35
36if(located)
37{
38printf("Located patern\n");
39index += strlen(pattern) - 1;
40num_replaced++;
41}
42
43index++;
44}
45
46return num_replaced;
47}
48
49
50int replace_word(uint32_t pattern, uint32_t repalcement, char* buffer, long buffer_size)
51{
52int num_replaced = 0;
53char* tmp = buffer;
54
55if(!buffer || !buffer_size) return 0;
56
57
58while(tmp < buffer + buffer_size - sizeof(uint32_t))
59{
60
61uint32_t* current= (uint32_t*)tmp;
62
63if(*current == pattern)
64{
65*current = repalcement;
66num_replaced++;
67tmp += 4;
68}
69else
70{
71tmp++;
72}
73}
74
75return num_replaced;
76}
77

Archive Download this file

Revision: 600