-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Nov 19, 2024
1 parent
cbccd56
commit 7790038
Showing
7 changed files
with
181 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
frida-cshell.js | ||
frida-cshell | ||
src/version.ts | ||
core |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
export enum MemProtection { | ||
PROT_NONE = 0, | ||
PROT_READ = 0x1, | ||
PROT_WRITE = 0x2, | ||
PROT_READ_WRITE = PROT_READ | PROT_WRITE, | ||
} | ||
|
||
export class Mem { | ||
private static readonly MAP_PRIVATE: number = 0x2; | ||
private static readonly MAP_ANONYMOUS: number = 0x20; | ||
|
||
private static readonly MAP_FAILED: NativePointer = ptr(-1); | ||
|
||
/* void *mmap(void addr[.length], size_t length, int prot, int flags, | ||
int fd, off_t offset); */ | ||
private fnMmap: SystemFunction< | ||
NativePointer, | ||
[NativePointer, number | UInt64, number, number, number, number | UInt64] | ||
>; | ||
|
||
/* int mprotect(void addr[.len], size_t len, int prot); */ | ||
private fnMprotect: SystemFunction< | ||
number, | ||
[NativePointer, number | UInt64, number] | ||
>; | ||
|
||
public constructor() { | ||
const pMmap = Module.findExportByName(null, 'mmap'); | ||
if (pMmap === null) throw new Error('failed to find mmap'); | ||
|
||
this.fnMmap = new SystemFunction(pMmap, 'pointer', [ | ||
'pointer', | ||
'size_t', | ||
'int', | ||
'int', | ||
'int', | ||
'size_t', | ||
]); | ||
|
||
const pMprotect = Module.findExportByName(null, 'mprotect'); | ||
if (pMprotect === null) throw new Error('failed to find mprotect'); | ||
|
||
this.fnMprotect = new SystemFunction(pMprotect, 'int', [ | ||
'pointer', | ||
'size_t', | ||
'int', | ||
]); | ||
} | ||
|
||
public map_anonymous(size: number): NativePointer { | ||
const ret = this.fnMmap( | ||
ptr(0), | ||
size, | ||
MemProtection.PROT_READ | MemProtection.PROT_WRITE, | ||
Mem.MAP_ANONYMOUS | Mem.MAP_PRIVATE, | ||
-1, | ||
0, | ||
) as UnixSystemFunctionResult<NativePointer>; | ||
if (ret.value.equals(Mem.MAP_FAILED)) | ||
throw new Error(`failed to mmap, errno: ${ret.errno}`); | ||
return ret.value; | ||
} | ||
|
||
public protect(addr: NativePointer, size: number, prot: MemProtection) { | ||
const ret = this.fnMprotect( | ||
addr, | ||
size, | ||
prot, | ||
) as UnixSystemFunctionResult<number>; | ||
if (ret.value === -1) | ||
throw new Error(`failed to mprotect, errno: ${ret.errno}`); | ||
} | ||
|
||
public static pageAlign(size: number): number { | ||
const mask = Process.pageSize - 1; | ||
return (size + mask) & ~mask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters