Skip to content

Commit

Permalink
Use flagspaces for libs, maps, symbols, imports, entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Oct 15, 2023
1 parent f1ed92f commit 1829f0f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/agent/lib/debug/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function listMemoryMaps() {
}

export function listMemoryMapsR2() {
return _squashRanges(listMemoryRangesJson())
const maps = _squashRanges(listMemoryRangesJson())
.filter(_ => _.file)
.map(({ base, size, protection, file }) => [
'f',
Expand All @@ -75,6 +75,7 @@ export function listMemoryMapsR2() {
]
.join(' '))
.join('\n') + '\n';
return "fs+maps\n" + maps + "fs-\n";
}

export function listMallocRanges(args: string[]) {
Expand Down
14 changes: 9 additions & 5 deletions src/agent/lib/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ export function listEntrypointJson(args?: string[]) {

export function listEntrypointR2(args: string[]) : string {
let n = 0;
return listEntrypointJson()
const entries = listEntrypointJson()
.map((entry) => {
return 'f entry' + (n++) + ' = ' + entry.address;
}).join('\n');
return "fs+symbols\n" + entries + "\nfs-\n";
}

export function listEntrypointQuiet(args: string[]) {
Expand Down Expand Up @@ -220,7 +221,7 @@ export function listImportsR2(args: string[]) {
flags.push('f sym.imp.' + sanitizeString(x.name) + ` = ${pltaddr}`);
}
}
return flags.join('\n');
return "fs+symbols\n" + flags.join('\n') + "\nfs-\n";
}).join('\n');
}

Expand Down Expand Up @@ -267,9 +268,10 @@ export function listModulesQuiet() {
}

export function listModulesR2() {
return Process.enumerateModules()
const libs = Process.enumerateModules()
.map(m => 'f lib.' + sanitizeString(m.name) + ' = ' + padPointer(m.base))
.join('\n');
return "fs+libs\n" + libs + "\nfs-\n";
}

export function listModulesJson() {
Expand Down Expand Up @@ -468,10 +470,11 @@ export function listAllSymbols(args: string[]) {
}

export function listAllSymbolsR2(args: string[]) {
return listAllSymbolsJson(args)
const symbols = listAllSymbolsJson(args)
.map(({ type, name, address }) => {
return ['f', 'sym.' + type.substring(0, 3) + '.' + sanitizeString(name), '=', address].join(' ');
}).join('\n');
return 'fs symbols\n' + symbols + '\nfs-\n';
}

export function listSymbols(args: string[]) {
Expand All @@ -483,13 +486,14 @@ export function listSymbols(args: string[]) {
}

export function listSymbolsR2(args: string[]) {
return listSymbolsJson(args)
const symbols = listSymbolsJson(args)
.filter(({ address }) => !address.isNull())
.filter(({ name }) => name !== "")
.map(({ name, address }) => {
return ['f', 'sym.' + sanitizeString(name), '=', address].join(' ');
})
.join('\n');
return 'fs symbols\n' + symbols + '\nfs-\n';
}

export function listSymbolsJson(args: string[]) {
Expand Down
12 changes: 6 additions & 6 deletions src/agent/lib/info/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export function lookupAddress(args: string[]) : string {
}

export function lookupAddressR2(args: string[]) : string {
return lookupAddressJson(args)
.map(({ type, name, address }) => ['f', 'sym.' + utils.sanitizeString(name), '=', address].join(' '))
.join('\n');
const symbols = lookupAddressJson(args)
.map(({ type, name, address }) => ['f', 'sym.' + utils.sanitizeString(name), '=', address].join(' '));
return ["fs+symbols", ...symbols, "fs-"].join("\n");
}

export function lookupAddressJson(args: string[]): any[] {
Expand Down Expand Up @@ -117,9 +117,9 @@ export function lookupSymbolMany(args: string[]) {
}

export function lookupSymbolManyR2(args: string[]) {
return lookupSymbolManyJson(args)
.map(({ name, address }) => ['f', 'sym.' + utils.sanitizeString(name), '=', address].join(' '))
.join('\n');
const symbols = lookupSymbolManyJson(args)
.map(({ name, address }) => ['f', 'sym.' + utils.sanitizeString(name), '=', address].join(' '));
return ["fs+symbols", ...symbols, "fs-"].join("\n");
}

export function lookupSymbolJson(args: string[]) {
Expand Down

0 comments on commit 1829f0f

Please sign in to comment.