forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathldmap.r2.js
More file actions
46 lines (41 loc) · 1.04 KB
/
Copy pathldmap.r2.js
File metadata and controls
46 lines (41 loc) · 1.04 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
/* ldmap.r2.js: parser for GNU ld map files -- by pancake@nopcode.org */
const mapFileName = "/tmp/pebble-app.map";
function isZeroAddress(addr) {
return addr.replace(/^0x0*/i, '') === '';
}
function parseMapLine(line) {
let match = line.match(/^\s*\S+\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+|\d+)\s+(.+)$/);
if (!match) {
match = line.match(/^\s*(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+|\d+)\s+(.+)$/);
}
if (!match) {
return null;
}
return {
addr: match[1],
file: match[3].trim(),
};
}
function loadLinesFromLdMap(fileName) {
const script = [];
const lines = r2.cmd("cat " + fileName).split("\n");
let inMap = false;
for (const line of lines) {
const trimmed = line.trim();
if (!inMap) {
if (trimmed === "Linker script and memory map") {
inMap = true;
}
continue;
}
if (trimmed === "DISCARD") {
break;
}
const item = parseMapLine(line);
if (item && item.file && !isZeroAddress(item.addr)) {
script.push("'CL " + item.addr + " " + item.file + ":0");
}
}
return script;
}
loadLinesFromLdMap(mapFileName).map(r2.cmd);