{"id":22852690,"url":"https://github.com/sha0coder/libscemu","last_synced_at":"2025-04-30T09:21:04.754Z","repository":{"id":59145120,"uuid":"534717579","full_name":"sha0coder/libscemu","owner":"sha0coder","description":"SCEMU The crates.io lib, x86 cpu and systems emulator focused mainly for anti-malware","archived":false,"fork":false,"pushed_at":"2024-04-09T16:54:43.000Z","size":1212,"stargazers_count":33,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-09T19:48:45.547Z","etag":null,"topics":["cpu","emulator","malware","rust","rust-lang","shellcodes"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sha0coder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-09-09T16:20:07.000Z","updated_at":"2024-04-15T09:51:06.996Z","dependencies_parsed_at":"2023-12-27T00:22:37.571Z","dependency_job_id":"54566ba5-0179-4b54-a714-2db567d44f02","html_url":"https://github.com/sha0coder/libscemu","commit_stats":{"total_commits":294,"total_committers":2,"mean_commits":147.0,"dds":0.08503401360544216,"last_synced_commit":"44d06df5b68f6e6a26632e6118cf9b54fabd1c4c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sha0coder%2Flibscemu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sha0coder%2Flibscemu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sha0coder%2Flibscemu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sha0coder%2Flibscemu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sha0coder","download_url":"https://codeload.github.com/sha0coder/libscemu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251674978,"owners_count":21625716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu","emulator","malware","rust","rust-lang","shellcodes"],"created_at":"2024-12-13T06:08:55.967Z","updated_at":"2025-04-30T09:21:04.748Z","avatar_url":"https://github.com/sha0coder.png","language":"Rust","readme":"\n# SCEMU the lib\n\nThis repo has been archived, now libscemu, pyscemu and scemu become 1 repo:\nhttps://github.com/sha0coder/mwemu\n\n\n\n\n## Usage\n\nDownload the maps32 or maps64 from:\nhttps://github.com/sha0coder/scemu\n\nIn the example it's on /tmp/ but dont use tmp.\n\nCreate an emu32 or emu64 and it's important to set the maps folder.\n\n```rust\nuse libscemu::emu32;\n\n\nfn main() {\n    let mut emu = emu32();\n    emu.set_maps_folder(\"/tmp/maps32/\");\n    emu.init(false, false);\n```\n\nLoad your shellcode or PE binary and run the emulator.\nNone parameter means emulate for-ever.\n\n```rust\nemu.load_code(\"shellcodes32/shikata.bin\");\nemu.set_verbose(2);\nemu.run(None).unwrap(); \n```\n\nOr if you prefer call specific function.\n\n```rust\nemu.load_code(\"samples/malware.exe\");\n\nlet crypto_key_gen = 0x40112233;\nlet ret_addr = 0x40110000; // any place safe to return.\n\nlet param1 = 0x33;\nlet param2_out_buff = emu.alloc(\"buffer\", 1024);\n\nemu.maps.memset(param2_out_buff, 0, 1024); // non necesary, by default alloc create zeros.\nemu.maps.write_spaced_bytes(param2_out_buff, \n        \"DE CC 6C 83 CC F3 66 85 34\"); // example of initialization.\n\n// call function\nemu.regs.set_eip(crypto_key_gen);\nemu.stack_push32(param2_out_buff);\nemu.stack_push32(param1);\nemu.stack_push32(ret_addr);\nemu.run(Some(ret_addr)).unwrap();   // emulate until arrive to ret_addr\n\n// or simpler way:\nlet eax = emu.call32(crypto_key_gen, \u0026[param1, param2_out_buff]).unwrap();\n\n// this would be slower but more control\nwhile emu.step() {\n    ...\n}\n\n// check result\nlog::info!(\"return value: 0x{:x}\", emu.regs.get_eax());\nemu.maps.dump(param2_out_buff);\n```\n\nNow it's possible to do hooks on libscemu but not on pyscemu.\n\n```rust\nuse libscemu::emu32;\n\n//need iced_x86 crate only for instruction hooks, to get the\n//instruction object, so add `iced-x86 = \"1.17.0\"`\nuse iced_x86::{Instruction};  \n\n\nfn trace_memory_read(emu:\u0026mut libscemu::emu::Emu, ip_addr:u64, \n                     mem_addr:u64, sz:u8) {\n    log::info!(\"0x{:x}: reading {} at 0x{:x}\", ip_addr, sz, mem_addr);\n    if mem_addr == 0x22dff0 {\n        emu.stop();\n    }\n}\n\nfn trace_memory_write(emu:\u0026mut libscemu::emu::Emu, ip_addr:u64, \n                      mem_addr:u64, sz:u8, value:u128) -\u003e u128 {\n    log::info!(\"0x{:x}: writing {} '0x{:x}' at 0x{:x}\", ip_addr, sz, \n             value, mem_addr);\n    value   // I could change the value to write\n}\n\nfn trace_interrupt(emu:\u0026mut libscemu::emu::Emu, ip_addr:u64, \n                   interrupt:u64) -\u003e bool {\n    log::info!(\"interrupt {} triggered at eip: 0x{:x}\", interrupt, \n             ip_addr);\n    true  // do handle interrupts\n}   \n\nfn trace_exceptions(emu:\u0026mut libscemu::emu::Emu, ip_addr:u64) -\u003e bool {\n    log::info!(\"0x{:x} triggered an exception\", ip_addr);\n    true // do handle exceptions\n}\n\nfn trace_pre_instruction(emu:\u0026mut libscemu::emu::Emu, ip_addr:u64, \n                         ins:\u0026Instruction, sz:usize) {\n}\n\nfn trace_post_instruction(emu:\u0026mut libscemu::emu::Emu, ip_addr:u64, \n                          ins:\u0026Instruction, sz:usize, emu_ok:bool) {\n}\n\nfn trace_winapi_call(emu:\u0026mut libscemu::emu::Emu, ip_addr:u64, api_addr:u64) -\u003e bool {\n    return true; // handle api calls\n}\n\nfn main() {\n    let mut emu = emu32();\n    emu.set_maps_folder(\"../scemu/maps32/\"); // download the maps, ideally from scemu git.\n    emu.init();\n\n    emu.load_code(\"/home/sha0/src/scemu/shellcodes32/mars.exe\");\n    emu.hook.on_memory_read(trace_memory_read);\n    emu.hook.on_memory_write(trace_memory_write);\n    emu.hook.on_interrupt(trace_interrupt);\n    emu.hook.on_exception(trace_exceptions);\n    emu.hook.on_pre_instruction(trace_pre_instruction);\n    emu.hook.on_post_instruction(trace_post_instruction);\n    emu.hook.on_winapi_call(trace_winapi_call);\n    emu.run(None).unwrap();\n    log::info!(\"end!\");\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsha0coder%2Flibscemu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsha0coder%2Flibscemu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsha0coder%2Flibscemu/lists"}